@abtnode/ux 1.8.32 → 1.8.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.
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = CancelConfirm;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
9
+ var _TextField = _interopRequireDefault(require("@mui/material/TextField"));
10
+ var _Alert = _interopRequireDefault(require("@mui/material/Alert"));
11
+ var _context = require("@arcblock/ux/lib/Locale/context");
12
+ var _clickToCopy = _interopRequireDefault(require("./click-to-copy"));
13
+ var _confirm = _interopRequireDefault(require("./confirm"));
14
+ var _jsxRuntime = require("react/jsx-runtime");
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ 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; }
17
+ 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; }
18
+ 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; }
19
+ function CancelConfirm(_ref) {
20
+ let {
21
+ title: _title,
22
+ description: _description,
23
+ confirmPlaceholder,
24
+ cancel,
25
+ confirm,
26
+ params: initialParams,
27
+ onCancel,
28
+ onConfirm,
29
+ keyName
30
+ } = _ref;
31
+ const {
32
+ t
33
+ } = (0, _context.useLocaleContext)();
34
+ const confirmSetting = {
35
+ title: () => /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
36
+ children: [_title, " (".concat(keyName, ")")]
37
+ }),
38
+ description: (params, setParams) => {
39
+ const setValue = value => {
40
+ // eslint-disable-next-line no-underscore-dangle
41
+ setParams(_objectSpread(_objectSpread({}, value), {}, {
42
+ __disableConfirm: value.__disableConfirm
43
+ }));
44
+ };
45
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
46
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Alert.default, {
47
+ severity: "warning",
48
+ style: {
49
+ width: '100%'
50
+ },
51
+ children: t('common.notice')
52
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
53
+ style: {
54
+ marginTop: 24,
55
+ marginBottom: 24
56
+ },
57
+ dangerouslySetInnerHTML: {
58
+ __html: _description
59
+ }
60
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
61
+ style: {
62
+ marginBottom: 24
63
+ },
64
+ children: [t('common.click'), "\uFF1A", /*#__PURE__*/(0, _jsxRuntime.jsx)(_clickToCopy.default, {
65
+ "data-cy": "click-copy",
66
+ children: keyName
67
+ })]
68
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
69
+ component: "div",
70
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextField.default, {
71
+ label: confirmPlaceholder,
72
+ autoComplete: "off",
73
+ "data-cy": "delete-confirm-input",
74
+ variant: "outlined",
75
+ fullWidth: true,
76
+ autoFocus: true,
77
+ value: params.inputVal,
78
+ onChange: e => {
79
+ setValue(_objectSpread(_objectSpread({}, params), {}, {
80
+ inputVal: e.target.value,
81
+ __disableConfirm: keyName !== e.target.value
82
+ }));
83
+ }
84
+ })
85
+ })]
86
+ });
87
+ },
88
+ confirm,
89
+ cancel,
90
+ onConfirm,
91
+ onCancel,
92
+ params: _objectSpread({
93
+ inputVal: '',
94
+ __disableConfirm: true
95
+ }, initialParams)
96
+ };
97
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_confirm.default, {
98
+ title: confirmSetting.title,
99
+ description: confirmSetting.description,
100
+ confirm: confirmSetting.confirm,
101
+ cancel: confirmSetting.cancel,
102
+ params: confirmSetting.params,
103
+ onConfirm: confirmSetting.onConfirm,
104
+ onCancel: confirmSetting.onCancel
105
+ });
106
+ }
107
+ CancelConfirm.propTypes = {
108
+ title: _propTypes.default.any.isRequired,
109
+ keyName: _propTypes.default.any.isRequired,
110
+ description: _propTypes.default.any.isRequired,
111
+ // can be a function that renders different content based on params
112
+ confirmPlaceholder: _propTypes.default.any.isRequired,
113
+ cancel: _propTypes.default.string,
114
+ confirm: _propTypes.default.string,
115
+ params: _propTypes.default.object,
116
+ // This object holds states managed in the dialog
117
+ onCancel: _propTypes.default.func,
118
+ onConfirm: _propTypes.default.func.isRequired
119
+ };
120
+ CancelConfirm.defaultProps = {
121
+ onCancel: () => {},
122
+ cancel: '',
123
+ confirm: 'Confirm',
124
+ params: {}
125
+ };
@@ -42,8 +42,12 @@ function FormTextInput(_ref) {
42
42
  const handleSubmit = async () => {
43
43
  setLoading(true);
44
44
  try {
45
- await onSubmit(value);
46
- setDefaultValue(value);
45
+ const shouldUpdate = await onSubmit(value);
46
+ if (shouldUpdate === false) {
47
+ setValue(defaultValue);
48
+ } else {
49
+ setDefaultValue(value);
50
+ }
47
51
  } catch (err) {
48
52
  setValue(defaultValue);
49
53
  } finally {
@@ -80,6 +84,9 @@ function FormTextInput(_ref) {
80
84
  }, rest)) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
81
85
  px: 1,
82
86
  className: "form-item-input slot",
87
+ style: {
88
+ whiteSpace: 'pre-wrap'
89
+ },
83
90
  children: value
84
91
  });
