@blocklet/discuss-kit-ux 2.4.35 → 2.4.37

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 (222) hide show
  1. package/dist/axios.d.ts +8 -0
  2. package/dist/blocklets.d.ts +1 -1
  3. package/dist/blocklets.mjs +17 -0
  4. package/dist/components/api-error-handler/api-error-handler.d.ts +1 -1
  5. package/dist/components/api-error-handler/api-error-handler.mjs +25 -0
  6. package/dist/components/api-error-handler/default-handler.mjs +69 -0
  7. package/dist/components/api-error-handler/index.mjs +2 -0
  8. package/dist/components/api-error-handler/json-validation-interceptor.d.ts +1 -1
  9. package/dist/components/api-error-handler/json-validation-interceptor.mjs +9 -0
  10. package/dist/components/arcsphere/index.mjs +51 -0
  11. package/dist/components/authz/access-control.d.ts +15 -1
  12. package/dist/components/authz/access-control.mjs +15 -0
  13. package/dist/components/authz/context.d.ts +2 -1
  14. package/dist/components/authz/context.mjs +30 -0
  15. package/dist/components/authz/index.d.ts +1 -1
  16. package/dist/components/authz/index.mjs +2 -0
  17. package/dist/components/auto-translate/api.d.ts +1 -1
  18. package/dist/components/auto-translate/api.mjs +23 -0
  19. package/dist/components/auto-translate/auto-translate-button.d.ts +2 -1
  20. package/dist/components/auto-translate/auto-translate-button.mjs +47 -0
  21. package/dist/components/auto-translate/editor-store-adaptor.mjs +14 -0
  22. package/dist/components/auto-translate/index.mjs +6 -0
  23. package/dist/components/auto-translate/languages.mjs +61 -0
  24. package/dist/components/auto-translate/post-auto-translate-plugin.d.ts +4 -3
  25. package/dist/components/auto-translate/post-auto-translate-plugin.mjs +32 -0
  26. package/dist/components/auto-translate/store.d.ts +3 -3
  27. package/dist/components/auto-translate/store.mjs +23 -0
  28. package/dist/components/auto-translate/translate.d.ts +3 -2
  29. package/dist/components/auto-translate/translate.mjs +103 -0
  30. package/dist/components/auto-translate/utils.d.ts +1 -1
  31. package/dist/components/auto-translate/utils.mjs +14 -0
  32. package/dist/components/auto-translate/with-availibility-check.d.ts +1 -1
  33. package/dist/components/auto-translate/with-availibility-check.mjs +10 -0
  34. package/dist/components/avatars/author-info.d.ts +3 -2
  35. package/dist/components/avatars/author-info.mjs +184 -0
  36. package/dist/components/avatars/avatar.d.ts +2 -1
  37. package/dist/components/avatars/avatar.mjs +9 -0
  38. package/dist/components/avatars/avatars.d.ts +4 -3
  39. package/dist/components/avatars/avatars.mjs +49 -0
  40. package/dist/components/avatars/badge.d.ts +2 -1
  41. package/dist/components/avatars/badge.mjs +178 -0
  42. package/dist/components/avatars/index.mjs +5 -0
  43. package/dist/components/avatars/system-user.d.ts +1 -1
  44. package/dist/components/avatars/system-user.mjs +58 -0
  45. package/dist/components/back.d.ts +2 -1
  46. package/dist/components/back.mjs +28 -0
  47. package/dist/components/blog/blog-link.mjs +16 -0
  48. package/dist/components/blog/blog-list.d.ts +4 -3
  49. package/dist/components/blog/blog-list.mjs +441 -0
  50. package/dist/components/blog/cover-image.d.ts +4 -3
  51. package/dist/components/blog/cover-image.mjs +160 -0
  52. package/dist/components/blog/index.mjs +4 -0
  53. package/dist/components/blog/permalink.d.ts +3 -2
  54. package/dist/components/blog/permalink.mjs +78 -0
  55. package/dist/components/blog/types.d.ts +1 -1
  56. package/dist/components/blog/types.mjs +0 -0
  57. package/dist/components/button-group/button-group.d.ts +2 -1
  58. package/dist/components/button-group/button-group.mjs +195 -0
  59. package/dist/components/button-group/index.mjs +1 -0
  60. package/dist/components/chat/channel-group.d.ts +3 -2
  61. package/dist/components/chat/channel-group.mjs +41 -0
  62. package/dist/components/chat/chat-client.d.ts +2 -2
  63. package/dist/components/chat/chat-client.mjs +33 -0
  64. package/dist/components/chat/chat-header-addon.d.ts +2 -1
  65. package/dist/components/chat/chat-header-addon.mjs +26 -0
  66. package/dist/components/chat/chat-in-wallet.d.ts +2 -1
  67. package/dist/components/chat/chat-in-wallet.mjs +67 -0
  68. package/dist/components/chat/chat-input.d.ts +3 -2
  69. package/dist/components/chat/chat-input.mjs +295 -0
  70. package/dist/components/chat/chat-list-in-wallet.d.ts +2 -1
  71. package/dist/components/chat/chat-list-in-wallet.mjs +113 -0
  72. package/dist/components/chat/chat-list.d.ts +2 -1
  73. package/dist/components/chat/chat-list.mjs +109 -0
  74. package/dist/components/chat/chat-room.d.ts +3 -2
  75. package/dist/components/chat/chat-room.mjs +225 -0
  76. package/dist/components/chat/chat.d.ts +2 -1
  77. package/dist/components/chat/chat.mjs +163 -0
  78. package/dist/components/chat/context.d.ts +4 -3
  79. package/dist/components/chat/context.mjs +303 -0
  80. package/dist/components/chat/hooks.d.ts +1 -1
  81. package/dist/components/chat/hooks.mjs +59 -0
  82. package/dist/components/chat/index.mjs +7 -0
  83. package/dist/components/chat/message-list.d.ts +3 -2
  84. package/dist/components/chat/message-list.mjs +151 -0
  85. package/dist/components/chat/message.d.ts +4 -3
  86. package/dist/components/chat/message.mjs +312 -0
  87. package/dist/components/chat/participants.d.ts +3 -2
  88. package/dist/components/chat/participants.mjs +60 -0
  89. package/dist/components/chat/time.d.ts +1 -1
  90. package/dist/components/chat/time.mjs +16 -0
  91. package/dist/components/chat/types.d.ts +1 -1
  92. package/dist/components/chat/types.mjs +0 -0
  93. package/dist/components/chat/unread-notification.d.ts +2 -2
  94. package/dist/components/chat/unread-notification.mjs +43 -0
  95. package/dist/components/chat/user-search.d.ts +2 -1
  96. package/dist/components/chat/user-search.mjs +143 -0
  97. package/dist/components/check-mark.d.ts +2 -1
  98. package/dist/components/check-mark.mjs +98 -0
  99. package/dist/components/confirm.d.ts +4 -4
  100. package/dist/components/confirm.mjs +103 -0
  101. package/dist/components/dayjs.d.ts +1 -1
  102. package/dist/components/dayjs.mjs +4 -0
  103. package/dist/components/default-editor-config-provider.d.ts +3 -2
  104. package/dist/components/default-editor-config-provider.mjs +107 -0
  105. package/dist/components/dirty-prompt.d.ts +3 -2
  106. package/dist/components/dirty-prompt.mjs +117 -0
  107. package/dist/components/editor/editor.d.ts +4 -3
  108. package/dist/{editor-B3z0rXVh.mjs → components/editor/editor.mjs} +7 -8
  109. package/dist/components/editor/index.mjs +2 -0
  110. package/dist/components/editor/lazy-editor.d.ts +3 -2
  111. package/dist/components/editor/lazy-editor.mjs +14 -0
  112. package/dist/components/editor/plugins/video-path-fixer-plugin.mjs +29 -0
  113. package/dist/components/editor/preview.d.ts +4 -3
  114. package/dist/components/editor/preview.mjs +32 -0
  115. package/dist/components/emoji-icon.d.ts +2 -1
  116. package/dist/components/emoji-icon.mjs +62 -0
  117. package/dist/components/empty-status/empty-status.d.ts +2 -1
  118. package/dist/components/empty-status/empty-status.mjs +24 -0
  119. package/dist/components/empty-status/index.mjs +1 -0
  120. package/dist/components/hooks/changed.mjs +34 -0
  121. package/dist/components/hooks/index.mjs +6 -0
  122. package/dist/components/hooks/interval.mjs +16 -0
  123. package/dist/components/hooks/locale-context.mjs +12 -0
  124. package/dist/components/hooks/measure.mjs +8 -0
  125. package/dist/components/hooks/now.mjs +10 -0
  126. package/dist/components/hooks/responsive.d.ts +1 -1
  127. package/dist/components/hooks/responsive.mjs +25 -0
  128. package/dist/components/hooks/session.d.ts +1 -0
  129. package/dist/components/hooks/session.mjs +41 -0
  130. package/dist/components/hooks/use-event-callback.mjs +14 -0
  131. package/dist/components/icon-button.d.ts +4 -3
  132. package/dist/components/icon-button.mjs +37 -0
  133. package/dist/components/input/auto-clear-plugin.mjs +26 -0
  134. package/dist/components/input/comment-input.d.ts +2 -1
  135. package/dist/components/input/comment-input.mjs +107 -0
  136. package/dist/components/input/image-path-fixer-plugin.mjs +29 -0
  137. package/dist/components/input/index.mjs +4 -0
  138. package/dist/components/input/input.d.ts +4 -4
  139. package/dist/components/input/input.mjs +152 -0
  140. package/dist/components/input/post-edit.d.ts +2 -1
  141. package/dist/components/input/post-edit.mjs +49 -0
  142. package/dist/components/input/scrollable-editor-wrapper.d.ts +2 -1
  143. package/dist/components/input/scrollable-editor-wrapper.mjs +18 -0
  144. package/dist/components/input/shortcut-plugin.mjs +28 -0
  145. package/dist/components/label-picker.d.ts +2 -1
  146. package/dist/components/label-picker.mjs +41 -0
  147. package/dist/components/lexical.mjs +69 -0
  148. package/dist/components/locale/en.mjs +92 -0
  149. package/dist/components/locale/index.mjs +3 -0
  150. package/dist/components/locale/zh.mjs +94 -0
  151. package/dist/components/pagination.d.ts +3 -2
  152. package/dist/components/pagination.mjs +44 -0
  153. package/dist/components/paywall.d.ts +2 -2
  154. package/dist/components/paywall.mjs +110 -0
  155. package/dist/components/point-up/{box-animation.json.d.ts → box-animation.json} +1 -4
  156. package/dist/components/point-up/index.d.ts +3 -2
  157. package/dist/components/point-up/index.mjs +153 -0
  158. package/dist/components/point-up/lottie-component.d.ts +2 -1
  159. package/dist/components/point-up/lottie-component.mjs +7 -0
  160. package/dist/components/posts/comment-list/comment-list.d.ts +2 -1
  161. package/dist/components/posts/comment-list/comment-list.mjs +163 -0
  162. package/dist/components/posts/comment-list/context.d.ts +4 -4
  163. package/dist/components/posts/comment-list/context.mjs +318 -0
  164. package/dist/components/posts/comment.d.ts +3 -2
  165. package/dist/components/posts/comment.mjs +184 -0
  166. package/dist/components/posts/index.mjs +6 -0
  167. package/dist/components/posts/menu.d.ts +3 -2
  168. package/dist/components/posts/menu.mjs +83 -0
  169. package/dist/components/posts/post-content.d.ts +2 -1
  170. package/dist/components/posts/post-content.mjs +86 -0
  171. package/dist/components/posts/post.d.ts +4 -4
  172. package/dist/components/posts/post.mjs +198 -0
  173. package/dist/components/profile-card/index.mjs +1 -0
  174. package/dist/components/profile-card/profile-card.d.ts +4 -3
  175. package/dist/components/profile-card/profile-card.mjs +162 -0
  176. package/dist/components/rating/binary-thumb.d.ts +4 -3
  177. package/dist/components/rating/binary-thumb.mjs +157 -0
  178. package/dist/components/rating/github-reaction-container.d.ts +2 -1
  179. package/dist/components/rating/github-reaction-container.mjs +46 -0
  180. package/dist/components/rating/github-reaction.d.ts +3 -2
  181. package/dist/components/rating/github-reaction.mjs +173 -0
  182. package/dist/components/rating/index.mjs +3 -0
  183. package/dist/components/rating/rater-list.d.ts +3 -2
  184. package/dist/components/rating/rater-list.mjs +33 -0
  185. package/dist/components/rating/rating.d.ts +1 -1
  186. package/dist/components/rating/rating.mjs +50 -0
  187. package/dist/components/routes.d.ts +1 -1
  188. package/dist/components/routes.mjs +27 -0
  189. package/dist/components/segmented-control.d.ts +3 -2
  190. package/dist/components/segmented-control.mjs +55 -0
  191. package/dist/components/shared/relative-time.d.ts +2 -1
  192. package/dist/components/shared/relative-time.mjs +21 -0
  193. package/dist/components/toast.d.ts +1 -1
  194. package/dist/components/toast.mjs +44 -0
  195. package/dist/components/uploader/index.d.ts +3 -3
  196. package/dist/components/uploader/index.mjs +70 -0
  197. package/dist/components/uploader/utils.mjs +16 -0
  198. package/dist/components/utils.d.ts +4 -4
  199. package/dist/components/utils.mjs +139 -0
  200. package/dist/components/view-more.d.ts +1 -1
  201. package/dist/components/view-more.mjs +50 -0
  202. package/dist/constants.mjs +14 -0
  203. package/dist/global.d.ts +1 -0
  204. package/dist/index.mjs +37 -0
  205. package/dist/preferences.mjs +9 -0
  206. package/dist/theme/index.d.ts +3 -3
  207. package/dist/theme/index.mjs +96 -0
  208. package/dist/theme/typography.d.ts +1 -1
  209. package/dist/theme/typography.mjs +66 -0
  210. package/dist/type-override.d.ts +7 -0
  211. package/dist/types.mjs +0 -0
  212. package/dist/vite-env.d.ts +1 -0
  213. package/dist/ws.d.ts +2 -2
  214. package/dist/ws.mjs +39 -0
  215. package/package.json +18 -25
  216. package/dist/components/avatars/Avatars.stories.d.ts +0 -5
  217. package/dist/components/posts/Post.stories.d.ts +0 -7
  218. package/dist/index-BlqRGWgQ.mjs +0 -7631
  219. package/dist/index.es.js +0 -118
  220. package/dist/index.umd.js +0 -7589
  221. package/dist/test/fixtures/index.d.ts +0 -4
  222. package/dist/test/fixtures/mock-session.d.ts +0 -3
