@guokit-dev/im-react 0.0.0-stage → 0.28.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 +158 -2
- package/dist/index.cjs +5279 -0
- package/dist/index.mjs +5257 -0
- package/dist/style.css +571 -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/groupAvatarCache.d.ts +37 -0
- package/dist/types/core/imStore.d.ts +13 -0
- package/dist/types/core/index.d.ts +11 -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/pinyinIndex.d.ts +15 -0
- package/dist/types/core/strings.d.ts +315 -0
- package/dist/types/index.d.ts +15 -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/contacts/AddFriendDialog.d.ts +2 -0
- package/dist/types/ui/contacts/ContactsPage.d.ts +9 -0
- package/dist/types/ui/contacts/FriendGroups.d.ts +6 -0
- package/dist/types/ui/contacts/FriendSettings.d.ts +4 -0
- package/dist/types/ui/contacts/NewFriendsPage.d.ts +2 -0
- package/dist/types/ui/contacts/UserCard.d.ts +8 -0
- package/dist/types/ui/contacts/index.d.ts +5 -0
- package/dist/types/ui/contacts/routes.d.ts +4 -0
- package/dist/types/ui/contacts/shared.d.ts +33 -0
- package/dist/types/ui/context.d.ts +44 -0
- package/dist/types/ui/conversation/ConversationList.d.ts +13 -0
- package/dist/types/ui/group/GroupChats.d.ts +2 -0
- package/dist/types/ui/group/GroupInfo.d.ts +9 -0
- package/dist/types/ui/group/GroupMembers.d.ts +11 -0
- package/dist/types/ui/group/GroupNotice.d.ts +8 -0
- package/dist/types/ui/group/SelectFriends.d.ts +8 -0
- package/dist/types/ui/group/routes.d.ts +4 -0
- package/dist/types/ui/group/shared.d.ts +47 -0
- package/dist/types/ui/hooks.d.ts +9 -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 +111 -0
- package/dist/types/ui/privacy/PrivacyPage.d.ts +7 -0
- package/dist/types/ui/privacy/routes.d.ts +4 -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/GroupAvatar.d.ts +21 -0
- package/dist/types/ui/widgets/Icon.d.ts +43 -0
- package/dist/types/ui/widgets/IndexedList.d.ts +14 -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
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { GuokitIm, ImConversation, ImFeatures, ImMessage, ImTarget } from '@guokit-dev/im';
|
|
2
|
+
import { type ExternalStore } from './externalStore';
|
|
3
|
+
/** 聊天对象三选一:对方 userId、群号、已知会话(从会话列表进来)。 */
|
|
4
|
+
export type ChatTarget = {
|
|
5
|
+
peer: string;
|
|
6
|
+
} | {
|
|
7
|
+
group: string;
|
|
8
|
+
} | {
|
|
9
|
+
conversation: ImConversation;
|
|
10
|
+
};
|
|
11
|
+
/** 聊天页的不可变快照;任何字段变化都换一个新对象,没变化时 getSnapshot 返回同一引用。 */
|
|
12
|
+
export interface ChatSnapshot {
|
|
13
|
+
/** 已确认的按 seq,未确认的(发送中 / 失败 / 被拒)排在后面按 createdAt。 */
|
|
14
|
+
readonly messages: readonly ImMessage[];
|
|
15
|
+
/** 首屏加载中。 */
|
|
16
|
+
readonly loading: boolean;
|
|
17
|
+
readonly loadingMore: boolean;
|
|
18
|
+
/** 还有更早的消息可以 loadMore。 */
|
|
19
|
+
readonly hasMore: boolean;
|
|
20
|
+
/** 单聊对方正在输入。 */
|
|
21
|
+
readonly peerTyping: boolean;
|
|
22
|
+
/** 本地会话;还没有会话(没聊过)时为 null,首条发送成功后补上。 */
|
|
23
|
+
readonly conversation: ImConversation | null;
|
|
24
|
+
readonly conversationId: number | null;
|
|
25
|
+
/** 已退群、被移出或群已解散:输入区禁用。 */
|
|
26
|
+
readonly quit: boolean;
|
|
27
|
+
/** 对方已读到的 seq;null = 站点没开已读回执、群聊或客服会话,不显示已读 / 未读。 */
|
|
28
|
+
readonly peerReadSeq: number | null;
|
|
29
|
+
/** 站点开关;没取到前为 null。 */
|
|
30
|
+
readonly features: ImFeatures | null;
|
|
31
|
+
/** 上传进度(0–1),按 clientMsgId;`null` = 总大小未知(不显示百分比)。发送结束即移除。 */
|
|
32
|
+
readonly progress: Readonly<Record<string, number | null>>;
|
|
33
|
+
/** 本设备发出的图片原文件,按 clientMsgId;SDK 发 Blob 时不留本地路径,UI 用它生成 objectURL 做预览。 */
|
|
34
|
+
readonly localFiles: Readonly<Record<string, Blob>>;
|
|
35
|
+
}
|
|
36
|
+
/** 「+」菜单宿主扩展项要的目标信息(结构同 UI 层的 `ImChatTarget`)。 */
|
|
37
|
+
export interface ChatTargetInfo {
|
|
38
|
+
peerId: string | null;
|
|
39
|
+
groupId: string | null;
|
|
40
|
+
conversationId: number | null;
|
|
41
|
+
/** 群聊为空串。 */
|
|
42
|
+
to: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 一个聊天窗口的状态:消息、翻页、对方正在输入、会话(已读位置、群资料)、上传进度。
|
|
46
|
+
* 对应 Flutter `ImChatController`(不含锚点模式)。
|
|
47
|
+
*
|
|
48
|
+
* 生命周期:`new` → `start()` → … → `dispose()`。构造不碰 SDK;参数不对同步抛 TypeError。
|
|
49
|
+
*/
|
|
50
|
+
export declare class ChatController implements ExternalStore<ChatSnapshot> {
|
|
51
|
+
readonly im: GuokitIm;
|
|
52
|
+
static readonly pageSize = 30;
|
|
53
|
+
readonly peerId: string | null;
|
|
54
|
+
readonly groupId: string | null;
|
|
55
|
+
private conv;
|
|
56
|
+
private byClient;
|
|
57
|
+
private sorted;
|
|
58
|
+
private snap;
|
|
59
|
+
private offs;
|
|
60
|
+
private listeners;
|
|
61
|
+
private newListeners;
|
|
62
|
+
private started;
|
|
63
|
+
private disposed;
|
|
64
|
+
private historyLoaded;
|
|
65
|
+
private active;
|
|
66
|
+
private loading;
|
|
67
|
+
private loadingMore;
|
|
68
|
+
private hasMore;
|
|
69
|
+
private peerTyping;
|
|
70
|
+
private features;
|
|
71
|
+
private progress;
|
|
72
|
+
private localFiles;
|
|
73
|
+
/** 发出去、还没从 messageUpdated 认领到 clientMsgId 的图片,按调用顺序。 */
|
|
74
|
+
private awaiting;
|
|
75
|
+
constructor(im: GuokitIm, target: ChatTarget);
|
|
76
|
+
get isGroup(): boolean;
|
|
77
|
+
get conversationId(): number | null;
|
|
78
|
+
/** `send*` 的目标参数。 */
|
|
79
|
+
get sendTarget(): ImTarget;
|
|
80
|
+
get target(): ChatTargetInfo;
|
|
81
|
+
subscribe: (fn: () => void) => (() => void);
|
|
82
|
+
getSnapshot: () => ChatSnapshot;
|
|
83
|
+
/** 有新消息进来(对方的、或本人在别的设备发的);页面据此决定是否滚到底。返回取消函数。 */
|
|
84
|
+
onNewMessage(fn: (m: ImMessage) => void): () => void;
|
|
85
|
+
private buildSnapshot;
|
|
86
|
+
private notify;
|
|
87
|
+
/** 挂上 SDK 事件并加载首屏。重复调用无效。 */
|
|
88
|
+
start(): Promise<void>;
|
|
89
|
+
private loadLatest;
|
|
90
|
+
/** 滚到顶时调:用最早一条**已确认**的消息作 before 再取一页。失败留着 hasMore,下次再试。 */
|
|
91
|
+
loadMore(): Promise<void>;
|
|
92
|
+
private belongs;
|
|
93
|
+
private onMessage;
|
|
94
|
+
/** 还没有会话时,首条消息发送成功后从消息里拿会话 id,再拉历史、标已读。 */
|
|
95
|
+
private adopt;
|
|
96
|
+
private onConversations;
|
|
97
|
+
private merge;
|
|
98
|
+
private markRead;
|
|
99
|
+
/** 页面前后台切换时调(如 visibilitychange);回到前台补一次已读。 */
|
|
100
|
+
setActive(active: boolean): void;
|
|
101
|
+
/** 单聊输入变化时调(SDK 按 3 秒节流);群聊服务端不支持,不发。 */
|
|
102
|
+
typing(): void;
|
|
103
|
+
private track;
|
|
104
|
+
/** 发文字;at 只在群里有效(`@all` 为所有人)。 */
|
|
105
|
+
sendText(text: string, at?: readonly string[]): Promise<ImMessage>;
|
|
106
|
+
/** 发图(JPEG / PNG / GIF / WebP);原文件留在快照 `localFiles` 里做预览。 */
|
|
107
|
+
sendImage(file: Blob): Promise<ImMessage>;
|
|
108
|
+
/** 发视频(mp4 / mov);时长与宽高必填(用 media 的 readVideoMeta 读),越界 SDK 抛 RangeError。 */
|
|
109
|
+
sendVideo(file: Blob, meta: {
|
|
110
|
+
durationMs: number;
|
|
111
|
+
width: number;
|
|
112
|
+
height: number;
|
|
113
|
+
}): Promise<ImMessage>;
|
|
114
|
+
/** 发文件;name 不传取 File.name(要带扩展名)。 */
|
|
115
|
+
sendFile(file: Blob, name?: string): Promise<ImMessage>;
|
|
116
|
+
/** 重发 failed 的消息;rejected 等其他状态不调 SDK,直接 reject。 */
|
|
117
|
+
resend(m: ImMessage): Promise<ImMessage>;
|
|
118
|
+
/** 撤回自己发的一条;没开启、超时限抛 ImApiError(直接显示 message)。成功后列表随 messageUpdated 更新。 */
|
|
119
|
+
recall(m: ImMessage): Promise<void>;
|
|
120
|
+
dispose(): void;
|
|
121
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 外部状态的最小契约,React 侧交给 `useSyncExternalStore`。
|
|
3
|
+
*
|
|
4
|
+
* - `subscribe` 与 `getSnapshot` 会被**不带 this** 地传出去,实现必须是闭包或箭头函数属性;
|
|
5
|
+
* - `getSnapshot` 在没变化时必须返回同一引用,否则会无限重渲染。
|
|
6
|
+
*/
|
|
7
|
+
export interface ExternalStore<T> {
|
|
8
|
+
subscribe(fn: () => void): () => void;
|
|
9
|
+
getSnapshot(): T;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 监听器集合:第一个订阅者进来时调 `onFirst`,最后一个离开时调 `onLast`(用来挂上、摘掉 SDK 事件)。
|
|
13
|
+
* 同一个函数订阅两次算两个订阅者;取消函数可重复调用。
|
|
14
|
+
*/
|
|
15
|
+
export declare class ListenerSet {
|
|
16
|
+
private onFirst?;
|
|
17
|
+
private onLast?;
|
|
18
|
+
private entries;
|
|
19
|
+
constructor(onFirst?: (() => void) | undefined, onLast?: (() => void) | undefined);
|
|
20
|
+
get size(): number;
|
|
21
|
+
add(fn: () => void): () => void;
|
|
22
|
+
notify(): void;
|
|
23
|
+
/** 丢掉全部订阅者,不调 onLast(销毁时用,调用方自己收尾)。 */
|
|
24
|
+
clear(): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GuokitIm, ImFeatures } from '@guokit-dev/im';
|
|
2
|
+
/**
|
|
3
|
+
* 站点开关,按 (im, 当前账号) 缓存:`features()` 每次都请求 `GET /me`。
|
|
4
|
+
*
|
|
5
|
+
* 换号即失效(同一个 im 实例可以换号登录,与 Flutter 按实例缓存不同);失败不缓存,下次再取;
|
|
6
|
+
* 未登录返回 rejected Promise,不同步抛。
|
|
7
|
+
*/
|
|
8
|
+
export declare function cachedFeatures(im: GuokitIm): Promise<ImFeatures>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ImConversation, ImMessage } from '@guokit-dev/im';
|
|
2
|
+
import { type ImUiStrings } from './strings';
|
|
3
|
+
/** 会话的显示名:群用群名(空串时「群聊」),单聊优先备注、再昵称、最后 userId。 */
|
|
4
|
+
export declare function conversationTitle(c: ImConversation, s: ImUiStrings): string;
|
|
5
|
+
/**
|
|
6
|
+
* 会话列表第二行。`atMe` 是要标红的前缀(群里有未读的 @ 我时为 `[有人@我] `,否则空串),
|
|
7
|
+
* `text` 是最后一条的预览——SDK 已按类型算好占位、撤回、群提示(`lastMessage.preview`),同 Flutter。
|
|
8
|
+
*/
|
|
9
|
+
export declare function conversationSummary(c: ImConversation, s: ImUiStrings): {
|
|
10
|
+
atMe: string;
|
|
11
|
+
text: string;
|
|
12
|
+
};
|
|
13
|
+
/** 未读角标文字:超过 99 显示 `99+`。 */
|
|
14
|
+
export declare function formatUnread(n: number): string;
|
|
15
|
+
/**
|
|
16
|
+
* 会话列表的时间:今天「时:分」,昨天「昨天」,7 天内「星期几」,更早「月/日」,跨年「年/月/日」。
|
|
17
|
+
* `time` 是毫秒时间戳;`now` 便于测试固定「现在」。
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatConversationTime(time: number, s: ImUiStrings, now?: number | Date): string;
|
|
20
|
+
/** 聊天页时间分隔:今天「时:分」,其余在会话列表的写法后面加「时:分」。 */
|
|
21
|
+
export declare function formatMessageTime(time: number, s: ImUiStrings, now?: number | Date): string;
|
|
22
|
+
/** 居中灰色提示类消息:撤回、群变动、`@system` 发的其他消息。 */
|
|
23
|
+
export declare function isTipMessage(m: ImMessage): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* 提示的文字。`nameOf` 把 userId 换成显示名(群成员缓存,不在缓存里返回 userId);
|
|
26
|
+
* 群变动消息里 `nameOf` 查不到的人(已退群)再用 content 的昵称快照 `names`。`operator` 为 `@system` 表示系统。
|
|
27
|
+
*/
|
|
28
|
+
export declare function tipText(m: ImMessage, s: ImUiStrings, opts: {
|
|
29
|
+
nameOf: (userId: string) => string;
|
|
30
|
+
me: string | null;
|
|
31
|
+
isGroup: boolean;
|
|
32
|
+
}): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { GuokitIm, ImGroupChange, ImGroupMember } from '@guokit-dev/im';
|
|
2
|
+
/**
|
|
3
|
+
* 九宫格群头像用的成员缓存(spec §6 B 期,口径同 Flutter `GroupAvatarCache`)。按 im 实例各一份。
|
|
4
|
+
*
|
|
5
|
+
* 有头像挂上(attach)才排队拉前 9 名成员,同时最多 3 个请求;进群、退群、移出、建群、解散,或改了群头像时
|
|
6
|
+
* 重拉该群(拉到前先显示旧的,免得闪成单色块)。失败 1 分钟内不再试。
|
|
7
|
+
*/
|
|
8
|
+
export declare class GroupAvatarCache {
|
|
9
|
+
private fetch;
|
|
10
|
+
private now;
|
|
11
|
+
static readonly maxConcurrent = 3;
|
|
12
|
+
static readonly retryAfterMs = 60000;
|
|
13
|
+
private static readonly memberActions;
|
|
14
|
+
private members;
|
|
15
|
+
private stale;
|
|
16
|
+
private failedAt;
|
|
17
|
+
private wanted;
|
|
18
|
+
private queue;
|
|
19
|
+
private inflight;
|
|
20
|
+
private gen;
|
|
21
|
+
private listeners;
|
|
22
|
+
private off;
|
|
23
|
+
constructor(fetch: (groupId: string) => Promise<ImGroupMember[]>, subscribeChanges: (fn: (c: ImGroupChange) => void) => () => void, now?: () => number);
|
|
24
|
+
private static byIm;
|
|
25
|
+
static of(im: GuokitIm): GroupAvatarCache;
|
|
26
|
+
/** 测试用:给某个实例换上自带的缓存。 */
|
|
27
|
+
static set(im: GuokitIm, cache: GroupAvatarCache): void;
|
|
28
|
+
subscribe: (fn: () => void) => (() => void);
|
|
29
|
+
/** 已拉到的前 9 名成员;没拉过或在拉为 undefined。没变化时引用不变。 */
|
|
30
|
+
membersOf: (groupId: string) => ImGroupMember[] | undefined;
|
|
31
|
+
attach(groupId: string): void;
|
|
32
|
+
detach(groupId: string): void;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
private enqueue;
|
|
35
|
+
private pump;
|
|
36
|
+
private onChange;
|
|
37
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GuokitIm, ImConnectionState, ImConversation, ImFriend } from '@guokit-dev/im';
|
|
2
|
+
import { type ExternalStore } from './externalStore';
|
|
3
|
+
/** 会话列表快照,置顶在前;未登录时是空数组(同一个冻结的空数组)。 */
|
|
4
|
+
export declare function conversationsStore(im: GuokitIm): ExternalStore<readonly ImConversation[]>;
|
|
5
|
+
/** 总未读(免打扰不计);登出时 SDK 会推一次 0。 */
|
|
6
|
+
export declare function totalUnreadStore(im: GuokitIm): ExternalStore<number>;
|
|
7
|
+
/** 实时连接状态。 */
|
|
8
|
+
export declare function connectionStore(im: GuokitIm): ExternalStore<ImConnectionState>;
|
|
9
|
+
/**
|
|
10
|
+
* 好友快照(按 userId 升序);未登录时是空数组。`friends()` 每次返回新数组、还会触发全量对账(最多 6 个请求),
|
|
11
|
+
* 所以只在「从无到有订阅者」时调一次取初值并触发对账,之后靠 `friendsChanged` 事件更新。冷启动先是空的。
|
|
12
|
+
*/
|
|
13
|
+
export declare function friendsStore(im: GuokitIm): ExternalStore<readonly ImFriend[]>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ListenerSet, type ExternalStore } from './externalStore';
|
|
2
|
+
export { conversationsStore, totalUnreadStore, connectionStore, friendsStore } from './imStore';
|
|
3
|
+
export { cachedFeatures } from './features';
|
|
4
|
+
export { ChatController, type ChatTarget, type ChatSnapshot, type ChatTargetInfo } from './chatController';
|
|
5
|
+
export { MemberCache } from './memberCache';
|
|
6
|
+
export { MentionEditing, mentionToken, type ImMention, type TextEdit } from './mention';
|
|
7
|
+
export { conversationTitle, conversationSummary, formatUnread, formatConversationTime, formatMessageTime, isTipMessage, tipText, } from './format';
|
|
8
|
+
export { classifyFile, checkSize, readVideoMeta, ObjectUrlRegistry, type MediaKind, type SizeIssue, type VideoMeta, } from './media';
|
|
9
|
+
export { defaultStrings, mergeStrings, fill, type ImUiStrings } from './strings';
|
|
10
|
+
export { indexLetterOf, indexSections, indexLetters, type IndexLetter, type IndexSection } from './pinyinIndex';
|
|
11
|
+
export { GroupAvatarCache } from './groupAvatarCache';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ImFeatures } from '@guokit-dev/im';
|
|
2
|
+
/** 附件走哪个发送方法:sendImage / sendVideo / sendFile。 */
|
|
3
|
+
export type MediaKind = 'image' | 'video' | 'file';
|
|
4
|
+
export declare function classifyFile(file: Blob & {
|
|
5
|
+
name?: string;
|
|
6
|
+
}): MediaKind;
|
|
7
|
+
/** 预检不通过的原因:`disabled` 站点没开这类(上限为 0);`tooLarge` 超过 `maxMb`。 */
|
|
8
|
+
export interface SizeIssue {
|
|
9
|
+
reason: 'disabled' | 'tooLarge';
|
|
10
|
+
maxMb: number;
|
|
11
|
+
}
|
|
12
|
+
/** 按 `fileMaxMb` / `videoMaxMb` 预检;图片没有上限。通过返回 null。 */
|
|
13
|
+
export declare function checkSize(file: Blob, kind: MediaKind, features: ImFeatures): SizeIssue | null;
|
|
14
|
+
export interface VideoMeta {
|
|
15
|
+
durationMs: number;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 用 `<video>` 读视频时长与宽高(sendVideo 必填)。读不出宽高或时长、解码失败、10 秒没结果都返回 null,
|
|
21
|
+
* 调用方改走 sendFile。只能在浏览器里用。
|
|
22
|
+
*/
|
|
23
|
+
export declare function readVideoMeta(file: Blob, timeoutMs?: number): Promise<VideoMeta | null>;
|
|
24
|
+
/**
|
|
25
|
+
* 本地预览用的 objectURL,按 key(clientMsgId)登记与回收。发 Blob 时 SDK 不留本地路径,
|
|
26
|
+
* 上传完成前只能靠它显示;离开聊天页时 `releaseAll()`。
|
|
27
|
+
*/
|
|
28
|
+
export declare class ObjectUrlRegistry {
|
|
29
|
+
private entries;
|
|
30
|
+
/** 登记并返回地址;同一 key 同一文件重复登记返回原地址,换了文件先回收旧的。 */
|
|
31
|
+
register(key: string, file: Blob): string;
|
|
32
|
+
get(key: string): string | null;
|
|
33
|
+
release(key: string): void;
|
|
34
|
+
/** 和一份 key → 文件 的表对齐(如 ChatController 快照的 `localFiles`):缺的登记,多出来的回收。 */
|
|
35
|
+
sync(files: Readonly<Record<string, Blob>>): void;
|
|
36
|
+
releaseAll(): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { GuokitIm, ImGroupMember } from '@guokit-dev/im';
|
|
2
|
+
import { type ExternalStore } from './externalStore';
|
|
3
|
+
/**
|
|
4
|
+
* 群成员名缓存:userId → 昵称、头像、角色。消息里没有发送人资料,群聊靠它解析。同 Flutter `GroupMemberCache`。
|
|
5
|
+
*
|
|
6
|
+
* `start()` 后拉全部成员(500 人封顶,每页 100 按游标翻),收到本群的 `groupChanged` 时重拉。
|
|
7
|
+
* 快照是按进群先后排的 `ReadonlyMap`,每次重拉成功换一个新 Map。
|
|
8
|
+
*/
|
|
9
|
+
export declare class MemberCache implements ExternalStore<ReadonlyMap<string, ImGroupMember>> {
|
|
10
|
+
readonly im: GuokitIm;
|
|
11
|
+
readonly groupId: string;
|
|
12
|
+
static readonly max = 500;
|
|
13
|
+
private map;
|
|
14
|
+
private list;
|
|
15
|
+
private gen;
|
|
16
|
+
private disposed;
|
|
17
|
+
private off;
|
|
18
|
+
private listeners;
|
|
19
|
+
constructor(im: GuokitIm, groupId: string);
|
|
20
|
+
subscribe: (fn: () => void) => (() => void);
|
|
21
|
+
getSnapshot: () => ReadonlyMap<string, ImGroupMember>;
|
|
22
|
+
/** 开始监听群变动并拉第一次。重复调用无效。 */
|
|
23
|
+
start(): void;
|
|
24
|
+
/** 当前在群的成员,按进群先后。 */
|
|
25
|
+
get members(): readonly ImGroupMember[];
|
|
26
|
+
get(userId: string): ImGroupMember | undefined;
|
|
27
|
+
/** 显示名:在缓存里用昵称(空时 userId),不在(已退群)用 userId。 */
|
|
28
|
+
nameOf(userId: string): string;
|
|
29
|
+
reload(): Promise<void>;
|
|
30
|
+
dispose(): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** 输入框里的一个 @:显示为「@昵称 」,发送时换成 userId(`@all` 为所有人)。 */
|
|
2
|
+
export interface ImMention {
|
|
3
|
+
userId: string;
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
/** 输入框的文本与光标(光标是 UTF-16 下标,同 `textarea.selectionStart`)。 */
|
|
7
|
+
export interface TextEdit {
|
|
8
|
+
text: string;
|
|
9
|
+
cursor: number;
|
|
10
|
+
}
|
|
11
|
+
/** 一个 @ 在文本里的样子:`@昵称 `(末尾一个空格)。 */
|
|
12
|
+
export declare const mentionToken: (m: ImMention) => string;
|
|
13
|
+
/**
|
|
14
|
+
* 群 @ 的编辑规则:插入、整段删除、发送时取 at 列表。纯逻辑,不碰 DOM。同 Flutter `MentionEditing`。
|
|
15
|
+
*/
|
|
16
|
+
export declare class MentionEditing {
|
|
17
|
+
/** 一条最多 @ 20 人(服务端限制)。 */
|
|
18
|
+
static readonly maxAt = 20;
|
|
19
|
+
private list;
|
|
20
|
+
get mentions(): readonly ImMention[];
|
|
21
|
+
clear(): void;
|
|
22
|
+
/** 把 `value` 里 `atIndex` 处那个「@」换成 `@昵称 `,光标放到它后面;那里不是「@」时插在光标处。 */
|
|
23
|
+
insert(value: TextEdit, atIndex: number, m: ImMention): TextEdit;
|
|
24
|
+
/**
|
|
25
|
+
* 输入变化时调:删除碰到某个 `@昵称 ` 时把整段删掉。返回应当显示的值;没变就原样返回 `next`(同一引用)。
|
|
26
|
+
* 删除同时有插入(替换选区)时不处理。
|
|
27
|
+
*/
|
|
28
|
+
onChanged(old: string, next: TextEdit): TextEdit;
|
|
29
|
+
/** 发送时的 at 列表:文字里还完整留着的 @,去重,最多 20 个。 */
|
|
30
|
+
atIds(text: string): string[];
|
|
31
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 首字母分节(spec §5,口径同 Flutter `indexed_list.dart`)。不引拼音库:用浏览器自带的拼音排序规则
|
|
3
|
+
* `Intl.Collator('zh-Hans-CN-u-co-pinyin')`,拿每个字母在拼音序里的第一个字当边界,二分出首字母。
|
|
4
|
+
*/
|
|
5
|
+
/** 索引条上的字母,`#` 排最后。 */
|
|
6
|
+
export declare const indexLetters: readonly ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "#"];
|
|
7
|
+
export type IndexLetter = (typeof indexLetters)[number];
|
|
8
|
+
export interface IndexSection<T> {
|
|
9
|
+
letter: IndexLetter;
|
|
10
|
+
items: T[];
|
|
11
|
+
}
|
|
12
|
+
/** 名字所在的节:英文字母取大写,汉字取拼音首字母,其他归 `#`。 */
|
|
13
|
+
export declare function indexLetterOf(name: string): IndexLetter;
|
|
14
|
+
/** 按首字母分节:节按 A–Z、# 排;节内按拼音序、再按 idOf 排。 */
|
|
15
|
+
export declare function indexSections<T>(items: Iterable<T>, nameOf: (it: T) => string, idOf: (it: T) => string): IndexSection<T>[];
|