nexus-chat-ui 0.0.1

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/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # nexus-chat-ui
2
+
3
+ 一个基于 `React 19 + Vite + TypeScript + Chatscope` 的即时通讯组件库示例。
4
+
5
+ 这个包已经把聊天界面和长连接逻辑一起封装好了。默认情况下,业务项目接入时只需要传入 `serverUrl`,即可建立 WebSocket 连接并完成消息收发。
6
+
7
+ ## 功能特性
8
+
9
+ - 使用 `Chatscope (Chat UI Kit React)` 构建聊天界面
10
+ - 内置 `WebSocket` 长连接管理
11
+ - 支持自动重连、发送队列、乐观发送
12
+ - 默认只需配置服务地址即可使用
13
+ - 输出 `ESM`、`CJS` 和 `.d.ts`
14
+
15
+ ## 安装
16
+
17
+ ```bash
18
+ pnpm install
19
+ ```
20
+
21
+ ## 本地开发
22
+
23
+ ```bash
24
+ pnpm dev
25
+ ```
26
+
27
+ ## 基础用法
28
+
29
+ 最简接入方式:
30
+
31
+ ```tsx
32
+ import { NexusChatUI } from 'nexus-chat-ui'
33
+
34
+ export default function ChatPage() {
35
+ return <NexusChatUI serverUrl="ws://localhost:8080/im/ws" />
36
+ }
37
+ ```
38
+
39
+ 带用户信息和房间信息的接入方式:
40
+
41
+ ```tsx
42
+ import { NexusChatUI } from 'nexus-chat-ui'
43
+
44
+ export default function ChatPage() {
45
+ return (
46
+ <NexusChatUI
47
+ serverUrl="ws://localhost:8080/im/ws"
48
+ roomId="support-room"
49
+ userId="u-1001"
50
+ userName="Alice"
51
+ title="Support Chat"
52
+ />
53
+ )
54
+ }
55
+ ```
56
+
57
+ ## 默认消息协议
58
+
59
+ 组件默认发送的消息格式为:
60
+
61
+ ```json
62
+ {
63
+ "type": "message",
64
+ "id": "outgoing-xxx",
65
+ "clientMessageId": "outgoing-xxx",
66
+ "roomId": "support-room",
67
+ "userId": "u-1001",
68
+ "sender": "Alice",
69
+ "message": "hello",
70
+ "sentTime": "14:30"
71
+ }
72
+ ```
73
+
74
+ 默认接收时会尽量兼容以下字段:
75
+
76
+ - `message` / `content` / `text`
77
+ - `sender` / `from` / `userName` / `username` / `name`
78
+ - `sentTime` / `time` / `timestamp`
79
+ - `id` / `messageId` / `clientMessageId`
80
+
81
+ ## Props 说明
82
+
83
+ | Prop | 类型 | 默认值 | 说明 |
84
+ | --- | --- | --- | --- |
85
+ | `serverUrl` | `string` | `undefined` | WebSocket 服务地址,推荐业务方只配置这个 |
86
+ | `requestUrl` | `string` | `undefined` | `serverUrl` 的别名 |
87
+ | `transport` | `'websocket' \| 'mock'` | `'websocket'` | 连接模式,演示环境可用 `mock` |
88
+ | `reconnect` | `boolean` | `true` | 是否自动重连 |
89
+ | `reconnectInterval` | `number` | `3000` | 重连间隔,单位毫秒 |
90
+ | `optimisticSend` | `boolean` | `true` | 是否发送后先本地追加消息 |
91
+ | `connectionParams` | `Record<string, string \| number \| boolean \| undefined>` | `undefined` | 自动拼接到连接 URL 的查询参数 |
92
+ | `roomId` | `string` | `undefined` | 房间 ID |
93
+ | `userId` | `string` | `undefined` | 用户 ID |
94
+ | `userName` | `string` | `'You'` | 发送者名称 |
95
+ | `title` | `string` | `'Chatscope Demo'` | 标题 |
96
+ | `placeholder` | `string` | `'Type message here'` | 输入框占位文案 |
97
+ | `height` | `number \| string` | `500` | 聊天窗口高度 |
98
+ | `disabled` | `boolean` | `false` | 是否禁用输入 |
99
+ | `showHeader` | `boolean` | `true` | 是否显示头部 |
100
+ | `autoConnect` | `boolean` | `true` | 是否自动建立连接 |
101
+ | `initialMessages` | `ChatMessageItem[]` | `[]` | 初始化消息 |
102
+ | `emptyMessageText` | `string` | `'Start your first conversation here.'` | 空消息时的占位文案 |
103
+ | `onMessageReceive` | `(message) => void` | `undefined` | 收到消息回调 |
104
+ | `onConnectionStatusChange` | `(status) => void` | `undefined` | 连接状态变更回调 |
105
+ | `onError` | `(error) => void` | `undefined` | 连接错误回调 |
106
+
107
+ ## 构建
108
+
109
+ ```bash
110
+ pnpm lint
111
+ pnpm typecheck
112
+ pnpm build
113
+ ```
114
+
115
+ 构建后会在 `dist` 目录输出:
116
+
117
+ - `index.js`
118
+ - `index.cjs`
119
+ - `index.d.ts`
120
+
121
+ ## npm 发布流程
122
+
123
+ ### 1. 确认包名
124
+
125
+ 先检查 `package.json` 中的 `name` 是否可用。如果你准备发布作用域包,可以改成:
126
+
127
+ ```json
128
+ {
129
+ "name": "@your-scope/nexus-chat-ui"
130
+ }
131
+ ```
132
+
133
+ ### 2. 登录 npm
134
+
135
+ ```bash
136
+ npm login
137
+ ```
138
+
139
+ ### 3. 发布前检查
140
+
141
+ ```bash
142
+ pnpm lint
143
+ pnpm typecheck
144
+ pnpm build
145
+ pnpm pack
146
+ ```
147
+
148
+ `pnpm pack` 会生成一个 `.tgz` 文件,建议先检查打包内容是否正确。
149
+
150
+ ### 4. 正式发布
151
+
152
+ 首次发布公开包:
153
+
154
+ ```bash
155
+ npm publish --access public
156
+ ```
157
+
158
+ 后续版本发布:
159
+
160
+ ```bash
161
+ npm version patch
162
+ npm publish
163
+ ```
164
+
165
+ ## 推荐发布检查清单
166
+
167
+ - `package.json` 的 `name`、`version`、`exports`、`types` 已确认
168
+ - `dist` 已成功生成
169
+ - `README` 已说明接入方式和协议格式
170
+ - `.d.ts` 类型文件已生成
171
+ - 只包含需要发布的内容
@@ -0,0 +1,13 @@
1
+ import { ChatUserProfile } from '../types';
2
+ type AllUsersModalMode = "conversation" | "channelMember";
3
+ interface AllUsersModalProps {
4
+ open: boolean;
5
+ users: ChatUserProfile[];
6
+ onCancel: () => void;
7
+ mode?: AllUsersModalMode;
8
+ channelId?: string;
9
+ channelName?: string;
10
+ }
11
+ export declare function AllUsersModal({ open, users, onCancel, mode, channelId, channelName, }: AllUsersModalProps): import("react/jsx-runtime").JSX.Element;
12
+ export default AllUsersModal;
13
+ //# sourceMappingURL=AllUsersModal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AllUsersModal.d.ts","sourceRoot":"","sources":["../../src/components/AllUsersModal.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C,KAAK,iBAAiB,GAAG,cAAc,GAAG,eAAe,CAAC;AAE1D,UAAU,kBAAkB;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAOD,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,IAAqB,EACrB,SAAS,EACT,WAAW,GACZ,EAAE,kBAAkB,2CA2KpB;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { CSSProperties } from 'react';
2
+ import { ChatConnectionStatus, ChatMessageItem } from '../types';
3
+ interface NexusChatPanelProps {
4
+ hasActiveConversation: boolean;
5
+ connectionStatus: ChatConnectionStatus;
6
+ hasReconnectExhausted: boolean;
7
+ isMessagesLoading: boolean;
8
+ messages: ChatMessageItem[];
9
+ inputValue: string;
10
+ placeholder: string;
11
+ resolvedDisabled: boolean;
12
+ headerName: string;
13
+ headerAvatar?: string;
14
+ headerInfo?: string;
15
+ isChannel?: boolean;
16
+ currentUserId?: string;
17
+ onAddMemberClick?: () => void;
18
+ onBackClick?: () => void;
19
+ onReconnect?: () => void;
20
+ className?: string;
21
+ style?: CSSProperties;
22
+ onChange: (innerHtml: string, textContent: string, innerText: string) => void;
23
+ onSend: (innerHtml: string, textContent: string, innerText: string) => void;
24
+ }
25
+ export declare function ChatPanel({ hasActiveConversation, connectionStatus, hasReconnectExhausted, isMessagesLoading, messages, inputValue, placeholder, resolvedDisabled, headerName, headerAvatar, headerInfo, isChannel, currentUserId, onAddMemberClick, onBackClick, onReconnect, className, style, onChange, onSend, }: NexusChatPanelProps): import("react/jsx-runtime").JSX.Element;
26
+ export {};
27
+ //# sourceMappingURL=ChatPanel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatPanel.d.ts","sourceRoot":"","sources":["../../src/components/ChatPanel.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAKrE,UAAU,mBAAmB;IAC3B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,gBAAgB,EAAE,oBAAoB,CAAC;IACvC,qBAAqB,EAAE,OAAO,CAAC;IAC/B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9E,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7E;AAED,wBAAgB,SAAS,CAAC,EACxB,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,QAAQ,EACR,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,UAAU,EACV,SAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,SAAS,EACT,KAAK,EACL,QAAQ,EACR,MAAM,GACP,EAAE,mBAAmB,2CA2GrB"}
@@ -0,0 +1,4 @@
1
+ import { NexusChatUIProps } from '../types';
2
+ export declare function NexusChatUI({ placeholder, className, disabled, ...chatOptions }: NexusChatUIProps): import("react/jsx-runtime").JSX.Element;
3
+ export default NexusChatUI;
4
+ //# sourceMappingURL=ChatUI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatUI.d.ts","sourceRoot":"","sources":["../../src/components/ChatUI.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGhD,wBAAgB,WAAW,CAAC,EAC1B,WAAiC,EACjC,SAAS,EACT,QAAgB,EAChB,GAAG,WAAW,EACf,EAAE,gBAAgB,2CAgQlB;AAED,eAAe,WAAW,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { CSSProperties } from 'react';
2
+ interface NexusConversationSidebarProps {
3
+ onSelectConversation: (conversationId: string) => void;
4
+ className?: string;
5
+ style?: CSSProperties;
6
+ conversationContentStyle?: CSSProperties;
7
+ conversationAvatarStyle?: CSSProperties;
8
+ }
9
+ export declare function ConversationSidebar({ onSelectConversation, className, style, conversationContentStyle, conversationAvatarStyle, }: NexusConversationSidebarProps): import("react/jsx-runtime").JSX.Element;
10
+ export {};
11
+ //# sourceMappingURL=ConversationSidebar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConversationSidebar.d.ts","sourceRoot":"","sources":["../../src/components/ConversationSidebar.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,aAAa,EAAY,MAAM,OAAO,CAAC;AAerD,UAAU,6BAA6B;IACrC,oBAAoB,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,wBAAwB,CAAC,EAAE,aAAa,CAAC;IACzC,uBAAuB,CAAC,EAAE,aAAa,CAAC;CACzC;AAED,wBAAgB,mBAAmB,CAAC,EAClC,oBAAoB,EACpB,SAAS,EACT,KAAK,EACL,wBAAwB,EACxB,uBAAuB,GACxB,EAAE,6BAA6B,2CAmN/B"}
@@ -0,0 +1,7 @@
1
+ interface CreateChannelModalProps {
2
+ open: boolean;
3
+ onCancel: () => void;
4
+ }
5
+ export declare function CreateChannelModal({ open, onCancel, }: CreateChannelModalProps): import("react/jsx-runtime").JSX.Element;
6
+ export default CreateChannelModal;
7
+ //# sourceMappingURL=CreateChannelModal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateChannelModal.d.ts","sourceRoot":"","sources":["../../src/components/CreateChannelModal.tsx"],"names":[],"mappings":"AAQA,UAAU,uBAAuB;IAC/B,IAAI,EAAE,OAAO,CAAA;IACb,QAAQ,EAAE,MAAM,IAAI,CAAA;CACrB;AAOD,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,EACJ,QAAQ,GACT,EAAE,uBAAuB,2CA+FzB;AAED,eAAe,kBAAkB,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { Modal } from '@douyinfe/semi-ui';
2
+ import { ComponentProps, ReactNode } from 'react';
3
+ type ModalBaseProps = Omit<ComponentProps<typeof Modal>, 'title' | 'visible'>;
4
+ export interface CommonModalProps extends ModalBaseProps {
5
+ open?: boolean;
6
+ title?: ReactNode;
7
+ description?: ReactNode;
8
+ headerClassName?: string;
9
+ titleClassName?: string;
10
+ descriptionClassName?: string;
11
+ bodyClassName?: string;
12
+ destroyOnHidden?: boolean;
13
+ }
14
+ declare const CommonModal: React.FC<CommonModalProps>;
15
+ export default CommonModal;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Modal/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGtD,KAAK,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC,CAAA;AAE7E,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAuD3C,CAAA;AAED,eAAe,WAAW,CAAA"}
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="46" fill="none" viewBox="0 0 48 46"><path fill="#863bff" d="M25.946 44.938c-.664.845-2.021.375-2.021-.698V33.937a2.26 2.26 0 0 0-2.262-2.262H10.287c-.92 0-1.456-1.04-.92-1.788l7.48-10.471c1.07-1.497 0-3.578-1.842-3.578H1.237c-.92 0-1.456-1.04-.92-1.788L10.013.474c.214-.297.556-.474.92-.474h28.894c.92 0 1.456 1.04.92 1.788l-7.48 10.471c-1.07 1.498 0 3.579 1.842 3.579h11.377c.943 0 1.473 1.088.89 1.83L25.947 44.94z" style="fill:#863bff;fill:color(display-p3 .5252 .23 1);fill-opacity:1"/><mask id="a" width="48" height="46" x="0" y="0" maskUnits="userSpaceOnUse" style="mask-type:alpha"><path fill="#000" d="M25.842 44.938c-.664.844-2.021.375-2.021-.698V33.937a2.26 2.26 0 0 0-2.262-2.262H10.183c-.92 0-1.456-1.04-.92-1.788l7.48-10.471c1.07-1.498 0-3.579-1.842-3.579H1.133c-.92 0-1.456-1.04-.92-1.787L9.91.473c.214-.297.556-.474.92-.474h28.894c.92 0 1.456 1.04.92 1.788l-7.48 10.471c-1.07 1.498 0 3.578 1.842 3.578h11.377c.943 0 1.473 1.088.89 1.832L25.843 44.94z" style="fill:#000;fill-opacity:1"/></mask><g mask="url(#a)"><g filter="url(#b)"><ellipse cx="5.508" cy="14.704" fill="#ede6ff" rx="5.508" ry="14.704" style="fill:#ede6ff;fill:color(display-p3 .9275 .9033 1);fill-opacity:1" transform="matrix(.00324 1 1 -.00324 -4.47 31.516)"/></g><g filter="url(#c)"><ellipse cx="10.399" cy="29.851" fill="#ede6ff" rx="10.399" ry="29.851" style="fill:#ede6ff;fill:color(display-p3 .9275 .9033 1);fill-opacity:1" transform="matrix(.00324 1 1 -.00324 -39.328 7.883)"/></g><g filter="url(#d)"><ellipse cx="5.508" cy="30.487" fill="#7e14ff" rx="5.508" ry="30.487" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(89.814 -25.913 -14.639)scale(1 -1)"/></g><g filter="url(#e)"><ellipse cx="5.508" cy="30.599" fill="#7e14ff" rx="5.508" ry="30.599" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(89.814 -32.644 -3.334)scale(1 -1)"/></g><g filter="url(#f)"><ellipse cx="5.508" cy="30.599" fill="#7e14ff" rx="5.508" ry="30.599" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="matrix(.00324 1 1 -.00324 -34.34 30.47)"/></g><g filter="url(#g)"><ellipse cx="14.072" cy="22.078" fill="#ede6ff" rx="14.072" ry="22.078" style="fill:#ede6ff;fill:color(display-p3 .9275 .9033 1);fill-opacity:1" transform="rotate(93.35 24.506 48.493)scale(-1 1)"/></g><g filter="url(#h)"><ellipse cx="3.47" cy="21.501" fill="#7e14ff" rx="3.47" ry="21.501" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(89.009 28.708 47.59)scale(-1 1)"/></g><g filter="url(#i)"><ellipse cx="3.47" cy="21.501" fill="#7e14ff" rx="3.47" ry="21.501" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(89.009 28.708 47.59)scale(-1 1)"/></g><g filter="url(#j)"><ellipse cx=".387" cy="8.972" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(39.51 .387 8.972)"/></g><g filter="url(#k)"><ellipse cx="47.523" cy="-6.092" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(37.892 47.523 -6.092)"/></g><g filter="url(#l)"><ellipse cx="41.412" cy="6.333" fill="#47bfff" rx="5.971" ry="9.665" style="fill:#47bfff;fill:color(display-p3 .2799 .748 1);fill-opacity:1" transform="rotate(37.892 41.412 6.333)"/></g><g filter="url(#m)"><ellipse cx="-1.879" cy="38.332" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(37.892 -1.88 38.332)"/></g><g filter="url(#n)"><ellipse cx="-1.879" cy="38.332" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(37.892 -1.88 38.332)"/></g><g filter="url(#o)"><ellipse cx="35.651" cy="29.907" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(37.892 35.651 29.907)"/></g><g filter="url(#p)"><ellipse cx="38.418" cy="32.4" fill="#47bfff" rx="5.971" ry="15.297" style="fill:#47bfff;fill:color(display-p3 .2799 .748 1);fill-opacity:1" transform="rotate(37.892 38.418 32.4)"/></g></g><defs><filter id="b" width="60.045" height="41.654" x="-19.77" y="16.149" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="7.659"/></filter><filter id="c" width="90.34" height="51.437" x="-54.613" y="-7.533" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="7.659"/></filter><filter id="d" width="79.355" height="29.4" x="-49.64" y="2.03" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="4.596"/></filter><filter id="e" width="79.579" height="29.4" x="-45.045" y="20.029" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="4.596"/></filter><filter id="f" width="79.579" height="29.4" x="-43.513" y="21.178" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="4.596"/></filter><filter id="g" width="74.749" height="58.852" x="15.756" y="-17.901" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="7.659"/></filter><filter id="h" width="61.377" height="25.362" x="23.548" y="2.284" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="4.596"/></filter><filter id="i" width="61.377" height="25.362" x="23.548" y="2.284" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="4.596"/></filter><filter id="j" width="56.045" height="63.649" x="-27.636" y="-22.853" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="4.596"/></filter><filter id="k" width="54.814" height="64.646" x="20.116" y="-38.415" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="4.596"/></filter><filter id="l" width="33.541" height="35.313" x="24.641" y="-11.323" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="4.596"/></filter><filter id="m" width="54.814" height="64.646" x="-29.286" y="6.009" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="4.596"/></filter><filter id="n" width="54.814" height="64.646" x="-29.286" y="6.009" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="4.596"/></filter><filter id="o" width="54.814" height="64.646" x="8.244" y="-2.416" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="4.596"/></filter><filter id="p" width="39.409" height="43.623" x="18.713" y="10.588" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="4.596"/></filter></defs></svg>
package/dist/icons.svg ADDED
@@ -0,0 +1,24 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg">
2
+ <symbol id="bluesky-icon" viewBox="0 0 16 17">
3
+ <g clip-path="url(#bluesky-clip)"><path fill="#08060d" d="M7.75 7.735c-.693-1.348-2.58-3.86-4.334-5.097-1.68-1.187-2.32-.981-2.74-.79C.188 2.065.1 2.812.1 3.251s.241 3.602.398 4.13c.52 1.744 2.367 2.333 4.07 2.145-2.495.37-4.71 1.278-1.805 4.512 3.196 3.309 4.38-.71 4.987-2.746.608 2.036 1.307 5.91 4.93 2.746 2.72-2.746.747-4.143-1.747-4.512 1.702.189 3.55-.4 4.07-2.145.156-.528.397-3.691.397-4.13s-.088-1.186-.575-1.406c-.42-.19-1.06-.395-2.741.79-1.755 1.24-3.64 3.752-4.334 5.099"/></g>
4
+ <defs><clipPath id="bluesky-clip"><path fill="#fff" d="M.1.85h15.3v15.3H.1z"/></clipPath></defs>
5
+ </symbol>
6
+ <symbol id="discord-icon" viewBox="0 0 20 19">
7
+ <path fill="#08060d" d="M16.224 3.768a14.5 14.5 0 0 0-3.67-1.153c-.158.286-.343.67-.47.976a13.5 13.5 0 0 0-4.067 0c-.128-.306-.317-.69-.476-.976A14.4 14.4 0 0 0 3.868 3.77C1.546 7.28.916 10.703 1.231 14.077a14.7 14.7 0 0 0 4.5 2.306q.545-.748.965-1.587a9.5 9.5 0 0 1-1.518-.74q.191-.14.372-.293c2.927 1.369 6.107 1.369 8.999 0q.183.152.372.294-.723.437-1.52.74.418.838.963 1.588a14.6 14.6 0 0 0 4.504-2.308c.37-3.911-.63-7.302-2.644-10.309m-9.13 8.234c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.894 0 1.614.82 1.599 1.82.001 1-.705 1.82-1.6 1.82m5.91 0c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.893 0 1.614.82 1.599 1.82 0 1-.706 1.82-1.6 1.82"/>
8
+ </symbol>
9
+ <symbol id="documentation-icon" viewBox="0 0 21 20">
10
+ <path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="m15.5 13.333 1.533 1.322c.645.555.967.833.967 1.178s-.322.623-.967 1.179L15.5 18.333m-3.333-5-1.534 1.322c-.644.555-.966.833-.966 1.178s.322.623.966 1.179l1.534 1.321"/>
11
+ <path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M17.167 10.836v-4.32c0-1.41 0-2.117-.224-2.68-.359-.906-1.118-1.621-2.08-1.96-.599-.21-1.349-.21-2.848-.21-2.623 0-3.935 0-4.983.369-1.684.591-3.013 1.842-3.641 3.428C3 6.449 3 7.684 3 10.154v2.122c0 2.558 0 3.838.706 4.726q.306.383.713.671c.76.536 1.79.64 3.581.66"/>
12
+ <path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M3 10a2.78 2.78 0 0 1 2.778-2.778c.555 0 1.209.097 1.748-.047.48-.129.854-.503.982-.982.145-.54.048-1.194.048-1.749a2.78 2.78 0 0 1 2.777-2.777"/>
13
+ </symbol>
14
+ <symbol id="github-icon" viewBox="0 0 19 19">
15
+ <path fill="#08060d" fill-rule="evenodd" d="M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844" clip-rule="evenodd"/>
16
+ </symbol>
17
+ <symbol id="social-icon" viewBox="0 0 20 20">
18
+ <path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M12.5 6.667a4.167 4.167 0 1 0-8.334 0 4.167 4.167 0 0 0 8.334 0"/>
19
+ <path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M2.5 16.667a5.833 5.833 0 0 1 8.75-5.053m3.837.474.513 1.035c.07.144.257.282.414.309l.93.155c.596.1.736.536.307.965l-.723.73a.64.64 0 0 0-.152.531l.207.903c.164.715-.213.991-.84.618l-.872-.52a.63.63 0 0 0-.577 0l-.872.52c-.624.373-1.003.094-.84-.618l.207-.903a.64.64 0 0 0-.152-.532l-.723-.729c-.426-.43-.289-.864.306-.964l.93-.156a.64.64 0 0 0 .412-.31l.513-1.034c.28-.562.735-.562 1.012 0"/>
20
+ </symbol>
21
+ <symbol id="x-icon" viewBox="0 0 19 19">
22
+ <path fill="#08060d" fill-rule="evenodd" d="M1.893 1.98c.052.072 1.245 1.769 2.653 3.77l2.892 4.114c.183.261.333.48.333.486s-.068.089-.152.183l-.522.593-.765.867-3.597 4.087c-.375.426-.734.834-.798.905a1 1 0 0 0-.118.148c0 .01.236.017.664.017h.663l.729-.83c.4-.457.796-.906.879-.999a692 692 0 0 0 1.794-2.038c.034-.037.301-.34.594-.675l.551-.624.345-.392a7 7 0 0 1 .34-.374c.006 0 .93 1.306 2.052 2.903l2.084 2.965.045.063h2.275c1.87 0 2.273-.003 2.266-.021-.008-.02-1.098-1.572-3.894-5.547-2.013-2.862-2.28-3.246-2.273-3.266.008-.019.282-.332 2.085-2.38l2-2.274 1.567-1.782c.022-.028-.016-.03-.65-.03h-.674l-.3.342a871 871 0 0 1-1.782 2.025c-.067.075-.405.458-.75.852a100 100 0 0 1-.803.91c-.148.172-.299.344-.99 1.127-.304.343-.32.358-.345.327-.015-.019-.904-1.282-1.976-2.808L6.365 1.85H1.8zm1.782.91 8.078 11.294c.772 1.08 1.413 1.973 1.425 1.984.016.017.241.02 1.05.017l1.03-.004-2.694-3.766L7.796 5.75 5.722 2.852l-1.039-.004-1.039-.004z" clip-rule="evenodd"/>
23
+ </symbol>
24
+ </svg>
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));require(`@douyinfe/semi-ui/react19-adapter`),require(`@chatscope/chat-ui-kit-styles/dist/default/styles.min.css`),require(`@tdesign-react/chat/es/style/index.js`);let c=require(`react`),l=require(`@chatscope/chat-ui-kit-react`),u=require(`@douyinfe/semi-ui`),d=require(`axios`);d=s(d,1);let f=require(`zustand`),p=require(`clsx`),m=require(`tailwind-merge`),h=require(`react/jsx-runtime`),g=require(`@tdesign-react/chat`),_=require(`dayjs`);_=s(_,1);let v=require(`tdesign-mobile-react`),y=require(`tdesign-icons-react`),b=require(`react-responsive`);var x=function(e){return e[e.SUCCESS=200]=`SUCCESS`,e[e.ERROR=500]=`ERROR`,e[e.OVERDUE=401]=`OVERDUE`,e[e.TIMEOUT=3e4]=`TIMEOUT`,e.TYPE=`success`,e}({}),S=(0,f.create)(e=>({wsAddress:void 0,httpUrl:void 0,token:``,connectionStatus:`idle`,setWsAddress:t=>e({wsAddress:t}),setHttpUrl:t=>e({httpUrl:t}),setToken:t=>e({token:t}),setConnectionStatus:t=>e({connectionStatus:t})})),C=e=>{switch(e){case 400:u.Toast.error(`请求失败!请您稍后重试`);break;case 401:u.Toast.error(`登录失效!请您重新登录`);break;case 403:u.Toast.error(`当前账号无权限访问!`);break;case 404:u.Toast.error(`你所访问的资源不存在!`);break;case 405:u.Toast.error(`请求方式错误!请您稍后重试`);break;case 408:u.Toast.error(`请求超时!请您稍后重试`);break;case 500:u.Toast.error(`服务异常!`);break;case 502:u.Toast.error(`网关错误!`);break;case 503:u.Toast.error(`服务不可用!`);break;case 504:u.Toast.error(`网关超时!`);break;default:u.Toast.error(`请求失败!`)}},w={baseURL:``,timeout:x.TIMEOUT,withCredentials:!1},T=new class{service;constructor(e){this.service=d.default.create(e),this.service.interceptors.request.use(e=>{let{httpUrl:t,token:n}=S.getState();return t&&(e.baseURL=t),e.headers&&typeof e.headers.set==`function`&&n&&e.headers.set(`Authorization`,`Bearer ${n}`),e},e=>Promise.reject(e)),this.service.interceptors.response.use(e=>{let{data:t}=e;return t.code&&t.code!=x.SUCCESS?Promise.reject(t):t},async e=>{let{response:t}=e;return console.log(t),e.message.indexOf(`timeout`)!==-1&&u.Toast.error(`请求超时!请您稍后重试`),e.message.indexOf(`Network Error`)!==-1&&u.Toast.error(`网络错误!请您稍后重试`),t&&C(t.status),Promise.reject(e)})}get(e,t,n={}){return this.service.get(e,{params:t,...n})}post(e,t,n={}){return this.service.post(e,t,n)}put(e,t,n={}){return this.service.put(e,t,n)}delete(e,t,n={}){return this.service.delete(e,{params:t,...n})}download(e,t,n={}){return this.service.post(e,t,{...n,responseType:`blob`})}}(w),E=()=>T.get(`/api/v1/conversations`),D=e=>T.post(`/api/v1/conversations`,{userId:e}),O=(e,t)=>T.get(`/api/v1/messages`,{roomId:e,roomType:t}),k=()=>T.get(`/api/v1/channels`),A=(e,t)=>T.post(`/api/v1/channels`,{name:e,description:t,type:`PRIVATE`,e2eeEnabled:!1}),j=(e,t)=>T.post(`/api/v1/channels/${e}/members`,{userId:t});function M(...e){return(0,m.twMerge)((0,p.clsx)(e))}var N=({open:e,title:t,description:n,headerClassName:r,titleClassName:i,descriptionClassName:a,children:o,centered:s=!0,destroyOnHidden:c=!0,footer:l=null,width:d=520,...f})=>{let p=t||n?(0,h.jsxs)(`div`,{className:M(`pr-[32px]`,r),children:[t?(0,h.jsx)(`div`,{className:M(`text-[20px] font-semibold leading-[28px] text-primary`,i),children:t}):null,n?(0,h.jsx)(`div`,{className:M(t?`mt-[8px]`:``,`text-[14px] leading-[22px] text-[#909090]`,a),children:n}):null]}):null;return(0,h.jsx)(u.Modal,{centered:s,visible:e,keepDOM:!c,footer:l,maskClosable:!0,title:p,width:d,...f,children:o})},P=e=>{let t=e.senderId;if(t)return{userId:t}},F=e=>{let t={};return e.forEach(e=>{e.userId&&(t[e.userId]={...t[e.userId],...e})}),Object.values(t)},I=e=>e.reduce((e,t)=>(e[t.userId]=t,e),{}),L=(e,t)=>{let n=I(e);return t.forEach(e=>{e.userId&&(n[e.userId]={...n[e.userId],...e})}),Object.values(n)},R=(0,f.create)(e=>({currentUser:void 0,allUserList:[],usersById:{},setAllUserList:t=>e(e=>{let n=F(t),r=e.currentUser?.userId?L(n,[e.currentUser]):n;return{allUserList:r,usersById:I(r)}}),setCurrentUser:t=>e(e=>{if(!t?.userId)return{currentUser:void 0};let n=L(e.allUserList,[t]);return{currentUser:t,allUserList:n,usersById:I(n)}}),upsertUsersFromMessages:t=>e(e=>{let n=t.map(P).filter(e=>!!e);if(n.length===0)return{};let r=L(e.allUserList,n);return{allUserList:r,usersById:I(r)}})})),z=(e,t)=>{let n=new Set(e.map(e=>e._id).filter(Boolean)),r=t.filter(e=>e._id?n.has(e._id)?!1:(n.add(e._id),!0):!0);return r.length>0?[...e,...r]:e},B=(0,f.create)(e=>({conversations:[],channels:[],tabbarValue:`conversations`,activeConversationId:void 0,isConversationsLoading:!1,isMessagesLoading:!1,setConversations:t=>e(e=>({conversations:t.map(t=>{let n=e.conversations.find(e=>e._id===t._id);return n?{...t,hasReq:n.hasReq,unreadDot:n.unreadDot,msg:n.msg}:{...t,hasReq:t.hasReq??!1,unreadDot:t.unreadDot??!1}}),activeConversationId:t.some(t=>t._id===e.activeConversationId)?e.activeConversationId:void 0})),setChannels:t=>e(e=>({channels:t.map(t=>{let n=e.channels.find(e=>e._id===t._id);return n?{...t,hasReq:n.hasReq,unreadDot:n.unreadDot,msg:n.msg}:{...t,hasReq:t.hasReq??!1,unreadDot:t.unreadDot??!1}})})),setTabbarValue:t=>e({tabbarValue:t}),prependConversation:t=>e(e=>({conversations:[{...t,hasReq:t.hasReq??!1,unreadDot:t.unreadDot??!1},...e.conversations.filter(e=>e._id!==t._id)]})),prependChannel:t=>e(e=>({channels:[{...t,hasReq:t.hasReq??!1,unreadDot:t.unreadDot??!1},...e.channels.filter(e=>e._id!==t._id)]})),setConversationsLoading:t=>e({isConversationsLoading:t}),setMessagesLoading:t=>e({isMessagesLoading:t}),setConversationMessages:(t,n)=>e(e=>{let r=e.conversations.find(e=>e._id===t),i=e.channels.find(e=>e._id===t);if(r)return{conversations:e.conversations.map(e=>e._id===t?{...e,hasReq:!0,unreadDot:!1,msg:z(n,r.msg)}:e)};if(i)return{channels:e.channels.map(e=>e._id===t?{...e,hasReq:!0,unreadDot:!1,msg:z(n,i.msg),updatedAt:new Date().toISOString()}:e)};let a=new Date().toISOString();return(n[0]?.roomType===`CHANNEL`?`CHANNEL`:`CONVERSATION`)==`CHANNEL`?{channels:[...e.channels,{_id:t,members:[],name:``,type:`CHANNEL`,createdBy:``,e2eeEnabled:!1,senderKeyVersion:0,createdAt:a,updatedAt:a,hasReq:!0,unreadDot:!1,roomType:`CHANNEL`,msg:n}],activeConversationId:e.activeConversationId??t}:{conversations:[...e.conversations,{_id:t,participants:[],createdAt:a,updatedAt:a,hasReq:!0,unreadDot:!1,roomType:`CONVERSATION`,msg:n}],activeConversationId:e.activeConversationId??t}}),setActiveConversationId:t=>e({activeConversationId:t}),ensureConversation:(t,n)=>e(e=>{let r=e.conversations.find(e=>e._id===t),i=e.channels.find(e=>e._id===t);if(r)return{conversations:e.conversations.map(e=>e._id===t?{...e,...n,hasReq:n?.hasReq??e.hasReq,unreadDot:n?.unreadDot??e.unreadDot,participants:n?.participants??e.participants,updatedAt:n?.updatedAt??e.updatedAt}:e)};if(i)return{channels:e.channels.map(e=>e._id===t?{...e,...n,roomType:`CHANNEL`,hasReq:n?.hasReq??e.hasReq,unreadDot:n?.unreadDot??e.unreadDot,members:n?.members??e.members,name:n?.name??e.name,type:n?.type??e.type,createdBy:n?.createdBy??e.createdBy,e2eeEnabled:n?.e2eeEnabled??e.e2eeEnabled,senderKeyVersion:n?.senderKeyVersion??e.senderKeyVersion,updatedAt:n?.updatedAt??e.updatedAt}:e)};let a=new Date().toISOString();return(n?.roomType??`CONVERSATION`)===`CHANNEL`?{channels:[...e.channels,{_id:t,members:n?.members??[],name:n?.name??``,type:n?.type??`CHANNEL`,createdBy:n?.createdBy??``,e2eeEnabled:n?.e2eeEnabled??!1,senderKeyVersion:n?.senderKeyVersion??0,createdAt:n?.createdAt??a,updatedAt:n?.updatedAt??a,hasReq:n?.hasReq??!1,unreadDot:n?.unreadDot??!1,roomType:`CHANNEL`,msg:[]}],activeConversationId:e.activeConversationId??t}:{conversations:[...e.conversations,{_id:t,participants:n?.participants??[],createdAt:n?.createdAt??a,updatedAt:n?.updatedAt??a,hasReq:n?.hasReq??!1,unreadDot:n?.unreadDot??!1,roomType:`CONVERSATION`,msg:[]}],activeConversationId:e.activeConversationId??t}}),appendMessages:(t,n)=>e(e=>{let r=e.conversations.find(e=>e._id===t),i=e.channels.find(e=>e._id===t),a=n[0]?.roomType===`CHANNEL`?`CHANNEL`:`CONVERSATION`;if(r)return{conversations:e.conversations.map(e=>e._id===t?{...e,hasReq:e.hasReq??!1,unreadDot:e.unreadDot??!1,msg:z(e.msg,n),updatedAt:new Date().toISOString()}:e)};if(i)return{channels:e.channels.map(e=>e._id===t?{...e,hasReq:e.hasReq??!1,unreadDot:e.unreadDot??!1,msg:z(e.msg,n),updatedAt:new Date().toISOString()}:e)};if(a===`CHANNEL`){let r=new Date().toISOString();return{channels:[...e.channels,{_id:t,members:[],name:``,type:`CHANNEL`,createdBy:``,e2eeEnabled:!1,senderKeyVersion:0,createdAt:r,updatedAt:r,hasReq:!1,unreadDot:!1,roomType:`CHANNEL`,msg:n}],activeConversationId:e.activeConversationId??t}}return{conversations:[...e.conversations,{_id:t,participants:[],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),hasReq:!1,unreadDot:!1,roomType:`CONVERSATION`,msg:n}],activeConversationId:e.activeConversationId??t}}),setConversationUnreadDot:(t,n,r)=>e(e=>{let i=e.conversations.find(e=>e._id===t),a=e.channels.find(e=>e._id===t);if(i)return{conversations:e.conversations.map(e=>e._id===t?{...e,unreadDot:n}:e)};if(a)return{channels:e.channels.map(e=>e._id===t?{...e,unreadDot:n}:e)};let o=new Date().toISOString();return(r?.roomType??`CONVERSATION`)===`CHANNEL`?{channels:[...e.channels,{_id:t,members:[],name:``,type:`PRIVATE`,createdBy:``,e2eeEnabled:!1,senderKeyVersion:0,createdAt:o,updatedAt:r?.sentAt??o,hasReq:!1,unreadDot:n,roomType:`CHANNEL`,msg:[]}],activeConversationId:e.activeConversationId}:{conversations:[...e.conversations,{_id:t,participants:[r?.senderId,R.getState().currentUser?.userId].filter(e=>!!e),createdAt:o,updatedAt:r?.sentAt??o,hasReq:!1,unreadDot:n,roomType:`CONVERSATION`,msg:[]}],activeConversationId:e.activeConversationId}})})),V=8,H=`https://chatscope.io/storybook/react/assets/emily-xzL8sDL2.svg`,U=u.Empty;function W({open:e,users:t,onCancel:n,mode:r=`conversation`,channelId:i,channelName:a}){let[o,s]=(0,c.useState)(1),[d,f]=(0,c.useState)(),p=R(e=>e.currentUser),m=B(e=>e.conversations),g=B(e=>e.channels),_=B(e=>e.prependConversation),v=B(e=>e.ensureConversation),y=B(e=>e.setActiveConversationId),b=B(e=>e.setTabbarValue),x=(0,c.useMemo)(()=>i?g.find(e=>e._id===i):void 0,[i,g]),S=x?.members??[],C=(0,c.useMemo)(()=>t.filter(e=>e.userId!==p?.userId),[p?.userId,t]),w=(0,c.useMemo)(()=>{let e=(o-1)*V;return C.slice(e,e+V)},[o,C]);(0,c.useEffect)(()=>{e&&s(1)},[e]),(0,c.useEffect)(()=>{let e=Math.max(1,Math.ceil(C.length/V));o>e&&s(e)},[o,C.length]);let T=async e=>{f(e.userId);try{if(r===`channelMember`){if(!i){u.Toast.error(`缺少群聊信息`);return}await j(i,e.userId),v(i,{roomType:`CHANNEL`,members:Array.from(new Set([...S,e.userId]))}),u.Toast.success(`添加成员成功`),n();return}let t=await D(e.userId),a=`_id`in t?t:t.data;if(!a?._id){u.Toast.error(`创建会话失败`);return}m.find(e=>e._id===a._id)||_({_id:a._id,participants:a.participants??[p?.userId,e.userId].filter(e=>!!e),createdAt:a.createdAt??new Date().toISOString(),updatedAt:a.updatedAt??new Date().toISOString(),msg:[],roomType:`CONVERSATION`}),b(`conversations`),y(a._id),n()}catch{u.Toast.error(r===`channelMember`?`添加成员失败,请稍后重试`:`创建会话失败,请稍后重试`)}finally{f(void 0)}};return(0,h.jsx)(N,{open:e,onCancel:n,title:r===`channelMember`?`添加群成员`:`全部用户`,description:r===`channelMember`?`${a??x?.name??`当前群聊`},共 ${C.length} 位可选用户`:`共 ${C.length} 位用户`,width:640,children:(0,h.jsxs)(`div`,{className:`flex min-h-[360px] flex-col pb-[30px]`,children:[w.length>0?(0,h.jsx)(`div`,{className:`flex flex-1 flex-col divide-y divide-slate-100 overflow-hidden rounded-[8px] border border-slate-200 bg-white`,children:w.map(e=>(0,h.jsxs)(`div`,{className:`flex items-center gap-[12px] px-[16px] py-[12px]`,children:[(0,h.jsx)(l.Avatar,{name:e.userName??e.userId,src:e.avatarUrl??H}),(0,h.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,h.jsx)(`div`,{className:`truncate text-[14px] font-medium text-slate-900`,children:e.userName??`未命名用户`}),(0,h.jsx)(`div`,{className:`truncate text-[12px] text-slate-500`,children:e.userId})]}),(0,h.jsx)(l.SendButton,{border:!0,disabled:!!d||r===`channelMember`&&S.includes(e.userId),onClick:()=>void T(e)})]},e.userId))}):(0,h.jsx)(`div`,{className:`flex flex-1 items-center justify-center rounded-[8px] border border-dashed border-slate-200`,children:(0,h.jsx)(U,{description:`暂无用户数据`})}),(0,h.jsx)(`div`,{className:`mt-[16px] flex justify-end`,children:(0,h.jsx)(u.Pagination,{currentPage:o,pageSize:V,total:C.length,onPageChange:s,hideOnSinglePage:!0,showSizeChanger:!1})})]})})}function G(){return{dayjs:_.default,formatDateTime:(0,c.useCallback)(e=>{if(!e)return``;let t=(0,_.default)(e);if(!t.isValid())return e;let n=(0,_.default)();return t.isSame(n,`day`)?t.format(`HH:mm`):t.isSame(n,`year`)?t.format(`MM-DD HH:mm`):t.format(`YYYY-MM-DD HH:mm`)},[])}}var K=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKgAAACoCAYAAAB0S6W0AAAACXBIWXMAACxLAAAsSwGlPZapAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABM5SURBVHgB7Z0PcF1Vnce/9yVhm/7bwnablv6hbbIQ2DRtpX9IluXPaLuu6A7V3a2VdkF218Uy7s4AzaziLgHF0ULU0YGpOipKaEHR1nHKaDLOMCoN1GJtWkvBJrRAoQlYtG3aCmme5/tyb3m579777jv33ffOefd8Zt4kuUnT93K/7/s753d+53csGHxZ15yecPY81KWrUJ9OYaJ1FtNgYaL4Vp39cKjz+vdpC0NWGifFp3wMZT6mMSB+x5D42MeP1afR93CvNQSDJxYMGT6yJD2fQhTCmS/+KvVCXPVCXBNQAmwh99mi7RdvhL7Nu6x+GJIr0DXL083CFeutEbSUUoxhcUQrnmOPeI59W56xepFAEiNQhuvhWrSKT5vFzW9VTZD5sAW7R3zaIx69QrADSAAVLVCK8u0JWEmXFF82o7Kgo3ajwsVakQJl+BYf1qoYumOiW4xfd2zZafWgwqgYgdohfJUQ5aqEiNILOmknKshVtRfo6tZ0fWoY7xGTiZUJFqYXDP+dugtVW4E6YRyVN7YsNloLVTuBCmEyKX47jDALRUuhaiPQzIx8PNaJMH49DFHQSqjKC9RMfoqPnVPdKkTaCcVRWqD2OJPhvA6GOKCLdqi8SqWkQE04LznKhn3lBGpcs2xkcqhCpN1QCGUEalxTDcT4dFvNKTysSgmgEgK1U0cbYVxTFeimbSqE/LIL9MMt6VViHXmtmaGrBWf6Qh2dj/ZYW1FGyirQD1+RvsWEdOXpLGc6qiwCtXObd8GsBulCn3jcU46QX3KBmvGmtp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oIRVdMxstBEpM2C8SCodzL7QRqIMRqjQM4x0qpI4KQTuBOhihhobC7FR5nBmEtgJ1MELNJTPGHEGXeHRv3mX1Q2O0F6iDLVTO+hObQ9Vp8hOWihFoNmJ9v0W8slYkwFVtUbIyTNswHkRFCtQhy1VXoPKOc+xNp9BTM4SuSnFLLypaoNk4Yk2POmuzbjlV2yl3YLQ2c0clizKbxAjUDVephANxn1SLuPn1qgnWCd10SfEc+yoxfIchsQJ1YzeamC8S2fPFX6W+lKI9N47kw0L/SBX6S7nvR2WMQANgCeBwLepBoVqjH4WjTbeFy8dEIa6JAUIecH0+IH7HyXQVBoUrnqQQzzuJo0kJ1zL8GVrxZzovkxNLAAAAAElFTkSuQmCC`;function q({hasActiveConversation:e,connectionStatus:t,hasReconnectExhausted:n,isMessagesLoading:r,messages:i,inputValue:a,placeholder:o,resolvedDisabled:s,headerName:d,headerAvatar:f,headerInfo:p,isChannel:m=!1,currentUserId:_,onAddMemberClick:v,onBackClick:y,onReconnect:b,className:x,style:S,onChange:C,onSend:w}){let T=R(e=>e.usersById),{formatDateTime:E}=G(),D=(0,c.useRef)(null),O={idle:`等待建立长连接`,connecting:`长连接正在连接中`,connected:`长连接已连接成功`,disconnected:`长连接已断开,正在尝试重连`,error:`长连接连接失败`};if(!e){let e=t!==`connected`;return(0,h.jsx)(`div`,{className:`flex h-full flex-1 items-center justify-center px-[24px] text-center text-[14px] text-slate-500 ${x??``}`.trim(),style:S,children:(0,h.jsxs)(`div`,{className:`flex flex-col items-center gap-[12px]`,children:[(0,h.jsx)(`div`,{children:e?O[t]:`Select a user to start a conversation`}),n?(0,h.jsx)(u.Button,{onClick:b,theme:`solid`,type:`primary`,children:`点击重连`}):null]})})}return(0,h.jsxs)(l.ChatContainer,{className:x,style:S,children:[(0,h.jsxs)(l.ConversationHeader,{children:[(0,h.jsx)(l.ConversationHeader.Back,{onClick:y}),(0,h.jsx)(l.Avatar,{name:d,src:f??`data:image/png;base64,iVBORw0KGgoAAAANSUhE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2c0clizKbxAjUDVephANxn1SLuPn1qgnWCd10SfEc+yoxfIchsQJ1YzeamC8S2fPFX6W+lKI9N47kw0L/SBX6S7nvR2WMQANgCeBwLepBoVqjH4WjTbeFy8dEIa6JAUIecH0+IH7HyXQVBoUrnqQQzzuJo0kJ1zL8GVrxZzovkxNLAAAAAElFTkSuQmCC`}),(0,h.jsx)(l.ConversationHeader.Content,{info:p,userName:d}),(0,h.jsx)(l.ConversationHeader.Actions,{children:m?(0,h.jsx)(l.AddUserButton,{onClick:v}):null})]}),(0,h.jsx)(l.MessageList,{loading:r,children:(0,h.jsx)(l.MessageList.Content,{className:`h-full`,children:(0,h.jsx)(`div`,{id:`scrollRef`,ref:D,className:`overflow-hidden overflow-y-auto h-full`,children:i.map(e=>(0,h.jsx)(g.ChatMessage,{id:e._id,role:`user`,name:T[e.senderId??``]?.userName??`Unknown`,avatar:T[e.senderId??``]?.avatarUrl??`Unknown`,datetime:E(e.sentAt),variant:e.senderId===_?`base`:`outline`,placement:e.senderId===_?`right`:`left`,content:[{type:`text`,data:e.encryption?.text??``}]},e._id))})})}),(0,h.jsx)(l.MessageInput,{value:a,placeholder:o,disabled:s,sendDisabled:s,attachButton:!1,sendButton:!0,onChange:C,onSend:w})]})}function J({open:e,onCancel:t}){let[n,r]=(0,c.useState)(!1),[i,a]=(0,c.useState)(),o=B(e=>e.prependChannel),s=B(e=>e.setActiveConversationId),l=B(e=>e.setTabbarValue);return(0,h.jsx)(N,{open:e,onCancel:t,title:`创建群聊`,description:`填写群聊名称和描述后即可创建`,width:520,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(u.Button,{theme:`light`,onClick:t,disabled:n,children:`取消`}),(0,h.jsx)(u.Button,{type:`primary`,loading:n,onClick:()=>i?.submitForm(),children:`创建群聊`})]}),children:(0,h.jsx)(u.Form,{layout:`vertical`,getFormApi:a,onSubmit:async({name:e,description:n})=>{r(!0);try{let r=await A(e,n),i=`_id`in r?r:r.data;if(!i?._id){u.Toast.error(`创建群聊失败`);return}o({_id:i._id,members:i.members??[],name:i.name??e,type:i.type??`CHANNEL`,createdBy:i.createdBy??``,e2eeEnabled:i.e2eeEnabled??!1,senderKeyVersion:i.senderKeyVersion??0,createdAt:i.createdAt??new Date().toISOString(),updatedAt:i.updatedAt??new Date().toISOString(),roomType:`CHANNEL`,msg:[]}),l(`channels`),s(i._id),t()}catch{u.Toast.error(`创建群聊失败,请稍后重试`)}finally{r(!1)}},children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-[16px]`,children:[(0,h.jsx)(u.Form.Input,{field:`name`,label:`群聊名称`,placeholder:`请输入群聊名称`,disabled:n,rules:[{required:!0,message:`请输入群聊名称`}]}),(0,h.jsx)(u.Form.TextArea,{field:`description`,label:`群聊描述`,placeholder:`请输入群聊描述`,disabled:n,rows:4,rules:[{required:!0,message:`请输入群聊描述`}]})]})})})}var Y=(e,t)=>e.participants.find(e=>e!==t)??e.participants[0]??e._id,X=({conversation:e,allUsers:t,currentUserId:n})=>{let r=Y(e,n),i=t.find(e=>e.userId===r);return{peerUserId:r,displayName:i?.userName??r??e._id,avatarUrl:i?.avatarUrl,info:r===e._id?`${e.msg.length} messages`:r}};function ee({onSelectConversation:e,className:t,style:n,conversationContentStyle:r,conversationAvatarStyle:i}){let a=u.Empty,o=B(e=>e.conversations),s=B(e=>e.channels),d=B(e=>e.activeConversationId),f=B(e=>e.isConversationsLoading),p=S(e=>e.connectionStatus),m=B(e=>e.tabbarValue),g=B(e=>e.setTabbarValue),_=R(e=>e.currentUser),b=R(e=>e.allUserList),{formatDateTime:x}=G(),[C,w]=(0,c.useState)(!1),[T,E]=(0,c.useState)(!1),[D,O]=(0,c.useState)(!1),k=f||p!==`connected`,A=()=>{O(!1),w(!0)},j=()=>{O(!1),E(!0)},M=()=>{k||O(e=>!e)},N=[{value:`conversations`,label:`单聊`,icon:(0,h.jsx)(y.ChatIcon,{}),badge:o.some(e=>e.unreadDot)},{value:`channels`,label:`群聊`,icon:(0,h.jsx)(y.ChatDoubleIcon,{}),badge:s.some(e=>e.unreadDot)}];return(0,h.jsxs)(l.Sidebar,{className:t,position:`left`,scrollable:!1,style:n,children:[(0,h.jsxs)(l.ConversationHeader,{children:[(0,h.jsx)(l.Avatar,{name:_?.userName??`Current User`,src:_?.avatarUrl??`https://chatscope.io/storybook/react/assets/emily-xzL8sDL2.svg`}),(0,h.jsx)(l.ConversationHeader.Content,{userName:_?.userName??`Current User`}),(0,h.jsx)(l.ConversationHeader.Actions,{children:(0,h.jsx)(u.Dropdown,{position:`bottomLeft`,trigger:`custom`,clickToHide:!0,visible:D,onClickOutSide:()=>O(!1),render:(0,h.jsxs)(u.Dropdown.Menu,{children:[(0,h.jsx)(u.Dropdown.Item,{icon:(0,h.jsx)(y.ChatIcon,{}),onClick:A,children:`Add Conversation`}),(0,h.jsx)(u.Dropdown.Item,{icon:(0,h.jsx)(y.ChatDoubleIcon,{}),onClick:j,children:`Add Channel`})]}),children:(0,h.jsx)(`div`,{onClick:M,children:(0,h.jsx)(l.AddUserButton,{disabled:k})})})})]}),f?(0,h.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,h.jsx)(l.Loader,{})}):(0,h.jsx)(`div`,{className:`overflow-hidden overflow-y-auto flex-1`,children:m===`conversations`?o.length>0?o.map(t=>{let{avatarUrl:n,displayName:a}=X({conversation:t,allUsers:b,currentUserId:_?.userId});return(0,h.jsxs)(l.Conversation,{active:t._id===d,unreadDot:t.unreadDot,lastActivityTime:x(t.updatedAt),onClick:()=>e(t._id),children:[(0,h.jsx)(l.Avatar,{name:a,src:n??`https://chatscope.io/storybook/react/assets/emily-xzL8sDL2.svg`,style:i}),(0,h.jsx)(l.Conversation.Content,{name:a,style:r})]},t._id)}):(0,h.jsx)(`div`,{className:`flex h-full items-center justify-center rounded-[8px] border border-dashed border-slate-200`,children:(0,h.jsx)(a,{description:`暂无单聊会话`})}):s.length>0?s.map(t=>(0,h.jsxs)(l.Conversation,{active:t._id===d,unreadDot:t.unreadDot,lastActivityTime:x(t.updatedAt),onClick:()=>e(t._id),children:[(0,h.jsx)(l.Avatar,{name:t.name,src:K,style:i}),(0,h.jsx)(l.Conversation.Content,{name:t.name,style:r})]},t._id)):(0,h.jsx)(`div`,{className:`flex h-full items-center justify-center rounded-[8px] border border-dashed border-slate-200`,children:(0,h.jsx)(a,{description:`暂无群聊会话`})})}),(0,h.jsx)(v.TabBar,{value:m,onChange:e=>{g(String(e))},theme:`tag`,fixed:!1,split:!1,children:N.map((e,t)=>(0,h.jsx)(v.TabBarItem,{icon:e.icon,value:e.value,badgeProps:{dot:e.badge},children:e.label},e.value||t))}),(0,h.jsx)(W,{open:C,users:b,onCancel:()=>w(!1)}),(0,h.jsx)(J,{open:T,onCancel:()=>E(!1)})]})}function te(){return{isMobile:(0,b.useMediaQuery)({query:`(max-width: 640px)`})}}var Z=e=>e===`CHANNEL`?`CHANNEL`:`CONVERSATION`,Q=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:null,ne=e=>{let t=Q(e);if(!t)return null;let n=Q(t.data)??t,r=Q(n.encryption),i=r?.text;return typeof i!=`string`||!i.trim()?null:{_id:typeof n._id==`string`?n._id:void 0,roomId:typeof n.roomId==`string`?n.roomId:void 0,roomType:Z(typeof n.roomType==`string`?n.roomType:void 0),senderId:typeof n.senderId==`string`?n.senderId:void 0,type:typeof n.type==`string`?n.type:void 0,status:typeof n.status==`string`?n.status:void 0,encryption:{scheme:typeof r?.scheme==`string`?r.scheme:void 0,text:i},sentAt:typeof n.sentAt==`string`?n.sentAt:void 0}},re=(e,t)=>{try{let n=new URL(e);return t.token&&n.searchParams.set(`token`,t.token),Object.entries(t.connectionParams??{}).forEach(([e,t])=>{t!==void 0&&n.searchParams.set(e,String(t))}),n.toString()}catch{return e}},ie=e=>JSON.stringify({event:`message:send`,data:{roomType:Z(e.roomType),roomId:e.roomId,type:e.type??`TEXT`,ciphertext:e.encryption?.text??``}}),ae=(e,t)=>{try{let n=Q(JSON.parse(e));if(!n||(typeof n.event==`string`?n.event:void 0)!==`message:new`)return[];let r=ne(n);return!r||r.senderId===t.userId?[]:[r]}catch{return[]}},oe=(e,t,n,r=`CONVERSATION`)=>({_id:`local-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,roomId:t,roomType:r,senderId:n,type:`TEXT`,status:`SENT`,encryption:{scheme:`NONE`,text:e},sentAt:new Date().toISOString()});function se({autoConnect:e=!0,reconnect:t=!0,reconnectInterval:n=3e3,maxReconnectAttempts:r=3,wsUrl:i,context:a,onConnectionStatusChange:o,onError:s,onMessages:l,onNotify:u,onEvent:d}){let f=(0,c.useRef)(null),p=(0,c.useRef)(null),m=(0,c.useRef)(0),h=(0,c.useRef)(()=>{}),g=(0,c.useRef)(!1),_=(0,c.useRef)([]),v=(0,c.useRef)(a),y=(0,c.useRef)(o),b=(0,c.useRef)(s),x=(0,c.useRef)(l),C=(0,c.useRef)(u),w=(0,c.useRef)(d),[T,E]=(0,c.useState)(!1),D=S(e=>e.connectionStatus),O=S(e=>e.setWsAddress),k=S(e=>e.setConnectionStatus);(0,c.useEffect)(()=>{v.current=a},[a]),(0,c.useEffect)(()=>{y.current=o},[o]),(0,c.useEffect)(()=>{b.current=s},[s]),(0,c.useEffect)(()=>{x.current=l},[l]),(0,c.useEffect)(()=>{C.current=u},[u]),(0,c.useEffect)(()=>{w.current=d},[d]);let A=(0,c.useCallback)(e=>{k(e),y.current?.(e)},[k]),j=(0,c.useCallback)(()=>{p.current!==null&&(window.clearTimeout(p.current),p.current=null)},[]),M=(0,c.useCallback)(()=>{f.current?.readyState===WebSocket.OPEN&&(_.current.forEach(e=>{f.current?.send(e)}),_.current=[])},[]),N=(0,c.useCallback)(()=>{if(!i||!e||f.current&&(f.current.readyState===WebSocket.OPEN||f.current.readyState===WebSocket.CONNECTING))return;j(),g.current=!1,E(!1),A(`connecting`);let a=re(i,v.current),o;try{o=new WebSocket(a)}catch(e){console.error(`WebSocket connection failed:`,{wsUrl:i,resolvedUrl:a,error:e}),A(`error`),b.current?.(e);return}f.current=o,o.addEventListener(`open`,()=>{f.current===o&&(m.current=0,A(`connected`),M())}),o.addEventListener(`message`,e=>{if(typeof e.data!=`string`)return;try{let t=JSON.parse(e.data);if(t.event&&w.current?.(t.event,t.data),t.event===`message:notify`&&t.data){C.current?.(t.data);return}}catch{}let t=ae(e.data,v.current);x.current?.(t)}),o.addEventListener(`close`,e=>{if(f.current===o){if(console.error(`WebSocket close event:`,{wsUrl:i,resolvedUrl:a,code:e.code,reason:e.reason,wasClean:e.wasClean,readyState:o.readyState}),f.current=null,g.current){A(`disconnected`);return}if(A(`disconnected`),t){if(m.current>=r){E(!0);return}m.current+=1,j(),p.current=window.setTimeout(()=>{h.current()},n)}}}),o.addEventListener(`error`,e=>{f.current===o&&(console.error(`WebSocket error event:`,{wsUrl:i,resolvedUrl:a,readyState:o.readyState,event:e}),A(`error`),b.current?.(e))})},[e,j,M,t,n,r,i,A]),P=(0,c.useCallback)(()=>{g.current=!0,j(),f.current?.close(),f.current=null},[j]),F=(0,c.useCallback)(()=>{i&&(g.current=!1,m.current=0,E(!1),j(),f.current&&(f.current.readyState===WebSocket.OPEN||f.current.readyState===WebSocket.CONNECTING)&&f.current.close(),h.current())},[j,i]),I=(0,c.useCallback)(t=>{if(f.current?.readyState===WebSocket.OPEN){f.current.send(t);return}_.current.push(t),e&&N()},[e,N]),L=(0,c.useCallback)(e=>{I(ie(e))},[I]);return(0,c.useEffect)(()=>{O(i)},[O,i]),(0,c.useEffect)(()=>{h.current=N},[N]),(0,c.useEffect)(()=>i?(N(),()=>{P()}):(m.current=0,E(!1),window.setTimeout(()=>A(`idle`),0),()=>{j()}),[j,N,P,A,i]),(0,c.useMemo)(()=>({status:D,resolvedWsUrl:i,sendMessage:L,sendPayload:I,reconnect:F,hasReconnectExhausted:T}),[T,F,L,I,D,i])}function ce({onMessageReceive:e}){let t=B(e=>e.conversations),n=B(e=>e.channels),r=B(e=>e.activeConversationId),i=B(e=>e.ensureConversation),a=B(e=>e.appendMessages),o=B(e=>e.setActiveConversationId),s=(0,c.useCallback)(e=>{o(e)},[o]),l=(0,c.useCallback)((t,n)=>{let o=n??t[0]?.roomId??r;if(!o){t.forEach(t=>{e?.(t)});return}i(o,{roomType:t[0]?.roomType===`CHANNEL`?`CHANNEL`:`CONVERSATION`}),a(o,t.map(e=>({...e,roomId:e.roomId??o}))),t.forEach(t=>{e?.(t)})},[r,a,i,e]),u=(0,c.useMemo)(()=>[...t,...n].find(e=>e._id===r),[r,n,t]);return{conversations:t,channels:n,activeConversationId:u?._id,messages:u?.msg??[],setActiveConversationId:s,appendMessages:l}}var $=()=>new Promise(e=>{window.requestAnimationFrame(()=>e())});function le(e={}){let{containerRef:t,elementId:n=`scrollRef`,threshold:r=80,behavior:i=`auto`}=e,a=(0,c.useCallback)(()=>t?.current??document.getElementById(n),[t,n]);return{scrollToBottom:(0,c.useCallback)(async()=>{await $();let e=a();e&&e.scrollTo({top:e.scrollHeight,behavior:i})},[i,a]),scrollToTop:(0,c.useCallback)(async()=>{await $();let e=a();e&&e.scrollTo({top:0,behavior:i})},[i,a]),scrollToBottomIfAtBottom:(0,c.useCallback)(async()=>{await $();let e=a();e&&e.scrollHeight-e.scrollTop-e.clientHeight<=r&&e.scrollTo({top:e.scrollHeight,behavior:i})},[i,a,r])}}function ue({allUserList:e,autoConnect:t=!0,connectionParams:n,disabled:r=!1,onConnectionStatusChange:i,onError:a,onMessageReceive:o,optimisticSend:s=!0,wsUrl:l,httpUrl:d,token:f,userId:p}){let[m,h]=(0,c.useState)(``),{scrollToBottom:g}=le(),_=R(e=>e.setAllUserList),v=R(e=>e.setCurrentUser),y=R(e=>e.upsertUsersFromMessages),b=B(e=>e.setConversations),x=B(e=>e.setChannels),C=B(e=>e.setConversationMessages),w=B(e=>e.setConversationUnreadDot),T=B(e=>e.setConversationsLoading),D=B(e=>e.isMessagesLoading),A=B(e=>e.setMessagesLoading),j=S(e=>e.setHttpUrl),M=S(e=>e.setToken),{activeConversationId:N,appendMessages:P,channels:F,conversations:I,messages:L,setActiveConversationId:z}=ce({onMessageReceive:o}),V=(0,c.useMemo)(()=>e.find(e=>e.userId===p),[e,p]),H=(0,c.useMemo)(()=>[...I,...F].find(e=>e._id===N),[F,I,N]),U=V?.userName??`You`,W=V?.avatarUrl,{resolvedWsUrl:G,sendMessage:K,sendPayload:q,status:J,reconnect:Y,hasReconnectExhausted:X}=se({autoConnect:t,reconnect:!0,reconnectInterval:3e3,maxReconnectAttempts:3,wsUrl:l,context:(0,c.useMemo)(()=>({userId:p,userName:U,userAvatar:W,token:f,connectionParams:n}),[n,W,U,f,p]),onConnectionStatusChange:i,onError:a,onMessages:(0,c.useCallback)(e=>{y(e);let t=e.reduce((e,t)=>{let n=t.roomId??N;return n?(e[n]||(e[n]=[]),e[n].push(t),e):e},{});Object.entries(t).forEach(([e,t])=>{P(t,e)})},[P,N,y]),onNotify:(0,c.useCallback)(e=>{!e.roomId||e.senderId===p||e.roomId===N&&H?.hasReq||w(e.roomId,!0,e)},[H?.hasReq,N,w,p]),onEvent:(0,c.useCallback)(async(e,t)=>{if(e!==`channel:member_added`)return;let n=typeof t==`object`&&t&&!Array.isArray(t)?t:void 0;if(!(!n||n.roomType!==`CHANNEL`||typeof n.memberId!=`string`||n.memberId!==p)){u.Toast.success(`你已被邀请进了新群聊`);try{x(((await k()).data??[]).map(e=>({...e,roomType:`CHANNEL`,msg:[]})))}catch(e){a?.(e)}}},[a,x,p])});return(0,c.useEffect)(()=>{_(e)},[e,_]),(0,c.useEffect)(()=>{j(d)},[d,j]),(0,c.useEffect)(()=>{f!==void 0&&M(f)},[M,f]),(0,c.useEffect)(()=>{if(J!==`connected`)return;let e=!1;return(async()=>{T(!0);try{let[t,n]=await Promise.all([E(),k()]),r=t,i=n;if(e)return;b((r.data??[]).map(e=>({...e,roomType:`CONVERSATION`,msg:[]}))),x((i.data??[]).map(e=>({...e,roomType:`CHANNEL`,msg:[]})))}catch(t){e||a?.(t)}finally{e||T(!1)}})(),()=>{e=!0}},[a,x,b,T,J]),(0,c.useEffect)(()=>{p&&v({userId:p,userName:U,avatarUrl:W})},[W,U,v,p]),(0,c.useEffect)(()=>{!N||!H?.hasReq||!H.unreadDot||w(N,!1)},[H?.hasReq,H?.unreadDot,N,w]),(0,c.useEffect)(()=>{if(!N||H?.hasReq){g();return}let e=!1,t=H?.roomType??`CONVERSATION`;return(async()=>{A(!0);try{q(JSON.stringify({event:`room:join`,data:{roomType:t,roomId:N}}));let n=await O(N,t);if(e)return;C(N,(n.data?[...n.data].reverse():[]).map(e=>({...e,roomId:e.roomId??N,roomType:t}))),g()}catch(t){e||a?.(t)}finally{A(!1)}})(),()=>{e=!0}},[H?.hasReq,H?.roomType,a,N,q,C,A,g]),{conversations:I,activeConversationId:N,connectionStatus:J,hasReconnectExhausted:X,inputValue:m,isMessagesLoading:D,messages:L,resolvedDisabled:r||!G||!N,handleConversationSelect:z,handleChange:(0,c.useCallback)((e,t,n)=>{h(t||n||e)},[]),handleReconnect:Y,handleSend:(0,c.useCallback)((e,t,n)=>{let r=(t||n||e).trim();if(!r||!N)return;let i=oe(r,N,p,H?.roomType??`CONVERSATION`);s&&P([i],N),K(i),h(``)},[H?.roomType,P,s,N,K,p])}}function de({placeholder:e=`Type message here`,className:t,disabled:n=!1,...r}){let i=[`flex w-full flex-col h-full`,t].filter(Boolean).join(` `),a={height:`100%`},[o,s]=(0,c.useState)(!1),[d,f]=(0,c.useState)({}),[p,m]=(0,c.useState)({}),[g,_]=(0,c.useState)({}),[v,y]=(0,c.useState)({}),[b,x]=(0,c.useState)(!1),[S,C]=(0,c.useState)(!1),w=(0,c.useRef)(null),{isMobile:T}=te(),{activeConversationId:E,connectionStatus:D,conversations:O,handleChange:k,handleConversationSelect:A,handleReconnect:j,handleSend:M,hasReconnectExhausted:P,inputValue:F,isMessagesLoading:I,messages:L,resolvedDisabled:z}=ue({...r,disabled:n}),V=R(e=>e.currentUser),H=R(e=>e.allUserList),U=B(e=>e.channels),G=B(e=>e.setActiveConversationId),K=(0,c.useMemo)(()=>[...O,...U].find(e=>e._id===E),[E,U,O]),J=(0,c.useMemo)(()=>K&&`members`in K?K:void 0,[K]),Y=(0,c.useMemo)(()=>{if(K)return`name`in K?{avatarUrl:void 0,displayName:K.name||`Channel`,info:void 0}:X({conversation:K,allUsers:H,currentUserId:V?.userId})},[K,H,V?.userId]),Z=(0,c.useMemo)(()=>{if(P)return`长连接重连次数已用完,请手动重连`;switch(D){case`idle`:return`等待建立长连接`;case`connecting`:return`长连接正在连接中`;case`disconnected`:return`长连接已断开,正在尝试重连`;case`error`:return`长连接连接失败`;default:return``}},[D,P]),Q=S&&!P&&D!==`connected`,ne=(0,c.useMemo)(()=>(0,h.jsx)(`div`,{className:`flex justify-end gap-[12px]`,children:(0,h.jsx)(u.Button,{loading:Q,theme:`solid`,type:`primary`,onClick:j,children:`继续重连`})}),[j,Q]),re=(0,c.useCallback)(e=>{A(e),o&&s(!1)},[A,o]),ie=(0,c.useCallback)(()=>{s(e=>!e),G(void 0)},[G]),ae=(0,c.useCallback)(()=>{J&&x(!0)},[J]);return(0,c.useEffect)(()=>{T&&!E&&s(!0)},[E,T]),(0,c.useEffect)(()=>{if(o){f({display:`flex`,flexBasis:`auto`,width:`100%`,maxWidth:`100%`}),_({display:`flex`}),y({marginRight:`1em`}),m({display:`none`});return}f({}),_({}),y({}),m({})},[o]),(0,c.useEffect)(()=>{P&&C(!0)},[P]),(0,c.useEffect)(()=>{D===`connected`&&C(!1)},[D]),(0,h.jsx)(`div`,{className:i,children:(0,h.jsxs)(`div`,{ref:w,className:`relative h-full w-full overflow-hidden border border-slate-200 bg-white shadow-[0_18px_48px_rgba(15,23,42,0.08),0_8px_20px_rgba(15,23,42,0.06)] [&_.cs-main-container]:border-0 [&_.cs-main-container]:bg-transparent [&_.cs-chat-container]:bg-[linear-gradient(180deg,_#f8fafc,_#ffffff_28%)] [&_.cs-message-input]:border-t [&_.cs-message-input]:border-slate-200 [&_.cs-message-input]:bg-white/95 [&_.cs-message-input__content-editor-wrapper]:bg-slate-50 [&_.cs-message-list]:bg-transparent`,style:a,children:[(0,h.jsx)(u.Spin,{tip:Z,spinning:D!==`connected`,wrapperClassName:`h-full!`,childStyle:{height:`100%`},children:(0,h.jsxs)(l.MainContainer,{responsive:!0,children:[(0,h.jsx)(ee,{onSelectConversation:re,style:d,conversationContentStyle:g,conversationAvatarStyle:v}),(0,h.jsx)(q,{hasActiveConversation:!!E,connectionStatus:D,hasReconnectExhausted:P,isMessagesLoading:I,messages:L,inputValue:F,placeholder:e,resolvedDisabled:z,headerAvatar:Y?.avatarUrl,headerName:Y?.displayName??`Conversation`,headerInfo:Y?.info,isChannel:!!J,currentUserId:V?.userId,onAddMemberClick:ae,onBackClick:ie,onReconnect:j,style:p,onChange:k,onSend:M}),(0,h.jsx)(W,{open:b,users:H,mode:`channelMember`,channelId:J?._id,channelName:J?.name,onCancel:()=>x(!1)})]})}),(0,h.jsx)(N,{open:S,title:`长连接已断开`,description:`自动重连已失败,是否继续重连?`,width:420,footer:ne,maskClosable:!1,closable:!1,closeOnEsc:!1,getPopupContainer:()=>w.current??document.body,onCancel:()=>{},children:(0,h.jsxs)(`div`,{className:`text-[14px] leading-[24px] text-slate-600`,children:[`当前连接状态:`,Z||`长连接连接异常`]})})]})})}exports.NexusChatUI=de,exports.useChatConnection=se,exports.useChatMessages=ce,exports.useNexusChat=ue;
@@ -0,0 +1,6 @@
1
+ export { NexusChatUI } from './components/ChatUI';
2
+ export { useNexusChat } from './hooks/useNexusChat';
3
+ export { useChatConnection } from './hooks/useChatConnection';
4
+ export { useChatMessages } from './hooks/useChatMessages';
5
+ export type { ChatConnectionContext, ChatConnectionStatus, ChatConversationItem, ChatMessageDirection, ChatMessageItem, ChatMessagePosition, ChatUserProfile, NexusChatUIProps, } from './types';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,mCAAmC,CAAA;AAC1C,OAAO,2DAA2D,CAAA;AAClE,OAAO,uCAAuC,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,YAAY,EACV,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,gBAAgB,GACjB,MAAM,SAAS,CAAA"}