@blocklet/ui-react 2.9.13 → 2.9.15
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/build.config.ts +29 -0
- package/es/@types/index.d.ts +63 -0
- package/es/@types/index.js +0 -0
- package/es/@types/shims.d.ts +12 -0
- package/es/Dashboard/index.d.ts +41 -0
- package/es/Dashboard/index.js +63 -97
- package/es/Footer/brand.d.ts +22 -0
- package/es/Footer/brand.js +20 -37
- package/es/Footer/copyright.d.ts +18 -0
- package/es/Footer/copyright.js +14 -16
- package/es/Footer/index.d.ts +6 -0
- package/es/Footer/index.js +31 -57
- package/es/Footer/internal-footer.d.ts +29 -0
- package/es/Footer/internal-footer.js +67 -94
- package/es/Footer/layout/plain.d.ts +15 -0
- package/es/Footer/layout/plain.js +19 -37
- package/es/Footer/layout/row.d.ts +18 -0
- package/es/Footer/layout/row.js +9 -19
- package/es/Footer/layout/standard.d.ts +15 -0
- package/es/Footer/layout/standard.js +29 -57
- package/es/Footer/links.d.ts +22 -0
- package/es/Footer/links.js +72 -104
- package/es/Footer/social-media.d.ts +14 -0
- package/es/Footer/social-media.js +35 -35
- package/es/Header/index.d.ts +9 -0
- package/es/Header/index.js +56 -101
- package/es/Icon/index.d.ts +23 -0
- package/es/Icon/index.js +23 -58
- package/es/UserCenter/assets/banner.png +0 -0
- package/es/UserCenter/components/notification.d.ts +5 -0
- package/es/UserCenter/components/notification.js +276 -0
- package/es/UserCenter/components/passport.d.ts +6 -0
- package/es/UserCenter/components/passport.js +69 -0
- package/es/UserCenter/components/privacy.d.ts +11 -0
- package/es/UserCenter/components/privacy.js +99 -0
- package/es/UserCenter/components/settings.d.ts +10 -0
- package/es/UserCenter/components/settings.js +68 -0
- package/es/UserCenter/components/user-basic-info.d.ts +8 -0
- package/es/UserCenter/components/user-basic-info.js +66 -0
- package/es/UserCenter/components/user-center.d.ts +9 -0
- package/es/UserCenter/components/user-center.js +397 -0
- package/es/UserCenter/components/user-info-item.d.ts +10 -0
- package/es/UserCenter/components/user-info-item.js +54 -0
- package/es/UserCenter/components/user-info.d.ts +6 -0
- package/es/UserCenter/components/user-info.js +68 -0
- package/es/UserCenter/components/webhook-item.d.ts +3 -0
- package/es/UserCenter/components/webhook-item.js +243 -0
- package/es/UserCenter/index.d.ts +1 -0
- package/es/UserCenter/index.js +1 -0
- package/es/UserCenter/libs/client.d.ts +2 -0
- package/es/UserCenter/libs/client.js +2 -0
- package/es/UserCenter/libs/locales.d.ts +72 -0
- package/es/UserCenter/libs/locales.js +72 -0
- package/es/UserCenter/libs/utils.d.ts +4 -0
- package/es/UserCenter/libs/utils.js +14 -0
- package/es/blocklets.d.ts +16 -0
- package/es/blocklets.js +56 -45
- package/es/common/header-addons.d.ts +22 -0
- package/es/common/header-addons.js +41 -59
- package/es/common/link-blocker.d.ts +7 -0
- package/es/common/link-blocker.js +10 -17
- package/es/common/overridable-theme-provider.d.ts +18 -0
- package/es/common/overridable-theme-provider.js +6 -16
- package/es/common/wallet-hidden-topbar.d.ts +1 -0
- package/es/common/wallet-hidden-topbar.js +12 -10
- package/es/index.d.ts +5 -0
- package/es/index.js +5 -0
- package/es/types.d.ts +2 -0
- package/es/types.js +17 -11
- package/es/utils.d.ts +8 -0
- package/es/utils.js +21 -26
- package/lib/@types/index.d.ts +63 -0
- package/lib/@types/index.js +1 -0
- package/lib/@types/shims.d.ts +12 -0
- package/lib/Dashboard/index.d.ts +41 -0
- package/lib/Dashboard/index.js +44 -71
- package/lib/Footer/brand.d.ts +22 -0
- package/lib/Footer/brand.js +65 -30
- package/lib/Footer/copyright.d.ts +18 -0
- package/lib/Footer/copyright.js +18 -23
- package/lib/Footer/index.d.ts +6 -0
- package/lib/Footer/index.js +33 -42
- package/lib/Footer/internal-footer.d.ts +29 -0
- package/lib/Footer/internal-footer.js +43 -59
- package/lib/Footer/layout/plain.d.ts +15 -0
- package/lib/Footer/layout/plain.js +25 -30
- package/lib/Footer/layout/row.d.ts +18 -0
- package/lib/Footer/layout/row.js +34 -23
- package/lib/Footer/layout/standard.d.ts +15 -0
- package/lib/Footer/layout/standard.js +35 -41
- package/lib/Footer/links.d.ts +22 -0
- package/lib/Footer/links.js +163 -60
- package/lib/Footer/social-media.d.ts +14 -0
- package/lib/Footer/social-media.js +31 -25
- package/lib/Header/index.d.ts +9 -0
- package/lib/Header/index.js +83 -76
- package/lib/Icon/index.d.ts +23 -0
- package/lib/Icon/index.js +37 -51
- package/lib/UserCenter/assets/banner.png +0 -0
- package/lib/UserCenter/components/notification.d.ts +5 -0
- package/lib/UserCenter/components/notification.js +261 -0
- package/lib/UserCenter/components/passport.d.ts +6 -0
- package/lib/UserCenter/components/passport.js +86 -0
- package/lib/UserCenter/components/privacy.d.ts +11 -0
- package/lib/UserCenter/components/privacy.js +101 -0
- package/lib/UserCenter/components/settings.d.ts +10 -0
- package/lib/UserCenter/components/settings.js +81 -0
- package/lib/UserCenter/components/user-basic-info.d.ts +8 -0
- package/lib/UserCenter/components/user-basic-info.js +67 -0
- package/lib/UserCenter/components/user-center.d.ts +9 -0
- package/lib/UserCenter/components/user-center.js +376 -0
- package/lib/UserCenter/components/user-info-item.d.ts +10 -0
- package/lib/UserCenter/components/user-info-item.js +46 -0
- package/lib/UserCenter/components/user-info.d.ts +6 -0
- package/lib/UserCenter/components/user-info.js +94 -0
- package/lib/UserCenter/components/webhook-item.d.ts +3 -0
- package/lib/UserCenter/components/webhook-item.js +236 -0
- package/lib/UserCenter/index.d.ts +1 -0
- package/lib/UserCenter/index.js +13 -0
- package/lib/UserCenter/libs/client.d.ts +2 -0
- package/lib/UserCenter/libs/client.js +8 -0
- package/lib/UserCenter/libs/locales.d.ts +72 -0
- package/lib/UserCenter/libs/locales.js +78 -0
- package/lib/UserCenter/libs/utils.d.ts +4 -0
- package/lib/UserCenter/libs/utils.js +25 -0
- package/lib/blocklets.d.ts +16 -0
- package/lib/blocklets.js +28 -36
- package/lib/common/header-addons.d.ts +22 -0
- package/lib/common/header-addons.js +24 -36
- package/lib/common/link-blocker.d.ts +7 -0
- package/lib/common/link-blocker.js +10 -18
- package/lib/common/overridable-theme-provider.d.ts +18 -0
- package/lib/common/overridable-theme-provider.js +9 -14
- package/lib/common/wallet-hidden-topbar.d.ts +1 -0
- package/lib/common/wallet-hidden-topbar.js +1 -3
- package/lib/index.d.ts +5 -0
- package/lib/index.js +52 -0
- package/lib/types.d.ts +2 -0
- package/lib/types.js +3 -5
- package/lib/utils.d.ts +8 -0
- package/lib/utils.js +16 -23
- package/package.json +18 -11
- package/src/@types/index.ts +70 -0
- package/src/@types/shims.d.ts +12 -0
- package/src/Footer/index.jsx +1 -1
- package/src/Header/index.jsx +1 -1
- package/src/UserCenter/assets/banner.png +0 -0
- package/src/UserCenter/components/notification.tsx +275 -0
- package/src/UserCenter/components/passport.tsx +83 -0
- package/src/UserCenter/components/privacy.tsx +107 -0
- package/src/UserCenter/components/settings.tsx +78 -0
- package/src/UserCenter/components/user-basic-info.tsx +70 -0
- package/src/UserCenter/components/user-center.tsx +410 -0
- package/src/UserCenter/components/user-info-item.tsx +50 -0
- package/src/UserCenter/components/user-info.tsx +85 -0
- package/src/UserCenter/components/webhook-item.tsx +243 -0
- package/src/UserCenter/index.tsx +1 -0
- package/src/UserCenter/libs/client.ts +3 -0
- package/src/UserCenter/libs/locales.ts +72 -0
- package/src/UserCenter/libs/utils.ts +21 -0
- package/src/blocklets.js +2 -0
- package/src/index.ts +9 -0
- /package/src/common/{link-blocker.js → link-blocker.jsx} +0 -0
|
@@ -1,88 +1,70 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import { Fragment } from
|
|
6
|
-
import { SessionContext } from
|
|
7
|
-
import SessionUser from
|
|
8
|
-
import SessionBlocklet from
|
|
9
|
-
import LocaleSelector from
|
|
10
|
-
import { useLocaleContext } from
|
|
11
|
-
import { sessionManagerProps } from
|
|
12
|
-
import { getLocalizedNavigation, filterNavByRole } from
|
|
13
|
-
|
|
14
|
-
// eslint-disable-next-line no-shadow
|
|
15
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
|
-
export default function HeaderAddons({
|
|
17
|
-
formattedBlocklet,
|
|
18
|
-
addons,
|
|
19
|
-
sessionManagerProps
|
|
20
|
-
}) {
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import "iconify-icon";
|
|
3
|
+
import { useContext, createElement } from "react";
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
|
+
import { Fragment } from "react/jsx-runtime";
|
|
6
|
+
import { SessionContext } from "@arcblock/did-connect/lib/Session";
|
|
7
|
+
import SessionUser from "@arcblock/ux/lib/SessionUser";
|
|
8
|
+
import SessionBlocklet from "@arcblock/ux/lib/SessionBlocklet";
|
|
9
|
+
import LocaleSelector from "@arcblock/ux/lib/Locale/selector";
|
|
10
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
11
|
+
import { sessionManagerProps } from "../types.js";
|
|
12
|
+
import { getLocalizedNavigation, filterNavByRole } from "../blocklets.js";
|
|
13
|
+
export default function HeaderAddons({ formattedBlocklet, addons, sessionManagerProps: sessionManagerProps2 }) {
|
|
21
14
|
const sessionCtx = useContext(SessionContext);
|
|
22
|
-
const {
|
|
23
|
-
|
|
24
|
-
} = useLocaleContext() || {};
|
|
25
|
-
const {
|
|
26
|
-
enableConnect = true,
|
|
27
|
-
enableLocale = true
|
|
28
|
-
} = formattedBlocklet;
|
|
15
|
+
const { locale } = useLocaleContext() || {};
|
|
16
|
+
const { enableConnect = true, enableLocale = true } = formattedBlocklet;
|
|
29
17
|
const authenticated = !!sessionCtx?.session?.user;
|
|
30
18
|
let localizedNav = getLocalizedNavigation(formattedBlocklet?.navigation?.sessionManager, locale) || [];
|
|
31
|
-
// 根据 role 筛选 nav 数据
|
|
32
19
|
localizedNav = filterNavByRole(localizedNav, sessionCtx?.session?.user?.role);
|
|
33
20
|
const renderAddons = () => {
|
|
34
|
-
|
|
35
|
-
if (addons && typeof addons !== 'function') {
|
|
21
|
+
if (addons && typeof addons !== "function") {
|
|
36
22
|
return Array.isArray(addons) ? addons : [addons];
|
|
37
23
|
}
|
|
38
24
|
let addonsArray = [];
|
|
39
|
-
// 启用了多语言并且检测到了 locale context
|
|
40
25
|
if (enableLocale && locale) {
|
|
41
|
-
addonsArray.push(
|
|
42
|
-
showText: false
|
|
43
|
-
}, "locale-selector"));
|
|
26
|
+
addonsArray.push(/* @__PURE__ */ jsx(LocaleSelector, { showText: false }, "locale-selector"));
|
|
44
27
|
}
|
|
45
|
-
// 启用了连接钱包并且检测到了 session context
|
|
46
28
|
if (enableConnect && sessionCtx) {
|
|
47
29
|
const menu = [];
|
|
48
30
|
if (authenticated) {
|
|
49
31
|
const navList = localizedNav ? localizedNav.slice(0, 5) : [];
|
|
50
|
-
navList.forEach(x => {
|
|
32
|
+
navList.forEach((x) => {
|
|
51
33
|
menu.push({
|
|
52
34
|
label: x.title,
|
|
53
|
-
icon: x.icon ?
|
|
54
|
-
|
|
55
|
-
height: 24,
|
|
56
|
-
style: {
|
|
57
|
-
marginRight: 8
|
|
58
|
-
}
|
|
59
|
-
}) : null,
|
|
60
|
-
component: 'a',
|
|
35
|
+
icon: x.icon ? /* @__PURE__ */ jsx("iconify-icon", { icon: x.icon, height: 24, style: { marginRight: 8 } }) : null,
|
|
36
|
+
component: "a",
|
|
61
37
|
href: x.link,
|
|
62
38
|
key: x.link
|
|
63
39
|
});
|
|
64
40
|
});
|
|
65
41
|
}
|
|
66
|
-
addonsArray.push(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
42
|
+
addonsArray.push(/* @__PURE__ */ jsx(SessionBlocklet, { session: sessionCtx.session, locale }, "session-blocklet"));
|
|
43
|
+
addonsArray.push(
|
|
44
|
+
/* @__PURE__ */ jsx(
|
|
45
|
+
SessionUser,
|
|
46
|
+
{
|
|
47
|
+
session: sessionCtx.session,
|
|
48
|
+
locale,
|
|
49
|
+
menu,
|
|
50
|
+
showRole: true,
|
|
51
|
+
...sessionManagerProps2
|
|
52
|
+
},
|
|
53
|
+
"session-user"
|
|
54
|
+
)
|
|
55
|
+
);
|
|
77
56
|
}
|
|
78
|
-
|
|
79
|
-
if (typeof addons === 'function') {
|
|
57
|
+
if (typeof addons === "function") {
|
|
80
58
|
addonsArray = addons(addonsArray) || [];
|
|
81
59
|
}
|
|
82
60
|
return addonsArray;
|
|
83
61
|
};
|
|
84
62
|
const renderedAddons = renderAddons();
|
|
85
|
-
const addonList =
|
|
63
|
+
const addonList = createElement(
|
|
64
|
+
Fragment,
|
|
65
|
+
null,
|
|
66
|
+
...Array.isArray(renderedAddons) ? renderedAddons : [renderedAddons]
|
|
67
|
+
);
|
|
86
68
|
return addonList;
|
|
87
69
|
}
|
|
88
70
|
HeaderAddons.propTypes = {
|
|
@@ -98,4 +80,4 @@ HeaderAddons.defaultProps = {
|
|
|
98
80
|
sessionManagerProps: {
|
|
99
81
|
showRole: true
|
|
100
82
|
}
|
|
101
|
-
};
|
|
83
|
+
};
|
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
import { jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
function hasParentOfType(node, type) {
|
|
3
|
-
if (!node)
|
|
4
|
-
|
|
3
|
+
if (!node)
|
|
4
|
+
return false;
|
|
5
|
+
if (type === node.nodeName)
|
|
6
|
+
return true;
|
|
5
7
|
return hasParentOfType(node.parentNode, type);
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
function LinkBlocker({
|
|
12
|
-
...rest
|
|
13
|
-
}) {
|
|
14
|
-
const handleOnClick = e => {
|
|
15
|
-
const isInsideLink = hasParentOfType(e.target, 'A');
|
|
9
|
+
function LinkBlocker({ ...rest }) {
|
|
10
|
+
const handleOnClick = (e) => {
|
|
11
|
+
const isInsideLink = hasParentOfType(e.target, "A");
|
|
16
12
|
if (isInsideLink) {
|
|
17
13
|
e.preventDefault();
|
|
18
14
|
}
|
|
19
15
|
};
|
|
20
|
-
return
|
|
21
|
-
onClick: handleOnClick,
|
|
22
|
-
...rest
|
|
23
|
-
});
|
|
16
|
+
return /* @__PURE__ */ jsx("div", { onClick: handleOnClick, ...rest });
|
|
24
17
|
}
|
|
25
|
-
export default LinkBlocker;
|
|
18
|
+
export default LinkBlocker;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 允许 theme 被覆盖的 ThemeProvider 组件, 默认使用 ux default theme, 可以传入 theme 进行覆盖
|
|
3
|
+
*/
|
|
4
|
+
declare function OverridableThemeProvider({ theme: themeOverrides, children }: {
|
|
5
|
+
theme: any;
|
|
6
|
+
children: any;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
8
|
+
declare namespace OverridableThemeProvider {
|
|
9
|
+
namespace propTypes {
|
|
10
|
+
let children: any;
|
|
11
|
+
let theme: any;
|
|
12
|
+
}
|
|
13
|
+
namespace defaultProps {
|
|
14
|
+
let theme_1: null;
|
|
15
|
+
export { theme_1 as theme };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export default OverridableThemeProvider;
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import { createTheme, ThemeProvider } from "@arcblock/ux/lib/Theme";
|
|
4
4
|
const defaultTheme = createTheme();
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 允许 theme 被覆盖的 ThemeProvider 组件, 默认使用 ux default theme, 可以传入 theme 进行覆盖
|
|
8
|
-
*/
|
|
9
|
-
export default function OverridableThemeProvider({
|
|
10
|
-
theme: themeOverrides,
|
|
11
|
-
children
|
|
12
|
-
}) {
|
|
5
|
+
export default function OverridableThemeProvider({ theme: themeOverrides, children }) {
|
|
13
6
|
const theme = themeOverrides ? createTheme(themeOverrides) : defaultTheme;
|
|
14
|
-
return
|
|
15
|
-
theme: theme,
|
|
16
|
-
children: children
|
|
17
|
-
});
|
|
7
|
+
return /* @__PURE__ */ jsx(ThemeProvider, { theme, children });
|
|
18
8
|
}
|
|
19
9
|
OverridableThemeProvider.propTypes = {
|
|
20
10
|
children: PropTypes.any.isRequired,
|
|
@@ -22,4 +12,4 @@ OverridableThemeProvider.propTypes = {
|
|
|
22
12
|
};
|
|
23
13
|
OverridableThemeProvider.defaultProps = {
|
|
24
14
|
theme: null
|
|
25
|
-
};
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function useWalletHiddenTopbar(): void;
|
|
@@ -7,15 +7,17 @@ export const useWalletHiddenTopbar = () => {
|
|
|
7
7
|
const browser = useBrowser();
|
|
8
8
|
useEffect(() => {
|
|
9
9
|
if (browser.wallet) {
|
|
10
|
-
import('dsbridge')
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
import('dsbridge')
|
|
11
|
+
.then((dsbridge) => {
|
|
12
|
+
if (!dsbridge.call) {
|
|
13
|
+
// eslint-disable-next-line no-param-reassign
|
|
14
|
+
dsbridge = dsbridge.default;
|
|
15
|
+
}
|
|
16
|
+
dsbridge.call('arcHideTopBar', '{}');
|
|
17
|
+
})
|
|
18
|
+
.catch((err) => {
|
|
19
|
+
console.error('load dsbridge error', err);
|
|
20
|
+
});
|
|
19
21
|
}
|
|
20
22
|
}, [browser]);
|
|
21
|
-
};
|
|
23
|
+
};
|
package/es/index.d.ts
ADDED
package/es/index.js
ADDED
package/es/types.d.ts
ADDED
package/es/types.js
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
/* eslint-disable import/prefer-default-export */
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
3
4
|
export const blockletMetaProps = PropTypes.shape({
|
|
4
5
|
appLogo: PropTypes.node,
|
|
5
6
|
appName: PropTypes.string,
|
|
6
7
|
theme: PropTypes.shape({
|
|
7
|
-
background: PropTypes.string
|
|
8
|
+
background: PropTypes.string,
|
|
8
9
|
}),
|
|
9
10
|
enableConnect: PropTypes.bool,
|
|
10
11
|
enableLocale: PropTypes.bool,
|
|
11
|
-
navigation: PropTypes.arrayOf(
|
|
12
|
-
|
|
13
|
-
link: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
|
14
|
-
icon: PropTypes.string,
|
|
15
|
-
items: PropTypes.arrayOf(PropTypes.shape({
|
|
12
|
+
navigation: PropTypes.arrayOf(
|
|
13
|
+
PropTypes.shape({
|
|
16
14
|
title: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
|
17
|
-
link: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
link: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
|
16
|
+
icon: PropTypes.string,
|
|
17
|
+
items: PropTypes.arrayOf(
|
|
18
|
+
PropTypes.shape({
|
|
19
|
+
title: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
|
20
|
+
link: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
|
21
|
+
})
|
|
22
|
+
),
|
|
23
|
+
})
|
|
24
|
+
),
|
|
20
25
|
});
|
|
26
|
+
|
|
21
27
|
export const sessionManagerProps = PropTypes.shape({
|
|
22
28
|
showText: PropTypes.bool,
|
|
23
29
|
showRole: PropTypes.bool,
|
|
@@ -33,5 +39,5 @@ export const sessionManagerProps = PropTypes.shape({
|
|
|
33
39
|
menu: PropTypes.array,
|
|
34
40
|
menuRender: PropTypes.func,
|
|
35
41
|
dark: PropTypes.bool,
|
|
36
|
-
size: PropTypes.number
|
|
37
|
-
});
|
|
42
|
+
size: PropTypes.number,
|
|
43
|
+
});
|
package/es/utils.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function mapRecursive(array: any, fn: any, childrenKey?: string): any;
|
|
2
|
+
export function flatRecursive(array: any, childrenKey?: string): any[];
|
|
3
|
+
export function countRecursive(array: any, childrenKey?: string): number;
|
|
4
|
+
export function filterRecursive(array: any, predicate: any, childrenKey?: string): any;
|
|
5
|
+
export function isUrl(str: any): boolean;
|
|
6
|
+
export function isIconifyString(str: any): boolean;
|
|
7
|
+
export function matchPath(path: any): any;
|
|
8
|
+
export function matchPaths(paths?: any[]): number;
|
package/es/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export const mapRecursive = (array, fn, childrenKey = 'children') => {
|
|
2
|
-
return array.map(item => {
|
|
2
|
+
return array.map((item) => {
|
|
3
3
|
if (Array.isArray(item[childrenKey])) {
|
|
4
4
|
return fn({
|
|
5
5
|
...item,
|
|
6
|
-
[childrenKey]: mapRecursive(item[childrenKey], fn, childrenKey)
|
|
6
|
+
[childrenKey]: mapRecursive(item[childrenKey], fn, childrenKey),
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
return fn(item);
|
|
@@ -13,7 +13,7 @@ export const mapRecursive = (array, fn, childrenKey = 'children') => {
|
|
|
13
13
|
// 展平有层级结构的 array
|
|
14
14
|
export const flatRecursive = (array, childrenKey = 'children') => {
|
|
15
15
|
const result = [];
|
|
16
|
-
mapRecursive(array, item => result.push(item), childrenKey);
|
|
16
|
+
mapRecursive(array, (item) => result.push(item), childrenKey);
|
|
17
17
|
return result;
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -27,38 +27,36 @@ export const countRecursive = (array, childrenKey = 'children') => {
|
|
|
27
27
|
// 对有层级结构的 array 进行 filter 处理
|
|
28
28
|
// 因为是 DFS 遍历, 可以借助 context.filteredChildren 在过滤/保留子结的同时保持父子结构 (即使父结点不满足筛选条件)
|
|
29
29
|
export const filterRecursive = (array, predicate, childrenKey = 'children') => {
|
|
30
|
-
return array
|
|
31
|
-
...item
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
return predicate(item, context);
|
|
43
|
-
});
|
|
30
|
+
return array
|
|
31
|
+
.map((item) => ({ ...item }))
|
|
32
|
+
.filter((item) => {
|
|
33
|
+
const children = item[childrenKey];
|
|
34
|
+
if (Array.isArray(children)) {
|
|
35
|
+
const filtered = filterRecursive(children, predicate, childrenKey);
|
|
36
|
+
item[childrenKey] = filtered?.length ? filtered : undefined;
|
|
37
|
+
}
|
|
38
|
+
const context = { filteredChildren: item[childrenKey], isLeaf: !children?.length };
|
|
39
|
+
return predicate(item, context);
|
|
40
|
+
});
|
|
44
41
|
};
|
|
45
42
|
|
|
46
43
|
// "http://", "https://" 2 种情况
|
|
47
|
-
export const isUrl = str => {
|
|
44
|
+
export const isUrl = (str) => {
|
|
48
45
|
return /^https?:\/\//.test(str);
|
|
49
46
|
};
|
|
50
|
-
|
|
47
|
+
|
|
48
|
+
export const isIconifyString = (str) => {
|
|
51
49
|
return /^[\w-]+:[\w-]+$/.test(str);
|
|
52
50
|
};
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
53
|
* 检测 path 是否匹配当前 location, path 只考虑 "/" 开头的相对路径
|
|
56
54
|
*/
|
|
57
|
-
export const matchPath = path => {
|
|
55
|
+
export const matchPath = (path) => {
|
|
58
56
|
if (!path || !path?.startsWith('/')) {
|
|
59
57
|
return false;
|
|
60
58
|
}
|
|
61
|
-
const ensureTrailingSlash = str => str.endsWith('/') ? str : `${str}
|
|
59
|
+
const ensureTrailingSlash = (str) => (str.endsWith('/') ? str : `${str}/`);
|
|
62
60
|
const pathname = ensureTrailingSlash(window.location.pathname);
|
|
63
61
|
const normalizedPath = ensureTrailingSlash(new URL(path, window.location.origin).pathname);
|
|
64
62
|
return pathname.startsWith(normalizedPath);
|
|
@@ -68,10 +66,7 @@ export const matchPath = path => {
|
|
|
68
66
|
* 从一组 paths 中, 找到匹配当前 location 的 path, 返回序号
|
|
69
67
|
*/
|
|
70
68
|
export const matchPaths = (paths = []) => {
|
|
71
|
-
const matched = paths.map((item, index) => ({
|
|
72
|
-
path: item,
|
|
73
|
-
index
|
|
74
|
-
})).filter(item => matchPath(item.path));
|
|
69
|
+
const matched = paths.map((item, index) => ({ path: item, index })).filter((item) => matchPath(item.path));
|
|
75
70
|
if (!matched?.length) {
|
|
76
71
|
return -1;
|
|
77
72
|
}
|
|
@@ -80,4 +75,4 @@ export const matchPaths = (paths = []) => {
|
|
|
80
75
|
return prev.path.length >= cur.path.length ? prev : cur;
|
|
81
76
|
}, matched[0]);
|
|
82
77
|
return mostSpecific.index;
|
|
83
|
-
};
|
|
78
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Axios } from 'axios';
|
|
2
|
+
export type SessionContext = {
|
|
3
|
+
session: Session;
|
|
4
|
+
api: Axios;
|
|
5
|
+
};
|
|
6
|
+
export type User = {
|
|
7
|
+
did: string;
|
|
8
|
+
fullName: string;
|
|
9
|
+
role: string;
|
|
10
|
+
avatar: string;
|
|
11
|
+
email?: string;
|
|
12
|
+
phone?: string;
|
|
13
|
+
sourceProvider?: string;
|
|
14
|
+
lastLoginAt?: string;
|
|
15
|
+
lastLoginIp?: string;
|
|
16
|
+
createdAt?: string;
|
|
17
|
+
passports?: any[];
|
|
18
|
+
};
|
|
19
|
+
export type UserCenterTab = {
|
|
20
|
+
value: string;
|
|
21
|
+
label: string;
|
|
22
|
+
url: string;
|
|
23
|
+
protected: boolean;
|
|
24
|
+
icon?: string;
|
|
25
|
+
};
|
|
26
|
+
export type Session = {
|
|
27
|
+
loading: boolean;
|
|
28
|
+
user: User;
|
|
29
|
+
login: any;
|
|
30
|
+
logout: any;
|
|
31
|
+
switch: any;
|
|
32
|
+
switchDid: any;
|
|
33
|
+
switchProfile: any;
|
|
34
|
+
switchPassport: any;
|
|
35
|
+
};
|
|
36
|
+
export type WebhookType = 'slack' | 'api';
|
|
37
|
+
export type WebhookItemData = {
|
|
38
|
+
type: WebhookType;
|
|
39
|
+
url: string;
|
|
40
|
+
};
|
|
41
|
+
export type WebhookItemProps = {
|
|
42
|
+
onTest: (params: WebhookItemData) => void;
|
|
43
|
+
onSave: (params: WebhookItemData) => void;
|
|
44
|
+
onDelete?: (params: WebhookItemData) => void;
|
|
45
|
+
onCancel?: () => void;
|
|
46
|
+
edit: boolean;
|
|
47
|
+
type?: WebhookType;
|
|
48
|
+
url?: string;
|
|
49
|
+
};
|
|
50
|
+
export type CreatePassportProps = {
|
|
51
|
+
issuer: string;
|
|
52
|
+
title: string;
|
|
53
|
+
issuerDid: string;
|
|
54
|
+
issuerAvatarUrl: string;
|
|
55
|
+
ownerDid: string;
|
|
56
|
+
ownerName: string;
|
|
57
|
+
ownerAvatarUrl: string;
|
|
58
|
+
preferredColor?: string;
|
|
59
|
+
revoked?: boolean;
|
|
60
|
+
isDataUrl?: boolean;
|
|
61
|
+
width?: string;
|
|
62
|
+
height?: string;
|
|
63
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export default Dashboard;
|
|
2
|
+
/**
|
|
3
|
+
* 专门用于 (composable) blocklet 的 Dashboard 组件, 解析 blocklet meta 中 section 为 dashboard 的 navigation 数据, 渲染一个 UX Dashboard
|
|
4
|
+
*/
|
|
5
|
+
declare function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddons, sessionManagerProps, links, ...rest }: {
|
|
6
|
+
[x: string]: any;
|
|
7
|
+
meta: any;
|
|
8
|
+
fallbackUrl: any;
|
|
9
|
+
invalidPathFallback: any;
|
|
10
|
+
headerAddons: any;
|
|
11
|
+
sessionManagerProps: any;
|
|
12
|
+
links: any;
|
|
13
|
+
}): import("react").JSX.Element | null;
|
|
14
|
+
declare namespace Dashboard {
|
|
15
|
+
namespace propTypes {
|
|
16
|
+
export { blockletMetaProps as meta };
|
|
17
|
+
export let fallbackUrl: any;
|
|
18
|
+
export let invalidPathFallback: any;
|
|
19
|
+
export let headerAddons: any;
|
|
20
|
+
export { sessionManagerProps };
|
|
21
|
+
export let links: any;
|
|
22
|
+
}
|
|
23
|
+
namespace defaultProps {
|
|
24
|
+
export let meta: {};
|
|
25
|
+
export { publicPath as fallbackUrl };
|
|
26
|
+
let invalidPathFallback_1: null;
|
|
27
|
+
export { invalidPathFallback_1 as invalidPathFallback };
|
|
28
|
+
let headerAddons_1: undefined;
|
|
29
|
+
export { headerAddons_1 as headerAddons };
|
|
30
|
+
export namespace sessionManagerProps_1 {
|
|
31
|
+
let showRole: boolean;
|
|
32
|
+
function onLogout(): void;
|
|
33
|
+
}
|
|
34
|
+
export { sessionManagerProps_1 as sessionManagerProps };
|
|
35
|
+
let links_1: never[];
|
|
36
|
+
export { links_1 as links };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
import { blockletMetaProps } from '../types';
|
|
40
|
+
import { sessionManagerProps } from '../types';
|
|
41
|
+
import { publicPath } from '../blocklets';
|