@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.
Files changed (186) hide show
  1. package/LICENSE +13 -0
  2. package/dist/axios.d.ts +8 -0
  3. package/dist/blocklets.d.ts +13 -0
  4. package/dist/blocklets.mjs +17 -0
  5. package/dist/components/api-error-handler/api-error-handler.d.ts +13 -0
  6. package/dist/components/api-error-handler/api-error-handler.mjs +25 -0
  7. package/dist/components/api-error-handler/default-handler.d.ts +8 -0
  8. package/dist/components/api-error-handler/default-handler.mjs +69 -0
  9. package/dist/components/api-error-handler/index.d.ts +2 -0
  10. package/dist/components/api-error-handler/index.mjs +2 -0
  11. package/dist/components/api-error-handler/json-validation-interceptor.d.ts +2 -0
  12. package/dist/components/api-error-handler/json-validation-interceptor.mjs +9 -0
  13. package/dist/components/arcsphere/index.d.ts +16 -0
  14. package/dist/components/arcsphere/index.mjs +52 -0
  15. package/dist/components/authz/access-control.d.ts +24 -0
  16. package/dist/components/authz/access-control.mjs +15 -0
  17. package/dist/components/authz/context.d.ts +13 -0
  18. package/dist/components/authz/context.mjs +30 -0
  19. package/dist/components/authz/index.d.ts +2 -0
  20. package/dist/components/authz/index.mjs +2 -0
  21. package/dist/components/auto-translate/api.d.ts +14 -0
  22. package/dist/components/auto-translate/api.mjs +23 -0
  23. package/dist/components/auto-translate/auto-translate-button.d.ts +5 -0
  24. package/dist/components/auto-translate/auto-translate-button.mjs +48 -0
  25. package/dist/components/auto-translate/editor-store-adaptor.d.ts +1 -0
  26. package/dist/components/auto-translate/editor-store-adaptor.mjs +14 -0
  27. package/dist/components/auto-translate/index.d.ts +6 -0
  28. package/dist/components/auto-translate/index.mjs +6 -0
  29. package/dist/components/auto-translate/languages.d.ts +13 -0
  30. package/dist/components/auto-translate/languages.mjs +61 -0
  31. package/dist/components/auto-translate/post-auto-translate-plugin.d.ts +14 -0
  32. package/dist/components/auto-translate/post-auto-translate-plugin.mjs +32 -0
  33. package/dist/components/auto-translate/store.d.ts +21 -0
  34. package/dist/components/auto-translate/store.mjs +23 -0
  35. package/dist/components/auto-translate/translate.d.ts +17 -0
  36. package/dist/components/auto-translate/translate.mjs +103 -0
  37. package/dist/components/auto-translate/utils.d.ts +4 -0
  38. package/dist/components/auto-translate/utils.mjs +14 -0
  39. package/dist/components/auto-translate/with-availibility-check.d.ts +2 -0
  40. package/dist/components/auto-translate/with-availibility-check.mjs +10 -0
  41. package/dist/components/avatars/author-info.d.ts +23 -0
  42. package/dist/components/avatars/author-info.mjs +178 -0
  43. package/dist/components/avatars/avatar.d.ts +7 -0
  44. package/dist/components/avatars/avatar.mjs +9 -0
  45. package/dist/components/avatars/avatars.d.ts +10 -0
  46. package/dist/components/avatars/avatars.mjs +49 -0
  47. package/dist/components/avatars/badge.d.ts +14 -0
  48. package/dist/components/avatars/badge.mjs +178 -0
  49. package/dist/components/avatars/index.d.ts +5 -0
  50. package/dist/components/avatars/index.mjs +5 -0
  51. package/dist/components/avatars/system-user.d.ts +10 -0
  52. package/dist/components/avatars/system-user.mjs +58 -0
  53. package/dist/components/button-group/button-group.d.ts +18 -0
  54. package/dist/components/button-group/button-group.mjs +195 -0
  55. package/dist/components/button-group/index.d.ts +1 -0
  56. package/dist/components/button-group/index.mjs +1 -0
  57. package/dist/components/confirm.d.ts +29 -0
  58. package/dist/components/confirm.mjs +103 -0
  59. package/dist/components/dayjs.d.ts +3 -0
  60. package/dist/components/dayjs.mjs +5 -0
  61. package/dist/components/default-editor-config-provider.d.ts +8 -0
  62. package/dist/components/default-editor-config-provider.mjs +108 -0
  63. package/dist/components/dirty-prompt.d.ts +8 -0
  64. package/dist/components/dirty-prompt.mjs +117 -0
  65. package/dist/components/editor/blocklet-editor.d.ts +1 -0
  66. package/dist/components/editor/blocklet-editor.mjs +1 -0
  67. package/dist/components/editor/editor.d.ts +17 -0
  68. package/dist/components/editor/editor.mjs +35 -0
  69. package/dist/components/editor/index.d.ts +4 -0
  70. package/dist/components/editor/index.mjs +3 -0
  71. package/dist/components/editor/lazy-editor.d.ts +3 -0
  72. package/dist/components/editor/lazy-editor.mjs +14 -0
  73. package/dist/components/editor/viewer.d.ts +10 -0
  74. package/dist/components/editor/viewer.mjs +18 -0
  75. package/dist/components/emoji-icon.d.ts +11 -0
  76. package/dist/components/emoji-icon.mjs +62 -0
  77. package/dist/components/empty-status/empty-status.d.ts +7 -0
  78. package/dist/components/empty-status/empty-status.mjs +24 -0
  79. package/dist/components/empty-status/index.d.ts +1 -0
  80. package/dist/components/empty-status/index.mjs +1 -0
  81. package/dist/components/hooks/changed.d.ts +10 -0
  82. package/dist/components/hooks/changed.mjs +34 -0
  83. package/dist/components/hooks/index.d.ts +6 -0
  84. package/dist/components/hooks/index.mjs +6 -0
  85. package/dist/components/hooks/interval.d.ts +6 -0
  86. package/dist/components/hooks/interval.mjs +16 -0
  87. package/dist/components/hooks/locale-context.d.ts +10 -0
  88. package/dist/components/hooks/locale-context.mjs +12 -0
  89. package/dist/components/hooks/measure.d.ts +5 -0
  90. package/dist/components/hooks/measure.mjs +8 -0
  91. package/dist/components/hooks/now.d.ts +1 -0
  92. package/dist/components/hooks/now.mjs +10 -0
  93. package/dist/components/hooks/responsive.d.ts +17 -0
  94. package/dist/components/hooks/responsive.mjs +25 -0
  95. package/dist/components/hooks/session.d.ts +12 -0
  96. package/dist/components/hooks/session.mjs +48 -0
  97. package/dist/components/hooks/use-event-callback.d.ts +1 -0
  98. package/dist/components/hooks/use-event-callback.mjs +14 -0
  99. package/dist/components/icon-button.d.ts +6 -0
  100. package/dist/components/icon-button.mjs +37 -0
  101. package/dist/components/input/auto-clear-plugin.d.ts +3 -0
  102. package/dist/components/input/auto-clear-plugin.mjs +20 -0
  103. package/dist/components/input/comment-input.d.ts +11 -0
  104. package/dist/components/input/comment-input.mjs +108 -0
  105. package/dist/components/input/index.d.ts +4 -0
  106. package/dist/components/input/index.mjs +4 -0
  107. package/dist/components/input/input.d.ts +29 -0
  108. package/dist/components/input/input.mjs +149 -0
  109. package/dist/components/input/post-edit.d.ts +10 -0
  110. package/dist/components/input/post-edit.mjs +49 -0
  111. package/dist/components/input/scrollable-editor-wrapper.d.ts +9 -0
  112. package/dist/components/input/scrollable-editor-wrapper.mjs +18 -0
  113. package/dist/components/input/shortcut-plugin.d.ts +7 -0
  114. package/dist/components/input/shortcut-plugin.mjs +28 -0
  115. package/dist/components/lexical.d.ts +10 -0
  116. package/dist/components/lexical.mjs +56 -0
  117. package/dist/components/locale/en.d.ts +117 -0
  118. package/dist/components/locale/en.mjs +116 -0
  119. package/dist/components/locale/index.d.ts +236 -0
  120. package/dist/components/locale/index.mjs +3 -0
  121. package/dist/components/locale/zh.d.ts +119 -0
  122. package/dist/components/locale/zh.mjs +118 -0
  123. package/dist/components/pagination.d.ts +12 -0
  124. package/dist/components/pagination.mjs +44 -0
  125. package/dist/components/posts/comment-list/comment-list.d.ts +5 -0
  126. package/dist/components/posts/comment-list/comment-list.mjs +163 -0
  127. package/dist/components/posts/comment-list/context.d.ts +76 -0
  128. package/dist/components/posts/comment-list/context.mjs +318 -0
  129. package/dist/components/posts/comment.d.ts +16 -0
  130. package/dist/components/posts/comment.mjs +184 -0
  131. package/dist/components/posts/index.d.ts +6 -0
  132. package/dist/components/posts/index.mjs +6 -0
  133. package/dist/components/posts/menu.d.ts +14 -0
  134. package/dist/components/posts/menu.mjs +83 -0
  135. package/dist/components/posts/post-content.d.ts +16 -0
  136. package/dist/components/posts/post-content.mjs +63 -0
  137. package/dist/components/posts/post.d.ts +26 -0
  138. package/dist/components/posts/post.mjs +198 -0
  139. package/dist/components/profile-card/index.d.ts +1 -0
  140. package/dist/components/profile-card/index.mjs +1 -0
  141. package/dist/components/profile-card/profile-card.d.ts +15 -0
  142. package/dist/components/profile-card/profile-card.mjs +140 -0
  143. package/dist/components/rating/binary-thumb.d.ts +9 -0
  144. package/dist/components/rating/binary-thumb.mjs +162 -0
  145. package/dist/components/rating/github-reaction-container.d.ts +9 -0
  146. package/dist/components/rating/github-reaction-container.mjs +46 -0
  147. package/dist/components/rating/github-reaction.d.ts +18 -0
  148. package/dist/components/rating/github-reaction.mjs +174 -0
  149. package/dist/components/rating/index.d.ts +3 -0
  150. package/dist/components/rating/index.mjs +3 -0
  151. package/dist/components/rating/rater-list.d.ts +10 -0
  152. package/dist/components/rating/rater-list.mjs +33 -0
  153. package/dist/components/rating/rating.d.ts +27 -0
  154. package/dist/components/rating/rating.mjs +50 -0
  155. package/dist/components/segmented-control.d.ts +14 -0
  156. package/dist/components/segmented-control.mjs +55 -0
  157. package/dist/components/shared/relative-time.d.ts +8 -0
  158. package/dist/components/shared/relative-time.mjs +21 -0
  159. package/dist/components/toast.d.ts +8 -0
  160. package/dist/components/toast.mjs +44 -0
  161. package/dist/components/uploader/index.d.ts +13 -0
  162. package/dist/components/uploader/index.mjs +70 -0
  163. package/dist/components/uploader/utils.d.ts +1 -0
  164. package/dist/components/uploader/utils.mjs +16 -0
  165. package/dist/components/utils.d.ts +22 -0
  166. package/dist/components/utils.mjs +103 -0
  167. package/dist/components/view-more.d.ts +4 -0
  168. package/dist/components/view-more.mjs +50 -0
  169. package/dist/constants.d.ts +5 -0
  170. package/dist/constants.mjs +14 -0
  171. package/dist/global.d.ts +1 -0
  172. package/dist/index.d.ts +29 -0
  173. package/dist/index.mjs +29 -0
  174. package/dist/preferences.d.ts +2 -0
  175. package/dist/preferences.mjs +9 -0
  176. package/dist/theme/index.d.ts +8 -0
  177. package/dist/theme/index.mjs +96 -0
  178. package/dist/theme/typography.d.ts +2 -0
  179. package/dist/theme/typography.mjs +66 -0
  180. package/dist/type-override.d.ts +7 -0
  181. package/dist/types.d.ts +84 -0
  182. package/dist/types.mjs +0 -0
  183. package/dist/vite-env.d.ts +1 -0
  184. package/dist/ws.d.ts +3 -0
  185. package/dist/ws.mjs +39 -0
  186. 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,3 @@
1
+ export { default as BinaryThumb } from './binary-thumb';
2
+ export { default as GithubReaction } from './github-reaction';
3
+ export { GithubReactionContainer } from './github-reaction-container';
@@ -0,0 +1,3 @@
1
+ export { default as BinaryThumb } from "./binary-thumb.mjs";
2
+ export { default as GithubReaction } from "./github-reaction.mjs";
3
+ export { GithubReactionContainer } from "./github-reaction-container.mjs";
@@ -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;