@blocklet/ui-react 2.9.15 → 2.9.16
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/ComponentInstaller/index.d.ts +45 -0
- package/es/ComponentInstaller/index.js +298 -0
- package/es/ComponentInstaller/locales.d.ts +28 -0
- package/es/ComponentInstaller/locales.js +22 -0
- package/es/ComponentInstaller/use-component-installed.d.ts +15 -0
- package/es/ComponentInstaller/use-component-installed.js +68 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/lib/ComponentInstaller/index.d.ts +45 -0
- package/lib/ComponentInstaller/index.js +381 -0
- package/lib/ComponentInstaller/locales.d.ts +28 -0
- package/lib/ComponentInstaller/locales.js +27 -0
- package/lib/ComponentInstaller/use-component-installed.d.ts +15 -0
- package/lib/ComponentInstaller/use-component-installed.js +78 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +17 -1
- package/package.json +8 -4
- package/src/ComponentInstaller/index.jsx +305 -0
- package/src/ComponentInstaller/locales.js +22 -0
- package/src/ComponentInstaller/use-component-installed.js +68 -0
- package/src/index.ts +4 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export default ComponentInstaller;
|
|
2
|
+
declare function ComponentInstaller({ warnIcon, did, noPermissionMute, onInstalled, onError, children, closeByOutSize, onClose, fallback, roles, }: {
|
|
3
|
+
warnIcon: any;
|
|
4
|
+
did: any;
|
|
5
|
+
noPermissionMute: any;
|
|
6
|
+
onInstalled: any;
|
|
7
|
+
onError: any;
|
|
8
|
+
children: any;
|
|
9
|
+
closeByOutSize: any;
|
|
10
|
+
onClose: any;
|
|
11
|
+
fallback: any;
|
|
12
|
+
roles?: string[] | undefined;
|
|
13
|
+
}): import("react").JSX.Element;
|
|
14
|
+
declare namespace ComponentInstaller {
|
|
15
|
+
namespace propTypes {
|
|
16
|
+
let warnIcon: any;
|
|
17
|
+
let did: any;
|
|
18
|
+
let noPermissionMute: any;
|
|
19
|
+
let onInstalled: any;
|
|
20
|
+
let onError: any;
|
|
21
|
+
let children: any;
|
|
22
|
+
let closeByOutSize: any;
|
|
23
|
+
let onClose: any;
|
|
24
|
+
let fallback: any;
|
|
25
|
+
let roles: any;
|
|
26
|
+
}
|
|
27
|
+
namespace defaultProps {
|
|
28
|
+
let warnIcon_1: null;
|
|
29
|
+
export { warnIcon_1 as warnIcon };
|
|
30
|
+
let noPermissionMute_1: boolean;
|
|
31
|
+
export { noPermissionMute_1 as noPermissionMute };
|
|
32
|
+
let onInstalled_1: null;
|
|
33
|
+
export { onInstalled_1 as onInstalled };
|
|
34
|
+
let onError_1: null;
|
|
35
|
+
export { onError_1 as onError };
|
|
36
|
+
let closeByOutSize_1: boolean;
|
|
37
|
+
export { closeByOutSize_1 as closeByOutSize };
|
|
38
|
+
let onClose_1: null;
|
|
39
|
+
export { onClose_1 as onClose };
|
|
40
|
+
let fallback_1: null;
|
|
41
|
+
export { fallback_1 as fallback };
|
|
42
|
+
let roles_1: string[];
|
|
43
|
+
export { roles_1 as roles };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Box, ClickAwayListener, Fade, Paper } from "@mui/material";
|
|
3
|
+
import { Icon } from "@iconify/react";
|
|
4
|
+
import { temp as colors } from "@arcblock/ux/lib/Colors";
|
|
5
|
+
import { SessionContext } from "@arcblock/did-connect/lib/Session";
|
|
6
|
+
import { useContext } from "react";
|
|
7
|
+
import SessionPermission from "@arcblock/ux/lib/SessionPermission";
|
|
8
|
+
import PropTypes from "prop-types";
|
|
9
|
+
import { useMemoizedFn } from "ahooks";
|
|
10
|
+
import { translate } from "@arcblock/ux/lib/Locale/util";
|
|
11
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
12
|
+
import useComponentInstalled from "./use-component-installed.js";
|
|
13
|
+
import translations from "./locales.js";
|
|
14
|
+
function ComponentInstaller({
|
|
15
|
+
warnIcon,
|
|
16
|
+
did,
|
|
17
|
+
noPermissionMute,
|
|
18
|
+
onInstalled,
|
|
19
|
+
onError,
|
|
20
|
+
children,
|
|
21
|
+
closeByOutSize,
|
|
22
|
+
onClose,
|
|
23
|
+
fallback,
|
|
24
|
+
roles = ["owner", "admin"]
|
|
25
|
+
}) {
|
|
26
|
+
const { locale } = useLocaleContext();
|
|
27
|
+
const t = useMemoizedFn((key, data = {}) => {
|
|
28
|
+
return translate(translations, key, locale, "en", data);
|
|
29
|
+
});
|
|
30
|
+
const { installed, optionalComponent, installUrl, storeUrl, installStatus, installStatusDone, definedInBlockletYML } = useComponentInstalled({
|
|
31
|
+
did,
|
|
32
|
+
onInstalled,
|
|
33
|
+
onError
|
|
34
|
+
});
|
|
35
|
+
const sessionCtx = useContext(SessionContext);
|
|
36
|
+
const handleInstall = () => {
|
|
37
|
+
window.open(installUrl, "_blank");
|
|
38
|
+
};
|
|
39
|
+
const handleClose = () => {
|
|
40
|
+
onClose?.(false);
|
|
41
|
+
};
|
|
42
|
+
const handleOpenStore = () => {
|
|
43
|
+
window.open(storeUrl, "_blank");
|
|
44
|
+
};
|
|
45
|
+
const handleRefresh = () => {
|
|
46
|
+
window.location.reload();
|
|
47
|
+
};
|
|
48
|
+
const size = 60;
|
|
49
|
+
return /* @__PURE__ */ jsx(SessionPermission, { session: sessionCtx?.session, roles, children: ({ hasPermission }) => {
|
|
50
|
+
if (installed) {
|
|
51
|
+
return children;
|
|
52
|
+
}
|
|
53
|
+
if (noPermissionMute && !hasPermission) {
|
|
54
|
+
return fallback || null;
|
|
55
|
+
}
|
|
56
|
+
if (typeof children === "function") {
|
|
57
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
58
|
+
fallback,
|
|
59
|
+
children({
|
|
60
|
+
hasPermission,
|
|
61
|
+
optionalComponent,
|
|
62
|
+
installStatus,
|
|
63
|
+
handleOpenStore,
|
|
64
|
+
handleInstall,
|
|
65
|
+
handleRefresh
|
|
66
|
+
})
|
|
67
|
+
] });
|
|
68
|
+
}
|
|
69
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
70
|
+
fallback,
|
|
71
|
+
/* @__PURE__ */ jsx(
|
|
72
|
+
ClickAwayListener,
|
|
73
|
+
{
|
|
74
|
+
onClickAway: (e) => {
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
e.stopPropagation();
|
|
77
|
+
if (closeByOutSize) {
|
|
78
|
+
handleClose();
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
children: /* @__PURE__ */ jsx(Fade, { in: true, timeout: 350, children: /* @__PURE__ */ jsx(
|
|
82
|
+
Paper,
|
|
83
|
+
{
|
|
84
|
+
variant: "outlined",
|
|
85
|
+
sx: {
|
|
86
|
+
position: "fixed",
|
|
87
|
+
top: 20,
|
|
88
|
+
right: 20,
|
|
89
|
+
zIndex: 3e3,
|
|
90
|
+
borderRadius: 3,
|
|
91
|
+
width: 400,
|
|
92
|
+
maxWidth: 400,
|
|
93
|
+
borderColor: colors.lineStep,
|
|
94
|
+
border: "0 !important",
|
|
95
|
+
fontSize: "14px",
|
|
96
|
+
textAlign: "left",
|
|
97
|
+
boxShadow: `0px 8px 16px 0px ${colors.gray6}, 0px 0px 0px 1px ${colors.gray6}`
|
|
98
|
+
},
|
|
99
|
+
children: !definedInBlockletYML ? /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column" }, children: [
|
|
100
|
+
/* @__PURE__ */ jsxs(
|
|
101
|
+
Box,
|
|
102
|
+
{
|
|
103
|
+
sx: {
|
|
104
|
+
padding: "20px 24px",
|
|
105
|
+
marginLeft: 0,
|
|
106
|
+
display: "flex",
|
|
107
|
+
flexDirection: "row",
|
|
108
|
+
justifyContent: "flex-start"
|
|
109
|
+
},
|
|
110
|
+
children: [
|
|
111
|
+
warnIcon || /* @__PURE__ */ jsx(Icon, { icon: "mdi:warning-box", style: { color: "yellowgreen", fontSize: 24 } }),
|
|
112
|
+
/* @__PURE__ */ jsx(Box, { sx: { marginLeft: 1, fontSize: "16px", fontWeight: "bold" }, children: t("componentInstallerTitle") })
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
),
|
|
116
|
+
/* @__PURE__ */ jsx(Box, { sx: { width: "100%", height: "1px", backgroundColor: colors.gray6 } }),
|
|
117
|
+
/* @__PURE__ */ jsxs(Box, { sx: { padding: "20px 24px", marginTop: 0 }, children: [
|
|
118
|
+
t("componentInstallerNoDefinedInBlockletYML"),
|
|
119
|
+
": ",
|
|
120
|
+
did
|
|
121
|
+
] }),
|
|
122
|
+
/* @__PURE__ */ jsx(Box, { sx: { padding: "0px 24px" }, children: onClose ? /* @__PURE__ */ jsx(Button, { sx: { marginBottom: 2 }, variant: "outlined", className: "button", onClick: handleClose, children: t("componentInstallerClose") }) : null })
|
|
123
|
+
] }) : /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column" }, children: [
|
|
124
|
+
/* @__PURE__ */ jsxs(
|
|
125
|
+
Box,
|
|
126
|
+
{
|
|
127
|
+
sx: {
|
|
128
|
+
padding: "20px 24px",
|
|
129
|
+
marginLeft: 0,
|
|
130
|
+
display: "flex",
|
|
131
|
+
flexDirection: "row",
|
|
132
|
+
justifyContent: "flex-start"
|
|
133
|
+
},
|
|
134
|
+
children: [
|
|
135
|
+
warnIcon || /* @__PURE__ */ jsx(Icon, { icon: "mdi:warning-box", style: { color: "yellowgreen", fontSize: 24 } }),
|
|
136
|
+
/* @__PURE__ */ jsx(Box, { sx: { marginLeft: 1, fontSize: "16px", fontWeight: "bold" }, children: t("componentInstallerTitle") })
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
),
|
|
140
|
+
/* @__PURE__ */ jsx(Box, { sx: { width: "100%", height: "1px", backgroundColor: colors.gray6 } }),
|
|
141
|
+
/* @__PURE__ */ jsxs(
|
|
142
|
+
Box,
|
|
143
|
+
{
|
|
144
|
+
sx: {
|
|
145
|
+
padding: "20px 24px",
|
|
146
|
+
paddingTop: 0.5,
|
|
147
|
+
marginTop: 2,
|
|
148
|
+
display: "flex",
|
|
149
|
+
flexDirection: "row",
|
|
150
|
+
justifyContent: "start",
|
|
151
|
+
alignItems: "flex-start"
|
|
152
|
+
},
|
|
153
|
+
children: [
|
|
154
|
+
/* @__PURE__ */ jsx(
|
|
155
|
+
"img",
|
|
156
|
+
{
|
|
157
|
+
style: { width: size, height: size, minWidth: size, minHeight: size },
|
|
158
|
+
src: optionalComponent.logoUrl,
|
|
159
|
+
alt: optionalComponent.meta.title
|
|
160
|
+
}
|
|
161
|
+
),
|
|
162
|
+
/* @__PURE__ */ jsxs(
|
|
163
|
+
Box,
|
|
164
|
+
{
|
|
165
|
+
sx: {
|
|
166
|
+
display: "flex",
|
|
167
|
+
flexDirection: "column",
|
|
168
|
+
justifyContent: "start",
|
|
169
|
+
alignItems: "start",
|
|
170
|
+
marginLeft: 2
|
|
171
|
+
},
|
|
172
|
+
children: [
|
|
173
|
+
/* @__PURE__ */ jsxs(
|
|
174
|
+
Box,
|
|
175
|
+
{
|
|
176
|
+
sx: {
|
|
177
|
+
fontSize: "16px",
|
|
178
|
+
fontWeight: "bold",
|
|
179
|
+
cursor: "pointer",
|
|
180
|
+
".link-icon": {
|
|
181
|
+
opacity: 0
|
|
182
|
+
},
|
|
183
|
+
":hover .link-icon": {
|
|
184
|
+
opacity: 1
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
onClick: handleOpenStore,
|
|
188
|
+
children: [
|
|
189
|
+
optionalComponent.meta.title,
|
|
190
|
+
/* @__PURE__ */ jsxs(
|
|
191
|
+
Box,
|
|
192
|
+
{
|
|
193
|
+
sx: {
|
|
194
|
+
paddingLeft: 1,
|
|
195
|
+
fontSize: "13px",
|
|
196
|
+
fontWeight: "400"
|
|
197
|
+
},
|
|
198
|
+
component: "span",
|
|
199
|
+
children: [
|
|
200
|
+
optionalComponent.meta.version,
|
|
201
|
+
/* @__PURE__ */ jsx(
|
|
202
|
+
Icon,
|
|
203
|
+
{
|
|
204
|
+
className: "link-icon",
|
|
205
|
+
icon: "fluent:open-20-filled",
|
|
206
|
+
style: {
|
|
207
|
+
color: colors.primaryBase,
|
|
208
|
+
fontSize: 16,
|
|
209
|
+
transform: "translate(6px, 3px)",
|
|
210
|
+
transition: "all 0.3s"
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
)
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
)
|
|
217
|
+
]
|
|
218
|
+
}
|
|
219
|
+
),
|
|
220
|
+
/* @__PURE__ */ jsx(Box, { sx: { marginTop: 0, opacity: 0.7 }, children: optionalComponent.meta.description }),
|
|
221
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: hasPermission ? "flex" : "none", flexDirection: "row", gap: 1 }, children: [
|
|
222
|
+
installStatus ? /* @__PURE__ */ jsx(Box, { sx: { marginTop: 2, opacity: 0.7 }, children: installStatusDone ? /* @__PURE__ */ jsx(Button, { variant: "contained", onClick: handleRefresh, children: t("componentInstallerRefresh") }, "refresh") : /* @__PURE__ */ jsx(
|
|
223
|
+
Button,
|
|
224
|
+
{
|
|
225
|
+
disabled: true,
|
|
226
|
+
sx: { color: "#333" },
|
|
227
|
+
startIcon: /* @__PURE__ */ jsx(Icon, { icon: "line-md:loading-loop", style: { color: "#333", fontSize: 16 } }),
|
|
228
|
+
variant: "contained",
|
|
229
|
+
children: installStatus
|
|
230
|
+
},
|
|
231
|
+
"status"
|
|
232
|
+
) }) : /* @__PURE__ */ jsx(
|
|
233
|
+
Button,
|
|
234
|
+
{
|
|
235
|
+
sx: { marginTop: 2 },
|
|
236
|
+
variant: "contained",
|
|
237
|
+
className: "button",
|
|
238
|
+
onClick: handleInstall,
|
|
239
|
+
children: t("componentInstallerInstall")
|
|
240
|
+
},
|
|
241
|
+
"install"
|
|
242
|
+
),
|
|
243
|
+
onClose ? /* @__PURE__ */ jsx(Button, { sx: { marginTop: 2 }, variant: "outlined", className: "button", onClick: handleClose, children: t("componentInstallerClose") }) : null
|
|
244
|
+
] }),
|
|
245
|
+
installStatusDone ? /* @__PURE__ */ jsx(Box, { sx: { marginTop: 2, opacity: 0.7 }, children: t("componentInstallerSuccessInstalled") }) : null
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
)
|
|
249
|
+
]
|
|
250
|
+
}
|
|
251
|
+
),
|
|
252
|
+
hasPermission ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
253
|
+
/* @__PURE__ */ jsx(Box, { sx: { width: "100%", height: "1px", backgroundColor: colors.gray6 } }),
|
|
254
|
+
/* @__PURE__ */ jsxs(Box, { sx: { padding: "20px 24px" }, children: [
|
|
255
|
+
/* @__PURE__ */ jsx(Box, { sx: { opacity: 1 }, children: t("componentInstallerSuggestions") }),
|
|
256
|
+
onClose ? /* @__PURE__ */ jsx(
|
|
257
|
+
Button,
|
|
258
|
+
{
|
|
259
|
+
sx: { marginTop: 2, alignSelf: "flex-start" },
|
|
260
|
+
variant: "outlined",
|
|
261
|
+
className: "button",
|
|
262
|
+
onClick: handleClose,
|
|
263
|
+
children: t("componentInstallerClose")
|
|
264
|
+
}
|
|
265
|
+
) : null
|
|
266
|
+
] })
|
|
267
|
+
] })
|
|
268
|
+
] })
|
|
269
|
+
}
|
|
270
|
+
) })
|
|
271
|
+
}
|
|
272
|
+
)
|
|
273
|
+
] });
|
|
274
|
+
} });
|
|
275
|
+
}
|
|
276
|
+
ComponentInstaller.propTypes = {
|
|
277
|
+
warnIcon: PropTypes.node,
|
|
278
|
+
did: PropTypes.string.isRequired,
|
|
279
|
+
noPermissionMute: PropTypes.bool,
|
|
280
|
+
onInstalled: PropTypes.func,
|
|
281
|
+
onError: PropTypes.func,
|
|
282
|
+
children: PropTypes.any.isRequired,
|
|
283
|
+
closeByOutSize: PropTypes.bool,
|
|
284
|
+
onClose: PropTypes.func,
|
|
285
|
+
fallback: PropTypes.node,
|
|
286
|
+
roles: PropTypes.array
|
|
287
|
+
};
|
|
288
|
+
ComponentInstaller.defaultProps = {
|
|
289
|
+
warnIcon: null,
|
|
290
|
+
noPermissionMute: false,
|
|
291
|
+
onInstalled: null,
|
|
292
|
+
onError: null,
|
|
293
|
+
closeByOutSize: false,
|
|
294
|
+
onClose: null,
|
|
295
|
+
fallback: null,
|
|
296
|
+
roles: ["owner", "admin"]
|
|
297
|
+
};
|
|
298
|
+
export default ComponentInstaller;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export default translations;
|
|
2
|
+
declare namespace translations {
|
|
3
|
+
namespace zh {
|
|
4
|
+
let componentInstallerTitle: string;
|
|
5
|
+
let componentInstallerInstall: string;
|
|
6
|
+
let componentInstallerClose: string;
|
|
7
|
+
let componentInstallerRefresh: string;
|
|
8
|
+
let componentInstallerSuccessInstalled: string;
|
|
9
|
+
let componentInstallerSuggestions: string;
|
|
10
|
+
let componentInstallerNoDefinedInBlockletYML: string;
|
|
11
|
+
}
|
|
12
|
+
namespace en {
|
|
13
|
+
let componentInstallerTitle_1: string;
|
|
14
|
+
export { componentInstallerTitle_1 as componentInstallerTitle };
|
|
15
|
+
let componentInstallerInstall_1: string;
|
|
16
|
+
export { componentInstallerInstall_1 as componentInstallerInstall };
|
|
17
|
+
let componentInstallerClose_1: string;
|
|
18
|
+
export { componentInstallerClose_1 as componentInstallerClose };
|
|
19
|
+
let componentInstallerRefresh_1: string;
|
|
20
|
+
export { componentInstallerRefresh_1 as componentInstallerRefresh };
|
|
21
|
+
let componentInstallerSuccessInstalled_1: string;
|
|
22
|
+
export { componentInstallerSuccessInstalled_1 as componentInstallerSuccessInstalled };
|
|
23
|
+
let componentInstallerSuggestions_1: string;
|
|
24
|
+
export { componentInstallerSuggestions_1 as componentInstallerSuggestions };
|
|
25
|
+
let componentInstallerNoDefinedInBlockletYML_1: string;
|
|
26
|
+
export { componentInstallerNoDefinedInBlockletYML_1 as componentInstallerNoDefinedInBlockletYML };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const translations = {
|
|
2
|
+
zh: {
|
|
3
|
+
componentInstallerTitle: '缺少组件',
|
|
4
|
+
componentInstallerInstall: '安装',
|
|
5
|
+
componentInstallerClose: '关闭',
|
|
6
|
+
componentInstallerRefresh: '重载页面',
|
|
7
|
+
componentInstallerSuccessInstalled: '安装成功,请重载页面查看变化。',
|
|
8
|
+
componentInstallerSuggestions: '请联系系统管理员安装该组件。',
|
|
9
|
+
componentInstallerNoDefinedInBlockletYML: '组件未在 blocklet.yml 中定义',
|
|
10
|
+
},
|
|
11
|
+
en: {
|
|
12
|
+
componentInstallerTitle: 'Missing component',
|
|
13
|
+
componentInstallerInstall: 'Install',
|
|
14
|
+
componentInstallerClose: 'Close',
|
|
15
|
+
componentInstallerRefresh: 'Refresh',
|
|
16
|
+
componentInstallerSuccessInstalled: 'Successfully installed, please refresh the page to see the changes.',
|
|
17
|
+
componentInstallerSuggestions: 'Please contact the system administrator to install the component.',
|
|
18
|
+
componentInstallerNoDefinedInBlockletYML: 'The component is not defined in blocklet.yml',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default translations;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default useComponentInstalled;
|
|
2
|
+
declare function useComponentInstalled({ did, onInstalled, onError }: {
|
|
3
|
+
did: any;
|
|
4
|
+
onInstalled: any;
|
|
5
|
+
onError: any;
|
|
6
|
+
}): {
|
|
7
|
+
optionalComponent: any;
|
|
8
|
+
installed: any;
|
|
9
|
+
installUrl: string;
|
|
10
|
+
storeUrl: string;
|
|
11
|
+
installStatus: string;
|
|
12
|
+
setInstallStatus: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
13
|
+
installStatusDone: boolean;
|
|
14
|
+
definedInBlockletYML: any;
|
|
15
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AUTH_SERVICE_PREFIX } from '@arcblock/did-connect/lib/constant';
|
|
2
|
+
import { useMemo, useRef, useState, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
function useComponentInstalled({ did, onInstalled, onError }) {
|
|
5
|
+
const { optionalComponents, componentMountPoints } = window.blocklet;
|
|
6
|
+
const onInstalledRef = useRef({ onInstalled, onError });
|
|
7
|
+
onInstalledRef.current = { onInstalled, onError };
|
|
8
|
+
|
|
9
|
+
const optionalComponent = useMemo(() => {
|
|
10
|
+
if (!optionalComponents || !optionalComponents.length) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const component = optionalComponents.find((c) => c.meta.did === did);
|
|
14
|
+
(component ? onInstalledRef.current.onError : onInstalledRef.current.onInstalled)?.(component);
|
|
15
|
+
return component;
|
|
16
|
+
}, [did, optionalComponents]);
|
|
17
|
+
|
|
18
|
+
const definedInBlockletYML = useMemo(() => {
|
|
19
|
+
if (optionalComponent) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return (componentMountPoints || []).find((item) => item.did === did);
|
|
23
|
+
}, [optionalComponent, componentMountPoints, did]);
|
|
24
|
+
|
|
25
|
+
const installUrl = `${window.blocklet.appUrl}/${AUTH_SERVICE_PREFIX}/admin/components?install-component=${did}`;
|
|
26
|
+
const storeUrl = optionalComponent ? `${optionalComponent.meta.homepage}/blocklets/${did}` : '';
|
|
27
|
+
const [installStatus, setInstallStatus] = useState('');
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const handle = (event) => {
|
|
31
|
+
if (event.origin !== window.blocklet.appUrl) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (event.data?.kind === 'component-installer' && event.data?.blocklet?.children) {
|
|
36
|
+
let hasChild = false;
|
|
37
|
+
event.data?.blocklet?.children.forEach((item) => {
|
|
38
|
+
if (item.meta?.did === did) {
|
|
39
|
+
hasChild = true;
|
|
40
|
+
setInstallStatus(item.status || 'waiting');
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
if (!hasChild) {
|
|
44
|
+
setInstallStatus('');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
window.addEventListener('message', handle);
|
|
49
|
+
return () => {
|
|
50
|
+
window.removeEventListener('message', handle);
|
|
51
|
+
};
|
|
52
|
+
}, [did]);
|
|
53
|
+
|
|
54
|
+
const installStatusDone = installStatus === 'stopped' || installStatus === 'running';
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
optionalComponent,
|
|
58
|
+
installed: !optionalComponent && definedInBlockletYML,
|
|
59
|
+
installUrl,
|
|
60
|
+
storeUrl,
|
|
61
|
+
installStatus,
|
|
62
|
+
setInstallStatus,
|
|
63
|
+
installStatusDone,
|
|
64
|
+
definedInBlockletYML,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default useComponentInstalled;
|
package/es/index.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export { default as Header } from './Header';
|
|
|
2
2
|
export { default as Footer } from './Footer';
|
|
3
3
|
export { default as Dashboard } from './Dashboard';
|
|
4
4
|
export { default as Icon } from './Icon';
|
|
5
|
+
export { default as ComponentInstaller } from './ComponentInstaller';
|
|
6
|
+
export { default as useComponentInstaller } from './ComponentInstaller/use-component-installer';
|
|
5
7
|
export * from './UserCenter';
|
package/es/index.js
CHANGED
|
@@ -2,4 +2,6 @@ export { default as Header } from "./Header/index.js";
|
|
|
2
2
|
export { default as Footer } from "./Footer/index.js";
|
|
3
3
|
export { default as Dashboard } from "./Dashboard/index.js";
|
|
4
4
|
export { default as Icon } from "./Icon/index.js";
|
|
5
|
+
export { default as ComponentInstaller } from "./ComponentInstaller/index.js";
|
|
6
|
+
export { default as useComponentInstaller } from "./ComponentInstaller/use-component-installer";
|
|
5
7
|
export * from "./UserCenter/index.js";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export default ComponentInstaller;
|
|
2
|
+
declare function ComponentInstaller({ warnIcon, did, noPermissionMute, onInstalled, onError, children, closeByOutSize, onClose, fallback, roles, }: {
|
|
3
|
+
warnIcon: any;
|
|
4
|
+
did: any;
|
|
5
|
+
noPermissionMute: any;
|
|
6
|
+
onInstalled: any;
|
|
7
|
+
onError: any;
|
|
8
|
+
children: any;
|
|
9
|
+
closeByOutSize: any;
|
|
10
|
+
onClose: any;
|
|
11
|
+
fallback: any;
|
|
12
|
+
roles?: string[] | undefined;
|
|
13
|
+
}): import("react").JSX.Element;
|
|
14
|
+
declare namespace ComponentInstaller {
|
|
15
|
+
namespace propTypes {
|
|
16
|
+
let warnIcon: any;
|
|
17
|
+
let did: any;
|
|
18
|
+
let noPermissionMute: any;
|
|
19
|
+
let onInstalled: any;
|
|
20
|
+
let onError: any;
|
|
21
|
+
let children: any;
|
|
22
|
+
let closeByOutSize: any;
|
|
23
|
+
let onClose: any;
|
|
24
|
+
let fallback: any;
|
|
25
|
+
let roles: any;
|
|
26
|
+
}
|
|
27
|
+
namespace defaultProps {
|
|
28
|
+
let warnIcon_1: null;
|
|
29
|
+
export { warnIcon_1 as warnIcon };
|
|
30
|
+
let noPermissionMute_1: boolean;
|
|
31
|
+
export { noPermissionMute_1 as noPermissionMute };
|
|
32
|
+
let onInstalled_1: null;
|
|
33
|
+
export { onInstalled_1 as onInstalled };
|
|
34
|
+
let onError_1: null;
|
|
35
|
+
export { onError_1 as onError };
|
|
36
|
+
let closeByOutSize_1: boolean;
|
|
37
|
+
export { closeByOutSize_1 as closeByOutSize };
|
|
38
|
+
let onClose_1: null;
|
|
39
|
+
export { onClose_1 as onClose };
|
|
40
|
+
let fallback_1: null;
|
|
41
|
+
export { fallback_1 as fallback };
|
|
42
|
+
let roles_1: string[];
|
|
43
|
+
export { roles_1 as roles };
|
|
44
|
+
}
|
|
45
|
+
}
|