@@ -0,0 +1,312 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import Box from "@mui/material/Box";
3
+ import Typography from "@mui/material/Typography";
4
+ import MenuItem from "@mui/material/MenuItem";
5
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
6
+ import { Icon } from "@iconify/react";
7
+ import { useTheme } from "@mui/material";
8
+ import { AuthorInfo } from "../avatars/index.mjs";
9
+ import { PostContent, Menu } from "../posts/index.mjs";
10
+ import { useChatContext } from "./context.mjs";
11
+ import { useSessionContext } from "../hooks/session.mjs";
12
+ import { useConfirm } from "../confirm.mjs";
13
+ import Time from "./time.mjs";
14
+ import { useChatInWallet } from "./hooks.mjs";
15
+ const baseItemSx = {
16
+ px: 1.25,
17
+ transition: "all 120ms linear"
18
+ };
19
+ export function Message({ message, prevMessage, showTime = true, ...rest }) {
20
+ const { t } = useLocaleContext();
21
+ const { session, isAdmin } = useSessionContext();
22
+ const { confirm } = useConfirm();
23
+ const { activeChatId, deleteMessage, isInWallet, renderMessage } = useChatContext();
24
+ const { isInArcSphere } = useChatInWallet();
25
+ const theme = useTheme();
26
+ const handleDeleteMessage = async () => {
27
+ if (activeChatId) {
28
+ const proceed = await confirm({
29
+ title: t("deleteMessage.title"),
30
+ description: t("deleteMessage.desc"),
31
+ okButtonProps: { color: "error" },
32
+ dialogProps: { sx: { top: `${window.chatInWallet?.safeAreaInsetTop ?? 0}px` } }
33
+ });
34
+ if (proceed) {
35
+ deleteMessage(activeChatId, message.id);
36
+ }
37
+ }
38
+ };
39
+ const renderPostContent = () => {
40
+ return /* @__PURE__ */ jsx(Box, { className: "author-chat-item", sx: { my: 1 }, children: renderMessage ? renderMessage(message) : /* @__PURE__ */ jsx(PostContent, { content: message.content }) });
41
+ };
42
+ const menuItems = [];
43
+ const isSender = message.sender.did === session?.user?.did;
44
+ const messageDate = new Date(message.createdAt);
45
+ const prevMessageDate = prevMessage ? new Date(prevMessage.createdAt) : /* @__PURE__ */ new Date(0);
46
+ const messageInterval = messageDate.getTime() - prevMessageDate.getTime();
47
+ const isSameUser = message.sender.did === prevMessage?.sender?.did;
48
+ if (isSender || isAdmin) {
49
+ menuItems.push(
50
+ /* @__PURE__ */ jsx(MenuItem, { onClick: handleDeleteMessage, children: /* @__PURE__ */ jsx(Box, { component: "span", sx: { color: "error.main" }, children: t("delete") }) }, "delete")
51
+ );
52
+ }
53
+ const compactMessage = messageInterval <= 6e4 && isSameUser;
54
+ return /* @__PURE__ */ jsxs(
55
+ Box,
56
+ {
57
+ ...rest,
58
+ sx: {
59
+ ...baseItemSx,
60
+ position: "relative",
61
+ fontSize: 14,
62
+ borderRadius: 1,
63
+ "&:hover": {
64
+ bgcolor: "action.hover",
65
+ ".message-menu": {
66
+ display: "flex !important"
67
+ }
68
+ },
69
+ ".author-info-title": {
70
+ fontSize: 14,
71
+ fontWeight: 500,
72
+ // username 下方首条消息的 margin-top
73
+ "+ div": { mt: 1 }
74
+ },
75
+ ".author-chat-item": {
76
+ ml: compactMessage ? 6 : 0,
77
+ width: "90%"
78
+ },
79
+ ...{
80
+ ".be-editable": {
81
+ "& > *:last-child": {
82
+ mb: "0 !important"
83
+ }
84
+ }
85
+ },
86
+ ...compactMessage && {
87
+ ".inline-translation-badge": {
88
+ display: "none"
89
+ }
90
+ }
91
+ },
92
+ children: [
93
+ /* @__PURE__ */ jsx(
94
+ Menu,
95
+ {
96
+ items: menuItems,
97
+ className: "message-menu",
98
+ style: {
99
+ position: "absolute",
100
+ right: 12,
101
+ top: 0,
102
+ bottom: 0,
103
+ zIndex: theme.zIndex.modal,
104
+ alignItems: "center",
105
+ display: "none"
106
+ }
107
+ }
108
+ ),
109
+ !compactMessage ? /* @__PURE__ */ jsx(
110
+ AuthorInfo,
111
+ {
112
+ showBadge: false,
113
+ showProfileCard: true,
114
+ showDID: false,
115
+ user: message.sender,
116
+ createdAt: showTime ? message.createdAt : void 0,
117
+ linkToProfile: !isInWallet || isInArcSphere,
118
+ size: "sm",
119
+ style: {
120
+ alignItems: "flex-start"
121
+ },
122
+ children: renderPostContent()
123
+ }
124
+ ) : renderPostContent()
125
+ ]
126
+ }
127
+ );
128
+ }
129
+ export function NotificationMessage({ chat, message, prevMessage }) {
130
+ const { session } = useSessionContext();
131
+ const { t } = useLocaleContext();
132
+ const renderQuote = ({ title, cover }) => {
133
+ if ("post" in message) {
134
+ return /* @__PURE__ */ jsxs(Box, { sx: { color: 14, mt: 1 }, children: [
135
+ /* @__PURE__ */ jsx(
136
+ Typography,
137
+ {
138
+ component: "a",
139
+ variant: "h6",
140
+ href: message.link,
141
+ target: "_blank",
142
+ style: { fontSize: 14, color: "info.main", textDecoration: "none" },
143
+ children: title || t("common.link")
144
+ }
145
+ ),
146
+ cover && // cover image
147
+ /* @__PURE__ */ jsx(Box, { sx: { maxWidth: 200, mt: 1 }, children: /* @__PURE__ */ jsx(
148
+ Box,
149
+ {
150
+ sx: [
151
+ {
152
+ height: 0,
153
+ pt: "56%",
154
+ overflow: "hidden",
155
+ borderRadius: 2,
156
+ backgroundImage: `url(${cover})`,
157
+ backgroundRepeat: "no-repeat",
158
+ backgroundSize: "cover",
159
+ backgroundPosition: "center",
160
+ boxShadow: "rgb(0 0 0 / 12%) 0px 8px 30px"
161
+ }
162
+ ]
163
+ }
164
+ ) })
165
+ ] });
166
+ }
167
+ return null;
168
+ };
169
+ const render = () => {
170
+ const baseCardSx = {
171
+ py: 1.5,
172
+ px: 2,
173
+ bgcolor: "grey.50",
174
+ width: "fit-content",
175
+ maxWidth: "calc(100% - 16px)",
176
+ wordWrap: "break-word",
177
+ borderRadius: 1,
178
+ transition: "all 120ms linear"
179
+ };
180
+ if (message.type === "post_create") {
181
+ return /* @__PURE__ */ jsxs(Box, { sx: { ...baseCardSx }, children: [
182
+ /* @__PURE__ */ jsxs(Box, { sx: { color: "primary.light" }, children: [
183
+ /* @__PURE__ */ jsxs(Box, { children: [
184
+ /* @__PURE__ */ jsx(Icon, { icon: "tabler:news", style: { verticalAlign: "middle", height: 15, width: 15, marginRight: 4 } }),
185
+ /* @__PURE__ */ jsx(Box, { component: "span", sx: { mr: 0.5 }, children: message.sourceUser.fullName }),
186
+ /* @__PURE__ */ jsx("span", { children: t("chat.newPost") })
187
+ ] }),
188
+ /* @__PURE__ */ jsx(Time, { createdAt: message.createdAt })
189
+ ] }),
190
+ renderQuote(message.post)
191
+ ] });
192
+ }
193
+ if (message.type === "comment") {
194
+ return /* @__PURE__ */ jsxs(Box, { sx: { ...baseCardSx }, children: [
195
+ /* @__PURE__ */ jsxs(Box, { sx: { color: "primary.light" }, children: [
196
+ /* @__PURE__ */ jsx(
197
+ Icon,
198
+ {
199
+ icon: "tabler:message-circle-2",
200
+ style: { verticalAlign: "middle", height: 15, width: 15, marginRight: 4 }
201
+ }
202
+ ),
203
+ /* @__PURE__ */ jsx(Box, { component: "span", sx: { mr: 0.5 }, children: message.sourceUser.fullName }),
204
+ /* @__PURE__ */ jsx("span", { children: message?.cc ? t("chat.commentedPost") : t("chat.commentedYourPost") }),
205
+ /* @__PURE__ */ jsx(Time, { createdAt: message.createdAt })
206
+ ] }),
207
+ /* @__PURE__ */ jsx(Typography, { variant: "body1", sx: { fontSize: 16 }, children: message?.comment?.excerpt }),
208
+ renderQuote(message.post)
209
+ ] });
210
+ }
211
+ if (message.type === "reply") {
212
+ return /* @__PURE__ */ jsxs(Box, { sx: { ...baseCardSx }, children: [
213
+ /* @__PURE__ */ jsxs(Box, { sx: { color: "primary.light" }, children: [
214
+ /* @__PURE__ */ jsx(
215
+ Icon,
216
+ {
217
+ icon: "tabler:message-circle-2",
218
+ style: { verticalAlign: "middle", height: 15, width: 15, marginRight: 4 }
219
+ }
220
+ ),
221
+ /* @__PURE__ */ jsx(Box, { component: "span", sx: { mr: 0.5 }, children: message.sourceUser.fullName }),
222
+ /* @__PURE__ */ jsx("span", { children: message?.cc ? t("chat.replyComment") : t("chat.replyYourComment") }),
223
+ /* @__PURE__ */ jsx(Time, { createdAt: message.createdAt })
224
+ ] }),
225
+ /* @__PURE__ */ jsx(Typography, { variant: "body1", sx: { fontSize: 16 }, children: message.reply.excerpt }),
226
+ renderQuote({ title: message.post.title, excerpt: message.comment.excerpt })
227
+ ] });
228
+ }
229
+ if (message.type === "mentionInComment") {
230
+ return /* @__PURE__ */ jsxs(
231
+ Box,
232
+ {
233
+ sx: {
234
+ ...baseCardSx
235
+ },
236
+ children: [
237
+ /* @__PURE__ */ jsxs(Box, { sx: { color: "primary.light" }, children: [
238
+ /* @__PURE__ */ jsx(
239
+ Icon,
240
+ {
241
+ icon: "tabler:message-circle-2",
242
+ style: { verticalAlign: "middle", height: 15, width: 15, marginRight: 4 }
243
+ }
244
+ ),
245
+ /* @__PURE__ */ jsx(Box, { component: "span", sx: { mr: 0.5 }, children: message.sourceUser.fullName }),
246
+ /* @__PURE__ */ jsxs("span", { children: [
247
+ " ",
248
+ t("chat.mentionInComment")
249
+ ] }),
250
+ /* @__PURE__ */ jsx(Time, { createdAt: message.createdAt })
251
+ ] }),
252
+ /* @__PURE__ */ jsx(Typography, { variant: "body1", sx: { fontSize: 16 }, children: message?.comment?.excerpt?.replace(session?.user?.fullName, "") }),
253
+ renderQuote(message.post)
254
+ ]
255
+ }
256
+ );
257
+ }
258
+ if (message.type === "mentionInPost") {
259
+ return /* @__PURE__ */ jsxs(Box, { sx: { ...baseCardSx }, children: [
260
+ /* @__PURE__ */ jsxs(Box, { sx: { color: "primary.light" }, children: [
261
+ /* @__PURE__ */ jsx(
262
+ Icon,
263
+ {
264
+ icon: "tabler:message-circle-2",
265
+ style: { verticalAlign: "middle", height: 15, width: 15, marginRight: 4 }
266
+ }
267
+ ),
268
+ /* @__PURE__ */ jsx(Box, { component: "span", sx: { mr: 0.5 }, children: message.sourceUser.fullName }),
269
+ /* @__PURE__ */ jsx("span", { children: t("chat.mentionInPost") }),
270
+ /* @__PURE__ */ jsx(Time, { createdAt: message.createdAt })
271
+ ] }),
272
+ renderQuote(message.post)
273
+ ] });
274
+ }
275
+ if (message.type === "pointUp") {
276
+ const { points, post, comment, eventKey = "" } = message;
277
+ const unit = points > 1 ? t("chat.points") : t("chat.point");
278
+ const event = eventKey ? `for ${eventKey.toLowerCase().replaceAll("-", " ")}: ` : ": ";
279
+ const tip = t("chat.pointUp", { points: `${points}`, unit, event });
280
+ return /* @__PURE__ */ jsxs(Box, { children: [
281
+ /* @__PURE__ */ jsx(Box, { component: "span", sx: { color: "grey.600" }, children: tip }),
282
+ comment && /* @__PURE__ */ jsx(Typography, { variant: "body1", children: comment.excerpt }),
283
+ post && renderQuote(post)
284
+ ] });
285
+ }
286
+ if (message.type === "task") {
287
+ const titles = {
288
+ open: t("chat.openTask"),
289
+ close: t("chat.closeTask"),
290
+ assign: t("chat.assignTask"),
291
+ unassign: t("chat.unassignTask")
292
+ };
293
+ return /* @__PURE__ */ jsxs(Box, { sx: { ...baseCardSx }, children: [
294
+ /* @__PURE__ */ jsxs(Box, { sx: { color: "primary.light" }, children: [
295
+ /* @__PURE__ */ jsx(
296
+ Icon,
297
+ {
298
+ icon: "tabler:arrow-forward-up",
299
+ style: { verticalAlign: "middle", height: 15, width: 15, marginRight: 4 }
300
+ }
301
+ ),
302
+ /* @__PURE__ */ jsx(Box, { component: "span", sx: { mr: 0.5 }, children: message.sourceUser.fullName }),
303
+ /* @__PURE__ */ jsx("span", { children: titles[message.subtype] }),
304
+ /* @__PURE__ */ jsx(Time, { createdAt: message.createdAt })
305
+ ] }),
306
+ renderQuote(message.post)
307
+ ] });
308
+ }
309
+ return /* @__PURE__ */ jsx(Message, { message, showTime: false });
310
+ };
311
+ return /* @__PURE__ */ jsx(Box, { sx: { ...baseItemSx, py: 0.5, fontSize: 14 }, children: render() });
312
+ }
@@ -1,8 +1,9 @@
1
+ /// <reference types="react" />
1
2
  import { SxProps } from '@mui/material';
