@abtnode/ux 1.16.11-next-470e8c41 → 1.16.11
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/space-selector.js +1 -1
- package/lib/blocklet/configuration.js +28 -0
- package/lib/blocklet/storage/action.js +10 -6
- package/lib/blocklet/storage/backups.js +36 -46
- package/lib/blocklet/storage/connect-to.js +41 -30
- package/lib/blocklet/storage/connected.js +94 -25
- package/lib/blocklet/storage/item.js +33 -14
- package/lib/form/form-select-input.js +200 -0
- package/lib/form/form-text-input.js +5 -97
- package/lib/form/form-wrapper.js +1 -1
- package/lib/form/input-triggers.js +104 -0
- package/lib/locales/en.js +8 -1
- package/lib/locales/zh.js +3 -1
- package/lib/util/space-gateway.js +58 -0
- package/lib/util/spaces.js +52 -0
- package/package.json +16 -16
|
@@ -157,7 +157,7 @@ function SpaceSelector(_ref) {
|
|
|
157
157
|
width: '100px',
|
|
158
158
|
height: '100%'
|
|
159
159
|
},
|
|
160
|
-
children: endpoint ? t('storage.spaces.reconnect') : t('storage.spaces.
|
|
160
|
+
children: endpoint ? t('storage.spaces.reconnect') : t('storage.spaces.connect.now')
|
|
161
161
|
})
|
|
162
162
|
})
|
|
163
163
|
}));
|
|
@@ -26,6 +26,7 @@ var _constant2 = require("@blocklet/constant");
|
|
|
26
26
|
var _util = require("@blocklet/meta/lib/util");
|
|
27
27
|
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
28
28
|
var _formTextInput = _interopRequireDefault(require("../form/form-text-input"));
|
|
29
|
+
var _formSelectInput = _interopRequireDefault(require("../form/form-select-input"));
|
|
29
30
|
var _node = require("../contexts/node");
|
|
30
31
|
var _util2 = require("../util");
|
|
31
32
|
var _permission = require("../permission");
|
|
@@ -49,6 +50,10 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
|
|
|
49
50
|
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); }
|
|
50
51
|
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; }
|
|
51
52
|
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; }
|
|
53
|
+
const languages = Object.keys(_constant2.SUPPORTED_LANGUAGES).map(x => ({
|
|
54
|
+
code: x,
|
|
55
|
+
name: _constant2.SUPPORTED_LANGUAGES[x].nativeName
|
|
56
|
+
}));
|
|
52
57
|
function BlockletEnvironment(_ref) {
|
|
53
58
|
var _blocklet$settings;
|
|
54
59
|
let {
|
|
@@ -94,6 +99,7 @@ function BlockletEnvironment(_ref) {
|
|
|
94
99
|
// configurable blocklet environment
|
|
95
100
|
const customDelete = blocklet.environments.find(x => x.key === 'BLOCKLET_DELETABLE');
|
|
96
101
|
const deletable = !customDelete || customDelete.value === 'yes';
|
|
102
|
+
const customLanguages = blocklet.environments.find(x => x.key === 'BLOCKLET_APP_LANGUAGES');
|
|
97
103
|
const customUrl = blocklet.environments.find(x => x.key === 'BLOCKLET_APP_URL');
|
|
98
104
|
const customLogoSquare = blocklet.environments.find(x => x.key === 'BLOCKLET_APP_LOGO_SQUARE');
|
|
99
105
|
const customLogoRect = blocklet.environments.find(x => x.key === 'BLOCKLET_APP_LOGO_RECT');
|
|
@@ -322,6 +328,28 @@ function BlockletEnvironment(_ref) {
|
|
|
322
328
|
className: "config-form",
|
|
323
329
|
component: _Divider.default,
|
|
324
330
|
my: 3
|
|
331
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
|
|
332
|
+
className: "config-form",
|
|
333
|
+
mt: 2,
|
|
334
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
|
|
335
|
+
className: "config-label",
|
|
336
|
+
fontSize: 14,
|
|
337
|
+
mb: 0,
|
|
338
|
+
children: t('blocklet.config.languages')
|
|
339
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_formSelectInput.default, {
|
|
340
|
+
style: {
|
|
341
|
+
marginTop: 0
|
|
342
|
+
},
|
|
343
|
+
disabled: loading || disabled,
|
|
344
|
+
loading: loading,
|
|
345
|
+
options: languages,
|
|
346
|
+
initialValue: customLanguages ? customLanguages.value.split(',') : ['en'],
|
|
347
|
+
onSubmit: value => onSubmitConfig('BLOCKLET_APP_LANGUAGES', value)
|
|
348
|
+
})]
|
|
349
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
|
|
350
|
+
className: "config-form",
|
|
351
|
+
component: _Divider.default,
|
|
352
|
+
my: 3
|
|
325
353
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
|
|
326
354
|
className: "config-form",
|
|
327
355
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
|
|
@@ -11,17 +11,18 @@ var _context = require("@arcblock/ux/lib/Locale/context");
|
|
|
11
11
|
var _ArrowOutward = _interopRequireDefault(require("@mui/icons-material/ArrowOutward"));
|
|
12
12
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
13
|
var _ElectricBoltOutlined = _interopRequireDefault(require("@mui/icons-material/ElectricBoltOutlined"));
|
|
14
|
-
var
|
|
14
|
+
var _FolderOutlined = _interopRequireDefault(require("@mui/icons-material/FolderOutlined"));
|
|
15
15
|
var _spaces = require("../../util/spaces");
|
|
16
16
|
var _delete = _interopRequireDefault(require("./delete"));
|
|
17
17
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _excluded = ["spaceGateway", "connected", "onDelete", "onConnect"];
|
|
18
|
+
const _excluded = ["spaceGateway", "connected", "onDelete", "onConnect", "enableSwitchToSpace"];
|
|
19
19
|
/**
|
|
20
20
|
* @description
|
|
21
21
|
* @param {{
|
|
22
22
|
* spaceGateway: import('./connected').SpaceGateway,
|
|
23
23
|
* onDelete: (import('./connected').SpaceGateway) => Promise<void>,
|
|
24
24
|
* onDelete: (import('./connected').SpaceGateway) => Promise<void>,
|
|
25
|
+
* enableSwitchToSpace: boolean,
|
|
25
26
|
* connected: boolean
|
|
26
27
|
* }} { spaceGateway, onDelete, ...rest }
|
|
27
28
|
* @return {*}
|
|
@@ -41,7 +42,8 @@ function SpaceItemAction(_ref) {
|
|
|
41
42
|
spaceGateway,
|
|
42
43
|
connected,
|
|
43
44
|
onDelete,
|
|
44
|
-
onConnect
|
|
45
|
+
onConnect,
|
|
46
|
+
enableSwitchToSpace
|
|
45
47
|
} = _ref,
|
|
46
48
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
47
49
|
const [anchorEl, setAnchorEl] = (0, _react.useState)(null);
|
|
@@ -102,13 +104,13 @@ function SpaceItemAction(_ref) {
|
|
|
102
104
|
style: {
|
|
103
105
|
minWidth: 24
|
|
104
106
|
},
|
|
105
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
107
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_FolderOutlined.default, {
|
|
106
108
|
fontSize: "small"
|
|
107
109
|
})
|
|
108
110
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ListItemText, {
|
|
109
111
|
children: t('storage.spaces.strategy.viewBackupFiles')
|
|
110
112
|
})]
|
|
111
|
-
}), !connected && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
|
113
|
+
}), !connected && enableSwitchToSpace && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
|
112
114
|
onClick: handleOnConnect,
|
|
113
115
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ListItemIcon, {
|
|
114
116
|
style: {
|
|
@@ -135,12 +137,14 @@ SpaceItemAction.propTypes = {
|
|
|
135
137
|
endpoint: _propTypes.default.string.isRequired
|
|
136
138
|
}).isRequired,
|
|
137
139
|
connected: _propTypes.default.bool.isRequired,
|
|
140
|
+
enableSwitchToSpace: _propTypes.default.bool,
|
|
138
141
|
onDelete: _propTypes.default.func,
|
|
139
142
|
onConnect: _propTypes.default.func
|
|
140
143
|
};
|
|
141
144
|
SpaceItemAction.defaultProps = {
|
|
142
145
|
onDelete: () => {},
|
|
143
|
-
onConnect: () => {}
|
|
146
|
+
onConnect: () => {},
|
|
147
|
+
enableSwitchToSpace: true
|
|
144
148
|
};
|
|
145
149
|
var _default = SpaceItemAction;
|
|
146
150
|
exports.default = _default;
|
|
@@ -17,7 +17,7 @@ var _propTypes = require("prop-types");
|
|
|
17
17
|
var _node = require("../../contexts/node");
|
|
18
18
|
var _blocklet = require("../../../lib/contexts/blocklet");
|
|
19
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
|
-
const _excluded = ["progress"];
|
|
20
|
+
const _excluded = ["progress", "spaceGateways"];
|
|
21
21
|
/**
|
|
22
22
|
* @description
|
|
23
23
|
* @param {{ blocklet: import('@abtnode/client').BlockletState }} { blocklet }
|
|
@@ -34,6 +34,7 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
34
34
|
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; }
|
|
35
35
|
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; }
|
|
36
36
|
function useBackups(_ref) {
|
|
37
|
+
var _blocklet$meta2;
|
|
37
38
|
let {
|
|
38
39
|
blocklet,
|
|
39
40
|
loading,
|
|
@@ -59,43 +60,26 @@ function useBackups(_ref) {
|
|
|
59
60
|
// eslint-disable-next-line require-await
|
|
60
61
|
(0, _ahooks.useAsyncEffect)(async () => {
|
|
61
62
|
fetchBackups();
|
|
62
|
-
}, [blocklet, progress, loading]);
|
|
63
|
+
}, [blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta2 = blocklet.meta) === null || _blocklet$meta2 === void 0 ? void 0 : _blocklet$meta2.did, progress, loading]);
|
|
63
64
|
return {
|
|
64
65
|
backups
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const {
|
|
78
|
-
spaceGateways: _spaceGateways
|
|
79
|
-
} = await api.getBlockletSpaceGateways({
|
|
80
|
-
input: {
|
|
81
|
-
did: blocklet.meta.did
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
setSpaceGateways([{
|
|
85
|
-
name: 'Prod DID Spaces',
|
|
86
|
-
url: 'https://www.didspaces.com/app',
|
|
87
|
-
protected: true
|
|
88
|
-
}, ...(_spaceGateways !== null && _spaceGateways !== void 0 ? _spaceGateways : [])]);
|
|
89
|
-
}, [blocklet]);
|
|
90
|
-
return {
|
|
91
|
-
spaceGateways
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function SpacesBackupRecords(_ref3) {
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @description
|
|
71
|
+
* @param {{
|
|
72
|
+
* progress: any,
|
|
73
|
+
* spaceGateways: Array<import('./connected').SpaceGateway>
|
|
74
|
+
* }} { progress, spaceGateways, ...rest }
|
|
75
|
+
* @return {*}
|
|
76
|
+
*/
|
|
77
|
+
function SpacesBackupRecords(_ref2) {
|
|
95
78
|
let {
|
|
96
|
-
progress
|
|
97
|
-
|
|
98
|
-
|
|
79
|
+
progress,
|
|
80
|
+
spaceGateways
|
|
81
|
+
} = _ref2,
|
|
82
|
+
rest = _objectWithoutProperties(_ref2, _excluded);
|
|
99
83
|
const {
|
|
100
84
|
t,
|
|
101
85
|
locale
|
|
@@ -109,23 +93,19 @@ function SpacesBackupRecords(_ref3) {
|
|
|
109
93
|
blocklet,
|
|
110
94
|
progress
|
|
111
95
|
});
|
|
112
|
-
const {
|
|
113
|
-
spaceGateways
|
|
114
|
-
} = useSpaceGateways({
|
|
115
|
-
blocklet
|
|
116
|
-
});
|
|
117
96
|
const columns = [{
|
|
118
97
|
label: 'DID Spaces',
|
|
119
98
|
name: 'target',
|
|
120
99
|
options: {
|
|
121
100
|
// eslint-disable-next-line react/no-unstable-nested-components
|
|
122
101
|
customBodyRenderLite: index => {
|
|
123
|
-
var _spaceGateways$find
|
|
102
|
+
var _spaceGateways$find;
|
|
124
103
|
// eslint-disable-next-line no-unused-vars
|
|
125
104
|
const {
|
|
126
|
-
targetUrl
|
|
105
|
+
targetUrl,
|
|
106
|
+
targetName
|
|
127
107
|
} = backups[index];
|
|
128
|
-
const spaceName = (
|
|
108
|
+
const spaceName = ((_spaceGateways$find = spaceGateways.find(spaceGateway => targetUrl === null || targetUrl === void 0 ? void 0 : targetUrl.includes(spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.url))) === null || _spaceGateways$find === void 0 ? void 0 : _spaceGateways$find.name) || targetName || 'DID Space';
|
|
129
109
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Link, {
|
|
130
110
|
fontSize: "16px",
|
|
131
111
|
href: targetUrl,
|
|
@@ -209,11 +189,16 @@ function SpacesBackupRecords(_ref3) {
|
|
|
209
189
|
}), " \xA0", /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Tooltip, {
|
|
210
190
|
style: {
|
|
211
191
|
display: 'flex',
|
|
212
|
-
alignItems: 'center'
|
|
192
|
+
alignItems: 'center',
|
|
193
|
+
flexShrink: 0
|
|
213
194
|
},
|
|
214
195
|
title: message,
|
|
215
196
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Icon, {
|
|
216
197
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_HelpOutline.default, {
|
|
198
|
+
style: {
|
|
199
|
+
width: '24px',
|
|
200
|
+
height: '24px'
|
|
201
|
+
},
|
|
217
202
|
color: "error"
|
|
218
203
|
})
|
|
219
204
|
})
|
|
@@ -231,12 +216,12 @@ function SpacesBackupRecords(_ref3) {
|
|
|
231
216
|
justifyContent: "space-between"
|
|
232
217
|
}, rest), {}, {
|
|
233
218
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
234
|
-
|
|
235
|
-
|
|
219
|
+
fontSize: "1.2rem",
|
|
220
|
+
fontWeight: "bold",
|
|
236
221
|
children: t('storage.spaces.backup.records')
|
|
237
222
|
})
|
|
238
223
|
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
|
239
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Datatable.default, {
|
|
224
|
+
children: backups !== null && backups !== void 0 && backups.length ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Datatable.default, {
|
|
240
225
|
data: backups,
|
|
241
226
|
columns: columns,
|
|
242
227
|
emptyNode: t('storage.spaces.record.emptyData', locale),
|
|
@@ -245,12 +230,17 @@ function SpacesBackupRecords(_ref3) {
|
|
|
245
230
|
filter: false,
|
|
246
231
|
print: false
|
|
247
232
|
}
|
|
233
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
|
234
|
+
color: "#9397A1",
|
|
235
|
+
marginTop: "24px",
|
|
236
|
+
children: t('storage.spaces.record.emptyData')
|
|
248
237
|
})
|
|
249
238
|
})]
|
|
250
239
|
});
|
|
251
240
|
}
|
|
252
241
|
SpacesBackupRecords.propTypes = {
|
|
253
|
-
progress: _propTypes.object.isRequired
|
|
242
|
+
progress: _propTypes.object.isRequired,
|
|
243
|
+
spaceGateways: _propTypes.array.isRequired
|
|
254
244
|
};
|
|
255
245
|
var _default = SpacesBackupRecords;
|
|
256
246
|
exports.default = _default;
|
|
@@ -11,11 +11,12 @@ var _context = require("@arcblock/ux/lib/Locale/context");
|
|
|
11
11
|
var _Connect = _interopRequireDefault(require("@arcblock/did-connect/lib/Connect"));
|
|
12
12
|
var _urlJoin = _interopRequireDefault(require("url-join"));
|
|
13
13
|
var _isUrl = _interopRequireDefault(require("is-url"));
|
|
14
|
-
var _ahooks = require("ahooks");
|
|
15
14
|
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
16
15
|
var _constant = require("@blocklet/constant");
|
|
17
16
|
var _SplitButton = _interopRequireDefault(require("@arcblock/ux/lib/SplitButton"));
|
|
18
17
|
var _Dialog = _interopRequireDefault(require("@arcblock/ux/lib/Dialog"));
|
|
18
|
+
var _Alert = _interopRequireDefault(require("@arcblock/ux/lib/Alert"));
|
|
19
|
+
var _propTypes = require("prop-types");
|
|
19
20
|
var _blocklet = require("../../../lib/contexts/blocklet");
|
|
20
21
|
var _api = require("../../util/api");
|
|
21
22
|
var _util = require("../../util");
|
|
@@ -23,6 +24,15 @@ var _node = require("../../contexts/node");
|
|
|
23
24
|
var _useBlockletInfoForConnectDidSpaces = _interopRequireDefault(require("../../hooks/use-blocklet-info-for-connect-did-spaces"));
|
|
24
25
|
var _spaces = require("../../util/spaces");
|
|
25
26
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
|
+
const _excluded = ["spaceGateways", "refreshSpaceGateways"];
|
|
28
|
+
/**
|
|
29
|
+
* @description
|
|
30
|
+
* @param {{
|
|
31
|
+
* spaceGateways: Array<import('./connected').SpaceGateway>,
|
|
32
|
+
* refreshSpaceGateways: () => void,
|
|
33
|
+
* }} { spaceGateways, refreshSpaceGateways, ...rest }
|
|
34
|
+
* @return {*}
|
|
35
|
+
*/
|
|
26
36
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
37
|
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); }
|
|
28
38
|
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; }
|
|
@@ -31,14 +41,16 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
31
41
|
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; }
|
|
32
42
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
33
43
|
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); }
|
|
34
|
-
function
|
|
44
|
+
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; }
|
|
45
|
+
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; }
|
|
35
46
|
function ConnectTo(_ref) {
|
|
36
|
-
let
|
|
47
|
+
let {
|
|
48
|
+
spaceGateways,
|
|
49
|
+
refreshSpaceGateways
|
|
50
|
+
} = _ref,
|
|
51
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
37
52
|
const {
|
|
38
|
-
blocklet
|
|
39
|
-
actions: {
|
|
40
|
-
refreshBlocklet
|
|
41
|
-
}
|
|
53
|
+
blocklet
|
|
42
54
|
} = (0, _blocklet.useBlockletContext)();
|
|
43
55
|
const {
|
|
44
56
|
info,
|
|
@@ -48,30 +60,18 @@ function ConnectTo(_ref) {
|
|
|
48
60
|
t,
|
|
49
61
|
locale
|
|
50
62
|
} = (0, _context.useLocaleContext)();
|
|
51
|
-
const [spaceGateways, setSpaceGateways] = (0, _react.useState)( /** @type {Array<SpaceGateway>} */
|
|
52
|
-
[]);
|
|
53
63
|
const spaceBackupEndpoint = (0, _react.useMemo)(() => (0, _spaces.getSpaceBackupEndpoint)(blocklet === null || blocklet === void 0 ? void 0 : blocklet.environments), [blocklet]);
|
|
54
64
|
const [url, setUrl] = (0, _react.useState)('');
|
|
55
65
|
const [loading, setLoading] = (0, _react.useState)(false);
|
|
56
66
|
const [open, setOpen] = (0, _react.useState)(false);
|
|
57
67
|
const [errorMessage, setErrorMessage] = (0, _react.useState)('');
|
|
58
|
-
(0, _ahooks.useAsyncEffect)(async () => {
|
|
59
|
-
const {
|
|
60
|
-
spaceGateways: _spaceGateways
|
|
61
|
-
} = await nodeApi.getBlockletSpaceGateways({
|
|
62
|
-
input: {
|
|
63
|
-
did: blocklet.meta.did
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
setSpaceGateways(_spaceGateways !== null && _spaceGateways !== void 0 ? _spaceGateways : []);
|
|
67
|
-
}, [blocklet]);
|
|
68
68
|
const blockletInfo = (0, _useBlockletInfoForConnectDidSpaces.default)({
|
|
69
69
|
blocklet
|
|
70
70
|
});
|
|
71
71
|
const webWalletUrl = (0, _util.getWebWalletUrl)(info);
|
|
72
72
|
const [authorizeFromNftConnect, setAuthorizeFromNftConnect] = (0, _react.useState)({
|
|
73
73
|
open: false,
|
|
74
|
-
action: 'get-did-spaces-
|
|
74
|
+
action: 'get-did-spaces-endpoint',
|
|
75
75
|
checkTimeout: 1000 * 300,
|
|
76
76
|
checkFn: _api.axios.create({
|
|
77
77
|
baseURL: (0, _urlJoin.default)(window.location.origin, (0, _util.getPathPrefix)())
|
|
@@ -130,7 +130,7 @@ function ConnectTo(_ref) {
|
|
|
130
130
|
}));
|
|
131
131
|
const endpoint = decrypt(response.endpoint);
|
|
132
132
|
const space = response.space ? decrypt(response.space) : {};
|
|
133
|
-
await
|
|
133
|
+
await addSpaceGateway(_objectSpread(_objectSpread({
|
|
134
134
|
endpoint
|
|
135
135
|
}, {
|
|
136
136
|
did: (0, _spaces.getDIDSpaceDidFromEndpoint)(endpoint),
|
|
@@ -148,7 +148,7 @@ function ConnectTo(_ref) {
|
|
|
148
148
|
* }} {endpoint, name, did}
|
|
149
149
|
* @returns {Promise<void>}
|
|
150
150
|
*/
|
|
151
|
-
const
|
|
151
|
+
const addSpaceGateway = async _ref2 => {
|
|
152
152
|
var _endpoint$replace, _endpoint$replace$tri, _spaceGateway$name;
|
|
153
153
|
let {
|
|
154
154
|
endpoint,
|
|
@@ -197,7 +197,7 @@ function ConnectTo(_ref) {
|
|
|
197
197
|
_Toast.default.success(t('storage.spaces.connectedWithName', {
|
|
198
198
|
name: (_spaceGateway$name = spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.name) !== null && _spaceGateway$name !== void 0 ? _spaceGateway$name : 'DID Spaces'
|
|
199
199
|
}));
|
|
200
|
-
|
|
200
|
+
refreshSpaceGateways();
|
|
201
201
|
};
|
|
202
202
|
const handleUseWalletConnect = () => {
|
|
203
203
|
setAuthorizeFromNftConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
|
|
@@ -213,15 +213,19 @@ function ConnectTo(_ref) {
|
|
|
213
213
|
}
|
|
214
214
|
}));
|
|
215
215
|
};
|
|
216
|
-
const handleUseSpaceGatewayConnect = () => {
|
|
216
|
+
const handleUseSpaceGatewayConnect = async () => {
|
|
217
217
|
try {
|
|
218
218
|
setLoading(true);
|
|
219
|
+
const fullUrl = url.startsWith('http') ? url : "https://".concat(url);
|
|
220
|
+
if (!(await (0, _spaces.isValidSpaceGatewayUrl)(fullUrl))) {
|
|
221
|
+
throw new Error(t('storage.spaces.gateway.add.invalidUrl'));
|
|
222
|
+
}
|
|
219
223
|
setAuthorizeConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
|
|
220
224
|
open: true,
|
|
221
|
-
prefix: (0, _urlJoin.default)(
|
|
222
|
-
baseUrl: new URL(
|
|
225
|
+
prefix: (0, _urlJoin.default)(fullUrl, 'space/api/did'),
|
|
226
|
+
baseUrl: new URL(fullUrl).origin,
|
|
223
227
|
checkFn: _api.axios.create({
|
|
224
|
-
baseURL: (0, _urlJoin.default)(
|
|
228
|
+
baseURL: (0, _urlJoin.default)(fullUrl, 'space')
|
|
225
229
|
}).get,
|
|
226
230
|
extraParams: {
|
|
227
231
|
appDid: blockletInfo.appDid,
|
|
@@ -348,12 +352,16 @@ function ConnectTo(_ref) {
|
|
|
348
352
|
setUrl(e.target.value);
|
|
349
353
|
},
|
|
350
354
|
disabled: loading,
|
|
351
|
-
onKeyPress:
|
|
355
|
+
onKeyPress: async e => {
|
|
356
|
+
if (e.key === 'Enter') {
|
|
357
|
+
await handleUseSpaceGatewayConnect();
|
|
358
|
+
}
|
|
359
|
+
},
|
|
352
360
|
autoFocus: true
|
|
353
361
|
})
|
|
354
362
|
})
|
|
355
363
|
})
|
|
356
|
-
}),
|
|
364
|
+
}), Boolean(errorMessage) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Alert.default, {
|
|
357
365
|
type: "error",
|
|
358
366
|
style: {
|
|
359
367
|
width: '100%'
|
|
@@ -363,6 +371,9 @@ function ConnectTo(_ref) {
|
|
|
363
371
|
})]
|
|
364
372
|
});
|
|
365
373
|
}
|
|
366
|
-
ConnectTo.propTypes = {
|
|
374
|
+
ConnectTo.propTypes = {
|
|
375
|
+
spaceGateways: _propTypes.array.isRequired,
|
|
376
|
+
refreshSpaceGateways: _propTypes.func.isRequired
|
|
377
|
+
};
|
|
367
378
|
var _default = ConnectTo;
|
|
368
379
|
exports.default = _default;
|
|
@@ -16,10 +16,69 @@ var _blocklet = require("../../../lib/contexts/blocklet");
|
|
|
16
16
|
var _node = require("../../contexts/node");
|
|
17
17
|
var _spaces = require("../../util/spaces");
|
|
18
18
|
var _useBackupProgress = _interopRequireDefault(require("../../hooks/use-backup-progress"));
|
|
19
|
+
var _spaceGateway = require("../../util/space-gateway");
|
|
20
|
+
var _util = require("../../util");
|
|
19
21
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
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); }
|
|
22
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
|
+
/**
|
|
26
|
+
* @description
|
|
27
|
+
* @param {{
|
|
28
|
+
* blockletDid: string,
|
|
29
|
+
* setLoading: (bool: boolean) => void,
|
|
30
|
+
* refreshBlocklet: Function
|
|
31
|
+
* }} { blockletDid, setLoading = () => undefined, refreshBlocklet }
|
|
32
|
+
* @return {{
|
|
33
|
+
* spaceGateways: Array<SpaceGateway>
|
|
34
|
+
* refreshSpaceGateways: Function
|
|
35
|
+
* }} {spaceGateways}
|
|
36
|
+
*/function useSpaceGateways(_ref) {
|
|
37
|
+
let {
|
|
38
|
+
blockletDid,
|
|
39
|
+
setLoading = () => undefined
|
|
40
|
+
} = _ref;
|
|
41
|
+
const [refresh, setRefresh] = (0, _react.useState)(false);
|
|
42
|
+
const [spaceGateways, setSpaceGateways] = (0, _react.useState)([]);
|
|
43
|
+
const {
|
|
44
|
+
api: nodeApi
|
|
45
|
+
} = (0, _node.useNodeContext)();
|
|
46
|
+
const refreshSpaceGateways = () => {
|
|
47
|
+
setRefresh(x => !x);
|
|
48
|
+
};
|
|
49
|
+
(0, _ahooks.useAsyncEffect)(async () => {
|
|
50
|
+
try {
|
|
51
|
+
if (!blockletDid) {
|
|
52
|
+
setSpaceGateways([]);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
setLoading(true);
|
|
56
|
+
const {
|
|
57
|
+
spaceGateways: _spaceGateways
|
|
58
|
+
} = await nodeApi.getBlockletSpaceGateways({
|
|
59
|
+
input: {
|
|
60
|
+
did: blockletDid
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
const latestSpaceGateways = await (0, _spaceGateway.updateSpaceGatewaysFromDIDSpaces)({
|
|
64
|
+
blockletDid,
|
|
65
|
+
nodeApi,
|
|
66
|
+
spaceGateways: _spaceGateways
|
|
67
|
+
});
|
|
68
|
+
setSpaceGateways(latestSpaceGateways !== null && latestSpaceGateways !== void 0 ? latestSpaceGateways : []);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error(error);
|
|
71
|
+
_Toast.default.error((0, _util.formatError)(error));
|
|
72
|
+
} finally {
|
|
73
|
+
setLoading(false);
|
|
74
|
+
}
|
|
75
|
+
}, [blockletDid, refresh]);
|
|
76
|
+
return {
|
|
77
|
+
refreshSpaceGateways,
|
|
78
|
+
spaceGateways
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
23
82
|
/**
|
|
24
83
|
* @typedef {{
|
|
25
84
|
* did: string,
|
|
@@ -28,7 +87,10 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
28
87
|
* endpoint: string
|
|
29
88
|
* protected?: boolean,
|
|
30
89
|
* }} SpaceGateway
|
|
31
|
-
*/
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
function Connected() {
|
|
93
|
+
var _blocklet$meta;
|
|
32
94
|
const {
|
|
33
95
|
t
|
|
34
96
|
} = (0, _context.useLocaleContext)();
|
|
@@ -42,28 +104,25 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
42
104
|
const {
|
|
43
105
|
api: nodeApi
|
|
44
106
|
} = (0, _node.useNodeContext)();
|
|
45
|
-
const [spaceGateways, setSpaceGateways] = (0, _react.useState)( /** @type {Array<SpaceGateway>} */
|
|
46
|
-
[]);
|
|
47
107
|
const backupEndpoint = (0, _react.useMemo)(() => (0, _spaces.getSpaceBackupEndpoint)(blocklet === null || blocklet === void 0 ? void 0 : blocklet.environments), [blocklet]);
|
|
48
108
|
const progress = (0, _useBackupProgress.default)({
|
|
49
109
|
appDid: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appDid
|
|
50
110
|
});
|
|
51
|
-
(0,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
111
|
+
const [loading, setLoading] = (0, _react.useState)(false);
|
|
112
|
+
const {
|
|
113
|
+
spaceGateways,
|
|
114
|
+
refreshSpaceGateways
|
|
115
|
+
} = useSpaceGateways({
|
|
116
|
+
blockletDid: blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta = blocklet.meta) === null || _blocklet$meta === void 0 ? void 0 : _blocklet$meta.did,
|
|
117
|
+
setLoading,
|
|
118
|
+
refreshBlocklet
|
|
119
|
+
});
|
|
120
|
+
const shouldShowLoading = loading && !(spaceGateways !== null && spaceGateways !== void 0 && spaceGateways.length);
|
|
61
121
|
|
|
62
122
|
/**
|
|
63
123
|
*
|
|
64
124
|
* @description
|
|
65
125
|
* @param {SpaceGateway} spaceGateway
|
|
66
|
-
* @param {number} index
|
|
67
126
|
*/
|
|
68
127
|
const onDeleteGateway = async spaceGateway => {
|
|
69
128
|
if (!spaceGateway) {
|
|
@@ -82,7 +141,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
82
141
|
_Toast.default.success(t('storage.spaces.gateway.delete.succeeded', {
|
|
83
142
|
name: "(".concat(spaceGateway.name, ")")
|
|
84
143
|
}));
|
|
85
|
-
|
|
144
|
+
refreshSpaceGateways();
|
|
86
145
|
};
|
|
87
146
|
const onBackupNow = async () => {
|
|
88
147
|
await nodeApi.backupBlocklet({
|
|
@@ -100,35 +159,45 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
100
159
|
flexDirection: "row",
|
|
101
160
|
alignItems: "center",
|
|
102
161
|
justifyContent: "space-between",
|
|
162
|
+
marginBottom: "12px",
|
|
103
163
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
104
|
-
|
|
105
|
-
|
|
164
|
+
fontSize: "1.2rem",
|
|
165
|
+
fontWeight: "bold",
|
|
106
166
|
children: t('storage.spaces.connected.title')
|
|
107
167
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_connectTo.default, {
|
|
108
168
|
style: {
|
|
109
|
-
fontSize: '
|
|
169
|
+
fontSize: '1rem'
|
|
110
170
|
},
|
|
111
|
-
display: "inline-flex"
|
|
171
|
+
display: "inline-flex",
|
|
172
|
+
spaceGateways: spaceGateways,
|
|
173
|
+
refreshSpaceGateways: refreshSpaceGateways
|
|
112
174
|
})]
|
|
113
175
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
|
114
|
-
|
|
115
|
-
|
|
176
|
+
children: shouldShowLoading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
|
177
|
+
display: "flex",
|
|
178
|
+
justifyContent: "center",
|
|
179
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.CircularProgress, {})
|
|
180
|
+
}) : spaceGateways.map((spaceGateway, index) => {
|
|
116
181
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_item.default, {
|
|
182
|
+
style: {
|
|
183
|
+
marginTop: '12px'
|
|
184
|
+
},
|
|
117
185
|
spaceGateway: spaceGateway,
|
|
118
186
|
connected: spaceGateways.findIndex(s => s.endpoint === backupEndpoint) === index,
|
|
119
|
-
onDelete:
|
|
187
|
+
onDelete: onDeleteGateway,
|
|
120
188
|
onBackupNow: onBackupNow,
|
|
121
|
-
progress: progress
|
|
189
|
+
progress: progress,
|
|
190
|
+
refreshSpaceGateways: refreshSpaceGateways
|
|
122
191
|
}, spaceGateway.endpoint);
|
|
123
192
|
})
|
|
124
193
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_backups.default, {
|
|
125
194
|
sx: {
|
|
126
|
-
marginTop: '
|
|
195
|
+
marginTop: '24px'
|
|
127
196
|
},
|
|
197
|
+
spaceGateways: spaceGateways,
|
|
128
198
|
progress: progress
|
|
129
199
|
})]
|
|
130
200
|
});
|
|
131
201
|
}
|
|
132
|
-
Connected.propTypes = {};
|
|
133
202
|
var _default = Connected;
|
|
134
203
|
exports.default = _default;
|