@abtnode/ux 1.16.19-beta-7d3ef675 → 1.16.19-beta-ba354e01
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/es/blocklet/component/add-component-core.js +35 -27
- package/es/blocklet/component/button.js +12 -0
- package/es/blocklet/component/did-space/connect-to.js +355 -0
- package/es/blocklet/component/did-space/connected.js +42 -0
- package/es/blocklet/component/did-space/delete.js +104 -0
- package/es/blocklet/component/did-space/disconnect.js +230 -0
- package/es/blocklet/component/did-space/index.js +73 -0
- package/es/blocklet/component/did-space/item.js +233 -0
- package/es/blocklet/component/index.js +3 -3
- package/es/blocklet/component/step-actions.js +99 -0
- package/es/blocklet/publish/create-release.js +14 -13
- package/es/blocklet/publish/project-list.js +1 -0
- package/es/blocklet/publish/release-list.js +1 -0
- package/es/blocklet/publish/tree.js +4 -0
- package/es/blocklet/resource-type.js +34 -0
- package/es/blocklet/storage/connect-to.js +11 -15
- package/es/contexts/config-space.js +160 -0
- package/es/hooks/use-mobile.js +17 -0
- package/es/hooks/use-storage-endpoint.js +23 -0
- package/es/images.js +48 -0
- package/es/locales/en.js +2 -0
- package/es/locales/zh.js +2 -0
- package/es/util/index.js +5 -1
- package/es/util/spaces.js +66 -5
- package/lib/blocklet/component/add-component-core.js +44 -36
- package/lib/blocklet/component/button.js +23 -0
- package/lib/blocklet/component/did-space/connect-to.js +362 -0
- package/lib/blocklet/component/did-space/connected.js +49 -0
- package/lib/blocklet/component/did-space/delete.js +111 -0
- package/lib/blocklet/component/did-space/disconnect.js +241 -0
- package/lib/blocklet/component/did-space/index.js +82 -0
- package/lib/blocklet/component/did-space/item.js +197 -0
- package/lib/blocklet/component/index.js +3 -3
- package/lib/blocklet/component/step-actions.js +63 -0
- package/lib/blocklet/publish/create-release.js +14 -13
- package/lib/blocklet/publish/project-list.js +1 -0
- package/lib/blocklet/publish/release-list.js +1 -0
- package/lib/blocklet/publish/tree.js +45 -38
- package/lib/blocklet/resource-type.js +51 -0
- package/lib/blocklet/storage/connect-to.js +11 -15
- package/lib/contexts/config-space.js +169 -0
- package/lib/hooks/use-mobile.js +24 -0
- package/lib/hooks/use-storage-endpoint.js +28 -0
- package/lib/images.js +51 -0
- package/lib/locales/en.js +2 -0
- package/lib/locales/zh.js +2 -0
- package/lib/util/index.js +8 -2
- package/lib/util/spaces.js +69 -3
- package/package.json +11 -7
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ConfigSpaceContext = exports.ConfigSpaceConsumer = void 0;
|
|
7
|
+
exports.ConfigSpaceProvider = ConfigSpaceProvider;
|
|
8
|
+
exports.useConfigSpaceContext = useConfigSpaceContext;
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _propTypes = require("prop-types");
|
|
11
|
+
var _lodash = require("lodash");
|
|
12
|
+
var _constant = require("@blocklet/constant");
|
|
13
|
+
var _ahooks = require("ahooks");
|
|
14
|
+
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
15
|
+
var _node = require("./node");
|
|
16
|
+
var _spaces = require("../util/spaces");
|
|
17
|
+
var _blocklet = require("./blocklet");
|
|
18
|
+
var _useStorageEndpoint = _interopRequireDefault(require("../hooks/use-storage-endpoint"));
|
|
19
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {{
|
|
23
|
+
* did: string,
|
|
24
|
+
* url: string,
|
|
25
|
+
* name: string,
|
|
26
|
+
* endpoint: string,
|
|
27
|
+
* }} SpaceGateway
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {{
|
|
32
|
+
* loading: boolean,
|
|
33
|
+
* spaceGateway: SpaceGateway,
|
|
34
|
+
* deleteSpaceGateway: (spaceGateway: SpaceGateway) => void | Promise<void>,
|
|
35
|
+
* updateSpaceGateway: (updateSpaceGateway: SpaceGateway) => void | Promise<void>,
|
|
36
|
+
* storageEndpoint: string,
|
|
37
|
+
* settingStorageEndpoint: (endpoint: string) => void | Promise<void>,
|
|
38
|
+
* hasStorageEndpoint: boolean,
|
|
39
|
+
* }} ConfigSpaceContextType
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/** @type {import('react').Context<ConfigSpaceContextType>} */const ConfigSpaceContext = /*#__PURE__*/(0, _react.createContext)({});
|
|
43
|
+
exports.ConfigSpaceContext = ConfigSpaceContext;
|
|
44
|
+
const {
|
|
45
|
+
Provider,
|
|
46
|
+
Consumer
|
|
47
|
+
} = ConfigSpaceContext;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @description
|
|
51
|
+
* @param {{
|
|
52
|
+
* children: React.ReactNode,
|
|
53
|
+
* }} { children }
|
|
54
|
+
* @return {any}
|
|
55
|
+
*/
|
|
56
|
+
exports.ConfigSpaceConsumer = Consumer;
|
|
57
|
+
function ConfigSpaceProvider(_ref) {
|
|
58
|
+
let {
|
|
59
|
+
children
|
|
60
|
+
} = _ref;
|
|
61
|
+
const [loading, setLoading] = (0, _react.useState)(false);
|
|
62
|
+
const [spaceGateway, setSpaceGateway] = (0, _react.useState)(null);
|
|
63
|
+
/**
|
|
64
|
+
* @type {{
|
|
65
|
+
* blocklet: import('@abtnode/client').BlockletState,
|
|
66
|
+
* actions: { refreshBlocklet: Function }
|
|
67
|
+
* }}
|
|
68
|
+
*/
|
|
69
|
+
const {
|
|
70
|
+
blocklet,
|
|
71
|
+
actions: {
|
|
72
|
+
refreshBlocklet
|
|
73
|
+
}
|
|
74
|
+
} = (0, _blocklet.useBlockletContext)();
|
|
75
|
+
const {
|
|
76
|
+
storageEndpoint
|
|
77
|
+
} = (0, _useStorageEndpoint.default)();
|
|
78
|
+
const {
|
|
79
|
+
api: nodeApi
|
|
80
|
+
} = (0, _node.useNodeContext)();
|
|
81
|
+
(0, _ahooks.useAsyncEffect)(async () => {
|
|
82
|
+
try {
|
|
83
|
+
setLoading(true);
|
|
84
|
+
if ((0, _lodash.isEmpty)(storageEndpoint)) {
|
|
85
|
+
setSpaceGateway(null);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const $spaceGateway = await (0, _spaces.getSpaceGateway)(storageEndpoint);
|
|
89
|
+
setSpaceGateway($spaceGateway);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error(error);
|
|
92
|
+
_Toast.default.error(error.message);
|
|
93
|
+
} finally {
|
|
94
|
+
setLoading(false);
|
|
95
|
+
}
|
|
96
|
+
}, [storageEndpoint]);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @description
|
|
100
|
+
* @param {SpaceGateway} spaceGateway
|
|
101
|
+
*/
|
|
102
|
+
const deleteSpaceGateway = () => {
|
|
103
|
+
setSpaceGateway(null);
|
|
104
|
+
refreshBlocklet();
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @description
|
|
109
|
+
* @param {SpaceGateway} x
|
|
110
|
+
*/
|
|
111
|
+
const updateSpaceGateway = async x => {
|
|
112
|
+
setSpaceGateway(x);
|
|
113
|
+
// eslint-disable-next-line no-use-before-define
|
|
114
|
+
await settingStorageEndpoint(x.endpoint);
|
|
115
|
+
refreshBlocklet();
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @description
|
|
120
|
+
* @param {string} endpoint
|
|
121
|
+
*/
|
|
122
|
+
const settingStorageEndpoint = async endpoint => {
|
|
123
|
+
await nodeApi.configBlocklet({
|
|
124
|
+
input: {
|
|
125
|
+
did: [blocklet.meta.did],
|
|
126
|
+
configs: [{
|
|
127
|
+
key: _constant.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SPACE_ENDPOINT,
|
|
128
|
+
value: endpoint
|
|
129
|
+
}]
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
refreshBlocklet();
|
|
133
|
+
};
|
|
134
|
+
(0, _react.useEffect)(() => {
|
|
135
|
+
async function syncSpaceGateway() {
|
|
136
|
+
if (!spaceGateway) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const name = await (0, _spaces.getSpaceNameByEndpoint)(spaceGateway.endpoint, spaceGateway.name);
|
|
140
|
+
const latestSpaceGateway = (0, _lodash.merge)(spaceGateway, {
|
|
141
|
+
name
|
|
142
|
+
});
|
|
143
|
+
setSpaceGateway(latestSpaceGateway);
|
|
144
|
+
}
|
|
145
|
+
syncSpaceGateway();
|
|
146
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
147
|
+
}, []);
|
|
148
|
+
const hasStorageEndpoint = Boolean(storageEndpoint && spaceGateway);
|
|
149
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Provider, {
|
|
150
|
+
value: {
|
|
151
|
+
loading,
|
|
152
|
+
spaceGateway,
|
|
153
|
+
deleteSpaceGateway,
|
|
154
|
+
updateSpaceGateway,
|
|
155
|
+
storageEndpoint,
|
|
156
|
+
settingStorageEndpoint,
|
|
157
|
+
hasStorageEndpoint
|
|
158
|
+
},
|
|
159
|
+
children: children
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
ConfigSpaceProvider.propTypes = {
|
|
163
|
+
children: _propTypes.node.isRequired
|
|
164
|
+
};
|
|
165
|
+
ConfigSpaceProvider.defaultProps = {};
|
|
166
|
+
function useConfigSpaceContext() {
|
|
167
|
+
const res = (0, _react.useContext)(ConfigSpaceContext);
|
|
168
|
+
return res;
|
|
169
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useMobile;
|
|
7
|
+
var _styles = require("@mui/material/styles");
|
|
8
|
+
var _useMediaQuery = _interopRequireDefault(require("@mui/material/useMediaQuery"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
/**
|
|
11
|
+
* @description
|
|
12
|
+
* @export
|
|
13
|
+
* @param {{ key: string | import('@mui/material').Breakpoint }} [{ key }={ key: 'md' }]
|
|
14
|
+
* @return {*}
|
|
15
|
+
*/
|
|
16
|
+
function useMobile() {
|
|
17
|
+
let {
|
|
18
|
+
key
|
|
19
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
20
|
+
key: 'sm'
|
|
21
|
+
};
|
|
22
|
+
const theme = (0, _styles.useTheme)();
|
|
23
|
+
return (0, _useMediaQuery.default)(theme.breakpoints.down(key));
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useStorageEndpoint;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _blocklet = require("../contexts/blocklet");
|
|
9
|
+
var _spaces = require("../util/spaces");
|
|
10
|
+
/**
|
|
11
|
+
* @description
|
|
12
|
+
* @export
|
|
13
|
+
* @return {{
|
|
14
|
+
* storageEndpoint: string
|
|
15
|
+
* }}
|
|
16
|
+
*/
|
|
17
|
+
function useStorageEndpoint() {
|
|
18
|
+
const [storageEndpoint, setStorageEndpoint] = (0, _react.useState)(null);
|
|
19
|
+
const {
|
|
20
|
+
blocklet
|
|
21
|
+
} = (0, _blocklet.useBlockletContext)();
|
|
22
|
+
(0, _react.useEffect)(() => {
|
|
23
|
+
setStorageEndpoint((0, _spaces.getDIDSpaceEndpoint)(blocklet));
|
|
24
|
+
}, [blocklet]);
|
|
25
|
+
return {
|
|
26
|
+
storageEndpoint
|
|
27
|
+
};
|
|
28
|
+
}
|
package/lib/images.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = Images;
|
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
9
|
+
var _Box = _interopRequireDefault(require("@mui/material/Box"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
var _templateObject;
|
|
12
|
+
const _excluded = ["data"];
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
15
|
+
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; }
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
19
|
+
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); }
|
|
20
|
+
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; }
|
|
21
|
+
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; }
|
|
22
|
+
function Images(_ref) {
|
|
23
|
+
let {
|
|
24
|
+
data
|
|
25
|
+
} = _ref,
|
|
26
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
27
|
+
if (!data || !data.length) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledBox, _objectSpread(_objectSpread({}, props), {}, {
|
|
31
|
+
children: data.map(item => /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
|
|
32
|
+
href: item.url,
|
|
33
|
+
target: "_blank",
|
|
34
|
+
rel: "noreferrer",
|
|
35
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
|
|
36
|
+
src: item.url,
|
|
37
|
+
alt: item.alt || ''
|
|
38
|
+
})
|
|
39
|
+
}, item.url))
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
Images.propTypes = {
|
|
43
|
+
data: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
44
|
+
url: _propTypes.default.string,
|
|
45
|
+
alt: _propTypes.default.string
|
|
46
|
+
}))
|
|
47
|
+
};
|
|
48
|
+
Images.defaultProps = {
|
|
49
|
+
data: []
|
|
50
|
+
};
|
|
51
|
+
const StyledBox = (0, _styled.default)(_Box.default)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n justify-content: flex-start;\n flex-wrap: wrap;\n margin-bottom: -12px;\n a {\n display: flex;\n }\n img {\n height: 128px;\n cursor: pointer;\n margin-right: 12px;\n margin-bottom: 12px;\n }\n"])));
|
package/lib/locales/en.js
CHANGED
|
@@ -640,6 +640,8 @@ module.exports = {
|
|
|
640
640
|
createRelease: 'Create a new release',
|
|
641
641
|
deleteReleaseTip: 'The release cannot be recovered after deletion',
|
|
642
642
|
createBlockletDid: 'Create from DID Wallet',
|
|
643
|
+
createReleaseSuccess: 'Release created successfully',
|
|
644
|
+
saveDraftSuccess: 'Draft saved successfully',
|
|
643
645
|
connect: {
|
|
644
646
|
title: 'Create Blocklet DID',
|
|
645
647
|
scan: 'Scan the QR code below to generate Blocklet DID',
|
package/lib/locales/zh.js
CHANGED
|
@@ -647,6 +647,8 @@ module.exports = {
|
|
|
647
647
|
createRelease: '创建新的发布',
|
|
648
648
|
deleteReleaseTip: '此发布删除后不可恢复,是否继续?',
|
|
649
649
|
createBlockletDid: '通过 DID 钱包创建',
|
|
650
|
+
createReleaseSuccess: '发布成功',
|
|
651
|
+
saveDraftSuccess: '保存成功',
|
|
650
652
|
connect: {
|
|
651
653
|
title: '创建 Blocklet DID',
|
|
652
654
|
scan: '扫描下面的二维码来生成 Blocklet DID',
|
package/lib/util/index.js
CHANGED
|
@@ -32,7 +32,7 @@ exports.getBlockletUrls = getBlockletUrls;
|
|
|
32
32
|
exports.getExplorerLink = getExplorerLink;
|
|
33
33
|
exports.getTransferAppLink = exports.getSystemDomains = exports.getSubscriptionURL = exports.getStoreList = exports.getRenewBlockletURL = exports.getPathPrefix = exports.getLogoHash = exports.getIssuePassportLink = exports.getInviteLink = void 0;
|
|
34
34
|
exports.getWebWalletUrl = getWebWalletUrl;
|
|
35
|
-
exports.isNewStoreUrl = exports.isInstalling = exports.isDownloading = exports.isChrome = exports.isCertificateMatch = exports.isBlockletDev = void 0;
|
|
35
|
+
exports.isNewStoreUrl = exports.isInstalling = exports.isDownloading = exports.isChrome = exports.isCertificateMatch = exports.isBlockletDev = exports.hasRequiredSteps = void 0;
|
|
36
36
|
exports.isProtectedRole = isProtectedRole;
|
|
37
37
|
exports.isUrlAccessible = exports.isSafari = exports.isRunning = void 0;
|
|
38
38
|
exports.isValidClusterSize = isValidClusterSize;
|
|
@@ -729,4 +729,10 @@ exports.nanoid = nanoid;
|
|
|
729
729
|
const getSystemDomains = domains => domains.filter(x => x.isProtected);
|
|
730
730
|
exports.getSystemDomains = getSystemDomains;
|
|
731
731
|
const getLogoHash = logo => encodeURIComponent((logo || '').split('/').slice(-1)[0].slice(0, 7));
|
|
732
|
-
exports.getLogoHash = getLogoHash;
|
|
732
|
+
exports.getLogoHash = getLogoHash;
|
|
733
|
+
const hasRequiredEnvironments = meta => (meta.environments || []).some(x => x.required);
|
|
734
|
+
const hasRequiredSteps = meta => {
|
|
735
|
+
var _meta$requirements, _meta$requirements$fu;
|
|
736
|
+
return !!((_meta$requirements = meta.requirements) !== null && _meta$requirements !== void 0 && (_meta$requirements$fu = _meta$requirements.fuels) !== null && _meta$requirements$fu !== void 0 && _meta$requirements$fu.length) || hasRequiredEnvironments(meta);
|
|
737
|
+
};
|
|
738
|
+
exports.hasRequiredSteps = hasRequiredSteps;
|
package/lib/util/spaces.js
CHANGED
|
@@ -9,7 +9,9 @@ exports.getDIDSpaceDidFromEndpoint = getDIDSpaceDidFromEndpoint;
|
|
|
9
9
|
exports.getDIDSpaceEndpoint = void 0;
|
|
10
10
|
exports.getDIDSpaceUrlFromEndpoint = getDIDSpaceUrlFromEndpoint;
|
|
11
11
|
exports.getSpaceBackupEndpoint = getSpaceBackupEndpoint;
|
|
12
|
+
exports.getSpaceGateway = getSpaceGateway;
|
|
12
13
|
exports.getSpaceGatewayFromEndpoint = getSpaceGatewayFromEndpoint;
|
|
14
|
+
exports.getSpaceGatewayUrl = getSpaceGatewayUrl;
|
|
13
15
|
exports.getSpaceNameByEndpoint = getSpaceNameByEndpoint;
|
|
14
16
|
exports.getSpaceNftDisplayUrlFromEndpoint = getSpaceNftDisplayUrlFromEndpoint;
|
|
15
17
|
exports.hasPermissionByEndpoint = hasPermissionByEndpoint;
|
|
@@ -22,6 +24,10 @@ var _api = require("./api");
|
|
|
22
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
25
|
/* eslint-disable import/prefer-default-export */
|
|
24
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {import('../contexts/config-space').SpaceGateway} SpaceGateway
|
|
29
|
+
*/
|
|
30
|
+
|
|
25
31
|
/**
|
|
26
32
|
* @FIXME 希望之后放在 sdk 中 @jianchao
|
|
27
33
|
* @description
|
|
@@ -99,7 +105,7 @@ function getSpaceBackupEndpoint(environments) {
|
|
|
99
105
|
* @description
|
|
100
106
|
* @export
|
|
101
107
|
* @param {string} endpoint
|
|
102
|
-
* @return {
|
|
108
|
+
* @return {string}
|
|
103
109
|
*/
|
|
104
110
|
function getSpaceGatewayFromEndpoint(endpoint) {
|
|
105
111
|
return endpoint === null || endpoint === void 0 ? void 0 : endpoint.replace(/\/api\/space\/.+/, '');
|
|
@@ -152,6 +158,11 @@ async function isValidSpaceGatewayUrl(spaceGatewayUrl) {
|
|
|
152
158
|
* @return {Promise<string >}
|
|
153
159
|
*/
|
|
154
160
|
async function getSpaceNameByEndpoint(endpoint) {
|
|
161
|
+
let {
|
|
162
|
+
timeout
|
|
163
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
164
|
+
timeout: 3000
|
|
165
|
+
};
|
|
155
166
|
try {
|
|
156
167
|
if (!(0, _isUrl.default)(endpoint)) {
|
|
157
168
|
return '';
|
|
@@ -159,7 +170,7 @@ async function getSpaceNameByEndpoint(endpoint) {
|
|
|
159
170
|
const {
|
|
160
171
|
headers
|
|
161
172
|
} = await _api.api.head(endpoint, {
|
|
162
|
-
timeout
|
|
173
|
+
timeout
|
|
163
174
|
});
|
|
164
175
|
const spaceName = headers['x-space-name'];
|
|
165
176
|
return spaceName ? decodeURIComponent(spaceName) : '';
|
|
@@ -190,4 +201,59 @@ const getDIDSpaceEndpoint = blocklet => {
|
|
|
190
201
|
var _blocklet$configs, _blocklet$configs$fin;
|
|
191
202
|
return (blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$configs = blocklet.configs) === null || _blocklet$configs === void 0 ? void 0 : (_blocklet$configs$fin = _blocklet$configs.find(item => item.key === _constant.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SPACE_ENDPOINT)) === null || _blocklet$configs$fin === void 0 ? void 0 : _blocklet$configs$fin.value) || null;
|
|
192
203
|
};
|
|
193
|
-
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @description
|
|
207
|
+
* @export
|
|
208
|
+
* @param {string} endpoint
|
|
209
|
+
* @returns {Promise<SpaceGateway>}
|
|
210
|
+
*/
|
|
211
|
+
exports.getDIDSpaceEndpoint = getDIDSpaceEndpoint;
|
|
212
|
+
async function getSpaceGateway(endpoint) {
|
|
213
|
+
/** @type {SpaceGateway} */
|
|
214
|
+
const spaceGateway = {};
|
|
215
|
+
spaceGateway.did = getDIDSpaceDidFromEndpoint(endpoint);
|
|
216
|
+
spaceGateway.name = await getSpaceNameByEndpoint(endpoint);
|
|
217
|
+
spaceGateway.url = getSpaceGatewayFromEndpoint(endpoint);
|
|
218
|
+
spaceGateway.endpoint = endpoint;
|
|
219
|
+
return spaceGateway;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* @description
|
|
224
|
+
* @export
|
|
225
|
+
* @param {string} anyUrl
|
|
226
|
+
* @param {{
|
|
227
|
+
* timeout: number,
|
|
228
|
+
* withSearchParams: true | false,
|
|
229
|
+
* }} options
|
|
230
|
+
* @returns {Promise<string>}
|
|
231
|
+
*/
|
|
232
|
+
async function getSpaceGatewayUrl(anyUrl) {
|
|
233
|
+
var _blockletMeta$compone;
|
|
234
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
235
|
+
timeout: 30000,
|
|
236
|
+
withSearchParams: true
|
|
237
|
+
};
|
|
238
|
+
if (!(0, _lodash.isString)(anyUrl)) {
|
|
239
|
+
throw new Error("url(".concat(anyUrl, ") must be a string"));
|
|
240
|
+
}
|
|
241
|
+
const url = anyUrl.startsWith('http') ? anyUrl : "https://".concat(anyUrl);
|
|
242
|
+
const u = new URL(url);
|
|
243
|
+
|
|
244
|
+
/** @type {{ data: import('@blocklet/sdk').WindowBlocklet }} */
|
|
245
|
+
const {
|
|
246
|
+
data: blockletMeta
|
|
247
|
+
} = await _api.api.get((0, _ufo.joinURL)(u.origin, '/__blocklet__.js?type=json'), {
|
|
248
|
+
timeout: options.timeout
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
/** @type {string} */
|
|
252
|
+
const mountPoint = (_blockletMeta$compone = blockletMeta.componentMountPoints.findLast(x => x.did === 'z8iZnaYxnkMD5AKRjTKiCb8pQr1ut8UantAcf')) === null || _blockletMeta$compone === void 0 ? void 0 : _blockletMeta$compone.mountPoint;
|
|
253
|
+
if (!mountPoint) {
|
|
254
|
+
throw new Error("MountPoint(".concat(mountPoint, ") not found"));
|
|
255
|
+
}
|
|
256
|
+
const didSpacesCoreUrl = (0, _ufo.joinURL)(u.origin, mountPoint);
|
|
257
|
+
const spaceGatewayUrl = options.withSearchParams && u.searchParams.get('spaceDid') ? (0, _ufo.joinURL)(didSpacesCoreUrl, "?spaceDid=".concat(u.searchParams.get('spaceDid'))) : didSpacesCoreUrl;
|
|
258
|
+
return spaceGatewayUrl;
|
|
259
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abtnode/ux",
|
|
3
|
-
"version": "1.16.19-beta-
|
|
3
|
+
"version": "1.16.19-beta-ba354e01",
|
|
4
4
|
"description": "UX components shared across abtnode packages",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@abtnode/auth": "1.16.19-beta-
|
|
31
|
-
"@abtnode/constant": "1.16.19-beta-
|
|
32
|
-
"@abtnode/util": "1.16.19-beta-
|
|
30
|
+
"@abtnode/auth": "1.16.19-beta-ba354e01",
|
|
31
|
+
"@abtnode/constant": "1.16.19-beta-ba354e01",
|
|
32
|
+
"@abtnode/util": "1.16.19-beta-ba354e01",
|
|
33
33
|
"@ahooksjs/use-url-state": "^3.5.1",
|
|
34
34
|
"@arcblock/did": "^1.18.95",
|
|
35
35
|
"@arcblock/did-connect": "^2.8.16",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"@arcblock/react-hooks": "^2.8.16",
|
|
40
40
|
"@arcblock/terminal": "^2.8.16",
|
|
41
41
|
"@arcblock/ux": "^2.8.16",
|
|
42
|
-
"@blocklet/constant": "1.16.19-beta-
|
|
42
|
+
"@blocklet/constant": "1.16.19-beta-ba354e01",
|
|
43
43
|
"@blocklet/launcher-layout": "2.2.40",
|
|
44
44
|
"@blocklet/list": "^0.12.53",
|
|
45
|
-
"@blocklet/meta": "1.16.19-beta-
|
|
45
|
+
"@blocklet/meta": "1.16.19-beta-ba354e01",
|
|
46
46
|
"@blocklet/ui-react": "^2.8.16",
|
|
47
47
|
"@blocklet/uploader": "^0.0.45",
|
|
48
48
|
"@emotion/react": "^11.10.4",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"babel-plugin-inline-react-svg": "^1.1.2",
|
|
101
101
|
"glob": "^10.3.3"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "d685f8ca8f2fe49298aa0e94f2f15e1e7ebf761b",
|
|
104
104
|
"exports": {
|
|
105
105
|
".": {
|
|
106
106
|
"import": "./es/index.js",
|
|
@@ -114,6 +114,10 @@
|
|
|
114
114
|
"import": "./es/blocklet/access/index.js",
|
|
115
115
|
"require": "./lib/blocklet/access/index.js"
|
|
116
116
|
},
|
|
117
|
+
"./lib/blocklet/component/did-space": {
|
|
118
|
+
"import": "./es/blocklet/component/did-space/index.js",
|
|
119
|
+
"require": "./lib/blocklet/component/did-space/index.js"
|
|
120
|
+
},
|
|
117
121
|
"./lib/blocklet/component": {
|
|
118
122
|
"import": "./es/blocklet/component/index.js",
|
|
119
123
|
"require": "./lib/blocklet/component/index.js"
|