@blocklet/ui-react 2.9.81 → 2.9.82
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/@types/shims.d.ts +0 -1
- package/es/ComponentInstaller/use-component-installed.js +3 -3
- package/es/ComponentManager/components/add-component.d.ts +13 -0
- package/es/ComponentManager/components/add-component.js +95 -0
- package/es/ComponentManager/components/check-component.d.ts +2 -0
- package/es/ComponentManager/components/check-component.js +2 -0
- package/es/ComponentManager/components/publish-component.d.ts +9 -0
- package/es/ComponentManager/components/publish-component.js +51 -0
- package/es/ComponentManager/components/resource-dialog.d.ts +9 -0
- package/es/ComponentManager/components/resource-dialog.js +56 -0
- package/es/ComponentManager/index.d.ts +3 -0
- package/es/ComponentManager/index.js +3 -0
- package/es/ComponentManager/libs/locales.d.ts +10 -0
- package/es/ComponentManager/libs/locales.js +10 -0
- package/es/UserCenter/libs/utils.js +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/lib/@types/shims.d.ts +0 -1
- package/lib/ComponentInstaller/use-component-installed.js +3 -4
- package/lib/ComponentManager/components/add-component.d.ts +13 -0
- package/lib/ComponentManager/components/add-component.js +99 -0
- package/lib/ComponentManager/components/check-component.d.ts +2 -0
- package/lib/ComponentManager/components/check-component.js +9 -0
- package/lib/ComponentManager/components/publish-component.d.ts +9 -0
- package/lib/ComponentManager/components/publish-component.js +67 -0
- package/lib/ComponentManager/components/resource-dialog.d.ts +9 -0
- package/lib/ComponentManager/components/resource-dialog.js +56 -0
- package/lib/ComponentManager/index.d.ts +3 -0
- package/lib/ComponentManager/index.js +27 -0
- package/lib/ComponentManager/libs/locales.d.ts +10 -0
- package/lib/ComponentManager/libs/locales.js +16 -0
- package/lib/UserCenter/libs/utils.js +2 -3
- package/lib/index.d.ts +1 -0
- package/lib/index.js +12 -0
- package/package.json +5 -6
- package/src/@types/shims.d.ts +0 -1
- package/src/ComponentInstaller/use-component-installed.js +3 -3
- package/src/ComponentManager/components/add-component.tsx +114 -0
- package/src/ComponentManager/components/check-component.tsx +3 -0
- package/src/ComponentManager/components/publish-component.tsx +66 -0
- package/src/ComponentManager/components/resource-dialog.tsx +64 -0
- package/src/ComponentManager/index.tsx +3 -0
- package/src/ComponentManager/libs/locales.ts +10 -0
- package/src/UserCenter/libs/utils.ts +1 -1
- package/src/index.ts +1 -0
package/es/@types/shims.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AUTH_SERVICE_PREFIX } from '@arcblock/did-connect/lib/constant';
|
|
2
2
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import
|
|
3
|
+
import { joinURL } from 'ufo';
|
|
4
4
|
|
|
5
5
|
const parseDidToSet = (did) => {
|
|
6
6
|
if (typeof did === 'string') {
|
|
@@ -36,8 +36,8 @@ function useComponentInstalled({ did, onInstalled, onError }) {
|
|
|
36
36
|
}, [optComponents, componentMountPoints, didKeys]);
|
|
37
37
|
|
|
38
38
|
optComponents.forEach((item) => {
|
|
39
|
-
item.storeUrl =
|
|
40
|
-
item.installUrl =
|
|
39
|
+
item.storeUrl = joinURL(item.meta.homepage, 'blocklets', item.meta.did);
|
|
40
|
+
item.installUrl = joinURL(
|
|
41
41
|
window.blocklet.appUrl,
|
|
42
42
|
AUTH_SERVICE_PREFIX,
|
|
43
43
|
`/admin/components?install-component=${item.meta.did}`
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
export default function AddComponent({ componentDid, resourceType, resourceDid, autoClose, onComplete, onClose, render, }: {
|
|
3
|
+
componentDid: string;
|
|
4
|
+
resourceType: string;
|
|
5
|
+
resourceDid: string;
|
|
6
|
+
autoClose: boolean;
|
|
7
|
+
onComplete: () => void;
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
render?: ({ onClick, loading }: {
|
|
10
|
+
onClick: () => void;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
}) => ReactElement;
|
|
13
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import Button from "@arcblock/ux/lib/Button";
|
|
4
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
5
|
+
import { WELLKNOWN_SERVICE_PATH_PREFIX } from "@arcblock/ux/lib/Util/constant";
|
|
6
|
+
import { useMemoizedFn, useReactive } from "ahooks";
|
|
7
|
+
import { translate } from "@arcblock/ux/lib/Locale/util";
|
|
8
|
+
import { joinURL } from "ufo";
|
|
9
|
+
import ResourceDialog from "./resource-dialog.js";
|
|
10
|
+
import { translations } from "../libs/locales.js";
|
|
11
|
+
export default function AddComponent({
|
|
12
|
+
componentDid,
|
|
13
|
+
resourceType,
|
|
14
|
+
resourceDid,
|
|
15
|
+
autoClose = true,
|
|
16
|
+
onComplete,
|
|
17
|
+
onClose,
|
|
18
|
+
render
|
|
19
|
+
}) {
|
|
20
|
+
const { locale } = useLocaleContext();
|
|
21
|
+
const t = useMemoizedFn((key, data = {}) => {
|
|
22
|
+
return translate(translations, key, locale, "en", data);
|
|
23
|
+
});
|
|
24
|
+
const currentState = useReactive({
|
|
25
|
+
loading: false,
|
|
26
|
+
showDialog: false
|
|
27
|
+
});
|
|
28
|
+
const baseUrl = new URL(
|
|
29
|
+
joinURL(WELLKNOWN_SERVICE_PATH_PREFIX, "embed/resources", componentDid, "add"),
|
|
30
|
+
window.location.origin
|
|
31
|
+
);
|
|
32
|
+
baseUrl.searchParams.set("resourceDid", resourceDid);
|
|
33
|
+
baseUrl.searchParams.set("resourceType", resourceType);
|
|
34
|
+
baseUrl.searchParams.set("mode", "dialog");
|
|
35
|
+
baseUrl.searchParams.set("showFromUrl", "false");
|
|
36
|
+
baseUrl.searchParams.set("showResourcesSwitch", "false");
|
|
37
|
+
baseUrl.searchParams.set("enableRunBackground", "false");
|
|
38
|
+
const importUrl = baseUrl.pathname + baseUrl.search;
|
|
39
|
+
const handleClose = useMemoizedFn(() => {
|
|
40
|
+
currentState.showDialog = false;
|
|
41
|
+
onClose?.();
|
|
42
|
+
});
|
|
43
|
+
const handleComplete = useMemoizedFn(() => {
|
|
44
|
+
currentState.showDialog = false;
|
|
45
|
+
onComplete?.();
|
|
46
|
+
});
|
|
47
|
+
const handleOpen = useMemoizedFn(() => {
|
|
48
|
+
currentState.loading = true;
|
|
49
|
+
currentState.showDialog = true;
|
|
50
|
+
});
|
|
51
|
+
const handleLoad = useMemoizedFn(() => {
|
|
52
|
+
currentState.loading = false;
|
|
53
|
+
});
|
|
54
|
+
const handleIframeMessage = useMemoizedFn((event) => {
|
|
55
|
+
if (event?.data?.event === "component.installed" && event.data.componentDid === componentDid) {
|
|
56
|
+
if (autoClose || event.data.manual) {
|
|
57
|
+
handleComplete();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (currentState.showDialog) {
|
|
63
|
+
window.addEventListener("message", handleIframeMessage);
|
|
64
|
+
} else {
|
|
65
|
+
window.removeEventListener("message", handleIframeMessage);
|
|
66
|
+
}
|
|
67
|
+
}, [currentState.showDialog]);
|
|
68
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
69
|
+
render ? render({ onClick: handleOpen, loading: currentState.loading }) : /* @__PURE__ */ jsx(
|
|
70
|
+
Button,
|
|
71
|
+
{
|
|
72
|
+
variant: "outlined",
|
|
73
|
+
color: "secondary",
|
|
74
|
+
type: "button",
|
|
75
|
+
className: "submit",
|
|
76
|
+
onClick: handleOpen,
|
|
77
|
+
loading: currentState.loading,
|
|
78
|
+
sx: { mr: 1, ml: 1 },
|
|
79
|
+
children: t("importResource")
|
|
80
|
+
},
|
|
81
|
+
"button"
|
|
82
|
+
),
|
|
83
|
+
currentState.showDialog && /* @__PURE__ */ jsx(
|
|
84
|
+
ResourceDialog,
|
|
85
|
+
{
|
|
86
|
+
src: importUrl,
|
|
87
|
+
open: true,
|
|
88
|
+
loading: currentState.loading,
|
|
89
|
+
onClose: handleClose,
|
|
90
|
+
onComplete: handleComplete,
|
|
91
|
+
onLoad: handleLoad
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
] });
|
|
95
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
export default function PublishComponent({ componentDid, onClose, render, }: {
|
|
3
|
+
componentDid: String;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
render?: ({ onClick, loading }: {
|
|
6
|
+
onClick: () => void;
|
|
7
|
+
loading: boolean;
|
|
8
|
+
}) => ReactElement;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Button from "@arcblock/ux/lib/Button";
|
|
3
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
4
|
+
import { WELLKNOWN_SERVICE_PATH_PREFIX } from "@arcblock/ux/lib/Util/constant";
|
|
5
|
+
import { useMemoizedFn, useReactive } from "ahooks";
|
|
6
|
+
import { translate } from "@arcblock/ux/lib/Locale/util";
|
|
7
|
+
import ResourceDialog from "./resource-dialog.js";
|
|
8
|
+
import { translations } from "../libs/locales.js";
|
|
9
|
+
export default function PublishComponent({
|
|
10
|
+
componentDid,
|
|
11
|
+
onClose,
|
|
12
|
+
render
|
|
13
|
+
}) {
|
|
14
|
+
const { locale } = useLocaleContext();
|
|
15
|
+
const t = useMemoizedFn((key, data = {}) => {
|
|
16
|
+
return translate(translations, key, locale, "en", data);
|
|
17
|
+
});
|
|
18
|
+
const currentState = useReactive({
|
|
19
|
+
showDialog: false,
|
|
20
|
+
loading: false
|
|
21
|
+
});
|
|
22
|
+
const exportUrl = `${WELLKNOWN_SERVICE_PATH_PREFIX}/embed/resources/${componentDid}/publish?mode=dialog`;
|
|
23
|
+
const handleClose = useMemoizedFn(() => {
|
|
24
|
+
currentState.showDialog = false;
|
|
25
|
+
onClose?.();
|
|
26
|
+
});
|
|
27
|
+
const handleLoad = useMemoizedFn(() => {
|
|
28
|
+
currentState.loading = false;
|
|
29
|
+
});
|
|
30
|
+
const handleOpen = useMemoizedFn(() => {
|
|
31
|
+
currentState.loading = true;
|
|
32
|
+
currentState.showDialog = true;
|
|
33
|
+
});
|
|
34
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
35
|
+
render ? render({ onClick: handleOpen, loading: currentState.loading }) : /* @__PURE__ */ jsx(
|
|
36
|
+
Button,
|
|
37
|
+
{
|
|
38
|
+
variant: "outlined",
|
|
39
|
+
color: "secondary",
|
|
40
|
+
type: "button",
|
|
41
|
+
className: "submit",
|
|
42
|
+
loading: currentState.loading,
|
|
43
|
+
onClick: handleOpen,
|
|
44
|
+
sx: { mr: 1, ml: 1 },
|
|
45
|
+
children: t("exportResource")
|
|
46
|
+
},
|
|
47
|
+
"button"
|
|
48
|
+
),
|
|
49
|
+
currentState.showDialog && /* @__PURE__ */ jsx(ResourceDialog, { src: exportUrl, open: true, onClose: handleClose, onLoad: handleLoad, loading: currentState.loading })
|
|
50
|
+
] });
|
|
51
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export default function ResourceDialog({ src, open, loading, onClose, onComplete, onLoad, }: {
|
|
3
|
+
src: string;
|
|
4
|
+
open?: boolean;
|
|
5
|
+
loading?: boolean;
|
|
6
|
+
onLoad?: () => void;
|
|
7
|
+
onClose?: () => void;
|
|
8
|
+
onComplete?: () => void;
|
|
9
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemoizedFn, useMount, useUnmount } from "ahooks";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
export default function ResourceDialog({
|
|
5
|
+
src,
|
|
6
|
+
open = false,
|
|
7
|
+
loading = true,
|
|
8
|
+
onClose = () => {
|
|
9
|
+
},
|
|
10
|
+
onComplete = () => {
|
|
11
|
+
},
|
|
12
|
+
onLoad = () => {
|
|
13
|
+
}
|
|
14
|
+
}) {
|
|
15
|
+
const iframeRef = useRef(null);
|
|
16
|
+
const listener = useMemoizedFn((event) => {
|
|
17
|
+
if (open) {
|
|
18
|
+
if (event?.data?.event === "resourceDialog.close") {
|
|
19
|
+
onClose();
|
|
20
|
+
}
|
|
21
|
+
if (event?.data?.event === "resourceDialog.complete") {
|
|
22
|
+
onComplete();
|
|
23
|
+
}
|
|
24
|
+
if (event?.data?.event === "resourceDialog.loaded") {
|
|
25
|
+
onLoad();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
useMount(() => {
|
|
30
|
+
window.addEventListener("message", listener);
|
|
31
|
+
});
|
|
32
|
+
useUnmount(() => {
|
|
33
|
+
window.removeEventListener("message", listener);
|
|
34
|
+
});
|
|
35
|
+
if (!open) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return /* @__PURE__ */ jsx(
|
|
39
|
+
"iframe",
|
|
40
|
+
{
|
|
41
|
+
ref: iframeRef,
|
|
42
|
+
src,
|
|
43
|
+
title: "Resource Dialog",
|
|
44
|
+
style: {
|
|
45
|
+
position: "fixed",
|
|
46
|
+
top: 0,
|
|
47
|
+
left: loading ? "-100vw" : 0,
|
|
48
|
+
width: "100vw",
|
|
49
|
+
height: "100vh",
|
|
50
|
+
zIndex: 9999,
|
|
51
|
+
backgroundColor: "transparent",
|
|
52
|
+
border: "none"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import joinURL from "
|
|
1
|
+
import { joinURL } from "ufo";
|
|
2
2
|
import { createPassportSvg as _createPassportSvg } from "@arcblock/ux/lib/Util/passport";
|
|
3
3
|
import { AUTH_SERVICE_PREFIX } from "@arcblock/ux/lib/Util/constant";
|
|
4
4
|
export const formatAxiosError = (err) => {
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
|
@@ -6,3 +6,4 @@ export { default as ComponentInstaller } from "./ComponentInstaller/index.js";
|
|
|
6
6
|
export { default as useComponentInstaller } from "./ComponentInstaller/use-component-installed.js";
|
|
7
7
|
export * from "./UserCenter/index.js";
|
|
8
8
|
export * from "./UserSessions/index.js";
|
|
9
|
+
export * from "./ComponentManager/index.js";
|
package/lib/@types/shims.d.ts
CHANGED
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
|
|
7
7
|
var _constant = require("@arcblock/did-connect/lib/constant");
|
|
8
8
|
var _react = require("react");
|
|
9
|
-
var
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
var _ufo = require("ufo");
|
|
11
10
|
const parseDidToSet = did => {
|
|
12
11
|
if (typeof did === 'string') {
|
|
13
12
|
return new Set(did.split(';;'));
|
|
@@ -50,8 +49,8 @@ function useComponentInstalled({
|
|
|
50
49
|
return (componentMountPoints || []).find(item => didSet.has(item.did));
|
|
51
50
|
}, [optComponents, componentMountPoints, didKeys]);
|
|
52
51
|
optComponents.forEach(item => {
|
|
53
|
-
item.storeUrl = (0,
|
|
54
|
-
item.installUrl = (0,
|
|
52
|
+
item.storeUrl = (0, _ufo.joinURL)(item.meta.homepage, 'blocklets', item.meta.did);
|
|
53
|
+
item.installUrl = (0, _ufo.joinURL)(window.blocklet.appUrl, _constant.AUTH_SERVICE_PREFIX, `/admin/components?install-component=${item.meta.did}`);
|
|
55
54
|
});
|
|
56
55
|
(0, _react.useEffect)(() => {
|
|
57
56
|
const handle = event => {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
export default function AddComponent({ componentDid, resourceType, resourceDid, autoClose, onComplete, onClose, render, }: {
|
|
3
|
+
componentDid: string;
|
|
4
|
+
resourceType: string;
|
|
5
|
+
resourceDid: string;
|
|
6
|
+
autoClose: boolean;
|
|
7
|
+
onComplete: () => void;
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
render?: ({ onClick, loading }: {
|
|
10
|
+
onClick: () => void;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
}) => ReactElement;
|
|
13
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = AddComponent;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
|
|
10
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
11
|
+
var _constant = require("@arcblock/ux/lib/Util/constant");
|
|
12
|
+
var _ahooks = require("ahooks");
|
|
13
|
+
var _util = require("@arcblock/ux/lib/Locale/util");
|
|
14
|
+
var _ufo = require("ufo");
|
|
15
|
+
var _resourceDialog = _interopRequireDefault(require("./resource-dialog"));
|
|
16
|
+
var _locales = require("../libs/locales");
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
function AddComponent({
|
|
19
|
+
componentDid,
|
|
20
|
+
resourceType,
|
|
21
|
+
resourceDid,
|
|
22
|
+
autoClose = true,
|
|
23
|
+
onComplete,
|
|
24
|
+
onClose,
|
|
25
|
+
render
|
|
26
|
+
}) {
|
|
27
|
+
const {
|
|
28
|
+
locale
|
|
29
|
+
} = (0, _context.useLocaleContext)();
|
|
30
|
+
const t = (0, _ahooks.useMemoizedFn)((key, data = {}) => {
|
|
31
|
+
return (0, _util.translate)(_locales.translations, key, locale, "en", data);
|
|
32
|
+
});
|
|
33
|
+
const currentState = (0, _ahooks.useReactive)({
|
|
34
|
+
loading: false,
|
|
35
|
+
showDialog: false
|
|
36
|
+
});
|
|
37
|
+
const baseUrl = new URL((0, _ufo.joinURL)(_constant.WELLKNOWN_SERVICE_PATH_PREFIX, "embed/resources", componentDid, "add"), window.location.origin);
|
|
38
|
+
baseUrl.searchParams.set("resourceDid", resourceDid);
|
|
39
|
+
baseUrl.searchParams.set("resourceType", resourceType);
|
|
40
|
+
baseUrl.searchParams.set("mode", "dialog");
|
|
41
|
+
baseUrl.searchParams.set("showFromUrl", "false");
|
|
42
|
+
baseUrl.searchParams.set("showResourcesSwitch", "false");
|
|
43
|
+
baseUrl.searchParams.set("enableRunBackground", "false");
|
|
44
|
+
const importUrl = baseUrl.pathname + baseUrl.search;
|
|
45
|
+
const handleClose = (0, _ahooks.useMemoizedFn)(() => {
|
|
46
|
+
currentState.showDialog = false;
|
|
47
|
+
onClose?.();
|
|
48
|
+
});
|
|
49
|
+
const handleComplete = (0, _ahooks.useMemoizedFn)(() => {
|
|
50
|
+
currentState.showDialog = false;
|
|
51
|
+
onComplete?.();
|
|
52
|
+
});
|
|
53
|
+
const handleOpen = (0, _ahooks.useMemoizedFn)(() => {
|
|
54
|
+
currentState.loading = true;
|
|
55
|
+
currentState.showDialog = true;
|
|
56
|
+
});
|
|
57
|
+
const handleLoad = (0, _ahooks.useMemoizedFn)(() => {
|
|
58
|
+
currentState.loading = false;
|
|
59
|
+
});
|
|
60
|
+
const handleIframeMessage = (0, _ahooks.useMemoizedFn)(event => {
|
|
61
|
+
if (event?.data?.event === "component.installed" && event.data.componentDid === componentDid) {
|
|
62
|
+
if (autoClose || event.data.manual) {
|
|
63
|
+
handleComplete();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
(0, _react.useEffect)(() => {
|
|
68
|
+
if (currentState.showDialog) {
|
|
69
|
+
window.addEventListener("message", handleIframeMessage);
|
|
70
|
+
} else {
|
|
71
|
+
window.removeEventListener("message", handleIframeMessage);
|
|
72
|
+
}
|
|
73
|
+
}, [currentState.showDialog]);
|
|
74
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
75
|
+
children: [render ? render({
|
|
76
|
+
onClick: handleOpen,
|
|
77
|
+
loading: currentState.loading
|
|
78
|
+
}) : /* @__PURE__ */(0, _jsxRuntime.jsx)(_Button.default, {
|
|
79
|
+
variant: "outlined",
|
|
80
|
+
color: "secondary",
|
|
81
|
+
type: "button",
|
|
82
|
+
className: "submit",
|
|
83
|
+
onClick: handleOpen,
|
|
84
|
+
loading: currentState.loading,
|
|
85
|
+
sx: {
|
|
86
|
+
mr: 1,
|
|
87
|
+
ml: 1
|
|
88
|
+
},
|
|
89
|
+
children: t("importResource")
|
|
90
|
+
}, "button"), currentState.showDialog && /* @__PURE__ */(0, _jsxRuntime.jsx)(_resourceDialog.default, {
|
|
91
|
+
src: importUrl,
|
|
92
|
+
open: true,
|
|
93
|
+
loading: currentState.loading,
|
|
94
|
+
onClose: handleClose,
|
|
95
|
+
onComplete: handleComplete,
|
|
96
|
+
onLoad: handleLoad
|
|
97
|
+
})]
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _ComponentInstaller = _interopRequireDefault(require("../../ComponentInstaller"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
module.exports = _ComponentInstaller.default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
export default function PublishComponent({ componentDid, onClose, render, }: {
|
|
3
|
+
componentDid: String;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
render?: ({ onClick, loading }: {
|
|
6
|
+
onClick: () => void;
|
|
7
|
+
loading: boolean;
|
|
8
|
+
}) => ReactElement;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = PublishComponent;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
|
|
9
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
10
|
+
var _constant = require("@arcblock/ux/lib/Util/constant");
|
|
11
|
+
var _ahooks = require("ahooks");
|
|
12
|
+
var _util = require("@arcblock/ux/lib/Locale/util");
|
|
13
|
+
var _resourceDialog = _interopRequireDefault(require("./resource-dialog"));
|
|
14
|
+
var _locales = require("../libs/locales");
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
function PublishComponent({
|
|
17
|
+
componentDid,
|
|
18
|
+
onClose,
|
|
19
|
+
render
|
|
20
|
+
}) {
|
|
21
|
+
const {
|
|
22
|
+
locale
|
|
23
|
+
} = (0, _context.useLocaleContext)();
|
|
24
|
+
const t = (0, _ahooks.useMemoizedFn)((key, data = {}) => {
|
|
25
|
+
return (0, _util.translate)(_locales.translations, key, locale, "en", data);
|
|
26
|
+
});
|
|
27
|
+
const currentState = (0, _ahooks.useReactive)({
|
|
28
|
+
showDialog: false,
|
|
29
|
+
loading: false
|
|
30
|
+
});
|
|
31
|
+
const exportUrl = `${_constant.WELLKNOWN_SERVICE_PATH_PREFIX}/embed/resources/${componentDid}/publish?mode=dialog`;
|
|
32
|
+
const handleClose = (0, _ahooks.useMemoizedFn)(() => {
|
|
33
|
+
currentState.showDialog = false;
|
|
34
|
+
onClose?.();
|
|
35
|
+
});
|
|
36
|
+
const handleLoad = (0, _ahooks.useMemoizedFn)(() => {
|
|
37
|
+
currentState.loading = false;
|
|
38
|
+
});
|
|
39
|
+
const handleOpen = (0, _ahooks.useMemoizedFn)(() => {
|
|
40
|
+
currentState.loading = true;
|
|
41
|
+
currentState.showDialog = true;
|
|
42
|
+
});
|
|
43
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
44
|
+
children: [render ? render({
|
|
45
|
+
onClick: handleOpen,
|
|
46
|
+
loading: currentState.loading
|
|
47
|
+
}) : /* @__PURE__ */(0, _jsxRuntime.jsx)(_Button.default, {
|
|
48
|
+
variant: "outlined",
|
|
49
|
+
color: "secondary",
|
|
50
|
+
type: "button",
|
|
51
|
+
className: "submit",
|
|
52
|
+
loading: currentState.loading,
|
|
53
|
+
onClick: handleOpen,
|
|
54
|
+
sx: {
|
|
55
|
+
mr: 1,
|
|
56
|
+
ml: 1
|
|
57
|
+
},
|
|
58
|
+
children: t("exportResource")
|
|
59
|
+
}, "button"), currentState.showDialog && /* @__PURE__ */(0, _jsxRuntime.jsx)(_resourceDialog.default, {
|
|
60
|
+
src: exportUrl,
|
|
61
|
+
open: true,
|
|
62
|
+
onClose: handleClose,
|
|
63
|
+
onLoad: handleLoad,
|
|
64
|
+
loading: currentState.loading
|
|
65
|
+
})]
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export default function ResourceDialog({ src, open, loading, onClose, onComplete, onLoad, }: {
|
|
3
|
+
src: string;
|
|
4
|
+
open?: boolean;
|
|
5
|
+
loading?: boolean;
|
|
6
|
+
onLoad?: () => void;
|
|
7
|
+
onClose?: () => void;
|
|
8
|
+
onComplete?: () => void;
|
|
9
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = ResourceDialog;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _ahooks = require("ahooks");
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
function ResourceDialog({
|
|
11
|
+
src,
|
|
12
|
+
open = false,
|
|
13
|
+
loading = true,
|
|
14
|
+
onClose = () => {},
|
|
15
|
+
onComplete = () => {},
|
|
16
|
+
onLoad = () => {}
|
|
17
|
+
}) {
|
|
18
|
+
const iframeRef = (0, _react.useRef)(null);
|
|
19
|
+
const listener = (0, _ahooks.useMemoizedFn)(event => {
|
|
20
|
+
if (open) {
|
|
21
|
+
if (event?.data?.event === "resourceDialog.close") {
|
|
22
|
+
onClose();
|
|
23
|
+
}
|
|
24
|
+
if (event?.data?.event === "resourceDialog.complete") {
|
|
25
|
+
onComplete();
|
|
26
|
+
}
|
|
27
|
+
if (event?.data?.event === "resourceDialog.loaded") {
|
|
28
|
+
onLoad();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
(0, _ahooks.useMount)(() => {
|
|
33
|
+
window.addEventListener("message", listener);
|
|
34
|
+
});
|
|
35
|
+
(0, _ahooks.useUnmount)(() => {
|
|
36
|
+
window.removeEventListener("message", listener);
|
|
37
|
+
});
|
|
38
|
+
if (!open) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)("iframe", {
|
|
42
|
+
ref: iframeRef,
|
|
43
|
+
src,
|
|
44
|
+
title: "Resource Dialog",
|
|
45
|
+
style: {
|
|
46
|
+
position: "fixed",
|
|
47
|
+
top: 0,
|
|
48
|
+
left: loading ? "-100vw" : 0,
|
|
49
|
+
width: "100vw",
|
|
50
|
+
height: "100vh",
|
|
51
|
+
zIndex: 9999,
|
|
52
|
+
backgroundColor: "transparent",
|
|
53
|
+
border: "none"
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "AddComponent", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _addComponent.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "CheckComponent", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _checkComponent.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "PublishComponent", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _publishComponent.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _publishComponent = _interopRequireDefault(require("./components/publish-component"));
|
|
25
|
+
var _addComponent = _interopRequireDefault(require("./components/add-component"));
|
|
26
|
+
var _checkComponent = _interopRequireDefault(require("./components/check-component"));
|
|
27
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.translations = void 0;
|
|
7
|
+
const translations = exports.translations = {
|
|
8
|
+
zh: {
|
|
9
|
+
importResource: "\u5BFC\u5165",
|
|
10
|
+
exportResource: "\u5BFC\u51FA"
|
|
11
|
+
},
|
|
12
|
+
en: {
|
|
13
|
+
importResource: "Import",
|
|
14
|
+
exportResource: "Export"
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -4,10 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.formatAxiosError = exports.createPassportSvg = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _ufo = require("ufo");
|
|
8
8
|
var _passport = require("@arcblock/ux/lib/Util/passport");
|
|
9
9
|
var _constant = require("@arcblock/ux/lib/Util/constant");
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
10
|
const formatAxiosError = err => {
|
|
12
11
|
const {
|
|
13
12
|
response
|
|
@@ -20,6 +19,6 @@ const formatAxiosError = err => {
|
|
|
20
19
|
exports.formatAxiosError = formatAxiosError;
|
|
21
20
|
const createPassportSvg = props => (0, _passport.createPassportSvg)({
|
|
22
21
|
...props,
|
|
23
|
-
issuerAvatarUrl: (0,
|
|
22
|
+
issuerAvatarUrl: (0, _ufo.joinURL)(window.location.origin, _constant.AUTH_SERVICE_PREFIX, "/blocklet/logo")
|
|
24
23
|
});
|
|
25
24
|
exports.createPassportSvg = createPassportSvg;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -77,4 +77,16 @@ Object.keys(_UserSessions).forEach(function (key) {
|
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
});
|
|
80
|
+
var _ComponentManager = require("./ComponentManager");
|
|
81
|
+
Object.keys(_ComponentManager).forEach(function (key) {
|
|
82
|
+
if (key === "default" || key === "__esModule") return;
|
|
83
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
84
|
+
if (key in exports && exports[key] === _ComponentManager[key]) return;
|
|
85
|
+
Object.defineProperty(exports, key, {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function () {
|
|
88
|
+
return _ComponentManager[key];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
80
92
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/ui-react",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.82",
|
|
4
4
|
"description": "Some useful front-end web components that can be used in Blocklets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@arcblock/bridge": "^2.9.
|
|
66
|
-
"@arcblock/react-hooks": "^2.9.
|
|
65
|
+
"@arcblock/bridge": "^2.9.82",
|
|
66
|
+
"@arcblock/react-hooks": "^2.9.82",
|
|
67
67
|
"@blocklet/js-sdk": "1.16.27-beta-c450492a",
|
|
68
68
|
"@iconify-icons/logos": "^1.2.36",
|
|
69
69
|
"@iconify-icons/material-symbols": "^1.2.58",
|
|
@@ -82,8 +82,7 @@
|
|
|
82
82
|
"react-error-boundary": "^3.1.4",
|
|
83
83
|
"react-placeholder": "^4.1.0",
|
|
84
84
|
"ua-parser-js": "^1.0.37",
|
|
85
|
-
"ufo": "^1.3.2"
|
|
86
|
-
"url-join": "^4.0.1"
|
|
85
|
+
"ufo": "^1.3.2"
|
|
87
86
|
},
|
|
88
87
|
"peerDependencies": {
|
|
89
88
|
"@arcblock/did-connect": "^2.9.79",
|
|
@@ -109,5 +108,5 @@
|
|
|
109
108
|
"jest": "^28.1.3",
|
|
110
109
|
"unbuild": "^2.0.0"
|
|
111
110
|
},
|
|
112
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "4984b9ac818af802b6eb9fb4d6d03e08882f5179"
|
|
113
112
|
}
|
package/src/@types/shims.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AUTH_SERVICE_PREFIX } from '@arcblock/did-connect/lib/constant';
|
|
2
2
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import
|
|
3
|
+
import { joinURL } from 'ufo';
|
|
4
4
|
|
|
5
5
|
const parseDidToSet = (did) => {
|
|
6
6
|
if (typeof did === 'string') {
|
|
@@ -36,8 +36,8 @@ function useComponentInstalled({ did, onInstalled, onError }) {
|
|
|
36
36
|
}, [optComponents, componentMountPoints, didKeys]);
|
|
37
37
|
|
|
38
38
|
optComponents.forEach((item) => {
|
|
39
|
-
item.storeUrl =
|
|
40
|
-
item.installUrl =
|
|
39
|
+
item.storeUrl = joinURL(item.meta.homepage, 'blocklets', item.meta.did);
|
|
40
|
+
item.installUrl = joinURL(
|
|
41
41
|
window.blocklet.appUrl,
|
|
42
42
|
AUTH_SERVICE_PREFIX,
|
|
43
43
|
`/admin/components?install-component=${item.meta.did}`
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { useEffect, ReactElement } from 'react';
|
|
2
|
+
import Button from '@arcblock/ux/lib/Button';
|
|
3
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
4
|
+
import { WELLKNOWN_SERVICE_PATH_PREFIX } from '@arcblock/ux/lib/Util/constant';
|
|
5
|
+
import { useMemoizedFn, useReactive } from 'ahooks';
|
|
6
|
+
import { translate } from '@arcblock/ux/lib/Locale/util';
|
|
7
|
+
import { joinURL } from 'ufo';
|
|
8
|
+
|
|
9
|
+
import ResourceDialog from './resource-dialog';
|
|
10
|
+
import { translations } from '../libs/locales';
|
|
11
|
+
|
|
12
|
+
export default function AddComponent({
|
|
13
|
+
componentDid,
|
|
14
|
+
resourceType,
|
|
15
|
+
resourceDid,
|
|
16
|
+
autoClose = true,
|
|
17
|
+
onComplete,
|
|
18
|
+
onClose,
|
|
19
|
+
render,
|
|
20
|
+
}: {
|
|
21
|
+
componentDid: string;
|
|
22
|
+
resourceType: string;
|
|
23
|
+
resourceDid: string;
|
|
24
|
+
autoClose: boolean;
|
|
25
|
+
onComplete: () => void;
|
|
26
|
+
onClose: () => void;
|
|
27
|
+
render?: ({ onClick, loading }: { onClick: () => void; loading: boolean }) => ReactElement;
|
|
28
|
+
}) {
|
|
29
|
+
const { locale } = useLocaleContext();
|
|
30
|
+
const t = useMemoizedFn((key, data = {}) => {
|
|
31
|
+
return translate(translations, key, locale, 'en', data);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const currentState = useReactive({
|
|
35
|
+
loading: false,
|
|
36
|
+
showDialog: false,
|
|
37
|
+
});
|
|
38
|
+
const baseUrl = new URL(
|
|
39
|
+
joinURL(WELLKNOWN_SERVICE_PATH_PREFIX, 'embed/resources', componentDid, 'add'),
|
|
40
|
+
window.location.origin
|
|
41
|
+
);
|
|
42
|
+
baseUrl.searchParams.set('resourceDid', resourceDid);
|
|
43
|
+
baseUrl.searchParams.set('resourceType', resourceType);
|
|
44
|
+
baseUrl.searchParams.set('mode', 'dialog');
|
|
45
|
+
// 以下为添加组件特有的参数
|
|
46
|
+
baseUrl.searchParams.set('showFromUrl', 'false');
|
|
47
|
+
baseUrl.searchParams.set('showResourcesSwitch', 'false');
|
|
48
|
+
baseUrl.searchParams.set('enableRunBackground', 'false');
|
|
49
|
+
const importUrl = baseUrl.pathname + baseUrl.search;
|
|
50
|
+
|
|
51
|
+
const handleClose = useMemoizedFn(() => {
|
|
52
|
+
currentState.showDialog = false;
|
|
53
|
+
onClose?.();
|
|
54
|
+
});
|
|
55
|
+
const handleComplete = useMemoizedFn(() => {
|
|
56
|
+
currentState.showDialog = false;
|
|
57
|
+
onComplete?.();
|
|
58
|
+
});
|
|
59
|
+
const handleOpen = useMemoizedFn(() => {
|
|
60
|
+
currentState.loading = true;
|
|
61
|
+
currentState.showDialog = true;
|
|
62
|
+
});
|
|
63
|
+
const handleLoad = useMemoizedFn(() => {
|
|
64
|
+
currentState.loading = false;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const handleIframeMessage = useMemoizedFn((event: MessageEvent) => {
|
|
68
|
+
if (event?.data?.event === 'component.installed' && event.data.componentDid === componentDid) {
|
|
69
|
+
if (autoClose || event.data.manual) {
|
|
70
|
+
handleComplete();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (currentState.showDialog) {
|
|
77
|
+
window.addEventListener('message', handleIframeMessage);
|
|
78
|
+
} else {
|
|
79
|
+
window.removeEventListener('message', handleIframeMessage);
|
|
80
|
+
}
|
|
81
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
82
|
+
}, [currentState.showDialog]);
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<>
|
|
86
|
+
{render ? (
|
|
87
|
+
render({ onClick: handleOpen, loading: currentState.loading })
|
|
88
|
+
) : (
|
|
89
|
+
<Button
|
|
90
|
+
key="button"
|
|
91
|
+
variant="outlined"
|
|
92
|
+
color="secondary"
|
|
93
|
+
type="button"
|
|
94
|
+
className="submit"
|
|
95
|
+
onClick={handleOpen}
|
|
96
|
+
loading={currentState.loading}
|
|
97
|
+
sx={{ mr: 1, ml: 1 }}>
|
|
98
|
+
{t('importResource')}
|
|
99
|
+
</Button>
|
|
100
|
+
)}
|
|
101
|
+
|
|
102
|
+
{currentState.showDialog && (
|
|
103
|
+
<ResourceDialog
|
|
104
|
+
src={importUrl}
|
|
105
|
+
open
|
|
106
|
+
loading={currentState.loading}
|
|
107
|
+
onClose={handleClose}
|
|
108
|
+
onComplete={handleComplete}
|
|
109
|
+
onLoad={handleLoad}
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
</>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import Button from '@arcblock/ux/lib/Button';
|
|
3
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
4
|
+
import { WELLKNOWN_SERVICE_PATH_PREFIX } from '@arcblock/ux/lib/Util/constant';
|
|
5
|
+
import { useMemoizedFn, useReactive } from 'ahooks';
|
|
6
|
+
import { translate } from '@arcblock/ux/lib/Locale/util';
|
|
7
|
+
|
|
8
|
+
import ResourceDialog from './resource-dialog';
|
|
9
|
+
import { translations } from '../libs/locales';
|
|
10
|
+
|
|
11
|
+
export default function PublishComponent({
|
|
12
|
+
componentDid,
|
|
13
|
+
onClose,
|
|
14
|
+
render,
|
|
15
|
+
}: {
|
|
16
|
+
componentDid: String;
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
render?: ({ onClick, loading }: { onClick: () => void; loading: boolean }) => ReactElement;
|
|
19
|
+
}) {
|
|
20
|
+
const { locale } = useLocaleContext();
|
|
21
|
+
const t = useMemoizedFn((key, data = {}) => {
|
|
22
|
+
return translate(translations, key, locale, 'en', data);
|
|
23
|
+
});
|
|
24
|
+
const currentState = useReactive({
|
|
25
|
+
showDialog: false,
|
|
26
|
+
loading: false,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const exportUrl = `${WELLKNOWN_SERVICE_PATH_PREFIX}/embed/resources/${componentDid}/publish?mode=dialog`;
|
|
30
|
+
|
|
31
|
+
const handleClose = useMemoizedFn(() => {
|
|
32
|
+
currentState.showDialog = false;
|
|
33
|
+
onClose?.();
|
|
34
|
+
});
|
|
35
|
+
const handleLoad = useMemoizedFn(() => {
|
|
36
|
+
currentState.loading = false;
|
|
37
|
+
});
|
|
38
|
+
const handleOpen = useMemoizedFn(() => {
|
|
39
|
+
currentState.loading = true;
|
|
40
|
+
currentState.showDialog = true;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<>
|
|
45
|
+
{render ? (
|
|
46
|
+
render({ onClick: handleOpen, loading: currentState.loading })
|
|
47
|
+
) : (
|
|
48
|
+
<Button
|
|
49
|
+
key="button"
|
|
50
|
+
variant="outlined"
|
|
51
|
+
color="secondary"
|
|
52
|
+
type="button"
|
|
53
|
+
className="submit"
|
|
54
|
+
loading={currentState.loading}
|
|
55
|
+
onClick={handleOpen}
|
|
56
|
+
sx={{ mr: 1, ml: 1 }}>
|
|
57
|
+
{t('exportResource')}
|
|
58
|
+
</Button>
|
|
59
|
+
)}
|
|
60
|
+
|
|
61
|
+
{currentState.showDialog && (
|
|
62
|
+
<ResourceDialog src={exportUrl} open onClose={handleClose} onLoad={handleLoad} loading={currentState.loading} />
|
|
63
|
+
)}
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useMemoizedFn, useMount, useUnmount } from 'ahooks';
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
|
|
4
|
+
export default function ResourceDialog({
|
|
5
|
+
src,
|
|
6
|
+
open = false,
|
|
7
|
+
loading = true,
|
|
8
|
+
onClose = () => {},
|
|
9
|
+
onComplete = () => {},
|
|
10
|
+
onLoad = () => {},
|
|
11
|
+
}: {
|
|
12
|
+
src: string;
|
|
13
|
+
open?: boolean;
|
|
14
|
+
loading?: boolean;
|
|
15
|
+
onLoad?: () => void;
|
|
16
|
+
onClose?: () => void;
|
|
17
|
+
onComplete?: () => void;
|
|
18
|
+
}) {
|
|
19
|
+
const iframeRef = useRef(null);
|
|
20
|
+
|
|
21
|
+
const listener = useMemoizedFn((event: MessageEvent) => {
|
|
22
|
+
if (open) {
|
|
23
|
+
if (event?.data?.event === 'resourceDialog.close') {
|
|
24
|
+
onClose();
|
|
25
|
+
}
|
|
26
|
+
if (event?.data?.event === 'resourceDialog.complete') {
|
|
27
|
+
onComplete();
|
|
28
|
+
}
|
|
29
|
+
if (event?.data?.event === 'resourceDialog.loaded') {
|
|
30
|
+
onLoad();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
useMount(() => {
|
|
36
|
+
window.addEventListener('message', listener);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
useUnmount(() => {
|
|
40
|
+
window.removeEventListener('message', listener);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (!open) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<iframe
|
|
49
|
+
ref={iframeRef}
|
|
50
|
+
src={src}
|
|
51
|
+
title="Resource Dialog"
|
|
52
|
+
style={{
|
|
53
|
+
position: 'fixed',
|
|
54
|
+
top: 0,
|
|
55
|
+
left: loading ? '-100vw' : 0,
|
|
56
|
+
width: '100vw',
|
|
57
|
+
height: '100vh',
|
|
58
|
+
zIndex: 9999,
|
|
59
|
+
backgroundColor: 'transparent',
|
|
60
|
+
border: 'none',
|
|
61
|
+
}}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AxiosError } from 'axios';
|
|
2
|
-
import joinURL from '
|
|
2
|
+
import { joinURL } from 'ufo';
|
|
3
3
|
import { createPassportSvg as _createPassportSvg } from '@arcblock/ux/lib/Util/passport';
|
|
4
4
|
import { AUTH_SERVICE_PREFIX } from '@arcblock/ux/lib/Util/constant';
|
|
5
5
|
import { CreatePassportProps } from '../../@types';
|
package/src/index.ts
CHANGED
|
@@ -12,3 +12,4 @@ export { default as ComponentInstaller } from './ComponentInstaller';
|
|
|
12
12
|
export { default as useComponentInstaller } from './ComponentInstaller/use-component-installed';
|
|
13
13
|
export * from './UserCenter';
|
|
14
14
|
export * from './UserSessions';
|
|
15
|
+
export * from './ComponentManager';
|