85
92
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_formWrapper.default, {
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useBlocklet = useBlocklet;
7
+ var _react = require("react");
8
+ var _merge = _interopRequireDefault(require("lodash/merge"));
9
+ var _omit = _interopRequireDefault(require("lodash/omit"));
10
+ var _constant = require("@blocklet/constant");
11
+ var _toast = _interopRequireDefault(require("../toast"));
12
+ var _util = require("../util");
13
+ var _util2 = require("../blocklet/util");
14
+ var _urlEvaluation = require("./url-evaluation");
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ 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; }
17
+ 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; }
18
+ 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; }
19
+ // eslint-disable-next-line import/prefer-default-export
20
+ function useBlocklet(_ref) {
21
+ var _blocklet$site, _blocklet$site$domain, _blocklet$meta, _blocklet$meta2, _blocklet$meta3, _blocklet$meta4, _blocklet$meta5, _blocklet$meta6, _blocklet$meta7, _blocklet$meta8;
22
+ let {
23
+ did,
24
+ client,
25
+ useSubscription,
26
+ getIP,
27
+ useLocaleContext,
28
+ disableSubscription
29
+ } = _ref;
30
+ const {
31
+ t,
32
+ locale
33
+ } = useLocaleContext();
34
+ const [error, setError] = (0, _react.useState)(null);
35
+ const [loading, setLoading] = (0, _react.useState)(false);
36
+ const [loadingRuntimeInfo, setLoadingRuntimeInfo] = (0, _react.useState)(false);
37
+ const [blocklet, setBlocklet] = (0, _react.useState)();
38
+ const [domainStatus, setDomainStatus] = (0, _react.useState)({});
39
+ const domainListStr = blocklet !== null && blocklet !== void 0 && (_blocklet$site = blocklet.site) !== null && _blocklet$site !== void 0 && (_blocklet$site$domain = _blocklet$site.domainAliases) !== null && _blocklet$site$domain !== void 0 && _blocklet$site$domain.length ? JSON.stringify(blocklet.site.domainAliases.map(x => x.value)) : '';
40
+ const domains = (0, _react.useMemo)(() => {
41
+ var _blocklet$site2;
42
+ return ((blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$site2 = blocklet.site) === null || _blocklet$site2 === void 0 ? void 0 : _blocklet$site2.domainAliases) || []).map(x => x.value);
43
+ }, [domainListStr]); // eslint-disable-line
44
+
45
+ const {
46
+ domainsAccessibility,
47
+ recommendedDomain
48
+ } = (0, _urlEvaluation.useDomainsAccessibility)(domains);
49
+ const refreshRuntimeInfo = async () => {
50
+ setLoadingRuntimeInfo(true);
51
+ try {
52
+ const {
53
+ blocklet: data
54
+ } = await client.getBlocklet({
55
+ input: {
56
+ did,
57
+ attachRuntimeInfo: true
58
+ }
59
+ });
60
+ await (0, _util2.fixBlocklet)(data, {
61
+ getIP
62
+ });
63
+ setBlocklet(data);
64
+ } catch (err) {
65
+ _toast.default.error(err.message);
66
+ } finally {
67
+ setLoadingRuntimeInfo(false);
68
+ }
69
+ };
70
+ const refreshBlocklet = async function refreshBlocklet() {
71
+ let {
72
+ showError = true,
73
+ attachRuntimeInfo = true
74
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
75
+ try {
76
+ setLoading(true);
77
+ setError(null);
78
+ const {
79
+ blocklet: data
80
+ } = await client.getBlocklet({
81
+ input: {
82
+ did,
83
+ attachRuntimeInfo: false
84
+ }
85
+ });
86
+ if (data) {
87
+ setBlocklet(oldBlocklet => {
88
+ (0, _util2.fixBlocklet)(data, {
89
+ fixRuntime: 'merge-old',
90
+ oldBlocklet
91
+ });
92
+ return data;
93
+ });
94
+ setLoading(false);
95
+ if (attachRuntimeInfo) {
96
+ refreshRuntimeInfo();
97
+ }
98
+ } else {
99
+ throw new Error(t('blocklet.notFound'));
100
+ }
101
+ } catch (err) {
102
+ setLoading(false);
103
+ setError(err);
104
+ if (showError) {
105
+ _toast.default.error(err.message);
106
+ }
107
+ }
108
+ };
109
+ const refreshDomainStatus = () => {
110
+ if (did && domainListStr) {
111
+ client.checkDomains({
112
+ input: {
113
+ did
114
+ }
115
+ }).catch(err => {
116
+ console.error(err);
117
+ });
118
+ }
119
+ };
120
+ (0, _react.useEffect)(() => {
121
+ if (domainListStr && !disableSubscription) {
122
+ refreshDomainStatus();
123
+ }
124
+ }, [domainListStr, disableSubscription]); // eslint-disable-line
125
+
126
+ useSubscription(_constant.BlockletEvents.domainStatus, data => {
127
+ setDomainStatus(pre => _objectSpread(_objectSpread({}, pre), {}, {
128
+ [data.domain]: _objectSpread(_objectSpread({}, pre[data.domain]), data)
129
+ }));
130
+ }, [blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta = blocklet.meta) === null || _blocklet$meta === void 0 ? void 0 : _blocklet$meta.did, !disableSubscription]);
131
+ useSubscription(_constant.BlockletEvents.statusChange, () => refreshBlocklet({
132
+ attachRuntimeInfo: false
133
+ }), [blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta2 = blocklet.meta) === null || _blocklet$meta2 === void 0 ? void 0 : _blocklet$meta2.did, !disableSubscription]);
134
+ useSubscription(_constant.BlockletEvents.started, refreshBlocklet, [blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta3 = blocklet.meta) === null || _blocklet$meta3 === void 0 ? void 0 : _blocklet$meta3.did, !disableSubscription]);
135
+ useSubscription(_constant.BlockletEvents.startFailed, refreshBlocklet, [blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta4 = blocklet.meta) === null || _blocklet$meta4 === void 0 ? void 0 : _blocklet$meta4.did, !disableSubscription]);
136
+ useSubscription(_constant.BlockletEvents.installed, refreshBlocklet, [blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta5 = blocklet.meta) === null || _blocklet$meta5 === void 0 ? void 0 : _blocklet$meta5.did, !disableSubscription]);
137
+ useSubscription(_constant.BlockletEvents.upgraded, refreshBlocklet, [blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta6 = blocklet.meta) === null || _blocklet$meta6 === void 0 ? void 0 : _blocklet$meta6.did, !disableSubscription]);
138
+ useSubscription(_constant.BlockletEvents.downgraded, refreshBlocklet, [blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta7 = blocklet.meta) === null || _blocklet$meta7 === void 0 ? void 0 : _blocklet$meta7.did, !disableSubscription]);
139
+ useSubscription(_constant.BlockletEvents.updated, refreshBlocklet, [blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta8 = blocklet.meta) === null || _blocklet$meta8 === void 0 ? void 0 : _blocklet$meta8.did, !disableSubscription]);
140
+ const data = blocklet ? (0, _merge.default)(blocklet, {
141
+ site: {
142
+ domainAliases: blocklet.site.domainAliases.map(x => {
143
+ const domain = x.value;
144
+ const key = (0, _util.toSlotDomain)(domain);
145
+ x.domainStatus = (0, _omit.default)(domainStatus[key], ['domain', 'meta']);
146
+ x.accessibility = (0, _omit.default)(domainsAccessibility[domain], ['domain']);
147
+ x.href = (0, _util.getBlockletUrl)({
148
+ blocklet,
149
+ domain: x,
150
+ params: (0, _util.getBlockletUrlParams)(blocklet, locale)
151
+ });
152
+ return x;
153
+ })
154
+ }
155
+ }) : null;
156
+ return {
157
+ loading,
158
+ loadingRuntimeInfo,
159
+ error,
160
+ blocklet: data,
161
+ recommendedDomain: recommendedDomain || '',
162
+ actions: {
163
+ refreshBlocklet,
164
+ refreshDomainStatus,
165
+ setBlocklet
166
+ }
167
+ };
168
+ }
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useBlockletUrlEvaluation = useBlockletUrlEvaluation;
7
+ exports.useDomainsAccessibility = useDomainsAccessibility;
8
+ exports.useUrlEvaluation = useUrlEvaluation;
9
+ var _react = require("react");
10
+ var _urlJoin = _interopRequireDefault(require("url-join"));
11
+ var _memoize = _interopRequireDefault(require("lodash/memoize"));
12
+ var _constant = require("@abtnode/constant");
13
+ var _urlEvaluation = require("@abtnode/util/lib/url-evaluation");
14
+ var _checkAccessibleBrowser = _interopRequireDefault(require("@abtnode/util/lib/url-evaluation/check-accessible-browser"));
15
+ var _context = require("@arcblock/ux/lib/Locale/context");
16
+ var _util = require("../util");
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ 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; }
19
+ 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; }
20
+ 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; }
21
+ // 如果同一个页面中存在多个部分同时对同一个 url 检测 url 可访问性, 避免造成重复请求
22
+ const ping = (0, _memoize.default)(url => (0, _checkAccessibleBrowser.default)((0, _urlJoin.default)(new URL(url).origin, _constant.WELLKNOWN_PING_PREFIX)));
23
+
24
+ // url <-> evaluation cache
25
+ const CACHE = {};
26
+ function useUrlEvaluation(_ref) {
27
+ let {
28
+ urls,
29
+ checkAccessible = _checkAccessibleBrowser.default,
30
+ disableCache = false
31
+ } = _ref;
32
+ // 基于 CACHE 初始化该 hook 的状态
33
+ // FIXME: 最好解决源头的 material-table 渲染 BlockletInterface 时的 re-mount 问题 (#4897)
34
+ const initialCachedRef = (0, _react.useRef)(urls.filter(url => CACHE[url]).map(url => CACHE[url]));
35
+ const allCached = initialCachedRef.current.length === urls.length;
36
+ const [urlsState, setUrlsState] = (0, _react.useState)(allCached ? initialCachedRef.current : []);
37
+ const [loading, setLoading] = (0, _react.useState)(!allCached);
38
+ const recommendedUrlState = (0, _react.useMemo)(() => {
39
+ if (!loading && urlsState.length) {
40
+ return urlsState[0];
41
+ }
42
+ return null;
43
+ }, [urlsState, loading]);
44
+ (0, _react.useEffect)(() => {
45
+ if ((urls === null || urls === void 0 ? void 0 : urls.length) > 0 && !allCached) {
46
+ const evaluate = async () => {
47
+ let results;
48
+ setLoading(true);
49
+ if (disableCache) {
50
+ results = await (0, _urlEvaluation.evaluateURLs)(urls, {
51
+ checkAccessible
52
+ });
53
+ results.forEach(item => {
54
+ CACHE[item.url] = item;
55
+ });
56
+ } else {
57
+ const misses = await (0, _urlEvaluation.evaluateURLs)(urls.filter(url => !CACHE[url]), {
58
+ checkAccessible
59
+ });
60
+ misses.forEach(item => {
61
+ CACHE[item.url] = item;
62
+ });
63
+ results = urls.map(url => CACHE[url]).sort((a, b) => b.score - a.score);
64
+ }
65
+ setUrlsState(results);
66
+ setLoading(false);
67
+ };
68
+ evaluate();
69
+ }
70
+ // eslint-disable-next-line react-hooks/exhaustive-deps
71
+ }, [urls, disableCache, allCached]);
72
+ return {
73
+ urlsState,
74
+ loading,
75
+ recommendedUrlState,
76
+ recommendedUrl: recommendedUrlState === null || recommendedUrlState === void 0 ? void 0 : recommendedUrlState.url
77
+ };
78
+ }
79
+
80
+ /**
81
+ * 主要对 blocklet 访问 urls 进行评估
82
+ * @param {object} blocklet
83
+ */
84
+ function useBlockletUrlEvaluation(blocklet) {
85
+ const {
86
+ locale
87
+ } = (0, _react.useContext)(_context.LocaleContext);
88
+ const urls = (0, _react.useMemo)(() => {
89
+ if (!blocklet) {
90
+ return [];
91
+ }
92
+ // getBlockletUrlParams 的调用是必须的, 会根据 blocklet 状态决定是否添加 "__start__" 参数, 以保证 blocklet 启动按钮可以正确的跳转到启动页面
93
+ return (0, _util.getBlockletUrls)({
94
+ blocklet,
95
+ params: (0, _util.getBlockletUrlParams)(blocklet, locale)
96
+ });
97
+ }, [blocklet, locale]);
98
+ const {
99
+ loading,
100
+ recommendedUrlState,
101
+ recommendedUrl
102
+ } = useUrlEvaluation({
103
+ urls,
104
+ checkAccessible: ping
105
+ });
106
+ return {
107
+ urls,
108
+ loading,
109
+ recommendedUrlState,
110
+ recommendedUrl
111
+ };
112
+ }
113
+
114
+ /**
115
+ * 主要对 blocklet domains 对应的 urls 进行评估, 配合 DomainStatusProvider 使用
116
+ * @param {string[]} domains
117
+ */
118
+ function useDomainsAccessibility(domains) {
119
+ // 获取 blocklet domain 对应的访问 url
120
+ const urls = (0, _react.useMemo)(() => domains.map(item => (0, _util.getAccessUrl)(item)), [domains]);
121
+ const {
122
+ urlsState,
123
+ loading,
124
+ recommendedUrl
125
+ } = useUrlEvaluation({
126
+ urls,
127
+ checkAccessible: ping
128
+ });
129
+ let result;
130
+ if (loading) {
131
+ result = {
132
+ domainsAccessibility: domains.reduce((acc, cur) => _objectSpread(_objectSpread({}, acc), {}, {
133
+ [cur]: {
134
+ loading: true
135
+ }
136
+ }), {}),
137
+ recommendedDomain: null
138
+ };
139
+ } else {
140
+ var _urlsState$find;
141
+ const domainsAccessibility = urlsState.reduce((acc, cur) => {
142
+ // 检测对象是 domain, 但检测可访问性用的是 domain 对应的 ping url, 所以需要取 hostname 作为结果
143
+ const domain = new URL(cur.url).hostname;
144
+ acc[domain] = _objectSpread(_objectSpread({}, cur), {}, {
145
+ domain
146
+ });
147
+ return acc;
148
+ }, {});
149
+ // 从排好优先级的 urls 中选择第一个可访问的 url 作为 recommendedDomain (对于自定义域名, 可能存在评分最高但不可访问的情况) (#5195)
150
+ const accessibleUrl = ((_urlsState$find = urlsState.find(item => item.accessible)) === null || _urlsState$find === void 0 ? void 0 : _urlsState$find.url) || recommendedUrl;
151
+ result = {
152
+ domainsAccessibility,
153
+ recommendedDomain: accessibleUrl ? new URL(accessibleUrl).hostname : null
154
+ };
155
+ }
156
+ return result;
157
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useSubscription = useSubscription;
7
+ var _react = require("react");
8
+ // eslint-disable-next-line import/prefer-default-export
9
+ function useSubscription(_ref) {
10
+ let {
11
+ wsClient,
12
+ event,
13
+ cb = () => {},
14
+ deps = []
15
+ } = _ref;
16
+ (0, _react.useEffect)(() => {
17
+ // if deps has false value, do not sub
18
+ const shouldSub = wsClient && (!deps.length || deps.every(Boolean));
19
+ if (shouldSub) {
20
+ wsClient.on(event, cb);
21
+ }
22
+ return () => {
23
+ if (shouldSub) {
24
+ wsClient.off(event, cb);
25
+ }
26
+ };
27
+ }, deps); // eslint-disable-line
28
+ }
package/lib/locales/en.js CHANGED
@@ -224,6 +224,7 @@ module.exports = {
224
224
  scheduleFailed: 'schedule failed',
225
225
  scheduleSuccess: 'successfully scheduled',
226
226
  search: 'Search',
227
+ security: 'Security',
227
228
  setting: 'Settings',
228
229
  start: 'Start',
229
230
  status: 'Status',
@@ -728,7 +729,7 @@ module.exports = {
728
729
  }
729
730
  },
730
731
  domainSecurity: {
731
- title: 'Update Domain Security',
732
+ title: 'Domain Security',
732
733
  cors: {
733
734
  title: 'Allowed CORS Domains',
734
735
  description: 'Domain list that can send cross origin requests to {name}, comma separated, use "*" to allow anyone, which is not recommended',
package/lib/locales/zh.js CHANGED
@@ -230,6 +230,7 @@ module.exports = {
230
230
  scheduleFailed: '加入任务队列失败',
231
231
  scheduleSuccess: '成功加入任务队列',
232
232
  search: '搜索',
233
+ security: '安全',
233
234
  setting: '设置',
234
235
  start: '启动',
235
236
  status: '状态',
@@ -732,7 +733,7 @@ module.exports = {
732
733
  }
733
734
  },
734
735
  domainSecurity: {
735
- title: '更新站点安全设置',
736
+ title: '站点安全设置',
736
737
  cors: {
737
738
  title: 'CORS 域名白名单',
738
739
  description: '此白名单显示的声明可以往 {name} 发送跨域请求的域名, 多个域名用逗号分隔, 可以用 "*" 来允许任何域名(我们不推荐这么做)',
@@ -55,7 +55,10 @@ const isFromExternal = (user, teamIssuerDid) => {
55
55
  if (!list.length) {
56
56
  return false;
57
57
  }
58
- return !list.some(z => z.issuer.id === teamIssuerDid);
58
+ return !list.some(z => {
59
+ var _z$issuer;
60
+ return ((_z$issuer = z.issuer) === null || _z$issuer === void 0 ? void 0 : _z$issuer.id) === teamIssuerDid;
61
+ });
59
62
  };
60
63
  function SimpleInfo(_ref) {
61
64
  let {
@@ -181,6 +184,9 @@ function MemberList(_ref2) {
181
184
  (res.users || []).forEach(x => {
182
185
  x.isFromExternal = isFromExternal(x, teamIssuerDid);
183
186
  x.avatar = (0, _util2.parseAvatar)(x.avatar, teamDid, inService);
187
+
188
+ // for backwards compatibility
189
+ x.passports = (x.passports || []).filter(y => y.issuer);
184
190
  });
185
191
  setUsers(res.users || []);
186
192
  setRowCount(res.paging.total);
@@ -78,6 +78,9 @@ function Member(_ref) {
78
78
  });
79
79
  if (res.getUser.user) {
80
80
  res.getUser.user.avatar = (0, _util2.parseAvatar)(res.getUser.user.avatar, teamDid, inService);
81
+
82
+ // for backwards compatibility
83
+ res.getUser.user.passports = (res.getUser.user.passports || []).filter(x => x.issuer);
81
84
  }
82
85
  setUser(res.getUser.user || {});
83
86
  setIssuances(res.getPassportIssuances.list || []);
package/lib/util/index.js CHANGED
@@ -22,7 +22,11 @@ exports.getAsset = getAsset;
22
22
  exports.getAssetExpiration = getAssetExpiration;
23
23
  exports.getBlockletLogoUrl = void 0;
24
24
  exports.getBlockletMetaUrl = getBlockletMetaUrl;
25
- exports.getEndPoint = exports.getBlockletUrlParams = exports.getBlockletServices = void 0;
25
+ exports.getBlockletServices = void 0;
26
+ exports.getBlockletUrl = getBlockletUrl;
27
+ exports.getBlockletUrlParams = void 0;
28
+ exports.getBlockletUrls = getBlockletUrls;
29
+ exports.getEndPoint = void 0;
26
30
  exports.getExplorerLink = getExplorerLink;
27
31
  exports.getPathPrefix = exports.getIssuePassportLink = exports.getInviteLink = void 0;
28
32
  exports.getRelativeTime = getRelativeTime;
@@ -35,7 +39,7 @@ exports.parseQuery = void 0;
35
39
  exports.patchJsxToLocale = patchJsxToLocale;
36
40
  exports.shouldCheckDomainStatus = void 0;
37
41
  exports.sleep = sleep;
38
- exports.validateDomain = exports.stringSortHandlerAsc = void 0;
42
+ exports.validateDomain = exports.toSlotDomain = exports.stringSortHandlerAsc = void 0;
39
43
  var _constant = require("@abtnode/constant");
40
44
  var _dayjs = _interopRequireDefault(require("dayjs"));
41
45
  require("moment/locale/zh-cn");
@@ -113,6 +117,53 @@ function getAccessUrl(hostname) {
113
117
  });
114
118
  return "".concat(url, "?").concat(searchParams.toString());
115
119
  }
120
+ function getBlockletUrl() {
121
+ let {
122
+ blocklet,
123
+ domain: inputDomain,
124
+ mountPoint: inputMountPoint,
125
+ params
126
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
127
+ const {
128
+ site
129
+ } = blocklet;
130
+ if (!site) {
131
+ return null;
132
+ }
133
+ const domain = inputDomain || (site.domainAliases || [])[0];
134
+ if (!domain) {
135
+ return null;
136
+ }
137
+ let mountPoint = inputMountPoint;
138
+ if (!mountPoint) {
139
+ const rule = site.rules.filter(x => !x.from.pathPrefix.startsWith(_constant.WELLKNOWN_PATH_PREFIX))[0];
140
+ mountPoint = rule ? rule.from.pathPrefix : '/';
141
+ }
142
+ return getAccessUrl(domain.value, mountPoint, params);
143
+ }
144
+ function getBlockletUrls() {
145
+ let {
146
+ blocklet,
147
+ mountPoint: inputMountPoint,
148
+ params
149
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
150
+ const {
151
+ site
152
+ } = blocklet;
153
+ if (!site) {
154
+ return [];
155
+ }
156
+ const domains = site.domainAliases || [];
157
+ if (!domains.length) {
158
+ return [];
159
+ }
160
+ let mountPoint = inputMountPoint;
161
+ if (!mountPoint) {
162
+ const rule = site.rules.filter(x => !x.from.pathPrefix.startsWith(_constant.WELLKNOWN_PATH_PREFIX))[0];
163
+ mountPoint = rule ? rule.name : '/';
164
+ }
165
+ return domains.map(domain => getAccessUrl(domain.value, mountPoint, params));
166
+ }
116
167
  function getExplorerLink(chainHost, did, type) {
117
168
  if (!chainHost) return undefined;
118
169
  try {
@@ -279,6 +330,9 @@ const formatPerson = person => {
279
330
  exports.formatPerson = formatPerson;
280
331
  const getBlockletServices = blocklet => {
281
332
  const services = [];
333
+ if (!blocklet) {
334
+ return services;
335
+ }
282
336
  const interfaces = (blocklet.meta.interfaces || []).filter(x => x.type === _constant2.BLOCKLET_INTERFACE_TYPE_SERVICE);
283
337
  interfaces.forEach(x => {
284
338
  services.push({
@@ -468,8 +522,8 @@ const isCertificateMatch = function isCertificateMatch() {
468
522
  let matchedSites = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
469
523
  try {
470
524
  return matchedSites.map(item => item.domain).some(domain => {
471
- return blockletUrls.some(blockletUrl => {
472
- const url = new window.URL(blockletUrl);
525
+ return blockletUrls.some(u => {
526
+ const url = new window.URL(u.startsWith('http') ? u : "http://".concat(u));
473
527
  return url.hostname === domain;
474
528
  });
475
529
  });
@@ -611,4 +665,15 @@ exports.isBlockletDev = isBlockletDev;
611
665
  const APP_PREFIX = ((_window$env = window.env) === null || _window$env === void 0 ? void 0 : _window$env.groupPathPrefix) || '/';
612
666
  exports.APP_PREFIX = APP_PREFIX;
613
667
  const BlockletAdminRoles = [_constant.ROLES.ADMIN, _constant.ROLES.OWNER];
614
- exports.BlockletAdminRoles = BlockletAdminRoles;
668
+ exports.BlockletAdminRoles = BlockletAdminRoles;
669
+ const toSlotDomain = domain => {
670
+ if (domain.endsWith(_constant.DEFAULT_IP_DOMAIN_SUFFIX)) {
671
+ const subDomain = domain.split('.').shift();
672
+ const matches = subDomain.match(_constant.IP);
673
+ if (matches) {
674
+ return domain.replace(matches[0].slice(1), _constant.SLOT_FOR_IP_DNS_SITE);
675
+ }
676
+ }
677
+ return domain;
678
+ };
679
+ exports.toSlotDomain = toSlotDomain;