@droppii-org/chat-sdk 0.0.2 → 0.0.4

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 (64) hide show
  1. package/dist/components/AutoScrollAnchor.d.ts +1 -1
  2. package/dist/components/AutoScrollAnchor.d.ts.map +1 -1
  3. package/dist/components/AutoScrollAnchor.js +12 -0
  4. package/dist/components/ChatBubble.d.ts +1 -1
  5. package/dist/components/ChatBubble.d.ts.map +1 -1
  6. package/dist/components/ChatBubble.js +18 -0
  7. package/dist/components/ChatHeader.d.ts +1 -1
  8. package/dist/components/ChatHeader.d.ts.map +1 -1
  9. package/dist/components/ChatHeader.js +32 -0
  10. package/dist/components/ChatInput.d.ts +1 -2
  11. package/dist/components/ChatInput.d.ts.map +1 -1
  12. package/dist/components/ChatInput.js +379 -0
  13. package/dist/components/ChatInputDemo.d.ts +1 -1
  14. package/dist/components/ChatInputDemo.d.ts.map +1 -1
  15. package/dist/components/ChatInputDemo.js +38 -0
  16. package/dist/components/ChatInputWithCustomIcon.d.ts +1 -2
  17. package/dist/components/ChatInputWithCustomIcon.d.ts.map +1 -1
  18. package/dist/components/ChatInputWithCustomIcon.js +85 -0
  19. package/dist/components/ChatLayout.d.ts +1 -1
  20. package/dist/components/ChatLayout.d.ts.map +1 -1
  21. package/dist/components/ChatLayout.js +48 -0
  22. package/dist/components/ConversationItem.d.ts +1 -1
  23. package/dist/components/ConversationItem.d.ts.map +1 -1
  24. package/dist/components/ConversationItem.js +27 -0
  25. package/dist/components/ConversationList.d.ts +1 -1
  26. package/dist/components/ConversationList.d.ts.map +1 -1
  27. package/dist/components/ConversationList.js +11 -0
  28. package/dist/components/DateDivider.d.ts +1 -1
  29. package/dist/components/DateDivider.d.ts.map +1 -1
  30. package/dist/components/DateDivider.js +27 -0
  31. package/dist/components/EmojiPicker.js +191 -0
  32. package/dist/components/ImageLightbox.d.ts +1 -1
  33. package/dist/components/ImageLightbox.d.ts.map +1 -1
  34. package/dist/components/ImageLightbox.js +8 -0
  35. package/dist/components/ImagePreviewModal.d.ts +1 -1
  36. package/dist/components/ImagePreviewModal.d.ts.map +1 -1
  37. package/dist/components/ImagePreviewModal.js +55 -0
  38. package/dist/components/MessageItem.d.ts +1 -1
  39. package/dist/components/MessageItem.d.ts.map +1 -1
  40. package/dist/components/MessageItem.js +38 -0
  41. package/dist/components/MessageItemDemo.d.ts +1 -1
  42. package/dist/components/MessageItemDemo.d.ts.map +1 -1
  43. package/dist/components/MessageItemDemo.js +166 -0
  44. package/dist/components/MessageList.d.ts +1 -1
  45. package/dist/components/MessageList.d.ts.map +1 -1
  46. package/dist/components/MessageList.js +243 -0
  47. package/dist/components/MessageListDemo.d.ts +1 -1
  48. package/dist/components/MessageListDemo.d.ts.map +1 -1
  49. package/dist/components/MessageListDemo.js +165 -0
  50. package/dist/components/StickerPicker.js +68 -0
  51. package/dist/components/SwipeIndicator.d.ts +1 -1
  52. package/dist/components/SwipeIndicator.d.ts.map +1 -1
  53. package/dist/components/SwipeIndicator.js +24 -0
  54. package/dist/components/TextFormattingToolbar.js +29 -0
  55. package/dist/components/TypingIndicator.d.ts +1 -1
  56. package/dist/components/TypingIndicator.d.ts.map +1 -1
  57. package/dist/components/TypingIndicator.js +21 -0
  58. package/dist/components/VoiceWaveIcon.d.ts +1 -1
  59. package/dist/components/VoiceWaveIcon.d.ts.map +1 -1
  60. package/dist/components/VoiceWaveIcon.js +5 -0
  61. package/dist/context/ChatContext.d.ts +1 -1
  62. package/dist/context/ChatContext.d.ts.map +1 -1
  63. package/dist/context/ChatContext.js +347 -0
  64. package/package.json +1 -1
