@blocklet/discuss-kit-ux 2.4.36 → 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-BsHdgrDc.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 +10 -17
  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-BZDpbkvV.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,225 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import Box from "@mui/material/Box";
4
+ import Button from "@mui/material/Button";
5
+ import CircularProgress from "@mui/material/CircularProgress";
6
+ import { Backdrop, Stack, useMediaQuery } from "@mui/material";
7
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
8
+ import { useTheme } from "@mui/material/styles";
9
+ import UsersPlusIcon from "virtual:icons/tabler/users-plus";
10
+ import { useLocalStorageState } from "ahooks";
11
+ import { EditorConfigProvider } from "@blocklet/editor";
12
+ import MessageList from "./message-list.mjs";
13
+ import { useChatContext } from "./context.mjs";
14
+ import { useSessionContext } from "../hooks/index.mjs";
15
+ import Participants from "./participants.mjs";
16
+ import { Menu } from "../posts/index.mjs";
17
+ import { useConfirm } from "../confirm.mjs";
18
+ import { Back } from "../back.mjs";
19
+ import { useChatInWallet } from "./hooks.mjs";
20
+ import { ChatInput } from "./chat-input.mjs";
21
+ import { Avatar } from "../avatars/index.mjs";
22
+ function getLineClamp(count) {
23
+ return {
24
+ display: "-webkit-box",
25
+ WebkitLineClamp: count,
26
+ WebkitBoxOrient: "vertical",
27
+ overflow: "hidden",
28
+ lineHeight: 1.5,
29
+ wordBreak: "break-word"
30
+ };
31
+ }
32
+ function RoomTitle({ title }) {
33
+ return /* @__PURE__ */ jsx(Box, { component: "span", sx: { fontSize: 14, fontWeight: "medium" }, children: title });
34
+ }
35
+ export default function ChatRoom({ chat, inWallet, ...rest }) {
36
+ const { isChatInWalletV2 } = useChatInWallet();
37
+ const { t } = useLocaleContext();
38
+ const theme = useTheme();
39
+ const downSm = useMediaQuery((currentTheme) => currentTheme.breakpoints.down("sm"));
40
+ const {
41
+ initChatRoom,
42
+ isActiveChat,
43
+ getOppositeUser,
44
+ sendMessage,
45
+ joinChannel,
46
+ leaveChannel,
47
+ deleteChannel,
48
+ setEditingChannel,
49
+ chatRoomHeaderAddons
50
+ } = useChatContext();
51
+ const { confirm } = useConfirm();
52
+ const isActive = isActiveChat(chat.id);
53
+ const { session, isAdmin } = useSessionContext();
54
+ const isCreator = chat.creator.did === session?.user?.did;
55
+ const [input, setInput] = useLocalStorageState(`chat-input-${chat.id}`, { defaultValue: "" });
56
+ const messageListRef = useRef(null);
57
+ useEffect(() => {
58
+ if (chat.isActivated) {
59
+ initChatRoom(chat.id);
60
+ }
61
+ }, [chat.isActivated]);
62
+ const handleDeleteChannel = async () => {
63
+ const proceed = await confirm({
64
+ title: t("chat.deleteChannelTitle"),
65
+ description: t("chat.deleteChannelDesc"),
66
+ okButtonProps: { color: "error" }
67
+ });
68
+ if (proceed) {
69
+ deleteChannel(chat.id);
70
+ }
71
+ };
72
+ const onFocusChange = (focused) => {
73
+ if (downSm && focused) messageListRef.current?.scrollToBottom();
74
+ };
75
+ const renderRoomHeader = () => {
76
+ if (chat.type === "notification") {
77
+ return /* @__PURE__ */ jsx(RoomTitle, { title: t("chat.notification") });
78
+ }
79
+ if (chat.type === "dm") {
80
+ const oppositeUser = getOppositeUser(chat);
81
+ return /* @__PURE__ */ jsxs(
82
+ Stack,
83
+ {
84
+ direction: "row",
85
+ sx: {
86
+ alignItems: "center",
87
+ justifyContent: "space-between",
88
+ width: 1
89
+ },
90
+ children: [
91
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
92
+ /* @__PURE__ */ jsx(Avatar, { did: oppositeUser?.did, src: oppositeUser?.avatar, size: 24, shape: "circle", variant: "rounded" }),
93
+ /* @__PURE__ */ jsx(RoomTitle, { title: oppositeUser.fullName })
94
+ ] }),
95
+ chatRoomHeaderAddons && chatRoomHeaderAddons(chat)
96
+ ]
97
+ }
98
+ );
99
+ }
100
+ if (chat.type === "channel") {
101
+ const menuItems = [];
102
+ if (chat.hasJoined && !isCreator) {
103
+ menuItems.push(
104
+ /* @__PURE__ */ jsx(Menu.Item, { onClick: () => leaveChannel(chat.id), children: /* @__PURE__ */ jsx(Box, { component: "span", sx: { color: "error.main" }, children: t("chat.leaveChannel") }) }, "leave")
105
+ );
106
+ }
107
+ if (isAdmin || isCreator) {
108
+ menuItems.unshift(
109
+ /* @__PURE__ */ jsx(Menu.Item, { onClick: () => setEditingChannel(chat), children: /* @__PURE__ */ jsx(Box, { component: "span", children: "Edit" }) }, "edit")
110
+ );
111
+ menuItems.push(
112
+ /* @__PURE__ */ jsx(Menu.Item, { onClick: handleDeleteChannel, children: /* @__PURE__ */ jsx(Box, { component: "span", sx: { color: "error.main" }, children: t("chat.deleteChannel") }) }, "delete")
113
+ );
114
+ }
115
+ return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", justifyContent: "space-between", alignItems: "center", width: 1, flex: 1 }, children: [
116
+ /* @__PURE__ */ jsxs(Box, { sx: { minWidth: 0 }, children: [
117
+ /* @__PURE__ */ jsx(Box, { component: "span", sx: { fontSize: 14, fontWeight: "bold", color: "grey.700", ...getLineClamp(1) }, children: chat.name }),
118
+ /* @__PURE__ */ jsx(Box, { sx: { fontSize: 12, color: "grey.500", ...getLineClamp(1) }, children: chat.description })
119
+ ] }),
120
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexShrink: 0, alignItems: "center", gap: 1 }, children: [
121
+ !chat.hasJoined && /* @__PURE__ */ jsx(
122
+ Button,
123
+ {
124
+ variant: "contained",
125
+ color: "primary",
126
+ onClick: () => joinChannel(chat.id),
127
+ startIcon: /* @__PURE__ */ jsx(Box, { component: UsersPlusIcon, sx: { fontSize: "16px!important" } }),
128
+ children: t("chat.joinChannel")
129
+ }
130
+ ),
131
+ chat.hasJoined && /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Participants, { users: chat.participants, sx: { border: "none" } }) }),
132
+ chatRoomHeaderAddons && chatRoomHeaderAddons(chat),
133
+ /* @__PURE__ */ jsx(Menu, { items: menuItems })
134
+ ] })
135
+ ] });
136
+ }
137
+ return null;
138
+ };
139
+ if (chat.isActivated && !chat.ready) {
140
+ return /* @__PURE__ */ jsx(
141
+ Backdrop,
142
+ {
143
+ open: true,
144
+ sx: {
145
+ zIndex: theme.zIndex.drawer + 1,
146
+ bgcolor: "transparent"
147
+ },
148
+ children: /* @__PURE__ */ jsx(CircularProgress, {})
149
+ }
150
+ );
151
+ }
152
+ return /* @__PURE__ */ jsxs(Box, { ...rest, sx: { display: isActive ? "flex" : "none", flexDirection: "column", height: "100%" }, children: [
153
+ !inWallet && /* @__PURE__ */ jsxs(
154
+ Box,
155
+ {
156
+ sx: {
157
+ display: "flex",
158
+ alignItems: "center",
159
+ flex: "0 0 auto",
160
+ height: 52,
161
+ px: 2.5,
162
+ borderBottom: "1px solid",
163
+ borderColor: "divider"
164
+ },
165
+ children: [
166
+ downSm && /* @__PURE__ */ jsx(Back, { iconOnly: true, url: "/chat" }),
167
+ renderRoomHeader()
168
+ ]
169
+ }
170
+ ),
171
+ !!inWallet && isChatInWalletV2 && /* @__PURE__ */ jsxs(
172
+ Box,
173
+ {
174
+ sx: {
175
+ display: "flex",
176
+ alignItems: "center",
177
+ flex: "0 0 auto",
178
+ height: 52,
179
+ px: 2.5,
180
+ borderBottom: "1px solid",
181
+ borderColor: "divider"
182
+ },
183
+ children: [
184
+ downSm && /* @__PURE__ */ jsx(Back, { iconOnly: true, url: "/chat-in-wallet" }),
185
+ renderRoomHeader()
186
+ ]
187
+ }
188
+ ),
189
+ /* @__PURE__ */ jsx(Box, { sx: { flex: 1, overflow: "hidden" }, children: /* @__PURE__ */ jsx(EditorConfigProvider, { value: { openLinkInNewTab: !!inWallet }, children: /* @__PURE__ */ jsx(MessageList, { ref: messageListRef, chat }) }) }),
190
+ /* @__PURE__ */ jsxs(Box, { sx: { position: "relative" }, children: [
191
+ chat.isActivated && chat.type !== "notification" && /* @__PURE__ */ jsx(Box, { sx: { px: { xs: 0, sm: 2.5 }, pb: { xs: 0, sm: 2.5 } }, children: /* @__PURE__ */ jsx(
192
+ ChatInput,
193
+ {
194
+ initialContent: input,
195
+ onContentChange: (v) => setInput(v),
196
+ onFocusChange,
197
+ send: (content) => sendMessage(chat.id, content)
198
+ }
199
+ ) }),
200
+ chat.type === "channel" && !chat.hasJoined && /* @__PURE__ */ jsxs(
201
+ Box,
202
+ {
203
+ sx: {
204
+ position: "absolute",
205
+ zIndex: 9999999,
206
+ top: 0,
207
+ left: 0,
208
+ right: 0,
209
+ bottom: 0,
210
+ bgcolor: "rgba(255, 255, 255, 0.7)",
211
+ display: "flex",
212
+ flexDirection: "column",
213
+ alignItems: "center",
214
+ justifyContent: "center",
215
+ color: "#fff"
216
+ },
217
+ children: [
218
+ /* @__PURE__ */ jsx(Box, { sx: { color: "primary.main", mb: 0.5, fontSize: 13, fontWeight: 500 }, children: t("chat.notYetJoinedTheChannel") }),
219
+ /* @__PURE__ */ jsx(Box, { sx: { color: "secondary.main", cursor: "pointer", fontSize: 13 }, onClick: () => joinChannel(chat.id), children: t("chat.joinChannel") })
220
+ ]
221
+ }
222
+ )
223
+ ] })
224
+ ] });
225
+ }
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { SxProps } from '@mui/material';
2
3
  import { ChannelUpdatePayload } from './types';