2
- import { User } from '../../types';
3
+ import type { User } from '../../types';
3
4
  interface Props {
4
5
  users: User[];
5
6
  sx?: SxProps;
6
7
  }
7
- export default function Participants({ users, sx, ...rest }: Props): import("react/jsx-runtime").JSX.Element;
8
+ export default function Participants({ users, sx, ...rest }: Props): import("react").JSX.Element;
8
9
  export {};
@@ -0,0 +1,60 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { styled } from "@mui/material/styles";
4
+ import { Box, Button, Tooltip, ClickAwayListener, tooltipClasses } from "@mui/material";
5
+ import { Avatars, AuthorInfo } from "../avatars/index.mjs";
6
+ const HtmlTooltip = styled(({ className, ...props }) => /* @__PURE__ */ jsx(Tooltip, { ...props, classes: { popper: className } }))(({ theme }) => ({
7
+ [`& .${tooltipClasses.tooltip}`]: {
8
+ color: "inherit",
9
+ backgroundColor: theme.palette.background.paper,
10
+ maxWidth: "initial",
11
+ maxHeight: 300,
12
+ marginLeft: -20,
13
+ overflowY: "auto",
14
+ border: `1px solid ${theme.palette.divider}`,
15
+ boxShadow: "0 8px 24px rgba(140,149,159,0.2)"
16
+ }
17
+ }));
18
+ export default function Participants({ users, sx, ...rest }) {
19
+ const [open, setOpen] = useState(false);
20
+ const handleTooltipClose = () => {
21
+ setOpen(false);
22
+ };
23
+ const handleTooltipOpen = () => {
24
+ setOpen(true);
25
+ };
26
+ const visibleUsers = users.slice(0, 5);
27
+ const mergedSx = [
28
+ {
29
+ display: "flex",
30
+ alignItems: "center",
31
+ gap: 1,
32
+ p: 0.5,
33
+ pr: 1,
34
+ border: 1,
35
+ borderColor: "grey.300",
36
+ ".MuiAvatarGroup-root": {
37
+ height: 24
38
+ }
39
+ },
40
+ ...Array.isArray(sx) ? sx : [sx]
41
+ ];
42
+ return /* @__PURE__ */ jsx(ClickAwayListener, { onClickAway: handleTooltipClose, children: /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
43
+ HtmlTooltip,
44
+ {
45
+ PopperProps: {
46
+ disablePortal: true
47
+ },
48
+ onClose: handleTooltipClose,
49
+ open,
50
+ disableFocusListener: true,
51
+ disableHoverListener: true,
52
+ disableTouchListener: true,
53
+ title: /* @__PURE__ */ jsx(Fragment, { children: users.map((item, i) => /* @__PURE__ */ jsx(Box, { sx: { p: 1 }, children: /* @__PURE__ */ jsx(AuthorInfo, { user: item, size: "sm" }) }, i)) }),
54
+ children: /* @__PURE__ */ jsxs(Button, { ...rest, sx: mergedSx, onClick: handleTooltipOpen, children: [
55
+ /* @__PURE__ */ jsx(Avatars, { users: visibleUsers, max: 5 }),
56
+ /* @__PURE__ */ jsx(Box, { sx: { fontSize: 12, fontWeight: "bold", color: "grey.600" }, children: users.length })
57
+ ] })
58
+ }
59
+ ) }) });
60
+ }
@@ -1,4 +1,4 @@
1
- import { default as React } from 'react';
1
+ import React from 'react';
2
2
  interface TimeShowProps {
3
3
  createdAt: string | Date;
4
4
  }
