@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.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +158 -2
  3. package/dist/index.cjs +5279 -0
  4. package/dist/index.mjs +5257 -0
  5. package/dist/style.css +571 -0
  6. package/dist/types/core/chatController.d.ts +121 -0
  7. package/dist/types/core/externalStore.d.ts +25 -0
  8. package/dist/types/core/features.d.ts +8 -0
  9. package/dist/types/core/format.d.ts +32 -0
  10. package/dist/types/core/groupAvatarCache.d.ts +37 -0
  11. package/dist/types/core/imStore.d.ts +13 -0
  12. package/dist/types/core/index.d.ts +11 -0
  13. package/dist/types/core/media.d.ts +37 -0
  14. package/dist/types/core/memberCache.d.ts +31 -0
  15. package/dist/types/core/mention.d.ts +31 -0
  16. package/dist/types/core/pinyinIndex.d.ts +15 -0
  17. package/dist/types/core/strings.d.ts +315 -0
  18. package/dist/types/index.d.ts +15 -0
  19. package/dist/types/ui/chat/ChatPage.d.ts +11 -0
  20. package/dist/types/ui/chat/Composer.d.ts +29 -0
  21. package/dist/types/ui/chat/MessageList.d.ts +17 -0
  22. package/dist/types/ui/chat/MessageRow.d.ts +24 -0
  23. package/dist/types/ui/chat/bubbles.d.ts +26 -0
  24. package/dist/types/ui/chat/emojis.d.ts +2 -0
  25. package/dist/types/ui/contacts/AddFriendDialog.d.ts +2 -0
  26. package/dist/types/ui/contacts/ContactsPage.d.ts +9 -0
  27. package/dist/types/ui/contacts/FriendGroups.d.ts +6 -0
  28. package/dist/types/ui/contacts/FriendSettings.d.ts +4 -0
  29. package/dist/types/ui/contacts/NewFriendsPage.d.ts +2 -0
  30. package/dist/types/ui/contacts/UserCard.d.ts +8 -0
  31. package/dist/types/ui/contacts/index.d.ts +5 -0
  32. package/dist/types/ui/contacts/routes.d.ts +4 -0
  33. package/dist/types/ui/contacts/shared.d.ts +33 -0
  34. package/dist/types/ui/context.d.ts +44 -0
  35. package/dist/types/ui/conversation/ConversationList.d.ts +13 -0
  36. package/dist/types/ui/group/GroupChats.d.ts +2 -0
  37. package/dist/types/ui/group/GroupInfo.d.ts +9 -0
  38. package/dist/types/ui/group/GroupMembers.d.ts +11 -0
  39. package/dist/types/ui/group/GroupNotice.d.ts +8 -0
  40. package/dist/types/ui/group/SelectFriends.d.ts +8 -0
  41. package/dist/types/ui/group/routes.d.ts +4 -0
  42. package/dist/types/ui/group/shared.d.ts +47 -0
  43. package/dist/types/ui/hooks.d.ts +9 -0
  44. package/dist/types/ui/layout/ImWorkspace.d.ts +8 -0
  45. package/dist/types/ui/layout/Layers.d.ts +19 -0
  46. package/dist/types/ui/layout/frame.d.ts +14 -0
  47. package/dist/types/ui/layout/useWide.d.ts +4 -0
  48. package/dist/types/ui/menu/Report.d.ts +7 -0
  49. package/dist/types/ui/navigator.d.ts +111 -0
  50. package/dist/types/ui/privacy/PrivacyPage.d.ts +7 -0
  51. package/dist/types/ui/privacy/routes.d.ts +4 -0
  52. package/dist/types/ui/routes.d.ts +7 -0
  53. package/dist/types/ui/theme.d.ts +30 -0
  54. package/dist/types/ui/types.d.ts +44 -0
  55. package/dist/types/ui/viewer/ImageViewer.d.ts +6 -0
  56. package/dist/types/ui/viewer/VideoPlayer.d.ts +5 -0
  57. package/dist/types/ui/widgets/Avatar.d.ts +16 -0
  58. package/dist/types/ui/widgets/GroupAvatar.d.ts +21 -0
  59. package/dist/types/ui/widgets/Icon.d.ts +43 -0
  60. package/dist/types/ui/widgets/IndexedList.d.ts +14 -0
  61. package/dist/types/ui/widgets/Menu.d.ts +36 -0
  62. package/dist/types/ui/widgets/Page.d.ts +16 -0
  63. package/dist/types/ui/widgets/UnreadBadge.d.ts +11 -0
  64. package/dist/types/ui/widgets/feedback.d.ts +23 -0
  65. package/dist/types/ui/widgets/useFocusTrap.d.ts +2 -0
  66. package/package.json +54 -4
