@abtnode/ux 1.16.23-beta-47ca27f8 → 1.16.23-beta-f25d8f54
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/agreement.js +23 -4
- package/es/blocklet/component/related-components-dialog.js +11 -9
- package/es/blocklet/publish/create-release.js +47 -4
- package/es/blocklet/publish/select-components.js +181 -0
- package/es/blocklet/router/rule-list.js +5 -1
- package/es/hooks/blocklet.js +29 -19
- package/es/hooks/use-components-by-blocklet-meta-url.js +1 -1
- package/es/invitation/invitation-receive.js +19 -9
- package/es/invitation/invitation-success.js +1 -1
- package/es/invitation/invitation.js +37 -26
- package/es/issue-passport.js +1 -2
- package/es/locales/ar.js +24 -2
- package/es/locales/de.js +24 -2
- package/es/locales/en.js +15 -2
- package/es/locales/es.js +24 -2
- package/es/locales/fr.js +24 -2
- package/es/locales/hi.js +24 -2
- package/es/locales/i18n.db +0 -0
- package/es/locales/id.js +24 -2
- package/es/locales/ja.js +24 -2
- package/es/locales/ko.js +24 -2
- package/es/locales/pt.js +24 -2
- package/es/locales/ru.js +24 -2
- package/es/locales/th.js +24 -2
- package/es/locales/vi.js +24 -2
- package/es/locales/zh-tw.js +24 -2
- package/es/locales/zh.js +17 -2
- package/es/util/storage-ttl.js +78 -0
- package/lib/blocklet/agreement.js +23 -4
- package/lib/blocklet/component/related-components-dialog.js +13 -9
- package/lib/blocklet/publish/create-release.js +47 -5
- package/lib/blocklet/publish/select-components.js +175 -0
- package/lib/blocklet/router/rule-list.js +5 -1
- package/lib/hooks/blocklet.js +37 -24
- package/lib/hooks/use-components-by-blocklet-meta-url.js +1 -1
- package/lib/invitation/invitation-receive.js +21 -9
- package/lib/invitation/invitation-success.js +1 -1
- package/lib/invitation/invitation.js +37 -26
- package/lib/issue-passport.js +6 -7
- package/lib/locales/ar.js +24 -2
- package/lib/locales/de.js +24 -2
- package/lib/locales/en.js +15 -2
- package/lib/locales/es.js +24 -2
- package/lib/locales/fr.js +24 -2
- package/lib/locales/hi.js +24 -2
- package/lib/locales/i18n.db +0 -0
- package/lib/locales/id.js +24 -2
- package/lib/locales/ja.js +24 -2
- package/lib/locales/ko.js +24 -2
- package/lib/locales/pt.js +24 -2
- package/lib/locales/ru.js +24 -2
- package/lib/locales/th.js +24 -2
- package/lib/locales/vi.js +24 -2
- package/lib/locales/zh-tw.js +24 -2
- package/lib/locales/zh.js +17 -2
- package/lib/util/storage-ttl.js +89 -0
- package/package.json +15 -15
package/es/blocklet/agreement.js
CHANGED
|
@@ -9,6 +9,7 @@ import { Box, Checkbox, FormControlLabel, IconButton } from '@mui/material';
|
|
|
9
9
|
import { useState } from 'react';
|
|
10
10
|
import AgreementApp from './agreement-app';
|
|
11
11
|
import RelatedComponentsDialog from './component/related-components-dialog';
|
|
12
|
+
import useComponentsByBlockletMetaUrl from '../hooks/use-components-by-blocklet-meta-url';
|
|
12
13
|
|
|
13
14
|
// TODO: 加载 Blocklet 定义的 Agreement
|
|
14
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -26,6 +27,10 @@ export default function Agreement({
|
|
|
26
27
|
locale
|
|
27
28
|
} = useLocaleContext();
|
|
28
29
|
const [showDependencies, setShowDependencies] = useState(false);
|
|
30
|
+
const {
|
|
31
|
+
components,
|
|
32
|
+
loading
|
|
33
|
+
} = useComponentsByBlockletMetaUrl(meta);
|
|
29
34
|
const clickNext = onClickNext || (() => {
|
|
30
35
|
navigate(`/launch-blocklet/install${window.location.search}`);
|
|
31
36
|
});
|
|
@@ -51,9 +56,21 @@ export default function Agreement({
|
|
|
51
56
|
})
|
|
52
57
|
})
|
|
53
58
|
})
|
|
54
|
-
}), /*#__PURE__*/_jsxs(
|
|
59
|
+
}), /*#__PURE__*/_jsxs(Box, {
|
|
55
60
|
className: "agreement-bottom",
|
|
56
|
-
|
|
61
|
+
sx: {
|
|
62
|
+
'> .agreement-loading': {
|
|
63
|
+
color: 'primary.main'
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
children: [loading ? /*#__PURE__*/_jsx(Icon, {
|
|
67
|
+
className: "agreement-loading",
|
|
68
|
+
icon: "line-md:loading-loop",
|
|
69
|
+
style: {
|
|
70
|
+
fontSize: 42,
|
|
71
|
+
transform: 'scale(0.6)'
|
|
72
|
+
}
|
|
73
|
+
}) : null, onChangeInstallRelated && components?.length ? /*#__PURE__*/_jsxs(Box, {
|
|
57
74
|
sx: {
|
|
58
75
|
display: 'flex',
|
|
59
76
|
flexDirection: 'row',
|
|
@@ -84,7 +101,7 @@ export default function Agreement({
|
|
|
84
101
|
})
|
|
85
102
|
})
|
|
86
103
|
})]
|
|
87
|
-
}), /*#__PURE__*/_jsx("div", {
|
|
104
|
+
}) : null, /*#__PURE__*/_jsx("div", {
|
|
88
105
|
className: "button-container",
|
|
89
106
|
"data-cy": "agree-all",
|
|
90
107
|
children: /*#__PURE__*/_jsx(ServerEula, {
|
|
@@ -100,7 +117,9 @@ export default function Agreement({
|
|
|
100
117
|
installRelated: installRelated,
|
|
101
118
|
meta: meta,
|
|
102
119
|
show: showDependencies,
|
|
103
|
-
onClose: handleHiddenDependencies
|
|
120
|
+
onClose: handleHiddenDependencies,
|
|
121
|
+
components: components,
|
|
122
|
+
loading: loading
|
|
104
123
|
})]
|
|
105
124
|
});
|
|
106
125
|
}
|
|
@@ -4,23 +4,23 @@ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
|
4
4
|
import { Box, useMediaQuery } from '@mui/material';
|
|
5
5
|
import { Icon } from '@iconify/react';
|
|
6
6
|
import { useMemo } from 'react';
|
|
7
|
-
import useComponentsByBlockletMetaUrl from '../../hooks/use-components-by-blocklet-meta-url';
|
|
8
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
8
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
function parseLogoUrl(component) {
|
|
10
|
+
return `${component.bundleSource?.store || component.meta.homepage}/assets/${component.meta?.did}/${component.meta?.logo || 'logo.png'}?v=${component.meta?.version}`;
|
|
11
|
+
}
|
|
10
12
|
export default function RelatedComponentsDialog({
|
|
11
13
|
installRelated,
|
|
12
14
|
meta,
|
|
13
15
|
show,
|
|
14
|
-
onClose
|
|
16
|
+
onClose,
|
|
17
|
+
components,
|
|
18
|
+
loading
|
|
15
19
|
}) {
|
|
16
20
|
const {
|
|
17
21
|
t
|
|
18
22
|
} = useLocaleContext();
|
|
19
23
|
const isMobile = useMediaQuery(theme => theme.breakpoints.down('md'));
|
|
20
|
-
const {
|
|
21
|
-
components,
|
|
22
|
-
loading
|
|
23
|
-
} = useComponentsByBlockletMetaUrl(meta);
|
|
24
24
|
const requiredList = useMemo(() => {
|
|
25
25
|
if (!meta || !meta.components) {
|
|
26
26
|
return {};
|
|
@@ -119,7 +119,7 @@ export default function RelatedComponentsDialog({
|
|
|
119
119
|
minWidth: size,
|
|
120
120
|
minHeight: size
|
|
121
121
|
},
|
|
122
|
-
src:
|
|
122
|
+
src: parseLogoUrl(component),
|
|
123
123
|
alt: component.meta.title
|
|
124
124
|
}), /*#__PURE__*/_jsxs(Box, {
|
|
125
125
|
sx: {
|
|
@@ -142,7 +142,7 @@ export default function RelatedComponentsDialog({
|
|
|
142
142
|
}
|
|
143
143
|
},
|
|
144
144
|
onClick: () => {
|
|
145
|
-
window.open(`${component.meta.homepage}/blocklets/${component.meta.did}`, '_blank');
|
|
145
|
+
window.open(`${component.bundleSource?.store || component.meta.homepage}/blocklets/${component.meta.did}`, '_blank');
|
|
146
146
|
},
|
|
147
147
|
children: [component.meta.title, /*#__PURE__*/_jsxs(Box, {
|
|
148
148
|
sx: {
|
|
@@ -180,7 +180,9 @@ RelatedComponentsDialog.propTypes = {
|
|
|
180
180
|
meta: PropTypes.object,
|
|
181
181
|
show: PropTypes.bool,
|
|
182
182
|
onClose: PropTypes.func.isRequired,
|
|
183
|
-
installRelated: PropTypes.func
|
|
183
|
+
installRelated: PropTypes.func,
|
|
184
|
+
components: PropTypes.array.isRequired,
|
|
185
|
+
loading: PropTypes.bool.isRequired
|
|
184
186
|
};
|
|
185
187
|
RelatedComponentsDialog.defaultProps = {
|
|
186
188
|
meta: null,
|
|
@@ -30,6 +30,7 @@ import EmptySpinner from '../../empty-spinner';
|
|
|
30
30
|
import ClickToCopy from '../../click-to-copy';
|
|
31
31
|
import { formatError } from '../../util';
|
|
32
32
|
import Resource from './resource';
|
|
33
|
+
import SelectComponents from './select-components';
|
|
33
34
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
34
35
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
35
36
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
@@ -103,9 +104,21 @@ const addComponentTabs = ({
|
|
|
103
104
|
value: key
|
|
104
105
|
});
|
|
105
106
|
};
|
|
106
|
-
const pickParams = release => {
|
|
107
|
-
const params = pick(release, ['blockletVersion', 'blockletTitle', 'blockletDescription', 'blockletLogo', 'blockletIntroduction', 'blockletScreenshots', 'note']);
|
|
107
|
+
const pickParams = (release, app) => {
|
|
108
|
+
const params = pick(release, ['blockletVersion', 'blockletTitle', 'blockletDescription', 'blockletLogo', 'blockletIntroduction', 'blockletScreenshots', 'blockletComponents', 'note']);
|
|
108
109
|
params.blockletScreenshots ||= [];
|
|
110
|
+
if (!params.blockletComponents) {
|
|
111
|
+
params.blockletComponents = (app.children || []).map(x => ({
|
|
112
|
+
did: x.meta.did,
|
|
113
|
+
included: true,
|
|
114
|
+
required: true
|
|
115
|
+
}));
|
|
116
|
+
} else {
|
|
117
|
+
params.blockletComponents = params.blockletComponents.map(x => ({
|
|
118
|
+
...x,
|
|
119
|
+
included: true
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
109
122
|
return params;
|
|
110
123
|
};
|
|
111
124
|
export default function CreateRelease({
|
|
@@ -170,7 +183,7 @@ export default function CreateRelease({
|
|
|
170
183
|
} else if (semver.valid(data.blockletVersion)) {
|
|
171
184
|
data.blockletVersion = semver.inc(data.blockletVersion, 'patch');
|
|
172
185
|
}
|
|
173
|
-
setParams(pickParams(data));
|
|
186
|
+
setParams(pickParams(data, blocklet));
|
|
174
187
|
setProjectType(data.type);
|
|
175
188
|
}).catch(err => {
|
|
176
189
|
setLoading(false);
|
|
@@ -186,7 +199,7 @@ export default function CreateRelease({
|
|
|
186
199
|
}
|
|
187
200
|
}).then(res => {
|
|
188
201
|
setLoading(false);
|
|
189
|
-
setParams(pickParams(res?.release));
|
|
202
|
+
setParams(pickParams(res?.release, blocklet));
|
|
190
203
|
setRelease(res?.release);
|
|
191
204
|
}).catch(err => {
|
|
192
205
|
setLoading(false);
|
|
@@ -237,6 +250,11 @@ export default function CreateRelease({
|
|
|
237
250
|
_params.blockletDescription = (_params.blockletDescription || '').trim();
|
|
238
251
|
_params.blockletIntroduction = (_params.blockletIntroduction || '').trim();
|
|
239
252
|
_params.note = (_params.note || '').trim();
|
|
253
|
+
if (projectType === 'pack') {
|
|
254
|
+
_params.blockletComponents = (_params.blockletComponents || []).filter(x => x.included).map(x => pick(x, ['did', 'required'])).map(JSON.stringify);
|
|
255
|
+
} else {
|
|
256
|
+
delete _params.blockletComponents;
|
|
257
|
+
}
|
|
240
258
|
setCreateLoading(status);
|
|
241
259
|
setLoading(true);
|
|
242
260
|
api.createRelease({
|
|
@@ -762,6 +780,31 @@ export default function CreateRelease({
|
|
|
762
780
|
children: resourceContent
|
|
763
781
|
})]
|
|
764
782
|
})]
|
|
783
|
+
}), projectType === 'pack' && /*#__PURE__*/_jsxs(Box, {
|
|
784
|
+
display: "flex",
|
|
785
|
+
mt: 3,
|
|
786
|
+
className: "section full-width",
|
|
787
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
|
788
|
+
className: "left",
|
|
789
|
+
children: /*#__PURE__*/_jsx(Typography, {
|
|
790
|
+
variant: "h3",
|
|
791
|
+
children: t('common.components')
|
|
792
|
+
})
|
|
793
|
+
}), /*#__PURE__*/_jsx(Box, {
|
|
794
|
+
sx: {
|
|
795
|
+
flex: 1
|
|
796
|
+
},
|
|
797
|
+
children: /*#__PURE__*/_jsx(SelectComponents, {
|
|
798
|
+
disabled: loading || readOnly,
|
|
799
|
+
app: blocklet,
|
|
800
|
+
value: params.blockletComponents,
|
|
801
|
+
onChange: data => {
|
|
802
|
+
setParams({
|
|
803
|
+
blockletComponents: data
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
})
|
|
807
|
+
})]
|
|
765
808
|
})]
|
|
766
809
|
})]
|
|
767
810
|
});
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import styled from '@emotion/styled';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import pick from 'lodash/pick';
|
|
6
|
+
import Checkbox from '@mui/material/Checkbox';
|
|
7
|
+
import Box from '@mui/material/Box';
|
|
8
|
+
import Datatable from '@arcblock/ux/lib/Datatable';
|
|
9
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
10
|
+
import BlockletBundleAvatar from '../bundle-avatar';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
export default function SelectComponents({
|
|
14
|
+
value,
|
|
15
|
+
app,
|
|
16
|
+
onChange,
|
|
17
|
+
disabled
|
|
18
|
+
}) {
|
|
19
|
+
const {
|
|
20
|
+
t,
|
|
21
|
+
locale
|
|
22
|
+
} = useLocaleContext();
|
|
23
|
+
const components = app.children || [];
|
|
24
|
+
const list = useMemo(() => app.children.map(component => {
|
|
25
|
+
const exist = value.find(item => item.did === component.meta.did);
|
|
26
|
+
return exist || {
|
|
27
|
+
did: component.meta.did
|
|
28
|
+
};
|
|
29
|
+
}), [app, value]);
|
|
30
|
+
const map = list.reduce((acc, curr) => {
|
|
31
|
+
acc[curr.did] = pick(curr, ['required', 'included']);
|
|
32
|
+
return acc;
|
|
33
|
+
}, {});
|
|
34
|
+
const toggleIncluded = did => {
|
|
35
|
+
const newValue = list.map(item => {
|
|
36
|
+
if (item.did === did) {
|
|
37
|
+
const included = !item.included;
|
|
38
|
+
return {
|
|
39
|
+
...item,
|
|
40
|
+
included,
|
|
41
|
+
required: included
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return item;
|
|
45
|
+
});
|
|
46
|
+
onChange(newValue);
|
|
47
|
+
};
|
|
48
|
+
const toggleRequired = did => {
|
|
49
|
+
const newValue = list.map(item => {
|
|
50
|
+
if (item.did === did) {
|
|
51
|
+
return {
|
|
52
|
+
...item,
|
|
53
|
+
required: !item.required
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return item;
|
|
57
|
+
});
|
|
58
|
+
onChange(newValue);
|
|
59
|
+
};
|
|
60
|
+
const columns = [{
|
|
61
|
+
label: t('common.name'),
|
|
62
|
+
name: 'meta.title',
|
|
63
|
+
width: 200,
|
|
64
|
+
options: {
|
|
65
|
+
// eslint-disable-next-line react/no-unstable-nested-components
|
|
66
|
+
customBodyRenderLite: rawIndex => {
|
|
67
|
+
const component = components[rawIndex];
|
|
68
|
+
const included = map[component.meta.did]?.included;
|
|
69
|
+
return /*#__PURE__*/_jsxs(Box, {
|
|
70
|
+
display: "flex",
|
|
71
|
+
alignItems: "center",
|
|
72
|
+
children: [/*#__PURE__*/_jsx(BlockletBundleAvatar, {
|
|
73
|
+
size: 24,
|
|
74
|
+
blocklet: component,
|
|
75
|
+
ancestors: [app]
|
|
76
|
+
}), /*#__PURE__*/_jsx(Box, {
|
|
77
|
+
ml: "4px",
|
|
78
|
+
className: classnames('text', {
|
|
79
|
+
excluded: !included
|
|
80
|
+
}),
|
|
81
|
+
children: /*#__PURE__*/_jsx(Box, {
|
|
82
|
+
children: component.meta.title
|
|
83
|
+
})
|
|
84
|
+
})]
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, {
|
|
89
|
+
label: t('blocklet.publish.componentIncluded'),
|
|
90
|
+
width: 100,
|
|
91
|
+
options: {
|
|
92
|
+
// eslint-disable-next-line react/no-unstable-nested-components
|
|
93
|
+
customBodyRenderLite: rawIndex => {
|
|
94
|
+
const component = components[rawIndex];
|
|
95
|
+
const included = map[component.meta.did]?.included;
|
|
96
|
+
return /*#__PURE__*/_jsx(Checkbox, {
|
|
97
|
+
size: "small",
|
|
98
|
+
checked: included,
|
|
99
|
+
onClick: () => toggleIncluded(component.meta.did),
|
|
100
|
+
disabled: disabled
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}, {
|
|
105
|
+
label: t('blocklet.publish.componentForceRequired'),
|
|
106
|
+
width: 100,
|
|
107
|
+
options: {
|
|
108
|
+
// eslint-disable-next-line react/no-unstable-nested-components
|
|
109
|
+
customBodyRenderLite: rawIndex => {
|
|
110
|
+
const component = components[rawIndex];
|
|
111
|
+
const included = map[component.meta.did]?.included;
|
|
112
|
+
const required = map[component.meta.did]?.required;
|
|
113
|
+
return /*#__PURE__*/_jsx(Checkbox, {
|
|
114
|
+
disabled: disabled || !included,
|
|
115
|
+
size: "small",
|
|
116
|
+
checked: required && included,
|
|
117
|
+
onClick: () => toggleRequired(component.meta.did)
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}];
|
|
122
|
+
return /*#__PURE__*/_jsx(Root, {
|
|
123
|
+
children: /*#__PURE__*/_jsx(Datatable, {
|
|
124
|
+
className: "main-table",
|
|
125
|
+
verticalKeyWidth: 100,
|
|
126
|
+
locale: locale,
|
|
127
|
+
data: components,
|
|
128
|
+
columns: columns,
|
|
129
|
+
options: {
|
|
130
|
+
sort: false,
|
|
131
|
+
download: false,
|
|
132
|
+
filter: false,
|
|
133
|
+
print: false,
|
|
134
|
+
search: false,
|
|
135
|
+
rowsPerPage: 100
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
SelectComponents.propTypes = {
|
|
141
|
+
app: PropTypes.object.isRequired,
|
|
142
|
+
value: PropTypes.arrayOf(PropTypes.shape({
|
|
143
|
+
did: PropTypes.string.isRequired,
|
|
144
|
+
required: PropTypes.bool,
|
|
145
|
+
included: PropTypes.bool
|
|
146
|
+
})),
|
|
147
|
+
onChange: PropTypes.func,
|
|
148
|
+
disabled: PropTypes.bool
|
|
149
|
+
};
|
|
150
|
+
SelectComponents.defaultProps = {
|
|
151
|
+
value: [],
|
|
152
|
+
onChange: () => {},
|
|
153
|
+
disabled: false
|
|
154
|
+
};
|
|
155
|
+
const Root = styled(Box)`
|
|
156
|
+
.main-table {
|
|
157
|
+
.text.excluded {
|
|
158
|
+
color: #999;
|
|
159
|
+
}
|
|
160
|
+
width: 400px;
|
|
161
|
+
${({
|
|
162
|
+
theme
|
|
163
|
+
}) => theme.breakpoints.down('md')} {
|
|
164
|
+
width: 100%;
|
|
165
|
+
}
|
|
166
|
+
> div:first-child {
|
|
167
|
+
display: none;
|
|
168
|
+
}
|
|
169
|
+
.MuiTableCell-head {
|
|
170
|
+
padding-top: 0;
|
|
171
|
+
padding-bottom: 0;
|
|
172
|
+
}
|
|
173
|
+
.MuiTableCell-body {
|
|
174
|
+
padding-top: 6px;
|
|
175
|
+
padding-bottom: 6px;
|
|
176
|
+
}
|
|
177
|
+
.datatable-footer {
|
|
178
|
+
display: none;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
`;
|
|
@@ -116,7 +116,11 @@ function RuleList({
|
|
|
116
116
|
}), typeof avatar === 'object' ? avatar : /*#__PURE__*/_jsx(Avatar, {
|
|
117
117
|
children: avatar
|
|
118
118
|
}), /*#__PURE__*/_jsxs(Box, {
|
|
119
|
-
|
|
119
|
+
sx: {
|
|
120
|
+
ml: 2,
|
|
121
|
+
flex: 1,
|
|
122
|
+
wordBreak: 'break-word'
|
|
123
|
+
},
|
|
120
124
|
children: [/*#__PURE__*/_jsxs(Box, {
|
|
121
125
|
style: {
|
|
122
126
|
color: '#222',
|
package/es/hooks/blocklet.js
CHANGED
|
@@ -7,9 +7,9 @@ import { toSlotDomain, getBlockletUrlParams, getBlockletUrl } from '../util';
|
|
|
7
7
|
import { fixBlocklet } from '../blocklet/util';
|
|
8
8
|
import { useDomainsAccessibility } from './url-evaluation';
|
|
9
9
|
import parseProgress from '../util/parse-progress';
|
|
10
|
+
import { getStorageWithTTL, removeStorageTTL, setStorageWithTTL } from '../util/storage-ttl';
|
|
11
|
+
const parseStatusKey = id => `blocklet-status-${id}`;
|
|
10
12
|
const excludeDownloadingStatus = {
|
|
11
|
-
waiting: 1,
|
|
12
|
-
installing: 1,
|
|
13
13
|
installed: 1,
|
|
14
14
|
starting: 1,
|
|
15
15
|
running: 1,
|
|
@@ -18,6 +18,26 @@ const excludeDownloadingStatus = {
|
|
|
18
18
|
restarting: 1,
|
|
19
19
|
deleting: 1
|
|
20
20
|
};
|
|
21
|
+
function rollbackSessionBlockletStatus(blocklet) {
|
|
22
|
+
if (blocklet) {
|
|
23
|
+
const children = blocklet.children || [];
|
|
24
|
+
let isExtracting = false;
|
|
25
|
+
children.forEach(item => {
|
|
26
|
+
if (item.status === 'downloading') {
|
|
27
|
+
const status = getStorageWithTTL(parseStatusKey(item.meta?.bundleDid));
|
|
28
|
+
item.status = status || item.status;
|
|
29
|
+
if (status === 'extracting') {
|
|
30
|
+
isExtracting = true;
|
|
31
|
+
}
|
|
32
|
+
} else if (excludeDownloadingStatus[blocklet.status]) {
|
|
33
|
+
removeStorageTTL(parseStatusKey(item.meta?.bundleDid));
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
if (isExtracting) {
|
|
37
|
+
blocklet.status = 'extracting';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
21
41
|
|
|
22
42
|
// eslint-disable-next-line import/prefer-default-export
|
|
23
43
|
export function useBlocklet({
|
|
@@ -62,6 +82,7 @@ export function useBlocklet({
|
|
|
62
82
|
await fixBlocklet(data, {
|
|
63
83
|
getIP
|
|
64
84
|
});
|
|
85
|
+
rollbackSessionBlockletStatus(data);
|
|
65
86
|
setBlocklet(data);
|
|
66
87
|
} catch (err) {
|
|
67
88
|
Toast.error(err.message);
|
|
@@ -116,12 +137,7 @@ export function useBlocklet({
|
|
|
116
137
|
fixRuntime: 'merge-old',
|
|
117
138
|
oldBlocklet
|
|
118
139
|
});
|
|
119
|
-
|
|
120
|
-
oldBlocklet?.children?.forEach(item => {
|
|
121
|
-
delete item.progress;
|
|
122
|
-
});
|
|
123
|
-
delete oldBlocklet.progress;
|
|
124
|
-
}
|
|
140
|
+
rollbackSessionBlockletStatus(data);
|
|
125
141
|
return data;
|
|
126
142
|
});
|
|
127
143
|
setLoading(false);
|
|
@@ -167,21 +183,14 @@ export function useBlocklet({
|
|
|
167
183
|
const children = oldBlocklet.children || [];
|
|
168
184
|
children.forEach(x => {
|
|
169
185
|
if (x.meta?.bundleDid === data.component?.did) {
|
|
186
|
+
setStorageWithTTL(parseStatusKey(x.meta?.bundleDid), data.status, 1000 * 60 * 5);
|
|
170
187
|
x.status = data.status;
|
|
171
188
|
}
|
|
172
189
|
});
|
|
173
|
-
|
|
174
|
-
// 判断当前下载的 children 是否都处于 extracting
|
|
175
|
-
const extracting = children.every(x => {
|
|
176
|
-
if (excludeDownloadingStatus[x.status]) {
|
|
177
|
-
return true;
|
|
178
|
-
}
|
|
179
|
-
return x.status === 'extracting';
|
|
180
|
-
});
|
|
181
190
|
return {
|
|
182
191
|
...oldBlocklet,
|
|
183
192
|
children,
|
|
184
|
-
status:
|
|
193
|
+
status: data.status
|
|
185
194
|
};
|
|
186
195
|
});
|
|
187
196
|
}
|
|
@@ -193,14 +202,15 @@ export function useBlocklet({
|
|
|
193
202
|
|
|
194
203
|
// keep largest files as progress
|
|
195
204
|
const children = oldBlocklet.children || [];
|
|
196
|
-
let progress =
|
|
205
|
+
let progress = oldBlocklet.progress || 0;
|
|
197
206
|
children.forEach(item => {
|
|
198
207
|
if (item.meta?.bundleDid === data.component?.did) {
|
|
199
208
|
item.progress = parseProgress(data.current, data.total);
|
|
200
209
|
item.status = data.status;
|
|
201
|
-
if (item.progress
|
|
210
|
+
if (item.progress > progress) {
|
|
202
211
|
progress = item.progress;
|
|
203
212
|
}
|
|
213
|
+
removeStorageTTL(parseStatusKey(item.meta?.bundleDid));
|
|
204
214
|
}
|
|
205
215
|
});
|
|
206
216
|
return {
|
|
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
|
|
|
2
2
|
import { useSearchParams } from 'react-router-dom';
|
|
3
3
|
import { useNodeContext } from '../contexts/node';
|
|
4
4
|
function parseBlockletMetaUrl(meta) {
|
|
5
|
-
return meta && meta.homepage && meta.did ? `${meta
|
|
5
|
+
return meta && (meta.registryUrl || meta.homepage) && meta.did ? `${meta.registryUrl || meta.homepage}/api/blocklets/${meta?.did}/blocklet.json` : '';
|
|
6
6
|
}
|
|
7
7
|
function useComponentsByBlockletMetaUrl(meta) {
|
|
8
8
|
const {
|
|
@@ -14,7 +14,8 @@ function InvitationReceive({
|
|
|
14
14
|
invitation,
|
|
15
15
|
onLogin,
|
|
16
16
|
onReceive,
|
|
17
|
-
inService
|
|
17
|
+
inService,
|
|
18
|
+
action
|
|
18
19
|
}) {
|
|
19
20
|
const {
|
|
20
21
|
t,
|
|
@@ -30,13 +31,20 @@ function InvitationReceive({
|
|
|
30
31
|
if (typeof window !== 'undefined') {
|
|
31
32
|
componentId = window?.blocklet?.componentId;
|
|
32
33
|
}
|
|
34
|
+
const passportId = getPassportId();
|
|
33
35
|
const extraParams = {
|
|
34
|
-
passportId: getPassportId(),
|
|
35
|
-
inviteId: invitation.inviteId,
|
|
36
36
|
// 生成 passport 信息需要 baseUrl 字段
|
|
37
37
|
baseUrl: window.location.origin,
|
|
38
38
|
componentId
|
|
39
39
|
};
|
|
40
|
+
if (passportId) {
|
|
41
|
+
extraParams.passportId = passportId;
|
|
42
|
+
}
|
|
43
|
+
if (action === 'invite') {
|
|
44
|
+
extraParams.inviteId = invitation.inviteId;
|
|
45
|
+
} else if (action === 'issue-passport') {
|
|
46
|
+
extraParams.id = invitation.inviteId;
|
|
47
|
+
}
|
|
40
48
|
const onClose = useCallback(() => {
|
|
41
49
|
connectApi.close();
|
|
42
50
|
}, [connectApi]);
|
|
@@ -51,9 +59,9 @@ function InvitationReceive({
|
|
|
51
59
|
}
|
|
52
60
|
if (inService) {
|
|
53
61
|
connectApi.openPopup({
|
|
54
|
-
action
|
|
62
|
+
action,
|
|
55
63
|
className: 'connect',
|
|
56
|
-
forceConnected: false,
|
|
64
|
+
forceConnected: invitation?.receiver?.did || false,
|
|
57
65
|
autoConnect: false,
|
|
58
66
|
locale,
|
|
59
67
|
extraParams: {
|
|
@@ -75,9 +83,9 @@ function InvitationReceive({
|
|
|
75
83
|
});
|
|
76
84
|
} else {
|
|
77
85
|
connectApi.open({
|
|
78
|
-
action
|
|
86
|
+
action,
|
|
79
87
|
className: 'connect',
|
|
80
|
-
forceConnected: false,
|
|
88
|
+
forceConnected: invitation?.receiver?.did || false,
|
|
81
89
|
autoConnect: false,
|
|
82
90
|
locale,
|
|
83
91
|
extraParams,
|
|
@@ -113,12 +121,14 @@ InvitationReceive.propTypes = {
|
|
|
113
121
|
invitation: PropTypes.object.isRequired,
|
|
114
122
|
onLogin: PropTypes.func,
|
|
115
123
|
onReceive: PropTypes.func,
|
|
116
|
-
inService: PropTypes.bool
|
|
124
|
+
inService: PropTypes.bool,
|
|
125
|
+
action: PropTypes.oneOf(['invite', 'issue-passport'])
|
|
117
126
|
};
|
|
118
127
|
InvitationReceive.defaultProps = {
|
|
119
128
|
onLogin: () => {},
|
|
120
129
|
onReceive: null,
|
|
121
|
-
inService: false
|
|
130
|
+
inService: false,
|
|
131
|
+
action: 'invite'
|
|
122
132
|
};
|
|
123
133
|
const Root = styled.div`
|
|
124
134
|
text-align: center;
|
|
@@ -59,7 +59,7 @@ function InvitationSuccess({
|
|
|
59
59
|
}
|
|
60
60
|
InvitationSuccess.propTypes = {
|
|
61
61
|
invitation: PropTypes.object.isRequired,
|
|
62
|
-
type: PropTypes.oneOf('inviter', 'receiver')
|
|
62
|
+
type: PropTypes.oneOf(['inviter', 'receiver'])
|
|
63
63
|
};
|
|
64
64
|
InvitationSuccess.defaultProps = {
|
|
65
65
|
type: 'inviter'
|