@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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +147 -2
  3. package/dist/index.cjs +3095 -0
  4. package/dist/index.mjs +3073 -0
  5. package/dist/style.css +280 -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/imStore.d.ts +8 -0
  11. package/dist/types/core/index.d.ts +9 -0
  12. package/dist/types/core/media.d.ts +37 -0
  13. package/dist/types/core/memberCache.d.ts +31 -0
  14. package/dist/types/core/mention.d.ts +31 -0
  15. package/dist/types/core/strings.d.ts +309 -0
  16. package/dist/types/index.d.ts +11 -0
  17. package/dist/types/ui/chat/ChatPage.d.ts +11 -0
  18. package/dist/types/ui/chat/Composer.d.ts +29 -0
  19. package/dist/types/ui/chat/MessageList.d.ts +17 -0
  20. package/dist/types/ui/chat/MessageRow.d.ts +24 -0
  21. package/dist/types/ui/chat/bubbles.d.ts +26 -0
  22. package/dist/types/ui/chat/emojis.d.ts +2 -0
  23. package/dist/types/ui/context.d.ts +44 -0
  24. package/dist/types/ui/conversation/ConversationList.d.ts +13 -0
  25. package/dist/types/ui/hooks.d.ts +7 -0
  26. package/dist/types/ui/layout/ImWorkspace.d.ts +8 -0
  27. package/dist/types/ui/layout/Layers.d.ts +19 -0
  28. package/dist/types/ui/layout/frame.d.ts +14 -0
  29. package/dist/types/ui/layout/useWide.d.ts +4 -0
  30. package/dist/types/ui/menu/Report.d.ts +7 -0
  31. package/dist/types/ui/navigator.d.ts +73 -0
  32. package/dist/types/ui/routes.d.ts +7 -0
  33. package/dist/types/ui/theme.d.ts +30 -0
  34. package/dist/types/ui/types.d.ts +44 -0
  35. package/dist/types/ui/viewer/ImageViewer.d.ts +6 -0
  36. package/dist/types/ui/viewer/VideoPlayer.d.ts +5 -0
  37. package/dist/types/ui/widgets/Avatar.d.ts +16 -0
  38. package/dist/types/ui/widgets/Icon.d.ts +32 -0
  39. package/dist/types/ui/widgets/Menu.d.ts +36 -0
  40. package/dist/types/ui/widgets/Page.d.ts +16 -0
  41. package/dist/types/ui/widgets/UnreadBadge.d.ts +11 -0
  42. package/dist/types/ui/widgets/feedback.d.ts +23 -0
  43. package/dist/types/ui/widgets/useFocusTrap.d.ts +2 -0
  44. package/package.json +54 -4
@@ -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,32 @@
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
+ };
27
+ export type IconName = keyof typeof PATHS;
28
+ export declare function Icon({ name, size }: {
29
+ name: IconName;
30
+ size?: number;
31
+ }): import("react").JSX.Element;
32
+ export {};
@@ -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.27.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.25.2 <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
+ }