@@ -0,0 +1,47 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type ImConversation, type ImGroup, type ImGroupMember } from '@guokit-dev/im';
3
+ import { MemberCache } from '../../core/memberCache';
4
+ import { type ImUiStrings } from '../../core/strings';
5
+ export declare function sameId(a: string, b: string): boolean;
6
+ export declare function errorText(e: unknown, s: ImUiStrings): string;
7
+ /** 成员显示名:昵称为空时用 userId。 */
8
+ export declare function memberName(m: ImGroupMember): string;
9
+ /** 角色标签:2 群主、1 管理员、0 成员。 */
10
+ export declare function roleName(role: number, s: ImUiStrings): string;
11
+ /** 剩余时长:不足 1 小时按分钟、不足 1 天按小时、再长按天,都向上取整(同 Flutter `remainingText`)。 */
12
+ export declare function remainingText(ms: number, s: ImUiStrings): string;
13
+ /** 本地日期「年/月/日」,可选带「时:分」。 */
14
+ export declare function ymd(ms: number, withTime?: boolean): string;
15
+ /**
16
+ * 群资料:进来拉一次,收到本群的 `groupChanged` 再拉(SDK 不缓存群资料)。
17
+ * 拉失败且还没有数据时给 error。
18
+ */
19
+ export declare function useGroup(groupId: string): {
20
+ group: ImGroup | null;
21
+ error: unknown;
22
+ reload: () => Promise<void>;
23
+ setGroup: import("react").Dispatch<import("react").SetStateAction<ImGroup | null>>;
24
+ };
25
+ /** 本页自己的群成员缓存(按进群先后,500 人封顶),群变动时自动重拉。groupId 为 null 时不拉。 */
26
+ export declare function useMembers(groupId: string | null): {
27
+ cache: MemberCache | null;
28
+ map: ReadonlyMap<string, ImGroupMember>;
29
+ members: ImGroupMember[];
30
+ };
31
+ /** 本地会话里的这个群(免打扰、置顶、清空记录用);还没有会话时为 null。 */
32
+ export declare function useGroupConversation(groupId: string): ImConversation | null;
33
+ /** 开关(role=switch)。 */
34
+ export declare function Switch({ label, checked, onChange, disabled }: {
35
+ label: string;
36
+ checked: boolean;
37
+ onChange: (v: boolean) => void;
38
+ disabled?: boolean;
39
+ }): import("react").JSX.Element;
40
+ /** 设置行:标题 + 右侧值或开关;传了 onClick 就是可点的行。 */
41
+ export declare function SettingRow({ title, value, sub, trailing, onClick }: {
42
+ title: string;
43
+ value?: ReactNode;
44
+ sub?: ReactNode;
45
+ trailing?: ReactNode;
46
+ onClick?: () => void;
47
+ }): import("react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import type { ImConnectionState, ImConversation, ImFriend } from '@guokit-dev/im';
2
+ /** 会话列表快照,置顶在前;未登录时是空数组。 */
3
+ export declare function useConversations(): readonly ImConversation[];
4
+ /** 总未读(免打扰不计)。 */
5
+ export declare function useTotalUnread(): number;
6
+ /** 实时连接状态。 */
7
+ export declare function useConnection(): ImConnectionState;
8
+ /** 好友快照(按 userId 升序);第一次订阅时触发对账,冷启动先是空的。 */
9
+ export declare function useFriends(): readonly ImFriend[];
@@ -0,0 +1,8 @@
1
+ export interface ImWorkspaceProps {
2
+ className?: string;
3
+ }
4
+ /**
5
+ * 开箱即用的整页,撑满父容器。容器宽 ≥ 768px 时导航条 + 列表栏 + 主区 + 右侧抽屉,
6
+ * 否则单栏页面栈(样式照 Flutter 稿)。
7
+ */
8
+ export declare function ImWorkspace({ className }: ImWorkspaceProps): import("react").JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { type NavState } from '../navigator';
2
+ /** 右侧抽屉:只显示栈顶,下面的保留挂载(返回时状态还在)。 */
3
+ export declare function DrawerLayer({ stack, back, close }: {
4
+ stack: NavState['drawer'];
5
+ back(): void;
6
+ close(): void;
7
+ }): import("react").JSX.Element | null;
8
+ /** 居中对话框,可以叠多层,每层一个遮罩。 */
9
+ export declare function DialogLayer({ stack, back }: {
10
+ stack: NavState['dialog'];
11
+ back(): void;
12
+ }): import("react").JSX.Element;
13
+ /** 全屏遮罩(图片、视频预览),宽窄屏都是遮罩。 */
14
+ export declare function OverlayLayer({ stack, back }: {
15
+ stack: NavState['overlay'];
16
+ back(): void;
17
+ }): import("react").JSX.Element;
18
+ /** 单页组件模式的浮层宿主:渲染 Provider 视图栈里的抽屉、对话框与遮罩。 */
19
+ export declare function LayerHost(): import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 页面所在的框:宽屏 main / list / drawer / dialog,窄屏 page(整页,带返回)。
3
+ * 页面组件据此决定头部画返回、关闭还是什么都不画。
4
+ */
5
+ export interface Frame {
6
+ kind: 'main' | 'list' | 'drawer' | 'dialog' | 'page' | 'standalone';
7
+ /** 头部要不要画返回(窄屏非底页、抽屉内堆栈非底层)。 */
8
+ canBack: boolean;
9
+ back(): void;
10
+ /** 关掉这一层(抽屉整体、对话框)。 */
11
+ close(): void;
12
+ }
13
+ export declare const FrameContext: import("react").Context<Frame>;
14
+ export declare function useFrame(): Frame;
@@ -0,0 +1,4 @@
1
+ import { type RefObject } from 'react';
2
+ /** 宽屏断点:看容器宽度,不看视口,宿主把整页嵌在局部也能切对。 */
3
+ export declare const WIDE_MIN = 768;
4
+ export declare function useWide(ref: RefObject<HTMLElement | null>): boolean;
@@ -0,0 +1,7 @@
1
+ import { type ImTarget } from '@guokit-dev/im';
2
+ /** 举报:原因单选两列,可勾选同时加入黑名单(设计稿 06,口径同 Flutter `showReportSheet`)。 */
3
+ export declare function ReportDialog({ target, title, messageIds }: {
4
+ target: ImTarget;
5
+ title: string;
6
+ messageIds?: number[];
7
+ }): import("react").JSX.Element;
@@ -0,0 +1,111 @@
1
+ import type { ImConversation, ImMessage, ImTarget } from '@guokit-dev/im';
2
+ /** 打开聊天的目标:三选一(C 期再加 service / anchor)。 */
3
+ export interface ChatRouteTarget {
4
+ conversation?: ImConversation;
5
+ peer?: string;
6
+ group?: string;
7
+ }
8
+ /** 内置视图栈的路由。各期往这里加成员;宽屏放在哪由 `routePlacement` 决定(spec §4)。 */
9
+ export type ImRoute = {
10
+ name: 'conversations';
11
+ } | {
12
+ name: 'chat';
13
+ target: ChatRouteTarget;
14
+ } | {
15
+ name: 'report';
16
+ target: ImTarget;
17
+ title: string;
18
+ messageIds?: number[];
19
+ } | {
20
+ name: 'imageViewer';
21
+ images: ImMessage[];
22
+ index: number;
23
+ } | {
24
+ name: 'videoPlayer';
25
+ message: ImMessage;
26
+ } | {
27
+ name: 'contacts';
28
+ } | {
29
+ name: 'contactProfile';
30
+ userId: string;
31
+ } | {
32
+ name: 'newFriends';
33
+ } | {
34
+ name: 'groupChats';
35
+ } | {
36
+ name: 'privacy';
37
+ } | {
38
+ name: 'blocklist';
39
+ } | {
40
+ name: 'userCard';
41
+ userId: string;
42
+ } | {
43
+ name: 'friendSettings';
44
+ userId: string;
45
+ } | {
46
+ name: 'friendGroups';
47
+ } | {
48
+ name: 'groupInfo';
49
+ groupId: string;
50
+ } | {
51
+ name: 'groupMembers';
52
+ groupId: string;
53
+ } | {
54
+ name: 'groupNotice';
55
+ groupId: string;
56
+ } | {
57
+ name: 'addFriend';
58
+ }
59
+ /** 不传 groupId 是发起群聊,传了是邀请进群。 */
60
+ | {
61
+ name: 'selectFriends';
62
+ groupId?: string;
63
+ };
64
+ export type ImRouteName = ImRoute['name'];
65
+ /**
66
+ * main 主区、list 列表栏、drawer 右侧抽屉(内部堆栈)、dialog 居中对话框、overlay 全屏遮罩(预览)。
67
+ * 窄屏下 main / drawer / dialog 都变成整页 push,overlay 仍是遮罩。
68
+ */
69
+ export type ImPlacement = 'main' | 'list' | 'drawer' | 'dialog' | 'overlay';
70
+ export declare const routePlacement: Record<ImRouteName, ImPlacement>;
71
+ export interface NavState {
72
+ list: ImRoute;
73
+ main: ImRoute | null;
74
+ drawer: ImRoute[];
75
+ dialog: ImRoute[];
76
+ overlay: ImRoute[];
77
+ }
78
+ export declare const initialNav: NavState;
79
+ type Action = {
80
+ type: 'open';
81
+ route: ImRoute;
82
+ as?: ImPlacement;
83
+ } | {
84
+ type: 'back';
85
+ } | {
86
+ type: 'close';
87
+ };
88
+ export declare function navReducer(s: NavState, a: Action): NavState;
89
+ /** 最上层的路由(窄屏当前页、宽屏最上层浮层或主区)。 */
90
+ export declare function topRoute(s: NavState): ImRoute | null;
91
+ export interface ImNavigator {
92
+ /** 打开一个路由,按放置规则落到主区、列表栏、抽屉或对话框。 */
93
+ open(route: ImRoute): void;
94
+ /** 退一层:遮罩 → 对话框 → 抽屉 → 主区。 */
95
+ back(): void;
96
+ /** 关掉所有抽屉、对话框与遮罩。 */
97
+ close(): void;
98
+ }
99
+ export interface NavContextValue extends ImNavigator {
100
+ state: NavState;
101
+ /** true 时 main / list 路由由视图栈自己渲染(ImWorkspace);false 时交给 `onMainOrList`(单页组件)。 */
102
+ workspace: boolean;
103
+ }
104
+ export declare const NavContext: import("react").Context<NavContextValue | null>;
105
+ /** 建一个视图栈。`onMainOrList` 给单页组件模式用:主区、列表栏类路由不入栈,交给它处理。 */
106
+ export declare function useNavState(workspace: boolean, onMainOrList?: (r: ImRoute) => void): NavContextValue;
107
+ /** 组件内部用:带状态的视图栈。 */
108
+ export declare function useNavContext(): NavContextValue;
109
+ /** 当前视图栈:`open(route)`、`back()`、`close()`。要放在 `GuokitImUi` 下面。 */
110
+ export declare function useImNavigator(): ImNavigator;
111
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 隐私:加好友方式三选一(进来读 `features().addPolicy`,点了即 `setFriendAddPolicy`,失败回滚)。
3
+ * 宽屏主区里黑名单作为第二段直接列出(设计稿 12);窄屏、抽屉里是一行入口,点进黑名单页。同 Flutter `ImPrivacyPage`。
4
+ */
5
+ export declare function ImPrivacy(): import("react").JSX.Element;
6
+ /** 黑名单页(窄屏从隐私页进入)。 */
7
+ export declare function BlocklistPage(): import("react").JSX.Element;
@@ -0,0 +1,4 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ImRoute } from '../navigator';
3
+ /** 隐私与黑名单路由(B5)。认领的路由返回页面,其他返回 undefined。 */
4
+ export declare function renderPrivacyRoute(route: ImRoute): ReactNode | undefined;
@@ -0,0 +1,7 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ImRoute } from './navigator';
3
+ /**
4
+ * 路由 → 页面。静态 switch,不用模块副作用登记(包声明了 sideEffects 只含 CSS,登记式会被打包器摇掉)。
5
+ * 页面不 import 本文件,避免循环。
6
+ */
7
+ export declare function renderRoute(route: ImRoute): ReactNode;
@@ -0,0 +1,30 @@
1
+ import type { CSSProperties } from 'react';
2
+ /** 头像形状:circle 圆形,rounded 圆角方形。 */
3
+ export type ImAvatarShape = 'circle' | 'rounded';
4
+ /**
5
+ * 皮肤。每项对应 `.gkim-root` 上的一个 CSS 变量,没设的用样式表里的默认值;
6
+ * 宿主也可以在 `@layer gkim` 之后直接写 CSS 覆盖这些变量。对照 Flutter `ImUiTheme`。
7
+ */
8
+ export interface ImUiTheme {
9
+ /** 强调色,默认 #2563EB。本人气泡、按钮、选中态都跟它。 */
10
+ accent?: string;
11
+ /** 本人气泡底色,默认跟 accent。 */
12
+ selfBubble?: string;
13
+ selfBubbleText?: string;
14
+ peerBubble?: string;
15
+ peerBubbleText?: string;
16
+ /** 气泡圆角,默认 12;靠头像的那个角固定为 4。数字按 px。 */
17
+ bubbleRadius?: number | string;
18
+ /** 单聊头像形状,默认 circle。 */
19
+ avatarShape?: ImAvatarShape;
20
+ /** 群头像形状,默认 rounded。 */
21
+ groupAvatarShape?: ImAvatarShape;
22
+ /** 聊天页头像边长,默认 40;会话列表是它的 1.2 倍。 */
23
+ avatarSize?: number;
24
+ /** 聊天页背景,默认 #F5F6F8。 */
25
+ chatBackground?: string;
26
+ /** 时间分隔字号,默认 12。 */
27
+ timeDividerSize?: number;
28
+ }
29
+ /** 把 theme 写成 `.gkim-root` 的行内 CSS 变量。 */
30
+ export declare function themeVars(t: ImUiTheme | undefined): CSSProperties;
@@ -0,0 +1,44 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ImCard, ImMessage } from '@guokit-dev/im';
3
+ import type { ChatTargetInfo } from '../core/chatController';
4
+ /**
5
+ * 当前聊天的对象,给「+」菜单的宿主扩展项用:单聊 `im.sendCustom(target.to, …)`,群聊 `im.sendCustom({ groupId: target.groupId }, …)`。
6
+ * 字段同 Flutter `ImChatTarget`:peerId 单聊对方(群聊 null)、groupId 群号(单聊 null)、conversationId 会话 id(还没有会话时 null)、to 群聊为空串。
7
+ */
8
+ export type ImChatTarget = ChatTargetInfo;
9
+ /** 「+」菜单里宿主追加的一项。 */
10
+ export interface ImMoreItem {
11
+ icon?: ReactNode;
12
+ label: string;
13
+ onClick: (target: ImChatTarget) => void;
14
+ }
15
+ /** 消息「更多」与右键菜单里宿主追加的一项。 */
16
+ export interface ImMenuItem {
17
+ icon?: ReactNode;
18
+ label: string;
19
+ onClick: (message: ImMessage) => void;
20
+ }
21
+ /** 交给宿主处理的事件。传了就走宿主;没传时打开组件内置页(语义同 Flutter `ImUiCallbacks`)。 */
22
+ export interface ImUiCallbacks {
23
+ /** 点头像,参数是 userId;点自己不回调。不传时打开内置资料卡(B 期)。 */
24
+ onAvatarTap?: (userId: string) => void;
25
+ /** 点业务卡片。不传时打开卡片链接:优先 webLink,其次 appLink,新标签页打开。 */
26
+ onCardTap?: (card: ImCard, message: ImMessage) => void;
27
+ /** 点位置消息。不传时位置气泡不可点。 */
28
+ onLocationTap?: (message: ImMessage) => void;
29
+ /** 点群聊右上角的群资料按钮。不传时打开内置群资料(B 期)。 */
30
+ onGroupInfoTap?: (groupId: string) => void;
31
+ /** 当前账号在别处登录或被服务端踢下线。宿主一般回登录页。 */
32
+ onKickedOut?: () => void;
33
+ /** 单页组件里点会话或「发消息」。`ImWorkspace` 内由组件自己打开,不回调。 */
34
+ onOpenConversation?: (target: ImChatTarget) => void;
35
+ /** 内置视图栈变化(`ImWorkspace` 内),参数是最上层路由;宿主要接浏览器后退键时用。 */
36
+ onNavigate?: (route: import('./navigator').ImRoute | null) => void;
37
+ }
38
+ /** 按消息 type 覆盖气泡内容;返回 null 时走默认渲染。 */
39
+ export type ImMessageRenderer = (message: ImMessage) => ReactNode | null;
40
+ /** 本人昵称与头像:SDK 不提供本人资料,聊天页本人头像用(群聊里优先用群成员资料)。 */
41
+ export interface ImMe {
42
+ nickname?: string;
43
+ avatarUrl?: string;
44
+ }
@@ -0,0 +1,6 @@
1
+ import type { ImMessage } from '@guokit-dev/im';
2
+ /** 图片预览:全屏遮罩,滚轮或按钮缩放、双击放大,← → 切换同会话已加载的图片,Esc 关闭,可在新标签页打开原图(设计稿 05)。 */
3
+ export declare function ImageViewer({ images, index }: {
4
+ images: ImMessage[];
5
+ index: number;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import type { ImMessage } from '@guokit-dev/im';
2
+ /** 视频:遮罩里用原生 `<video controls>` 播放。 */
3
+ export declare function VideoPlayer({ message }: {
4
+ message: ImMessage;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,16 @@
1
+ export declare function avatarColor(id: string): string;
2
+ export declare function avatarInitial(name: string, id: string): string;
3
+ export interface AvatarProps {
4
+ /** 取底色的稳定标识(userId 或 groupId)。 */
5
+ id: string;
6
+ /** 显示名,取第一个字作占位。 */
7
+ name: string;
8
+ url?: string;
9
+ /** 边长 px;不传时用 `--gkim-avatar-size`。 */
10
+ size?: number;
11
+ /** group 时用 `--gkim-group-avatar-radius`。 */
12
+ group?: boolean;
13
+ onClick?: () => void;
14
+ }
15
+ /** 头像:有图显示图,没图或加载失败显示名字首字。 */
16
+ export declare function Avatar({ id, name, url, size, group, onClick }: AvatarProps): import("react").JSX.Element;
@@ -0,0 +1,21 @@
1
+ import type { ImGroupMember } from '@guokit-dev/im';
2
+ export interface ImGroupAvatarProps {
3
+ groupId: string;
4
+ /** 群名,单色块兜底时取首字。 */
5
+ name?: string;
6
+ /** 群头像;非空时直接用,不拉成员。 */
7
+ url?: string;
8
+ /** 边长 px;不传时用 `--gkim-avatar-size`(会话列表里是放大后的尺寸)。 */
9
+ size?: number;
10
+ }
11
+ /** 九宫格本体:最多前 9 人,1–4 人两列、5–9 人三列,内边距与格间距 2px。 */
12
+ export declare function GroupGrid({ members, label, size }: {
13
+ members: ImGroupMember[];
14
+ label: string;
15
+ size?: number;
16
+ }): import("react").JSX.Element;
17
+ /**
18
+ * 九宫格群头像:群设了头像直接用;没设时取前 9 名成员拼格子。滚进视口才拉(同一个 im 共用缓存,
19
+ * 同时最多 3 个请求),进退群或改群头像时重拉;拉不到时退回单色块。同 Flutter `ImGroupAvatar`。
20
+ */
21
+ export declare function ImGroupAvatar({ groupId, name, url, size }: ImGroupAvatarProps): import("react").JSX.Element;
@@ -0,0 +1,43 @@
1
+ declare const PATHS: {
2
+ readonly message: import("react").JSX.Element;
3
+ readonly back: import("react").JSX.Element;
4
+ readonly close: import("react").JSX.Element;
5
+ readonly more: import("react").JSX.Element;
6
+ readonly emoji: import("react").JSX.Element;
7
+ readonly image: import("react").JSX.Element;
8
+ readonly file: import("react").JSX.Element;
9
+ readonly plus: import("react").JSX.Element;
10
+ readonly copy: import("react").JSX.Element;
11
+ readonly recall: import("react").JSX.Element;
12
+ readonly report: import("react").JSX.Element;
13
+ readonly down: import("react").JSX.Element;
14
+ readonly play: import("react").JSX.Element;
15
+ readonly pause: import("react").JSX.Element;
16
+ readonly zoomIn: import("react").JSX.Element;
17
+ readonly zoomOut: import("react").JSX.Element;
18
+ readonly external: import("react").JSX.Element;
19
+ readonly location: import("react").JSX.Element;
20
+ readonly alert: import("react").JSX.Element;
21
+ readonly retry: import("react").JSX.Element;
22
+ readonly group: import("react").JSX.Element;
23
+ readonly check: import("react").JSX.Element;
24
+ readonly checkAll: import("react").JSX.Element;
25
+ readonly mute: import("react").JSX.Element;
26
+ readonly add: import("react").JSX.Element;
27
+ readonly userPlus: import("react").JSX.Element;
28
+ readonly chatPlus: import("react").JSX.Element;
29
+ readonly contacts: import("react").JSX.Element;
30
+ readonly shield: import("react").JSX.Element;
31
+ readonly search: import("react").JSX.Element;
32
+ readonly edit: import("react").JSX.Element;
33
+ readonly grip: import("react").JSX.Element;
34
+ readonly minus: import("react").JSX.Element;
35
+ readonly chevron: import("react").JSX.Element;
36
+ readonly minusLine: import("react").JSX.Element;
37
+ };
38
+ export type IconName = keyof typeof PATHS;
39
+ export declare function Icon({ name, size }: {
40
+ name: IconName;
41
+ size?: number;
42
+ }): import("react").JSX.Element;
43
+ export {};
@@ -0,0 +1,14 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type IndexSection } from '../../core/pinyinIndex';
3
+ export interface IndexedListProps<T> {
4
+ sections: IndexSection<T>[];
5
+ renderItem: (item: T) => ReactNode;
6
+ keyOf: (item: T) => string;
7
+ /** 跟着列表一起滚的头部(搜索框、入口、分组)。 */
8
+ header?: ReactNode;
9
+ /** 列表末尾(空态、人数)。 */
10
+ footer?: ReactNode;
11
+ className?: string;
12
+ }
13
+ /** 首字母分节列表 + 右侧 ↑ A–Z # 索引条(可点可拖)。通讯录与选择好友共用,同 Flutter `ImIndexedList`。 */
14
+ export declare function IndexedList<T>({ sections, renderItem, keyOf, header, footer, className }: IndexedListProps<T>): import("react").JSX.Element;
@@ -0,0 +1,36 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface MenuEntry {
3
+ label: string;
4
+ icon?: ReactNode;
5
+ danger?: boolean;
6
+ disabled?: boolean;
7
+ onSelect: () => void;
8
+ /** 二级菜单(如禁言时长)。 */
9
+ children?: MenuEntry[];
10
+ }
11
+ export interface MenuProps {
12
+ entries: MenuEntry[];
13
+ /** 视口坐标:右键时是鼠标位置,按钮触发时是按钮左下角。 */
14
+ x: number;
15
+ y: number;
16
+ onClose: () => void;
17
+ label?: string;
18
+ }
19
+ /** 浮动菜单:贴着坐标弹、超出视口时翻转;上下键移动、Enter 选择、Esc 或点外面关闭,关闭后焦点还给触发点。 */
20
+ export declare function Menu({ entries, x, y, onClose, label }: MenuProps): import("react").ReactPortal;
21
+ export interface MenuState {
22
+ x: number;
23
+ y: number;
24
+ }
25
+ /** 右键与触屏长按(500ms)打开同一个菜单。返回绑在目标元素上的事件与当前菜单位置。 */
26
+ export declare function useContextMenu(): {
27
+ at: MenuState | null;
28
+ open: import("react").Dispatch<import("react").SetStateAction<MenuState | null>>;
29
+ close: () => void;
30
+ bind: {
31
+ onContextMenu: (e: React.MouseEvent) => void;
32
+ onTouchStart: (e: React.TouchEvent) => void;
33
+ onTouchMove: (e: React.TouchEvent) => void;
34
+ onTouchEnd: () => void;
35
+ };
36
+ };
@@ -0,0 +1,16 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface PageProps {
3
+ title: ReactNode;
4
+ /** 标题右侧的按钮。 */
5
+ actions?: ReactNode;
6
+ /** 头部下方、正文上方的一条(断线横条、客服状态条)。 */
7
+ banner?: ReactNode;
8
+ /** 底部固定区(输入区、对话框按钮)。 */
9
+ footer?: ReactNode;
10
+ children?: ReactNode;
11
+ className?: string;
12
+ /** 正文自己管滚动(聊天消息列表)时传 false。 */
13
+ scroll?: boolean;
14
+ }
15
+ /** 内置页的骨架:头部 + 正文 + 底部。按所在的框画返回或关闭,对话框框里画成卡片。 */
16
+ export declare function Page({ title, actions, banner, footer, children, className, scroll }: PageProps): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import type { ReactNode } from 'react';
2
+ /** 未读角标:数字(超过 99 显示 99+)或小红点。count 为 0 且不是 dot 时不渲染。 */
3
+ export declare function Badge({ count, dot, muted }: {
4
+ count?: number;
5
+ dot?: boolean;
6
+ muted?: boolean;
7
+ }): import("react").JSX.Element | null;
8
+ /** 在宿主自己的图标(如底部「消息」tab)右上角叠总未读角标,同 Flutter `ImUnreadBadge`。 */
9
+ export declare function ImUnreadBadge({ children }: {
10
+ children: ReactNode;
11
+ }): import("react").JSX.Element;
@@ -0,0 +1,23 @@
1
+ import { type ReactNode } from 'react';
2
+ interface ConfirmOptions {
3
+ title?: string;
4
+ content: string;
5
+ ok?: string;
6
+ /** 确定按钮用警示色。 */
7
+ danger?: boolean;
8
+ }
9
+ interface Feedback {
10
+ /** 底部轻提示,2.5 秒后消失。 */
11
+ toast(text: string): void;
12
+ /** 二次确认,确定返回 true。 */
13
+ confirm(o: ConfirmOptions): Promise<boolean>;
14
+ }
15
+ export declare function FeedbackProvider({ labels, children }: {
16
+ labels: {
17
+ ok: string;
18
+ cancel: string;
19
+ };
20
+ children: ReactNode;
21
+ }): import("react").JSX.Element;
22
+ export declare function useFeedback(): Feedback;
23
+ export {};
@@ -0,0 +1,2 @@
1
+ /** 打开时把焦点移进容器、Tab 在容器里循环;卸载时把焦点还给打开前的元素。 */
2
+ export declare function useFocusTrap<T extends HTMLElement>(active?: boolean): import("react").RefObject<T | null>;
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@guokit-dev/im-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.28.0",
4
+ "description": "guokit IM 的 React UI 组件:开箱即用的整页会话、聊天,可换皮",
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/guokit/guokit-im-sdk.git",
12
+ "directory": "react"
13
+ },
14
+ "type": "module",
15
+ "main": "./dist/index.cjs",
16
+ "module": "./dist/index.mjs",
17
+ "types": "./dist/types/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/types/index.d.ts",
21
+ "import": "./dist/index.mjs",
22
+ "require": "./dist/index.cjs"
23
+ },
24
+ "./style.css": "./dist/style.css"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "README.md",
29
+ "LICENSE"
30
+ ],
31
+ "sideEffects": [
32
+ "*.css"
33
+ ],
34
+ "scripts": {
35
+ "build": "node build.mjs",
36
+ "test": "vitest run",
37
+ "type-check": "tsc --noEmit -p tsconfig.test.json"
38
+ },
39
+ "peerDependencies": {
40
+ "@guokit-dev/im": ">=0.28.0 <1",
41
+ "react": ">=18.2 <20",
42
+ "react-dom": ">=18.2 <20"
43
+ },
44
+ "devDependencies": {
45
+ "@guokit-dev/im": "file:../js",
46
+ "@testing-library/react": "^16.3.0",
47
+ "@types/react": "^19.1.0",
48
+ "@types/react-dom": "^19.1.0",
49
+ "esbuild": "^0.28.2",
50
+ "jsdom": "^27.0.0",
51
+ "react": "^19.1.0",
52
+ "react-dom": "^19.1.0",
53
+ "typescript": "5.9.3",
54
+ "vitest": "^4.0.0"
55
+ }
56
+ }