@@ -0,0 +1,16 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import Box from "@mui/material/Box";
3
+ import dayjs from "dayjs";
4
+ import RelativeTime from "../shared/relative-time.mjs";
5
+ const Time = ({ createdAt }) => {
6
+ if (!createdAt) {
7
+ return null;
8
+ }
9
+ const messageTime = typeof createdAt === "string" ? new Date(createdAt) : createdAt;
10
+ const now = /* @__PURE__ */ new Date();
11
+ const diffInMilliseconds = now.getTime() - messageTime.getTime();
12
+ const diffInDays = diffInMilliseconds / (1e3 * 60 * 60 * 24);
13
+ const isWithinSevenDays = diffInDays <= 3;
14
+ return /* @__PURE__ */ jsx(Box, { component: "span", sx: { fontSize: 12, color: "grey.500", ml: 0.8 }, children: isWithinSevenDays ? /* @__PURE__ */ jsx(RelativeTime, { value: createdAt }) : dayjs(messageTime).format("YYYY-MM-DD HH:mm") });
15
+ };
16
+ export default Time;
@@ -1,4 +1,4 @@
1
- import { User } from '../../types';
1
+ import type { User } from '../../types';
2
2
  export interface Message {
3
3
  id: string;
4
4
  content?: string;
File without changes
@@ -10,7 +10,7 @@ interface UnreadNotificationContextType {
10
10
  markChatAsRead: (chatId: string) => void;
11
11
  unreadMessageCount: number;
12
12
  }
13
- export declare const UnreadNotificationContext: import('react').Context<UnreadNotificationContextType>;
13
+ export declare const UnreadNotificationContext: import("react").Context<UnreadNotificationContextType>;
14
14
  export declare const useUnreadNotification: () => UnreadNotificationContextType;
15
- export declare function UnreadNotificationProvider({ fetchUnreadState, children }: UnreadNotificationProviderProps): import("react/jsx-runtime").JSX.Element;
15
+ export declare function UnreadNotificationProvider({ fetchUnreadState, children }: UnreadNotificationProviderProps): import("react").JSX.Element;
16
16
  export {};
@@ -0,0 +1,43 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useMemo, useState, useCallback } from "react";
3
+ import { useSessionContext } from "../hooks/index.mjs";
4
+ import preferences from "../../preferences.mjs";
5
+ export const UnreadNotificationContext = createContext(
6
+ {}
7
+ );
8
+ export const useUnreadNotification = () => useContext(UnreadNotificationContext);
9
+ export function UnreadNotificationProvider({ fetchUnreadState, children }) {
10
+ const { session } = useSessionContext();
11
+ const [chatUnreadCounts, setChatUnreadCounts] = useState({});
12
+ const unread = useMemo(() => Object.values(chatUnreadCounts).some((x) => x > 0), [chatUnreadCounts]);
13
+ const unreadMessageCount = useMemo(
14
+ () => Object.values(chatUnreadCounts).reduce((acc, x) => acc + x, 0),
15
+ [chatUnreadCounts]
16
+ );
17
+ const incrementUnreadCount = useCallback((chatId, count) => {
18
+ setChatUnreadCounts((prev) => ({ ...prev, [chatId]: (prev[chatId] || 0) + count }));
19
+ }, []);
20
+ const markChatAsRead = useCallback((chatId) => {
21
+ setChatUnreadCounts((prev) => ({ ...prev, [chatId]: 0 }));
22
+ }, []);
23
+ const update = async () => {
24
+ const unreadState = await fetchUnreadState();
25
+ setChatUnreadCounts(unreadState);
26
+ };
27
+ useEffect(() => {
28
+ if (session.user && preferences.enableNotificationBadge && preferences.chatEnabled) {
29
+ update();
30
+ }
31
+ }, [session.user]);
32
+ const value = useMemo(
33
+ () => ({
34
+ unread,
35
+ chatUnreadCounts,
36
+ unreadMessageCount,
37
+ incrementUnreadCount,
38
+ markChatAsRead
39
+ }),
40
+ [unread, chatUnreadCounts, unreadMessageCount, incrementUnreadCount, markChatAsRead]
41
+ );
42
+ return /* @__PURE__ */ jsx(UnreadNotificationContext.Provider, { value, children });
43
+ }
@@ -1,7 +1,8 @@
1
+ /// <reference types="react" />
1
2
  import { SxProps } from '@mui/material';
