@abtnode/ux 1.16.7 → 1.16.8-beta-0c0c5eb2
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/blocklet/component/add.js +1 -17
- package/lib/blocklet/component/environment.js +8 -4
- package/lib/blocklet/component/setting.js +3 -31
- package/lib/blocklet/router/action/add-domain-alias.js +2 -1
- package/lib/blocklet/router/action/delete-domain-alias.js +0 -3
- package/lib/blocklet/router/domain-actions.js +25 -18
- package/lib/blocklet/storage/add.js +156 -0
- package/lib/blocklet/storage/connect.js +226 -0
- package/lib/blocklet/storage/delete.js +106 -0
- package/lib/blocklet/storage/index.js +434 -0
- package/lib/blocklet/storage/item.js +122 -0
- package/lib/blocklet/storage/switch-did-spaces.js +317 -0
- package/lib/confirm.js +8 -5
- package/lib/form/form-text-input.js +20 -2
- package/lib/locales/en.js +55 -7
- package/lib/locales/zh.js +56 -9
- package/lib/util/spaces.js +73 -0
- package/package.json +7 -7
- package/lib/blocklet/storage.js +0 -180
|
@@ -550,7 +550,7 @@ function AddComponent(_ref2) {
|
|
|
550
550
|
if (config) {
|
|
551
551
|
doc = _objectSpread(_objectSpread({}, doc), {}, {
|
|
552
552
|
pathPrefix: config.mountPoint,
|
|
553
|
-
title:
|
|
553
|
+
title: title || '',
|
|
554
554
|
componentName: config.meta.name,
|
|
555
555
|
// use history's environments
|
|
556
556
|
hasEnvironmentsStep: false
|
|
@@ -824,22 +824,6 @@ function AddComponent(_ref2) {
|
|
|
824
824
|
value: (0, _util2.formatMountPoint)(pathPrefix)
|
|
825
825
|
}));
|
|
826
826
|
}
|
|
827
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextField.default, {
|
|
828
|
-
label: t('common.title'),
|
|
829
|
-
autoComplete: "off",
|
|
830
|
-
variant: "outlined",
|
|
831
|
-
fullWidth: true,
|
|
832
|
-
style: {
|
|
833
|
-
marginBottom: 32
|
|
834
|
-
},
|
|
835
|
-
margin: "normal",
|
|
836
|
-
value: params.title,
|
|
837
|
-
onChange: e => {
|
|
838
|
-
const title = e.target.value;
|
|
839
|
-
setParams(_objectSpread(_objectSpread({}, params), {}, {
|
|
840
|
-
title
|
|
841
|
-
}));
|
|
842
|
-
}
|
|
843
827
|
}), !!error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Alert.default, {
|
|
844
828
|
type: "error",
|
|
845
829
|
style: {
|
|
@@ -35,7 +35,11 @@ const getDescription = (data, t) => {
|
|
|
35
35
|
description
|
|
36
36
|
} = data;
|
|
37
37
|
if (Object.values(_constant.CHAIN_PROP_MAP).includes(data.key)) {
|
|
38
|
-
|
|
38
|
+
if (description) {
|
|
39
|
+
description = "".concat(description, " (").concat(t('blocklet.config.sharedToAllComponents'), ")");
|
|
40
|
+
} else {
|
|
41
|
+
description = t('blocklet.config.sharedToAllComponents');
|
|
42
|
+
}
|
|
39
43
|
}
|
|
40
44
|
return description && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
41
45
|
style: {
|
|
@@ -205,12 +209,12 @@ function ComponentEnvironment(_ref) {
|
|
|
205
209
|
initialEditValue: 'Value',
|
|
206
210
|
width: 'calc((100% - (96px + 30%)) / 1)',
|
|
207
211
|
render: d => {
|
|
208
|
-
if (d.secure) {
|
|
209
|
-
return '******';
|
|
210
|
-
}
|
|
211
212
|
if (!d.value) {
|
|
212
213
|
return null;
|
|
213
214
|
}
|
|
215
|
+
if (d.secure) {
|
|
216
|
+
return '******';
|
|
217
|
+
}
|
|
214
218
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_clickToCopy.default, {
|
|
215
219
|
unstyled: true,
|
|
216
220
|
value: d.value,
|
|
@@ -51,24 +51,6 @@ function ComponentSetting(_ref) {
|
|
|
51
51
|
if (blocklet.status === 'unknown' && (0, _util.isInstalling)(blocklet.status)) {
|
|
52
52
|
return null;
|
|
53
53
|
}
|
|
54
|
-
const onSubmitTitle = async value => {
|
|
55
|
-
setLoading(true);
|
|
56
|
-
try {
|
|
57
|
-
setLoading(false);
|
|
58
|
-
await api.updateComponentTitle({
|
|
59
|
-
input: {
|
|
60
|
-
rootDid,
|
|
61
|
-
did: blocklet.meta.did,
|
|
62
|
-
title: value
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
} catch (err) {
|
|
66
|
-
setLoading(false);
|
|
67
|
-
err.message = (0, _util.formatError)(err);
|
|
68
|
-
_toast.default.error(err.message);
|
|
69
|
-
throw err;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
54
|
const onSubmitMountPoint = async value => {
|
|
73
55
|
setLoading(true);
|
|
74
56
|
try {
|
|
@@ -99,19 +81,9 @@ function ComponentSetting(_ref) {
|
|
|
99
81
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Div, _objectSpread(_objectSpread({
|
|
100
82
|
component: "div"
|
|
101
83
|
}, rest), {}, {
|
|
102
|
-
children: /*#__PURE__*/(0, _jsxRuntime.
|
|
84
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
|
|
103
85
|
mt: 3,
|
|
104
|
-
children:
|
|
105
|
-
label: t('common.title'),
|
|
106
|
-
style: {
|
|
107
|
-
marginTop: -24
|
|
108
|
-
},
|
|
109
|
-
disabled: loading || disabled,
|
|
110
|
-
loading: loading,
|
|
111
|
-
required: true,
|
|
112
|
-
initialValue: blocklet.meta.title,
|
|
113
|
-
onSubmit: onSubmitTitle
|
|
114
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_formTextInput.default, {
|
|
86
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_formTextInput.default, {
|
|
115
87
|
label: t('blocklet.component.mountPoint'),
|
|
116
88
|
style: {
|
|
117
89
|
marginTop: -24
|
|
@@ -124,7 +96,7 @@ function ComponentSetting(_ref) {
|
|
|
124
96
|
onChange: handleMountPointChange,
|
|
125
97
|
helperText: mountPointHelperText,
|
|
126
98
|
formatterBeforeSubmit: value => (0, _urlPathFriendly.default)(value)
|
|
127
|
-
})
|
|
99
|
+
})
|
|
128
100
|
})
|
|
129
101
|
}));
|
|
130
102
|
}
|
|
@@ -10,6 +10,7 @@ var _ListItemIcon = _interopRequireDefault(require("@mui/material/ListItemIcon")
|
|
|
10
10
|
var _ListItemText = _interopRequireDefault(require("@mui/material/ListItemText"));
|
|
11
11
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
12
12
|
var _Delete = _interopRequireDefault(require("@mui/icons-material/Delete"));
|
|
13
|
+
var _Tooltip = _interopRequireDefault(require("@mui/material/Tooltip"));
|
|
13
14
|
var _actions = _interopRequireDefault(require("../../actions"));
|
|
14
15
|
var _deleteDomainAlias = _interopRequireDefault(require("./action/delete-domain-alias"));
|
|
15
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
@@ -23,6 +24,7 @@ function DomainActions(_ref) {
|
|
|
23
24
|
const {
|
|
24
25
|
t
|
|
25
26
|
} = (0, _context.useLocaleContext)();
|
|
27
|
+
const isCurrentDomain = domain.value === window.location.hostname;
|
|
26
28
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_actions.default, {
|
|
27
29
|
"data-cy": "domain-actions",
|
|
28
30
|
actions: [
|
|
@@ -40,24 +42,29 @@ function DomainActions(_ref) {
|
|
|
40
42
|
let {
|
|
41
43
|
open
|
|
42
44
|
} = _ref3;
|
|
43
|
-
return /*#__PURE__*/(0, _jsxRuntime.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
45
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
|
|
46
|
+
title: isCurrentDomain ? t('blocklet.router.currentDomainTip') : '',
|
|
47
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
48
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_MenuItem.default, {
|
|
49
|
+
disabled: domain.isProtected || isCurrentDomain,
|
|
50
|
+
dense: true,
|
|
51
|
+
onClick: e => {
|
|
52
|
+
close();
|
|
53
|
+
open(e);
|
|
54
|
+
},
|
|
55
|
+
"data-cy": "action-toggle-block",
|
|
56
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItemIcon.default, {
|
|
57
|
+
style: {
|
|
58
|
+
minWidth: 24,
|
|
59
|
+
marginRight: 8
|
|
60
|
+
},
|
|
61
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Delete.default, {})
|
|
62
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItemText.default, {
|
|
63
|
+
primary: t('common.delete')
|
|
64
|
+
})]
|
|
65
|
+
}, "remove")
|
|
66
|
+
})
|
|
67
|
+
});
|
|
61
68
|
}
|
|
62
69
|
});
|
|
63
70
|
}]
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
|
|
8
|
+
var _Dialog = _interopRequireDefault(require("@arcblock/ux/lib/Dialog"));
|
|
9
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
10
|
+
var _material = require("@mui/material");
|
|
11
|
+
var _react = require("react");
|
|
12
|
+
var _DialogContentText = _interopRequireDefault(require("@mui/material/DialogContentText"));
|
|
13
|
+
var _Alert = _interopRequireDefault(require("@arcblock/ux/lib/Alert"));
|
|
14
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
+
var _util = require("../../util");
|
|
16
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
+
const _excluded = ["onAdd"];
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {{
|
|
20
|
+
* name: string,
|
|
21
|
+
* url: string,
|
|
22
|
+
* protected?: boolean,
|
|
23
|
+
* }} SpaceGateway
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
*
|
|
28
|
+
* @export
|
|
29
|
+
* @param {{
|
|
30
|
+
* onAdd: (url: string) => Promise<void> | void,
|
|
31
|
+
* }} { onAdd, spaceGateways, ...rest }
|
|
32
|
+
* @return {*}
|
|
33
|
+
*/
|
|
34
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
|
+
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; }
|
|
36
|
+
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; }
|
|
37
|
+
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; }
|
|
38
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
39
|
+
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); }
|
|
40
|
+
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; }
|
|
41
|
+
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; }
|
|
42
|
+
function AddDIDSpacesGateWay(_ref) {
|
|
43
|
+
let {
|
|
44
|
+
onAdd
|
|
45
|
+
} = _ref,
|
|
46
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
47
|
+
const {
|
|
48
|
+
t,
|
|
49
|
+
locale
|
|
50
|
+
} = (0, _context.useLocaleContext)();
|
|
51
|
+
const [url, setUrl] = (0, _react.useState)('');
|
|
52
|
+
const [loading, setLoading] = (0, _react.useState)(false);
|
|
53
|
+
const [open, setOpen] = (0, _react.useState)(false);
|
|
54
|
+
const [errorMessage, setErrorMessage] = (0, _react.useState)('');
|
|
55
|
+
const onConfirm = async () => {
|
|
56
|
+
try {
|
|
57
|
+
setLoading(true);
|
|
58
|
+
await onAdd(url);
|
|
59
|
+
setOpen(false);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
const _errorMessage = "".concat(t('storage.spaces.gateway.add.failed', locale), ": ").concat((0, _util.formatError)(err));
|
|
62
|
+
setErrorMessage(_errorMessage);
|
|
63
|
+
} finally {
|
|
64
|
+
setLoading(false);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
68
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, _objectSpread(_objectSpread({
|
|
69
|
+
size: "small",
|
|
70
|
+
color: "primary",
|
|
71
|
+
variant: "outlined",
|
|
72
|
+
onClick: () => setOpen(true)
|
|
73
|
+
}, rest), {}, {
|
|
74
|
+
children: t('storage.spaces.gateway.add.title')
|
|
75
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Dialog.default, {
|
|
76
|
+
title: t('storage.spaces.gateway.add.title'),
|
|
77
|
+
fullWidth: true,
|
|
78
|
+
maxWidth: "md",
|
|
79
|
+
open: open,
|
|
80
|
+
onClose: () => setOpen(false),
|
|
81
|
+
PaperProps: {
|
|
82
|
+
style: {
|
|
83
|
+
minHeight: 'auto'
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
actions: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
87
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
|
|
88
|
+
onClick: e => {
|
|
89
|
+
e.stopPropagation();
|
|
90
|
+
setOpen(false);
|
|
91
|
+
},
|
|
92
|
+
color: "inherit",
|
|
93
|
+
children: t('common.cancel')
|
|
94
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Button.default, {
|
|
95
|
+
onClick: e => {
|
|
96
|
+
e.stopPropagation();
|
|
97
|
+
onConfirm();
|
|
98
|
+
},
|
|
99
|
+
color: "primary",
|
|
100
|
+
"data-cy": "install-blocklet-next-step",
|
|
101
|
+
disabled: loading || !url,
|
|
102
|
+
variant: "contained",
|
|
103
|
+
autoFocus: true,
|
|
104
|
+
children: [loading && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.CircularProgress, {
|
|
105
|
+
size: 16
|
|
106
|
+
}), t('common.confirm')]
|
|
107
|
+
})]
|
|
108
|
+
}),
|
|
109
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
110
|
+
style: {
|
|
111
|
+
paddingTop: 12,
|
|
112
|
+
overflowY: 'hidden'
|
|
113
|
+
},
|
|
114
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_DialogContentText.default, {
|
|
115
|
+
component: "div",
|
|
116
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
117
|
+
component: "div",
|
|
118
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.TextField, {
|
|
119
|
+
label: t('storage.spaces.gateway.add.label'),
|
|
120
|
+
autoComplete: "off",
|
|
121
|
+
variant: "outlined",
|
|
122
|
+
name: "url",
|
|
123
|
+
fullWidth: true,
|
|
124
|
+
value: url,
|
|
125
|
+
onChange: e => {
|
|
126
|
+
setErrorMessage(null);
|
|
127
|
+
setUrl(e.target.value);
|
|
128
|
+
},
|
|
129
|
+
disabled: loading,
|
|
130
|
+
onKeyPress: async e => {
|
|
131
|
+
if (e.key === 'Enter') {
|
|
132
|
+
e.preventDefault();
|
|
133
|
+
await onConfirm();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
}), !!errorMessage && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Alert.default, {
|
|
140
|
+
type: "error",
|
|
141
|
+
style: {
|
|
142
|
+
width: '100%'
|
|
143
|
+
},
|
|
144
|
+
children: errorMessage
|
|
145
|
+
})]
|
|
146
|
+
})]
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
AddDIDSpacesGateWay.propTypes = {
|
|
150
|
+
onAdd: _propTypes.default.func
|
|
151
|
+
};
|
|
152
|
+
AddDIDSpacesGateWay.defaultProps = {
|
|
153
|
+
onAdd: async () => undefined
|
|
154
|
+
};
|
|
155
|
+
var _default = AddDIDSpacesGateWay;
|
|
156
|
+
exports.default = _default;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
|
|
10
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
11
|
+
var _Connect = _interopRequireDefault(require("@arcblock/did-connect/lib/Connect"));
|
|
12
|
+
var _material = require("@mui/material");
|
|
13
|
+
var _lodash = require("lodash");
|
|
14
|
+
var _urlJoin = _interopRequireDefault(require("url-join"));
|
|
15
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
16
|
+
var _util = require("@blocklet/meta/lib/util");
|
|
17
|
+
var _toast = _interopRequireDefault(require("../../toast"));
|
|
18
|
+
var _node = require("../../contexts/node");
|
|
19
|
+
var _blocklet = require("../../../lib/contexts/blocklet");
|
|
20
|
+
var _spaces = require("../../util/spaces");
|
|
21
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
24
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
+
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; }
|
|
26
|
+
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; }
|
|
27
|
+
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; }
|
|
28
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
29
|
+
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); } /**
|
|
30
|
+
* @typedef {{
|
|
31
|
+
* name: string,
|
|
32
|
+
* url: string,
|
|
33
|
+
* protected?: boolean,
|
|
34
|
+
* endpoint?: string,
|
|
35
|
+
* }} SpaceGateway
|
|
36
|
+
*/ /**
|
|
37
|
+
*
|
|
38
|
+
*
|
|
39
|
+
* @param {import('@abtnode/client').BlockletState} blocklet
|
|
40
|
+
* @return {*}
|
|
41
|
+
*/
|
|
42
|
+
function useBlockletInfo(blocklet) {
|
|
43
|
+
var _blocklet$site, _blocklet$site$domain, _blocklet$site$domain2;
|
|
44
|
+
const {
|
|
45
|
+
appDid
|
|
46
|
+
} = blocklet;
|
|
47
|
+
const appName = (0, _util.getAppName)(blocklet);
|
|
48
|
+
const appDescription = (0, _util.getAppDescription)(blocklet);
|
|
49
|
+
const appUrls = blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$site = blocklet.site) === null || _blocklet$site === void 0 ? void 0 : (_blocklet$site$domain = _blocklet$site.domainAliases) === null || _blocklet$site$domain === void 0 ? void 0 : (_blocklet$site$domain2 = _blocklet$site$domain.sort((a, b) => {
|
|
50
|
+
if (a.accessibility.accessible && b.accessibility.accessible) {
|
|
51
|
+
return +a.isProtected - +b.isProtected;
|
|
52
|
+
}
|
|
53
|
+
return +b.accessibility.accessible - +a.accessibility.accessible;
|
|
54
|
+
})) === null || _blocklet$site$domain2 === void 0 ? void 0 : _blocklet$site$domain2.map(domainAlias => {
|
|
55
|
+
var _domainAlias$domainSt;
|
|
56
|
+
const protocol = domainAlias !== null && domainAlias !== void 0 && (_domainAlias$domainSt = domainAlias.domainStatus) !== null && _domainAlias$domainSt !== void 0 && _domainAlias$domainSt.isHttps ? 'https://' : 'http://';
|
|
57
|
+
const value = domainAlias === null || domainAlias === void 0 ? void 0 : domainAlias.value;
|
|
58
|
+
return "".concat(protocol).concat(value);
|
|
59
|
+
}).filter(Boolean);
|
|
60
|
+
const appUrl = appUrls === null || appUrls === void 0 ? void 0 : appUrls[0];
|
|
61
|
+
const scopes = 'list:object read:object write:object';
|
|
62
|
+
const referrer = window.location.href;
|
|
63
|
+
|
|
64
|
+
// 授权的时候提供 appUrl, 因为 appUrl 可能很久都拿不到值,所以加一个 isReady 来表示就绪状态
|
|
65
|
+
return {
|
|
66
|
+
appDid,
|
|
67
|
+
appName,
|
|
68
|
+
appDescription,
|
|
69
|
+
appUrl,
|
|
70
|
+
scopes,
|
|
71
|
+
referrer,
|
|
72
|
+
isReady: Boolean(appUrl)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
*
|
|
79
|
+
* @export
|
|
80
|
+
* @param {{
|
|
81
|
+
* spaceGateway: SpaceGateway,
|
|
82
|
+
* onConnect: (spaceGateway: SpaceGateway, endpoint: string) => void | Promise<void>
|
|
83
|
+
* }} { spaceGateway, onConnect }
|
|
84
|
+
* @return {React.Component}
|
|
85
|
+
*/
|
|
86
|
+
function ConnectDIDSpaces(_ref) {
|
|
87
|
+
let {
|
|
88
|
+
spaceGateway,
|
|
89
|
+
onConnect
|
|
90
|
+
} = _ref;
|
|
91
|
+
const {
|
|
92
|
+
t,
|
|
93
|
+
locale
|
|
94
|
+
} = (0, _context.useLocaleContext)();
|
|
95
|
+
const {
|
|
96
|
+
info
|
|
97
|
+
} = (0, _node.useNodeContext)();
|
|
98
|
+
const nodeDid = info.did;
|
|
99
|
+
const {
|
|
100
|
+
url
|
|
101
|
+
} = spaceGateway;
|
|
102
|
+
const [loading, setLoading] = (0, _react.useState)(false);
|
|
103
|
+
/** @type {{ blocklet: import('@abtnode/client').BlockletState }} */
|
|
104
|
+
const {
|
|
105
|
+
blocklet,
|
|
106
|
+
actions: {
|
|
107
|
+
refreshBlocklet
|
|
108
|
+
}
|
|
109
|
+
} = (0, _blocklet.useBlockletContext)();
|
|
110
|
+
const {
|
|
111
|
+
appDid,
|
|
112
|
+
appName,
|
|
113
|
+
appDescription,
|
|
114
|
+
appUrl,
|
|
115
|
+
scopes,
|
|
116
|
+
referrer,
|
|
117
|
+
isReady
|
|
118
|
+
} = useBlockletInfo(blocklet);
|
|
119
|
+
const [authorizeConnect, setAuthorizeConnect] = (0, _react.useState)({
|
|
120
|
+
open: false,
|
|
121
|
+
action: 'one-click-authorization',
|
|
122
|
+
checkTimeout: 1000 * 300,
|
|
123
|
+
messages: {
|
|
124
|
+
title: t('storage.spaces.authorize.title', {
|
|
125
|
+
appName
|
|
126
|
+
}, locale),
|
|
127
|
+
scan: t('storage.spaces.authorize.scan', {
|
|
128
|
+
appName
|
|
129
|
+
}, locale),
|
|
130
|
+
confirm: '',
|
|
131
|
+
success: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
132
|
+
gutterBottom: true,
|
|
133
|
+
children: t('storage.spaces.authorize.success')
|
|
134
|
+
})
|
|
135
|
+
},
|
|
136
|
+
extraParams: {
|
|
137
|
+
appDid,
|
|
138
|
+
appName,
|
|
139
|
+
appDescription,
|
|
140
|
+
scopes,
|
|
141
|
+
appUrl,
|
|
142
|
+
referrer,
|
|
143
|
+
nodeDid
|
|
144
|
+
},
|
|
145
|
+
onClose: () => {
|
|
146
|
+
// eslint-disable-next-line no-shadow
|
|
147
|
+
setAuthorizeConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
|
|
148
|
+
open: false
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
const onConnectSuccess = async (response, decrypt) => {
|
|
153
|
+
setTimeout(async () => {
|
|
154
|
+
setAuthorizeConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
|
|
155
|
+
open: false
|
|
156
|
+
}));
|
|
157
|
+
const endpoint = decrypt(response.endpoint);
|
|
158
|
+
await onConnect(spaceGateway, endpoint);
|
|
159
|
+
refreshBlocklet();
|
|
160
|
+
}, 3000);
|
|
161
|
+
};
|
|
162
|
+
const handleOnClick = async () => {
|
|
163
|
+
try {
|
|
164
|
+
setLoading(true);
|
|
165
|
+
if ((0, _lodash.isEmpty)(url)) {
|
|
166
|
+
_toast.default.error(t('storage.spaces.addressCannotEmpty', locale));
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// 我们已经有 endpoint && 权限还在 的话,就无需 connect 了
|
|
171
|
+
if (await (0, _spaces.hasPermissionByEndpoint)(spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.endpoint)) {
|
|
172
|
+
await onConnect(spaceGateway, spaceGateway.endpoint);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
setAuthorizeConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
|
|
176
|
+
open: true,
|
|
177
|
+
prefix: (0, _urlJoin.default)(url, 'space/api/did'),
|
|
178
|
+
baseUrl: new URL(url).origin,
|
|
179
|
+
checkFn: _axios.default.create({
|
|
180
|
+
baseURL: (0, _urlJoin.default)(url, 'space')
|
|
181
|
+
}).get
|
|
182
|
+
}));
|
|
183
|
+
} finally {
|
|
184
|
+
setLoading(false);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
188
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
|
|
189
|
+
size: "small",
|
|
190
|
+
loading: !isReady || loading,
|
|
191
|
+
color: "secondary",
|
|
192
|
+
variant: "contained",
|
|
193
|
+
onClick: handleOnClick,
|
|
194
|
+
children: t('storage.spaces.gateway.connectTo')
|
|
195
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Connect.default, {
|
|
196
|
+
forceConnected: false,
|
|
197
|
+
saveConnect: false,
|
|
198
|
+
prefix: authorizeConnect.prefix,
|
|
199
|
+
open: authorizeConnect.open,
|
|
200
|
+
popup: true,
|
|
201
|
+
action: authorizeConnect.action,
|
|
202
|
+
baseUrl: authorizeConnect.baseUrl,
|
|
203
|
+
checkFn: authorizeConnect.checkFn,
|
|
204
|
+
onSuccess: onConnectSuccess,
|
|
205
|
+
onClose: authorizeConnect.onClose,
|
|
206
|
+
checkTimeout: authorizeConnect.checkTimeout,
|
|
207
|
+
extraParams: authorizeConnect.extraParams,
|
|
208
|
+
messages: authorizeConnect.messages,
|
|
209
|
+
locale: locale
|
|
210
|
+
})]
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
ConnectDIDSpaces.propTypes = {
|
|
214
|
+
spaceGateway: _propTypes.default.shape({
|
|
215
|
+
name: _propTypes.default.string.isRequired,
|
|
216
|
+
url: _propTypes.default.string.isRequired,
|
|
217
|
+
protected: _propTypes.default.bool,
|
|
218
|
+
endpoint: _propTypes.default.string
|
|
219
|
+
}).isRequired,
|
|
220
|
+
onConnect: _propTypes.default.func
|
|
221
|
+
};
|
|
222
|
+
ConnectDIDSpaces.defaultProps = {
|
|
223
|
+
onConnect: async () => undefined
|
|
224
|
+
};
|
|
225
|
+
var _default = ConnectDIDSpaces;
|
|
226
|
+
exports.default = _default;
|