@abtnode/ux 1.16.7 → 1.16.8-beta-ca58a421
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/environment.js +8 -4
- 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
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _Dialog = _interopRequireDefault(require("@arcblock/ux/lib/Dialog"));
|
|
8
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
9
|
+
var _material = require("@mui/material");
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
var _ListItem = _interopRequireDefault(require("@mui/material/ListItem"));
|
|
12
|
+
var _isUrl = _interopRequireDefault(require("is-url"));
|
|
13
|
+
var _urlJoin = _interopRequireDefault(require("url-join"));
|
|
14
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
+
var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
|
|
16
|
+
var _constant = require("@blocklet/constant");
|
|
17
|
+
var _ahooks = require("ahooks");
|
|
18
|
+
var _lodash = require("lodash");
|
|
19
|
+
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
20
|
+
var _add = _interopRequireDefault(require("./add"));
|
|
21
|
+
var _item = _interopRequireDefault(require("./item"));
|
|
22
|
+
var _connect = _interopRequireDefault(require("./connect"));
|
|
23
|
+
var _session = require("../../../lib/contexts/session");
|
|
24
|
+
var _blocklet = require("../../../lib/contexts/blocklet");
|
|
25
|
+
var _toast = _interopRequireDefault(require("../../toast"));
|
|
26
|
+
var _node = require("../../contexts/node");
|
|
27
|
+
var _spaces = require("../../util/spaces");
|
|
28
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
29
|
+
var _templateObject;
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {{
|
|
32
|
+
* name: string,
|
|
33
|
+
* url: string,
|
|
34
|
+
* protected?: boolean,
|
|
35
|
+
* endpoint?: string
|
|
36
|
+
* }} SpaceGateway
|
|
37
|
+
*/
|
|
38
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
|
+
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; }
|
|
40
|
+
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; }
|
|
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; }
|
|
42
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
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); }
|
|
44
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
45
|
+
const BoxContainer = (0, _styled.default)(_material.Box)(_templateObject || (_templateObject = _taggedTemplateLiteral([""])));
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @FIXME 希望之后放在 sdk 中 @jianchao
|
|
49
|
+
* @description
|
|
50
|
+
* @param {string} endpoint
|
|
51
|
+
* @returns {string}
|
|
52
|
+
*/
|
|
53
|
+
function getSpaceUrlFromEndpoint(endpoint) {
|
|
54
|
+
const prefix = endpoint.replace(/\/api\/space\/.+/, '');
|
|
55
|
+
const strArray = endpoint.replace(/\/$/, '').split('/');
|
|
56
|
+
const spaceDid = strArray.at(-4);
|
|
57
|
+
return (0, _urlJoin.default)(prefix, 'space', spaceDid);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @description
|
|
62
|
+
* @param {{
|
|
63
|
+
* mode: 'add' | 'switch'
|
|
64
|
+
* }} {mode}
|
|
65
|
+
* @return {React.Component}
|
|
66
|
+
*/
|
|
67
|
+
function SwitchDIDSpaces(_ref) {
|
|
68
|
+
var _connectedGateway$nam;
|
|
69
|
+
let {
|
|
70
|
+
mode
|
|
71
|
+
} = _ref;
|
|
72
|
+
/** @type {{ blocklet: import('@abtnode/client').BlockletState }} */
|
|
73
|
+
const {
|
|
74
|
+
blocklet,
|
|
75
|
+
actions: {
|
|
76
|
+
refreshBlocklet
|
|
77
|
+
}
|
|
78
|
+
} = (0, _blocklet.useBlockletContext)();
|
|
79
|
+
const {
|
|
80
|
+
t
|
|
81
|
+
} = (0, _context.useLocaleContext)();
|
|
82
|
+
const [open, setOpen] = (0, _react.useState)(false);
|
|
83
|
+
const [spaceGateways, setSpaceGateways] = (0, _react.useState)( /** @type {SpaceGateway[]} */
|
|
84
|
+
[]);
|
|
85
|
+
const spaceBackupEndpoint = (0, _react.useMemo)(() => (0, _spaces.getSpaceBackupEndpoint)(blocklet === null || blocklet === void 0 ? void 0 : blocklet.environments), [blocklet]);
|
|
86
|
+
const {
|
|
87
|
+
api
|
|
88
|
+
} = (0, _session.useSessionContext)();
|
|
89
|
+
const {
|
|
90
|
+
api: nodeApi
|
|
91
|
+
} = (0, _node.useNodeContext)();
|
|
92
|
+
const [selectedGateway, setSelectedGateway] = (0, _react.useState)({});
|
|
93
|
+
const [connectedGateway, setConnectedGateway] = (0, _react.useState)(null);
|
|
94
|
+
(0, _ahooks.useAsyncEffect)(async () => {
|
|
95
|
+
var _spaceGateways$find;
|
|
96
|
+
const {
|
|
97
|
+
spaceGateways: _spaceGateways
|
|
98
|
+
} = await nodeApi.getBlockletSpaceGateways({
|
|
99
|
+
input: {
|
|
100
|
+
did: blocklet.meta.did
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
setSpaceGateways([{
|
|
104
|
+
name: 'Prod DID Spaces',
|
|
105
|
+
url: 'https://www.didspaces.com/app',
|
|
106
|
+
protected: true
|
|
107
|
+
}, ...(_spaceGateways !== null && _spaceGateways !== void 0 ? _spaceGateways : [])]);
|
|
108
|
+
setConnectedGateway((_spaceGateways$find = _spaceGateways.find(spaceGateway => spaceBackupEndpoint.includes(spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.url))) !== null && _spaceGateways$find !== void 0 ? _spaceGateways$find : {});
|
|
109
|
+
if ((0, _lodash.isEmpty)(selectedGateway)) {
|
|
110
|
+
var _spaceGateways$find2;
|
|
111
|
+
setSelectedGateway((_spaceGateways$find2 = _spaceGateways.find(spaceGateway => spaceBackupEndpoint.includes(spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.url))) !== null && _spaceGateways$find2 !== void 0 ? _spaceGateways$find2 : {});
|
|
112
|
+
}
|
|
113
|
+
}, [blocklet]);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
*
|
|
117
|
+
* @param {SpaceGateway} spaceGateway
|
|
118
|
+
*/
|
|
119
|
+
const onSelectGateway = async spaceGateway => {
|
|
120
|
+
if ((spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.url) !== (selectedGateway === null || selectedGateway === void 0 ? void 0 : selectedGateway.url)) {
|
|
121
|
+
setSelectedGateway(spaceGateway);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
*
|
|
127
|
+
* @param {string} url
|
|
128
|
+
* @returns {Promise<void>}
|
|
129
|
+
*/
|
|
130
|
+
const onAddGateway = async url => {
|
|
131
|
+
if (!(0, _lodash.isString)(url)) {
|
|
132
|
+
throw new Error(t('storage.spaces.gateway.add.invalidUrl'));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// eslint-disable-next-line no-param-reassign
|
|
136
|
+
url = url.trim().replace(/\/$/, '');
|
|
137
|
+
if (!url.startsWith('http')) {
|
|
138
|
+
// eslint-disable-next-line no-param-reassign
|
|
139
|
+
url = "https://".concat(url);
|
|
140
|
+
}
|
|
141
|
+
if (!(0, _isUrl.default)(url)) {
|
|
142
|
+
throw new Error(t('storage.spaces.gateway.add.invalidUrl'));
|
|
143
|
+
}
|
|
144
|
+
const duplicate = spaceGateways.some(s => s.url === url);
|
|
145
|
+
if (duplicate) {
|
|
146
|
+
throw new Error(t('storage.spaces.gateway.add.duplicate', {
|
|
147
|
+
url: url.url
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
const {
|
|
151
|
+
data
|
|
152
|
+
} = await api.get((0, _urlJoin.default)(url, '/__blocklet__.js?type=json'));
|
|
153
|
+
const spaceGateway = {
|
|
154
|
+
name: data.appName,
|
|
155
|
+
url
|
|
156
|
+
};
|
|
157
|
+
await nodeApi.addBlockletSpaceGateway({
|
|
158
|
+
input: {
|
|
159
|
+
did: blocklet.meta.did,
|
|
160
|
+
spaceGateway
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
setSpaceGateways(preValue => {
|
|
164
|
+
return [...preValue, spaceGateway];
|
|
165
|
+
});
|
|
166
|
+
setSelectedGateway(spaceGateway);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
*
|
|
171
|
+
* @description
|
|
172
|
+
* @param {SpaceGateway} spaceGateway
|
|
173
|
+
* @param {number} index
|
|
174
|
+
*/
|
|
175
|
+
const onDeleteGateway = async (spaceGateway, index) => {
|
|
176
|
+
if (!spaceGateway) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (spaceBackupEndpoint === (spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.endpoint)) {
|
|
180
|
+
_toast.default.warning(t('storage.spaces.gateway.delete.failedForConnected'));
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
await nodeApi.deleteBlockletSpaceGateway({
|
|
184
|
+
input: {
|
|
185
|
+
did: blocklet.meta.did,
|
|
186
|
+
url: spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.url
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
setSpaceGateways(preSpaceGateways => {
|
|
190
|
+
return preSpaceGateways.filter(s => s.url !== spaceGateway.url);
|
|
191
|
+
});
|
|
192
|
+
if ((spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.url) === (selectedGateway === null || selectedGateway === void 0 ? void 0 : selectedGateway.url)) {
|
|
193
|
+
setSelectedGateway(spaceGateways[index - 1]);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
*
|
|
199
|
+
*
|
|
200
|
+
* @param {SpaceGateway} spaceGateway
|
|
201
|
+
* @param {string} _endpoint
|
|
202
|
+
* @return {Promise<void>}
|
|
203
|
+
*/
|
|
204
|
+
const onConnectGateway = async (spaceGateway, _endpoint) => {
|
|
205
|
+
var _spaceGateway$name;
|
|
206
|
+
const {
|
|
207
|
+
data
|
|
208
|
+
} = await api.get((0, _urlJoin.default)(spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.url, '/__blocklet__.js?type=json'));
|
|
209
|
+
await nodeApi.updateBlockletSpaceGateway({
|
|
210
|
+
input: {
|
|
211
|
+
did: blocklet.meta.did,
|
|
212
|
+
where: {
|
|
213
|
+
url: spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.url
|
|
214
|
+
},
|
|
215
|
+
spaceGateway: _objectSpread(_objectSpread({}, spaceGateway), {}, {
|
|
216
|
+
name: data === null || data === void 0 ? void 0 : data.appName,
|
|
217
|
+
endpoint: _endpoint
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
if (spaceBackupEndpoint !== _endpoint) {
|
|
222
|
+
await nodeApi.configBlocklet({
|
|
223
|
+
input: {
|
|
224
|
+
did: [blocklet.meta.did],
|
|
225
|
+
configs: [{
|
|
226
|
+
key: _constant.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SPACES_URL,
|
|
227
|
+
value: spaceGateway.url
|
|
228
|
+
}, {
|
|
229
|
+
key: _constant.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_BACKUP_ENDPOINT,
|
|
230
|
+
value: _endpoint
|
|
231
|
+
}]
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
_toast.default.success(t('storage.spaces.connectedWithName', {
|
|
236
|
+
name: (_spaceGateway$name = spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.name) !== null && _spaceGateway$name !== void 0 ? _spaceGateway$name : 'DID Spaces'
|
|
237
|
+
}));
|
|
238
|
+
refreshBlocklet();
|
|
239
|
+
setTimeout(() => setOpen(false), 1000);
|
|
240
|
+
};
|
|
241
|
+
const textProps = mode === 'add' ? {
|
|
242
|
+
text: t('storage.spaces.gateway.connect.add'),
|
|
243
|
+
tips: t('storage.spaces.gateway.connect.addTips')
|
|
244
|
+
} : {
|
|
245
|
+
text: t('storage.spaces.gateway.connect.switch'),
|
|
246
|
+
tips: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
247
|
+
children: [t('storage.spaces.gateway.connect.switchTips', {
|
|
248
|
+
name: ''
|
|
249
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Link, {
|
|
250
|
+
href: getSpaceUrlFromEndpoint(spaceBackupEndpoint),
|
|
251
|
+
target: "_blank",
|
|
252
|
+
children: (_connectedGateway$nam = connectedGateway === null || connectedGateway === void 0 ? void 0 : connectedGateway.name) !== null && _connectedGateway$nam !== void 0 ? _connectedGateway$nam : 'Spaces'
|
|
253
|
+
})]
|
|
254
|
+
})
|
|
255
|
+
};
|
|
256
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(BoxContainer, {
|
|
257
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
|
258
|
+
marginTop: "16px",
|
|
259
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
260
|
+
display: "inline",
|
|
261
|
+
children: [t('storage.spaces.tips'), ": \xA0", ' ', /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
|
262
|
+
display: "inline",
|
|
263
|
+
color: "primary.main",
|
|
264
|
+
fontWeight: "fontWeightBold",
|
|
265
|
+
children: textProps.tips
|
|
266
|
+
})]
|
|
267
|
+
})
|
|
268
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
|
269
|
+
marginTop: "16px",
|
|
270
|
+
display: "flex",
|
|
271
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
|
|
272
|
+
size: "small",
|
|
273
|
+
variant: "contained",
|
|
274
|
+
onClick: () => setOpen(true),
|
|
275
|
+
children: textProps.text
|
|
276
|
+
})
|
|
277
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dialog.default, {
|
|
278
|
+
open: open,
|
|
279
|
+
title: t('storage.spaces.gateway.select'),
|
|
280
|
+
disableEscapeKeyDown: true,
|
|
281
|
+
disablePortal: false,
|
|
282
|
+
fullWidth: true,
|
|
283
|
+
onClose: () => setOpen(false),
|
|
284
|
+
actions: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
285
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_add.default, {
|
|
286
|
+
onAdd: onAddGateway
|
|
287
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_connect.default, {
|
|
288
|
+
spaceGateway: selectedGateway,
|
|
289
|
+
onConnect: onConnectGateway
|
|
290
|
+
})]
|
|
291
|
+
}),
|
|
292
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.List, {
|
|
293
|
+
children: spaceGateways.map((spaceGateway, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItem.default, {
|
|
294
|
+
button: true,
|
|
295
|
+
selected: (spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.url) === (selectedGateway === null || selectedGateway === void 0 ? void 0 : selectedGateway.url),
|
|
296
|
+
"data-cy": "switch-did-spaces-gateway",
|
|
297
|
+
onClick: () => onSelectGateway(spaceGateway),
|
|
298
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ListItemText, {
|
|
299
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_item.default, {
|
|
300
|
+
spaceGateway: spaceGateway,
|
|
301
|
+
connected: spaceBackupEndpoint === (spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.endpoint),
|
|
302
|
+
onDelete: _spaceGateway => onDeleteGateway(_spaceGateway, index)
|
|
303
|
+
})
|
|
304
|
+
})
|
|
305
|
+
}, spaceGateway.url))
|
|
306
|
+
})
|
|
307
|
+
})]
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
SwitchDIDSpaces.propTypes = {
|
|
311
|
+
mode: _propTypes.default.oneOf(['add', 'switch'])
|
|
312
|
+
};
|
|
313
|
+
SwitchDIDSpaces.defaultProps = {
|
|
314
|
+
mode: 'switch'
|
|
315
|
+
};
|
|
316
|
+
var _default = SwitchDIDSpaces;
|
|
317
|
+
exports.default = _default;
|
package/lib/confirm.js
CHANGED
|
@@ -34,7 +34,8 @@ function ConfirmDialog(_ref) {
|
|
|
34
34
|
color,
|
|
35
35
|
params: initialParams,
|
|
36
36
|
onCancel,
|
|
37
|
-
onConfirm
|
|
37
|
+
onConfirm,
|
|
38
|
+
loading: inputLoading
|
|
38
39
|
} = _ref;
|
|
39
40
|
const [params, setParams] = (0, _react.useState)(initialParams);
|
|
40
41
|
const [open, setOpen] = (0, _react.useState)(true);
|
|
@@ -114,11 +115,11 @@ function ConfirmDialog(_ref) {
|
|
|
114
115
|
color: color
|
|
115
116
|
// eslint-disable-next-line no-underscore-dangle
|
|
116
117
|
,
|
|
117
|
-
disabled: params.__disableConfirm || loading,
|
|
118
|
+
disabled: params.__disableConfirm || loading || inputLoading,
|
|
118
119
|
variant: "contained",
|
|
119
120
|
"data-cy": "submit-confirm-dialog",
|
|
120
121
|
autoFocus: true,
|
|
121
|
-
children: [loading && /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {
|
|
122
|
+
children: [(loading || inputLoading) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {
|
|
122
123
|
size: 16
|
|
123
124
|
}), confirm]
|
|
124
125
|
})]
|
|
@@ -136,7 +137,8 @@ ConfirmDialog.propTypes = {
|
|
|
136
137
|
params: _propTypes.default.object,
|
|
137
138
|
// This object holds states managed in the dialog
|
|
138
139
|
onCancel: _propTypes.default.func,
|
|
139
|
-
onConfirm: _propTypes.default.func.isRequired
|
|
140
|
+
onConfirm: _propTypes.default.func.isRequired,
|
|
141
|
+
loading: _propTypes.default.bool
|
|
140
142
|
};
|
|
141
143
|
ConfirmDialog.defaultProps = {
|
|
142
144
|
onCancel: () => {},
|
|
@@ -144,6 +146,7 @@ ConfirmDialog.defaultProps = {
|
|
|
144
146
|
cancel: '',
|
|
145
147
|
confirm: 'Confirm',
|
|
146
148
|
color: 'error',
|
|
147
|
-
params: {}
|
|
149
|
+
params: {},
|
|
150
|
+
loading: false
|
|
148
151
|
};
|
|
149
152
|
const StyledDialog = (0, _styled.default)(_Dialog.default)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .delete-actions .Mui-disabled {\n color: rgba(0, 0, 0, 0.26) !important;\n box-shadow: none;\n background-color: rgba(0, 0, 0, 0.12) !important;\n }\n"])));
|
|
@@ -25,6 +25,10 @@ var _required = _interopRequireDefault(require("./required"));
|
|
|
25
25
|
var _formWrapper = _interopRequireDefault(require("./form-wrapper"));
|
|
26
26
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
27
|
const _excluded = ["label", "disabled", "required", "initialValue", "onChange", "placeholder", "style", "onSubmit", "secure", "triggers", "formatterBeforeSubmit"];
|
|
28
|
+
/**
|
|
29
|
+
* @param {*} value value 空时, null 表示未修改, '' 表示已修改
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
28
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
33
|
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); }
|
|
30
34
|
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; }
|
|
@@ -35,6 +39,18 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
|
|
|
35
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); }
|
|
36
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; }
|
|
37
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
|
+
const getDisplayValue = (value, secure, initialValue) => {
|
|
43
|
+
if (value === null && secure && initialValue) {
|
|
44
|
+
return '******';
|
|
45
|
+
}
|
|
46
|
+
if (!value) {
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
if (secure) {
|
|
50
|
+
return '******';
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
};
|
|
38
54
|
function InputTriggers(_ref) {
|
|
39
55
|
let {
|
|
40
56
|
triggers,
|
|
@@ -136,7 +152,9 @@ function FormTextInput(_ref2) {
|
|
|
136
152
|
rest = _objectWithoutProperties(_ref2, _excluded);
|
|
137
153
|
const [editing, setEditing] = (0, _react.useState)(false);
|
|
138
154
|
const [loading, setLoading] = (0, _react.useState)(false);
|
|
139
|
-
|
|
155
|
+
|
|
156
|
+
// value 空时, null 表示未修改, '' 表示已修改
|
|
157
|
+
const [defaultValue, setDefaultValue] = (0, _react.useState)(secure && initialValue === '__encrypted__' ? null : initialValue);
|
|
140
158
|
const [value, setValue] = (0, _react.useState)(defaultValue);
|
|
141
159
|
const handleSubmit = async () => {
|
|
142
160
|
setLoading(true);
|
|
@@ -192,7 +210,7 @@ function FormTextInput(_ref2) {
|
|
|
192
210
|
style: {
|
|
193
211
|
whiteSpace: 'pre-wrap'
|
|
194
212
|
},
|
|
195
|
-
children: secure
|
|
213
|
+
children: getDisplayValue(value, secure, initialValue)
|
|
196
214
|
});
|
|
197
215
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_formWrapper.default, {
|
|
198
216
|
className: "form",
|
package/lib/locales/en.js
CHANGED
|
@@ -260,6 +260,7 @@ module.exports = {
|
|
|
260
260
|
status: 'Status',
|
|
261
261
|
stop: 'Stop',
|
|
262
262
|
storage: 'Storage',
|
|
263
|
+
backup: 'Backup',
|
|
263
264
|
store: 'Store',
|
|
264
265
|
success: 'success',
|
|
265
266
|
support: 'Support',
|
|
@@ -295,7 +296,13 @@ module.exports = {
|
|
|
295
296
|
gateway: 'Gateway',
|
|
296
297
|
verifyNFT: 'Verify NFT',
|
|
297
298
|
errorMessage: 'Error Message:',
|
|
298
|
-
slugifyHint: 'The actual mount point will be: {value}'
|
|
299
|
+
slugifyHint: 'The actual mount point will be: {value}',
|
|
300
|
+
strategy: 'Strategy',
|
|
301
|
+
auto: 'Auto',
|
|
302
|
+
manual: 'Manual',
|
|
303
|
+
progress: 'Progress',
|
|
304
|
+
startTime: 'Start time',
|
|
305
|
+
endTime: 'End time'
|
|
299
306
|
},
|
|
300
307
|
blocklet: {
|
|
301
308
|
external: 'External',
|
|
@@ -531,7 +538,8 @@ module.exports = {
|
|
|
531
538
|
domainLockTooltip: 'The system generated Domain cannot be edited.',
|
|
532
539
|
urlLockTooltip: 'The system generated URL Path cannot be edited.',
|
|
533
540
|
showAllDomains: 'Show all domains',
|
|
534
|
-
showAllDIDs: 'Show all DIDs'
|
|
541
|
+
showAllDIDs: 'Show all DIDs',
|
|
542
|
+
currentDomainTip: 'You are accessing the current page through this domain'
|
|
535
543
|
},
|
|
536
544
|
export: {
|
|
537
545
|
title: 'Export Blocklet',
|
|
@@ -1300,20 +1308,60 @@ module.exports = {
|
|
|
1300
1308
|
spaces: {
|
|
1301
1309
|
tips: 'Tips',
|
|
1302
1310
|
label: 'Enter DID Spaces Gateway',
|
|
1303
|
-
connected: 'You have successfully
|
|
1311
|
+
connected: 'You have successfully connected to DID Spaces',
|
|
1312
|
+
connectedWithName: 'You have successfully connected to {name}',
|
|
1304
1313
|
connect: 'Connect',
|
|
1305
1314
|
reconnect: 'Reconnect',
|
|
1306
1315
|
addressCannotEmpty: 'Address cannot be empty',
|
|
1307
1316
|
addressNotValid: '{url} is not a valid address',
|
|
1308
1317
|
authorize: {
|
|
1309
|
-
title: '
|
|
1310
|
-
scan: 'Use your DID Wallet to scan the QR code below to
|
|
1311
|
-
success: '
|
|
1318
|
+
title: 'Connect {appName} to DID Spaces',
|
|
1319
|
+
scan: 'Use your DID Wallet to scan the QR code below to allow the app {appName} to connect to DID Spaces',
|
|
1320
|
+
success: 'Connection successful'
|
|
1312
1321
|
},
|
|
1313
1322
|
backup: 'Backup',
|
|
1314
1323
|
backupSuccessfully: 'Backup successfully',
|
|
1315
1324
|
restore: 'Restore',
|
|
1316
|
-
restoreSuccessfully: 'Restore successfully'
|
|
1325
|
+
restoreSuccessfully: 'Restore successfully',
|
|
1326
|
+
gateway: {
|
|
1327
|
+
title: 'Gateway',
|
|
1328
|
+
select: 'Select a DID Spaces',
|
|
1329
|
+
add: {
|
|
1330
|
+
title: 'Add DID Spaces',
|
|
1331
|
+
label: 'Enter the url of the DID Spaces',
|
|
1332
|
+
failed: 'Add DID Spaces failed',
|
|
1333
|
+
invalidUrl: 'Invalid DID Spaces url',
|
|
1334
|
+
duplicate: 'DID Spaces already exist'
|
|
1335
|
+
},
|
|
1336
|
+
delete: {
|
|
1337
|
+
title: 'Delete gateway',
|
|
1338
|
+
failed: 'Delete gateway failed',
|
|
1339
|
+
failedForConnected: 'Unable to delete a connected DID Spaces'
|
|
1340
|
+
},
|
|
1341
|
+
connect: {
|
|
1342
|
+
title: 'Connect to my DID Spaces',
|
|
1343
|
+
add: 'Connect to DID Spaces now',
|
|
1344
|
+
addTips: 'You are not connected to any Space yet',
|
|
1345
|
+
switch: 'Switch DID Spaces',
|
|
1346
|
+
switchTips: 'You are connected to {name}',
|
|
1347
|
+
connected: 'Connected'
|
|
1348
|
+
},
|
|
1349
|
+
connectTo: 'Connect to DID Spaces'
|
|
1350
|
+
},
|
|
1351
|
+
strategy: {
|
|
1352
|
+
title: 'Backup Strategy',
|
|
1353
|
+
autoBackup: 'Auto backup',
|
|
1354
|
+
backupNow: 'Backup now',
|
|
1355
|
+
viewBackupFiles: 'View backup files'
|
|
1356
|
+
},
|
|
1357
|
+
progress: {
|
|
1358
|
+
title: 'Backup progress'
|
|
1359
|
+
},
|
|
1360
|
+
record: {
|
|
1361
|
+
title: 'Backup record',
|
|
1362
|
+
emptyData: 'No record'
|
|
1363
|
+
},
|
|
1364
|
+
notYet: "You don't have a backup in progress yet..."
|
|
1317
1365
|
}
|
|
1318
1366
|
},
|
|
1319
1367
|
log: {
|
package/lib/locales/zh.js
CHANGED
|
@@ -265,6 +265,7 @@ module.exports = {
|
|
|
265
265
|
status: '状态',
|
|
266
266
|
stop: '停止',
|
|
267
267
|
storage: '存储',
|
|
268
|
+
backup: '备份',
|
|
268
269
|
store: '商店',
|
|
269
270
|
success: '成功',
|
|
270
271
|
support: '服务支持',
|
|
@@ -300,7 +301,13 @@ module.exports = {
|
|
|
300
301
|
gateway: '网关',
|
|
301
302
|
verifyNFT: '验证凭证',
|
|
302
303
|
errorMessage: '错误信息:',
|
|
303
|
-
slugifyHint: '最终生效的挂载点是: {value}'
|
|
304
|
+
slugifyHint: '最终生效的挂载点是: {value}',
|
|
305
|
+
strategy: '策略',
|
|
306
|
+
auto: '自动',
|
|
307
|
+
manual: '手动',
|
|
308
|
+
progress: '进行中',
|
|
309
|
+
startTime: '开始时间',
|
|
310
|
+
endTime: '结束时间'
|
|
304
311
|
},
|
|
305
312
|
blocklet: {
|
|
306
313
|
external: '外部',
|
|
@@ -538,7 +545,8 @@ module.exports = {
|
|
|
538
545
|
domainLockTooltip: '无法编辑由系统生成的 域名',
|
|
539
546
|
urlLockTooltip: '无法编辑由系统生成的 URL 路径',
|
|
540
547
|
showAllDomains: '显示所有域名',
|
|
541
|
-
showAllDIDs: '显示所有 DID'
|
|
548
|
+
showAllDIDs: '显示所有 DID',
|
|
549
|
+
currentDomainTip: '你正在通过该域名访问当前页面'
|
|
542
550
|
},
|
|
543
551
|
export: {
|
|
544
552
|
title: '导出 Blocklet',
|
|
@@ -1304,20 +1312,59 @@ module.exports = {
|
|
|
1304
1312
|
spaces: {
|
|
1305
1313
|
tips: '提示',
|
|
1306
1314
|
label: '请输入 DID Spaces 服务地址',
|
|
1307
|
-
connected: '
|
|
1308
|
-
|
|
1309
|
-
|
|
1315
|
+
connected: '你已成功连接至 DID Spaces',
|
|
1316
|
+
connectedWithName: '你已成功连接至 {name}',
|
|
1317
|
+
connect: '立即连接',
|
|
1318
|
+
reconnect: '重新连接',
|
|
1310
1319
|
addressCannotEmpty: '地址不能为空',
|
|
1311
1320
|
addressNotValid: '{url} 不是一个合法的地址',
|
|
1312
1321
|
authorize: {
|
|
1313
|
-
title: '
|
|
1314
|
-
scan: '使用你的 DID Wallet
|
|
1315
|
-
success: '
|
|
1322
|
+
title: '连接 {appName} 至 DID Spaces',
|
|
1323
|
+
scan: '使用你的 DID Wallet 扫描下面的二维码以允许应用 {appName} 连接至 DID Spaces',
|
|
1324
|
+
success: '连接成功'
|
|
1316
1325
|
},
|
|
1317
1326
|
backup: '备份',
|
|
1318
1327
|
backupSuccessfully: '备份成功',
|
|
1319
1328
|
restore: '还原',
|
|
1320
|
-
restoreSuccessfully: '还原成功'
|
|
1329
|
+
restoreSuccessfully: '还原成功',
|
|
1330
|
+
gateway: {
|
|
1331
|
+
select: '选择一个 DID Spaces',
|
|
1332
|
+
add: {
|
|
1333
|
+
title: '添加 DID Spaces',
|
|
1334
|
+
label: '输入 DID Spaces 的地址',
|
|
1335
|
+
failed: '添加 DID Spaces 失败',
|
|
1336
|
+
invalidUrl: '无效的 DID Spaces 地址',
|
|
1337
|
+
duplicate: 'DID Spaces 已存在'
|
|
1338
|
+
},
|
|
1339
|
+
delete: {
|
|
1340
|
+
title: '删除 DID Spaces',
|
|
1341
|
+
failed: '删除 DID Spaces 失败',
|
|
1342
|
+
failedForConnected: '无法删除一个已连接的 DID Spaces'
|
|
1343
|
+
},
|
|
1344
|
+
connect: {
|
|
1345
|
+
title: '连接到我的 DID Spaces',
|
|
1346
|
+
add: '立即连接 DID Spaces',
|
|
1347
|
+
addTips: '你还没有连接到任何的 DID Spaces',
|
|
1348
|
+
switch: '切换 DID Spaces',
|
|
1349
|
+
switchTips: '你已连接到 {name}',
|
|
1350
|
+
connected: '已连接'
|
|
1351
|
+
},
|
|
1352
|
+
connectTo: '连接至 DID Spaces'
|
|
1353
|
+
},
|
|
1354
|
+
strategy: {
|
|
1355
|
+
title: '备份策略',
|
|
1356
|
+
autoBackup: '自动备份',
|
|
1357
|
+
backupNow: '立即备份',
|
|
1358
|
+
viewBackupFiles: '查看备份文件'
|
|
1359
|
+
},
|
|
1360
|
+
progress: {
|
|
1361
|
+
title: '备份进度'
|
|
1362
|
+
},
|
|
1363
|
+
record: {
|
|
1364
|
+
title: '备份记录',
|
|
1365
|
+
emptyData: '暂无记录'
|
|
1366
|
+
},
|
|
1367
|
+
notYet: '你还没有正在进行中的备份...'
|
|
1321
1368
|
}
|
|
1322
1369
|
},
|
|
1323
1370
|
log: {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getBackupFilesUrlFromEndpoint = getBackupFilesUrlFromEndpoint;
|
|
7
|
+
exports.getSpaceBackupEndpoint = getSpaceBackupEndpoint;
|
|
8
|
+
exports.getSpaceGatewayFromEndpoint = getSpaceGatewayFromEndpoint;
|
|
9
|
+
exports.hasPermissionByEndpoint = hasPermissionByEndpoint;
|
|
10
|
+
var _isUrl = _interopRequireDefault(require("is-url"));
|
|
11
|
+
var _constant = require("@blocklet/constant");
|
|
12
|
+
var _api = require("./api");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
/* eslint-disable import/prefer-default-export */
|
|
15
|
+
const joinUrl = require('url-join');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @FIXME 希望之后放在 sdk 中 @jianchao
|
|
19
|
+
* @description
|
|
20
|
+
* @param {string} endpoint
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
function getBackupFilesUrlFromEndpoint(endpoint) {
|
|
24
|
+
const prefix = endpoint.replace(/\/api\/space\/.+/, '');
|
|
25
|
+
const strArray = endpoint.replace(/\/$/, '').split('/');
|
|
26
|
+
const spaceDid = strArray.at(-4);
|
|
27
|
+
const appDid = strArray.at(-2);
|
|
28
|
+
return joinUrl(prefix, 'space', spaceDid, 'apps', appDid, 'explorer', "?key=/apps/".concat(appDid, "/.did-objects/").concat(appDid, "/"));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @description
|
|
33
|
+
* @export
|
|
34
|
+
* @param {string} endpoint
|
|
35
|
+
* @return {Promise<boolean>}
|
|
36
|
+
*/
|
|
37
|
+
async function hasPermissionByEndpoint(endpoint) {
|
|
38
|
+
try {
|
|
39
|
+
if (!(0, _isUrl.default)(endpoint)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const {
|
|
43
|
+
headers
|
|
44
|
+
} = await _api.api.head(endpoint, {
|
|
45
|
+
timeout: 5000
|
|
46
|
+
});
|
|
47
|
+
return headers['x-listable'] === 'true' && headers['x-readable'] === 'true' && headers['x-writeable'] === 'true';
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(error);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @description
|
|
56
|
+
* @export
|
|
57
|
+
* @param {import('@abtnode/client').ConfigEntry[]} environments
|
|
58
|
+
* @return {string}
|
|
59
|
+
*/
|
|
60
|
+
function getSpaceBackupEndpoint(environments) {
|
|
61
|
+
var _environments$find;
|
|
62
|
+
return (environments === null || environments === void 0 ? void 0 : (_environments$find = environments.find(e => e.key === _constant.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_BACKUP_ENDPOINT)) === null || _environments$find === void 0 ? void 0 : _environments$find.value) || '';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @description
|
|
67
|
+
* @export
|
|
68
|
+
* @param {string} endpoint
|
|
69
|
+
* @return {boolean}
|
|
70
|
+
*/
|
|
71
|
+
function getSpaceGatewayFromEndpoint(endpoint) {
|
|
72
|
+
return endpoint === null || endpoint === void 0 ? void 0 : endpoint.replace(/\/api\/space\/.+/, '');
|
|
73
|
+
}
|