3
4
  interface ChatProps {
@@ -8,5 +9,5 @@ interface ChatProps {
8
9
  onSubmit: (payload: ChannelUpdatePayload) => void;
9
10
  }>;
10
11
  }
11
- export default function Chat({ sx, ChannelEditComponent, ...rest }: ChatProps): import("react/jsx-runtime").JSX.Element;
12
+ export default function Chat({ sx, ChannelEditComponent, ...rest }: ChatProps): import("react").JSX.Element;
12
13
  export {};
@@ -0,0 +1,163 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
3
+ import { Backdrop, useMediaQuery } from "@mui/material";
4
+ import Box from "@mui/material/Box";
5
+ import IconButton from "@mui/material/IconButton";
6
+ import CircularProgress from "@mui/material/CircularProgress";
7
+ import ChatBubbleEmptyIcon from "virtual:icons/iconoir/chat-bubble-empty";
8
+ import { Add as AddIcon } from "@mui/icons-material";
9
+ import { Helmet } from "react-helmet";
10
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
11
+ import ChatList from "./chat-list.mjs";
12
+ import ChatRoom from "./chat-room.mjs";
13
+ import { useChatContext } from "./context.mjs";
14
+ import { AccessControl } from "../authz/index.mjs";
15
+ import { UserSearch } from "./user-search.mjs";
16
+ function Empty({ sx }) {
17
+ const { t } = useLocaleContext();
18
+ const mergedSx = [
19
+ {
20
+ display: "flex",
21
+ flexDirection: "column",
22
+ justifyContent: "center",
23
+ alignItems: "center",
24
+ gap: 1,
25
+ color: "grey.600"
26
+ },
27
+ ...Array.isArray(sx) ? sx : [sx]
28
+ ];
29
+ return /* @__PURE__ */ jsxs(Box, { sx: mergedSx, children: [
30
+ /* @__PURE__ */ jsx(ChatBubbleEmptyIcon, { style: { fontSize: 32 } }),
31
+ /* @__PURE__ */ jsx(Box, { component: "span", sx: { fontSize: 14, fontWeight: 500 }, children: t("chat.noChats") })
32
+ ] });
33
+ }
34
+ export default function Chat({ sx, ChannelEditComponent, ...rest }) {
35
+ const {
36
+ client,
37
+ initialized,
38
+ chats,
39
+ activeChatId,
40
+ addChat,
41
+ updateChat,
42
+ setActiveChat,
43
+ getOppositeUser,
44
+ editingChannel,
45
+ setEditingChannel
46
+ } = useChatContext();
47
+ const downMd = useMediaQuery((theme) => theme.breakpoints.down("sm"));
48
+ const { t } = useLocaleContext();
49
+ const activeChat = chats?.filter((chat) => chat?.id === activeChatId)?.[0];
50
+ const webTitleMap = {
51
+ dm: () => getOppositeUser(activeChat)?.fullName || t("chat.unknown"),
52
+ notification: () => t("chat.notification"),
53
+ channel: () => activeChat?.type === "channel" ? `# ${activeChat.name}` : t("chat.unknownChannel"),
54
+ default: () => t("chat.chats")
55
+ };
56
+ const getWebTitle = () => {
57
+ if (!activeChat) {
58
+ return t("chat.chats");
59
+ }
60
+ const getTitle = webTitleMap[activeChat.type] || webTitleMap.default;
61
+ return getTitle();
62
+ };
63
+ const show = useMemo(() => {
64
+ if (downMd) {
65
+ return {
66
+ left: !activeChatId,
67
+ right: !!activeChatId
68
+ };
69
+ }
70
+ return {
71
+ left: true,
72
+ right: true
73
+ };
74
+ }, [downMd, activeChatId]);
75
+ if (!initialized) {
76
+ return /* @__PURE__ */ jsx(
77
+ Backdrop,
78
+ {
79
+ open: true,
80
+ sx: {
81
+ zIndex: (theme) => theme.zIndex.drawer + 1,
82
+ bgcolor: "transparent"
83
+ },
84
+ children: /* @__PURE__ */ jsx(CircularProgress, {})
85
+ }
86
+ );
87
+ }
88
+ const mergedSx = [
89
+ { display: "flex", height: "100%", bgcolor: "background.default" },
90
+ ...Array.isArray(sx) ? sx : [sx]
91
+ ];
92
+ const handleChannelEdit = async (payload) => {
93
+ if (payload.id) {
94
+ await client.updateChannel(payload);
95
+ updateChat(payload.id, (chat) => ({ ...chat, ...payload }));
96
+ setEditingChannel(null);
97
+ } else {
98
+ const saved = await client.createChannel(payload);
99
+ const newChannel = { ...saved, hasJoined: true };
100
+ addChat(newChannel);
101
+ setEditingChannel(null);
102
+ setActiveChat(newChannel);
103
+ }
104
+ };
105
+ return /* @__PURE__ */ jsxs(Box, { ...rest, sx: mergedSx, children: [
106
+ /* @__PURE__ */ jsx(Helmet, { title: getWebTitle() }),
107
+ show.left && /* @__PURE__ */ jsxs(
108
+ Box,
109
+ {
110
+ sx: {
111
+ display: "flex",
112
+ flexDirection: "column",
113
+ width: { sm: 320, xs: "100%" },
114
+ borderRight: ({ palette }) => `1px solid ${palette.divider}`
115
+ },
116
+ children: [
117
+ /* @__PURE__ */ jsxs(
118
+ Box,
119
+ {
120
+ sx: {
121
+ display: "flex",
122
+ justifyContent: "space-between",
123
+ alignItems: "center",
124
+ gap: 1,
125
+ height: 52,
126
+ px: 3,
127
+ borderBottom: "1px solid",
128
+ borderColor: "divider"
129
+ },
130
+ children: [
131
+ /* @__PURE__ */ jsx(UserSearch, { sx: { fontSize: 16, flex: 1 } }),
132
+ /* @__PURE__ */ jsx(AccessControl, { roles: ["owner", "admin"], children: /* @__PURE__ */ jsx(
133
+ IconButton,
134
+ {
135
+ onClick: () => setEditingChannel({ name: "", description: "" }),
136
+ sx: { p: 1, borderRadius: 1, border: 1, borderColor: "grey.200", height: 32, width: 32 },
137
+ children: /* @__PURE__ */ jsx(AddIcon, { sx: { color: "text.primary" } })
138
+ }
139
+ ) })
140
+ ]
141
+ }
142
+ ),
143
+ !!chats?.length && /* @__PURE__ */ jsx(ChatList, { sx: { flex: 1, overflowY: "auto" }, inWallet: false }),
144
+ !chats?.length && /* @__PURE__ */ jsx(Empty, { sx: { flex: 1 } })
145
+ ]
146
+ }
147
+ ),
148
+ show.right && /* @__PURE__ */ jsxs(Box, { sx: { flex: 1, overflow: "hidden" }, children: [
149
+ chats.map((chat) => {
150
+ return /* @__PURE__ */ jsx(ChatRoom, { chat, inWallet: false }, chat.id);
151
+ }),
152
+ !activeChatId && /* @__PURE__ */ jsx(Empty, { sx: { height: 1 } })
153
+ ] }),
154
+ ChannelEditComponent && /* @__PURE__ */ jsx(
155
+ ChannelEditComponent,
156
+ {
157
+ initialValue: editingChannel,
158
+ onClose: () => setEditingChannel(null),
159
+ onSubmit: handleChannelEdit
160
+ }
161
+ )
162
+ ] });
163
+ }
@@ -1,5 +1,6 @@
1
- import { User } from '../../types';
2
- import { default as ChatClient } from './chat-client';
1
+ /// <reference types="react" />
2
+ import type { User } from '../../types';
3
+ import ChatClient from './chat-client';
3
4
  import { Message, Chat as ChatType, ChannelUpdatePayload } from './types';
4
5
  export interface ChatProviderProps {
5
6
  children: React.ReactNode;
@@ -42,5 +43,5 @@ interface ChatContextValue extends ChatState {
42
43
  chatRoomHeaderAddons?: (chat: ChatType) => React.ReactNode;
43
44
  }
44
45
  export declare const useChatContext: () => ChatContextValue;
45
- export declare function ChatProvider({ client, activeChatId, children, isInWallet, renderMessage, chatRoomHeaderAddons, }: ChatProviderProps): import("react/jsx-runtime").JSX.Element;
46
+ export declare function ChatProvider({ client, activeChatId, children, isInWallet, renderMessage, chatRoomHeaderAddons, }: ChatProviderProps): import("react").JSX.Element;
46
47
  export {};