@blocklet/ui-react 2.2.1 → 2.2.4

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.
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _reactRouterDom = require("react-router-dom");
11
+
12
+ var _context = require("@arcblock/ux/lib/Locale/context");
13
+
14
+ var _dashboard = _interopRequireDefault(require("@arcblock/ux/lib/Layout/dashboard"));
15
+
16
+ var _Address = _interopRequireDefault(require("@arcblock/did-connect/lib/Address"));
17
+
18
+ var _Avatar = _interopRequireDefault(require("@arcblock/did-connect/lib/Avatar"));
19
+
20
+ var _types = require("../types");
21
+
22
+ var _blocklets = require("../blocklets");
23
+
24
+ var _jsxRuntime = require("react/jsx-runtime");
25
+
26
+ const _excluded = ["meta"];
27
+
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
+
30
+ 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; }
31
+
32
+ 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; }
33
+
34
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
+
36
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
37
+
38
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
39
+
40
+ /**
41
+ * 专门用于 (composable) blocklet 的 Dashboard 组件, 解析 blocklet meta 中 section 为 dashboard 的 navigation 数据, 渲染一个 UX Dashboard
42
+ */
43
+ function Dashboard(_ref) {
44
+ var _formattedBlocklet$na;
45
+
46
+ let {
47
+ meta
48
+ } = _ref,
49
+ rest = _objectWithoutProperties(_ref, _excluded);
50
+
51
+ const {
52
+ locale
53
+ } = (0, _context.useLocaleContext)() || {};
54
+ const blocklet = Object.assign({}, window.blocklet, meta);
55
+ const formattedBlocklet = (0, _react.useMemo)(() => {
56
+ try {
57
+ return (0, _blocklets.formatBlockletInfo)(blocklet);
58
+ } catch (e) {
59
+ console.error('Failed to format blocklet info', e, blocklet);
60
+ return blocklet;
61
+ }
62
+ }, [blocklet]);
63
+
64
+ if (!blocklet.appName) {
65
+ return null;
66
+ }
67
+
68
+ const {
69
+ did,
70
+ appLogo,
71
+ appName
72
+ } = formattedBlocklet;
73
+ 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.dashboard, locale) || [];
74
+ localizedNav = localizedNav.map(item => _objectSpread(_objectSpread({}, item), {}, {
75
+ url: item.link,
76
+ label: item.title,
77
+ icon: item.icon ? /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
78
+ className: "iconify",
79
+ "data-icon": item.icon
80
+ }) : null
81
+ }));
82
+ const allLinks = [...(rest.links || []), localizedNav]; // https://github.com/ArcBlock/ux/issues/755#issuecomment-1208692620
83
+
84
+ allLinks.flat().forEach(item => {
85
+ item.external = true;
86
+ });
87
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_dashboard.default, _objectSpread(_objectSpread({
88
+ title: appName,
89
+ fullWidth: true,
90
+ sidebarWidth: 128,
91
+ legacy: false
92
+ }, rest), {}, {
93
+ headerProps: _objectSpread({
94
+ brand: appName,
95
+ description: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
96
+ compact: true,
97
+ responsive: false,
98
+ copyable: false,
99
+ prepend: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
100
+ did: did,
101
+ size: 16,
102
+ style: {
103
+ marginRight: 4
104
+ }
105
+ }),
106
+ children: did
107
+ }),
108
+ logo: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.Link, {
109
+ to: _blocklets.publicPath,
110
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
111
+ src: appLogo,
112
+ alt: "logo"
113
+ })
114
+ })
115
+ }, rest.headerProps),
116
+ links: allLinks
117
+ }));
118
+ }
119
+
120
+ Dashboard.propTypes = {
121
+ meta: _types.blockletMetaProps
122
+ };
123
+ Dashboard.defaultProps = {
124
+ meta: {}
125
+ };
126
+ var _default = Dashboard;
127
+ exports.default = _default;
@@ -177,14 +177,14 @@ function Header(_ref) {
177
177
  if (enableLocale && locale) {
178
178
  addonsArray.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_selector.default, {
179
179
  showText: false
180
- }));
180
+ }, "locale-selector"));
181
181
  } // 启用了连接钱包并且检测到了 session context
182
182
 
183
183
 
184
184
  if (enableConnect && sessionInfo) {
185
185
  addonsArray.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SessionManager.default, _objectSpread({
186
186
  session: sessionInfo.session
187
- }, sessionManagerProps)));
187
+ }, sessionManagerProps), "session-manager"));
188
188
  } // 在内置 addons 基础上定制 addons