2
3
  interface Props {
3
4
  sx?: SxProps;
4
5
  inputSx?: SxProps;
5
6
  }
6
- export declare function UserSearch({ sx, inputSx, ...rest }: Props): import("react/jsx-runtime").JSX.Element;
7
+ export declare function UserSearch({ sx, inputSx, ...rest }: Props): import("react").JSX.Element;
7
8
  export {};
@@ -0,0 +1,143 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { createElement } from "react";
3
+ import { Autocomplete, Backdrop, Box, InputAdornment, TextField, Typography } from "@mui/material";
4
+ import { useState } from "react";
5
+ import { useRequest } from "ahooks";
6
+ import DID from "@arcblock/ux/lib/DID";
7
+ import SearchIcon from "virtual:icons/tabler/search";
8
+ import { useNavigate } from "react-router-dom";
9
+ import ReactDOM from "react-dom";
10
+ import { mergeSx } from "../utils.mjs";
11
+ import { useChatContext } from "./context.mjs";
12
+ import { Avatar } from "../avatars/index.mjs";
13
+ import { useSessionContext } from "../hooks/index.mjs";
14
+ import { useChatInWallet } from "./hooks.mjs";
15
+ export function UserSearch({ sx, inputSx, ...rest }) {
16
+ const { session } = useSessionContext();
17
+ const navigate = useNavigate();
18
+ const { client, isInWallet, chats, setActiveChat, createDM } = useChatContext();
19
+ const [inputValue, setInputValue] = useState("");
20
+ const [open, setOpen] = useState(false);
21
+ const { navigateToChat } = useChatInWallet();
22
+ const { data, loading } = useRequest(
23
+ async () => {
24
+ if (!open) {
25
+ return Promise.resolve([]);
26
+ }
27
+ const results = await client.searchUsers({ search: inputValue });
28
+ if (!results?.length) {
29
+ return [];
30
+ }
31
+ return results.filter((x) => x.did !== session?.user?.did);
32
+ },
33
+ {
34
+ throttleWait: 500,
35
+ throttleLeading: false,
36
+ refreshDeps: [open, inputValue, session?.user?.did]
37
+ }
38
+ );
39
+ const mergedSx = mergeSx({}, sx);
40
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
41
+ /* @__PURE__ */ jsx(Box, { sx: mergedSx, ...rest, children: /* @__PURE__ */ jsx(
42
+ Autocomplete,
43
+ {
44
+ open,
45
+ onOpen: () => setOpen(true),
46
+ onClose: () => {
47
+ setInputValue("");
48
+ setOpen(false);
49
+ },
50
+ disableClearable: true,
51
+ filterOptions: (x) => x,
52
+ options: data || [],
53
+ getOptionLabel: () => "",
54
+ renderOption: (props, option) => /* @__PURE__ */ createElement(Box, { component: "li", ...props, key: option.did, sx: { px: "8px!important" } }, /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", width: 1 }, children: [
55
+ /* @__PURE__ */ jsx(Box, { sx: { mt: 0.25, lineHeight: 1 }, children: /* @__PURE__ */ jsx(Avatar, { did: option.did, src: option.avatar, size: 28, shape: "circle", variant: "circle" }) }),
56
+ /* @__PURE__ */ jsxs(
57
+ Box,
58
+ {
59
+ sx: {
60
+ flex: 1,
61
+ display: "flex",
62
+ flexDirection: "column",
63
+ overflow: "hidden",
64
+ ml: 1
65
+ },
66
+ children: [
67
+ /* @__PURE__ */ jsx(
68
+ Typography,
69
+ {
70
+ variant: "body2",
71
+ sx: {
72
+ fontSize: 12,
73
+ fontWeight: "bold",
74
+ overflow: "hidden",
75
+ whiteSpace: "nowrap",
76
+ textOverflow: "ellipsis"
77
+ },
78
+ children: option.fullName
79
+ }
80
+ ),
81
+ /* @__PURE__ */ jsx(Box, { sx: { ".span": { lineHeight: 1 } }, children: /* @__PURE__ */ jsx(DID, { did: option.did, copyable: false, compact: true, responsive: false, size: 12 }) })
82
+ ]
83
+ }
84
+ )
85
+ ] })),
86
+ onChange: async (event, newValue, reason) => {
87
+ if (event.type === "keydown" && event.key === "Backspace" && reason === "removeOption") {
88
+ return;
89
+ }
90
+ const chatId = [newValue.did, session?.user?.did].sort().join("-");
91
+ const chat = chats.find((x) => x.id === chatId);
92
+ if (isInWallet) {
93
+ if (chat) {
94
+ navigateToChat({ id: chat.id, title: newValue.fullName });
95
+ } else {
96
+ const dm = await createDM(newValue.did);
97
+ navigateToChat({ id: dm.id, title: newValue.fullName });
98
+ }
99
+ } else if (chat) {
100
+ setActiveChat(chat);
101
+ } else {
102
+ navigate(`/chat/dm/${newValue.did}`);
103
+ }
104
+ },
105
+ loading,
106
+ onInputChange: (_, newInputValue, reason) => {
107
+ if (reason === "reset") {
108
+ return;
109
+ }
110
+ setInputValue(newInputValue);
111
+ },
112
+ renderInput: (params) => /* @__PURE__ */ jsx(
113
+ TextField,
114
+ {
115
+ ...params,
116
+ placeholder: "Search user",
117
+ variant: "outlined",
118
+ sx: {
119
+ fontSize: 12,
120
+ ".MuiInputBase-root": { pr: "8px!important" },
121
+ ".MuiInputBase-input": { py: "0!important" },
122
+ fieldset: { borderColor: "divider!important" }
123
+ },
124
+ slotProps: {
125
+ input: {
126
+ ...params.InputProps,
127
+ type: "search",
128
+ sx: inputSx,
129
+ startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx(Box, { component: SearchIcon, sx: { fontSize: 14 } }) })
130
+ }
131
+ }
132
+ }
133
+ ),
134
+ isOptionEqualToValue: (option, value) => option.did === value.did,
135
+ sx: { ".MuiAutocomplete-endAdornment": { display: "none" } }
136
+ }
137
+ ) }),
138
+ ReactDOM.createPortal(
139
+ /* @__PURE__ */ jsx(Backdrop, { open, sx: { zIndex: "modal", bgcolor: "transparent" } }),
140
+ window.document.body
141
+ )
142
+ ] });
143
+ }
@@ -1,7 +1,8 @@
1
+ /// <reference types="react" />
1
2
  interface Props {
2
3
  size?: number;
3
4
  animationKey: string;
4
5
  eager?: boolean;
5
6
  }
6
- export default function CheckMark({ size, animationKey, eager }: Props): import("react/jsx-runtime").JSX.Element;
7
+ export default function CheckMark({ size, animationKey, eager }: Props): import("react").JSX.Element;
7
8
  export {};