@blocklet/discuss-kit-ux-lite 2.6.0
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/LICENSE +13 -0
- package/dist/axios.d.ts +8 -0
- package/dist/blocklets.d.ts +13 -0
- package/dist/blocklets.mjs +17 -0
- package/dist/components/api-error-handler/api-error-handler.d.ts +13 -0
- package/dist/components/api-error-handler/api-error-handler.mjs +25 -0
- package/dist/components/api-error-handler/default-handler.d.ts +8 -0
- package/dist/components/api-error-handler/default-handler.mjs +69 -0
- package/dist/components/api-error-handler/index.d.ts +2 -0
- package/dist/components/api-error-handler/index.mjs +2 -0
- package/dist/components/api-error-handler/json-validation-interceptor.d.ts +2 -0
- package/dist/components/api-error-handler/json-validation-interceptor.mjs +9 -0
- package/dist/components/arcsphere/index.d.ts +16 -0
- package/dist/components/arcsphere/index.mjs +52 -0
- package/dist/components/authz/access-control.d.ts +24 -0
- package/dist/components/authz/access-control.mjs +15 -0
- package/dist/components/authz/context.d.ts +13 -0
- package/dist/components/authz/context.mjs +30 -0
- package/dist/components/authz/index.d.ts +2 -0
- package/dist/components/authz/index.mjs +2 -0
- package/dist/components/auto-translate/api.d.ts +14 -0
- package/dist/components/auto-translate/api.mjs +23 -0
- package/dist/components/auto-translate/auto-translate-button.d.ts +5 -0
- package/dist/components/auto-translate/auto-translate-button.mjs +48 -0
- package/dist/components/auto-translate/editor-store-adaptor.d.ts +1 -0
- package/dist/components/auto-translate/editor-store-adaptor.mjs +14 -0
- package/dist/components/auto-translate/index.d.ts +6 -0
- package/dist/components/auto-translate/index.mjs +6 -0
- package/dist/components/auto-translate/languages.d.ts +13 -0
- package/dist/components/auto-translate/languages.mjs +61 -0
- package/dist/components/auto-translate/post-auto-translate-plugin.d.ts +14 -0
- package/dist/components/auto-translate/post-auto-translate-plugin.mjs +32 -0
- package/dist/components/auto-translate/store.d.ts +21 -0
- package/dist/components/auto-translate/store.mjs +23 -0
- package/dist/components/auto-translate/translate.d.ts +17 -0
- package/dist/components/auto-translate/translate.mjs +103 -0
- package/dist/components/auto-translate/utils.d.ts +4 -0
- package/dist/components/auto-translate/utils.mjs +14 -0
- package/dist/components/auto-translate/with-availibility-check.d.ts +2 -0
- package/dist/components/auto-translate/with-availibility-check.mjs +10 -0
- package/dist/components/avatars/author-info.d.ts +23 -0
- package/dist/components/avatars/author-info.mjs +178 -0
- package/dist/components/avatars/avatar.d.ts +7 -0
- package/dist/components/avatars/avatar.mjs +9 -0
- package/dist/components/avatars/avatars.d.ts +10 -0
- package/dist/components/avatars/avatars.mjs +49 -0
- package/dist/components/avatars/badge.d.ts +14 -0
- package/dist/components/avatars/badge.mjs +178 -0
- package/dist/components/avatars/index.d.ts +5 -0
- package/dist/components/avatars/index.mjs +5 -0
- package/dist/components/avatars/system-user.d.ts +10 -0
- package/dist/components/avatars/system-user.mjs +58 -0
- package/dist/components/button-group/button-group.d.ts +18 -0
- package/dist/components/button-group/button-group.mjs +195 -0
- package/dist/components/button-group/index.d.ts +1 -0
- package/dist/components/button-group/index.mjs +1 -0
- package/dist/components/confirm.d.ts +29 -0
- package/dist/components/confirm.mjs +103 -0
- package/dist/components/dayjs.d.ts +3 -0
- package/dist/components/dayjs.mjs +5 -0
- package/dist/components/default-editor-config-provider.d.ts +8 -0
- package/dist/components/default-editor-config-provider.mjs +108 -0
- package/dist/components/dirty-prompt.d.ts +8 -0
- package/dist/components/dirty-prompt.mjs +117 -0
- package/dist/components/editor/blocklet-editor.d.ts +1 -0
- package/dist/components/editor/blocklet-editor.mjs +1 -0
- package/dist/components/editor/editor.d.ts +17 -0
- package/dist/components/editor/editor.mjs +35 -0
- package/dist/components/editor/index.d.ts +4 -0
- package/dist/components/editor/index.mjs +3 -0
- package/dist/components/editor/lazy-editor.d.ts +3 -0
- package/dist/components/editor/lazy-editor.mjs +14 -0
- package/dist/components/editor/viewer.d.ts +10 -0
- package/dist/components/editor/viewer.mjs +18 -0
- package/dist/components/emoji-icon.d.ts +11 -0
- package/dist/components/emoji-icon.mjs +62 -0
- package/dist/components/empty-status/empty-status.d.ts +7 -0
- package/dist/components/empty-status/empty-status.mjs +24 -0
- package/dist/components/empty-status/index.d.ts +1 -0
- package/dist/components/empty-status/index.mjs +1 -0
- package/dist/components/hooks/changed.d.ts +10 -0
- package/dist/components/hooks/changed.mjs +34 -0
- package/dist/components/hooks/index.d.ts +6 -0
- package/dist/components/hooks/index.mjs +6 -0
- package/dist/components/hooks/interval.d.ts +6 -0
- package/dist/components/hooks/interval.mjs +16 -0
- package/dist/components/hooks/locale-context.d.ts +10 -0
- package/dist/components/hooks/locale-context.mjs +12 -0
- package/dist/components/hooks/measure.d.ts +5 -0
- package/dist/components/hooks/measure.mjs +8 -0
- package/dist/components/hooks/now.d.ts +1 -0
- package/dist/components/hooks/now.mjs +10 -0
- package/dist/components/hooks/responsive.d.ts +17 -0
- package/dist/components/hooks/responsive.mjs +25 -0
- package/dist/components/hooks/session.d.ts +12 -0
- package/dist/components/hooks/session.mjs +48 -0
- package/dist/components/hooks/use-event-callback.d.ts +1 -0
- package/dist/components/hooks/use-event-callback.mjs +14 -0
- package/dist/components/icon-button.d.ts +6 -0
- package/dist/components/icon-button.mjs +37 -0
- package/dist/components/input/auto-clear-plugin.d.ts +3 -0
- package/dist/components/input/auto-clear-plugin.mjs +20 -0
- package/dist/components/input/comment-input.d.ts +11 -0
- package/dist/components/input/comment-input.mjs +108 -0
- package/dist/components/input/index.d.ts +4 -0
- package/dist/components/input/index.mjs +4 -0
- package/dist/components/input/input.d.ts +29 -0
- package/dist/components/input/input.mjs +149 -0
- package/dist/components/input/post-edit.d.ts +10 -0
- package/dist/components/input/post-edit.mjs +49 -0
- package/dist/components/input/scrollable-editor-wrapper.d.ts +9 -0
- package/dist/components/input/scrollable-editor-wrapper.mjs +18 -0
- package/dist/components/input/shortcut-plugin.d.ts +7 -0
- package/dist/components/input/shortcut-plugin.mjs +28 -0
- package/dist/components/lexical.d.ts +10 -0
- package/dist/components/lexical.mjs +56 -0
- package/dist/components/locale/en.d.ts +117 -0
- package/dist/components/locale/en.mjs +116 -0
- package/dist/components/locale/index.d.ts +236 -0
- package/dist/components/locale/index.mjs +3 -0
- package/dist/components/locale/zh.d.ts +119 -0
- package/dist/components/locale/zh.mjs +118 -0
- package/dist/components/pagination.d.ts +12 -0
- package/dist/components/pagination.mjs +44 -0
- package/dist/components/posts/comment-list/comment-list.d.ts +5 -0
- package/dist/components/posts/comment-list/comment-list.mjs +163 -0
- package/dist/components/posts/comment-list/context.d.ts +76 -0
- package/dist/components/posts/comment-list/context.mjs +318 -0
- package/dist/components/posts/comment.d.ts +16 -0
- package/dist/components/posts/comment.mjs +184 -0
- package/dist/components/posts/index.d.ts +6 -0
- package/dist/components/posts/index.mjs +6 -0
- package/dist/components/posts/menu.d.ts +14 -0
- package/dist/components/posts/menu.mjs +83 -0
- package/dist/components/posts/post-content.d.ts +16 -0
- package/dist/components/posts/post-content.mjs +63 -0
- package/dist/components/posts/post.d.ts +26 -0
- package/dist/components/posts/post.mjs +198 -0
- package/dist/components/profile-card/index.d.ts +1 -0
- package/dist/components/profile-card/index.mjs +1 -0
- package/dist/components/profile-card/profile-card.d.ts +15 -0
- package/dist/components/profile-card/profile-card.mjs +140 -0
- package/dist/components/rating/binary-thumb.d.ts +9 -0
- package/dist/components/rating/binary-thumb.mjs +162 -0
- package/dist/components/rating/github-reaction-container.d.ts +9 -0
- package/dist/components/rating/github-reaction-container.mjs +46 -0
- package/dist/components/rating/github-reaction.d.ts +18 -0
- package/dist/components/rating/github-reaction.mjs +174 -0
- package/dist/components/rating/index.d.ts +3 -0
- package/dist/components/rating/index.mjs +3 -0
- package/dist/components/rating/rater-list.d.ts +10 -0
- package/dist/components/rating/rater-list.mjs +33 -0
- package/dist/components/rating/rating.d.ts +27 -0
- package/dist/components/rating/rating.mjs +50 -0
- package/dist/components/segmented-control.d.ts +14 -0
- package/dist/components/segmented-control.mjs +55 -0
- package/dist/components/shared/relative-time.d.ts +8 -0
- package/dist/components/shared/relative-time.mjs +21 -0
- package/dist/components/toast.d.ts +8 -0
- package/dist/components/toast.mjs +44 -0
- package/dist/components/uploader/index.d.ts +13 -0
- package/dist/components/uploader/index.mjs +70 -0
- package/dist/components/uploader/utils.d.ts +1 -0
- package/dist/components/uploader/utils.mjs +16 -0
- package/dist/components/utils.d.ts +22 -0
- package/dist/components/utils.mjs +103 -0
- package/dist/components/view-more.d.ts +4 -0
- package/dist/components/view-more.mjs +50 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.mjs +14 -0
- package/dist/global.d.ts +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.mjs +29 -0
- package/dist/preferences.d.ts +2 -0
- package/dist/preferences.mjs +9 -0
- package/dist/theme/index.d.ts +8 -0
- package/dist/theme/index.mjs +96 -0
- package/dist/theme/typography.d.ts +2 -0
- package/dist/theme/typography.mjs +66 -0
- package/dist/type-override.d.ts +7 -0
- package/dist/types.d.ts +84 -0
- package/dist/types.mjs +0 -0
- package/dist/vite-env.d.ts +1 -0
- package/dist/ws.d.ts +3 -0
- package/dist/ws.mjs +39 -0
- package/package.json +81 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Box from "@mui/material/Box";
|
|
3
|
+
import DID from "@arcblock/ux/lib/DID";
|
|
4
|
+
import NotificationsActiveOutlinedIcon from "@mui/icons-material/NotificationsActiveOutlined";
|
|
5
|
+
export default function SystemUser({
|
|
6
|
+
name = "System",
|
|
7
|
+
showDidAddress = true,
|
|
8
|
+
showIcon = true,
|
|
9
|
+
size = "normal",
|
|
10
|
+
icon,
|
|
11
|
+
...rest
|
|
12
|
+
}) {
|
|
13
|
+
const sm = size === "sm";
|
|
14
|
+
const iconSize = sm ? 40 : 48;
|
|
15
|
+
return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1, fontSize: 14 }, ...rest, children: [
|
|
16
|
+
showIcon && /* @__PURE__ */ jsx(
|
|
17
|
+
Box,
|
|
18
|
+
{
|
|
19
|
+
sx: {
|
|
20
|
+
flex: "0 0 auto",
|
|
21
|
+
display: "flex",
|
|
22
|
+
justifyContent: "center",
|
|
23
|
+
alignItems: "center",
|
|
24
|
+
width: iconSize,
|
|
25
|
+
height: iconSize,
|
|
26
|
+
p: 1,
|
|
27
|
+
color: "#fff",
|
|
28
|
+
bgcolor: "secondary.main",
|
|
29
|
+
borderRadius: "100%"
|
|
30
|
+
},
|
|
31
|
+
children: icon || /* @__PURE__ */ jsx(NotificationsActiveOutlinedIcon, { sx: { fontSize: size === "sm" ? 16 : 18 } })
|
|
32
|
+
}
|
|
33
|
+
),
|
|
34
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", overflow: "hidden" }, children: [
|
|
35
|
+
/* @__PURE__ */ jsx(
|
|
36
|
+
Box,
|
|
37
|
+
{
|
|
38
|
+
sx: {
|
|
39
|
+
lineHeight: 1.5,
|
|
40
|
+
display: "flex",
|
|
41
|
+
alignItems: "center"
|
|
42
|
+
},
|
|
43
|
+
children: /* @__PURE__ */ jsx(Box, { component: "span", sx: { fontWeight: "bold" }, children: name })
|
|
44
|
+
}
|
|
45
|
+
),
|
|
46
|
+
showDidAddress && /* @__PURE__ */ jsx(
|
|
47
|
+
DID,
|
|
48
|
+
{
|
|
49
|
+
style: { lineHeight: 1.5, minHeight: 20, maxWidth: 200 },
|
|
50
|
+
size: 14,
|
|
51
|
+
did: window.blocklet.appId,
|
|
52
|
+
copyable: false,
|
|
53
|
+
compact: true
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
] })
|
|
57
|
+
] });
|
|
58
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface ButtonItem {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
icon: string;
|
|
6
|
+
}
|
|
7
|
+
interface Props {
|
|
8
|
+
data: ButtonItem[];
|
|
9
|
+
theme: string;
|
|
10
|
+
urlName: string;
|
|
11
|
+
defaultButton?: ButtonItem;
|
|
12
|
+
onSelectTab: (selectTab: string[]) => void;
|
|
13
|
+
type: string;
|
|
14
|
+
allButton?: boolean;
|
|
15
|
+
urlParams?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export default function ButtonGroup({ data, theme, urlName, defaultButton, urlParams, allButton, onSelectTab, type, ...rest }: Props): import("react").JSX.Element;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
3
|
+
import { Box, Button } from "@mui/material";
|
|
4
|
+
import { css } from "@emotion/css";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
import IconButton from "@mui/material/IconButton";
|
|
7
|
+
import { Link, useNavigate, useParams, useSearchParams } from "react-router-dom";
|
|
8
|
+
import { BorderColorOutlined as BorderColorOutlinedIcon } from "@mui/icons-material";
|
|
9
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
10
|
+
import { AccessControl } from "../authz/index.mjs";
|
|
11
|
+
export default function ButtonGroup({
|
|
12
|
+
data,
|
|
13
|
+
theme = "dark",
|
|
14
|
+
urlName,
|
|
15
|
+
defaultButton,
|
|
16
|
+
urlParams = true,
|
|
17
|
+
allButton = true,
|
|
18
|
+
onSelectTab,
|
|
19
|
+
type,
|
|
20
|
+
...rest
|
|
21
|
+
}) {
|
|
22
|
+
const { t } = useLocaleContext();
|
|
23
|
+
const downSm = useMediaQuery((mainTheme) => mainTheme.breakpoints.down("sm"));
|
|
24
|
+
const navigate = useNavigate();
|
|
25
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
26
|
+
const { boardId } = useParams();
|
|
27
|
+
const selectedString = searchParams.get(urlName);
|
|
28
|
+
const dataWithDefault = defaultButton && data?.length > 0 ? [defaultButton, ...data] : data;
|
|
29
|
+
const selectedArray = selectedString !== null && selectedString !== "" ? selectedString.split(",") : dataWithDefault?.map((item) => item.id);
|
|
30
|
+
const [selectTab, setSelectTab] = useState(urlParams ? selectedArray : [boardId]);
|
|
31
|
+
const [selectAll, setSelectAll] = useState(false);
|
|
32
|
+
const updateUrl = (url, newSelectTab) => {
|
|
33
|
+
const formatNewSelectTab = newSelectTab.filter(Boolean);
|
|
34
|
+
if (urlParams) {
|
|
35
|
+
setSearchParams({
|
|
36
|
+
...searchParams,
|
|
37
|
+
[url]: formatNewSelectTab.join(",")
|
|
38
|
+
});
|
|
39
|
+
} else if (formatNewSelectTab.length === 0) {
|
|
40
|
+
navigate(`/${type}`);
|
|
41
|
+
} else {
|
|
42
|
+
navigate(`/${type}/boards/${formatNewSelectTab.join(",")}`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const handleClick = (item) => {
|
|
46
|
+
setSelectTab([item.id]);
|
|
47
|
+
updateUrl(urlName, [item.id]);
|
|
48
|
+
};
|
|
49
|
+
const handleSelectAll = () => {
|
|
50
|
+
setSelectAll((prevSelectAll) => {
|
|
51
|
+
const newSelectAll = !prevSelectAll;
|
|
52
|
+
const newSelectTab = newSelectAll ? dataWithDefault?.map((item) => item.id) : [];
|
|
53
|
+
setSelectTab(newSelectTab);
|
|
54
|
+
updateUrl(urlName, [""]);
|
|
55
|
+
return newSelectAll;
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (JSON.stringify(selectedArray) !== JSON.stringify(selectTab)) {
|
|
60
|
+
if (urlParams) {
|
|
61
|
+
setSelectTab(selectedArray || []);
|
|
62
|
+
} else if (boardId) {
|
|
63
|
+
if (data?.find((item) => item.id === boardId) || boardId === "default") {
|
|
64
|
+
setSelectTab([boardId]);
|
|
65
|
+
} else {
|
|
66
|
+
navigate(`/${type}/`);
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
setSelectTab(dataWithDefault?.map((item) => item.id));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, [data, boardId]);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (urlParams) {
|
|
75
|
+
if (selectedString === null || selectedString === "") {
|
|
76
|
+
setSelectAll(true);
|
|
77
|
+
} else if (selectTab?.length === dataWithDefault?.length) {
|
|
78
|
+
setSelectAll(true);
|
|
79
|
+
} else {
|
|
80
|
+
setSelectAll(false);
|
|
81
|
+
}
|
|
82
|
+
} else if (boardId) {
|
|
83
|
+
setSelectAll(false);
|
|
84
|
+
} else {
|
|
85
|
+
setSelectAll(true);
|
|
86
|
+
}
|
|
87
|
+
if (onSelectTab) onSelectTab(selectTab);
|
|
88
|
+
}, [selectTab, selectedArray, boardId]);
|
|
89
|
+
return (
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
91
|
+
/* @__PURE__ */ jsxs(Box, { className: Group, children: [
|
|
92
|
+
/* @__PURE__ */ jsxs(
|
|
93
|
+
Box,
|
|
94
|
+
{
|
|
95
|
+
sx: {
|
|
96
|
+
bgcolor: theme === "dark" ? "#F9FAFB" : "",
|
|
97
|
+
width: "fit-content",
|
|
98
|
+
maxWidth: "calc(100% - 16px)",
|
|
99
|
+
borderRadius: "99999px",
|
|
100
|
+
borderTopRightRadius: downSm ? 0 : "99999px",
|
|
101
|
+
borderBottomRightRadius: downSm ? 0 : "99999px",
|
|
102
|
+
overflow: "scroll",
|
|
103
|
+
whiteSpace: "nowrap",
|
|
104
|
+
mr: 2
|
|
105
|
+
},
|
|
106
|
+
children: [
|
|
107
|
+
allButton && /* @__PURE__ */ jsx(
|
|
108
|
+
Button,
|
|
109
|
+
{
|
|
110
|
+
onClick: handleSelectAll,
|
|
111
|
+
sx: {
|
|
112
|
+
backgroundColor: selectAll ? "#ffffff" : "",
|
|
113
|
+
color: selectAll ? "#030712" : "#4b5563",
|
|
114
|
+
border: selectAll ? "1px solid #e5e7eb!important" : "1px solid transparent"
|
|
115
|
+
},
|
|
116
|
+
...rest,
|
|
117
|
+
children: t("all")
|
|
118
|
+
}
|
|
119
|
+
),
|
|
120
|
+
dataWithDefault?.map((item, index) => {
|
|
121
|
+
const isActive = urlParams ? !selectAll && selectTab?.includes(item.id) : boardId === item.id;
|
|
122
|
+
return /* @__PURE__ */ jsx(
|
|
123
|
+
Button,
|
|
124
|
+
{
|
|
125
|
+
onClick: () => handleClick(item),
|
|
126
|
+
sx: {
|
|
127
|
+
...isActive && {
|
|
128
|
+
backgroundColor: "#ffffff",
|
|
129
|
+
color: "#030712",
|
|
130
|
+
border: "1px solid #e5e7eb!important"
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
...rest,
|
|
134
|
+
children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center" }, children: [
|
|
135
|
+
item?.icon,
|
|
136
|
+
" ",
|
|
137
|
+
item?.title
|
|
138
|
+
] })
|
|
139
|
+
},
|
|
140
|
+
index
|
|
141
|
+
);
|
|
142
|
+
})
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
),
|
|
146
|
+
urlName !== "type" && /* @__PURE__ */ jsx(AccessControl, { roles: ["admin", "owner"], children: /* @__PURE__ */ jsx(
|
|
147
|
+
IconButton,
|
|
148
|
+
{
|
|
149
|
+
component: Link,
|
|
150
|
+
color: "inherit",
|
|
151
|
+
size: "small",
|
|
152
|
+
to: `/boards?type=${type}`,
|
|
153
|
+
sx: { color: "grey.500" },
|
|
154
|
+
children: /* @__PURE__ */ jsx(BorderColorOutlinedIcon, { sx: { fontSize: 16 } })
|
|
155
|
+
}
|
|
156
|
+
) })
|
|
157
|
+
] })
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
const Group = css`
|
|
161
|
+
display: flex;
|
|
162
|
+
flex-direction: row;
|
|
163
|
+
.MuiButtonBase-root {
|
|
164
|
+
border-radius: 9999px;
|
|
165
|
+
color: #4b5563;
|
|
166
|
+
margin: 5px 8px 5px 5px;
|
|
167
|
+
padding: 5px 12px;
|
|
168
|
+
line-height: 22px;
|
|
169
|
+
font-size: 13px;
|
|
170
|
+
border: 1px solid transparent;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.MuiButtonBase-root:last-of-type {
|
|
174
|
+
margin-right: 0;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.MuiButtonBase-root:first-of-type {
|
|
178
|
+
margin-left: 0;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.MuiButtonBase-root:hover {
|
|
182
|
+
background-color: #ffffff;
|
|
183
|
+
color: #030712;
|
|
184
|
+
border: 1px solid #e5e7eb;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
* {
|
|
188
|
+
scrollbar-width: none; /* Firefox */
|
|
189
|
+
-ms-overflow-style: none; /* IE and Edge */
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
*::-webkit-scrollbar {
|
|
193
|
+
display: none; /* Chrome, Safari and Opera */
|
|
194
|
+
}
|
|
195
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ButtonGroup } from './button-group';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ButtonGroup } from "./button-group.mjs";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DialogProps, ButtonProps } from '@mui/material';
|
|
2
|
+
import { ReactNode, type JSX } from 'react';
|
|
3
|
+
interface ConfirmProviderProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
type ConfirmOptions = {
|
|
7
|
+
title: ReactNode;
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
cancelText?: ReactNode;
|
|
10
|
+
okText?: ReactNode;
|
|
11
|
+
cancelButtonProps?: ButtonProps;
|
|
12
|
+
okButtonProps?: ButtonProps;
|
|
13
|
+
dialogProps?: Omit<DialogProps, 'open'>;
|
|
14
|
+
actions?: (actions: JSX.Element[], onClose: () => void) => JSX.Element[];
|
|
15
|
+
};
|
|
16
|
+
type ConfirmFunc = (options: ConfirmOptions) => Promise<boolean>;
|
|
17
|
+
interface ConfirmContextType {
|
|
18
|
+
open: boolean;
|
|
19
|
+
confirm: ConfirmFunc;
|
|
20
|
+
}
|
|
21
|
+
interface ConfirmProps extends Omit<DialogProps, 'title'>, Omit<ConfirmOptions, 'dialogProps'> {
|
|
22
|
+
handleOk: () => void;
|
|
23
|
+
handleCancel: () => void;
|
|
24
|
+
}
|
|
25
|
+
export declare function Confirm({ open, title, description, handleOk, handleCancel, okText, okButtonProps, cancelText, cancelButtonProps, actions, ...rest }: ConfirmProps): JSX.Element | null;
|
|
26
|
+
export declare const ConfirmContext: import("react").Context<ConfirmContextType>;
|
|
27
|
+
export declare const useConfirm: () => ConfirmContextType;
|
|
28
|
+
export declare function ConfirmProvider({ children }: ConfirmProviderProps): JSX.Element;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
Dialog,
|
|
4
|
+
DialogActions,
|
|
5
|
+
DialogContent,
|
|
6
|
+
DialogContentText,
|
|
7
|
+
DialogTitle,
|
|
8
|
+
Button,
|
|
9
|
+
useMediaQuery
|
|
10
|
+
} from "@mui/material";
|
|
11
|
+
import { useTheme } from "@mui/material/styles";
|
|
12
|
+
import { createContext, isValidElement, useContext, useMemo, useRef, useState } from "react";
|
|
13
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
14
|
+
export function Confirm({
|
|
15
|
+
open,
|
|
16
|
+
title,
|
|
17
|
+
description,
|
|
18
|
+
handleOk,
|
|
19
|
+
handleCancel,
|
|
20
|
+
okText,
|
|
21
|
+
okButtonProps,
|
|
22
|
+
cancelText,
|
|
23
|
+
cancelButtonProps,
|
|
24
|
+
actions,
|
|
25
|
+
...rest
|
|
26
|
+
}) {
|
|
27
|
+
const theme = useTheme();
|
|
28
|
+
const fullScreen = useMediaQuery(theme.breakpoints.down("md"));
|
|
29
|
+
const { t } = useLocaleContext();
|
|
30
|
+
const renderDesc = () => {
|
|
31
|
+
if (isValidElement(description)) {
|
|
32
|
+
return description;
|
|
33
|
+
}
|
|
34
|
+
return /* @__PURE__ */ jsx(DialogContentText, { children: description });
|
|
35
|
+
};
|
|
36
|
+
if (!open) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const renderActions = () => {
|
|
40
|
+
const actionsArr = [
|
|
41
|
+
/* @__PURE__ */ jsx(Button, { color: "inherit", variant: "text", onClick: handleCancel, ...cancelButtonProps, children: cancelText || t("cancel") || "Cancel" }, "cancel"),
|
|
42
|
+
/* @__PURE__ */ jsx(Button, { color: "primary", variant: "contained", onClick: handleOk, ...okButtonProps, children: okText || t("confirm") || "Yes" }, "confirm")
|
|
43
|
+
];
|
|
44
|
+
if (actions) {
|
|
45
|
+
return actions(actionsArr, handleCancel);
|
|
46
|
+
}
|
|
47
|
+
return actionsArr;
|
|
48
|
+
};
|
|
49
|
+
return /* @__PURE__ */ jsxs(Dialog, { fullScreen, onClose: handleCancel, maxWidth: "md", ...rest, open, children: [
|
|
50
|
+
/* @__PURE__ */ jsx(DialogTitle, { variant: "h4", children: title }),
|
|
51
|
+
/* @__PURE__ */ jsx(DialogContent, { sx: { minWidth: { xs: "initial", md: 400 } }, children: renderDesc() }),
|
|
52
|
+
/* @__PURE__ */ jsx(DialogActions, { children: renderActions() })
|
|
53
|
+
] });
|
|
54
|
+
}
|
|
55
|
+
export const ConfirmContext = createContext({});
|
|
56
|
+
export const useConfirm = () => useContext(ConfirmContext);
|
|
57
|
+
export function ConfirmProvider({ children }) {
|
|
58
|
+
const [open, setOpen] = useState(false);
|
|
59
|
+
const [currentOptions, setCurrentOptions] = useState({});
|
|
60
|
+
const resolver = useRef(void 0);
|
|
61
|
+
const handleOk = () => {
|
|
62
|
+
resolver.current?.(true);
|
|
63
|
+
setOpen(false);
|
|
64
|
+
};
|
|
65
|
+
const handleCancel = () => {
|
|
66
|
+
resolver.current?.(false);
|
|
67
|
+
setOpen(false);
|
|
68
|
+
};
|
|
69
|
+
const confirm = (options) => {
|
|
70
|
+
setCurrentOptions(options);
|
|
71
|
+
setOpen(true);
|
|
72
|
+
return new Promise((resolve) => {
|
|
73
|
+
resolver.current = resolve;
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const value = useMemo(
|
|
77
|
+
() => ({
|
|
78
|
+
open,
|
|
79
|
+
confirm
|
|
80
|
+
}),
|
|
81
|
+
[open]
|
|
82
|
+
);
|
|
83
|
+
return /* @__PURE__ */ jsxs(ConfirmContext.Provider, { value, children: [
|
|
84
|
+
children,
|
|
85
|
+
/* @__PURE__ */ jsx(
|
|
86
|
+
Confirm,
|
|
87
|
+
{
|
|
88
|
+
...currentOptions.dialogProps,
|
|
89
|
+
open,
|
|
90
|
+
onClose: handleCancel,
|
|
91
|
+
title: currentOptions.title,
|
|
92
|
+
description: currentOptions.description,
|
|
93
|
+
okText: currentOptions.okText,
|
|
94
|
+
okButtonProps: currentOptions.okButtonProps,
|
|
95
|
+
cancelText: currentOptions.cancelText,
|
|
96
|
+
cancelButtonProps: currentOptions.cancelButtonProps,
|
|
97
|
+
handleOk,
|
|
98
|
+
handleCancel,
|
|
99
|
+
actions: currentOptions.actions
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
] });
|
|
103
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { AxiosInstance } from 'axios';
|
|
3
|
+
import type { EditorConfig } from '@blocklet/editor/lib/config';
|
|
4
|
+
export default function DefaultEditorConfigProvider({ request, children, editorConfig, }: {
|
|
5
|
+
request: AxiosInstance;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
editorConfig?: EditorConfig;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { EditorConfigProvider } from "@blocklet/editor/lib/config";
|
|
4
|
+
import { joinURL } from "ufo";
|
|
5
|
+
import { useMediaQuery } from "@mui/material";
|
|
6
|
+
import { useSessionContext } from "./hooks/index.mjs";
|
|
7
|
+
import { discussKitMountPoint } from "./utils.mjs";
|
|
8
|
+
import { useUploader } from "./uploader/index.mjs";
|
|
9
|
+
import { MAX_DISCUSSION_LENGTH } from "../constants.mjs";
|
|
10
|
+
const baseURL = joinURL(window.location.origin, discussKitMountPoint || "");
|
|
11
|
+
let cachedTemplateList = null;
|
|
12
|
+
export default function DefaultEditorConfigProvider({
|
|
13
|
+
request,
|
|
14
|
+
children,
|
|
15
|
+
editorConfig
|
|
16
|
+
}) {
|
|
17
|
+
const downMd = useMediaQuery((theme) => theme.breakpoints.down("md"));
|
|
18
|
+
const { session } = useSessionContext();
|
|
19
|
+
const isAdmin = ["owner", "admin"].includes(session?.user?.role);
|
|
20
|
+
const uploaderRef = useUploader();
|
|
21
|
+
const config = useMemo(() => {
|
|
22
|
+
const userService = {
|
|
23
|
+
search: async (text) => {
|
|
24
|
+
const { data } = await request.get(`/api/mention?search=${text}`, { baseURL });
|
|
25
|
+
return data;
|
|
26
|
+
},
|
|
27
|
+
getCurrentUserDid: () => session?.user?.did
|
|
28
|
+
};
|
|
29
|
+
const AI = {
|
|
30
|
+
checkAvailable: async () => {
|
|
31
|
+
if (downMd) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const { data } = await request.get("/api/aigne/check", { baseURL });
|
|
36
|
+
return !!data?.connected;
|
|
37
|
+
} catch (e) {
|
|
38
|
+
e.markAsHandled?.();
|
|
39
|
+
console.error(e);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
completions: async (payload) => {
|
|
44
|
+
if (typeof payload === "string") {
|
|
45
|
+
const result = await request.post(
|
|
46
|
+
joinURL("/api/aigne/chat"),
|
|
47
|
+
{ message: payload },
|
|
48
|
+
{ baseURL, timeout: 3e4 }
|
|
49
|
+
);
|
|
50
|
+
return result.data?.result?.text || "";
|
|
51
|
+
}
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const templatePlugin = {
|
|
56
|
+
fetchTemplateList: async ({ reload = false } = {}) => {
|
|
57
|
+
if (!reload && cachedTemplateList?.length > 0) {
|
|
58
|
+
return cachedTemplateList;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const { data = [] } = await request.get(joinURL("/api/resources/posts"), { baseURL });
|
|
62
|
+
cachedTemplateList = data;
|
|
63
|
+
return data;
|
|
64
|
+
} catch (e) {
|
|
65
|
+
e.markAsHandled?.();
|
|
66
|
+
console.error(e);
|
|
67
|
+
cachedTemplateList = null;
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
importTemplate: async (item) => {
|
|
72
|
+
if (!item?.id || !item?.content) {
|
|
73
|
+
throw new Error("item is required");
|
|
74
|
+
}
|
|
75
|
+
const { data } = await request.post(joinURL("/api/resources/import"), item, { baseURL });
|
|
76
|
+
return data;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const value = {
|
|
80
|
+
uploader: {
|
|
81
|
+
upload: async (blobFile) => {
|
|
82
|
+
const uploader = uploaderRef.current.getUploader();
|
|
83
|
+
const { data } = await uploader.uploadFile(blobFile).then((result) => {
|
|
84
|
+
return result?.response;
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
url: `/${data.filename}`
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
userService,
|
|
92
|
+
blockletEmbedEndpoint: joinURL(window.location.origin, discussKitMountPoint || "", "/api/embed/check"),
|
|
93
|
+
openGraphEndpoint: joinURL(window.location.origin, discussKitMountPoint || "", "/api/embed/og"),
|
|
94
|
+
AI,
|
|
95
|
+
templatePlugin,
|
|
96
|
+
characterLimitConfig: {
|
|
97
|
+
maxLength: MAX_DISCUSSION_LENGTH,
|
|
98
|
+
indicatorStyle: {
|
|
99
|
+
position: "fixed",
|
|
100
|
+
bottom: 12
|
|
101
|
+
},
|
|
102
|
+
alignLeft: true
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
return { ...value, ...editorConfig };
|
|
106
|
+
}, [isAdmin, request, session?.user?.did, downMd, editorConfig]);
|
|
107
|
+
return /* @__PURE__ */ jsx(EditorConfigProvider, { value: config, children });
|
|
108
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const DirtyPromptContainer: import("unstated-next").Container<{
|
|
3
|
+
dirty: boolean;
|
|
4
|
+
markDirty: () => void;
|
|
5
|
+
reset: (callback?: Function) => void;
|
|
6
|
+
check: () => Promise<boolean>;
|
|
7
|
+
}, void>;
|
|
8
|
+
export declare function ConfirmNavigation(): import("react").JSX.Element;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { createContainer } from "unstated-next";
|
|
4
|
+
import { useBlocker } from "react-router-dom";
|
|
5
|
+
import { useGetState } from "ahooks";
|
|
6
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
7
|
+
import { useConfirm, Confirm } from "./confirm.mjs";
|
|
8
|
+
const useBeforeUnloadPrompt = (dirty) => {
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const showPrompt = (e) => {
|
|
11
|
+
if (dirty) {
|
|
12
|
+
e.preventDefault();
|
|
13
|
+
e.returnValue = "";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
window.addEventListener("beforeunload", showPrompt);
|
|
17
|
+
return () => {
|
|
18
|
+
window.removeEventListener("beforeunload", showPrompt);
|
|
19
|
+
};
|
|
20
|
+
}, [dirty]);
|
|
21
|
+
};
|
|
22
|
+
const useDirtySources = () => {
|
|
23
|
+
const [state, setState] = useState({});
|
|
24
|
+
const dirty = Object.values(state).some(Boolean);
|
|
25
|
+
const markDirty = useCallback(
|
|
26
|
+
(key) => {
|
|
27
|
+
setState((prev) => ({ ...prev, [key]: true }));
|
|
28
|
+
},
|
|
29
|
+
[setState]
|
|
30
|
+
);
|
|
31
|
+
const resetDirty = useCallback(
|
|
32
|
+
(key) => {
|
|
33
|
+
setState((prev) => ({ ...prev, [key]: false }));
|
|
34
|
+
},
|
|
35
|
+
[setState]
|
|
36
|
+
);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const onMarkDirty = ((e) => markDirty(e.detail.key));
|
|
39
|
+
const onReset = ((e) => resetDirty(e.detail.key));
|
|
40
|
+
window.addEventListener("blocklet:markDirty", onMarkDirty);
|
|
41
|
+
window.addEventListener("blocklet:resetDirty", onReset);
|
|
42
|
+
return () => {
|
|
43
|
+
window.removeEventListener("blocklet:markDirty", onMarkDirty);
|
|
44
|
+
window.removeEventListener("blocklet:resetDirty", onReset);
|
|
45
|
+
};
|
|
46
|
+
}, [markDirty, resetDirty]);
|
|
47
|
+
return { dirty };
|
|
48
|
+
};
|
|
49
|
+
const useDirtyPrompt = () => {
|
|
50
|
+
const { t } = useLocaleContext();
|
|
51
|
+
const [dirty, setDirty, getDirty] = useGetState(false);
|
|
52
|
+
const { confirm } = useConfirm();
|
|
53
|
+
const resetCallbackRef = useRef(null);
|
|
54
|
+
const multiDirtySourceState = useDirtySources();
|
|
55
|
+
useBeforeUnloadPrompt(dirty || multiDirtySourceState.dirty);
|
|
56
|
+
const reset = useCallback(
|
|
57
|
+
(callback) => {
|
|
58
|
+
resetCallbackRef.current = callback;
|
|
59
|
+
setDirty(false);
|
|
60
|
+
},
|
|
61
|
+
[setDirty]
|
|
62
|
+
);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (!dirty) {
|
|
65
|
+
resetCallbackRef.current?.();
|
|
66
|
+
resetCallbackRef.current = null;
|
|
67
|
+
}
|
|
68
|
+
}, [dirty]);
|
|
69
|
+
const markDirty = useCallback(() => setDirty(true), [setDirty]);
|
|
70
|
+
const check = useCallback(async () => {
|
|
71
|
+
if (getDirty()) {
|
|
72
|
+
const proceed = await confirm({
|
|
73
|
+
title: t("unsaved.title"),
|
|
74
|
+
description: t("unsaved.desc"),
|
|
75
|
+
okText: t("unsaved.leave"),
|
|
76
|
+
cancelText: t("unsaved.stay"),
|
|
77
|
+
okButtonProps: { color: "warning" }
|
|
78
|
+
});
|
|
79
|
+
if (proceed) {
|
|
80
|
+
reset();
|
|
81
|
+
}
|
|
82
|
+
return proceed;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}, [confirm, reset, getDirty, t]);
|
|
86
|
+
return { dirty: dirty || multiDirtySourceState.dirty, markDirty, reset, check };
|
|
87
|
+
};
|
|
88
|
+
export const DirtyPromptContainer = createContainer(useDirtyPrompt);
|
|
89
|
+
export function ConfirmNavigation() {
|
|
90
|
+
const { t } = useLocaleContext();
|
|
91
|
+
const { dirty, reset } = DirtyPromptContainer.useContainer();
|
|
92
|
+
const blocker = useBlocker(dirty);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (blocker.state === "blocked" && !dirty) {
|
|
95
|
+
blocker.reset();
|
|
96
|
+
}
|
|
97
|
+
}, [blocker, dirty]);
|
|
98
|
+
const handleOk = () => {
|
|
99
|
+
blocker.proceed?.();
|
|
100
|
+
reset();
|
|
101
|
+
};
|
|
102
|
+
return /* @__PURE__ */ jsx(
|
|
103
|
+
Confirm,
|
|
104
|
+
{
|
|
105
|
+
open: blocker.state === "blocked",
|
|
106
|
+
onClose: () => blocker.reset?.(),
|
|
107
|
+
title: t("unsaved.title"),
|
|
108
|
+
description: t("unsaved.desc"),
|
|
109
|
+
okText: t("unsaved.leave"),
|
|
110
|
+
okButtonProps: { color: "warning" },
|
|
111
|
+
cancelText: t("unsaved.stay"),
|
|
112
|
+
handleOk,
|
|
113
|
+
handleCancel: () => blocker.reset?.(),
|
|
114
|
+
sx: { zIndex: 99999 }
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BlockletEditor, useBlockletEditorLoaded } from '@blocklet/editor/lib/blocklet-editor';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BlockletEditor, useBlockletEditorLoaded } from "@blocklet/editor/lib/blocklet-editor";
|