189
189
 
190
190
 
@@ -264,7 +264,7 @@ Header.defaultProps = {
264
264
  const StyledUxHeader = (0, _styledComponents.default)(_Header.ResponsiveHeader).withConfig({
265
265
  displayName: "Header__StyledUxHeader",
266
266
  componentId: "sc-kcf4st-0"
267
- })(["", " font-family:Lato,Avenir,-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';.header-logo{min-width:44px;}", "{.header-logo{min-width:32px;}}.header-nav{.navmenu-sub .navmenu-item{min-width:80px;}}"], _ref3 => {
267
+ })(["", " font-family:Lato,Avenir,-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';.header-logo{min-width:44px;}", "{.header-logo{min-width:32px;}}.header-nav{.navmenu-sub .navmenu-item{min-width:80px;}}.header-nav.navmenu--horizontal{.navmenu-item{padding:16px 4px;}}"], _ref3 => {
268
268
  let {
269
269
  $bgcolor
270
270
  } = _ref3;
package/lib/blocklets.js CHANGED
@@ -7,7 +7,7 @@ exports.publicPath = exports.parseNavigation = exports.getLocalizedNavigation =
7
7
 
8
8
  var _utils = require("./utils");
9
9
 
10
- var _window, _window$blocklet;
10
+ var _window, _window$blocklet, _window2, _window2$blocklet;
11
11
 
12
12
  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
13
 
@@ -15,7 +15,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
15
15
 
16
16
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
17
 
18
- const publicPath = ((_window = window) === null || _window === void 0 ? void 0 : (_window$blocklet = _window.blocklet) === null || _window$blocklet === void 0 ? void 0 : _window$blocklet.prefix) || '/';
18
+ 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) || '/';
19
19
  /**
20
20
  * 格式化 theme (目前仅考虑 background)
21
21
  */
@@ -90,7 +90,9 @@ const parseNavigation = navigation => {
90
90
  // 对应 footer social media
91
91
  social: [],
92
92
  // 对应 footer 底部 links
93
- bottom: []
93
+ bottom: [],
94
+ // 对应 dashboard#sidenav 导航
95
+ dashboard: []
94
96
  }; // 对 navigation 顶层元素按 section 分组
95
97
 
96
98
  navigation.forEach(item => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/ui-react",
3
- "version": "2.2.1",
3
+ "version": "2.2.4",
4
4
  "description": "Some useful front-end web components that can be used in Blocklets.",
5
5
  "keywords": [
6
6
  "react",
@@ -17,7 +17,7 @@
17
17
  "url": "git+https://github.com/ArcBlock/ux.git"
18
18
  },
19
19
  "scripts": {
20
- "lint": "eslint src stories tests",
20
+ "lint": "eslint src tests",
21
21
  "build": "babel src --out-dir lib --copy-files --no-copy-ignored",
22
22
  "watch": "babel src --out-dir lib -w --copy-files --no-copy-ignored",
23
23
  "precommit": "CI=1 yarn test",
@@ -30,8 +30,8 @@
30
30
  "url": "https://github.com/ArcBlock/ux/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@arcblock/did-connect": "^2.2.1",
34
- "@arcblock/ux": "^2.2.1",
33
+ "@arcblock/did-connect": "^2.2.4",
34
+ "@arcblock/ux": "^2.2.4",
35
35
  "@iconify/iconify": "^2.2.1",
36
36
  "@mui/material": "^5.9.3",
37
37
  "core-js": "^3.24.1",
@@ -53,5 +53,5 @@
53
53
  "eslint-plugin-react-hooks": "^4.6.0",
54
54
  "jest": "^24.9.0"
55
55
  },
56
- "gitHead": "7fd063875d78f056aadea005b21b48c8c3bfb6c7"
56
+ "gitHead": "6658d7679f6a8e679e1fddae1af19ae8a2e64963"
57
57
  }
@@ -0,0 +1,81 @@
1
+ import { useMemo } from 'react';
2
+ import { Link } from 'react-router-dom';
3
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
4
+ import UxDashboard from '@arcblock/ux/lib/Layout/dashboard';
5
+ import DidAddress from '@arcblock/did-connect/lib/Address';
6
+ import DidAvatar from '@arcblock/did-connect/lib/Avatar';
7
+ import { blockletMetaProps } from '../types';
8
+ import { publicPath, formatBlockletInfo, getLocalizedNavigation } from '../blocklets';
9
+
10
+ /**
11
+ * 专门用于 (composable) blocklet 的 Dashboard 组件, 解析 blocklet meta 中 section 为 dashboard 的 navigation 数据, 渲染一个 UX Dashboard
12
+ */
13
+ function Dashboard({ meta, ...rest }) {
14
+ const { locale } = useLocaleContext() || {};
15
+ const blocklet = Object.assign({}, window.blocklet, meta);
16
+ const formattedBlocklet = useMemo(() => {
17
+ try {
18
+ return formatBlockletInfo(blocklet);
19
+ } catch (e) {
20
+ console.error('Failed to format blocklet info', e, blocklet);
21
+ return blocklet;
22
+ }
23
+ }, [blocklet]);
24
+
25
+ if (!blocklet.appName) {
26
+ return null;
27
+ }
28
+
29
+ const { did, appLogo, appName } = formattedBlocklet;
30
+ let localizedNav = getLocalizedNavigation(formattedBlocklet?.navigation?.dashboard, locale) || [];
31
+ localizedNav = localizedNav.map((item) => ({
32
+ ...item,
33
+ url: item.link,
34
+ label: item.title,
35
+ icon: item.icon ? <span className="iconify" data-icon={item.icon} /> : null,
36
+ }));
37
+ const allLinks = [...(rest.links || []), localizedNav];
38
+ // https://github.com/ArcBlock/ux/issues/755#issuecomment-1208692620
39
+ allLinks.flat().forEach((item) => {
40
+ item.external = true;
41
+ });
42
+
43
+ return (
44
+ <UxDashboard
45
+ title={appName}
46
+ fullWidth
47
+ sidebarWidth={128}
48
+ legacy={false}
49
+ {...rest}
50
+ headerProps={{
51
+ brand: appName,
52
+ description: (
53
+ <DidAddress
54
+ compact
55
+ responsive={false}
56
+ copyable={false}
57
+ prepend={<DidAvatar did={did} size={16} style={{ marginRight: 4 }} />}>
58
+ {did}
59
+ </DidAddress>
60
+ ),
61
+ logo: (
62
+ <Link to={publicPath}>
63
+ <img src={appLogo} alt="logo" />
64
+ </Link>
65
+ ),
66
+ ...rest.headerProps,
67
+ }}
68
+ links={allLinks}
69
+ />
70
+ );
71
+ }
72
+
73
+ Dashboard.propTypes = {
74
+ meta: blockletMetaProps,
75
+ };
76
+
77
+ Dashboard.defaultProps = {
78
+ meta: {},
79
+ };
80
+
81
+ export default Dashboard;
@@ -96,11 +96,11 @@ function Header({ meta, addons, sessionManagerProps, homeLink, ...rest }) {
96
96
  let addonsArray = [];
97
97
  // 启用了多语言并且检测到了 locale context
98
98
  if (enableLocale && locale) {
99
- addonsArray.push(<LocaleSelector showText={false} />);
99
+ addonsArray.push(<LocaleSelector key="locale-selector" showText={false} />);
100
100
  }
101
101
  // 启用了连接钱包并且检测到了 session context
102
102
  if (enableConnect && sessionInfo) {
103
- addonsArray.push(<SessionManager session={sessionInfo.session} {...sessionManagerProps} />);
103
+ addonsArray.push(<SessionManager key="session-manager" session={sessionInfo.session} {...sessionManagerProps} />);
104
104
  }
105
105
  // 在内置 addons 基础上定制 addons
106
106
  if (typeof addons === 'function') {
@@ -200,6 +200,11 @@ const StyledUxHeader = styled(ResponsiveHeader)`
200
200
  min-width: 80px;
201
201
  }
202
202
  }
203
+ .header-nav.navmenu--horizontal {
204
+ .navmenu-item {
205
+ padding: 16px 4px;
206
+ }
207
+ }
203
208
  `;
204
209
 
205
210
  export default withErrorBoundary(Header, {
package/src/blocklets.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { mapRecursive } from './utils';
2
2
 
3
- export const publicPath = window?.blocklet?.prefix || '/';
3
+ export const publicPath = window?.blocklet?.groupPrefix || window?.blocklet?.prefix || '/';
4
4
 
5
5
  /**
6
6
  * 格式化 theme (目前仅考虑 background)
@@ -61,6 +61,8 @@ export const parseNavigation = (navigation) => {
61
61
  social: [],
62
62
  // 对应 footer 底部 links
63
63
  bottom: [],
64
+ // 对应 dashboard#sidenav 导航
65
+ dashboard: [],
64
66
  };
65
67
 
66
68
  // 对 navigation 顶层元素按 section 分组