@blocklet/ui-react 1.17.18 → 1.17.21

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.
@@ -7,8 +7,6 @@ exports.default = Footer;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
10
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
10
  var _styledComponents = _interopRequireDefault(require("styled-components"));
13
11
 
14
12
  var _useTheme = _interopRequireDefault(require("@material-ui/core/styles/useTheme"));
@@ -17,7 +15,9 @@ var _Container = _interopRequireDefault(require("@material-ui/core/Container"));
17
15
 
18
16
  var _NavMenu = _interopRequireDefault(require("@arcblock/ux/lib/NavMenu"));
19
17
 
20
- const _excluded = ["blockletMeta"];
18
+ var _types = require("../types");
19
+
20
+ const _excluded = ["meta"];
21
21
 
22
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
23
 
@@ -30,19 +30,23 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
30
30
  */
31
31
  function Footer(_ref) {
32
32
  let {
33
- blockletMeta
33
+ meta
34
34
  } = _ref,
35
35
  rest = _objectWithoutProperties(_ref, _excluded);
36
36
 
37
- const theme = (0, _useTheme.default)(); // eslint-disable-next-line no-param-reassign
37
+ const theme = (0, _useTheme.default)();
38
+ const blocklet = Object.assign({}, window.blocklet, meta);
39
+
40
+ if (!blocklet.appName) {
41
+ return null;
42
+ }
38
43
 
39
- blockletMeta = blockletMeta || window.blocklet;
40
44
  const {
41
45
  appLogo,
42
46
  appName,
43
47
  theme: blockletTheme,
44
48
  navigation
45
- } = blockletMeta;
49
+ } = blocklet;
46
50
  return /*#__PURE__*/_react.default.createElement(Root, Object.assign({}, rest, {
47
51
  $bgcolor: blockletTheme === null || blockletTheme === void 0 ? void 0 : blockletTheme.background,
48
52
  $theme: theme
@@ -71,10 +75,10 @@ function Footer(_ref) {
71
75
  }
72
76
 
73
77
  Footer.propTypes = {
74
- blockletMeta: _propTypes.default.object
78
+ meta: _types.blockletMetaProps
75
79
  };
76
80
  Footer.defaultProps = {
77
- blockletMeta: null
81
+ meta: {}
78
82
  };
79
83
 
80
84
  const Root = _styledComponents.default.div.withConfig({
@@ -25,7 +25,9 @@ var _context = require("@arcblock/ux/lib/Locale/context");
25
25
 
26
26
  require("@iconify/iconify");
27
27
 
28
- const _excluded = ["blockletMeta", "addons"];
28
+ var _types = require("../types");
29
+
30
+ const _excluded = ["meta", "addons", "sessionManagerProps"];
29
31
 
30
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
33
 
@@ -83,12 +85,14 @@ const parseNavigation = navigation => {
83
85
  /**
84
86
  * 专门用于 (composable) blocklet 的 Header 组件, 解析 blocklet meta 中的数据, 通过组合 UX 中的 Header & NavMenu 组件来渲染
85
87
  */
88
+ // eslint-disable-next-line no-shadow
86
89
 
87
90
 
88
91
  function Header(_ref) {
89
92
  let {
90
- blockletMeta,
91
- addons
93
+ meta,
94
+ addons,
95
+ sessionManagerProps
92
96
  } = _ref,
93
97
  rest = _objectWithoutProperties(_ref, _excluded);
94
98
 
@@ -96,23 +100,21 @@ function Header(_ref) {
96
100
 
97
101
  const {
98
102
  locale
99
- } = (0, _context.useLocaleContext)() || {}; // eslint-disable-next-line no-param-reassign
100
-
101
- blockletMeta = blockletMeta || window.blocklet;
103
+ } = (0, _context.useLocaleContext)() || {};
104
+ const blocklet = Object.assign({}, window.blocklet, meta);
102
105
 
103
- if (!blockletMeta) {
104
- console.warn('blocklet meta is not found.');
106
+ if (!blocklet.appName) {
105
107
  return null;
106
108
  }
107
109
 
108
110
  const {
109
111
  appLogo,
110
112
  appName,
111
- theme: blockletTheme,
113
+ theme,
112
114
  navigation = [],
113
115
  enableConnect = true,
114
116
  enableLocale = true
115
- } = blockletMeta;
117
+ } = blocklet;
116
118
  const navItems = parseNavigation(navigation);
117
119
 
118
120
  const renderAddons = () => {
@@ -131,10 +133,9 @@ function Header(_ref) {
131
133
 
132
134
 
133
135
  if (enableConnect && sessionInfo) {
134
- addonsArray.push( /*#__PURE__*/_react.default.createElement(_SessionManager.default, {
135
- session: sessionInfo.session,
136
- showRole: true
137
- }));
136
+ addonsArray.push( /*#__PURE__*/_react.default.createElement(_SessionManager.default, Object.assign({
137
+ session: sessionInfo.session
138
+ }, sessionManagerProps)));
138
139
  } // 在内置 addons 基础上定制 addons
139
140
 
140
141
 
@@ -157,7 +158,7 @@ function Header(_ref) {
157
158
  brand: appName,
158
159
  addons: renderAddons()
159
160
  }, rest, {
160
- $bgcolor: blockletTheme === null || blockletTheme === void 0 ? void 0 : blockletTheme.background
161
+ $bgcolor: theme === null || theme === void 0 ? void 0 : theme.background
161
162
  }), !(navItems !== null && navItems !== void 0 && navItems.length) ? null : _ref2 => {
162
163
  let {
163
164
  isMobile,
@@ -174,15 +175,19 @@ function Header(_ref) {
174
175
  }
175
176
 
176
177
  Header.propTypes = {
177
- blockletMeta: _propTypes.default.object,
178
+ meta: _types.blockletMetaProps,
178
179
  // 需要考虑 定制的 addons 与内置的 连接钱包/选择语言 addons 共存的情况
179
180
  // - PropTypes.func: 可以把自定义 addons 插在 session-manager 或 locale-selector (如果存在的话) 前/中/后
180
181
  // - PropTypes.node: 将 addons 原样传给 UX Header 组件
181
- addons: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node])
182
+ addons: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node]),
183
+ sessionManagerProps: _types.sessionManagerProps
182
184
  };
183
185
  Header.defaultProps = {
184
- blockletMeta: null,
185
- addons: null
186
+ meta: {},
187
+ addons: null,
188
+ sessionManagerProps: {
189
+ showRole: true
190
+ }
186
191
  };
187
192
  const StyledUxHeader = (0, _styledComponents.default)(_Header.ResponsiveHeader).withConfig({
188
193
  displayName: "Header__StyledUxHeader",
package/lib/types.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sessionManagerProps = exports.blockletMetaProps = void 0;
7
+
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ /* eslint-disable import/prefer-default-export */
13
+ const blockletMetaProps = _propTypes.default.shape({
14
+ appLogo: _propTypes.default.string,
15
+ appName: _propTypes.default.string,
16
+ theme: _propTypes.default.shape({
17
+ background: _propTypes.default.string
18
+ }),
19
+ enableConnect: _propTypes.default.bool,
20
+ enableLocale: _propTypes.default.bool,
21
+ navigation: _propTypes.default.arrayOf(_propTypes.default.shape({
22
+ title: _propTypes.default.string,
23
+ link: _propTypes.default.string,
24
+ icon: _propTypes.default.string,
25
+ items: _propTypes.default.arrayOf(_propTypes.default.shape({
26
+ title: _propTypes.default.string,
27
+ link: _propTypes.default.string
28
+ }))
29
+ }))
30
+ });
31
+
32
+ exports.blockletMetaProps = blockletMetaProps;
33
+
34
+ const sessionManagerProps = _propTypes.default.shape({
35
+ showText: _propTypes.default.bool,
36
+ showRole: _propTypes.default.bool,
37
+ switchDid: _propTypes.default.bool,
38
+ switchProfile: _propTypes.default.bool,
39
+ switchPassport: _propTypes.default.bool,
40
+ disableLogout: _propTypes.default.bool,
41
+ onLogin: _propTypes.default.func,
42
+ onLogout: _propTypes.default.func,
43
+ onSwitchDid: _propTypes.default.func,
44
+ onSwitchProfile: _propTypes.default.func,
45
+ onSwitchPassport: _propTypes.default.func,
46
+ menu: _propTypes.default.array,
47
+ menuRender: _propTypes.default.func,
48
+ dark: _propTypes.default.bool,
49
+ size: _propTypes.default.number
50
+ });
51
+
52
+ exports.sessionManagerProps = sessionManagerProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/ui-react",
3
- "version": "1.17.18",
3
+ "version": "1.17.21",
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": "^1.17.18",
38
- "@arcblock/ux": "^1.17.18",
37
+ "@arcblock/did-connect": "^1.17.21",
38
+ "@arcblock/ux": "^1.17.21",
39
39
  "@iconify/iconify": "^2.2.1",
40
40
  "@material-ui/core": "^4.12.3",
41
41
  "core-js": "^3.6.4",
@@ -56,5 +56,5 @@
56
56
  "eslint-plugin-react-hooks": "^4.2.0",
57
57
  "jest": "^24.1.0"
58
58
  },
59
- "gitHead": "d5c90d25f6b2e2313188645b82e997cf53ce274f"
59
+ "gitHead": "72ee6788c33de8033ac6fcc884554c9e2bdb0849"
60
60
  }
@@ -1,18 +1,22 @@
1
1
  import React from 'react';
2
- import PropTypes from 'prop-types';
3
2
  import styled from 'styled-components';
4
3
  import useTheme from '@material-ui/core/styles/useTheme';
5
4
  import Container from '@material-ui/core/Container';
6
5
  import NavMenu from '@arcblock/ux/lib/NavMenu';
7
6
 
7
+ import { blockletMetaProps } from '../types';
8
+
8
9
  /**
9
10
  * 专门用于 (composable) blocklet 的 Footer 组件, 基于 blocklet meta 中的数据渲染
10
11
  */
11
- export default function Footer({ blockletMeta, ...rest }) {
12
+ export default function Footer({ meta, ...rest }) {
12
13
  const theme = useTheme();
13
- // eslint-disable-next-line no-param-reassign
14
- blockletMeta = blockletMeta || window.blocklet;
15
- const { appLogo, appName, theme: blockletTheme, navigation } = blockletMeta;
14
+ const blocklet = Object.assign({}, window.blocklet, meta);
15
+ if (!blocklet.appName) {
16
+ return null;
17
+ }
18
+
19
+ const { appLogo, appName, theme: blockletTheme, navigation } = blocklet;
16
20
  return (
17
21
  <Root {...rest} $bgcolor={blockletTheme?.background} $theme={theme}>
18
22
  <Container>
@@ -45,11 +49,11 @@ export default function Footer({ blockletMeta, ...rest }) {
45
49
  }
46
50
 
47
51
  Footer.propTypes = {
48
- blockletMeta: PropTypes.object,
52
+ meta: blockletMetaProps,
49
53
  };
50
54
 
51
55
  Footer.defaultProps = {
52
- blockletMeta: null,
56
+ meta: {},
53
57
  };
54
58
 
55
59
  const Root = styled.div`
@@ -9,6 +9,8 @@ import LocaleSelector from '@arcblock/ux/lib/Locale/selector';
9
9
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
10
10
  import '@iconify/iconify';
11
11
 
12
+ import { blockletMetaProps, sessionManagerProps } from '../types';
13
+
12
14
  const isLinkActive = link => {
13
15
  if (window.location.pathname === '/') {
14
16
  return link === '/';
@@ -53,23 +55,23 @@ const parseNavigation = navigation => {
53
55
  /**
54
56
  * 专门用于 (composable) blocklet 的 Header 组件, 解析 blocklet meta 中的数据, 通过组合 UX 中的 Header & NavMenu 组件来渲染
55
57
  */
56
- export default function Header({ blockletMeta, addons, ...rest }) {
58
+ // eslint-disable-next-line no-shadow
59
+ export default function Header({ meta, addons, sessionManagerProps, ...rest }) {
57
60
  const sessionInfo = React.useContext(SessionContext);
58
61
  const { locale } = useLocaleContext() || {};
59
- // eslint-disable-next-line no-param-reassign
60
- blockletMeta = blockletMeta || window.blocklet;
61
- if (!blockletMeta) {
62
- console.warn('blocklet meta is not found.');
62
+ const blocklet = Object.assign({}, window.blocklet, meta);
63
+ if (!blocklet.appName) {
63
64
  return null;
64
65
  }
66
+
65
67
  const {
66
68
  appLogo,
67
69
  appName,
68
- theme: blockletTheme,
70
+ theme,
69
71
  navigation = [],
70
72
  enableConnect = true,
71
73
  enableLocale = true,
72
- } = blockletMeta;
74
+ } = blocklet;
73
75
  const navItems = parseNavigation(navigation);
74
76
 
75
77
  const renderAddons = () => {
@@ -84,7 +86,7 @@ export default function Header({ blockletMeta, addons, ...rest }) {
84
86
  }
85
87
  // 启用了连接钱包并且检测到了 session context
86
88
  if (enableConnect && sessionInfo) {
87
- addonsArray.push(<SessionManager session={sessionInfo.session} showRole />);
89
+ addonsArray.push(<SessionManager session={sessionInfo.session} {...sessionManagerProps} />);
88
90
  }
89
91
  // 在内置 addons 基础上定制 addons
90
92
  if (typeof addons === 'function') {
@@ -93,6 +95,7 @@ export default function Header({ blockletMeta, addons, ...rest }) {
93
95
  const addonsFragment = React.createElement(React.Fragment, null, ...addonsArray);
94
96
  return addonsFragment;
95
97
  };
98
+
96
99
  return (
97
100
  <StyledUxHeader
98
101
  logo={
@@ -103,7 +106,7 @@ export default function Header({ blockletMeta, addons, ...rest }) {
103
106
  brand={appName}
104
107
  addons={renderAddons()}
105
108
  {...rest}
106
- $bgcolor={blockletTheme?.background}>
109
+ $bgcolor={theme?.background}>
107
110
  {/* blocklet.yml 没有配置 navigation 时, 则为 children 传入 null, 此时 ResponsiveHeader 会渲染普通的不带 menu 的 Header */}
108
111
  {!navItems?.length
109
112
  ? null
@@ -121,16 +124,22 @@ export default function Header({ blockletMeta, addons, ...rest }) {
121
124
  }
122
125
 
123
126
  Header.propTypes = {
124
- blockletMeta: PropTypes.object,
127
+ meta: blockletMetaProps,
128
+
125
129
  // 需要考虑 定制的 addons 与内置的 连接钱包/选择语言 addons 共存的情况
126
130
  // - PropTypes.func: 可以把自定义 addons 插在 session-manager 或 locale-selector (如果存在的话) 前/中/后
127
131
  // - PropTypes.node: 将 addons 原样传给 UX Header 组件
128
132
  addons: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
133
+
134
+ sessionManagerProps,
129
135
  };
130
136
 
131
137
  Header.defaultProps = {
132
- blockletMeta: null,
138
+ meta: {},
133
139
  addons: null,
140
+ sessionManagerProps: {
141
+ showRole: true,
142
+ },
134
143
  };
135
144
 
136
145
  const StyledUxHeader = styled(ResponsiveHeader)`
package/src/types.js ADDED
@@ -0,0 +1,43 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ import PropTypes from 'prop-types';
3
+
4
+ export const blockletMetaProps = PropTypes.shape({
5
+ appLogo: PropTypes.string,
6
+ appName: PropTypes.string,
7
+ theme: PropTypes.shape({
8
+ background: PropTypes.string,
9
+ }),
10
+ enableConnect: PropTypes.bool,
11
+ enableLocale: PropTypes.bool,
12
+ navigation: PropTypes.arrayOf(
13
+ PropTypes.shape({
14
+ title: PropTypes.string,
15
+ link: PropTypes.string,
16
+ icon: PropTypes.string,
17
+ items: PropTypes.arrayOf(
18
+ PropTypes.shape({
19
+ title: PropTypes.string,
20
+ link: PropTypes.string,
21
+ })
22
+ ),
23
+ })
24
+ ),
25
+ });
26
+
27
+ export const sessionManagerProps = PropTypes.shape({
28
+ showText: PropTypes.bool,
29
+ showRole: PropTypes.bool,
30
+ switchDid: PropTypes.bool,
31
+ switchProfile: PropTypes.bool,
32
+ switchPassport: PropTypes.bool,
33
+ disableLogout: PropTypes.bool,
34
+ onLogin: PropTypes.func,
35
+ onLogout: PropTypes.func,
36
+ onSwitchDid: PropTypes.func,
37
+ onSwitchProfile: PropTypes.func,
38
+ onSwitchPassport: PropTypes.func,
39
+ menu: PropTypes.array,
40
+ menuRender: PropTypes.func,
41
+ dark: PropTypes.bool,
42
+ size: PropTypes.number,
43
+ });