@acorex/components 21.0.0-next.20 โ†’ 21.0.0-next.21

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.
@@ -0,0 +1,421 @@
1
+ # @acorex/components/conversation2
2
+
3
+ A modern, fully-featured conversation/chat component for Angular 18+. Built with signals, standalone components, and extensibility in mind.
4
+
5
+ ## ๐Ÿš€ Features
6
+
7
+ - **Real-time Messaging** - Live message updates with WebSocket support
8
+ - **Multiple Message Types** - Text, images, videos, audio, voice, files, locations, stickers, contacts
9
+ - **Rich Interactions** - Reactions, replies, message editing, deletion, forwarding
10
+ - **Group & Private Chats** - Support for 1-on-1 and group conversations
11
+ - **Typing Indicators** - Real-time typing status
12
+ - **Read Receipts** - Message delivery and read status
13
+ - **Infinite Scroll** - Efficient pagination for message history
14
+ - **Search** - Search within conversations and messages
15
+ - **Extensible** - Plugin system for custom message renderers and actions
16
+ - **Responsive** - Mobile-friendly design
17
+ - **Accessibility** - ARIA labels and keyboard navigation
18
+
19
+ ## ๐Ÿ“ฆ Installation
20
+
21
+ ```bash
22
+ npm install @acorex/components/conversation2
23
+ ```
24
+
25
+ ## ๐Ÿ”ง Peer Dependencies
26
+
27
+ This package requires the following peer dependencies:
28
+
29
+ ### Required Angular Dependencies
30
+
31
+ ```json
32
+ {
33
+ "@angular/common": "^18.0.0",
34
+ "@angular/core": "^18.0.0",
35
+ "@angular/forms": "^18.0.0",
36
+ "rxjs": "^7.8.0"
37
+ }
38
+ ```
39
+
40
+ ### Required Acorex Dependencies
41
+
42
+ #### Core Packages
43
+
44
+ - `@acorex/cdk/common` - Common utilities and directives
45
+ - `@acorex/core/date-time` - Date and time formatting
46
+ - `@acorex/core/format` - General formatting utilities
47
+
48
+ #### Component Packages
49
+
50
+ - `@acorex/components/avatar` - User avatars
51
+ - `@acorex/components/badge` - Notification badges
52
+ - `@acorex/components/button` - Button components
53
+ - `@acorex/components/decorators` - Decorative elements
54
+ - `@acorex/components/dialog` - Dialog service
55
+ - `@acorex/components/dropdown` - Dropdown panels
56
+ - `@acorex/components/image` - Image components
57
+ - `@acorex/components/label` - Label components
58
+ - `@acorex/components/loading` - Loading indicators
59
+ - `@acorex/components/menu` - Context menus
60
+ - `@acorex/components/popover` - Popover components
61
+ - `@acorex/components/popup` - Popup service
62
+ - `@acorex/components/search-box` - Search functionality
63
+ - `@acorex/components/select-box` - Select dropdowns
64
+ - `@acorex/components/tabs` - Tab components
65
+ - `@acorex/components/text-area` - Text input areas
66
+ - `@acorex/components/text-box` - Text input boxes
67
+ - `@acorex/components/toast` - Toast notifications
68
+ - `@acorex/components/tooltip` - Tooltips
69
+ - `@acorex/components/uploader` - File upload functionality
70
+
71
+ ## ๐ŸŽฏ Quick Start
72
+
73
+ ### 1. Standalone Application (Recommended)
74
+
75
+ ```typescript
76
+ import { ApplicationConfig } from '@angular/core';
77
+ import { provideConversation, AXIndexedDBApi } from '@acorex/components/conversation2';
78
+
79
+ export const appConfig: ApplicationConfig = {
80
+ providers: [
81
+ provideConversation({
82
+ api: AXIndexedDBApi, // or your custom API implementation
83
+ config: {
84
+ pageSize: 20,
85
+ maxFileSize: 10 * 1024 * 1024, // 10MB
86
+ allowedFileTypes: ['image/*', 'video/*', 'audio/*', 'application/pdf'],
87
+ },
88
+ registry: {
89
+ // Optional: Register custom message renderers, actions, etc.
90
+ }
91
+ })
92
+ ]
93
+ };
94
+ ```
95
+
96
+ ### 2. NgModule Application (Legacy)
97
+
98
+ ```typescript
99
+ import { NgModule } from '@angular/core';
100
+ import { AXConversation2Module, AXIndexedDBApi } from '@acorex/components/conversation2';
101
+
102
+ @NgModule({
103
+ imports: [
104
+ AXConversation2Module.forRoot({
105
+ api: AXIndexedDBApi,
106
+ config: { /* ... */ }
107
+ })
108
+ ]
109
+ })
110
+ export class AppModule { }
111
+ ```
112
+
113
+ ### 3. Use in Template
114
+
115
+ ```html
116
+ <ax-conversation-container></ax-conversation-container>
117
+ ```
118
+
119
+ ## ๐Ÿ”Œ API Implementation
120
+
121
+ You must provide an API implementation that extends `AXConversationApi`:
122
+
123
+ ```typescript
124
+ import { Injectable } from '@angular/core';
125
+ import { HttpClient } from '@angular/common/http';
126
+ import { AXConversationApi, AXPagination, AXPaginatedResult } from '@acorex/components/conversation2';
127
+
128
+ @Injectable()
129
+ export class MyConversationApi extends AXConversationApi {
130
+ constructor(private http: HttpClient) {
131
+ super();
132
+ }
133
+
134
+ async connect(): Promise<void> {
135
+ // Initialize WebSocket connection
136
+ }
137
+
138
+ async fetchConversations(pagination: AXPagination): Promise<AXPaginatedResult<AXConversation>> {
139
+ const response = await this.http.get('/api/conversations', {
140
+ params: { page: pagination.page, pageSize: pagination.pageSize }
141
+ }).toPromise();
142
+ return response;
143
+ }
144
+
145
+ // Implement other required methods...
146
+ }
147
+ ```
148
+
149
+ ### Built-in API Implementations
150
+
151
+ #### IndexedDB API (Development/Demo)
152
+
153
+ ```typescript
154
+ import { AXIndexedDBApi } from '@acorex/components/conversation2';
155
+
156
+ // Provides in-memory storage with sample data
157
+ // Perfect for development and demos
158
+ provideConversation({ api: AXIndexedDBApi })
159
+ ```
160
+
161
+ #### IndexedDB with AI API (AI-Powered Demo)
162
+
163
+ ```typescript
164
+ import { AXIndexedDBAIApi } from '@acorex/components/conversation2';
165
+
166
+ // Includes AI-powered auto-responses
167
+ provideConversation({ api: AXIndexedDBAIApi })
168
+ ```
169
+
170
+ ## โš™๏ธ Configuration
171
+
172
+ ### Conversation Config
173
+
174
+ ```typescript
175
+ interface AXConversationConfig {
176
+ // Pagination
177
+ pageSize?: number; // Default: 20
178
+ infiniteScrollThreshold?: number; // Default: 200px
179
+ scrollThreshold?: number; // Default: 100px
180
+
181
+ // File Upload
182
+ maxFileSize?: number; // Default: 10MB
183
+ allowedFileTypes?: string[]; // Default: all types
184
+
185
+ // UI Behavior
186
+ messageHighlightDuration?: number; // Default: 2000ms
187
+ typingIndicatorTimeout?: number; // Default: 3000ms
188
+
189
+ // Features
190
+ enableReactions?: boolean; // Default: true
191
+ enableReplies?: boolean; // Default: true
192
+ enableEditing?: boolean; // Default: true
193
+ enableDeletion?: boolean; // Default: true
194
+ }
195
+ ```
196
+
197
+ ### Registry Configuration
198
+
199
+ ```typescript
200
+ interface AXRegistryConfiguration {
201
+ messageRenderers?: AXMessageRenderer[];
202
+ messageActions?: AXMessageAction[];
203
+ composerActions?: AXComposerAction[];
204
+ composerTabs?: AXComposerTab[];
205
+ conversationTabs?: AXConversationTab[];
206
+ infoBarActions?: AXInfoBarAction[];
207
+ conversationItemActions?: AXConversationItemAction[];
208
+ }
209
+ ```
210
+
211
+ ## ๐ŸŽจ Customization
212
+
213
+ ### Custom Message Renderer
214
+
215
+ ```typescript
216
+ import { Component, input } from '@angular/core';
217
+ import { AXMessageRenderer } from '@acorex/components/conversation2';
218
+
219
+ @Component({
220
+ selector: 'my-custom-renderer',
221
+ template: `<div>{{ message().payload.customData }}</div>`
222
+ })
223
+ export class MyCustomRendererComponent {
224
+ message = input.required<AXMessage>();
225
+ }
226
+
227
+ const myRenderer: AXMessageRenderer = {
228
+ type: 'custom',
229
+ component: MyCustomRendererComponent,
230
+ priority: 100
231
+ };
232
+
233
+ // Register in config
234
+ provideConversation({
235
+ api: MyApi,
236
+ registry: {
237
+ messageRenderers: [myRenderer]
238
+ }
239
+ });
240
+ ```
241
+
242
+ ### Custom Message Action
243
+
244
+ ```typescript
245
+ const forwardAction: AXMessageAction = {
246
+ id: 'forward',
247
+ label: 'Forward',
248
+ icon: 'forward',
249
+ shortcut: 'Ctrl+F',
250
+ enabled: (message, user) => message.senderId === user.id,
251
+ execute: async (message, service) => {
252
+ // Forward logic
253
+ }
254
+ };
255
+
256
+ provideConversation({
257
+ api: MyApi,
258
+ registry: {
259
+ messageActions: [forwardAction]
260
+ }
261
+ });
262
+ ```
263
+
264
+ ## ๐Ÿ“ฑ Components
265
+
266
+ ### Main Components
267
+
268
+ - `<ax-conversation-container>` - Full conversation UI with sidebar, messages, and composer
269
+ - `<ax-conversation-sidebar>` - Conversation list sidebar
270
+ - `<ax-conversation-message-list>` - Message list with virtual scrolling
271
+ - `<ax-conversation-composer>` - Message input area
272
+ - `<ax-conversation-info-bar>` - Conversation header with actions
273
+
274
+ ### Usage Examples
275
+
276
+ ```html
277
+ <!-- Full conversation UI -->
278
+ <ax-conversation-container></ax-conversation-container>
279
+
280
+ <!-- Custom layout -->
281
+ <div class="my-chat-layout">
282
+ <ax-conversation-sidebar></ax-conversation-sidebar>
283
+ <div class="chat-main">
284
+ <ax-conversation-info-bar></ax-conversation-info-bar>
285
+ <ax-conversation-message-list></ax-conversation-message-list>
286
+ <ax-conversation-composer></ax-conversation-composer>
287
+ </div>
288
+ </div>
289
+ ```
290
+
291
+ ## ๐ŸŽญ Services
292
+
293
+ ### AXConversationService
294
+
295
+ Main service for conversation operations:
296
+
297
+ ```typescript
298
+ import { inject } from '@angular/core';
299
+ import { AXConversationService } from '@acorex/components/conversation2';
300
+
301
+ export class MyComponent {
302
+ private conversationService = inject(AXConversationService);
303
+
304
+ async sendMessage() {
305
+ await this.conversationService.sendMessage({
306
+ conversationId: 'conv-123',
307
+ type: 'text',
308
+ payload: { text: 'Hello!' }
309
+ });
310
+ }
311
+
312
+ async createConversation() {
313
+ const conv = await this.conversationService.createConversation(
314
+ ['user-1', 'user-2'],
315
+ 'private'
316
+ );
317
+ }
318
+ }
319
+ ```
320
+
321
+ ## ๐Ÿงช Testing
322
+
323
+ ```typescript
324
+ import { TestBed } from '@angular/core/testing';
325
+ import { provideConversation, AXConversationService } from '@acorex/components/conversation2';
326
+ import { MockConversationApi } from './mocks/mock-api';
327
+
328
+ describe('MyComponent', () => {
329
+ beforeEach(() => {
330
+ TestBed.configureTestingModule({
331
+ providers: [
332
+ provideConversation({ api: MockConversationApi })
333
+ ]
334
+ });
335
+ });
336
+
337
+ it('should send message', async () => {
338
+ const service = TestBed.inject(AXConversationService);
339
+ const message = await service.sendMessage({
340
+ conversationId: 'test',
341
+ type: 'text',
342
+ payload: { text: 'Test' }
343
+ });
344
+ expect(message).toBeDefined();
345
+ });
346
+ });
347
+ ```
348
+
349
+ ## ๐ŸŽฏ Message Types
350
+
351
+ Supported message types out of the box:
352
+
353
+ - **text** - Plain text messages
354
+ - **image** - Image messages with thumbnails
355
+ - **video** - Video messages with playback
356
+ - **audio** - Audio file messages
357
+ - **voice** - Voice recordings
358
+ - **file** - Generic file attachments
359
+ - **location** - Location sharing
360
+ - **sticker** - Sticker messages
361
+ - **contact** - Contact card sharing
362
+ - **system** - System notifications
363
+
364
+ ## ๐Ÿ”’ Security Considerations
365
+
366
+ - **API Keys**: Never hardcode API keys in source code. Use environment variables or injection tokens.
367
+ - **File Upload**: Validate file types and sizes on both client and server.
368
+ - **XSS Protection**: All user content is sanitized by default.
369
+ - **Authentication**: Implement proper authentication in your API layer.
370
+
371
+ ## ๐Ÿ“Š Performance Tips
372
+
373
+ 1. **Virtual Scrolling**: Enabled by default for large message lists
374
+ 2. **Lazy Loading**: Images and media are loaded on demand
375
+ 3. **Pagination**: Messages are loaded in pages to reduce initial load
376
+ 4. **Debouncing**: Typing indicators are debounced to reduce network traffic
377
+ 5. **Memoization**: Use computed signals for expensive calculations
378
+
379
+ ## ๐Ÿ› Troubleshooting
380
+
381
+ ### Common Issues
382
+
383
+ **Issue**: Messages not appearing
384
+
385
+ - Check if API is connected: `conversationService.connectionStatus$()`
386
+ - Verify API implementation returns correct data structure
387
+
388
+ **Issue**: File upload fails
389
+
390
+ - Check `maxFileSize` and `allowedFileTypes` configuration
391
+ - Verify API `uploadFile()` implementation
392
+
393
+ **Issue**: Styling issues
394
+
395
+ - Ensure all Acorex component styles are imported
396
+ - Check for CSS conflicts with global styles
397
+
398
+ ## ๐Ÿ“š Additional Resources
399
+
400
+ - [API Documentation](./docs/API.md)
401
+ - [Examples](./docs/EXAMPLES.md)
402
+ - [Migration Guide](./docs/MIGRATION.md)
403
+ - [Contributing](./CONTRIBUTING.md)
404
+ - [Improvements Roadmap](./IMPROVEMENTS.md)
405
+
406
+ ## ๐Ÿค Contributing
407
+
408
+ Contributions are welcome! Please read our [Contributing Guide](./CONTRIBUTING.md) for details.
409
+
410
+ ## ๐Ÿ“„ License
411
+
412
+ MIT License - see LICENSE file for details
413
+
414
+ ## ๐Ÿ”„ Changelog
415
+
416
+ See [CHANGELOG.md](./CHANGELOG.md) for version history and updates.
417
+
418
+ ## ๐Ÿ’ฌ Support
419
+
420
+ - GitHub Issues: [Report a bug](https://github.com/acorexui/acorex-ui/issues)
421
+ - Discussions: [Ask questions](https://github.com/acorexui/acorex-ui/discussions)