@abtnode/ux 1.7.4 → 1.7.7

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.
@@ -25,6 +25,8 @@ var _Connect = _interopRequireDefault(require("@arcblock/did-connect/lib/Connect
25
25
 
26
26
  var _context = require("@arcblock/ux/lib/Locale/context");
27
27
 
28
+ var _constant = require("@abtnode/constant");
29
+
28
30
  var _wrapLocale = _interopRequireDefault(require("./wrap-locale"));
29
31
 
30
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -66,11 +68,18 @@ function IssuePassport(_ref) {
66
68
  }
67
69
 
68
70
  const onLogin = () => {
71
+ var _window$env;
72
+
69
73
  try {
70
74
  session.logout();
71
75
  } catch (err) {// Do nothing
72
76
  }
73
77
 
78
+ if ((((_window$env = window.env) === null || _window$env === void 0 ? void 0 : _window$env.apiPrefix) || '').startsWith(_constant.WELLKNOWN_SERVICE_PATH_PREFIX)) {
79
+ history.replace("".concat(_constant.WELLKNOWN_SERVICE_PATH_PREFIX, "/login"));
80
+ return;
81
+ }
82
+
74
83
  history.replace('/');
75
84
  };
76
85
 
@@ -36,7 +36,11 @@ function HeaderAddon(_ref) {
36
36
  let {
37
37
  SessionContext,
38
38
  webWalletUrl,
39
- extraItems
39
+ extraItems,
40
+ showLocale,
41
+ showHelper,
42
+ showSessionManager,
43
+ sessionManagerProps
40
44
  } = _ref;
41
45
  const {
42
46
  session
@@ -69,37 +73,44 @@ function HeaderAddon(_ref) {
69
73
  path = docPaths[pathName];
70
74
  }
71
75
 
72
- const w = window.open('about:blank');
73
- w.location.href = "https://docs.arcblock.io/abtnode/".concat(locale).concat(path);
76
+ window.open("https://docs.arcblock.io/abtnode/".concat(locale).concat(path), '_blank');
74
77
  };
75
78
 
76
- return /*#__PURE__*/_react.default.createElement(Div, null, extraItems.map(x => x), /*#__PURE__*/_react.default.createElement(_selector.default, {
79
+ return /*#__PURE__*/_react.default.createElement(Div, null, extraItems.map(x => x), showLocale && /*#__PURE__*/_react.default.createElement(_selector.default, {
77
80
  "data-cy": "locale-addon",
78
81
  size: 23,
79
82
  showText: false,
80
83
  className: "locale-addon"
81
- }), /*#__PURE__*/_react.default.createElement(_IconButton.default, {
84
+ }), showHelper && /*#__PURE__*/_react.default.createElement(_IconButton.default, {
82
85
  onClick: onHelpClick
83
86
  }, /*#__PURE__*/_react.default.createElement(_HelpOutline.default, {
84
87
  style: {
85
88
  fontSize: 28
86
89
  }
87
- })), /*#__PURE__*/_react.default.createElement(_SessionManager.default, {
90
+ })), showSessionManager && /*#__PURE__*/_react.default.createElement(_SessionManager.default, Object.assign({
88
91
  session: session,
89
92
  webWalletUrl: walletUrl,
90
93
  size: 24,
91
94
  showRole: true
92
- }));
95
+ }, sessionManagerProps)));
93
96
  }
94
97
 
95
98
  HeaderAddon.propTypes = {
96
99
  SessionContext: _propTypes.default.object.isRequired,
97
100
  webWalletUrl: _propTypes.default.string,
98
- extraItems: _propTypes.default.array
101
+ extraItems: _propTypes.default.array,
102
+ showLocale: _propTypes.default.bool,
103
+ showSessionManager: _propTypes.default.bool,
104
+ showHelper: _propTypes.default.bool,
105
+ sessionManagerProps: _propTypes.default.object
99
106
  };
100
107
  HeaderAddon.defaultProps = {
101
108
  webWalletUrl: '',
102
- extraItems: []
109
+ extraItems: [],
110
+ showLocale: true,
111
+ showSessionManager: true,
112
+ showHelper: true,
113
+ sessionManagerProps: {}
103
114
  };
104
115
 
105
116
  const Div = _styledComponents.default.div.withConfig({
@@ -41,6 +41,8 @@ var _context = require("@arcblock/ux/lib/Locale/context");
41
41
 
42
42
  var _Connect = _interopRequireDefault(require("@arcblock/did-connect/lib/Connect"));
43
43
 
44
+ var _constant = require("@abtnode/constant");
45
+
44
46
  var _cardSelector = _interopRequireDefault(require("./card-selector"));
45
47
 
46
48
  var _wrapLocale = _interopRequireDefault(require("./wrap-locale"));
@@ -129,13 +131,26 @@ function LostPassport(_ref2) {
129
131
  };
130
132
 
131
133
  const onLogin = () => {
134
+ var _window$env;
135
+
132
136
  try {
133
137
  session.logout();
134
138
  } catch (err) {// Do nothing
135
139
  }
136
140
 
137
- const redirect = searchParams.get('redirect') || '/';
138
- history.replace(redirect);
141
+ const redirect = searchParams.get('redirect');
142
+
143
+ if (redirect) {
144
+ history.replace(redirect);
145
+ return;
146
+ }
147
+
148
+ if ((((_window$env = window.env) === null || _window$env === void 0 ? void 0 : _window$env.apiPrefix) || '').startsWith(_constant.WELLKNOWN_SERVICE_PATH_PREFIX)) {
149
+ history.replace("".concat(_constant.WELLKNOWN_SERVICE_PATH_PREFIX, "/login"));
150
+ return;
151
+ }
152
+
153
+ history.replace('/');
139
154
  };
140
155
 
141
156
  const handleChange = event => {
package/lib/util/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.getAccessUrl = getAccessUrl;
6
7
  exports.sleep = sleep;
7
8
  exports.validateDomain = void 0;
8
9
 
@@ -31,5 +32,53 @@ const validateDomain = function validateDomain(domain) {
31
32
 
32
33
  return null;
33
34
  };
35
+ /**
36
+ * get access url
37
+ * auto fix http/https, port, query
38
+ * docker friendly
39
+ */
34
40
 
35
- exports.validateDomain = validateDomain;
41
+
42
+ exports.validateDomain = validateDomain;
43
+
44
+ function getAccessUrl(hostname) {
45
+ let path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
46
+ let params = arguments.length > 2 ? arguments[2] : undefined;
47
+
48
+ if (!hostname) {
49
+ return '';
50
+ }
51
+
52
+ let protocol = 'http';
53
+
54
+ if (window.location.protocol === 'https:') {
55
+ if (hostname.endsWith(_constant.DEFAULT_IP_DOMAIN_SUFFIX)) {
56
+ protocol = 'https';
57
+ }
58
+
59
+ if (hostname.endsWith(_constant.DEFAULT_DID_DOMAIN)) {
60
+ protocol = 'https';
61
+ }
62
+ }
63
+
64
+ let port = '';
65
+ const browserPort = Number(window.location.port);
66
+
67
+ if (process.env.NODE_ENV !== 'development' && browserPort && ![80, 443].includes(browserPort)) {
68
+ port = ":".concat(browserPort);
69
+ }
70
+
71
+ const urlObj = new URL("".concat(protocol, "://").concat(hostname).concat(port));
72
+ urlObj.pathname = path;
73
+ const url = urlObj.href.replace(/\/$/, '');
74
+
75
+ if (!params || !Object.keys(params)) {
76
+ return url;
77
+ }
78
+
79
+ const searchParams = new URLSearchParams();
80
+ Object.keys(params).forEach(key => {
81
+ searchParams.append(key, params[key]);
82
+ });
83
+ return "".concat(url, "?").concat(searchParams.toString());
84
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.7.4",
6
+ "version": "1.7.7",
7
7
  "description": "UX components shared across abtnode packages",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -14,16 +14,17 @@
14
14
  "lint:fix": "eslint src --fix",
15
15
  "prepublishOnly": "npm run build",
16
16
  "build": "babel src --out-dir lib --copy-files",
17
- "watch": "babel src --out-dir lib -w --copy-files"
17
+ "watch": "babel src --out-dir lib -w --copy-files",
18
+ "test": "node tools/jest.js"
18
19
  },
19
20
  "keywords": [],
20
21
  "author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
21
22
  "license": "MIT",
22
23
  "dependencies": {
23
- "@abtnode/constant": "1.7.4",
24
- "@arcblock/did-connect": "^1.16.61",
25
- "@arcblock/ux": "^1.16.61",
26
- "@blocklet/meta": "1.7.4",
24
+ "@abtnode/constant": "1.7.7",
25
+ "@arcblock/did-connect": "^1.17.2",
26
+ "@arcblock/ux": "^1.17.2",
27
+ "@blocklet/meta": "1.7.7",
27
28
  "@material-ui/core": "^4.12.3",
28
29
  "@material-ui/icons": "^4.11.2",
29
30
  "notistack": "^1.0.6",
@@ -41,5 +42,5 @@
41
42
  "babel-plugin-inline-react-svg": "^1.1.1",
42
43
  "babel-plugin-styled-components": "^1.10.7"
43
44
  },
44
- "gitHead": "02b25a877e5b56b389ab318a851bea01212e10df"
45
+ "gitHead": "619db37ea7a91c64a9bf30836a55c70d55325e73"
45
46
  }