@@ -0,0 +1,347 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createContext, useContext, useReducer, useEffect } from "react";
4
+ const initialState = {
5
+ config: null,
6
+ conversations: [],
7
+ messages: {},
8
+ users: {},
9
+ typingStatuses: [],
10
+ currentUser: null,
11
+ isConnected: false,
12
+ };
13
+ function chatReducer(state, action) {
14
+ switch (action.type) {
15
+ case "SET_CONFIG":
16
+ return Object.assign(Object.assign({}, state), { config: action.payload });
17
+ case "SET_CONVERSATIONS":
18
+ return Object.assign(Object.assign({}, state), { conversations: action.payload });
19
+ case "ADD_CONVERSATION":
20
+ return Object.assign(Object.assign({}, state), { conversations: [action.payload, ...state.conversations] });
21
+ case "UPDATE_CONVERSATION":
22
+ return Object.assign(Object.assign({}, state), { conversations: state.conversations.map((conv) => (conv.id === action.payload.id ? action.payload : conv)) });
23
+ case "SET_MESSAGES":
24
+ return Object.assign(Object.assign({}, state), { messages: Object.assign(Object.assign({}, state.messages), { [action.payload.conversationId]: action.payload.messages }) });
25
+ case "ADD_MESSAGE":
26
+ const conversationId = action.payload.conversationId;
27
+ return Object.assign(Object.assign({}, state), { messages: Object.assign(Object.assign({}, state.messages), { [conversationId]: [...(state.messages[conversationId] || []), action.payload] }) });
28
+ case "UPDATE_MESSAGE":
29
+ return Object.assign(Object.assign({}, state), { messages: Object.assign(Object.assign({}, state.messages), { [action.payload.conversationId]: (state.messages[action.payload.conversationId] || []).map((msg) => msg.id === action.payload.id ? action.payload : msg) }) });
30
+ case "SET_USERS":
31
+ return Object.assign(Object.assign({}, state), { users: action.payload });
32
+ case "UPDATE_USER":
33
+ return Object.assign(Object.assign({}, state), { users: Object.assign(Object.assign({}, state.users), { [action.payload.id]: action.payload }) });
34
+ case "SET_TYPING":
35
+ return Object.assign(Object.assign({}, state), { typingStatuses: [
36
+ ...state.typingStatuses.filter((t) => !(t.userId === action.payload.userId && t.conversationId === action.payload.conversationId)),
37
+ action.payload,
38
+ ] });
39
+ case "REMOVE_TYPING":
40
+ return Object.assign(Object.assign({}, state), { typingStatuses: state.typingStatuses.filter((t) => !(t.userId === action.payload.userId && t.conversationId === action.payload.conversationId)) });
41
+ case "SET_CONNECTION_STATUS":
42
+ return Object.assign(Object.assign({}, state), { isConnected: action.payload });
43
+ default:
44
+ return state;
45
+ }
46
+ }
47
+ const ChatContext = createContext(null);
48
+ export function useChatContext() {
49
+ const context = useContext(ChatContext);
50
+ if (!context) {
51
+ throw new Error("useChatContext must be used within a ChatProvider");
52
+ }
53
+ return context;
54
+ }
55
+ export function ChatProvider({ children, userId, token, onTokenRefresh, websocketUrl = "demo", // Use "demo" as default to disable WebSocket
56
+ enableWebSocket = false, // Disabled by default for demo
57
+ }) {
58
+ const [state, dispatch] = useReducer(chatReducer, initialState);
59
+ // Initialize config
60
+ useEffect(() => {
61
+ const config = {
62
+ userId,
63
+ token,
64
+ wsUrl: enableWebSocket ? websocketUrl : "demo",
65
+ onTokenRefresh,
66
+ };
67
+ dispatch({ type: "SET_CONFIG", payload: config });
68
+ // Initialize current user
69
+ const currentUser = {
70
+ id: userId,
71
+ name: "You",
72
+ status: "online",
73
+ };
74
+ dispatch({ type: "UPDATE_USER", payload: currentUser });
75
+ }, [userId, token, websocketUrl, onTokenRefresh, enableWebSocket]);
76
+ // Initialize with mock data for demo - MORE CONVERSATIONS
77
+ useEffect(() => {
78
+ if (!state.config)
79
+ return;
80
+ const mockUsers = {
81
+ [userId]: {
82
+ id: userId,
83
+ name: "You",
84
+ status: "online",
85
+ },
86
+ "user-2": {
87
+ id: "user-2",
88
+ name: "Alice Johnson",
89
+ status: "online",
90
+ avatar: "/placeholder.svg?height=40&width=40",
91
+ },
92
+ "user-3": {
93
+ id: "user-3",
94
+ name: "Bob Smith",
95
+ status: "offline",
96
+ avatar: "/placeholder.svg?height=40&width=40",
97
+ lastSeen: new Date(Date.now() - 7200000),
98
+ },
99
+ "user-4": {
100
+ id: "user-4",
101
+ name: "Carol Davis",
102
+ status: "online",
103
+ avatar: "/placeholder.svg?height=40&width=40",
104
+ },
105
+ "user-5": {
106
+ id: "user-5",
107
+ name: "David Wilson",
108
+ status: "away",
109
+ avatar: "/placeholder.svg?height=40&width=40",
110
+ lastSeen: new Date(Date.now() - 1800000),
111
+ },
112
+ "user-6": {
113
+ id: "user-6",
114
+ name: "Emma Brown",
115
+ status: "online",
116
+ avatar: "/placeholder.svg?height=40&width=40",
117
+ },
118
+ "user-7": {
119
+ id: "user-7",
120
+ name: "Frank Miller",
121
+ status: "offline",
122
+ avatar: "/placeholder.svg?height=40&width=40",
123
+ lastSeen: new Date(Date.now() - 86400000),
124
+ },
125
+ "user-8": {
126
+ id: "user-8",
127
+ name: "Grace Lee",
128
+ status: "online",
129
+ avatar: "/placeholder.svg?height=40&width=40",
130
+ },
131
+ "user-9": {
132
+ id: "user-9",
133
+ name: "Henry Taylor",
134
+ status: "away",
135
+ avatar: "/placeholder.svg?height=40&width=40",
136
+ lastSeen: new Date(Date.now() - 3600000),
137
+ },
138
+ "user-10": {
139
+ id: "user-10",
140
+ name: "Ivy Chen",
141
+ status: "online",
142
+ avatar: "/placeholder.svg?height=40&width=40",
143
+ },
144
+ "group-1": {
145
+ id: "group-1",
146
+ name: "Team Project",
147
+ status: "online",
148
+ avatar: "/placeholder.svg?height=40&width=40",
149
+ },
150
+ "group-2": {
151
+ id: "group-2",
152
+ name: "Family Chat",
153
+ status: "online",
154
+ avatar: "/placeholder.svg?height=40&width=40",
155
+ },
156
+ };
157
+ const mockConversations = [
158
+ {
159
+ id: "conv-1",
160
+ participants: [mockUsers["user-2"], mockUsers[userId]],
161
+ unreadCount: 2,
162
+ updatedAt: new Date(Date.now() - 300000), // 5 minutes ago
163
+ type: "direct",
164
+ lastMessage: {
165
+ id: "msg-1",
166
+ conversationId: "conv-1",
167
+ senderId: "user-2",
168
+ content: "Hey there! How are you doing? 😊",
169
+ type: "text",
170
+ timestamp: new Date(Date.now() - 300000),
171
+ status: "delivered",
172
+ },
173
+ },
174
+ {
175
+ id: "conv-2",
176
+ participants: [mockUsers["user-3"], mockUsers[userId]],
177
+ unreadCount: 0,
178
+ updatedAt: new Date(Date.now() - 1800000), // 30 minutes ago
179
+ type: "direct",
180
+ lastMessage: {
181
+ id: "msg-2",
182
+ conversationId: "conv-2",
183
+ senderId: userId,
184
+ content: "Thanks for the help earlier!",
185
+ type: "text",
186
+ timestamp: new Date(Date.now() - 1800000),
187
+ status: "read",
188
+ },
189
+ },
190
+ {
191
+ id: "conv-3",
192
+ participants: [mockUsers["user-4"], mockUsers[userId]],
193
+ unreadCount: 1,
194
+ updatedAt: new Date(Date.now() - 3600000), // 1 hour ago
195
+ type: "direct",
196
+ lastMessage: {
197
+ id: "msg-3",
198
+ conversationId: "conv-3",
199
+ senderId: "user-4",
200
+ content: "Can you review this document?",
201
+ type: "file",
202
+ timestamp: new Date(Date.now() - 3600000),
203
+ status: "delivered",
204
+ },
205
+ },
206
+ {
207
+ id: "conv-4",
208
+ participants: [mockUsers["user-5"], mockUsers[userId]],
209
+ unreadCount: 0,
210
+ updatedAt: new Date(Date.now() - 7200000), // 2 hours ago
211
+ type: "direct",
212
+ lastMessage: {
213
+ id: "msg-4",
214
+ conversationId: "conv-4",
215
+ senderId: userId,
216
+ content: "See you tomorrow!",
217
+ type: "text",
218
+ timestamp: new Date(Date.now() - 7200000),
219
+ status: "read",
220
+ },
221
+ },
222
+ {
223
+ id: "conv-5",
224
+ participants: [mockUsers["user-6"], mockUsers[userId]],
225
+ unreadCount: 3,
226
+ updatedAt: new Date(Date.now() - 10800000), // 3 hours ago
227
+ type: "direct",
228
+ lastMessage: {
229
+ id: "msg-5",
230
+ conversationId: "conv-5",
231
+ senderId: "user-6",
232
+ content: "Check out these photos from the event!",
233
+ type: "image",
234
+ timestamp: new Date(Date.now() - 10800000),
235
+ status: "delivered",
236
+ },
237
+ },
238
+ {
239
+ id: "conv-6",
240
+ participants: [mockUsers["user-7"], mockUsers[userId]],
241
+ unreadCount: 0,
242
+ updatedAt: new Date(Date.now() - 86400000), // 1 day ago
243
+ type: "direct",
244
+ lastMessage: {
245
+ id: "msg-6",
246
+ conversationId: "conv-6",
247
+ senderId: "user-7",
248
+ content: "Happy birthday! 🎉",
249
+ type: "text",
250
+ timestamp: new Date(Date.now() - 86400000),
251
+ status: "read",
252
+ },
253
+ },
254
+ {
255
+ id: "conv-7",
256
+ participants: [mockUsers["user-8"], mockUsers[userId]],
257
+ unreadCount: 0,
258
+ updatedAt: new Date(Date.now() - 172800000), // 2 days ago
259
+ type: "direct",
260
+ lastMessage: {
261
+ id: "msg-7",
262
+ conversationId: "conv-7",
263
+ senderId: userId,
264
+ content: "Thanks for the coffee recommendation!",
265
+ type: "text",
266
+ timestamp: new Date(Date.now() - 172800000),
267
+ status: "read",
268
+ },
269
+ },
270
+ {
271
+ id: "conv-8",
272
+ participants: [mockUsers["user-9"], mockUsers[userId]],
273
+ unreadCount: 1,
274
+ updatedAt: new Date(Date.now() - 259200000), // 3 days ago
275
+ type: "direct",
276
+ lastMessage: {
277
+ id: "msg-8",
278
+ conversationId: "conv-8",
279
+ senderId: "user-9",
280
+ content: "Let's schedule a meeting next week",
281
+ type: "text",
282
+ timestamp: new Date(Date.now() - 259200000),
283
+ status: "delivered",
284
+ },
285
+ },
286
+ {
287
+ id: "conv-9",
288
+ participants: [mockUsers["user-10"], mockUsers[userId]],
289
+ unreadCount: 0,
290
+ updatedAt: new Date(Date.now() - 345600000), // 4 days ago
291
+ type: "direct",
292
+ lastMessage: {
293
+ id: "msg-9",
294
+ conversationId: "conv-9",
295
+ senderId: userId,
296
+ content: "Great presentation today!",
297
+ type: "text",
298
+ timestamp: new Date(Date.now() - 345600000),
299
+ status: "read",
300
+ },
301
+ },
302
+ {
303
+ id: "group-conv-1",
304
+ participants: [mockUsers["group-1"], mockUsers[userId], mockUsers["user-2"], mockUsers["user-4"]],
305
+ unreadCount: 5,
306
+ updatedAt: new Date(Date.now() - 600000), // 10 minutes ago
307
+ type: "group",
308
+ name: "Team Project",
309
+ avatar: "/placeholder.svg?height=40&width=40",
310
+ lastMessage: {
311
+ id: "msg-group-1",
312
+ conversationId: "group-conv-1",
313
+ senderId: "user-4",
314
+ content: "The deadline has been moved to Friday",
315
+ type: "text",
316
+ timestamp: new Date(Date.now() - 600000),
317
+ status: "delivered",
318
+ },
319
+ },
320
+ {
321
+ id: "group-conv-2",
322
+ participants: [mockUsers["group-2"], mockUsers[userId], mockUsers["user-6"], mockUsers["user-8"]],
323
+ unreadCount: 0,
324
+ updatedAt: new Date(Date.now() - 432000000), // 5 days ago
325
+ type: "group",
326
+ name: "Family Chat",
327
+ avatar: "/placeholder.svg?height=40&width=40",
328
+ lastMessage: {
329
+ id: "msg-group-2",
330
+ conversationId: "group-conv-2",
331
+ senderId: "user-6",
332
+ content: "Looking forward to the reunion!",
333
+ type: "text",
334
+ timestamp: new Date(Date.now() - 432000000),
335
+ status: "read",
336
+ },
337
+ },
338
+ ];
339
+ dispatch({ type: "SET_USERS", payload: mockUsers });
340
+ dispatch({ type: "SET_CONVERSATIONS", payload: mockConversations });
341
+ }, [state.config, userId]);
342
+ const value = {
343
+ state,
344
+ dispatch,
345
+ };
346
+ return _jsx(ChatContext.Provider, { value: value, children: children });
347
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@droppii-org/chat-sdk",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Droppii React Chat SDK",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",