@guokit-dev/im-react 0.0.0-stage → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/dist/index.cjs +3095 -0
- package/dist/index.mjs +3073 -0
- package/dist/style.css +280 -0
- package/dist/types/core/chatController.d.ts +121 -0
- package/dist/types/core/externalStore.d.ts +25 -0
- package/dist/types/core/features.d.ts +8 -0
- package/dist/types/core/format.d.ts +32 -0
- package/dist/types/core/imStore.d.ts +8 -0
- package/dist/types/core/index.d.ts +9 -0
- package/dist/types/core/media.d.ts +37 -0
- package/dist/types/core/memberCache.d.ts +31 -0
- package/dist/types/core/mention.d.ts +31 -0
- package/dist/types/core/strings.d.ts +309 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/ui/chat/ChatPage.d.ts +11 -0
- package/dist/types/ui/chat/Composer.d.ts +29 -0
- package/dist/types/ui/chat/MessageList.d.ts +17 -0
- package/dist/types/ui/chat/MessageRow.d.ts +24 -0
- package/dist/types/ui/chat/bubbles.d.ts +26 -0
- package/dist/types/ui/chat/emojis.d.ts +2 -0
- package/dist/types/ui/context.d.ts +44 -0
- package/dist/types/ui/conversation/ConversationList.d.ts +13 -0
- package/dist/types/ui/hooks.d.ts +7 -0
- package/dist/types/ui/layout/ImWorkspace.d.ts +8 -0
- package/dist/types/ui/layout/Layers.d.ts +19 -0
- package/dist/types/ui/layout/frame.d.ts +14 -0
- package/dist/types/ui/layout/useWide.d.ts +4 -0
- package/dist/types/ui/menu/Report.d.ts +7 -0
- package/dist/types/ui/navigator.d.ts +73 -0
- package/dist/types/ui/routes.d.ts +7 -0
- package/dist/types/ui/theme.d.ts +30 -0
- package/dist/types/ui/types.d.ts +44 -0
- package/dist/types/ui/viewer/ImageViewer.d.ts +6 -0
- package/dist/types/ui/viewer/VideoPlayer.d.ts +5 -0
- package/dist/types/ui/widgets/Avatar.d.ts +16 -0
- package/dist/types/ui/widgets/Icon.d.ts +32 -0
- package/dist/types/ui/widgets/Menu.d.ts +36 -0
- package/dist/types/ui/widgets/Page.d.ts +16 -0
- package/dist/types/ui/widgets/UnreadBadge.d.ts +11 -0
- package/dist/types/ui/widgets/feedback.d.ts +23 -0
- package/dist/types/ui/widgets/useFocusTrap.d.ts +2 -0
- package/package.json +54 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,3095 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
GuokitImUi: () => GuokitImUi,
|
|
25
|
+
ImAvatar: () => Avatar,
|
|
26
|
+
ImChat: () => ImChat,
|
|
27
|
+
ImConversationList: () => ImConversationList,
|
|
28
|
+
ImUnreadBadge: () => ImUnreadBadge,
|
|
29
|
+
ImWorkspace: () => ImWorkspace,
|
|
30
|
+
defaultStrings: () => defaultStrings,
|
|
31
|
+
useConnection: () => useConnection,
|
|
32
|
+
useConversations: () => useConversations,
|
|
33
|
+
useIm: () => useIm,
|
|
34
|
+
useImNavigator: () => useImNavigator,
|
|
35
|
+
useTotalUnread: () => useTotalUnread
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// src/ui/context.tsx
|
|
40
|
+
var import_react19 = require("react");
|
|
41
|
+
|
|
42
|
+
// src/core/strings.ts
|
|
43
|
+
var defaultStrings = {
|
|
44
|
+
conversationsTitle: "消息",
|
|
45
|
+
markAllRead: "全部已读",
|
|
46
|
+
disconnected: "网络连接已断开,正在重连…",
|
|
47
|
+
emptyConversations: "暂无消息",
|
|
48
|
+
groupChat: "群聊",
|
|
49
|
+
atMe: "[有人@我] ",
|
|
50
|
+
pin: "置顶",
|
|
51
|
+
unpin: "取消置顶",
|
|
52
|
+
mute: "消息免打扰",
|
|
53
|
+
unmute: "取消免打扰",
|
|
54
|
+
deleteConversation: "删除会话",
|
|
55
|
+
deleteConversationConfirm: "删除后,聊天记录将从本设备移除。",
|
|
56
|
+
cancel: "取消",
|
|
57
|
+
confirm: "确定",
|
|
58
|
+
yesterday: "昨天",
|
|
59
|
+
weekdays: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
|
|
60
|
+
operationFailed: "操作失败",
|
|
61
|
+
typing: "对方正在输入…",
|
|
62
|
+
notInGroup: "你已不在群聊中",
|
|
63
|
+
read: "已读",
|
|
64
|
+
unreadMark: "未读",
|
|
65
|
+
aiGenerated: "AI 生成",
|
|
66
|
+
send: "发送",
|
|
67
|
+
sendRejected: "消息未能发出",
|
|
68
|
+
you: "你",
|
|
69
|
+
peer: "对方",
|
|
70
|
+
admin: "管理员",
|
|
71
|
+
system: "系统",
|
|
72
|
+
recalled: "{name}撤回了一条消息",
|
|
73
|
+
image: "[图片]",
|
|
74
|
+
voice: "[语音]",
|
|
75
|
+
video: "[视频]",
|
|
76
|
+
file: "[文件]",
|
|
77
|
+
location: "[位置]",
|
|
78
|
+
unsupported: "[暂不支持的消息]",
|
|
79
|
+
tipCreate: "{op}创建了群聊",
|
|
80
|
+
tipJoin: "{op}邀请{targets}加入了群聊",
|
|
81
|
+
tipQuit: "{targets}退出了群聊",
|
|
82
|
+
tipKick: "{op}将{targets}移出了群聊",
|
|
83
|
+
tipDismiss: "群聊已解散",
|
|
84
|
+
tipUpdate: "{op}修改了群资料",
|
|
85
|
+
tipRename: "{op}将群名改为「{name}」",
|
|
86
|
+
tipNotice: "{op}更新了群公告",
|
|
87
|
+
tipAdminOn: "{targets}成为管理员",
|
|
88
|
+
tipAdminOff: "{targets}不再是管理员",
|
|
89
|
+
tipTransfer: "{targets}成为新群主",
|
|
90
|
+
tipMute: "{targets}被禁言",
|
|
91
|
+
tipUnmute: "{targets}被解除禁言",
|
|
92
|
+
tipOther: "[群通知]",
|
|
93
|
+
mentionTitle: "选择提醒的人",
|
|
94
|
+
search: "搜索",
|
|
95
|
+
atAll: "所有人",
|
|
96
|
+
emoji: "表情",
|
|
97
|
+
keyboard: "键盘",
|
|
98
|
+
more: "更多",
|
|
99
|
+
cardKinds: { "order": "订单", "product": "商品", "service": "服务", "article": "文章", "page": "页面", "ticket": "工单" },
|
|
100
|
+
cardKindOther: "链接",
|
|
101
|
+
album: "相册",
|
|
102
|
+
camera: "拍摄",
|
|
103
|
+
fileItem: "文件",
|
|
104
|
+
holdToTalk: "按住 说话",
|
|
105
|
+
releaseToSend: "松开 发送",
|
|
106
|
+
slideUpToCancel: "手指上滑,取消发送",
|
|
107
|
+
releaseToCancel: "松开手指,取消发送",
|
|
108
|
+
tooShort: "说话时间太短",
|
|
109
|
+
noMicPermission: "没有麦克风权限",
|
|
110
|
+
voiceInput: "语音输入",
|
|
111
|
+
fileTooLarge: "文件过大,最大 {mb} MB",
|
|
112
|
+
videoUnreadable: "读不了这个视频",
|
|
113
|
+
copy: "复制",
|
|
114
|
+
copied: "已复制",
|
|
115
|
+
recall: "撤回",
|
|
116
|
+
report: "举报",
|
|
117
|
+
reportReasons: { "porn": "色情低俗", "fraud": "诈骗", "harass": "骚扰辱骂", "ad": "广告营销", "illegal": "违法违规", "other": "其他" },
|
|
118
|
+
alsoBlock: "同时拉黑对方",
|
|
119
|
+
submit: "提交",
|
|
120
|
+
reported: "已提交,我们会尽快处理",
|
|
121
|
+
reportDuplicated: "已有一条待处理的举报",
|
|
122
|
+
// B 期:通用
|
|
123
|
+
done: "完成",
|
|
124
|
+
indexBar: "字母索引",
|
|
125
|
+
unknownUser: "用户 {id}",
|
|
126
|
+
rateLimited: "操作过于频繁,请稍后再试",
|
|
127
|
+
// B 期:会话列表「+」菜单
|
|
128
|
+
startGroupChat: "发起群聊",
|
|
129
|
+
addFriend: "添加朋友",
|
|
130
|
+
// B 期:通讯录
|
|
131
|
+
contactsTitle: "通讯录",
|
|
132
|
+
contactsSearchHint: "搜索备注或昵称",
|
|
133
|
+
newFriends: "新的朋友",
|
|
134
|
+
groupChats: "群聊",
|
|
135
|
+
blocklist: "黑名单",
|
|
136
|
+
allFriends: "全部",
|
|
137
|
+
emptyContacts: "还没有好友",
|
|
138
|
+
emptyGroupChats: "暂无群聊",
|
|
139
|
+
// B 期:新的朋友
|
|
140
|
+
requestsIn: "收到的",
|
|
141
|
+
requestsOut: "发出的",
|
|
142
|
+
accept: "同意",
|
|
143
|
+
reject: "拒绝",
|
|
144
|
+
requestPending: "等待验证",
|
|
145
|
+
requestAccepted: "已添加",
|
|
146
|
+
requestRejected: "已拒绝",
|
|
147
|
+
requestExpired: "已过期",
|
|
148
|
+
requestsTip: "超过 30 天未处理的申请自动过期;拒绝不会通知对方",
|
|
149
|
+
emptyRequests: "暂无申请",
|
|
150
|
+
// B 期:添加朋友
|
|
151
|
+
addFriendHint: "账号或搜索号",
|
|
152
|
+
addFriendTip: "需要完整输入对方的账号或搜索号,不支持按昵称模糊查找",
|
|
153
|
+
matchedByUserId: "账号:{q}",
|
|
154
|
+
matchedBySearchKey: "搜索号:{q}",
|
|
155
|
+
view: "查看",
|
|
156
|
+
userNotFound: "没有找到该用户",
|
|
157
|
+
userNotFoundTip: "请确认账号或搜索号是否完整、正确",
|
|
158
|
+
searchSelf: "这是你自己",
|
|
159
|
+
// B 期:资料卡
|
|
160
|
+
userCardTitle: "资料卡",
|
|
161
|
+
nicknameLabel: "昵称:{name}",
|
|
162
|
+
accountLabel: "账号:{id}",
|
|
163
|
+
remarkAndGroups: "备注和分组",
|
|
164
|
+
friendSince: "成为好友",
|
|
165
|
+
sendMessage: "发消息",
|
|
166
|
+
blockUser: "加入黑名单",
|
|
167
|
+
blockConfirm: "对方不会收到通知。拉黑后对方发给你的消息会被拒收,也不能再申请加你为朋友。",
|
|
168
|
+
deleteFriend: "删除好友",
|
|
169
|
+
deleteFriendConfirm: "确定删除好友「{name}」?",
|
|
170
|
+
addToContacts: "添加到通讯录",
|
|
171
|
+
friendRequestTitle: "发送添加朋友申请",
|
|
172
|
+
friendRequestDefault: "我是{name}",
|
|
173
|
+
sendRequest: "发送申请",
|
|
174
|
+
requestSent: "申请已发送",
|
|
175
|
+
becameFriends: "已添加为好友",
|
|
176
|
+
addDenied: "对方不允许加好友",
|
|
177
|
+
addBlocked: "无法添加对方为好友",
|
|
178
|
+
// B 期:备注与分组
|
|
179
|
+
remark: "备注",
|
|
180
|
+
remarkTip: "昵称:{name}。备注只有你自己能看到,清空后显示昵称",
|
|
181
|
+
clearRemark: "清空备注",
|
|
182
|
+
friendGroupsMulti: "分组(可多选)",
|
|
183
|
+
manageFriendGroups: "管理分组",
|
|
184
|
+
newFriendGroup: "新建分组",
|
|
185
|
+
friendGroupName: "分组名称",
|
|
186
|
+
// B 期:分组管理
|
|
187
|
+
friendGroupsTitle: "好友分组",
|
|
188
|
+
friendGroupsTip: "拖动右侧把手调整顺序;删除分组不会删除组里的好友",
|
|
189
|
+
rename: "重命名",
|
|
190
|
+
deleteFriendGroup: "删除分组",
|
|
191
|
+
deleteFriendGroupConfirm: "删除分组「{name}」?组里的好友不会被删除。",
|
|
192
|
+
dragToSort: "拖动排序",
|
|
193
|
+
// B 期:群资料
|
|
194
|
+
groupInfoTitle: "群聊信息",
|
|
195
|
+
groupIdAndCount: "群号 {id} · {n} 人",
|
|
196
|
+
inviteMember: "邀请",
|
|
197
|
+
removeMember: "移出",
|
|
198
|
+
viewAllMembers: "查看全部 {n} 名成员",
|
|
199
|
+
groupNameLabel: "群聊名称",
|
|
200
|
+
groupNotice: "群公告",
|
|
201
|
+
notSet: "未设置",
|
|
202
|
+
pinChat: "置顶聊天",
|
|
203
|
+
groupManage: "群管理",
|
|
204
|
+
muteAll: "全员禁言",
|
|
205
|
+
muteAllTip: "开启后只有群主和管理员可以发言",
|
|
206
|
+
inviteAdminOnly: "仅群主和管理员可邀请",
|
|
207
|
+
groupAdmins: "群管理员",
|
|
208
|
+
peopleCount: "{n} 人",
|
|
209
|
+
transferOwner: "转让群主",
|
|
210
|
+
clearHistory: "清空聊天记录",
|
|
211
|
+
clearHistoryConfirm: "确定清空本群的聊天记录?",
|
|
212
|
+
quitGroup: "退出群聊",
|
|
213
|
+
quitGroupConfirm: "退出后,将不再接收此群聊的消息。",
|
|
214
|
+
ownerQuitTip: "群主要先转让群主,才能退出群聊",
|
|
215
|
+
dismissGroup: "解散群聊",
|
|
216
|
+
dismissGroupConfirm: "解散后,所有成员都无法再发言。",
|
|
217
|
+
roleOwner: "群主",
|
|
218
|
+
roleAdmin: "管理员",
|
|
219
|
+
roleMember: "成员",
|
|
220
|
+
// B 期:群成员
|
|
221
|
+
groupMembersTitle: "群成员",
|
|
222
|
+
searchMembers: "搜索群成员",
|
|
223
|
+
mutedRemaining: "禁言 · 还剩 {time}",
|
|
224
|
+
joinedAt: "{role} · {date} 进群",
|
|
225
|
+
viewProfile: "查看资料",
|
|
226
|
+
setAdmin: "设为管理员",
|
|
227
|
+
unsetAdmin: "取消管理员",
|
|
228
|
+
muteMember: "禁言",
|
|
229
|
+
unmuteMember: "解除禁言",
|
|
230
|
+
muteDurations: { 600: "10 分钟", 3600: "1 小时", 43200: "12 小时", 86400: "1 天", 604800: "7 天", 2592e3: "30 天" },
|
|
231
|
+
durationMinutes: "{n} 分钟",
|
|
232
|
+
durationHours: "{n} 小时",
|
|
233
|
+
durationDays: "{n} 天",
|
|
234
|
+
kickMember: "移出群聊",
|
|
235
|
+
kickConfirm: "确定将「{name}」移出群聊?",
|
|
236
|
+
transferTo: "转让群主给他",
|
|
237
|
+
transferConfirm: "确定将群主转让给「{name}」?转让后你将成为普通成员。",
|
|
238
|
+
// B 期:选择好友
|
|
239
|
+
selectFriendsTitle: "选择好友",
|
|
240
|
+
doneWithCount: "完成({n})",
|
|
241
|
+
searchFriends: "搜索好友",
|
|
242
|
+
alreadyInGroup: "已在群里",
|
|
243
|
+
inviteToGroup: "邀请进群",
|
|
244
|
+
skippedMembers: "{n} 人未能加入",
|
|
245
|
+
groupNameSeparator: "、",
|
|
246
|
+
// B 期:群公告
|
|
247
|
+
editNotice: "编辑",
|
|
248
|
+
publish: "发布",
|
|
249
|
+
noticePublishedAt: "{date} 发布",
|
|
250
|
+
noticeEditTip: "只有群主和管理员可以编辑",
|
|
251
|
+
noticeHint: "公告内容",
|
|
252
|
+
noticePublishTip: "发布后会在群里发一条提示",
|
|
253
|
+
emptyNotice: "暂无群公告",
|
|
254
|
+
// B 期:隐私与黑名单
|
|
255
|
+
privacyTitle: "隐私",
|
|
256
|
+
addMeWhen: "加我为朋友时",
|
|
257
|
+
addPolicyTitles: ["需要我验证", "允许任何人直接加我", "不允许任何人加我"],
|
|
258
|
+
addPolicyTips: ["对方发申请,我同意后成为朋友", "对方点「添加」后直接成为朋友", "对方能搜到我,但发不了申请"],
|
|
259
|
+
blocklistTip: "对方不会收到通知。拉黑后对方发给你的消息会被拒收,也不能再申请加你为朋友",
|
|
260
|
+
unblock: "移出",
|
|
261
|
+
blockedAt: "{date} 拉黑",
|
|
262
|
+
emptyBlocklist: "黑名单是空的",
|
|
263
|
+
// C 期:消息搜索与定位
|
|
264
|
+
searchContacts: "联系人",
|
|
265
|
+
searchGroups: "群聊",
|
|
266
|
+
searchMessagesTitle: "聊天记录",
|
|
267
|
+
searchMore: "查看更多",
|
|
268
|
+
searchRelated: "{n} 条相关聊天记录",
|
|
269
|
+
searchLoadMore: "继续加载",
|
|
270
|
+
searchNoResult: "没有找到相关结果",
|
|
271
|
+
searchFailed: "搜索失败,点击重试",
|
|
272
|
+
searchNoMore: "没有更多了",
|
|
273
|
+
findChatHistory: "查找聊天记录",
|
|
274
|
+
conversationGone: "会话已不存在",
|
|
275
|
+
backToLatest: "回到最新消息",
|
|
276
|
+
// C 期:客服会话
|
|
277
|
+
csTitle: "客服",
|
|
278
|
+
csBot: "智能助手接待中",
|
|
279
|
+
csHandoff: "转人工",
|
|
280
|
+
csQueued: "排队中,前面还有 {n} 位",
|
|
281
|
+
csQueuedNext: "排队中,马上为您接入",
|
|
282
|
+
csOffline: "暂无客服在线,可以先留下联系方式",
|
|
283
|
+
csOfflineWait: "暂无客服在线,请稍候",
|
|
284
|
+
csActive: "人工客服接待中",
|
|
285
|
+
csLeave: "留联系方式",
|
|
286
|
+
leaveTitle: "留下联系方式",
|
|
287
|
+
leaveTip: "客服上线后按您留的方式联系您。留言内容就是您刚才在会话里说的话,不用再填。",
|
|
288
|
+
leaveName: "称呼(选填)",
|
|
289
|
+
leavePhone: "手机号",
|
|
290
|
+
leaveEmail: "邮箱",
|
|
291
|
+
leaveOptional: "选填",
|
|
292
|
+
leaveContactTip: "手机号与邮箱至少填一项",
|
|
293
|
+
leaveDone: "已提交",
|
|
294
|
+
ratingTitle: "请对本次服务进行评价",
|
|
295
|
+
ratingLevels: ["非常不满意", "不满意", "一般", "满意", "非常满意"],
|
|
296
|
+
ratingScore: "{n} 星 · {label}",
|
|
297
|
+
ratingComment: "说说您的感受(选填)",
|
|
298
|
+
ratingCommentHint: "200 字以内",
|
|
299
|
+
ratingSubmit: "提交评价",
|
|
300
|
+
ratingDone: "已评价,感谢您的反馈",
|
|
301
|
+
back: "返回",
|
|
302
|
+
close: "关闭",
|
|
303
|
+
inputPlaceholder: "发消息…",
|
|
304
|
+
enterToSend: "Enter 发送,Shift+Enter 换行",
|
|
305
|
+
dropToSend: "松开即可发送给 {name}",
|
|
306
|
+
removeAttachment: "移除",
|
|
307
|
+
sendImageOrVideo: "发送图片或视频",
|
|
308
|
+
sendFile: "发送文件",
|
|
309
|
+
zoomIn: "放大",
|
|
310
|
+
zoomOut: "缩小",
|
|
311
|
+
prevImage: "上一张",
|
|
312
|
+
nextImage: "下一张",
|
|
313
|
+
openOriginal: "在新标签页打开原图",
|
|
314
|
+
navMessages: "消息",
|
|
315
|
+
selectConversation: "选择一个会话开始聊天",
|
|
316
|
+
fileNotAllowed: "站点未开放发送这类文件",
|
|
317
|
+
imageIndex: "{n} / {total}"
|
|
318
|
+
};
|
|
319
|
+
function mergeStrings(over) {
|
|
320
|
+
return over ? { ...defaultStrings, ...over } : defaultStrings;
|
|
321
|
+
}
|
|
322
|
+
function fill(template, vars) {
|
|
323
|
+
return template.replace(/\{(\w+)\}/g, (m, k) => k in vars ? String(vars[k]) : m);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// src/ui/navigator.ts
|
|
327
|
+
var import_react = require("react");
|
|
328
|
+
var routePlacement = {
|
|
329
|
+
conversations: "list",
|
|
330
|
+
chat: "main",
|
|
331
|
+
report: "dialog",
|
|
332
|
+
imageViewer: "overlay",
|
|
333
|
+
videoPlayer: "overlay"
|
|
334
|
+
};
|
|
335
|
+
var initialNav = { list: { name: "conversations" }, main: null, drawer: [], dialog: [], overlay: [] };
|
|
336
|
+
function navReducer(s, a) {
|
|
337
|
+
switch (a.type) {
|
|
338
|
+
case "open": {
|
|
339
|
+
const p = routePlacement[a.route.name];
|
|
340
|
+
if (p === "list") return { ...s, list: a.route, drawer: [], dialog: [] };
|
|
341
|
+
if (p === "main") return { ...s, main: a.route, drawer: [], dialog: [] };
|
|
342
|
+
if (p === "drawer") return { ...s, drawer: [...s.drawer, a.route] };
|
|
343
|
+
if (p === "dialog") return { ...s, dialog: [...s.dialog, a.route] };
|
|
344
|
+
return { ...s, overlay: [...s.overlay, a.route] };
|
|
345
|
+
}
|
|
346
|
+
case "back":
|
|
347
|
+
if (s.overlay.length) return { ...s, overlay: s.overlay.slice(0, -1) };
|
|
348
|
+
if (s.dialog.length) return { ...s, dialog: s.dialog.slice(0, -1) };
|
|
349
|
+
if (s.drawer.length) return { ...s, drawer: s.drawer.slice(0, -1) };
|
|
350
|
+
if (s.main) return { ...s, main: null };
|
|
351
|
+
return s;
|
|
352
|
+
case "close":
|
|
353
|
+
return { ...s, drawer: [], dialog: [], overlay: [] };
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function topRoute(s) {
|
|
357
|
+
return s.overlay.at(-1) ?? s.dialog.at(-1) ?? s.drawer.at(-1) ?? s.main ?? null;
|
|
358
|
+
}
|
|
359
|
+
var NavContext = (0, import_react.createContext)(null);
|
|
360
|
+
function useNavState(workspace, onMainOrList) {
|
|
361
|
+
const [state, dispatch] = (0, import_react.useReducer)(navReducer, initialNav);
|
|
362
|
+
const open = (0, import_react.useCallback)((route) => {
|
|
363
|
+
const p = routePlacement[route.name];
|
|
364
|
+
if (!workspace && (p === "main" || p === "list")) {
|
|
365
|
+
onMainOrList?.(route);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
dispatch({ type: "open", route });
|
|
369
|
+
}, [workspace, onMainOrList]);
|
|
370
|
+
const back = (0, import_react.useCallback)(() => dispatch({ type: "back" }), []);
|
|
371
|
+
const close = (0, import_react.useCallback)(() => dispatch({ type: "close" }), []);
|
|
372
|
+
return (0, import_react.useMemo)(() => ({ state, open, back, close, workspace }), [state, open, back, close, workspace]);
|
|
373
|
+
}
|
|
374
|
+
function useNavContext() {
|
|
375
|
+
const nav = (0, import_react.useContext)(NavContext);
|
|
376
|
+
if (!nav) throw new Error("没有找到 GuokitImUi:IM 组件要放在 GuokitImUi 下面。");
|
|
377
|
+
return nav;
|
|
378
|
+
}
|
|
379
|
+
function useImNavigator() {
|
|
380
|
+
return useNavContext();
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// src/ui/theme.ts
|
|
384
|
+
var px = (v) => typeof v === "number" ? `${v}px` : v;
|
|
385
|
+
var radius = (s) => s === "circle" ? "50%" : "25%";
|
|
386
|
+
function themeVars(t) {
|
|
387
|
+
const v = {};
|
|
388
|
+
if (!t) return v;
|
|
389
|
+
if (t.accent) v["--gkim-accent"] = t.accent;
|
|
390
|
+
if (t.selfBubble) v["--gkim-bubble-self-bg"] = t.selfBubble;
|
|
391
|
+
if (t.selfBubbleText) v["--gkim-bubble-self-fg"] = t.selfBubbleText;
|
|
392
|
+
if (t.peerBubble) v["--gkim-bubble-peer-bg"] = t.peerBubble;
|
|
393
|
+
if (t.peerBubbleText) v["--gkim-bubble-peer-fg"] = t.peerBubbleText;
|
|
394
|
+
if (t.bubbleRadius != null) v["--gkim-bubble-radius"] = px(t.bubbleRadius);
|
|
395
|
+
if (t.avatarShape) v["--gkim-avatar-radius"] = radius(t.avatarShape);
|
|
396
|
+
if (t.groupAvatarShape) v["--gkim-group-avatar-radius"] = radius(t.groupAvatarShape);
|
|
397
|
+
if (t.avatarSize != null) v["--gkim-avatar-size"] = px(t.avatarSize);
|
|
398
|
+
if (t.chatBackground) v["--gkim-chat-bg"] = t.chatBackground;
|
|
399
|
+
if (t.timeDividerSize != null) v["--gkim-time-divider-size"] = px(t.timeDividerSize);
|
|
400
|
+
return v;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// src/ui/layout/Layers.tsx
|
|
404
|
+
var import_react18 = require("react");
|
|
405
|
+
|
|
406
|
+
// src/ui/chat/ChatPage.tsx
|
|
407
|
+
var import_react12 = require("react");
|
|
408
|
+
var import_im2 = require("@guokit-dev/im");
|
|
409
|
+
|
|
410
|
+
// src/core/externalStore.ts
|
|
411
|
+
var ListenerSet = class {
|
|
412
|
+
constructor(onFirst, onLast) {
|
|
413
|
+
this.onFirst = onFirst;
|
|
414
|
+
this.onLast = onLast;
|
|
415
|
+
this.entries = /* @__PURE__ */ new Set();
|
|
416
|
+
}
|
|
417
|
+
get size() {
|
|
418
|
+
return this.entries.size;
|
|
419
|
+
}
|
|
420
|
+
add(fn) {
|
|
421
|
+
if (this.entries.size === 0) this.onFirst?.();
|
|
422
|
+
const entry = { fn };
|
|
423
|
+
this.entries.add(entry);
|
|
424
|
+
return () => {
|
|
425
|
+
if (!this.entries.delete(entry)) return;
|
|
426
|
+
if (this.entries.size === 0) this.onLast?.();
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
notify() {
|
|
430
|
+
for (const e of [...this.entries]) e.fn();
|
|
431
|
+
}
|
|
432
|
+
/** 丢掉全部订阅者,不调 onLast(销毁时用,调用方自己收尾)。 */
|
|
433
|
+
clear() {
|
|
434
|
+
this.entries.clear();
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
// src/core/features.ts
|
|
439
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
440
|
+
function cachedFeatures(im) {
|
|
441
|
+
const me = im.currentUserId;
|
|
442
|
+
if (me === null) return Promise.reject(new Error("未登录"));
|
|
443
|
+
const hit = cache.get(im);
|
|
444
|
+
if (hit && hit.userId === me) return hit.promise;
|
|
445
|
+
let promise;
|
|
446
|
+
try {
|
|
447
|
+
promise = im.features();
|
|
448
|
+
} catch (e) {
|
|
449
|
+
return Promise.reject(e);
|
|
450
|
+
}
|
|
451
|
+
const entry = { userId: me, promise };
|
|
452
|
+
cache.set(im, entry);
|
|
453
|
+
promise.catch(() => {
|
|
454
|
+
if (cache.get(im) === entry) cache.delete(im);
|
|
455
|
+
});
|
|
456
|
+
return promise;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// src/core/chatController.ts
|
|
460
|
+
var _ChatController = class _ChatController {
|
|
461
|
+
constructor(im, target) {
|
|
462
|
+
this.im = im;
|
|
463
|
+
this.byClient = /* @__PURE__ */ new Map();
|
|
464
|
+
this.sorted = null;
|
|
465
|
+
this.snap = null;
|
|
466
|
+
this.offs = [];
|
|
467
|
+
this.listeners = new ListenerSet();
|
|
468
|
+
this.newListeners = /* @__PURE__ */ new Set();
|
|
469
|
+
this.started = false;
|
|
470
|
+
this.disposed = false;
|
|
471
|
+
this.historyLoaded = false;
|
|
472
|
+
this.active = true;
|
|
473
|
+
this.loading = true;
|
|
474
|
+
this.loadingMore = false;
|
|
475
|
+
this.hasMore = true;
|
|
476
|
+
this.peerTyping = false;
|
|
477
|
+
this.features = null;
|
|
478
|
+
this.progress = {};
|
|
479
|
+
this.localFiles = {};
|
|
480
|
+
/** 发出去、还没从 messageUpdated 认领到 clientMsgId 的图片,按调用顺序。 */
|
|
481
|
+
this.awaiting = [];
|
|
482
|
+
// ---------------- 订阅 ----------------
|
|
483
|
+
this.subscribe = (fn) => this.listeners.add(fn);
|
|
484
|
+
this.getSnapshot = () => this.snap ?? (this.snap = this.buildSnapshot());
|
|
485
|
+
let peerId = null;
|
|
486
|
+
let groupId = null;
|
|
487
|
+
let conv = null;
|
|
488
|
+
if ("conversation" in target) {
|
|
489
|
+
conv = target.conversation;
|
|
490
|
+
groupId = conv?.group?.groupId ?? null;
|
|
491
|
+
peerId = groupId === null ? conv?.peer?.userId ?? null : null;
|
|
492
|
+
} else if ("group" in target) {
|
|
493
|
+
groupId = target.group;
|
|
494
|
+
} else {
|
|
495
|
+
peerId = target.peer;
|
|
496
|
+
}
|
|
497
|
+
if (!peerId && !groupId) throw new TypeError("聊天对象不能为空:peer、group 须为非空字符串,conversation 须有 peer 或 group");
|
|
498
|
+
this.peerId = peerId;
|
|
499
|
+
this.groupId = groupId;
|
|
500
|
+
this.conv = conv;
|
|
501
|
+
}
|
|
502
|
+
get isGroup() {
|
|
503
|
+
return this.groupId !== null;
|
|
504
|
+
}
|
|
505
|
+
get conversationId() {
|
|
506
|
+
return this.conv?.id ?? null;
|
|
507
|
+
}
|
|
508
|
+
/** `send*` 的目标参数。 */
|
|
509
|
+
get sendTarget() {
|
|
510
|
+
return this.groupId !== null ? { groupId: this.groupId } : this.peerId;
|
|
511
|
+
}
|
|
512
|
+
get target() {
|
|
513
|
+
return { peerId: this.peerId, groupId: this.groupId, conversationId: this.conversationId, to: this.peerId ?? "" };
|
|
514
|
+
}
|
|
515
|
+
/** 有新消息进来(对方的、或本人在别的设备发的);页面据此决定是否滚到底。返回取消函数。 */
|
|
516
|
+
onNewMessage(fn) {
|
|
517
|
+
this.newListeners.add(fn);
|
|
518
|
+
return () => void this.newListeners.delete(fn);
|
|
519
|
+
}
|
|
520
|
+
buildSnapshot() {
|
|
521
|
+
const c = this.conv;
|
|
522
|
+
return {
|
|
523
|
+
messages: this.sorted ?? (this.sorted = [...this.byClient.values()].sort(compare)),
|
|
524
|
+
loading: this.loading,
|
|
525
|
+
loadingMore: this.loadingMore,
|
|
526
|
+
hasMore: this.hasMore,
|
|
527
|
+
peerTyping: this.peerTyping,
|
|
528
|
+
conversation: c,
|
|
529
|
+
conversationId: c?.id ?? null,
|
|
530
|
+
quit: c?.group?.quit ?? false,
|
|
531
|
+
peerReadSeq: this.isGroup || c?.type === "service" ? null : c?.peerReadSeq ?? null,
|
|
532
|
+
features: this.features,
|
|
533
|
+
progress: this.progress,
|
|
534
|
+
localFiles: this.localFiles
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
notify() {
|
|
538
|
+
if (this.disposed) return;
|
|
539
|
+
this.snap = null;
|
|
540
|
+
this.listeners.notify();
|
|
541
|
+
}
|
|
542
|
+
// ---------------- 加载 ----------------
|
|
543
|
+
/** 挂上 SDK 事件并加载首屏。重复调用无效。 */
|
|
544
|
+
async start() {
|
|
545
|
+
if (this.started || this.disposed) return;
|
|
546
|
+
this.started = true;
|
|
547
|
+
const im = this.im;
|
|
548
|
+
this.offs.push(
|
|
549
|
+
im.on("newMessage", (m) => this.onMessage(m, true)),
|
|
550
|
+
im.on("messageUpdated", (m) => this.onMessage(m, false)),
|
|
551
|
+
im.on("conversations", (list) => this.onConversations(list)),
|
|
552
|
+
im.on("sendProgress", (p) => {
|
|
553
|
+
if (!this.byClient.has(p.clientMsgId)) return;
|
|
554
|
+
this.progress = { ...this.progress, [p.clientMsgId]: p.total > 0 ? p.sent / p.total : null };
|
|
555
|
+
this.notify();
|
|
556
|
+
}),
|
|
557
|
+
im.on("typing", (t) => {
|
|
558
|
+
if (!this.isGroup && t.conversationId === this.conversationId && this.peerTyping !== t.active) {
|
|
559
|
+
this.peerTyping = t.active;
|
|
560
|
+
this.notify();
|
|
561
|
+
}
|
|
562
|
+
})
|
|
563
|
+
);
|
|
564
|
+
cachedFeatures(im).then(
|
|
565
|
+
(f) => {
|
|
566
|
+
this.features = f;
|
|
567
|
+
this.notify();
|
|
568
|
+
},
|
|
569
|
+
() => {
|
|
570
|
+
}
|
|
571
|
+
);
|
|
572
|
+
try {
|
|
573
|
+
this.conv ?? (this.conv = this.isGroup ? im.conversationWithGroup(this.groupId) : im.conversationWith(this.peerId));
|
|
574
|
+
if (this.conv === null) {
|
|
575
|
+
this.merge(this.isGroup ? im.pendingToGroup(this.groupId) : im.pendingTo(this.peerId));
|
|
576
|
+
this.hasMore = false;
|
|
577
|
+
} else {
|
|
578
|
+
await this.loadLatest();
|
|
579
|
+
}
|
|
580
|
+
} catch {
|
|
581
|
+
this.hasMore = false;
|
|
582
|
+
}
|
|
583
|
+
if (this.disposed) return;
|
|
584
|
+
this.loading = false;
|
|
585
|
+
this.notify();
|
|
586
|
+
}
|
|
587
|
+
async loadLatest() {
|
|
588
|
+
const id = this.conversationId;
|
|
589
|
+
this.historyLoaded = true;
|
|
590
|
+
const list = await this.im.messages(id, { limit: _ChatController.pageSize });
|
|
591
|
+
if (this.disposed) return;
|
|
592
|
+
this.merge(list);
|
|
593
|
+
this.hasMore = list.filter((m) => m.seq !== null).length >= _ChatController.pageSize;
|
|
594
|
+
this.markRead();
|
|
595
|
+
}
|
|
596
|
+
/** 滚到顶时调:用最早一条**已确认**的消息作 before 再取一页。失败留着 hasMore,下次再试。 */
|
|
597
|
+
async loadMore() {
|
|
598
|
+
const id = this.conversationId;
|
|
599
|
+
if (this.loadingMore || !this.hasMore || id === null || this.disposed) return;
|
|
600
|
+
const first = this.getSnapshot().messages.find((m) => m.seq !== null);
|
|
601
|
+
if (!first) {
|
|
602
|
+
this.hasMore = false;
|
|
603
|
+
this.notify();
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
this.loadingMore = true;
|
|
607
|
+
this.notify();
|
|
608
|
+
try {
|
|
609
|
+
const list = await this.im.messages(id, { before: first, limit: _ChatController.pageSize });
|
|
610
|
+
if (this.disposed) return;
|
|
611
|
+
this.merge(list);
|
|
612
|
+
this.hasMore = list.length >= _ChatController.pageSize;
|
|
613
|
+
} catch {
|
|
614
|
+
}
|
|
615
|
+
this.loadingMore = false;
|
|
616
|
+
this.notify();
|
|
617
|
+
}
|
|
618
|
+
// ---------------- 事件 ----------------
|
|
619
|
+
belongs(m) {
|
|
620
|
+
const id = this.conversationId;
|
|
621
|
+
if (id !== null && m.conversationId === id) return true;
|
|
622
|
+
if (this.groupId !== null) return m.groupId !== null && m.groupId.toLowerCase() === this.groupId.toLowerCase();
|
|
623
|
+
return m.groupId === null && (m.from === this.peerId || m.to === this.peerId);
|
|
624
|
+
}
|
|
625
|
+
onMessage(m, fresh) {
|
|
626
|
+
if (this.disposed || !this.belongs(m)) return;
|
|
627
|
+
const cid = m.clientMsgId;
|
|
628
|
+
if (m.status !== "sending" && cid in this.progress) {
|
|
629
|
+
const rest = { ...this.progress };
|
|
630
|
+
delete rest[cid];
|
|
631
|
+
this.progress = rest;
|
|
632
|
+
}
|
|
633
|
+
if (m.isSelf && m.type === "image" && m.status === "sending" && !(cid in this.localFiles) && this.awaiting.length) {
|
|
634
|
+
this.localFiles = { ...this.localFiles, [cid]: this.awaiting.shift() };
|
|
635
|
+
}
|
|
636
|
+
this.merge([m]);
|
|
637
|
+
this.adopt(m.conversationId);
|
|
638
|
+
if (fresh) {
|
|
639
|
+
if (!m.isSelf) this.peerTyping = false;
|
|
640
|
+
this.markRead();
|
|
641
|
+
}
|
|
642
|
+
this.notify();
|
|
643
|
+
if (fresh) for (const fn of [...this.newListeners]) fn(m);
|
|
644
|
+
}
|
|
645
|
+
/** 还没有会话时,首条消息发送成功后从消息里拿会话 id,再拉历史、标已读。 */
|
|
646
|
+
adopt(id) {
|
|
647
|
+
if (id === null || this.conversationId !== null) return;
|
|
648
|
+
let c = null;
|
|
649
|
+
try {
|
|
650
|
+
c = this.isGroup ? this.im.conversationWithGroup(this.groupId) : this.im.conversationWith(this.peerId);
|
|
651
|
+
} catch {
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
if (!c || c.id !== id) return;
|
|
655
|
+
this.conv = c;
|
|
656
|
+
if (!this.historyLoaded) this.loadLatest().then(() => this.notify(), () => {
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
onConversations(list) {
|
|
660
|
+
const id = this.conversationId;
|
|
661
|
+
const gid = this.groupId?.toLowerCase();
|
|
662
|
+
for (const c of list) {
|
|
663
|
+
const hit = id !== null ? c.id === id : gid !== void 0 ? c.group?.groupId.toLowerCase() === gid : c.group === null && c.peer?.userId === this.peerId;
|
|
664
|
+
if (!hit) continue;
|
|
665
|
+
if (c === this.conv) return;
|
|
666
|
+
const first = this.conv === null;
|
|
667
|
+
this.conv = c;
|
|
668
|
+
if (first && !this.historyLoaded && !this.loading) this.loadLatest().then(() => this.notify(), () => {
|
|
669
|
+
});
|
|
670
|
+
this.notify();
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
merge(list) {
|
|
675
|
+
for (const m of list) this.byClient.set(m.clientMsgId, m);
|
|
676
|
+
this.sorted = null;
|
|
677
|
+
}
|
|
678
|
+
markRead() {
|
|
679
|
+
const id = this.conversationId;
|
|
680
|
+
if (id === null || !this.active || this.disposed) return;
|
|
681
|
+
try {
|
|
682
|
+
this.im.markRead(id).catch(() => {
|
|
683
|
+
});
|
|
684
|
+
} catch {
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
/** 页面前后台切换时调(如 visibilitychange);回到前台补一次已读。 */
|
|
688
|
+
setActive(active) {
|
|
689
|
+
this.active = active;
|
|
690
|
+
if (active) this.markRead();
|
|
691
|
+
}
|
|
692
|
+
/** 单聊输入变化时调(SDK 按 3 秒节流);群聊服务端不支持,不发。 */
|
|
693
|
+
typing() {
|
|
694
|
+
const id = this.conversationId;
|
|
695
|
+
if (this.isGroup || id === null) return;
|
|
696
|
+
try {
|
|
697
|
+
this.im.sendTyping(id).catch(() => {
|
|
698
|
+
});
|
|
699
|
+
} catch {
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
// ---------------- 发送 ----------------
|
|
703
|
+
//
|
|
704
|
+
// 发送失败不抛,看返回消息的 status(failed 可 resend,rejected 只显示原因)与 errorCode。
|
|
705
|
+
// 参数不对、未登录时 SDK 同步抛,这里变成 rejected Promise。
|
|
706
|
+
track(m) {
|
|
707
|
+
this.onMessage(m, false);
|
|
708
|
+
return m;
|
|
709
|
+
}
|
|
710
|
+
/** 发文字;at 只在群里有效(`@all` 为所有人)。 */
|
|
711
|
+
async sendText(text, at) {
|
|
712
|
+
const opts = at && at.length ? { at: [...at] } : {};
|
|
713
|
+
return this.track(await this.im.sendText(this.sendTarget, text, opts));
|
|
714
|
+
}
|
|
715
|
+
/** 发图(JPEG / PNG / GIF / WebP);原文件留在快照 `localFiles` 里做预览。 */
|
|
716
|
+
async sendImage(file) {
|
|
717
|
+
this.awaiting.push(file);
|
|
718
|
+
let m;
|
|
719
|
+
try {
|
|
720
|
+
m = await this.im.sendImage(this.sendTarget, file);
|
|
721
|
+
} finally {
|
|
722
|
+
const i = this.awaiting.indexOf(file);
|
|
723
|
+
if (i >= 0) this.awaiting.splice(i, 1);
|
|
724
|
+
}
|
|
725
|
+
if (!(m.clientMsgId in this.localFiles)) this.localFiles = { ...this.localFiles, [m.clientMsgId]: file };
|
|
726
|
+
return this.track(m);
|
|
727
|
+
}
|
|
728
|
+
/** 发视频(mp4 / mov);时长与宽高必填(用 media 的 readVideoMeta 读),越界 SDK 抛 RangeError。 */
|
|
729
|
+
async sendVideo(file, meta) {
|
|
730
|
+
const { durationMs, width, height } = meta;
|
|
731
|
+
return this.track(await this.im.sendVideo(this.sendTarget, file, { durationMs, width, height }));
|
|
732
|
+
}
|
|
733
|
+
/** 发文件;name 不传取 File.name(要带扩展名)。 */
|
|
734
|
+
async sendFile(file, name) {
|
|
735
|
+
return this.track(await this.im.sendFile(this.sendTarget, file, name ? { name } : {}));
|
|
736
|
+
}
|
|
737
|
+
/** 重发 failed 的消息;rejected 等其他状态不调 SDK,直接 reject。 */
|
|
738
|
+
async resend(m) {
|
|
739
|
+
if (m.status !== "failed") throw new TypeError("只能重发 failed 的消息");
|
|
740
|
+
return this.track(await this.im.resend(m));
|
|
741
|
+
}
|
|
742
|
+
/** 撤回自己发的一条;没开启、超时限抛 ImApiError(直接显示 message)。成功后列表随 messageUpdated 更新。 */
|
|
743
|
+
async recall(m) {
|
|
744
|
+
await this.im.recall(m);
|
|
745
|
+
}
|
|
746
|
+
dispose() {
|
|
747
|
+
if (this.disposed) return;
|
|
748
|
+
this.disposed = true;
|
|
749
|
+
this.offs.forEach((f) => f());
|
|
750
|
+
this.offs = [];
|
|
751
|
+
this.listeners.clear();
|
|
752
|
+
this.newListeners.clear();
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
_ChatController.pageSize = 30;
|
|
756
|
+
var ChatController = _ChatController;
|
|
757
|
+
function compare(a, b) {
|
|
758
|
+
const sa = a.seq;
|
|
759
|
+
const sb = b.seq;
|
|
760
|
+
if (sa !== null && sb !== null) return sa - sb;
|
|
761
|
+
if (sa !== null) return -1;
|
|
762
|
+
if (sb !== null) return 1;
|
|
763
|
+
return a.createdAt - b.createdAt;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// src/core/format.ts
|
|
767
|
+
function conversationTitle(c, s) {
|
|
768
|
+
const g = c.group;
|
|
769
|
+
if (g) return g.name !== "" ? g.name : s.groupChat;
|
|
770
|
+
const p = c.peer;
|
|
771
|
+
if (!p) return "";
|
|
772
|
+
if (p.remark !== "") return p.remark;
|
|
773
|
+
if (p.nickname !== "") return p.nickname;
|
|
774
|
+
return p.userId;
|
|
775
|
+
}
|
|
776
|
+
function conversationSummary(c, s) {
|
|
777
|
+
return { atMe: c.atMe && c.unread > 0 ? s.atMe : "", text: c.lastMessage?.preview ?? "" };
|
|
778
|
+
}
|
|
779
|
+
var two = (n) => String(n).padStart(2, "0");
|
|
780
|
+
var DAY = 864e5;
|
|
781
|
+
function startOfDay(d) {
|
|
782
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
|
783
|
+
}
|
|
784
|
+
function formatConversationTime(time, s, now = Date.now()) {
|
|
785
|
+
const t = new Date(time);
|
|
786
|
+
const n = new Date(now);
|
|
787
|
+
const diff = Math.round((startOfDay(n) - startOfDay(t)) / DAY);
|
|
788
|
+
if (diff <= 0) return `${two(t.getHours())}:${two(t.getMinutes())}`;
|
|
789
|
+
if (diff === 1) return s.yesterday;
|
|
790
|
+
if (diff < 7) return s.weekdays[(t.getDay() + 6) % 7];
|
|
791
|
+
if (t.getFullYear() === n.getFullYear()) return `${t.getMonth() + 1}/${t.getDate()}`;
|
|
792
|
+
return `${t.getFullYear()}/${t.getMonth() + 1}/${t.getDate()}`;
|
|
793
|
+
}
|
|
794
|
+
function formatMessageTime(time, s, now = Date.now()) {
|
|
795
|
+
const t = new Date(time);
|
|
796
|
+
const hm = `${two(t.getHours())}:${two(t.getMinutes())}`;
|
|
797
|
+
const day = formatConversationTime(time, s, now);
|
|
798
|
+
return day === hm ? hm : `${day} ${hm}`;
|
|
799
|
+
}
|
|
800
|
+
function isTipMessage(m) {
|
|
801
|
+
return m.isRecalled || m.type === "group_tip" || m.from === "@system";
|
|
802
|
+
}
|
|
803
|
+
function tipText(m, s, opts) {
|
|
804
|
+
const { nameOf, me, isGroup } = opts;
|
|
805
|
+
const c = m.content ?? {};
|
|
806
|
+
const snap = c.names;
|
|
807
|
+
const who = (id) => {
|
|
808
|
+
if (id === "@system") return s.system;
|
|
809
|
+
if (id === me) return s.you;
|
|
810
|
+
const n = nameOf(id);
|
|
811
|
+
if (n !== id) return n;
|
|
812
|
+
const v = snap && typeof snap === "object" && !Array.isArray(snap) ? snap[id] : null;
|
|
813
|
+
return typeof v === "string" && v !== "" ? v : id;
|
|
814
|
+
};
|
|
815
|
+
if (m.isRecalled) {
|
|
816
|
+
let name;
|
|
817
|
+
switch (m.recalledBy) {
|
|
818
|
+
case "agent":
|
|
819
|
+
case "server":
|
|
820
|
+
case "admin":
|
|
821
|
+
name = s.admin;
|
|
822
|
+
break;
|
|
823
|
+
default:
|
|
824
|
+
name = m.isSelf ? s.you : isGroup ? nameOf(m.from) : s.peer;
|
|
825
|
+
}
|
|
826
|
+
return fill(s.recalled, { name });
|
|
827
|
+
}
|
|
828
|
+
if (m.type !== "group_tip") {
|
|
829
|
+
const t = c.text;
|
|
830
|
+
return typeof t === "string" && t !== "" ? t : s.tipOther;
|
|
831
|
+
}
|
|
832
|
+
const op = who(typeof c.operator === "string" ? c.operator : "@system");
|
|
833
|
+
const targets = Array.isArray(c.targets) ? c.targets.filter((x) => typeof x === "string").map(who).join("、") : "";
|
|
834
|
+
const f = (tpl, name = "") => fill(tpl, { op, targets, name });
|
|
835
|
+
switch (c.action) {
|
|
836
|
+
case "create":
|
|
837
|
+
return f(s.tipCreate);
|
|
838
|
+
case "join":
|
|
839
|
+
return f(s.tipJoin);
|
|
840
|
+
case "quit":
|
|
841
|
+
return f(s.tipQuit);
|
|
842
|
+
case "kick":
|
|
843
|
+
return f(s.tipKick);
|
|
844
|
+
case "dismiss":
|
|
845
|
+
return f(s.tipDismiss);
|
|
846
|
+
case "update": {
|
|
847
|
+
const name = c.fields && typeof c.fields === "object" ? c.fields.name : null;
|
|
848
|
+
return typeof name === "string" ? f(s.tipRename, name) : f(s.tipUpdate);
|
|
849
|
+
}
|
|
850
|
+
case "notice":
|
|
851
|
+
return f(s.tipNotice);
|
|
852
|
+
case "role":
|
|
853
|
+
return f(c.role === 1 ? s.tipAdminOn : s.tipAdminOff);
|
|
854
|
+
case "transfer":
|
|
855
|
+
return f(s.tipTransfer);
|
|
856
|
+
case "mute":
|
|
857
|
+
return f(c.until == null ? s.tipUnmute : s.tipMute);
|
|
858
|
+
default:
|
|
859
|
+
return s.tipOther;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// src/core/media.ts
|
|
864
|
+
var IMAGE_MIME = /* @__PURE__ */ new Set(["image/jpeg", "image/png", "image/gif", "image/webp"]);
|
|
865
|
+
var VIDEO_MIME = /* @__PURE__ */ new Set(["video/mp4", "video/quicktime"]);
|
|
866
|
+
function classifyFile(file) {
|
|
867
|
+
const mime = (file.type || "").toLowerCase();
|
|
868
|
+
if (IMAGE_MIME.has(mime)) return "image";
|
|
869
|
+
if (VIDEO_MIME.has(mime)) return "video";
|
|
870
|
+
return "file";
|
|
871
|
+
}
|
|
872
|
+
function checkSize(file, kind, features) {
|
|
873
|
+
if (kind === "image") return null;
|
|
874
|
+
const maxMb = kind === "video" ? features.videoMaxMb : features.fileMaxMb;
|
|
875
|
+
if (!(maxMb > 0)) return { reason: "disabled", maxMb: 0 };
|
|
876
|
+
return file.size > maxMb * 1024 * 1024 ? { reason: "tooLarge", maxMb } : null;
|
|
877
|
+
}
|
|
878
|
+
function readVideoMeta(file, timeoutMs = 1e4) {
|
|
879
|
+
return new Promise((resolve) => {
|
|
880
|
+
const url = URL.createObjectURL(file);
|
|
881
|
+
const video = document.createElement("video");
|
|
882
|
+
let done = false;
|
|
883
|
+
const finish = (v) => {
|
|
884
|
+
if (done) return;
|
|
885
|
+
done = true;
|
|
886
|
+
clearTimeout(timer);
|
|
887
|
+
video.onloadedmetadata = null;
|
|
888
|
+
video.onerror = null;
|
|
889
|
+
video.removeAttribute("src");
|
|
890
|
+
video.load();
|
|
891
|
+
URL.revokeObjectURL(url);
|
|
892
|
+
resolve(v);
|
|
893
|
+
};
|
|
894
|
+
const timer = setTimeout(() => finish(null), timeoutMs);
|
|
895
|
+
video.preload = "metadata";
|
|
896
|
+
video.muted = true;
|
|
897
|
+
video.onloadedmetadata = () => {
|
|
898
|
+
const width = video.videoWidth;
|
|
899
|
+
const height = video.videoHeight;
|
|
900
|
+
const sec = video.duration;
|
|
901
|
+
if (!(width > 0 && height > 0 && Number.isFinite(sec) && sec > 0)) return finish(null);
|
|
902
|
+
finish({ durationMs: Math.round(sec * 1e3), width, height });
|
|
903
|
+
};
|
|
904
|
+
video.onerror = () => finish(null);
|
|
905
|
+
video.src = url;
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
var ObjectUrlRegistry = class {
|
|
909
|
+
constructor() {
|
|
910
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
911
|
+
}
|
|
912
|
+
/** 登记并返回地址;同一 key 同一文件重复登记返回原地址,换了文件先回收旧的。 */
|
|
913
|
+
register(key, file) {
|
|
914
|
+
const hit = this.entries.get(key);
|
|
915
|
+
if (hit && hit.file === file) return hit.url;
|
|
916
|
+
if (hit) URL.revokeObjectURL(hit.url);
|
|
917
|
+
const url = URL.createObjectURL(file);
|
|
918
|
+
this.entries.set(key, { file, url });
|
|
919
|
+
return url;
|
|
920
|
+
}
|
|
921
|
+
get(key) {
|
|
922
|
+
return this.entries.get(key)?.url ?? null;
|
|
923
|
+
}
|
|
924
|
+
release(key) {
|
|
925
|
+
const hit = this.entries.get(key);
|
|
926
|
+
if (!hit) return;
|
|
927
|
+
URL.revokeObjectURL(hit.url);
|
|
928
|
+
this.entries.delete(key);
|
|
929
|
+
}
|
|
930
|
+
/** 和一份 key → 文件 的表对齐(如 ChatController 快照的 `localFiles`):缺的登记,多出来的回收。 */
|
|
931
|
+
sync(files) {
|
|
932
|
+
for (const key of [...this.entries.keys()]) if (!(key in files)) this.release(key);
|
|
933
|
+
for (const [key, file] of Object.entries(files)) this.register(key, file);
|
|
934
|
+
}
|
|
935
|
+
releaseAll() {
|
|
936
|
+
for (const { url } of this.entries.values()) URL.revokeObjectURL(url);
|
|
937
|
+
this.entries.clear();
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
|
|
941
|
+
// src/core/memberCache.ts
|
|
942
|
+
var _MemberCache = class _MemberCache {
|
|
943
|
+
constructor(im, groupId) {
|
|
944
|
+
this.im = im;
|
|
945
|
+
this.groupId = groupId;
|
|
946
|
+
this.map = /* @__PURE__ */ new Map();
|
|
947
|
+
this.list = null;
|
|
948
|
+
this.gen = 0;
|
|
949
|
+
this.disposed = false;
|
|
950
|
+
this.off = null;
|
|
951
|
+
this.listeners = new ListenerSet();
|
|
952
|
+
this.subscribe = (fn) => this.listeners.add(fn);
|
|
953
|
+
this.getSnapshot = () => this.map;
|
|
954
|
+
}
|
|
955
|
+
/** 开始监听群变动并拉第一次。重复调用无效。 */
|
|
956
|
+
start() {
|
|
957
|
+
if (this.off || this.disposed) return;
|
|
958
|
+
const gid = this.groupId.toLowerCase();
|
|
959
|
+
this.off = this.im.on("groupChanged", (c) => {
|
|
960
|
+
if (c.groupId.toLowerCase() === gid) void this.reload();
|
|
961
|
+
});
|
|
962
|
+
void this.reload();
|
|
963
|
+
}
|
|
964
|
+
/** 当前在群的成员,按进群先后。 */
|
|
965
|
+
get members() {
|
|
966
|
+
return this.list ?? (this.list = [...this.map.values()]);
|
|
967
|
+
}
|
|
968
|
+
get(userId) {
|
|
969
|
+
return this.map.get(userId);
|
|
970
|
+
}
|
|
971
|
+
/** 显示名:在缓存里用昵称(空时 userId),不在(已退群)用 userId。 */
|
|
972
|
+
nameOf(userId) {
|
|
973
|
+
const m = this.map.get(userId);
|
|
974
|
+
return !m || m.nickname === "" ? userId : m.nickname;
|
|
975
|
+
}
|
|
976
|
+
async reload() {
|
|
977
|
+
const gen = ++this.gen;
|
|
978
|
+
const next = /* @__PURE__ */ new Map();
|
|
979
|
+
let cursor = null;
|
|
980
|
+
try {
|
|
981
|
+
do {
|
|
982
|
+
const page = await this.im.groupMembers(this.groupId, {
|
|
983
|
+
cursor,
|
|
984
|
+
limit: 100
|
|
985
|
+
});
|
|
986
|
+
for (const m of page.items) next.set(m.userId, m);
|
|
987
|
+
cursor = page.nextCursor;
|
|
988
|
+
} while (cursor !== null && next.size < _MemberCache.max);
|
|
989
|
+
} catch {
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
if (this.disposed || gen !== this.gen) return;
|
|
993
|
+
this.map = next;
|
|
994
|
+
this.list = null;
|
|
995
|
+
this.listeners.notify();
|
|
996
|
+
}
|
|
997
|
+
dispose() {
|
|
998
|
+
this.disposed = true;
|
|
999
|
+
this.off?.();
|
|
1000
|
+
this.off = null;
|
|
1001
|
+
this.listeners.clear();
|
|
1002
|
+
}
|
|
1003
|
+
};
|
|
1004
|
+
_MemberCache.max = 500;
|
|
1005
|
+
var MemberCache = _MemberCache;
|
|
1006
|
+
|
|
1007
|
+
// src/ui/widgets/feedback.tsx
|
|
1008
|
+
var import_react3 = require("react");
|
|
1009
|
+
|
|
1010
|
+
// src/ui/widgets/useFocusTrap.ts
|
|
1011
|
+
var import_react2 = require("react");
|
|
1012
|
+
var FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])';
|
|
1013
|
+
function useFocusTrap(active = true) {
|
|
1014
|
+
const ref = (0, import_react2.useRef)(null);
|
|
1015
|
+
(0, import_react2.useEffect)(() => {
|
|
1016
|
+
if (!active) return;
|
|
1017
|
+
const el = ref.current;
|
|
1018
|
+
if (!el) return;
|
|
1019
|
+
const prev = document.activeElement;
|
|
1020
|
+
const first = el.querySelector("[data-autofocus]") ?? el.querySelector(FOCUSABLE);
|
|
1021
|
+
(first ?? el).focus();
|
|
1022
|
+
const onKey = (e) => {
|
|
1023
|
+
if (e.key !== "Tab") return;
|
|
1024
|
+
const items = Array.from(el.querySelectorAll(FOCUSABLE));
|
|
1025
|
+
if (!items.length) return;
|
|
1026
|
+
const a = items[0], b = items[items.length - 1];
|
|
1027
|
+
if (e.shiftKey && document.activeElement === a) {
|
|
1028
|
+
e.preventDefault();
|
|
1029
|
+
b.focus();
|
|
1030
|
+
} else if (!e.shiftKey && document.activeElement === b) {
|
|
1031
|
+
e.preventDefault();
|
|
1032
|
+
a.focus();
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
el.addEventListener("keydown", onKey);
|
|
1036
|
+
return () => {
|
|
1037
|
+
el.removeEventListener("keydown", onKey);
|
|
1038
|
+
if (prev && document.contains(prev)) prev.focus();
|
|
1039
|
+
};
|
|
1040
|
+
}, [active]);
|
|
1041
|
+
return ref;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// src/ui/widgets/feedback.tsx
|
|
1045
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1046
|
+
var Ctx = (0, import_react3.createContext)(null);
|
|
1047
|
+
function ConfirmBox({ o, labels, done }) {
|
|
1048
|
+
const ref = useFocusTrap();
|
|
1049
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "gkim-dialog-layer gkim-dialog-layer--top", onKeyDown: (e) => {
|
|
1050
|
+
if (e.key === "Escape") {
|
|
1051
|
+
e.stopPropagation();
|
|
1052
|
+
done(false);
|
|
1053
|
+
}
|
|
1054
|
+
}, children: [
|
|
1055
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "gkim-scrim", onClick: () => done(false) }),
|
|
1056
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "gkim-dialog gkim-confirm", ref, role: "alertdialog", "aria-modal": "true", "aria-label": o.title ?? o.content, tabIndex: -1, children: [
|
|
1057
|
+
o.title && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "gkim-confirm__title", children: o.title }),
|
|
1058
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "gkim-confirm__text", children: o.content }),
|
|
1059
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "gkim-confirm__actions", children: [
|
|
1060
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "gkim-btn", onClick: () => done(false), children: labels.cancel }),
|
|
1061
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", "data-autofocus": true, className: o.danger ? "gkim-btn gkim-btn--danger" : "gkim-btn gkim-btn--primary", onClick: () => done(true), children: o.ok ?? labels.ok })
|
|
1062
|
+
] })
|
|
1063
|
+
] })
|
|
1064
|
+
] });
|
|
1065
|
+
}
|
|
1066
|
+
function FeedbackProvider({ labels, children }) {
|
|
1067
|
+
const [toastText, setToast] = (0, import_react3.useState)(null);
|
|
1068
|
+
const timer = (0, import_react3.useRef)(void 0);
|
|
1069
|
+
const [pending, setPending] = (0, import_react3.useState)(null);
|
|
1070
|
+
const toast = (0, import_react3.useCallback)((text) => {
|
|
1071
|
+
setToast(text);
|
|
1072
|
+
clearTimeout(timer.current);
|
|
1073
|
+
timer.current = setTimeout(() => setToast(null), 2500);
|
|
1074
|
+
}, []);
|
|
1075
|
+
const confirm = (0, import_react3.useCallback)((o) => new Promise((resolve) => setPending({ o, resolve })), []);
|
|
1076
|
+
const value = (0, import_react3.useMemo)(() => ({ toast, confirm }), [toast, confirm]);
|
|
1077
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Ctx.Provider, { value, children: [
|
|
1078
|
+
children,
|
|
1079
|
+
pending && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfirmBox, { o: pending.o, labels, done: (v) => {
|
|
1080
|
+
pending.resolve(v);
|
|
1081
|
+
setPending(null);
|
|
1082
|
+
} }),
|
|
1083
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "gkim-toast-region", role: "status", "aria-live": "polite", children: toastText && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "gkim-toast", children: toastText }) })
|
|
1084
|
+
] });
|
|
1085
|
+
}
|
|
1086
|
+
function useFeedback() {
|
|
1087
|
+
const v = (0, import_react3.useContext)(Ctx);
|
|
1088
|
+
if (!v) throw new Error("没有找到 GuokitImUi:IM 组件要放在 GuokitImUi 下面。");
|
|
1089
|
+
return v;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
// src/ui/widgets/Icon.tsx
|
|
1093
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1094
|
+
var PATHS = {
|
|
1095
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M4 5h16v11H9l-5 4z" }),
|
|
1096
|
+
back: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M15 5l-7 7 7 7" }),
|
|
1097
|
+
close: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M6 6l12 12M18 6L6 18" }),
|
|
1098
|
+
more: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1099
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "5", cy: "12", r: "1.2" }),
|
|
1100
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "1.2" }),
|
|
1101
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "19", cy: "12", r: "1.2" })
|
|
1102
|
+
] }),
|
|
1103
|
+
emoji: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1104
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "9.5" }),
|
|
1105
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M8 14.5a5 5 0 0 0 8 0" }),
|
|
1106
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M9 9.5v.01M15 9.5v.01" })
|
|
1107
|
+
] }),
|
|
1108
|
+
image: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1109
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: "3", y: "4", width: "18", height: "16", rx: "2" }),
|
|
1110
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "9", cy: "10", r: "2" }),
|
|
1111
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M21 16l-5-5-9 9" })
|
|
1112
|
+
] }),
|
|
1113
|
+
file: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1114
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M6 3h8l4 4v14H6z" }),
|
|
1115
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M14 3v4h4" })
|
|
1116
|
+
] }),
|
|
1117
|
+
plus: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1118
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "9.5" }),
|
|
1119
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 8v8M8 12h8" })
|
|
1120
|
+
] }),
|
|
1121
|
+
copy: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1122
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: "8", y: "8", width: "12", height: "12", rx: "2" }),
|
|
1123
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M16 8V5a1 1 0 0 0-1-1H5a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h3" })
|
|
1124
|
+
] }),
|
|
1125
|
+
recall: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1126
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M9 14L4 9l5-5" }),
|
|
1127
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M4 9h10a6 6 0 0 1 0 12h-3" })
|
|
1128
|
+
] }),
|
|
1129
|
+
report: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M5 21V4h11l-1.5 4L16 12H5" }) }),
|
|
1130
|
+
down: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 5v14M6 13l6 6 6-6" }),
|
|
1131
|
+
play: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M8 5l11 7-11 7z" }),
|
|
1132
|
+
pause: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M8 5v14M16 5v14" }),
|
|
1133
|
+
zoomIn: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1134
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "11", cy: "11", r: "7" }),
|
|
1135
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M21 21l-4.3-4.3M11 8v6M8 11h6" })
|
|
1136
|
+
] }),
|
|
1137
|
+
zoomOut: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1138
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "11", cy: "11", r: "7" }),
|
|
1139
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M21 21l-4.3-4.3M8 11h6" })
|
|
1140
|
+
] }),
|
|
1141
|
+
external: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1142
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M14 4h6v6" }),
|
|
1143
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M20 4l-9 9" }),
|
|
1144
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5" })
|
|
1145
|
+
] }),
|
|
1146
|
+
location: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1147
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 21s-7-6.2-7-11a7 7 0 0 1 14 0c0 4.8-7 11-7 11z" }),
|
|
1148
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "10", r: "2.5" })
|
|
1149
|
+
] }),
|
|
1150
|
+
alert: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1151
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "9.5" }),
|
|
1152
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 7.5v5.5M12 16.5v.01" })
|
|
1153
|
+
] }),
|
|
1154
|
+
retry: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1155
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M20 11a8 8 0 1 0-2.3 5.7" }),
|
|
1156
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M20 4v7h-7" })
|
|
1157
|
+
] }),
|
|
1158
|
+
group: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1159
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "9", cy: "8", r: "3.5" }),
|
|
1160
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M2.5 20a6.5 6.5 0 0 1 13 0" }),
|
|
1161
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M16 4.5a3.5 3.5 0 0 1 0 7" }),
|
|
1162
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M18 14a6 6 0 0 1 3.5 6" })
|
|
1163
|
+
] }),
|
|
1164
|
+
check: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M5 12l5 5 9-10" }),
|
|
1165
|
+
checkAll: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1166
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M2 12l5 5 9-10" }),
|
|
1167
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 16l1 1 9-10" })
|
|
1168
|
+
] }),
|
|
1169
|
+
mute: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1170
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M13.7 21a2 2 0 0 1-3.4 0" }),
|
|
1171
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M18 8a6 6 0 0 0-9.3-5" }),
|
|
1172
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M6.3 6.3A6 6 0 0 0 6 8c0 7-3 9-3 9h14" }),
|
|
1173
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M3 3l18 18" })
|
|
1174
|
+
] })
|
|
1175
|
+
};
|
|
1176
|
+
function Icon({ name, size = 20 }) {
|
|
1177
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1178
|
+
"svg",
|
|
1179
|
+
{
|
|
1180
|
+
className: "gkim-icon",
|
|
1181
|
+
width: size,
|
|
1182
|
+
height: size,
|
|
1183
|
+
viewBox: "0 0 24 24",
|
|
1184
|
+
fill: "none",
|
|
1185
|
+
stroke: "currentColor",
|
|
1186
|
+
strokeWidth: 1.8,
|
|
1187
|
+
strokeLinecap: "round",
|
|
1188
|
+
strokeLinejoin: "round",
|
|
1189
|
+
"aria-hidden": "true",
|
|
1190
|
+
children: PATHS[name]
|
|
1191
|
+
}
|
|
1192
|
+
);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
// src/ui/widgets/Page.tsx
|
|
1196
|
+
var import_react5 = require("react");
|
|
1197
|
+
|
|
1198
|
+
// src/ui/layout/frame.ts
|
|
1199
|
+
var import_react4 = require("react");
|
|
1200
|
+
var noop = () => {
|
|
1201
|
+
};
|
|
1202
|
+
var FrameContext = (0, import_react4.createContext)({ kind: "standalone", canBack: false, back: noop, close: noop });
|
|
1203
|
+
function useFrame() {
|
|
1204
|
+
return (0, import_react4.useContext)(FrameContext);
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
// src/ui/widgets/Page.tsx
|
|
1208
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1209
|
+
function Page({ title, actions, banner, footer, children, className, scroll = true }) {
|
|
1210
|
+
const f = useFrame();
|
|
1211
|
+
const s = useImUi().strings;
|
|
1212
|
+
const titleId = (0, import_react5.useId)();
|
|
1213
|
+
const dialog = f.kind === "dialog";
|
|
1214
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1215
|
+
"section",
|
|
1216
|
+
{
|
|
1217
|
+
className: `gkim-page gkim-page--${f.kind}${className ? " " + className : ""}`,
|
|
1218
|
+
role: dialog ? "dialog" : void 0,
|
|
1219
|
+
"aria-modal": dialog || void 0,
|
|
1220
|
+
"aria-labelledby": titleId,
|
|
1221
|
+
children: [
|
|
1222
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("header", { className: "gkim-page__head", children: [
|
|
1223
|
+
f.canBack && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: "gkim-iconbtn", "aria-label": s.back, onClick: f.back, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { name: "back" }) }),
|
|
1224
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h2", { id: titleId, className: "gkim-page__title", children: title }),
|
|
1225
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gkim-page__actions", children: [
|
|
1226
|
+
actions,
|
|
1227
|
+
(f.kind === "drawer" || dialog) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: "gkim-iconbtn", "aria-label": s.close, onClick: f.close, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { name: "close" }) })
|
|
1228
|
+
] })
|
|
1229
|
+
] }),
|
|
1230
|
+
banner,
|
|
1231
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: scroll ? "gkim-page__body gkim-page__body--scroll" : "gkim-page__body", children }),
|
|
1232
|
+
footer && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("footer", { className: "gkim-page__foot", children: footer })
|
|
1233
|
+
]
|
|
1234
|
+
}
|
|
1235
|
+
);
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
// src/ui/chat/Composer.tsx
|
|
1239
|
+
var import_react8 = require("react");
|
|
1240
|
+
|
|
1241
|
+
// src/core/mention.ts
|
|
1242
|
+
var mentionToken = (m) => `@${m.name} `;
|
|
1243
|
+
var _MentionEditing = class _MentionEditing {
|
|
1244
|
+
constructor() {
|
|
1245
|
+
this.list = [];
|
|
1246
|
+
}
|
|
1247
|
+
get mentions() {
|
|
1248
|
+
return this.list;
|
|
1249
|
+
}
|
|
1250
|
+
clear() {
|
|
1251
|
+
this.list = [];
|
|
1252
|
+
}
|
|
1253
|
+
/** 把 `value` 里 `atIndex` 处那个「@」换成 `@昵称 `,光标放到它后面;那里不是「@」时插在光标处。 */
|
|
1254
|
+
insert(value, atIndex, m) {
|
|
1255
|
+
const { text } = value;
|
|
1256
|
+
const token = mentionToken(m);
|
|
1257
|
+
const hasAt = atIndex >= 0 && atIndex < text.length && text[atIndex] === "@";
|
|
1258
|
+
const start = hasAt ? atIndex : Math.min(Math.max(value.cursor, 0), text.length);
|
|
1259
|
+
const end = hasAt ? atIndex + 1 : start;
|
|
1260
|
+
this.list.push(m);
|
|
1261
|
+
return { text: text.slice(0, start) + token + text.slice(end), cursor: start + token.length };
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* 输入变化时调:删除碰到某个 `@昵称 ` 时把整段删掉。返回应当显示的值;没变就原样返回 `next`(同一引用)。
|
|
1265
|
+
* 删除同时有插入(替换选区)时不处理。
|
|
1266
|
+
*/
|
|
1267
|
+
onChanged(old, next) {
|
|
1268
|
+
const now = next.text;
|
|
1269
|
+
if (now.length >= old.length || this.list.length === 0) return next;
|
|
1270
|
+
let a = 0;
|
|
1271
|
+
while (a < now.length && old[a] === now[a]) a++;
|
|
1272
|
+
let b = 0;
|
|
1273
|
+
while (b < now.length - a && old[old.length - 1 - b] === now[now.length - 1 - b]) b++;
|
|
1274
|
+
const delStart = a;
|
|
1275
|
+
const delEnd = old.length - b;
|
|
1276
|
+
if (now.length - a - b !== 0) return next;
|
|
1277
|
+
for (const m of this.list) {
|
|
1278
|
+
const token = mentionToken(m);
|
|
1279
|
+
let from = 0;
|
|
1280
|
+
for (; ; ) {
|
|
1281
|
+
const i = old.indexOf(token, from);
|
|
1282
|
+
if (i < 0) break;
|
|
1283
|
+
const j = i + token.length;
|
|
1284
|
+
if (delStart < j && delEnd > i) {
|
|
1285
|
+
const s = Math.min(delStart, i);
|
|
1286
|
+
const e = Math.max(delEnd, j);
|
|
1287
|
+
return { text: old.slice(0, s) + old.slice(e), cursor: s };
|
|
1288
|
+
}
|
|
1289
|
+
from = j;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
return next;
|
|
1293
|
+
}
|
|
1294
|
+
/** 发送时的 at 列表:文字里还完整留着的 @,去重,最多 20 个。 */
|
|
1295
|
+
atIds(text) {
|
|
1296
|
+
const out = [];
|
|
1297
|
+
for (const m of this.list) {
|
|
1298
|
+
if (text.includes(mentionToken(m)) && !out.includes(m.userId)) out.push(m.userId);
|
|
1299
|
+
if (out.length >= _MentionEditing.maxAt) break;
|
|
1300
|
+
}
|
|
1301
|
+
return out;
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
/** 一条最多 @ 20 人(服务端限制)。 */
|
|
1305
|
+
_MentionEditing.maxAt = 20;
|
|
1306
|
+
var MentionEditing = _MentionEditing;
|
|
1307
|
+
|
|
1308
|
+
// src/ui/widgets/Avatar.tsx
|
|
1309
|
+
var import_react6 = require("react");
|
|
1310
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1311
|
+
var PALETTE = ["#0F766E", "#B45309", "#7C3AED", "#BE185D", "#4D7C0F", "#0369A1", "#9A3412", "#475569"];
|
|
1312
|
+
function avatarColor(id) {
|
|
1313
|
+
let h = 0;
|
|
1314
|
+
for (let i = 0; i < id.length; i++) h = h * 31 + id.charCodeAt(i) & 2147483647;
|
|
1315
|
+
return PALETTE[h % PALETTE.length];
|
|
1316
|
+
}
|
|
1317
|
+
function avatarInitial(name, id) {
|
|
1318
|
+
const s = name.trim() || id;
|
|
1319
|
+
if (!s) return "?";
|
|
1320
|
+
return String.fromCodePoint(s.codePointAt(0)).toUpperCase();
|
|
1321
|
+
}
|
|
1322
|
+
function Avatar({ id, name, url, size, group, onClick }) {
|
|
1323
|
+
const [broken, setBroken] = (0, import_react6.useState)(null);
|
|
1324
|
+
const label = name || id;
|
|
1325
|
+
const style = size ? { ["--gkim-av"]: `${size}px` } : void 0;
|
|
1326
|
+
const cls = `gkim-avatar${group ? " gkim-avatar--group" : ""}`;
|
|
1327
|
+
const inner = url && broken !== url ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("img", { src: url, alt: "", onError: () => setBroken(url) }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { background: avatarColor(id) }, children: avatarInitial(name, id) });
|
|
1328
|
+
if (onClick) {
|
|
1329
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: cls, style, "aria-label": label, onClick, children: inner });
|
|
1330
|
+
}
|
|
1331
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: cls, style, role: "img", "aria-label": label, children: inner });
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
// src/ui/widgets/Menu.tsx
|
|
1335
|
+
var import_react7 = require("react");
|
|
1336
|
+
var import_react_dom = require("react-dom");
|
|
1337
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1338
|
+
function Menu({ entries, x, y, onClose, label }) {
|
|
1339
|
+
const ref = (0, import_react7.useRef)(null);
|
|
1340
|
+
const [pos, setPos] = (0, import_react7.useState)({ left: x, top: y });
|
|
1341
|
+
const [sub, setSub] = (0, import_react7.useState)(null);
|
|
1342
|
+
(0, import_react7.useLayoutEffect)(() => {
|
|
1343
|
+
const el = ref.current;
|
|
1344
|
+
if (!el) return;
|
|
1345
|
+
const r = el.getBoundingClientRect();
|
|
1346
|
+
const vw = window.innerWidth, vh = window.innerHeight;
|
|
1347
|
+
setPos({ left: x + r.width > vw - 8 ? Math.max(8, x - r.width) : x, top: y + r.height > vh - 8 ? Math.max(8, y - r.height) : y });
|
|
1348
|
+
}, [x, y]);
|
|
1349
|
+
(0, import_react7.useEffect)(() => {
|
|
1350
|
+
const prev = document.activeElement;
|
|
1351
|
+
ref.current?.querySelector('[role="menuitem"]:not([disabled])')?.focus();
|
|
1352
|
+
const down = (e) => {
|
|
1353
|
+
if (ref.current && !ref.current.contains(e.target)) onClose();
|
|
1354
|
+
};
|
|
1355
|
+
document.addEventListener("mousedown", down, true);
|
|
1356
|
+
window.addEventListener("blur", onClose);
|
|
1357
|
+
return () => {
|
|
1358
|
+
document.removeEventListener("mousedown", down, true);
|
|
1359
|
+
window.removeEventListener("blur", onClose);
|
|
1360
|
+
if (prev && document.contains(prev)) prev.focus();
|
|
1361
|
+
};
|
|
1362
|
+
}, [onClose]);
|
|
1363
|
+
const onKey = (e) => {
|
|
1364
|
+
const items = Array.from(ref.current?.querySelectorAll(':scope > [role="menuitem"]:not([disabled])') ?? []);
|
|
1365
|
+
const i = items.indexOf(document.activeElement);
|
|
1366
|
+
if (e.key === "ArrowDown") {
|
|
1367
|
+
e.preventDefault();
|
|
1368
|
+
items[(i + 1) % items.length]?.focus();
|
|
1369
|
+
} else if (e.key === "ArrowUp") {
|
|
1370
|
+
e.preventDefault();
|
|
1371
|
+
items[(i - 1 + items.length) % items.length]?.focus();
|
|
1372
|
+
} else if (e.key === "Escape") {
|
|
1373
|
+
e.preventDefault();
|
|
1374
|
+
e.stopPropagation();
|
|
1375
|
+
onClose();
|
|
1376
|
+
} else if (e.key === "Tab") {
|
|
1377
|
+
e.preventDefault();
|
|
1378
|
+
onClose();
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
const menu = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1382
|
+
"div",
|
|
1383
|
+
{
|
|
1384
|
+
ref,
|
|
1385
|
+
className: "gkim-menu gkim-root-menu",
|
|
1386
|
+
role: "menu",
|
|
1387
|
+
"aria-label": label,
|
|
1388
|
+
style: pos,
|
|
1389
|
+
onKeyDown: onKey,
|
|
1390
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
1391
|
+
children: entries.map((it, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1392
|
+
"button",
|
|
1393
|
+
{
|
|
1394
|
+
type: "button",
|
|
1395
|
+
role: "menuitem",
|
|
1396
|
+
disabled: it.disabled,
|
|
1397
|
+
"aria-haspopup": it.children ? "menu" : void 0,
|
|
1398
|
+
"aria-expanded": it.children ? sub === i : void 0,
|
|
1399
|
+
className: `gkim-menu__item${it.danger ? " gkim-menu__item--danger" : ""}`,
|
|
1400
|
+
onMouseEnter: () => setSub(it.children ? i : null),
|
|
1401
|
+
onKeyDown: (e) => {
|
|
1402
|
+
if (it.children && e.key === "ArrowRight") {
|
|
1403
|
+
e.preventDefault();
|
|
1404
|
+
setSub(i);
|
|
1405
|
+
}
|
|
1406
|
+
},
|
|
1407
|
+
onClick: () => {
|
|
1408
|
+
if (it.children) {
|
|
1409
|
+
setSub(i);
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
onClose();
|
|
1413
|
+
it.onSelect();
|
|
1414
|
+
},
|
|
1415
|
+
children: [
|
|
1416
|
+
it.icon,
|
|
1417
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: it.label }),
|
|
1418
|
+
it.children && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "gkim-menu__arrow", children: "›" }),
|
|
1419
|
+
it.children && sub === i && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "gkim-menu gkim-menu--sub", role: "menu", children: it.children.map((c, j) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1420
|
+
"span",
|
|
1421
|
+
{
|
|
1422
|
+
role: "menuitem",
|
|
1423
|
+
tabIndex: 0,
|
|
1424
|
+
className: "gkim-menu__item",
|
|
1425
|
+
onClick: (e) => {
|
|
1426
|
+
e.stopPropagation();
|
|
1427
|
+
onClose();
|
|
1428
|
+
c.onSelect();
|
|
1429
|
+
},
|
|
1430
|
+
onKeyDown: (e) => {
|
|
1431
|
+
if (e.key === "Enter") {
|
|
1432
|
+
e.stopPropagation();
|
|
1433
|
+
onClose();
|
|
1434
|
+
c.onSelect();
|
|
1435
|
+
}
|
|
1436
|
+
},
|
|
1437
|
+
children: c.label
|
|
1438
|
+
},
|
|
1439
|
+
j
|
|
1440
|
+
)) })
|
|
1441
|
+
]
|
|
1442
|
+
},
|
|
1443
|
+
i
|
|
1444
|
+
))
|
|
1445
|
+
}
|
|
1446
|
+
);
|
|
1447
|
+
const host = typeof document !== "undefined" && (document.activeElement?.closest(".gkim-root") ?? document.querySelector(".gkim-root")) || document.body;
|
|
1448
|
+
return (0, import_react_dom.createPortal)(menu, host);
|
|
1449
|
+
}
|
|
1450
|
+
function useContextMenu() {
|
|
1451
|
+
const [at, setAt] = (0, import_react7.useState)(null);
|
|
1452
|
+
const timer = (0, import_react7.useRef)(void 0);
|
|
1453
|
+
const start = (0, import_react7.useRef)(null);
|
|
1454
|
+
const bind = {
|
|
1455
|
+
onContextMenu: (e) => {
|
|
1456
|
+
e.preventDefault();
|
|
1457
|
+
setAt({ x: e.clientX, y: e.clientY });
|
|
1458
|
+
},
|
|
1459
|
+
onTouchStart: (e) => {
|
|
1460
|
+
const t = e.touches[0];
|
|
1461
|
+
start.current = { x: t.clientX, y: t.clientY };
|
|
1462
|
+
timer.current = setTimeout(() => {
|
|
1463
|
+
if (start.current) setAt(start.current);
|
|
1464
|
+
}, 500);
|
|
1465
|
+
},
|
|
1466
|
+
onTouchMove: (e) => {
|
|
1467
|
+
const t = e.touches[0], s = start.current;
|
|
1468
|
+
if (s && Math.hypot(t.clientX - s.x, t.clientY - s.y) > 10) {
|
|
1469
|
+
clearTimeout(timer.current);
|
|
1470
|
+
start.current = null;
|
|
1471
|
+
}
|
|
1472
|
+
},
|
|
1473
|
+
onTouchEnd: () => {
|
|
1474
|
+
clearTimeout(timer.current);
|
|
1475
|
+
start.current = null;
|
|
1476
|
+
}
|
|
1477
|
+
};
|
|
1478
|
+
const close = (0, import_react7.useCallback)(() => setAt(null), []);
|
|
1479
|
+
return { at, open: setAt, close, bind };
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
// src/ui/chat/emojis.ts
|
|
1483
|
+
var EMOJIS = [
|
|
1484
|
+
"😀",
|
|
1485
|
+
"😁",
|
|
1486
|
+
"😂",
|
|
1487
|
+
"🤣",
|
|
1488
|
+
"😊",
|
|
1489
|
+
"😍",
|
|
1490
|
+
"😘",
|
|
1491
|
+
"😜",
|
|
1492
|
+
"🤔",
|
|
1493
|
+
"😏",
|
|
1494
|
+
"😎",
|
|
1495
|
+
"🥳",
|
|
1496
|
+
"😭",
|
|
1497
|
+
"😢",
|
|
1498
|
+
"😡",
|
|
1499
|
+
"😱",
|
|
1500
|
+
"😴",
|
|
1501
|
+
"🤗",
|
|
1502
|
+
"🙄",
|
|
1503
|
+
"😅",
|
|
1504
|
+
"😆",
|
|
1505
|
+
"😉",
|
|
1506
|
+
"😋",
|
|
1507
|
+
"😇",
|
|
1508
|
+
"🥰",
|
|
1509
|
+
"🤩",
|
|
1510
|
+
"😌",
|
|
1511
|
+
"😔",
|
|
1512
|
+
"😳",
|
|
1513
|
+
"🤯",
|
|
1514
|
+
"😤",
|
|
1515
|
+
"😷",
|
|
1516
|
+
"🤒",
|
|
1517
|
+
"🤧",
|
|
1518
|
+
"🥺",
|
|
1519
|
+
"😬",
|
|
1520
|
+
"🤐",
|
|
1521
|
+
"🤫",
|
|
1522
|
+
"🤭",
|
|
1523
|
+
"😶",
|
|
1524
|
+
"👍",
|
|
1525
|
+
"👎",
|
|
1526
|
+
"👏",
|
|
1527
|
+
"🙏",
|
|
1528
|
+
"💪",
|
|
1529
|
+
"👌",
|
|
1530
|
+
"✌️",
|
|
1531
|
+
"🤝",
|
|
1532
|
+
"👋",
|
|
1533
|
+
"🙌",
|
|
1534
|
+
"❤️",
|
|
1535
|
+
"💔",
|
|
1536
|
+
"💯",
|
|
1537
|
+
"🔥",
|
|
1538
|
+
"✨",
|
|
1539
|
+
"🎉",
|
|
1540
|
+
"🎁",
|
|
1541
|
+
"🌹",
|
|
1542
|
+
"☕",
|
|
1543
|
+
"🍺",
|
|
1544
|
+
"🍉",
|
|
1545
|
+
"🍰",
|
|
1546
|
+
"🧧",
|
|
1547
|
+
"💰",
|
|
1548
|
+
"📅",
|
|
1549
|
+
"⏰",
|
|
1550
|
+
"✅",
|
|
1551
|
+
"❌",
|
|
1552
|
+
"❓",
|
|
1553
|
+
"⭐"
|
|
1554
|
+
];
|
|
1555
|
+
|
|
1556
|
+
// src/ui/chat/Composer.tsx
|
|
1557
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1558
|
+
var MAX_ROWS_PX = 6 * 21 + 8;
|
|
1559
|
+
var seq = 0;
|
|
1560
|
+
var Composer = (0, import_react8.forwardRef)(function Composer2(p, ref) {
|
|
1561
|
+
const { im, strings: s, moreItems } = useImUi();
|
|
1562
|
+
const { toast } = useFeedback();
|
|
1563
|
+
const [text, setText] = (0, import_react8.useState)("");
|
|
1564
|
+
const [tray, setTray] = (0, import_react8.useState)([]);
|
|
1565
|
+
const [emoji, setEmoji] = (0, import_react8.useState)(false);
|
|
1566
|
+
const [more, setMore] = (0, import_react8.useState)(null);
|
|
1567
|
+
const [mention, setMention] = (0, import_react8.useState)(null);
|
|
1568
|
+
const [busy, setBusy] = (0, import_react8.useState)(false);
|
|
1569
|
+
const closeMore = (0, import_react8.useCallback)(() => setMore(null), []);
|
|
1570
|
+
const ta = (0, import_react8.useRef)(null);
|
|
1571
|
+
const media = (0, import_react8.useRef)(null);
|
|
1572
|
+
const anyFile = (0, import_react8.useRef)(null);
|
|
1573
|
+
const mentions = (0, import_react8.useMemo)(() => new MentionEditing(), []);
|
|
1574
|
+
const f = p.features;
|
|
1575
|
+
const canImage = true;
|
|
1576
|
+
const canVideo = (f?.videoMaxMb ?? 0) > 0;
|
|
1577
|
+
const canFile = (f?.fileMaxMb ?? 0) > 0;
|
|
1578
|
+
(0, import_react8.useLayoutEffect)(() => {
|
|
1579
|
+
const el = ta.current;
|
|
1580
|
+
if (!el) return;
|
|
1581
|
+
el.style.height = "auto";
|
|
1582
|
+
el.style.height = `${Math.min(el.scrollHeight, MAX_ROWS_PX)}px`;
|
|
1583
|
+
}, [text]);
|
|
1584
|
+
const addFiles = (files) => {
|
|
1585
|
+
if (!f) return;
|
|
1586
|
+
const ok = [];
|
|
1587
|
+
for (const file of files) {
|
|
1588
|
+
let kind = classifyFile(file);
|
|
1589
|
+
if (kind === "video" && !canVideo) kind = "file";
|
|
1590
|
+
const issue = checkSize(file, kind, f);
|
|
1591
|
+
if (issue) {
|
|
1592
|
+
toast(issue.reason === "disabled" ? s.fileNotAllowed : fill(s.fileTooLarge, { mb: issue.maxMb }));
|
|
1593
|
+
continue;
|
|
1594
|
+
}
|
|
1595
|
+
ok.push({ id: ++seq, file, kind });
|
|
1596
|
+
}
|
|
1597
|
+
if (ok.length) setTray((t) => [...t, ...ok]);
|
|
1598
|
+
};
|
|
1599
|
+
(0, import_react8.useImperativeHandle)(ref, () => ({ addFiles }));
|
|
1600
|
+
const thumbs = (0, import_react8.useMemo)(() => /* @__PURE__ */ new Map(), []);
|
|
1601
|
+
(0, import_react8.useEffect)(() => {
|
|
1602
|
+
for (const [id, url] of thumbs) if (!tray.some((a) => a.id === id)) {
|
|
1603
|
+
URL.revokeObjectURL(url);
|
|
1604
|
+
thumbs.delete(id);
|
|
1605
|
+
}
|
|
1606
|
+
}, [tray, thumbs]);
|
|
1607
|
+
(0, import_react8.useEffect)(() => () => {
|
|
1608
|
+
for (const url of thumbs.values()) URL.revokeObjectURL(url);
|
|
1609
|
+
}, [thumbs]);
|
|
1610
|
+
const thumb = (a) => {
|
|
1611
|
+
let u = thumbs.get(a.id);
|
|
1612
|
+
if (!u) {
|
|
1613
|
+
u = URL.createObjectURL(a.file);
|
|
1614
|
+
thumbs.set(a.id, u);
|
|
1615
|
+
}
|
|
1616
|
+
return u;
|
|
1617
|
+
};
|
|
1618
|
+
const candidates = (0, import_react8.useMemo)(() => {
|
|
1619
|
+
if (!mention || !p.members) return [];
|
|
1620
|
+
const q = mention.q.toLowerCase();
|
|
1621
|
+
const me = im.currentUserId;
|
|
1622
|
+
const list = [];
|
|
1623
|
+
if (p.canAtAll && !q) list.push({ userId: "@all", name: s.atAll });
|
|
1624
|
+
for (const m of p.members) {
|
|
1625
|
+
if (m.userId === me) continue;
|
|
1626
|
+
if (q && !m.nickname.toLowerCase().includes(q) && !m.userId.toLowerCase().includes(q)) continue;
|
|
1627
|
+
list.push({ userId: m.userId, name: m.nickname || m.userId });
|
|
1628
|
+
if (list.length >= 50) break;
|
|
1629
|
+
}
|
|
1630
|
+
return list;
|
|
1631
|
+
}, [mention, p.members, p.canAtAll, im, s]);
|
|
1632
|
+
const pickMention = (m) => {
|
|
1633
|
+
if (!mention) return;
|
|
1634
|
+
const el = ta.current;
|
|
1635
|
+
const base = text.slice(0, mention.at + 1) + text.slice(mention.at + 1 + mention.q.length);
|
|
1636
|
+
const r = mentions.insert({ text: base, cursor: mention.at + 1 }, mention.at, m);
|
|
1637
|
+
setText(r.text);
|
|
1638
|
+
setMention(null);
|
|
1639
|
+
requestAnimationFrame(() => {
|
|
1640
|
+
el?.focus();
|
|
1641
|
+
el?.setSelectionRange(r.cursor, r.cursor);
|
|
1642
|
+
});
|
|
1643
|
+
};
|
|
1644
|
+
const onChange = (value, cursor) => {
|
|
1645
|
+
const fixed = mentions.onChanged(text, { text: value, cursor });
|
|
1646
|
+
setText(fixed.text);
|
|
1647
|
+
if (fixed.text !== value) requestAnimationFrame(() => ta.current?.setSelectionRange(fixed.cursor, fixed.cursor));
|
|
1648
|
+
p.onTyping?.();
|
|
1649
|
+
if (!p.members) return;
|
|
1650
|
+
const before = fixed.text.slice(0, fixed.cursor);
|
|
1651
|
+
const at = before.lastIndexOf("@");
|
|
1652
|
+
if (at >= 0 && !/\s/.test(before.slice(at + 1)) && (mention || fixed.text.length > text.length)) {
|
|
1653
|
+
setMention({ at, q: before.slice(at + 1), i: 0 });
|
|
1654
|
+
} else if (mention) setMention(null);
|
|
1655
|
+
};
|
|
1656
|
+
const send = async () => {
|
|
1657
|
+
if (busy) return;
|
|
1658
|
+
const t = text.trim();
|
|
1659
|
+
if (!t && !tray.length) return;
|
|
1660
|
+
setBusy(true);
|
|
1661
|
+
const files = tray;
|
|
1662
|
+
const at = mentions.atIds(text);
|
|
1663
|
+
setTray([]);
|
|
1664
|
+
setText("");
|
|
1665
|
+
mentions.clear();
|
|
1666
|
+
try {
|
|
1667
|
+
for (const a of files) await p.onSendFile(a);
|
|
1668
|
+
if (t) await p.onSend(t, at);
|
|
1669
|
+
} finally {
|
|
1670
|
+
setBusy(false);
|
|
1671
|
+
ta.current?.focus();
|
|
1672
|
+
}
|
|
1673
|
+
};
|
|
1674
|
+
const onKey = (e) => {
|
|
1675
|
+
if (mention && candidates.length) {
|
|
1676
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
1677
|
+
e.preventDefault();
|
|
1678
|
+
const d = e.key === "ArrowDown" ? 1 : -1;
|
|
1679
|
+
setMention({ ...mention, i: (mention.i + d + candidates.length) % candidates.length });
|
|
1680
|
+
return;
|
|
1681
|
+
}
|
|
1682
|
+
if (e.key === "Enter" && !e.nativeEvent.isComposing) {
|
|
1683
|
+
e.preventDefault();
|
|
1684
|
+
pickMention(candidates[mention.i]);
|
|
1685
|
+
return;
|
|
1686
|
+
}
|
|
1687
|
+
if (e.key === "Escape") {
|
|
1688
|
+
e.preventDefault();
|
|
1689
|
+
e.stopPropagation();
|
|
1690
|
+
setMention(null);
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing && e.keyCode !== 229) {
|
|
1695
|
+
e.preventDefault();
|
|
1696
|
+
void send();
|
|
1697
|
+
}
|
|
1698
|
+
};
|
|
1699
|
+
const onPaste = (e) => {
|
|
1700
|
+
const files = Array.from(e.clipboardData.files);
|
|
1701
|
+
if (!files.length) return;
|
|
1702
|
+
e.preventDefault();
|
|
1703
|
+
addFiles(files);
|
|
1704
|
+
};
|
|
1705
|
+
const insertEmoji = (x) => {
|
|
1706
|
+
const el = ta.current;
|
|
1707
|
+
const a = el?.selectionStart ?? text.length, b = el?.selectionEnd ?? text.length;
|
|
1708
|
+
const next = text.slice(0, a) + x + text.slice(b);
|
|
1709
|
+
setText(next);
|
|
1710
|
+
requestAnimationFrame(() => {
|
|
1711
|
+
el?.focus();
|
|
1712
|
+
el?.setSelectionRange(a + x.length, a + x.length);
|
|
1713
|
+
});
|
|
1714
|
+
};
|
|
1715
|
+
const onEmojiKey = (e) => {
|
|
1716
|
+
const btns = Array.from(e.currentTarget.querySelectorAll("button"));
|
|
1717
|
+
const i = btns.indexOf(document.activeElement);
|
|
1718
|
+
const step = { ArrowRight: 1, ArrowLeft: -1, ArrowDown: 10, ArrowUp: -10 }[e.key];
|
|
1719
|
+
if (step) {
|
|
1720
|
+
e.preventDefault();
|
|
1721
|
+
btns[Math.min(btns.length - 1, Math.max(0, i + step))]?.focus();
|
|
1722
|
+
}
|
|
1723
|
+
if (e.key === "Escape") {
|
|
1724
|
+
e.preventDefault();
|
|
1725
|
+
e.stopPropagation();
|
|
1726
|
+
setEmoji(false);
|
|
1727
|
+
ta.current?.focus();
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
if (p.disabledHint) return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "gkim-composer gkim-composer--disabled", children: p.disabledHint });
|
|
1731
|
+
const accept = ["image/jpeg", "image/png", "image/gif", "image/webp", ...canVideo ? ["video/mp4", "video/quicktime"] : []].join(",");
|
|
1732
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "gkim-composer", onPaste, children: [
|
|
1733
|
+
emoji && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "gkim-emoji", role: "dialog", "aria-label": s.emoji, onKeyDown: onEmojiKey, children: EMOJIS.map((x) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", onClick: () => insertEmoji(x), children: x }, x)) }),
|
|
1734
|
+
mention && candidates.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: "gkim-mention-pick", role: "listbox", "aria-label": s.mentionTitle, children: candidates.map((m, i) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
1735
|
+
"li",
|
|
1736
|
+
{
|
|
1737
|
+
role: "option",
|
|
1738
|
+
"aria-selected": i === mention.i,
|
|
1739
|
+
onMouseDown: (e) => {
|
|
1740
|
+
e.preventDefault();
|
|
1741
|
+
pickMention(m);
|
|
1742
|
+
},
|
|
1743
|
+
children: [
|
|
1744
|
+
m.userId === "@all" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "gkim-mention-pick__all", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "group", size: 16 }) }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Avatar, { id: m.userId, name: m.name, url: p.members?.find((x) => x.userId === m.userId)?.avatarUrl, size: 28 }),
|
|
1745
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: m.name })
|
|
1746
|
+
]
|
|
1747
|
+
},
|
|
1748
|
+
m.userId
|
|
1749
|
+
)) }),
|
|
1750
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "gkim-composer__tools", children: [
|
|
1751
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1752
|
+
"button",
|
|
1753
|
+
{
|
|
1754
|
+
type: "button",
|
|
1755
|
+
className: "gkim-iconbtn",
|
|
1756
|
+
"aria-label": s.emoji,
|
|
1757
|
+
"aria-expanded": emoji,
|
|
1758
|
+
onClick: () => setEmoji((v) => !v),
|
|
1759
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "emoji" })
|
|
1760
|
+
}
|
|
1761
|
+
),
|
|
1762
|
+
canImage && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "gkim-iconbtn", "aria-label": s.sendImageOrVideo, onClick: () => media.current?.click(), children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "image" }) }),
|
|
1763
|
+
canFile && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "gkim-iconbtn", "aria-label": s.sendFile, onClick: () => anyFile.current?.click(), children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "file" }) }),
|
|
1764
|
+
moreItems.length > 0 && p.target && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1765
|
+
"button",
|
|
1766
|
+
{
|
|
1767
|
+
type: "button",
|
|
1768
|
+
className: "gkim-iconbtn",
|
|
1769
|
+
"aria-label": s.more,
|
|
1770
|
+
"aria-haspopup": "menu",
|
|
1771
|
+
onClick: (e) => {
|
|
1772
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
1773
|
+
setMore({ x: r.left, y: r.top - 8 });
|
|
1774
|
+
},
|
|
1775
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "plus" })
|
|
1776
|
+
}
|
|
1777
|
+
),
|
|
1778
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1779
|
+
"input",
|
|
1780
|
+
{
|
|
1781
|
+
ref: media,
|
|
1782
|
+
type: "file",
|
|
1783
|
+
hidden: true,
|
|
1784
|
+
multiple: true,
|
|
1785
|
+
accept,
|
|
1786
|
+
onChange: (e) => {
|
|
1787
|
+
addFiles(Array.from(e.target.files ?? []));
|
|
1788
|
+
e.target.value = "";
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
),
|
|
1792
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1793
|
+
"input",
|
|
1794
|
+
{
|
|
1795
|
+
ref: anyFile,
|
|
1796
|
+
type: "file",
|
|
1797
|
+
hidden: true,
|
|
1798
|
+
multiple: true,
|
|
1799
|
+
onChange: (e) => {
|
|
1800
|
+
addFiles(Array.from(e.target.files ?? []));
|
|
1801
|
+
e.target.value = "";
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
)
|
|
1805
|
+
] }),
|
|
1806
|
+
tray.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: "gkim-tray", "aria-label": "附件", children: tray.map((a) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: "gkim-tray__item", children: [
|
|
1807
|
+
a.kind === "image" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("img", { src: thumb(a), alt: "" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "gkim-tray__file", children: [
|
|
1808
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: a.kind === "video" ? "play" : "file", size: 18 }),
|
|
1809
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: a.file.name })
|
|
1810
|
+
] }),
|
|
1811
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1812
|
+
"button",
|
|
1813
|
+
{
|
|
1814
|
+
type: "button",
|
|
1815
|
+
className: "gkim-tray__x",
|
|
1816
|
+
"aria-label": `${s.removeAttachment} ${a.file.name}`,
|
|
1817
|
+
onClick: () => setTray((t) => t.filter((x) => x.id !== a.id)),
|
|
1818
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "close", size: 12 })
|
|
1819
|
+
}
|
|
1820
|
+
)
|
|
1821
|
+
] }, a.id)) }),
|
|
1822
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { className: "gkim-composer__field", children: [
|
|
1823
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "gkim-sr-only", children: s.inputPlaceholder }),
|
|
1824
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1825
|
+
"textarea",
|
|
1826
|
+
{
|
|
1827
|
+
ref: ta,
|
|
1828
|
+
rows: 1,
|
|
1829
|
+
value: text,
|
|
1830
|
+
placeholder: s.inputPlaceholder,
|
|
1831
|
+
"aria-autocomplete": p.members ? "list" : void 0,
|
|
1832
|
+
"aria-expanded": p.members ? !!mention : void 0,
|
|
1833
|
+
onChange: (e) => onChange(e.target.value, e.target.selectionStart ?? e.target.value.length),
|
|
1834
|
+
onKeyDown: onKey,
|
|
1835
|
+
onBlur: () => setMention(null)
|
|
1836
|
+
}
|
|
1837
|
+
)
|
|
1838
|
+
] }),
|
|
1839
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "gkim-composer__foot", children: [
|
|
1840
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "gkim-composer__hint", children: s.enterToSend }),
|
|
1841
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1842
|
+
"button",
|
|
1843
|
+
{
|
|
1844
|
+
type: "button",
|
|
1845
|
+
className: "gkim-btn gkim-btn--primary gkim-composer__send",
|
|
1846
|
+
disabled: busy || !text.trim() && !tray.length,
|
|
1847
|
+
onClick: send,
|
|
1848
|
+
children: s.send
|
|
1849
|
+
}
|
|
1850
|
+
)
|
|
1851
|
+
] }),
|
|
1852
|
+
more && p.target && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1853
|
+
Menu,
|
|
1854
|
+
{
|
|
1855
|
+
x: more.x,
|
|
1856
|
+
y: more.y,
|
|
1857
|
+
onClose: closeMore,
|
|
1858
|
+
label: s.more,
|
|
1859
|
+
entries: moreItems.map((it) => ({ label: it.label, icon: it.icon, onSelect: () => it.onClick(p.target) }))
|
|
1860
|
+
}
|
|
1861
|
+
)
|
|
1862
|
+
] });
|
|
1863
|
+
});
|
|
1864
|
+
|
|
1865
|
+
// src/ui/chat/MessageList.tsx
|
|
1866
|
+
var import_react11 = require("react");
|
|
1867
|
+
|
|
1868
|
+
// src/ui/chat/MessageRow.tsx
|
|
1869
|
+
var import_react10 = require("react");
|
|
1870
|
+
|
|
1871
|
+
// src/ui/chat/bubbles.tsx
|
|
1872
|
+
var import_react9 = require("react");
|
|
1873
|
+
var import_im = require("@guokit-dev/im");
|
|
1874
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1875
|
+
function useAsyncUrl(load) {
|
|
1876
|
+
const [url, setUrl] = (0, import_react9.useState)(null);
|
|
1877
|
+
const enabled = load !== null;
|
|
1878
|
+
(0, import_react9.useEffect)(() => {
|
|
1879
|
+
if (!load) return;
|
|
1880
|
+
let alive = true;
|
|
1881
|
+
Promise.resolve().then(load).then((u) => {
|
|
1882
|
+
if (alive) setUrl(u);
|
|
1883
|
+
}, () => {
|
|
1884
|
+
});
|
|
1885
|
+
return () => {
|
|
1886
|
+
alive = false;
|
|
1887
|
+
};
|
|
1888
|
+
}, [enabled]);
|
|
1889
|
+
return url;
|
|
1890
|
+
}
|
|
1891
|
+
function fit(w, h, max = 180, min = 80) {
|
|
1892
|
+
const ww = typeof w === "number" && w > 0 ? w : max;
|
|
1893
|
+
const hh = typeof h === "number" && h > 0 ? h : max;
|
|
1894
|
+
const scale = max / Math.max(ww, hh);
|
|
1895
|
+
const clamp = (v) => Math.min(max, Math.max(min, v));
|
|
1896
|
+
return { width: clamp(ww * scale), height: clamp(hh * scale) };
|
|
1897
|
+
}
|
|
1898
|
+
function formatFileSize(bytes) {
|
|
1899
|
+
if (bytes == null) return "";
|
|
1900
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
1901
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
1902
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
1903
|
+
}
|
|
1904
|
+
function formatDuration(sec) {
|
|
1905
|
+
if (sec == null) return "";
|
|
1906
|
+
const s = Math.round(sec);
|
|
1907
|
+
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
|
|
1908
|
+
}
|
|
1909
|
+
function openExternal(url) {
|
|
1910
|
+
window.open(url, "_blank", "noopener");
|
|
1911
|
+
}
|
|
1912
|
+
var MENTION = /@[^\s@]+/g;
|
|
1913
|
+
function TextBubble({ message: m, text, children }) {
|
|
1914
|
+
const raw = text ?? (typeof m.content.text === "string" ? m.content.text : "");
|
|
1915
|
+
let body = children ?? raw;
|
|
1916
|
+
if (!children && m.groupId && Array.isArray(m.content.at)) {
|
|
1917
|
+
const out = [];
|
|
1918
|
+
let i = 0;
|
|
1919
|
+
for (const x of raw.matchAll(MENTION)) {
|
|
1920
|
+
if (x.index > i) out.push(raw.slice(i, x.index));
|
|
1921
|
+
out.push(/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-mention", children: x[0] }, x.index));
|
|
1922
|
+
i = x.index + x[0].length;
|
|
1923
|
+
}
|
|
1924
|
+
if (i < raw.length) out.push(raw.slice(i));
|
|
1925
|
+
body = out;
|
|
1926
|
+
}
|
|
1927
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: `gkim-bubble gkim-bubble--text${m.isSelf ? " gkim-bubble--self" : ""}`, children: body });
|
|
1928
|
+
}
|
|
1929
|
+
function ProgressMask({ p }) {
|
|
1930
|
+
if (p == null) return null;
|
|
1931
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "gkim-media__mask", children: [
|
|
1932
|
+
Math.round(p * 100),
|
|
1933
|
+
"%"
|
|
1934
|
+
] });
|
|
1935
|
+
}
|
|
1936
|
+
function ImageBubble({ message: m, localUrl, progress, onImageClick }) {
|
|
1937
|
+
const { im, strings: s } = useImUi();
|
|
1938
|
+
const sent = m.status === "sent";
|
|
1939
|
+
const remote = useAsyncUrl(sent && !localUrl ? () => im.imageUrl(m) : null);
|
|
1940
|
+
const [broken, setBroken] = (0, import_react9.useState)(false);
|
|
1941
|
+
const src = localUrl ?? remote;
|
|
1942
|
+
const size = fit(m.content.width, m.content.height);
|
|
1943
|
+
const img = src && !broken ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { src, alt: s.image, onError: () => setBroken(true) }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-media__ph", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "image" }) });
|
|
1944
|
+
const style = { width: size.width, height: size.height };
|
|
1945
|
+
if (sent && onImageClick) {
|
|
1946
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("button", { type: "button", className: "gkim-media", style, "aria-label": s.image, onClick: () => onImageClick(m), children: [
|
|
1947
|
+
img,
|
|
1948
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ProgressMask, { p: progress })
|
|
1949
|
+
] });
|
|
1950
|
+
}
|
|
1951
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "gkim-media", style, children: [
|
|
1952
|
+
img,
|
|
1953
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ProgressMask, { p: progress })
|
|
1954
|
+
] });
|
|
1955
|
+
}
|
|
1956
|
+
function VideoBubble({ message: m, progress, onVideoClick }) {
|
|
1957
|
+
const { im, strings: s } = useImUi();
|
|
1958
|
+
const sent = m.status === "sent";
|
|
1959
|
+
const cover = useAsyncUrl(sent ? () => im.videoCoverUrl(m) : null);
|
|
1960
|
+
const size = fit(m.content.width, m.content.height, 200);
|
|
1961
|
+
const inner = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1962
|
+
cover ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { src: cover, alt: "" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-media__dark" }),
|
|
1963
|
+
progress == null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-media__play", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "play", size: 28 }) }),
|
|
1964
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ProgressMask, { p: progress }),
|
|
1965
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-media__dur", children: formatDuration(m.duration) })
|
|
1966
|
+
] });
|
|
1967
|
+
const style = { width: size.width, height: size.height };
|
|
1968
|
+
if (sent && onVideoClick) {
|
|
1969
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "gkim-media", style, "aria-label": s.video, onClick: () => onVideoClick(m), children: inner });
|
|
1970
|
+
}
|
|
1971
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-media", style, children: inner });
|
|
1972
|
+
}
|
|
1973
|
+
function VoiceBubble({ message: m, playing, onVoiceClick }) {
|
|
1974
|
+
const { strings: s } = useImUi();
|
|
1975
|
+
const sec = m.duration ?? 0;
|
|
1976
|
+
const width = 80 + Math.min(sec, 60) * 2;
|
|
1977
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1978
|
+
"button",
|
|
1979
|
+
{
|
|
1980
|
+
type: "button",
|
|
1981
|
+
className: `gkim-bubble gkim-bubble--voice${m.isSelf ? " gkim-bubble--self" : ""}`,
|
|
1982
|
+
style: { width },
|
|
1983
|
+
"aria-label": `${s.voice} ${formatDuration(m.duration)}`,
|
|
1984
|
+
"aria-pressed": playing,
|
|
1985
|
+
disabled: m.status !== "sent",
|
|
1986
|
+
onClick: () => onVoiceClick?.(m),
|
|
1987
|
+
children: [
|
|
1988
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: playing ? "pause" : "play", size: 16 }),
|
|
1989
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
1990
|
+
Math.round(sec),
|
|
1991
|
+
"″"
|
|
1992
|
+
] })
|
|
1993
|
+
]
|
|
1994
|
+
}
|
|
1995
|
+
);
|
|
1996
|
+
}
|
|
1997
|
+
function FileBubble({ message: m, progress }) {
|
|
1998
|
+
const { im, strings: s } = useImUi();
|
|
1999
|
+
const name = m.fileName ?? s.file;
|
|
2000
|
+
const dot = name.lastIndexOf(".");
|
|
2001
|
+
const ext = dot > 0 && dot < name.length - 1 ? name.slice(dot + 1).toUpperCase().slice(0, 4) : "?";
|
|
2002
|
+
const open = async () => {
|
|
2003
|
+
const url = await im.fileUrl(m).catch(() => null);
|
|
2004
|
+
if (url) openExternal(url);
|
|
2005
|
+
};
|
|
2006
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("button", { type: "button", className: "gkim-framed gkim-file", disabled: m.status !== "sent", onClick: open, children: [
|
|
2007
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "gkim-file__info", children: [
|
|
2008
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-file__name", children: name }),
|
|
2009
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-file__size", children: formatFileSize(m.fileSize) }),
|
|
2010
|
+
progress != null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-progress", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: { width: `${Math.round(progress * 100)}%` } }) })
|
|
2011
|
+
] }),
|
|
2012
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-file__ext", children: ext })
|
|
2013
|
+
] });
|
|
2014
|
+
}
|
|
2015
|
+
function LocationBubble({ message: m }) {
|
|
2016
|
+
const { strings: s, callbacks } = useImUi();
|
|
2017
|
+
const name = typeof m.content.name === "string" ? m.content.name.trim() : "";
|
|
2018
|
+
const address = typeof m.content.address === "string" ? m.content.address.trim() : "";
|
|
2019
|
+
const inner = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
2020
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "gkim-location__text", children: [
|
|
2021
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-location__name", children: name || s.location }),
|
|
2022
|
+
address && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-location__addr", children: address })
|
|
2023
|
+
] }),
|
|
2024
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-location__map", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "location", size: 32 }) })
|
|
2025
|
+
] });
|
|
2026
|
+
const onTap = callbacks.onLocationTap;
|
|
2027
|
+
if (!onTap) return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "gkim-framed gkim-location", children: inner });
|
|
2028
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "gkim-framed gkim-location", onClick: () => onTap(m), children: inner });
|
|
2029
|
+
}
|
|
2030
|
+
function CardBubble({ message: m, card }) {
|
|
2031
|
+
const { strings: s, callbacks } = useImUi();
|
|
2032
|
+
const link = card.webLink ?? card.appLink;
|
|
2033
|
+
const onClick = callbacks.onCardTap ? () => callbacks.onCardTap(card, m) : link ? () => openExternal(link) : void 0;
|
|
2034
|
+
const inner = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
2035
|
+
card.kind != null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-card__kind", children: s.cardKinds[card.kind] ?? s.cardKindOther }),
|
|
2036
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "gkim-card__main", children: [
|
|
2037
|
+
card.image && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { className: "gkim-card__img", src: card.image, alt: "" }),
|
|
2038
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "gkim-card__text", children: [
|
|
2039
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-card__title", children: card.title }),
|
|
2040
|
+
card.subtitle && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-card__sub", children: card.subtitle })
|
|
2041
|
+
] })
|
|
2042
|
+
] }),
|
|
2043
|
+
card.fields.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-card__fields", children: card.fields.slice(0, 4).map((f, i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "gkim-card__field", children: [
|
|
2044
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: f.label }),
|
|
2045
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: f.value })
|
|
2046
|
+
] }, i)) })
|
|
2047
|
+
] });
|
|
2048
|
+
if (!onClick) return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "gkim-framed gkim-card", children: inner });
|
|
2049
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "gkim-framed gkim-card", onClick, children: inner });
|
|
2050
|
+
}
|
|
2051
|
+
function MessageContent(props) {
|
|
2052
|
+
const { messageRenderers, strings: s } = useImUi();
|
|
2053
|
+
const m = props.message;
|
|
2054
|
+
const custom = messageRenderers[m.type]?.(m);
|
|
2055
|
+
if (custom != null) return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: custom });
|
|
2056
|
+
switch (m.type) {
|
|
2057
|
+
case "text":
|
|
2058
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TextBubble, { message: m });
|
|
2059
|
+
case "image":
|
|
2060
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ImageBubble, { ...props });
|
|
2061
|
+
case "file":
|
|
2062
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FileBubble, { ...props });
|
|
2063
|
+
case "location":
|
|
2064
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(LocationBubble, { ...props });
|
|
2065
|
+
case "video":
|
|
2066
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(VideoBubble, { ...props });
|
|
2067
|
+
case "voice":
|
|
2068
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(VoiceBubble, { ...props });
|
|
2069
|
+
case "custom": {
|
|
2070
|
+
const card = (0, import_im.messageCard)(m);
|
|
2071
|
+
if (card) return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CardBubble, { message: m, card });
|
|
2072
|
+
const desc = m.content.desc;
|
|
2073
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TextBubble, { message: m, text: typeof desc === "string" && desc ? desc : s.unsupported });
|
|
2074
|
+
}
|
|
2075
|
+
default:
|
|
2076
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TextBubble, { message: m, text: s.unsupported });
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
// src/ui/chat/MessageRow.tsx
|
|
2081
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
2082
|
+
function CenterTip({ text }) {
|
|
2083
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "gkim-tip", children: text });
|
|
2084
|
+
}
|
|
2085
|
+
var MessageRow = (0, import_react10.memo)(function MessageRow2(p) {
|
|
2086
|
+
const { strings: s } = useImUi();
|
|
2087
|
+
const { toast } = useFeedback();
|
|
2088
|
+
const m = p.message;
|
|
2089
|
+
const self = m.isSelf;
|
|
2090
|
+
const tappable = !self && !m.from.startsWith("@") && p.onAvatarClick;
|
|
2091
|
+
let status = null;
|
|
2092
|
+
if (m.status === "sending") status = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "gkim-row__sending", role: "img", "aria-label": "…" });
|
|
2093
|
+
else if (m.status === "failed" || m.status === "rejected") {
|
|
2094
|
+
const rejected = m.status === "rejected";
|
|
2095
|
+
status = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2096
|
+
"button",
|
|
2097
|
+
{
|
|
2098
|
+
type: "button",
|
|
2099
|
+
className: "gkim-row__status",
|
|
2100
|
+
"aria-label": rejected ? s.sendRejected : s.operationFailed,
|
|
2101
|
+
title: rejected ? m.errorMessage || s.sendRejected : void 0,
|
|
2102
|
+
onClick: () => rejected ? toast(m.errorMessage || s.sendRejected) : p.onResend?.(m),
|
|
2103
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: rejected ? "alert" : "retry", size: 18 })
|
|
2104
|
+
}
|
|
2105
|
+
);
|
|
2106
|
+
}
|
|
2107
|
+
const press = (0, import_react10.useRef)(null);
|
|
2108
|
+
const touchStart = (e) => {
|
|
2109
|
+
if (!p.onMenu) return;
|
|
2110
|
+
const t = e.touches[0];
|
|
2111
|
+
const x = t.clientX, y = t.clientY;
|
|
2112
|
+
press.current = { x, y, t: setTimeout(() => {
|
|
2113
|
+
press.current = null;
|
|
2114
|
+
p.onMenu(m, x, y);
|
|
2115
|
+
}, 500) };
|
|
2116
|
+
};
|
|
2117
|
+
const touchMove = (e) => {
|
|
2118
|
+
const c = press.current, t = e.touches[0];
|
|
2119
|
+
if (c && Math.hypot(t.clientX - c.x, t.clientY - c.y) > 10) {
|
|
2120
|
+
clearTimeout(c.t);
|
|
2121
|
+
press.current = null;
|
|
2122
|
+
}
|
|
2123
|
+
};
|
|
2124
|
+
const touchEnd = () => {
|
|
2125
|
+
if (press.current) {
|
|
2126
|
+
clearTimeout(press.current.t);
|
|
2127
|
+
press.current = null;
|
|
2128
|
+
}
|
|
2129
|
+
};
|
|
2130
|
+
const menu = (e) => {
|
|
2131
|
+
if (!p.onMenu) return;
|
|
2132
|
+
e.preventDefault();
|
|
2133
|
+
p.onMenu(m, e.clientX, e.clientY);
|
|
2134
|
+
};
|
|
2135
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `gkim-row${self ? " gkim-row--self" : ""}`, "data-cid": m.clientMsgId, children: [
|
|
2136
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2137
|
+
Avatar,
|
|
2138
|
+
{
|
|
2139
|
+
id: m.from,
|
|
2140
|
+
name: p.senderName,
|
|
2141
|
+
url: p.senderAvatarUrl,
|
|
2142
|
+
onClick: tappable ? () => p.onAvatarClick(m.from) : void 0
|
|
2143
|
+
}
|
|
2144
|
+
),
|
|
2145
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "gkim-row__col", children: [
|
|
2146
|
+
p.showName && !self && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "gkim-row__name", children: p.senderName }),
|
|
2147
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "gkim-row__line", children: [
|
|
2148
|
+
self && status,
|
|
2149
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "gkim-row__bubble", onContextMenu: menu, onTouchStart: touchStart, onTouchMove: touchMove, onTouchEnd: touchEnd, children: [
|
|
2150
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2151
|
+
MessageContent,
|
|
2152
|
+
{
|
|
2153
|
+
message: m,
|
|
2154
|
+
localUrl: p.localUrl,
|
|
2155
|
+
progress: p.progress,
|
|
2156
|
+
playing: p.playing,
|
|
2157
|
+
onImageClick: p.onImageClick,
|
|
2158
|
+
onVideoClick: p.onVideoClick,
|
|
2159
|
+
onVoiceClick: p.onVoiceClick
|
|
2160
|
+
}
|
|
2161
|
+
),
|
|
2162
|
+
p.hoverBar
|
|
2163
|
+
] }),
|
|
2164
|
+
!self && status
|
|
2165
|
+
] }),
|
|
2166
|
+
p.read !== null && self && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: `gkim-row__meta${p.read ? "" : " gkim-row__meta--unread"}`, children: p.read ? s.read : s.unreadMark }),
|
|
2167
|
+
m.isBot && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "gkim-row__meta", children: s.aiGenerated })
|
|
2168
|
+
] })
|
|
2169
|
+
] });
|
|
2170
|
+
});
|
|
2171
|
+
|
|
2172
|
+
// src/ui/chat/MessageList.tsx
|
|
2173
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
2174
|
+
var FIVE_MIN = 5 * 6e4;
|
|
2175
|
+
function MessageList({ ctl, snap, isGroup, nameOf, renderRow, scrollRef }) {
|
|
2176
|
+
const { im, strings: s } = useImUi();
|
|
2177
|
+
const ref = (0, import_react11.useRef)(null);
|
|
2178
|
+
const me = im.currentUserId;
|
|
2179
|
+
const nearTop = (el) => el.scrollHeight - el.clientHeight + el.scrollTop < 200;
|
|
2180
|
+
const check = (0, import_react11.useCallback)(() => {
|
|
2181
|
+
const el = ref.current;
|
|
2182
|
+
if (el && snap.hasMore && !snap.loadingMore && nearTop(el)) ctl.loadMore();
|
|
2183
|
+
}, [ctl, snap.hasMore, snap.loadingMore]);
|
|
2184
|
+
(0, import_react11.useLayoutEffect)(() => {
|
|
2185
|
+
check();
|
|
2186
|
+
}, [check, snap.messages]);
|
|
2187
|
+
(0, import_react11.useEffect)(() => {
|
|
2188
|
+
scrollRef.current = () => {
|
|
2189
|
+
if (ref.current) ref.current.scrollTop = 0;
|
|
2190
|
+
};
|
|
2191
|
+
return () => {
|
|
2192
|
+
scrollRef.current = null;
|
|
2193
|
+
};
|
|
2194
|
+
}, [scrollRef]);
|
|
2195
|
+
(0, import_react11.useEffect)(() => ctl.onNewMessage((m) => {
|
|
2196
|
+
const el = ref.current;
|
|
2197
|
+
if (el && (m.isSelf || el.scrollTop > -120)) el.scrollTop = 0;
|
|
2198
|
+
}), [ctl]);
|
|
2199
|
+
const now = Date.now();
|
|
2200
|
+
const items = [];
|
|
2201
|
+
let prev = null;
|
|
2202
|
+
for (const m of snap.messages) {
|
|
2203
|
+
if (prev === null || m.createdAt - prev >= FIVE_MIN) {
|
|
2204
|
+
items.push(/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CenterTip, { text: formatMessageTime(m.createdAt, s, now) }, `t-${m.clientMsgId}`));
|
|
2205
|
+
}
|
|
2206
|
+
prev = m.createdAt;
|
|
2207
|
+
if (isTipMessage(m)) {
|
|
2208
|
+
items.push(/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CenterTip, { text: tipText(m, s, { nameOf, me, isGroup }) }, m.clientMsgId));
|
|
2209
|
+
continue;
|
|
2210
|
+
}
|
|
2211
|
+
items.push(/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react11.Fragment, { children: renderRow(m) }, m.clientMsgId));
|
|
2212
|
+
}
|
|
2213
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "gkim-msglist", ref, onScroll: check, role: "log", "aria-live": "polite", "aria-relevant": "additions", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "gkim-msglist__inner", children: [
|
|
2214
|
+
snap.loadingMore && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "gkim-msglist__spinner", role: "img", "aria-label": "…" }),
|
|
2215
|
+
items
|
|
2216
|
+
] }) });
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
// src/ui/chat/ChatPage.tsx
|
|
2220
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
2221
|
+
var noSub = () => () => {
|
|
2222
|
+
};
|
|
2223
|
+
var EMPTY_SNAP = {
|
|
2224
|
+
messages: [],
|
|
2225
|
+
loading: true,
|
|
2226
|
+
loadingMore: false,
|
|
2227
|
+
hasMore: false,
|
|
2228
|
+
peerTyping: false,
|
|
2229
|
+
conversation: null,
|
|
2230
|
+
conversationId: null,
|
|
2231
|
+
quit: false,
|
|
2232
|
+
peerReadSeq: null,
|
|
2233
|
+
features: null,
|
|
2234
|
+
progress: {},
|
|
2235
|
+
localFiles: {}
|
|
2236
|
+
};
|
|
2237
|
+
var EMPTY_MEMBERS = /* @__PURE__ */ new Map();
|
|
2238
|
+
function targetOf(p) {
|
|
2239
|
+
const n = Number(p.conversation != null) + Number(p.peer != null) + Number(p.group != null);
|
|
2240
|
+
if (n !== 1) throw new TypeError("ImChat:conversation、peer、group 须且只能传一个");
|
|
2241
|
+
if (p.conversation) return { conversation: p.conversation };
|
|
2242
|
+
if (p.peer != null) {
|
|
2243
|
+
if (!p.peer) throw new TypeError("ImChat:peer 不能为空");
|
|
2244
|
+
return { peer: p.peer };
|
|
2245
|
+
}
|
|
2246
|
+
if (!p.group) throw new TypeError("ImChat:group 不能为空");
|
|
2247
|
+
return { group: p.group };
|
|
2248
|
+
}
|
|
2249
|
+
function ImChat(props) {
|
|
2250
|
+
const target = targetOf(props);
|
|
2251
|
+
const { im, me, strings: s, callbacks } = useImUi();
|
|
2252
|
+
const nav = useNavContext();
|
|
2253
|
+
const { toast } = useFeedback();
|
|
2254
|
+
const key = "conversation" in target ? `c${target.conversation.id}` : "group" in target ? `g${target.group}` : `p${target.peer}`;
|
|
2255
|
+
const isGroup = "group" in target || "conversation" in target && target.conversation.group !== null;
|
|
2256
|
+
const groupId = "group" in target ? target.group : "conversation" in target ? target.conversation.group?.groupId ?? null : null;
|
|
2257
|
+
const [ctl, setCtl] = (0, import_react12.useState)(null);
|
|
2258
|
+
(0, import_react12.useEffect)(() => {
|
|
2259
|
+
const c = new ChatController(im, target);
|
|
2260
|
+
setCtl(c);
|
|
2261
|
+
void c.start();
|
|
2262
|
+
const vis = () => c.setActive(document.visibilityState === "visible");
|
|
2263
|
+
document.addEventListener("visibilitychange", vis);
|
|
2264
|
+
return () => {
|
|
2265
|
+
document.removeEventListener("visibilitychange", vis);
|
|
2266
|
+
c.dispose();
|
|
2267
|
+
};
|
|
2268
|
+
}, [im, key]);
|
|
2269
|
+
const snap = (0, import_react12.useSyncExternalStore)(ctl?.subscribe ?? noSub, ctl?.getSnapshot ?? (() => EMPTY_SNAP));
|
|
2270
|
+
const [members, setMembers] = (0, import_react12.useState)(null);
|
|
2271
|
+
(0, import_react12.useEffect)(() => {
|
|
2272
|
+
if (!groupId) return;
|
|
2273
|
+
const m = new MemberCache(im, groupId);
|
|
2274
|
+
setMembers(m);
|
|
2275
|
+
m.start();
|
|
2276
|
+
return () => {
|
|
2277
|
+
m.dispose();
|
|
2278
|
+
setMembers(null);
|
|
2279
|
+
};
|
|
2280
|
+
}, [im, groupId]);
|
|
2281
|
+
const memberMap = (0, import_react12.useSyncExternalStore)(members?.subscribe ?? noSub, members?.getSnapshot ?? (() => EMPTY_MEMBERS));
|
|
2282
|
+
const memberList = (0, import_react12.useMemo)(() => [...memberMap.values()], [memberMap]);
|
|
2283
|
+
const urls = (0, import_react12.useMemo)(() => new ObjectUrlRegistry(), []);
|
|
2284
|
+
(0, import_react12.useEffect)(() => () => urls.releaseAll(), [urls]);
|
|
2285
|
+
urls.sync(snap.localFiles);
|
|
2286
|
+
const conv = snap.conversation;
|
|
2287
|
+
const myId = im.currentUserId;
|
|
2288
|
+
const nameOf = (0, import_react12.useCallback)((id) => {
|
|
2289
|
+
const mm = memberMap.get(id);
|
|
2290
|
+
if (mm && mm.nickname) return mm.nickname;
|
|
2291
|
+
if (id === myId) return me.nickname || id;
|
|
2292
|
+
if (conv?.peer && conv.peer.userId === id) return conversationTitle(conv, s);
|
|
2293
|
+
return id;
|
|
2294
|
+
}, [memberMap, myId, me.nickname, conv, s]);
|
|
2295
|
+
const avatarOf = (0, import_react12.useCallback)((id) => {
|
|
2296
|
+
const mm = memberMap.get(id);
|
|
2297
|
+
if (mm?.avatarUrl) return mm.avatarUrl;
|
|
2298
|
+
if (id === myId) return me.avatarUrl ?? "";
|
|
2299
|
+
return conv?.peer && conv.peer.userId === id ? conv.peer.avatarUrl : "";
|
|
2300
|
+
}, [memberMap, myId, me.avatarUrl, conv]);
|
|
2301
|
+
const audio = (0, import_react12.useRef)(null);
|
|
2302
|
+
const [playing, setPlaying] = (0, import_react12.useState)(null);
|
|
2303
|
+
(0, import_react12.useEffect)(() => () => {
|
|
2304
|
+
audio.current?.pause();
|
|
2305
|
+
}, []);
|
|
2306
|
+
const onVoice = (0, import_react12.useCallback)(async (m) => {
|
|
2307
|
+
const a = audio.current ?? (audio.current = new Audio());
|
|
2308
|
+
a.onended = () => setPlaying(null);
|
|
2309
|
+
if (playing === m.clientMsgId) {
|
|
2310
|
+
a.pause();
|
|
2311
|
+
setPlaying(null);
|
|
2312
|
+
return;
|
|
2313
|
+
}
|
|
2314
|
+
a.pause();
|
|
2315
|
+
const url = await im.voiceUrl(m).catch(() => null);
|
|
2316
|
+
if (!url) return;
|
|
2317
|
+
a.src = url;
|
|
2318
|
+
setPlaying(m.clientMsgId);
|
|
2319
|
+
a.play().catch(() => setPlaying(null));
|
|
2320
|
+
}, [im, playing]);
|
|
2321
|
+
const onImage = (0, import_react12.useCallback)((m) => {
|
|
2322
|
+
const images = snap.messages.filter((x) => x.type === "image" && x.status === "sent");
|
|
2323
|
+
const index = images.findIndex((x) => x.clientMsgId === m.clientMsgId);
|
|
2324
|
+
if (index >= 0) nav.open({ name: "imageViewer", images, index });
|
|
2325
|
+
}, [snap.messages, nav]);
|
|
2326
|
+
const onVideo = (0, import_react12.useCallback)((m) => {
|
|
2327
|
+
audio.current?.pause();
|
|
2328
|
+
setPlaying(null);
|
|
2329
|
+
nav.open({ name: "videoPlayer", message: m });
|
|
2330
|
+
}, [nav]);
|
|
2331
|
+
const onResend = (0, import_react12.useCallback)((m) => {
|
|
2332
|
+
ctl?.resend(m).catch(() => toast(s.sendRejected));
|
|
2333
|
+
}, [ctl, toast, s]);
|
|
2334
|
+
const onAvatar = callbacks.onAvatarTap;
|
|
2335
|
+
const scrollToLatest = (0, import_react12.useRef)(null);
|
|
2336
|
+
const send = (0, import_react12.useCallback)(async (text, at) => {
|
|
2337
|
+
if (!ctl) return;
|
|
2338
|
+
try {
|
|
2339
|
+
const m = await ctl.sendText(text, at);
|
|
2340
|
+
scrollToLatest.current?.();
|
|
2341
|
+
if (m.status === "rejected") toast(m.errorMessage || s.sendRejected);
|
|
2342
|
+
} catch {
|
|
2343
|
+
toast(s.operationFailed);
|
|
2344
|
+
}
|
|
2345
|
+
}, [ctl, toast, s]);
|
|
2346
|
+
const sendFile = (0, import_react12.useCallback)(async (a) => {
|
|
2347
|
+
if (!ctl) return;
|
|
2348
|
+
try {
|
|
2349
|
+
let m;
|
|
2350
|
+
if (a.kind === "image") m = await ctl.sendImage(a.file);
|
|
2351
|
+
else if (a.kind === "video") {
|
|
2352
|
+
const meta = await readVideoMeta(a.file);
|
|
2353
|
+
m = meta ? await ctl.sendVideo(a.file, meta) : await ctl.sendFile(a.file, a.file.name);
|
|
2354
|
+
} else m = await ctl.sendFile(a.file, a.file.name);
|
|
2355
|
+
scrollToLatest.current?.();
|
|
2356
|
+
if (m.status === "rejected") toast(m.errorMessage || s.sendRejected);
|
|
2357
|
+
} catch (e) {
|
|
2358
|
+
toast(e instanceof RangeError ? e.message : s.operationFailed);
|
|
2359
|
+
}
|
|
2360
|
+
}, [ctl, toast, s]);
|
|
2361
|
+
const composer = (0, import_react12.useRef)(null);
|
|
2362
|
+
const [dragging, setDragging] = (0, import_react12.useState)(false);
|
|
2363
|
+
const depth = (0, import_react12.useRef)(0);
|
|
2364
|
+
const hasFiles = (e) => Array.from(e.dataTransfer.types).includes("Files");
|
|
2365
|
+
const dropProps = snap.quit ? {} : {
|
|
2366
|
+
onDragEnter: (e) => {
|
|
2367
|
+
if (!hasFiles(e)) return;
|
|
2368
|
+
e.preventDefault();
|
|
2369
|
+
depth.current++;
|
|
2370
|
+
setDragging(true);
|
|
2371
|
+
},
|
|
2372
|
+
onDragOver: (e) => {
|
|
2373
|
+
if (hasFiles(e)) e.preventDefault();
|
|
2374
|
+
},
|
|
2375
|
+
onDragLeave: () => {
|
|
2376
|
+
if (--depth.current <= 0) {
|
|
2377
|
+
depth.current = 0;
|
|
2378
|
+
setDragging(false);
|
|
2379
|
+
}
|
|
2380
|
+
},
|
|
2381
|
+
onDrop: (e) => {
|
|
2382
|
+
if (!hasFiles(e)) return;
|
|
2383
|
+
e.preventDefault();
|
|
2384
|
+
depth.current = 0;
|
|
2385
|
+
setDragging(false);
|
|
2386
|
+
composer.current?.addFiles(Array.from(e.dataTransfer.files));
|
|
2387
|
+
}
|
|
2388
|
+
};
|
|
2389
|
+
const [menu, setMenu] = (0, import_react12.useState)(null);
|
|
2390
|
+
const closeMenu = (0, import_react12.useCallback)(() => setMenu(null), []);
|
|
2391
|
+
const { menuItems } = useImUi();
|
|
2392
|
+
const recallMinutes = snap.features?.recallMinutes ?? 0;
|
|
2393
|
+
const entriesFor = (0, import_react12.useCallback)((m) => {
|
|
2394
|
+
const out = [];
|
|
2395
|
+
if (m.type === "text") {
|
|
2396
|
+
out.push({ label: s.copy, icon: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Icon, { name: "copy", size: 16 }), onSelect: () => {
|
|
2397
|
+
navigator.clipboard?.writeText(typeof m.content.text === "string" ? m.content.text : "").then(() => toast(s.copied), () => toast(s.operationFailed));
|
|
2398
|
+
} });
|
|
2399
|
+
}
|
|
2400
|
+
if (m.isSelf && m.id !== null && m.status === "sent" && recallMinutes > 0 && Date.now() - m.createdAt < recallMinutes * 6e4) {
|
|
2401
|
+
out.push({ label: s.recall, icon: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Icon, { name: "recall", size: 16 }), onSelect: () => {
|
|
2402
|
+
ctl?.recall(m).catch((e) => toast(e instanceof import_im2.ImApiError && e.message ? e.message : s.operationFailed));
|
|
2403
|
+
} });
|
|
2404
|
+
}
|
|
2405
|
+
if (!m.isSelf && m.id !== null) {
|
|
2406
|
+
out.push({ label: s.report, icon: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Icon, { name: "report", size: 16 }), onSelect: () => {
|
|
2407
|
+
nav.open({ name: "report", target: m.from, title: s.report, messageIds: [m.id] });
|
|
2408
|
+
} });
|
|
2409
|
+
}
|
|
2410
|
+
for (const it of menuItems?.(m) ?? []) out.push({ label: it.label, icon: it.icon, onSelect: () => it.onClick(m) });
|
|
2411
|
+
return out;
|
|
2412
|
+
}, [s, toast, recallMinutes, ctl, nav, menuItems]);
|
|
2413
|
+
const onMenu = (0, import_react12.useCallback)((m, x, y) => {
|
|
2414
|
+
if (entriesFor(m).length) setMenu({ m, x, y });
|
|
2415
|
+
}, [entriesFor]);
|
|
2416
|
+
const hoverBar = (m) => {
|
|
2417
|
+
const all = entriesFor(m);
|
|
2418
|
+
if (!all.length || m.status !== "sent") return null;
|
|
2419
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "gkim-hoverbar", role: "toolbar", "aria-label": s.more, children: [
|
|
2420
|
+
all.slice(0, 2).map((e, i) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "gkim-hoverbar__btn", "aria-label": e.label, title: e.label, onClick: e.onSelect, children: e.icon }, i)),
|
|
2421
|
+
all.length > 2 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2422
|
+
"button",
|
|
2423
|
+
{
|
|
2424
|
+
type: "button",
|
|
2425
|
+
className: "gkim-hoverbar__btn",
|
|
2426
|
+
"aria-label": s.more,
|
|
2427
|
+
title: s.more,
|
|
2428
|
+
"aria-haspopup": "menu",
|
|
2429
|
+
onClick: (ev) => {
|
|
2430
|
+
const r = ev.currentTarget.getBoundingClientRect();
|
|
2431
|
+
setMenu({ m, x: r.left, y: r.bottom + 4 });
|
|
2432
|
+
},
|
|
2433
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Icon, { name: "more", size: 16 })
|
|
2434
|
+
}
|
|
2435
|
+
)
|
|
2436
|
+
] });
|
|
2437
|
+
};
|
|
2438
|
+
const peerReadSeq = snap.peerReadSeq;
|
|
2439
|
+
const renderRow = (m) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2440
|
+
MessageRow,
|
|
2441
|
+
{
|
|
2442
|
+
message: m,
|
|
2443
|
+
senderName: nameOf(m.from),
|
|
2444
|
+
senderAvatarUrl: avatarOf(m.from),
|
|
2445
|
+
showName: isGroup,
|
|
2446
|
+
read: m.isSelf && peerReadSeq !== null && m.seq !== null ? m.seq <= peerReadSeq : null,
|
|
2447
|
+
localUrl: urls.get(m.clientMsgId),
|
|
2448
|
+
progress: snap.progress[m.clientMsgId],
|
|
2449
|
+
playing: playing === m.clientMsgId,
|
|
2450
|
+
onResend,
|
|
2451
|
+
onAvatarClick: onAvatar,
|
|
2452
|
+
onImageClick: onImage,
|
|
2453
|
+
onVideoClick: onVideo,
|
|
2454
|
+
onVoiceClick: onVoice,
|
|
2455
|
+
onMenu,
|
|
2456
|
+
hoverBar: hoverBar(m)
|
|
2457
|
+
}
|
|
2458
|
+
);
|
|
2459
|
+
let title = conv ? conversationTitle(conv, s) : groupId ?? props.peer ?? "";
|
|
2460
|
+
let count = null;
|
|
2461
|
+
if (conv?.group && !conv.group.quit) {
|
|
2462
|
+
const cached = memberMap.size;
|
|
2463
|
+
count = cached > 0 && cached < MemberCache.max ? cached : conv.group.memberCount;
|
|
2464
|
+
if (!count) count = null;
|
|
2465
|
+
}
|
|
2466
|
+
if (!title) title = s.groupChat;
|
|
2467
|
+
const groupInfo = callbacks.onGroupInfoTap;
|
|
2468
|
+
const actions = isGroup && groupId && groupInfo ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "gkim-iconbtn", "aria-label": s.groupInfoTitle, onClick: () => groupInfo(groupId), children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Icon, { name: "more" }) }) : null;
|
|
2469
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2470
|
+
Page,
|
|
2471
|
+
{
|
|
2472
|
+
className: "gkim-chat",
|
|
2473
|
+
scroll: false,
|
|
2474
|
+
actions,
|
|
2475
|
+
title: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
|
|
2476
|
+
title,
|
|
2477
|
+
count !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "gkim-chat__count", children: [
|
|
2478
|
+
"(",
|
|
2479
|
+
count,
|
|
2480
|
+
")"
|
|
2481
|
+
] }),
|
|
2482
|
+
!isGroup && snap.peerTyping && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "gkim-chat__sub", children: s.typing })
|
|
2483
|
+
] }),
|
|
2484
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2485
|
+
Composer,
|
|
2486
|
+
{
|
|
2487
|
+
ref: composer,
|
|
2488
|
+
onSend: send,
|
|
2489
|
+
onSendFile: sendFile,
|
|
2490
|
+
onTyping: () => ctl?.typing(),
|
|
2491
|
+
disabledHint: snap.quit ? s.notInGroup : null,
|
|
2492
|
+
features: snap.features,
|
|
2493
|
+
members: isGroup ? memberList : null,
|
|
2494
|
+
canAtAll: (conv?.group?.role ?? 0) >= 1,
|
|
2495
|
+
target: ctl?.target ?? null
|
|
2496
|
+
}
|
|
2497
|
+
),
|
|
2498
|
+
children: [
|
|
2499
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "gkim-chat__area", ...dropProps, children: [
|
|
2500
|
+
snap.loading || !ctl ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "gkim-loading", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "gkim-msglist__spinner", role: "img", "aria-label": "…" }) }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(MessageList, { ctl, snap, isGroup, nameOf, renderRow, scrollRef: scrollToLatest }),
|
|
2501
|
+
dragging && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "gkim-dropmask", children: fill(s.dropToSend, { name: title }) })
|
|
2502
|
+
] }),
|
|
2503
|
+
menu && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Menu, { entries: entriesFor(menu.m), x: menu.x, y: menu.y, onClose: closeMenu })
|
|
2504
|
+
]
|
|
2505
|
+
}
|
|
2506
|
+
);
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
// src/ui/conversation/ConversationList.tsx
|
|
2510
|
+
var import_react14 = require("react");
|
|
2511
|
+
var import_im3 = require("@guokit-dev/im");
|
|
2512
|
+
|
|
2513
|
+
// src/ui/hooks.ts
|
|
2514
|
+
var import_react13 = require("react");
|
|
2515
|
+
|
|
2516
|
+
// src/core/imStore.ts
|
|
2517
|
+
var EMPTY = Object.freeze([]);
|
|
2518
|
+
var cache2 = /* @__PURE__ */ new WeakMap();
|
|
2519
|
+
function storesOf(im) {
|
|
2520
|
+
let s = cache2.get(im);
|
|
2521
|
+
if (!s) cache2.set(im, s = {});
|
|
2522
|
+
return s;
|
|
2523
|
+
}
|
|
2524
|
+
function conversationsStore(im) {
|
|
2525
|
+
const s = storesOf(im);
|
|
2526
|
+
return s.conversations ?? (s.conversations = createConversationsStore(im));
|
|
2527
|
+
}
|
|
2528
|
+
function totalUnreadStore(im) {
|
|
2529
|
+
const s = storesOf(im);
|
|
2530
|
+
return s.totalUnread ?? (s.totalUnread = valueStore(im, "totalUnread", () => im.totalUnread));
|
|
2531
|
+
}
|
|
2532
|
+
function connectionStore(im) {
|
|
2533
|
+
const s = storesOf(im);
|
|
2534
|
+
return s.connection ?? (s.connection = valueStore(im, "connection", () => im.connectionState));
|
|
2535
|
+
}
|
|
2536
|
+
function createConversationsStore(im) {
|
|
2537
|
+
let snap = EMPTY;
|
|
2538
|
+
let owner = null;
|
|
2539
|
+
let last = EMPTY;
|
|
2540
|
+
let offs = [];
|
|
2541
|
+
const getSnapshot = () => {
|
|
2542
|
+
const me = im.currentUserId;
|
|
2543
|
+
if (me === null) {
|
|
2544
|
+
snap = EMPTY;
|
|
2545
|
+
owner = null;
|
|
2546
|
+
return EMPTY;
|
|
2547
|
+
}
|
|
2548
|
+
return me === owner ? snap : EMPTY;
|
|
2549
|
+
};
|
|
2550
|
+
const check = () => {
|
|
2551
|
+
const v = getSnapshot();
|
|
2552
|
+
if (v === last) return;
|
|
2553
|
+
last = v;
|
|
2554
|
+
listeners.notify();
|
|
2555
|
+
};
|
|
2556
|
+
const listeners = new ListenerSet(
|
|
2557
|
+
() => {
|
|
2558
|
+
offs = [
|
|
2559
|
+
im.on("conversations", (list) => {
|
|
2560
|
+
const me2 = im.currentUserId;
|
|
2561
|
+
if (me2 === null) return;
|
|
2562
|
+
snap = list;
|
|
2563
|
+
owner = me2;
|
|
2564
|
+
check();
|
|
2565
|
+
}),
|
|
2566
|
+
im.on("connection", check),
|
|
2567
|
+
im.on("totalUnread", check)
|
|
2568
|
+
];
|
|
2569
|
+
const me = im.currentUserId;
|
|
2570
|
+
if (me !== null) {
|
|
2571
|
+
try {
|
|
2572
|
+
snap = im.conversations();
|
|
2573
|
+
owner = me;
|
|
2574
|
+
} catch {
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
last = getSnapshot();
|
|
2578
|
+
},
|
|
2579
|
+
() => {
|
|
2580
|
+
offs.forEach((f) => f());
|
|
2581
|
+
offs = [];
|
|
2582
|
+
}
|
|
2583
|
+
);
|
|
2584
|
+
return { subscribe: (fn) => listeners.add(fn), getSnapshot };
|
|
2585
|
+
}
|
|
2586
|
+
function valueStore(im, event, read) {
|
|
2587
|
+
let off = null;
|
|
2588
|
+
let last;
|
|
2589
|
+
const listeners = new ListenerSet(
|
|
2590
|
+
() => {
|
|
2591
|
+
last = read();
|
|
2592
|
+
off = im.on(event, () => {
|
|
2593
|
+
const v = read();
|
|
2594
|
+
if (v === last) return;
|
|
2595
|
+
last = v;
|
|
2596
|
+
listeners.notify();
|
|
2597
|
+
});
|
|
2598
|
+
},
|
|
2599
|
+
() => {
|
|
2600
|
+
off?.();
|
|
2601
|
+
off = null;
|
|
2602
|
+
}
|
|
2603
|
+
);
|
|
2604
|
+
return { subscribe: (fn) => listeners.add(fn), getSnapshot: read };
|
|
2605
|
+
}
|
|
2606
|
+
|
|
2607
|
+
// src/ui/hooks.ts
|
|
2608
|
+
function useStore(s) {
|
|
2609
|
+
return (0, import_react13.useSyncExternalStore)(s.subscribe, s.getSnapshot, s.getSnapshot);
|
|
2610
|
+
}
|
|
2611
|
+
function useConversations() {
|
|
2612
|
+
return useStore(conversationsStore(useIm()));
|
|
2613
|
+
}
|
|
2614
|
+
function useTotalUnread() {
|
|
2615
|
+
return useStore(totalUnreadStore(useIm()));
|
|
2616
|
+
}
|
|
2617
|
+
function useConnection() {
|
|
2618
|
+
return useStore(connectionStore(useIm()));
|
|
2619
|
+
}
|
|
2620
|
+
|
|
2621
|
+
// src/ui/widgets/UnreadBadge.tsx
|
|
2622
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2623
|
+
function Badge({ count = 0, dot = false, muted = false }) {
|
|
2624
|
+
if (dot) return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "gkim-badge gkim-badge--dot", "aria-hidden": "true" });
|
|
2625
|
+
if (count <= 0) return null;
|
|
2626
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: `gkim-badge${muted ? " gkim-badge--muted" : ""}`, children: count > 99 ? "99+" : count });
|
|
2627
|
+
}
|
|
2628
|
+
function ImUnreadBadge({ children }) {
|
|
2629
|
+
const n = useTotalUnread();
|
|
2630
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { className: "gkim-badge-anchor", children: [
|
|
2631
|
+
children,
|
|
2632
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Badge, { count: n })
|
|
2633
|
+
] });
|
|
2634
|
+
}
|
|
2635
|
+
|
|
2636
|
+
// src/ui/conversation/ConversationList.tsx
|
|
2637
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
2638
|
+
function errorText(e, fallback) {
|
|
2639
|
+
return e instanceof import_im3.ImApiError && e.message ? e.message : fallback;
|
|
2640
|
+
}
|
|
2641
|
+
function Row({ c, selected, onOpen }) {
|
|
2642
|
+
const { im, strings: s } = useImUi();
|
|
2643
|
+
const { toast, confirm } = useFeedback();
|
|
2644
|
+
const menu = useContextMenu();
|
|
2645
|
+
const title = conversationTitle(c, s);
|
|
2646
|
+
const sum = conversationSummary(c, s);
|
|
2647
|
+
const g = c.group;
|
|
2648
|
+
const run = async (f) => {
|
|
2649
|
+
try {
|
|
2650
|
+
await f();
|
|
2651
|
+
} catch (e) {
|
|
2652
|
+
toast(errorText(e, s.operationFailed));
|
|
2653
|
+
}
|
|
2654
|
+
};
|
|
2655
|
+
const entries = [
|
|
2656
|
+
{ label: c.pinned ? s.unpin : s.pin, onSelect: () => run(() => im.setPinned(c.id, !c.pinned)) },
|
|
2657
|
+
{ label: c.muted ? s.unmute : s.mute, onSelect: () => run(() => im.setMuted(c.id, !c.muted)) },
|
|
2658
|
+
{
|
|
2659
|
+
label: s.deleteConversation,
|
|
2660
|
+
danger: true,
|
|
2661
|
+
onSelect: async () => {
|
|
2662
|
+
if (await confirm({ title: s.deleteConversation, content: s.deleteConversationConfirm, danger: true })) run(() => im.deleteConversation(c.id));
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
];
|
|
2666
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("li", { className: `gkim-conv${c.pinned ? " gkim-conv--pinned" : ""}${selected ? " gkim-conv--selected" : ""}`, children: [
|
|
2667
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
2668
|
+
"button",
|
|
2669
|
+
{
|
|
2670
|
+
type: "button",
|
|
2671
|
+
className: "gkim-conv__btn",
|
|
2672
|
+
onClick: onOpen,
|
|
2673
|
+
"aria-current": selected || void 0,
|
|
2674
|
+
"aria-label": c.unread > 0 ? `${title},${c.unread} 条未读` : title,
|
|
2675
|
+
...menu.bind,
|
|
2676
|
+
children: [
|
|
2677
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "gkim-conv__avatar", children: [
|
|
2678
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
2679
|
+
Avatar,
|
|
2680
|
+
{
|
|
2681
|
+
id: g?.groupId ?? c.peer?.userId ?? "",
|
|
2682
|
+
name: title,
|
|
2683
|
+
url: g?.avatarUrl ?? c.peer?.avatarUrl,
|
|
2684
|
+
group: !!g,
|
|
2685
|
+
size: void 0
|
|
2686
|
+
}
|
|
2687
|
+
),
|
|
2688
|
+
c.unread > 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "gkim-conv__badge", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Badge, { count: c.unread, dot: c.muted }) })
|
|
2689
|
+
] }),
|
|
2690
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "gkim-conv__body", children: [
|
|
2691
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "gkim-conv__line", children: [
|
|
2692
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "gkim-conv__title", children: title }),
|
|
2693
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "gkim-conv__time", children: formatConversationTime(c.lastMsgAt, s) })
|
|
2694
|
+
] }),
|
|
2695
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "gkim-conv__line", children: [
|
|
2696
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "gkim-conv__preview", children: [
|
|
2697
|
+
sum.atMe && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "gkim-conv__at", children: sum.atMe }),
|
|
2698
|
+
sum.text
|
|
2699
|
+
] }),
|
|
2700
|
+
c.muted && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "gkim-conv__muted", "aria-label": s.mute, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Icon, { name: "mute", size: 14 }) })
|
|
2701
|
+
] })
|
|
2702
|
+
] })
|
|
2703
|
+
]
|
|
2704
|
+
}
|
|
2705
|
+
),
|
|
2706
|
+
menu.at && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Menu, { entries, x: menu.at.x, y: menu.at.y, onClose: menu.close, label: title })
|
|
2707
|
+
] });
|
|
2708
|
+
}
|
|
2709
|
+
function ImConversationList({ onOpen, showAddMenu = true, showSearch = true, selectedId }) {
|
|
2710
|
+
const { im, strings: s } = useImUi();
|
|
2711
|
+
const { toast } = useFeedback();
|
|
2712
|
+
const convs = useConversations();
|
|
2713
|
+
const conn = useConnection();
|
|
2714
|
+
const nav = useNavContext();
|
|
2715
|
+
const frame = useFrame();
|
|
2716
|
+
const [busy, setBusy] = (0, import_react14.useState)(false);
|
|
2717
|
+
void showAddMenu;
|
|
2718
|
+
void showSearch;
|
|
2719
|
+
const mainChat = nav.state.main?.name === "chat" ? nav.state.main.target : null;
|
|
2720
|
+
const selected = selectedId !== void 0 ? selectedId : mainChat?.conversation?.id ?? null;
|
|
2721
|
+
const open = (c) => onOpen ? onOpen(c) : nav.open({ name: "chat", target: { conversation: c } });
|
|
2722
|
+
const anyUnread = convs.some((c) => c.unread > 0);
|
|
2723
|
+
const markAll = async () => {
|
|
2724
|
+
setBusy(true);
|
|
2725
|
+
try {
|
|
2726
|
+
await im.markAllRead();
|
|
2727
|
+
} catch (e) {
|
|
2728
|
+
toast(errorText(e, s.operationFailed));
|
|
2729
|
+
} finally {
|
|
2730
|
+
setBusy(false);
|
|
2731
|
+
}
|
|
2732
|
+
};
|
|
2733
|
+
const markAllBtn = (
|
|
2734
|
+
// 总未读不含免打扰会话,按各会话判断,免打扰的也能一键清掉。
|
|
2735
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
2736
|
+
"button",
|
|
2737
|
+
{
|
|
2738
|
+
type: "button",
|
|
2739
|
+
className: "gkim-iconbtn",
|
|
2740
|
+
"aria-label": s.markAllRead,
|
|
2741
|
+
title: s.markAllRead,
|
|
2742
|
+
disabled: !anyUnread || busy,
|
|
2743
|
+
onClick: markAll,
|
|
2744
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Icon, { name: "checkAll" })
|
|
2745
|
+
}
|
|
2746
|
+
)
|
|
2747
|
+
);
|
|
2748
|
+
const banner = conn === "disconnected" ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "gkim-banner gkim-banner--danger", role: "status", children: s.disconnected }) : null;
|
|
2749
|
+
const list = convs.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "gkim-empty gkim-grow", children: s.emptyConversations }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("ul", { className: "gkim-conv-list", "aria-label": s.conversationsTitle, children: convs.map((c) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Row, { c, selected: c.id === selected, onOpen: () => open(c) }, c.id)) });
|
|
2750
|
+
if (frame.kind === "list") {
|
|
2751
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "gkim-listpane", children: [
|
|
2752
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "gkim-listpane__head", children: [
|
|
2753
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h2", { className: "gkim-sr-only", children: s.conversationsTitle }),
|
|
2754
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "gkim-grow" }),
|
|
2755
|
+
markAllBtn
|
|
2756
|
+
] }),
|
|
2757
|
+
banner,
|
|
2758
|
+
list
|
|
2759
|
+
] });
|
|
2760
|
+
}
|
|
2761
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Page, { title: s.conversationsTitle, actions: markAllBtn, banner, children: list });
|
|
2762
|
+
}
|
|
2763
|
+
|
|
2764
|
+
// src/ui/menu/Report.tsx
|
|
2765
|
+
var import_react15 = require("react");
|
|
2766
|
+
var import_im4 = require("@guokit-dev/im");
|
|
2767
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
2768
|
+
function ReportDialog({ target, title, messageIds }) {
|
|
2769
|
+
const { im, strings: s } = useImUi();
|
|
2770
|
+
const { toast } = useFeedback();
|
|
2771
|
+
const frame = useFrame();
|
|
2772
|
+
const [reason, setReason] = (0, import_react15.useState)(null);
|
|
2773
|
+
const [block, setBlock] = (0, import_react15.useState)(false);
|
|
2774
|
+
const [busy, setBusy] = (0, import_react15.useState)(false);
|
|
2775
|
+
const submit = async () => {
|
|
2776
|
+
if (!reason) return;
|
|
2777
|
+
setBusy(true);
|
|
2778
|
+
let tip;
|
|
2779
|
+
try {
|
|
2780
|
+
const r = await im.report(typeof target === "string" ? target : target.groupId, reason, { messageIds: messageIds?.length ? messageIds : void 0, block });
|
|
2781
|
+
tip = r.duplicated ? s.reportDuplicated : s.reported;
|
|
2782
|
+
} catch (e) {
|
|
2783
|
+
tip = e instanceof import_im4.ImApiError && e.message ? e.message : s.operationFailed;
|
|
2784
|
+
}
|
|
2785
|
+
toast(tip);
|
|
2786
|
+
frame.close();
|
|
2787
|
+
};
|
|
2788
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
2789
|
+
Page,
|
|
2790
|
+
{
|
|
2791
|
+
title,
|
|
2792
|
+
className: "gkim-report",
|
|
2793
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
2794
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "button", className: "gkim-btn", onClick: frame.close, children: s.cancel }),
|
|
2795
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "button", className: "gkim-btn gkim-btn--primary", disabled: !reason || busy, onClick: submit, children: s.submit })
|
|
2796
|
+
] }),
|
|
2797
|
+
children: [
|
|
2798
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("fieldset", { className: "gkim-report__reasons", children: [
|
|
2799
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("legend", { className: "gkim-sr-only", children: title }),
|
|
2800
|
+
import_im4.reportReasons.map((r) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: `gkim-choice${reason === r ? " gkim-choice--on" : ""}`, children: [
|
|
2801
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("input", { type: "radio", name: "gkim-report-reason", value: r, checked: reason === r, disabled: busy, onChange: () => setReason(r) }),
|
|
2802
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: s.reportReasons[r] ?? r })
|
|
2803
|
+
] }, r))
|
|
2804
|
+
] }),
|
|
2805
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "gkim-check", children: [
|
|
2806
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("input", { type: "checkbox", checked: block, disabled: busy, onChange: (e) => setBlock(e.target.checked) }),
|
|
2807
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: s.alsoBlock })
|
|
2808
|
+
] })
|
|
2809
|
+
]
|
|
2810
|
+
}
|
|
2811
|
+
);
|
|
2812
|
+
}
|
|
2813
|
+
|
|
2814
|
+
// src/ui/viewer/ImageViewer.tsx
|
|
2815
|
+
var import_react16 = require("react");
|
|
2816
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
2817
|
+
var MIN = 1;
|
|
2818
|
+
var MAX = 4;
|
|
2819
|
+
function ImageViewer({ images, index }) {
|
|
2820
|
+
const { im, strings: s } = useImUi();
|
|
2821
|
+
const frame = useFrame();
|
|
2822
|
+
const [i, setI] = (0, import_react16.useState)(index);
|
|
2823
|
+
const [scale, setScale] = (0, import_react16.useState)(1);
|
|
2824
|
+
const [urls, setUrls] = (0, import_react16.useState)({});
|
|
2825
|
+
const m = images[i];
|
|
2826
|
+
(0, import_react16.useEffect)(() => {
|
|
2827
|
+
if (!m || m.clientMsgId in urls) return;
|
|
2828
|
+
let alive = true;
|
|
2829
|
+
im.imageUrl(m).then((u) => {
|
|
2830
|
+
if (alive) setUrls((x) => ({ ...x, [m.clientMsgId]: u }));
|
|
2831
|
+
}, () => {
|
|
2832
|
+
});
|
|
2833
|
+
return () => {
|
|
2834
|
+
alive = false;
|
|
2835
|
+
};
|
|
2836
|
+
}, [im, m, urls]);
|
|
2837
|
+
const go = (d) => {
|
|
2838
|
+
const n = i + d;
|
|
2839
|
+
if (n >= 0 && n < images.length) {
|
|
2840
|
+
setI(n);
|
|
2841
|
+
setScale(1);
|
|
2842
|
+
}
|
|
2843
|
+
};
|
|
2844
|
+
const zoom = (d) => setScale((v) => Math.min(MAX, Math.max(MIN, +(v + d).toFixed(2))));
|
|
2845
|
+
const onKey = (e) => {
|
|
2846
|
+
if (e.key === "ArrowLeft") go(-1);
|
|
2847
|
+
else if (e.key === "ArrowRight") go(1);
|
|
2848
|
+
else if (e.key === "+" || e.key === "=") zoom(0.5);
|
|
2849
|
+
else if (e.key === "-") zoom(-0.5);
|
|
2850
|
+
};
|
|
2851
|
+
const onWheel = (e) => zoom(e.deltaY < 0 ? 0.25 : -0.25);
|
|
2852
|
+
const url = m ? urls[m.clientMsgId] : null;
|
|
2853
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "gkim-viewer", onKeyDown: onKey, children: [
|
|
2854
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "gkim-viewer__bar", children: [
|
|
2855
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "gkim-viewer__count", children: fill(s.imageIndex, { n: i + 1, total: images.length }) }),
|
|
2856
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: "gkim-viewer__btn", "aria-label": s.zoomOut, disabled: scale <= MIN, onClick: () => zoom(-0.5), children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Icon, { name: "zoomOut" }) }),
|
|
2857
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: "gkim-viewer__btn", "aria-label": s.zoomIn, disabled: scale >= MAX, onClick: () => zoom(0.5), children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Icon, { name: "zoomIn" }) }),
|
|
2858
|
+
url && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("a", { className: "gkim-viewer__btn", href: url, target: "_blank", rel: "noopener", "aria-label": s.openOriginal, title: s.openOriginal, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Icon, { name: "external" }) }),
|
|
2859
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: "gkim-viewer__btn", "aria-label": s.close, "data-autofocus": true, onClick: frame.close, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Icon, { name: "close" }) })
|
|
2860
|
+
] }),
|
|
2861
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "gkim-viewer__stage", onWheel, onClick: (e) => {
|
|
2862
|
+
if (e.target === e.currentTarget) frame.close();
|
|
2863
|
+
}, children: [
|
|
2864
|
+
url ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("img", { src: url, alt: s.image, style: { transform: `scale(${scale})` }, onDoubleClick: () => setScale((v) => v > 1 ? 1 : 2), draggable: false }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "gkim-msglist__spinner", role: "img", "aria-label": "…" }),
|
|
2865
|
+
i > 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: "gkim-viewer__nav gkim-viewer__nav--prev", "aria-label": s.prevImage, onClick: () => go(-1), children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Icon, { name: "back", size: 28 }) }),
|
|
2866
|
+
i < images.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: "gkim-viewer__nav gkim-viewer__nav--next", "aria-label": s.nextImage, onClick: () => go(1), children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Icon, { name: "back", size: 28 }) })
|
|
2867
|
+
] })
|
|
2868
|
+
] });
|
|
2869
|
+
}
|
|
2870
|
+
|
|
2871
|
+
// src/ui/viewer/VideoPlayer.tsx
|
|
2872
|
+
var import_react17 = require("react");
|
|
2873
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
2874
|
+
function VideoPlayer({ message }) {
|
|
2875
|
+
const { im, strings: s } = useImUi();
|
|
2876
|
+
const frame = useFrame();
|
|
2877
|
+
const [url, setUrl] = (0, import_react17.useState)(null);
|
|
2878
|
+
const [failed, setFailed] = (0, import_react17.useState)(false);
|
|
2879
|
+
(0, import_react17.useEffect)(() => {
|
|
2880
|
+
let alive = true;
|
|
2881
|
+
im.videoUrl(message).then((u) => {
|
|
2882
|
+
if (alive) {
|
|
2883
|
+
setUrl(u);
|
|
2884
|
+
if (!u) setFailed(true);
|
|
2885
|
+
}
|
|
2886
|
+
}, () => alive && setFailed(true));
|
|
2887
|
+
return () => {
|
|
2888
|
+
alive = false;
|
|
2889
|
+
};
|
|
2890
|
+
}, [im, message]);
|
|
2891
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "gkim-viewer", children: [
|
|
2892
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "gkim-viewer__bar", children: [
|
|
2893
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "gkim-viewer__count" }),
|
|
2894
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { type: "button", className: "gkim-viewer__btn", "aria-label": s.close, "data-autofocus": true, onClick: frame.close, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Icon, { name: "close" }) })
|
|
2895
|
+
] }),
|
|
2896
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "gkim-viewer__stage", onClick: (e) => {
|
|
2897
|
+
if (e.target === e.currentTarget) frame.close();
|
|
2898
|
+
}, children: url ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("video", { src: url, controls: true, autoPlay: true, playsInline: true }) : failed ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { children: s.operationFailed }) : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "gkim-msglist__spinner", role: "img", "aria-label": "…" }) })
|
|
2899
|
+
] });
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2902
|
+
// src/ui/routes.tsx
|
|
2903
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
2904
|
+
function renderRoute(route) {
|
|
2905
|
+
switch (route.name) {
|
|
2906
|
+
case "conversations":
|
|
2907
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ImConversationList, {});
|
|
2908
|
+
case "chat": {
|
|
2909
|
+
const t = route.target;
|
|
2910
|
+
if (t.conversation) return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ImChat, { conversation: t.conversation }, `c${t.conversation.id}`);
|
|
2911
|
+
if (t.group) return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ImChat, { group: t.group }, `g${t.group}`);
|
|
2912
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ImChat, { peer: t.peer }, `p${t.peer}`);
|
|
2913
|
+
}
|
|
2914
|
+
case "report":
|
|
2915
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ReportDialog, { target: route.target, title: route.title, messageIds: route.messageIds });
|
|
2916
|
+
case "imageViewer":
|
|
2917
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ImageViewer, { images: route.images, index: route.index });
|
|
2918
|
+
case "videoPlayer":
|
|
2919
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(VideoPlayer, { message: route.message });
|
|
2920
|
+
default:
|
|
2921
|
+
return null;
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2925
|
+
// src/ui/layout/Layers.tsx
|
|
2926
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
2927
|
+
function escToBack(back) {
|
|
2928
|
+
return (e) => {
|
|
2929
|
+
if (e.key === "Escape") {
|
|
2930
|
+
e.stopPropagation();
|
|
2931
|
+
back();
|
|
2932
|
+
}
|
|
2933
|
+
};
|
|
2934
|
+
}
|
|
2935
|
+
function FrameBox({ frame, children }) {
|
|
2936
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FrameContext.Provider, { value: frame, children });
|
|
2937
|
+
}
|
|
2938
|
+
function DrawerLayer({ stack, back, close }) {
|
|
2939
|
+
const ref = useFocusTrap(stack.length > 0);
|
|
2940
|
+
if (!stack.length) return null;
|
|
2941
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "gkim-drawer-layer", children: [
|
|
2942
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "gkim-scrim", onClick: close }),
|
|
2943
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("aside", { className: "gkim-drawer", ref, tabIndex: -1, onKeyDown: escToBack(back), children: stack.map((r, i) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "gkim-stack-item", hidden: i !== stack.length - 1, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FrameBox, { frame: { kind: "drawer", canBack: i > 0, back, close }, children: renderRoute(r) }) }, i)) })
|
|
2944
|
+
] });
|
|
2945
|
+
}
|
|
2946
|
+
function DialogBox({ children, back }) {
|
|
2947
|
+
const ref = useFocusTrap();
|
|
2948
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "gkim-dialog-layer", onKeyDown: escToBack(back), children: [
|
|
2949
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "gkim-scrim", onClick: back }),
|
|
2950
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "gkim-dialog", ref, tabIndex: -1, children })
|
|
2951
|
+
] });
|
|
2952
|
+
}
|
|
2953
|
+
function DialogLayer({ stack, back }) {
|
|
2954
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_jsx_runtime17.Fragment, { children: stack.map((r, i) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(DialogBox, { back, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FrameBox, { frame: { kind: "dialog", canBack: false, back, close: back }, children: renderRoute(r) }) }, i)) });
|
|
2955
|
+
}
|
|
2956
|
+
function OverlayBox({ children, back }) {
|
|
2957
|
+
const ref = useFocusTrap();
|
|
2958
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "gkim-overlay", ref, tabIndex: -1, onKeyDown: escToBack(back), children });
|
|
2959
|
+
}
|
|
2960
|
+
function OverlayLayer({ stack, back }) {
|
|
2961
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_jsx_runtime17.Fragment, { children: stack.map((r, i) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(OverlayBox, { back, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FrameBox, { frame: { kind: "dialog", canBack: false, back, close: back }, children: renderRoute(r) }) }, i)) });
|
|
2962
|
+
}
|
|
2963
|
+
function LayerHost() {
|
|
2964
|
+
const { state: st, back, close } = useNavContext();
|
|
2965
|
+
return (0, import_react18.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
|
|
2966
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(DrawerLayer, { stack: st.drawer, back, close }),
|
|
2967
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(DialogLayer, { stack: st.dialog, back }),
|
|
2968
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(OverlayLayer, { stack: st.overlay, back })
|
|
2969
|
+
] }), [st, back, close]);
|
|
2970
|
+
}
|
|
2971
|
+
|
|
2972
|
+
// src/ui/context.tsx
|
|
2973
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2974
|
+
var UiContext = (0, import_react19.createContext)(null);
|
|
2975
|
+
var EMPTY2 = {};
|
|
2976
|
+
var NO_ITEMS = [];
|
|
2977
|
+
function chatTargetOf(t) {
|
|
2978
|
+
const c = t.conversation;
|
|
2979
|
+
const peerId = c ? c.group ? null : c.peer?.userId ?? null : t.peer ?? null;
|
|
2980
|
+
const groupId = c ? c.group?.groupId ?? null : t.group ?? null;
|
|
2981
|
+
return { peerId, groupId, conversationId: c?.id ?? null, to: peerId ?? "" };
|
|
2982
|
+
}
|
|
2983
|
+
function GuokitImUi(props) {
|
|
2984
|
+
const { im, me, theme, strings, callbacks, messageRenderers, moreItems, menuItems, className, style, children } = props;
|
|
2985
|
+
const merged = (0, import_react19.useMemo)(() => mergeStrings(strings), [strings]);
|
|
2986
|
+
const cb = callbacks ?? EMPTY2;
|
|
2987
|
+
const value = (0, import_react19.useMemo)(() => ({
|
|
2988
|
+
im,
|
|
2989
|
+
me: me ?? EMPTY2,
|
|
2990
|
+
strings: merged,
|
|
2991
|
+
callbacks: cb,
|
|
2992
|
+
messageRenderers: messageRenderers ?? EMPTY2,
|
|
2993
|
+
moreItems: moreItems ?? NO_ITEMS,
|
|
2994
|
+
menuItems
|
|
2995
|
+
}), [im, me, merged, cb, messageRenderers, moreItems, menuItems]);
|
|
2996
|
+
const cbRef = (0, import_react19.useRef)(cb);
|
|
2997
|
+
cbRef.current = cb;
|
|
2998
|
+
(0, import_react19.useEffect)(() => im.on("kickedOut", () => cbRef.current.onKickedOut?.()), [im]);
|
|
2999
|
+
const onMainOrList = (0, import_react19.useCallback)((r) => {
|
|
3000
|
+
if (r.name === "chat") cbRef.current.onOpenConversation?.(chatTargetOf(r.target));
|
|
3001
|
+
}, []);
|
|
3002
|
+
const nav = useNavState(false, onMainOrList);
|
|
3003
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(UiContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(NavContext.Provider, { value: nav, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: className ? `gkim-root ${className}` : "gkim-root", style: { ...themeVars(theme), ...style }, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(FeedbackProvider, { labels: { ok: merged.confirm, cancel: merged.cancel }, children: [
|
|
3004
|
+
children,
|
|
3005
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(LayerHost, {})
|
|
3006
|
+
] }) }) }) });
|
|
3007
|
+
}
|
|
3008
|
+
function useImUi() {
|
|
3009
|
+
const v = (0, import_react19.useContext)(UiContext);
|
|
3010
|
+
if (!v) throw new Error("没有找到 GuokitImUi:IM 组件要放在 GuokitImUi 下面。");
|
|
3011
|
+
return v;
|
|
3012
|
+
}
|
|
3013
|
+
function useIm() {
|
|
3014
|
+
return useImUi().im;
|
|
3015
|
+
}
|
|
3016
|
+
|
|
3017
|
+
// src/ui/layout/ImWorkspace.tsx
|
|
3018
|
+
var import_react21 = require("react");
|
|
3019
|
+
|
|
3020
|
+
// src/ui/layout/useWide.ts
|
|
3021
|
+
var import_react20 = require("react");
|
|
3022
|
+
var WIDE_MIN = 768;
|
|
3023
|
+
function useWide(ref) {
|
|
3024
|
+
const [wide, setWide] = (0, import_react20.useState)(true);
|
|
3025
|
+
(0, import_react20.useLayoutEffect)(() => {
|
|
3026
|
+
const el = ref.current;
|
|
3027
|
+
if (!el || typeof ResizeObserver === "undefined") return;
|
|
3028
|
+
const ro = new ResizeObserver((entries) => {
|
|
3029
|
+
const w = entries[0]?.contentRect.width ?? el.clientWidth;
|
|
3030
|
+
setWide(w >= WIDE_MIN);
|
|
3031
|
+
});
|
|
3032
|
+
ro.observe(el);
|
|
3033
|
+
return () => ro.disconnect();
|
|
3034
|
+
}, [ref]);
|
|
3035
|
+
return wide;
|
|
3036
|
+
}
|
|
3037
|
+
|
|
3038
|
+
// src/ui/layout/ImWorkspace.tsx
|
|
3039
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
3040
|
+
function Rail() {
|
|
3041
|
+
const { im, me, strings: s } = useImUi();
|
|
3042
|
+
const unread = useTotalUnread();
|
|
3043
|
+
const uid = im.currentUserId ?? "";
|
|
3044
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("nav", { className: "gkim-rail", "aria-label": "IM", children: [
|
|
3045
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Avatar, { id: uid, name: me.nickname ?? "", url: me.avatarUrl, size: 36 }),
|
|
3046
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("button", { type: "button", className: "gkim-rail__item", "aria-label": s.navMessages, "aria-current": "page", children: [
|
|
3047
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Icon, { name: "message", size: 22 }),
|
|
3048
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Badge, { count: unread })
|
|
3049
|
+
] })
|
|
3050
|
+
] });
|
|
3051
|
+
}
|
|
3052
|
+
function Wide({ nav }) {
|
|
3053
|
+
const { state: st, back, close } = nav;
|
|
3054
|
+
const { strings: s } = useImUi();
|
|
3055
|
+
const noop2 = () => {
|
|
3056
|
+
};
|
|
3057
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
|
|
3058
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Rail, {}),
|
|
3059
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "gkim-listcol", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(FrameContext.Provider, { value: { kind: "list", canBack: false, back: noop2, close: noop2 }, children: renderRoute(st.list) }) }),
|
|
3060
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "gkim-main", children: [
|
|
3061
|
+
st.main ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(FrameContext.Provider, { value: { kind: "main", canBack: false, back, close }, children: renderRoute(st.main) }) : /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "gkim-empty gkim-main__empty", children: s.selectConversation }),
|
|
3062
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DrawerLayer, { stack: st.drawer, back, close })
|
|
3063
|
+
] }),
|
|
3064
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DialogLayer, { stack: st.dialog, back }),
|
|
3065
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(OverlayLayer, { stack: st.overlay, back })
|
|
3066
|
+
] });
|
|
3067
|
+
}
|
|
3068
|
+
function Narrow({ nav }) {
|
|
3069
|
+
const { state: st, back } = nav;
|
|
3070
|
+
const pages = [
|
|
3071
|
+
{ key: "list", route: st.list },
|
|
3072
|
+
...st.main ? [{ key: "main", route: st.main }] : [],
|
|
3073
|
+
...st.drawer.map((route, i) => ({ key: `d${i}`, route })),
|
|
3074
|
+
...st.dialog.map((route, i) => ({ key: `g${i}`, route }))
|
|
3075
|
+
];
|
|
3076
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
|
|
3077
|
+
pages.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "gkim-stack-item gkim-narrow-page", hidden: i !== pages.length - 1, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(FrameContext.Provider, { value: { kind: "page", canBack: i > 0, back, close: back }, children: renderRoute(p.route) }) }, p.key)),
|
|
3078
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(OverlayLayer, { stack: st.overlay, back })
|
|
3079
|
+
] });
|
|
3080
|
+
}
|
|
3081
|
+
function ImWorkspace({ className }) {
|
|
3082
|
+
const ref = (0, import_react21.useRef)(null);
|
|
3083
|
+
const wide = useWide(ref);
|
|
3084
|
+
const { callbacks } = useImUi();
|
|
3085
|
+
const nav = useNavState(true);
|
|
3086
|
+
const onNavigate = (0, import_react21.useRef)(callbacks.onNavigate);
|
|
3087
|
+
onNavigate.current = callbacks.onNavigate;
|
|
3088
|
+
const last = (0, import_react21.useRef)(nav.state);
|
|
3089
|
+
(0, import_react21.useEffect)(() => {
|
|
3090
|
+
if (last.current === nav.state) return;
|
|
3091
|
+
last.current = nav.state;
|
|
3092
|
+
onNavigate.current?.(topRoute(nav.state));
|
|
3093
|
+
}, [nav.state]);
|
|
3094
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(NavContext.Provider, { value: nav, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { ref, className: `gkim-workspace gkim-workspace--${wide ? "wide" : "narrow"}${className ? " " + className : ""}`, children: wide ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Wide, { nav }) : /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Narrow, { nav }) }) });
|
|
3095
|
+
}
|