@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,140 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useNavigate } from "react-router-dom";
|
|
3
|
+
import { Box, styled } from "@mui/material";
|
|
4
|
+
import Tooltip, { tooltipClasses } from "@mui/material/Tooltip";
|
|
5
|
+
import DID from "@arcblock/ux/lib/DID";
|
|
6
|
+
import { green } from "@mui/material/colors";
|
|
7
|
+
import { SocialActions } from "@arcblock/ux/lib/UserCard";
|
|
8
|
+
import { useBrowser } from "@arcblock/react-hooks";
|
|
9
|
+
import { useState } from "react";
|
|
10
|
+
import Avatar from "../avatars/avatar.mjs";
|
|
11
|
+
import { useSessionContext } from "../hooks/index.mjs";
|
|
12
|
+
import Badge from "../avatars/badge.mjs";
|
|
13
|
+
import { openProfile, isInDiscussKitApp } from "../utils.mjs";
|
|
14
|
+
export function ProfileCard({ user, click, ...rest }) {
|
|
15
|
+
const { session } = useSessionContext();
|
|
16
|
+
const isLogin = !!session?.user?.did;
|
|
17
|
+
return /* @__PURE__ */ jsxs(
|
|
18
|
+
Box,
|
|
19
|
+
{
|
|
20
|
+
sx: {
|
|
21
|
+
boxSizing: "border-box",
|
|
22
|
+
width: 340,
|
|
23
|
+
p: 2,
|
|
24
|
+
border: "1px solid",
|
|
25
|
+
borderColor: "divider",
|
|
26
|
+
borderRadius: 1,
|
|
27
|
+
fontSize: 14,
|
|
28
|
+
color: "grey.700",
|
|
29
|
+
bgcolor: "background.paper"
|
|
30
|
+
},
|
|
31
|
+
...rest,
|
|
32
|
+
children: [
|
|
33
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 2, cursor: "pointer" }, onClick: click, children: [
|
|
34
|
+
/* @__PURE__ */ jsx(Avatar, { did: user.did, src: user.avatar, size: 44, shape: "circle", variant: "circle" }),
|
|
35
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", flex: 1, overflow: "hidden" }, children: [
|
|
36
|
+
/* @__PURE__ */ jsxs(
|
|
37
|
+
Box,
|
|
38
|
+
{
|
|
39
|
+
component: "span",
|
|
40
|
+
sx: {
|
|
41
|
+
display: "flex",
|
|
42
|
+
justifyContent: "space-between",
|
|
43
|
+
alignItems: "center",
|
|
44
|
+
lineHeight: 1.3
|
|
45
|
+
},
|
|
46
|
+
children: [
|
|
47
|
+
/* @__PURE__ */ jsx(Box, { sx: { fontWeight: "bold" }, children: user.fullName }),
|
|
48
|
+
user.role && /* @__PURE__ */ jsx(
|
|
49
|
+
Box,
|
|
50
|
+
{
|
|
51
|
+
sx: {
|
|
52
|
+
px: 1.25,
|
|
53
|
+
border: 1,
|
|
54
|
+
borderColor: green[600],
|
|
55
|
+
color: green[600],
|
|
56
|
+
fontSize: 12,
|
|
57
|
+
fontWeight: "bold",
|
|
58
|
+
lineHeight: 1.5,
|
|
59
|
+
borderRadius: "100vh",
|
|
60
|
+
textTransform: "capitalize"
|
|
61
|
+
},
|
|
62
|
+
children: user.role
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
),
|
|
68
|
+
/* @__PURE__ */ jsx(
|
|
69
|
+
DID,
|
|
70
|
+
{
|
|
71
|
+
style: { marginTop: 4, lineHeight: 1, height: 14, maxWidth: 250, color: "inherit !important" },
|
|
72
|
+
size: 14,
|
|
73
|
+
did: user.did
|
|
74
|
+
}
|
|
75
|
+
),
|
|
76
|
+
/* @__PURE__ */ jsx(Box, { sx: { mt: 1 }, children: /* @__PURE__ */ jsx(Badge, { passports: user?.passports || [], pointInfo: user?.pointInfo || {}, did: user?.did }) })
|
|
77
|
+
] })
|
|
78
|
+
] }),
|
|
79
|
+
(!isLogin || user?.did !== window.blocklet.appId && session?.user?.did && session?.user?.did !== user.did) && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
80
|
+
/* @__PURE__ */ jsx(Box, { sx: { my: 2, borderTop: "1px solid", borderColor: "divider" } }),
|
|
81
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(SocialActions, { session, showSocialActions: true, user }) })
|
|
82
|
+
] })
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
const HtmlTooltip = styled(({ className, ...props }) => /* @__PURE__ */ jsx(
|
|
88
|
+
Tooltip,
|
|
89
|
+
{
|
|
90
|
+
...props,
|
|
91
|
+
classes: { popper: className },
|
|
92
|
+
slotProps: {
|
|
93
|
+
popper: {
|
|
94
|
+
disablePortal: true
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
))(() => ({
|
|
99
|
+
[`& .${tooltipClasses.tooltip}`]: {
|
|
100
|
+
backgroundColor: "transparent",
|
|
101
|
+
maxWidth: "initial"
|
|
102
|
+
}
|
|
103
|
+
}));
|
|
104
|
+
export function ProfileCardTooltip({ user, children }) {
|
|
105
|
+
const navigate = useNavigate();
|
|
106
|
+
const [open, setOpen] = useState(false);
|
|
107
|
+
const { mobile } = useBrowser();
|
|
108
|
+
const click = (e) => {
|
|
109
|
+
e?.stopPropagation?.();
|
|
110
|
+
e?.preventDefault?.();
|
|
111
|
+
setOpen(false);
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
if (isInDiscussKitApp) {
|
|
114
|
+
navigate(`/profile?did=${user?.did}`);
|
|
115
|
+
} else {
|
|
116
|
+
openProfile(user?.did);
|
|
117
|
+
}
|
|
118
|
+
}, 100);
|
|
119
|
+
};
|
|
120
|
+
const renderChildren = () => {
|
|
121
|
+
if (typeof children === "function") {
|
|
122
|
+
return children({ navigateToProfile: click });
|
|
123
|
+
}
|
|
124
|
+
return children;
|
|
125
|
+
};
|
|
126
|
+
if (mobile.any) {
|
|
127
|
+
return renderChildren();
|
|
128
|
+
}
|
|
129
|
+
return /* @__PURE__ */ jsx(
|
|
130
|
+
HtmlTooltip,
|
|
131
|
+
{
|
|
132
|
+
open,
|
|
133
|
+
onClose: () => setOpen(false),
|
|
134
|
+
onOpen: () => setOpen(true),
|
|
135
|
+
PopperProps: { disablePortal: false },
|
|
136
|
+
title: /* @__PURE__ */ jsx(ProfileCard, { user, click }),
|
|
137
|
+
children: renderChildren()
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type RatingProps } from './rating';
|
|
3
|
+
import type { Rating as RatingType } from '../../types';
|
|
4
|
+
export type BinaryThumbProps = {
|
|
5
|
+
data: RatingType[];
|
|
6
|
+
variant?: 'default' | 'inverse';
|
|
7
|
+
size?: 'sm' | 'lg';
|
|
8
|
+
} & Pick<RatingProps, 'onRate' | 'onUnrate'>;
|
|
9
|
+
export default function BinaryThumb({ data, variant, size, ...rest }: BinaryThumbProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
3
|
+
import { styled } from "@arcblock/ux/lib/Theme";
|
|
4
|
+
import Box from "@mui/material/Box";
|
|
5
|
+
import clsx from "clsx";
|
|
6
|
+
import { Icon } from "@iconify/react";
|
|
7
|
+
import ThumbUpIcon from "@iconify/icons-iconoir/thumbs-up";
|
|
8
|
+
import RaterList from "./rater-list.mjs";
|
|
9
|
+
import Rating from "./rating.mjs";
|
|
10
|
+
import { useSessionContext } from "../hooks/index.mjs";
|
|
11
|
+
const values = ["1", "-1"];
|
|
12
|
+
export default function BinaryThumb({ data = [], variant = "default", size = "sm", ...rest }) {
|
|
13
|
+
const { session } = useSessionContext();
|
|
14
|
+
const [raterListVisible, setRaterListVisible] = useState(null);
|
|
15
|
+
const [loading, setLoading] = useState(false);
|
|
16
|
+
const countPerValue = useMemo(() => {
|
|
17
|
+
return data.reduce((acc, cur) => {
|
|
18
|
+
acc[cur.value] = (acc[cur.value] || 0) + 1;
|
|
19
|
+
return acc;
|
|
20
|
+
}, {});
|
|
21
|
+
}, [data]);
|
|
22
|
+
const selectedValue = useMemo(() => {
|
|
23
|
+
return data.find((x) => x.rater?.did === session?.user?.did)?.value;
|
|
24
|
+
}, [data, session.user]);
|
|
25
|
+
const render = ({ options, toggleRate }) => {
|
|
26
|
+
const handleTextClick = (event, value) => {
|
|
27
|
+
setRaterListVisible(value);
|
|
28
|
+
};
|
|
29
|
+
const clickRateHandle = async (option) => {
|
|
30
|
+
if (loading) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
setLoading(true);
|
|
34
|
+
await toggleRate(option.value);
|
|
35
|
+
setLoading(false);
|
|
36
|
+
};
|
|
37
|
+
return /* @__PURE__ */ jsx(Root, { children: options.map((option) => {
|
|
38
|
+
const iconStyle = {};
|
|
39
|
+
if (option.value === "-1") {
|
|
40
|
+
iconStyle.transform = "rotate(180deg)";
|
|
41
|
+
}
|
|
42
|
+
const icon = /* @__PURE__ */ jsx(Icon, { icon: ThumbUpIcon, style: iconStyle });
|
|
43
|
+
return /* @__PURE__ */ jsxs("div", { className: "reaction-item", children: [
|
|
44
|
+
/* @__PURE__ */ jsx(
|
|
45
|
+
IconButton,
|
|
46
|
+
{
|
|
47
|
+
className: "reaction-item-btn",
|
|
48
|
+
icon,
|
|
49
|
+
text: option.count,
|
|
50
|
+
selected: option.selected,
|
|
51
|
+
onClick: () => clickRateHandle(option),
|
|
52
|
+
variant,
|
|
53
|
+
size,
|
|
54
|
+
onTextClick: (e) => handleTextClick(e, option.value),
|
|
55
|
+
disabled: loading
|
|
56
|
+
}
|
|
57
|
+
),
|
|
58
|
+
/* @__PURE__ */ jsx(
|
|
59
|
+
RaterList,
|
|
60
|
+
{
|
|
61
|
+
open: raterListVisible === option.value,
|
|
62
|
+
onClose: () => setRaterListVisible(null),
|
|
63
|
+
value: raterListVisible,
|
|
64
|
+
ratings: data
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
] }, option.value);
|
|
68
|
+
}) });
|
|
69
|
+
};
|
|
70
|
+
return /* @__PURE__ */ jsx(
|
|
71
|
+
Rating,
|
|
72
|
+
{
|
|
73
|
+
...rest,
|
|
74
|
+
ratingType: "binary-thumb",
|
|
75
|
+
values,
|
|
76
|
+
countPerValue,
|
|
77
|
+
selectedValue,
|
|
78
|
+
render
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
const Root = styled(Box)`
|
|
83
|
+
display: flex;
|
|
84
|
+
.reaction-item {
|
|
85
|
+
display: flex;
|
|
86
|
+
align-items: center;
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
function IconButton({ icon, text, onClick, selected, variant, size, onTextClick, disabled, ...rest }) {
|
|
90
|
+
const classes = clsx(rest.className, `reaction-btn-${size} reaction-btn-${variant}`, {
|
|
91
|
+
"reaction-btn-selected": selected,
|
|
92
|
+
"button-disabled": disabled
|
|
93
|
+
});
|
|
94
|
+
return /* @__PURE__ */ jsxs(IconButtonRoot, { ...rest, className: classes, children: [
|
|
95
|
+
/* @__PURE__ */ jsx("span", { className: "reaction-btn-icon", onClick, children: icon }),
|
|
96
|
+
!!text && /* @__PURE__ */ jsx("span", { className: "reaction-btn-text", onClick: (e) => onTextClick?.(e), children: text })
|
|
97
|
+
] });
|
|
98
|
+
}
|
|
99
|
+
const IconButtonRoot = styled("div")`
|
|
100
|
+
display: flex;
|
|
101
|
+
align-items: center;
|
|
102
|
+
&.reaction-btn-selected {
|
|
103
|
+
color: ${(props) => props.theme.palette.primary.main};
|
|
104
|
+
}
|
|
105
|
+
.reaction-btn-icon {
|
|
106
|
+
display: flex;
|
|
107
|
+
line-height: 1;
|
|
108
|
+
cursor: pointer;
|
|
109
|
+
}
|
|
110
|
+
&.button-disabled {
|
|
111
|
+
opacity: 0.5;
|
|
112
|
+
.reaction-btn-icon {
|
|
113
|
+
cursor: not-allowed;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
svg {
|
|
117
|
+
width: auto;
|
|
118
|
+
}
|
|
119
|
+
.reaction-btn-text {
|
|
120
|
+
display: inline-block;
|
|
121
|
+
cursor: pointer;
|
|
122
|
+
}
|
|
123
|
+
&.reaction-btn-sm {
|
|
124
|
+
min-width: 64px;
|
|
125
|
+
height: 18px;
|
|
126
|
+
font-size: 12px;
|
|
127
|
+
svg {
|
|
128
|
+
font-size: 15px;
|
|
129
|
+
}
|
|
130
|
+
.reaction-btn-text {
|
|
131
|
+
margin-left: 8px;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
&.reaction-btn-lg {
|
|
135
|
+
min-width: 100px;
|
|
136
|
+
font-size: 14px;
|
|
137
|
+
.reaction-btn-icon {
|
|
138
|
+
justify-content: center;
|
|
139
|
+
align-items: center;
|
|
140
|
+
width: 44px;
|
|
141
|
+
height: 44px;
|
|
142
|
+
border-radius: 8px;
|
|
143
|
+
}
|
|
144
|
+
svg {
|
|
145
|
+
height: 20px;
|
|
146
|
+
}
|
|
147
|
+
.reaction-btn-text {
|
|
148
|
+
margin-left: 12px;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
&.reaction-btn-inverse {
|
|
152
|
+
.reaction-btn-icon {
|
|
153
|
+
background-color: ${(props) => props.theme.palette.grey[200]};
|
|
154
|
+
}
|
|
155
|
+
&.reaction-btn-selected {
|
|
156
|
+
.reaction-btn-icon {
|
|
157
|
+
color: #fff;
|
|
158
|
+
background-color: ${(props) => props.theme.palette.primary.main};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
`;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { AxiosInstance } from 'axios';
|
|
3
|
+
import { GithubReactionProps } from './github-reaction';
|
|
4
|
+
interface Props extends Omit<GithubReactionProps, 'data' | 'onRate' | 'onUnrate'> {
|
|
5
|
+
id: string;
|
|
6
|
+
request: AxiosInstance;
|
|
7
|
+
}
|
|
8
|
+
export declare function GithubReactionContainer({ id, request, ...rest }: Props): import("react").JSX.Element | null;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { useCreation, useRequest } from "ahooks";
|
|
4
|
+
import GithubReaction from "./github-reaction.mjs";
|
|
5
|
+
import { discussKitApiBaseUrl } from "../utils.mjs";
|
|
6
|
+
import { useSessionContext } from "../hooks/session.mjs";
|
|
7
|
+
const baseConfig = { baseURL: discussKitApiBaseUrl };
|
|
8
|
+
const createApi = (request) => {
|
|
9
|
+
return {
|
|
10
|
+
fetchRatings: async (id) => {
|
|
11
|
+
const { data } = await request.get(`/ratings/${id}`, baseConfig);
|
|
12
|
+
return data;
|
|
13
|
+
},
|
|
14
|
+
rate: async ({ id, ratingType, value }) => {
|
|
15
|
+
await request.post(`/topics/${id}/ratings`, { ratingType, value }, baseConfig);
|
|
16
|
+
},
|
|
17
|
+
unrate: async ({ id }) => {
|
|
18
|
+
await request.delete(`/topics/${id}/ratings`, baseConfig);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export function GithubReactionContainer({ id, request, ...rest }) {
|
|
23
|
+
const { session } = useSessionContext();
|
|
24
|
+
const api = useCreation(() => createApi(request || axios.create({})), [request]);
|
|
25
|
+
const { data, loading, error } = useRequest(() => api.fetchRatings(id), {
|
|
26
|
+
refreshDeps: [id]
|
|
27
|
+
});
|
|
28
|
+
const handleRate = async ({ ratingType, value }) => {
|
|
29
|
+
if (!session.user) {
|
|
30
|
+
session.login();
|
|
31
|
+
throw new Error("Unauthenticated.");
|
|
32
|
+
}
|
|
33
|
+
await api.rate({ id, ratingType, value });
|
|
34
|
+
};
|
|
35
|
+
const handleUnrate = async () => {
|
|
36
|
+
if (!session.user) {
|
|
37
|
+
session.login();
|
|
38
|
+
throw new Error("Unauthenticated.");
|
|
39
|
+
}
|
|
40
|
+
await api.unrate({ id });
|
|
41
|
+
};
|
|
42
|
+
if (loading || error) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return /* @__PURE__ */ jsx(GithubReaction, { data, onRate: handleRate, onUnrate: handleUnrate, ...rest });
|
|
46
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IconButtonProps } from '@mui/material';
|
|
3
|
+
import type { Rating as RatingType } from '../../types';
|
|
4
|
+
export type GithubReactionProps = {
|
|
5
|
+
data: RatingType[];
|
|
6
|
+
onRate: ({ ratingType, value }: {
|
|
7
|
+
ratingType: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}) => Promise<any>;
|
|
10
|
+
onUnrate: () => Promise<any>;
|
|
11
|
+
interactive?: boolean;
|
|
12
|
+
} & IconButtonProps;
|
|
13
|
+
/**
|
|
14
|
+
* 说明:
|
|
15
|
+
* GithubReaction 与 Rating 组件不兼容, 后者是 n 选 1, GithubReaction 是 n 选 m,
|
|
16
|
+
* 所以 GithubReaction 相当于重写, 与 Rating 组件和 BinaryThumb 组件没有关系
|
|
17
|
+
*/
|
|
18
|
+
export default function GithubReaction({ data, onRate, onUnrate, interactive, sx, ...rest }: GithubReactionProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
3
|
+
import { Box, Chip, ClickAwayListener, Tooltip, alpha } from "@mui/material";
|
|
4
|
+
import { Icon } from "@iconify/react";
|
|
5
|
+
import MoodPlusIcon from "@iconify/icons-tabler/mood-plus";
|
|
6
|
+
import { useSessionContext } from "../hooks/index.mjs";
|
|
7
|
+
import { IconButton } from "../icon-button.mjs";
|
|
8
|
+
const emojiFont = {
|
|
9
|
+
fontFamily: '"Twemoji Mozilla", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "EmojiOne Color"'
|
|
10
|
+
};
|
|
11
|
+
export default function GithubReaction({
|
|
12
|
+
data,
|
|
13
|
+
onRate,
|
|
14
|
+
onUnrate,
|
|
15
|
+
interactive = true,
|
|
16
|
+
sx,
|
|
17
|
+
...rest
|
|
18
|
+
}) {
|
|
19
|
+
const { session } = useSessionContext();
|
|
20
|
+
const [open, setOpen] = useState(false);
|
|
21
|
+
const [raters, setRaters] = useState(null);
|
|
22
|
+
const [myReaction, setMyReaction] = useState(null);
|
|
23
|
+
const options = [
|
|
24
|
+
{ value: "thumbs_up", label: "\u{1F44D}" },
|
|
25
|
+
{ value: "thumbs_down", label: "\u{1F44E}" },
|
|
26
|
+
{ value: "white_check_mark", label: "\u2705" },
|
|
27
|
+
{ value: "laugh", label: "\u{1F604}" },
|
|
28
|
+
{ value: "joy", label: "\u{1F602}" },
|
|
29
|
+
{ value: "hooray", label: "\u{1F389}" },
|
|
30
|
+
{ value: "heart", label: "\u2764\uFE0F" },
|
|
31
|
+
{ value: "rocket", label: "\u{1F680}" },
|
|
32
|
+
{ value: "eyes", label: "\u{1F440}" }
|
|
33
|
+
];
|
|
34
|
+
const ratings = useMemo(() => {
|
|
35
|
+
const mapped = data.map((x) => {
|
|
36
|
+
if (x.value == "1" || x.value == "-1") {
|
|
37
|
+
return { ...x, value: x.value == "1" ? ["thumbs_up"] : ["thumbs_down"] };
|
|
38
|
+
}
|
|
39
|
+
return { ...x, value: x.value?.split(",") || [] };
|
|
40
|
+
});
|
|
41
|
+
if (session?.user?.did && myReaction) {
|
|
42
|
+
return [...mapped.filter((x) => x.rater?.did !== session.user.did), { rater: session.user, value: myReaction }];
|
|
43
|
+
}
|
|
44
|
+
return mapped;
|
|
45
|
+
}, [data, myReaction, session.user]);
|
|
46
|
+
const countPerValue = useMemo(() => {
|
|
47
|
+
return ratings.reduce((acc, cur) => {
|
|
48
|
+
cur.value.forEach((item) => {
|
|
49
|
+
acc[item] = (acc[item] || 0) + 1;
|
|
50
|
+
});
|
|
51
|
+
return acc;
|
|
52
|
+
}, {});
|
|
53
|
+
}, [ratings]);
|
|
54
|
+
const selectedValues = useMemo(() => {
|
|
55
|
+
return ratings.find((x) => x.rater?.did === session?.user?.did)?.value || [];
|
|
56
|
+
}, [ratings, session.user]);
|
|
57
|
+
const selectedValuesMap = useMemo(() => {
|
|
58
|
+
return selectedValues.reduce((acc, cur) => ({ ...acc, [cur]: true }), {});
|
|
59
|
+
}, [selectedValues]);
|
|
60
|
+
const hasReaction = Object.keys(countPerValue).length > 0;
|
|
61
|
+
const toggleRate = (value) => {
|
|
62
|
+
if (!interactive) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const valuesMap = { ...selectedValuesMap };
|
|
66
|
+
valuesMap[value] = !valuesMap[value];
|
|
67
|
+
const values = Object.keys(valuesMap).filter((x) => valuesMap[x]);
|
|
68
|
+
if (values.length) {
|
|
69
|
+
onRate({
|
|
70
|
+
ratingType: "github-reaction",
|
|
71
|
+
value: values.join(",")
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
onUnrate();
|
|
75
|
+
}
|
|
76
|
+
setMyReaction(values);
|
|
77
|
+
setOpen(false);
|
|
78
|
+
};
|
|
79
|
+
const getRatersNames = (value) => {
|
|
80
|
+
return ratings.filter((x) => x.rater && x.value.includes(value)).map((x) => x.rater.fullName);
|
|
81
|
+
};
|
|
82
|
+
const handleOpen = () => {
|
|
83
|
+
if (interactive) {
|
|
84
|
+
setOpen(!open);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const mergedSx = [{ position: "relative", ...hasReaction && { mt: 2.5 } }, ...Array.isArray(sx) ? sx : [sx]];
|
|
88
|
+
return /* @__PURE__ */ jsxs(IconButton, { onClick: handleOpen, sx: mergedSx, ...rest, children: [
|
|
89
|
+
/* @__PURE__ */ jsx(Box, { component: Icon, icon: MoodPlusIcon }),
|
|
90
|
+
hasReaction && /* @__PURE__ */ jsx(Box, { sx: { position: "absolute", top: -24, left: 5, display: "flex", gap: 1 }, children: options.map((option) => {
|
|
91
|
+
if (!countPerValue[option.value]) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const selected = selectedValuesMap[option.value];
|
|
95
|
+
return /* @__PURE__ */ jsx(Tooltip, { title: raters?.join(", "), children: /* @__PURE__ */ jsx(
|
|
96
|
+
Chip,
|
|
97
|
+
{
|
|
98
|
+
label: /* @__PURE__ */ jsxs(Box, { component: "span", sx: { display: "inline-flex", alignItems: "center", gap: 1 }, children: [
|
|
99
|
+
/* @__PURE__ */ jsx(Box, { component: "span", sx: emojiFont, children: option.label }),
|
|
100
|
+
/* @__PURE__ */ jsx("span", { children: countPerValue[option.value] })
|
|
101
|
+
] }),
|
|
102
|
+
color: "default",
|
|
103
|
+
size: "small",
|
|
104
|
+
variant: selected ? "outlined" : "filled",
|
|
105
|
+
sx: {
|
|
106
|
+
lineHeight: "24px",
|
|
107
|
+
fontSize: 13,
|
|
108
|
+
border: 1,
|
|
109
|
+
borderColor: "divider",
|
|
110
|
+
borderRadius: 1,
|
|
111
|
+
cursor: "pointer",
|
|
112
|
+
bgcolor: "transparent",
|
|
113
|
+
"&:hover": {
|
|
114
|
+
bgcolor: "grey.100"
|
|
115
|
+
},
|
|
116
|
+
...selected && {
|
|
117
|
+
borderColor: "warning.light",
|
|
118
|
+
bgcolor: (theme) => alpha(theme.palette.warning.light, 0.2)
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
onClick: (e) => {
|
|
122
|
+
e.stopPropagation();
|
|
123
|
+
toggleRate(option.value);
|
|
124
|
+
},
|
|
125
|
+
onMouseEnter: () => setRaters(getRatersNames(option.value)),
|
|
126
|
+
onMouseLeave: () => setRaters(null)
|
|
127
|
+
}
|
|
128
|
+
) }, option.value);
|
|
129
|
+
}) }),
|
|
130
|
+
open && /* @__PURE__ */ jsx(ClickAwayListener, { onClickAway: () => setOpen(false), children: /* @__PURE__ */ jsx(
|
|
131
|
+
Box,
|
|
132
|
+
{
|
|
133
|
+
sx: {
|
|
134
|
+
display: "flex",
|
|
135
|
+
gap: 0.5,
|
|
136
|
+
position: "absolute",
|
|
137
|
+
left: 0,
|
|
138
|
+
bottom: 36,
|
|
139
|
+
px: 1,
|
|
140
|
+
py: 0.5,
|
|
141
|
+
border: 1,
|
|
142
|
+
borderColor: "grey.300",
|
|
143
|
+
bgcolor: "background.paper",
|
|
144
|
+
borderRadius: 1
|
|
145
|
+
},
|
|
146
|
+
children: options.map((option) => {
|
|
147
|
+
const selected = selectedValuesMap[option.value];
|
|
148
|
+
return /* @__PURE__ */ jsx(
|
|
149
|
+
Box,
|
|
150
|
+
{
|
|
151
|
+
onClick: () => toggleRate(option.value),
|
|
152
|
+
sx: {
|
|
153
|
+
display: "flex",
|
|
154
|
+
justifyContent: "center",
|
|
155
|
+
alignItems: "center",
|
|
156
|
+
width: 28,
|
|
157
|
+
height: 28,
|
|
158
|
+
fontSize: 14,
|
|
159
|
+
borderRadius: 1,
|
|
160
|
+
cursor: "pointer",
|
|
161
|
+
":hover": { bgcolor: "grey.100" },
|
|
162
|
+
...selected && {
|
|
163
|
+
bgcolor: (theme) => alpha(theme.palette.primary.light, 0.2)
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
children: /* @__PURE__ */ jsx(Box, { sx: emojiFont, children: option.label })
|
|
167
|
+
},
|
|
168
|
+
option.value
|
|
169
|
+
);
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
) })
|
|
173
|
+
] });
|
|
174
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Rating } from '../../types';
|
|
3
|
+
interface Props {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
value: string;
|
|
7
|
+
ratings: Rating[];
|
|
8
|
+
}
|
|
9
|
+
export default function RaterList({ open, onClose, value, ratings }: Props): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Box from "@mui/material/Box";
|
|
3
|
+
import { styled } from "@mui/material";
|
|
4
|
+
import Dialog from "@arcblock/ux/lib/Dialog";
|
|
5
|
+
import { Avatar } from "../avatars/index.mjs";
|
|
6
|
+
const StyledDialog = styled(Dialog)`
|
|
7
|
+
.ux-dialog_header {
|
|
8
|
+
padding: 0 16px;
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
export default function RaterList({ open, onClose, value, ratings }) {
|
|
12
|
+
const raters = ratings.filter((item) => item.value === value).map((item) => item.rater);
|
|
13
|
+
return /* @__PURE__ */ jsx(StyledDialog, { open, onClose, PaperProps: { style: { width: 400, minHeight: 200 } }, children: /* @__PURE__ */ jsx(Box, { children: raters.map((rater) => {
|
|
14
|
+
return /* @__PURE__ */ jsxs(
|
|
15
|
+
Box,
|
|
16
|
+
{
|
|
17
|
+
sx: {
|
|
18
|
+
display: "flex",
|
|
19
|
+
alignItems: "center",
|
|
20
|
+
gap: 2,
|
|
21
|
+
fontSize: 13,
|
|
22
|
+
color: "grey.700",
|
|
23
|
+
"& + &": { mt: 1 }
|
|
24
|
+
},
|
|
25
|
+
children: [
|
|
26
|
+
/* @__PURE__ */ jsx(Avatar, { did: rater.did, src: rater.avatar, variant: "circle", size: 26 }),
|
|
27
|
+
/* @__PURE__ */ jsx(Box, { children: rater.fullName })
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
rater.did
|
|
31
|
+
);
|
|
32
|
+
}) }) });
|
|
33
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export type RatingType = 'binary-thumb' | 'five-star';
|
|
3
|
+
interface Option {
|
|
4
|
+
value: string;
|
|
5
|
+
count: number;
|
|
6
|
+
selected: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface RenderProps {
|
|
9
|
+
options: Option[];
|
|
10
|
+
toggleRate: (value: string) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface RatingProps {
|
|
13
|
+
ratingType: RatingType;
|
|
14
|
+
values: string[];
|
|
15
|
+
countPerValue?: {
|
|
16
|
+
[key: string]: number;
|
|
17
|
+
};
|
|
18
|
+
selectedValue?: string;
|
|
19
|
+
render: ({ options, toggleRate }: RenderProps) => React.ReactElement<any>;
|
|
20
|
+
onRate: ({ ratingType, value }: {
|
|
21
|
+
ratingType: RatingType;
|
|
22
|
+
value: string;
|
|
23
|
+
}) => Promise<any>;
|
|
24
|
+
onUnrate: () => Promise<any>;
|
|
25
|
+
}
|
|
26
|
+
declare function Rating({ ratingType, values, countPerValue, selectedValue, render, onRate, onUnrate }: RatingProps): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | null;
|
|
27
|
+
export default Rating;
|