@ihoomanai/react-chat 2.0.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.
- package/README.md +220 -0
- package/dist/ChatWidget.d.ts +42 -0
- package/dist/ChatWidget.d.ts.map +1 -0
- package/dist/ChatWidgetProvider.d.ts +28 -0
- package/dist/ChatWidgetProvider.d.ts.map +1 -0
- package/dist/context.d.ts +50 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/index.cjs.js +405 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +399 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.esm.min.js +2 -0
- package/dist/index.esm.min.js.map +1 -0
- package/dist/types.d.ts +124 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/useChatWidget.d.ts +67 -0
- package/dist/useChatWidget.d.ts.map +1 -0
- package/package.json +89 -0
- package/src/ChatWidget.tsx +232 -0
- package/src/ChatWidgetProvider.tsx +67 -0
- package/src/context.tsx +79 -0
- package/src/index.ts +79 -0
- package/src/types.ts +175 -0
- package/src/useChatWidget.ts +149 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ihoomanai/react-chat v2.0.0
|
|
3
|
+
* React components and hooks for Ihooman Chat Widget - secure Widget ID based initialization
|
|
4
|
+
*
|
|
5
|
+
* @license MIT
|
|
6
|
+
* @copyright Ihooman AI
|
|
7
|
+
*/
|
|
8
|
+
import { createContext, useContext, useRef, useCallback, useEffect, useState, useMemo } from 'react';
|
|
9
|
+
import { jsx } from 'react/jsx-runtime';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* React Context for Ihooman Chat Widget
|
|
13
|
+
*
|
|
14
|
+
* Provides global access to widget state and controls
|
|
15
|
+
* throughout the React component tree.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Default context value (used when no provider is present)
|
|
19
|
+
*/
|
|
20
|
+
const defaultContextValue = {
|
|
21
|
+
widgetRef: null,
|
|
22
|
+
setWidgetRef: () => {
|
|
23
|
+
console.warn('ChatWidgetProvider not found. Wrap your app with <ChatWidgetProvider>.');
|
|
24
|
+
},
|
|
25
|
+
isReady: false,
|
|
26
|
+
setIsReady: () => { },
|
|
27
|
+
isOpen: false,
|
|
28
|
+
setIsOpen: () => { },
|
|
29
|
+
isConnected: false,
|
|
30
|
+
setIsConnected: () => { },
|
|
31
|
+
messages: [],
|
|
32
|
+
setMessages: () => { },
|
|
33
|
+
unreadCount: 0,
|
|
34
|
+
setUnreadCount: () => { },
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* React Context for the Chat Widget
|
|
38
|
+
*/
|
|
39
|
+
const ChatWidgetContext = createContext(defaultContextValue);
|
|
40
|
+
/**
|
|
41
|
+
* Hook to access the ChatWidget context
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
function useChatWidgetContext() {
|
|
45
|
+
return useContext(ChatWidgetContext);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Type guard to check if widget is available
|
|
49
|
+
*/
|
|
50
|
+
function isWidgetAvailable(widget) {
|
|
51
|
+
return widget !== null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* ChatWidget React Component
|
|
56
|
+
*
|
|
57
|
+
* A React wrapper for the Ihooman Chat Widget that handles
|
|
58
|
+
* initialization, lifecycle management, and SSR compatibility.
|
|
59
|
+
*
|
|
60
|
+
* @module @ihooman/react-chat
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* ChatWidget Component
|
|
64
|
+
*
|
|
65
|
+
* Renders the Ihooman Chat Widget with React lifecycle management.
|
|
66
|
+
* Supports SSR by deferring initialization to useEffect.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```tsx
|
|
70
|
+
* import { ChatWidget } from '@ihooman/react-chat';
|
|
71
|
+
*
|
|
72
|
+
* function App() {
|
|
73
|
+
* return (
|
|
74
|
+
* <ChatWidget
|
|
75
|
+
* widgetId="wgt_abc123def456"
|
|
76
|
+
* position="bottom-right"
|
|
77
|
+
* onReady={() => console.log('Widget ready!')}
|
|
78
|
+
* />
|
|
79
|
+
* );
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @example With user information
|
|
84
|
+
* ```tsx
|
|
85
|
+
* <ChatWidget
|
|
86
|
+
* widgetId="wgt_abc123def456"
|
|
87
|
+
* user={{ name: 'John Doe', email: 'john@example.com' }}
|
|
88
|
+
* />
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
function ChatWidget({ widgetId, serverUrl, theme, position, startOpen, user, title, subtitle, welcomeMessage, placeholder, primaryColor, gradientFrom, gradientTo, showTimestamps, showTypingIndicator, enableSounds, enableFileUpload, persistSession, zIndex, width, height, buttonSize, borderRadius, fontFamily, avatarUrl, poweredBy, onReady, onOpen, onClose, onMessage, onError, }) {
|
|
92
|
+
const widgetInstanceRef = useRef(null);
|
|
93
|
+
const isInitializedRef = useRef(false);
|
|
94
|
+
const context = useChatWidgetContext();
|
|
95
|
+
// Memoize callbacks to prevent unnecessary re-initialization
|
|
96
|
+
const handleReady = useCallback(() => {
|
|
97
|
+
context.setIsReady(true);
|
|
98
|
+
onReady?.();
|
|
99
|
+
}, [context, onReady]);
|
|
100
|
+
const handleOpen = useCallback(() => {
|
|
101
|
+
context.setIsOpen(true);
|
|
102
|
+
onOpen?.();
|
|
103
|
+
}, [context, onOpen]);
|
|
104
|
+
const handleClose = useCallback(() => {
|
|
105
|
+
context.setIsOpen(false);
|
|
106
|
+
onClose?.();
|
|
107
|
+
}, [context, onClose]);
|
|
108
|
+
const handleMessage = useCallback((message) => {
|
|
109
|
+
// Update messages in context
|
|
110
|
+
if (widgetInstanceRef.current) {
|
|
111
|
+
const state = widgetInstanceRef.current.getState();
|
|
112
|
+
context.setMessages(state.messages);
|
|
113
|
+
context.setUnreadCount(state.unreadCount);
|
|
114
|
+
}
|
|
115
|
+
onMessage?.(message);
|
|
116
|
+
}, [context, onMessage]);
|
|
117
|
+
const handleError = useCallback((error) => {
|
|
118
|
+
onError?.(error);
|
|
119
|
+
}, [onError]);
|
|
120
|
+
// Initialize widget on mount (client-side only for SSR compatibility)
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
// Skip if already initialized or if we're in SSR
|
|
123
|
+
if (isInitializedRef.current || typeof window === 'undefined') {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
let isMounted = true;
|
|
127
|
+
const initWidget = async () => {
|
|
128
|
+
try {
|
|
129
|
+
// Dynamic import to support SSR
|
|
130
|
+
const { IhoomanChat } = await import('@ihooman/chat-widget');
|
|
131
|
+
if (!isMounted)
|
|
132
|
+
return;
|
|
133
|
+
// Build configuration
|
|
134
|
+
const config = {
|
|
135
|
+
widgetId,
|
|
136
|
+
serverUrl,
|
|
137
|
+
theme,
|
|
138
|
+
position,
|
|
139
|
+
startOpen,
|
|
140
|
+
title,
|
|
141
|
+
subtitle,
|
|
142
|
+
welcomeMessage,
|
|
143
|
+
placeholder,
|
|
144
|
+
primaryColor,
|
|
145
|
+
gradientFrom,
|
|
146
|
+
gradientTo,
|
|
147
|
+
showTimestamps,
|
|
148
|
+
showTypingIndicator,
|
|
149
|
+
enableSounds,
|
|
150
|
+
enableFileUpload,
|
|
151
|
+
persistSession,
|
|
152
|
+
zIndex,
|
|
153
|
+
width,
|
|
154
|
+
height,
|
|
155
|
+
buttonSize,
|
|
156
|
+
borderRadius,
|
|
157
|
+
fontFamily,
|
|
158
|
+
avatarUrl,
|
|
159
|
+
poweredBy,
|
|
160
|
+
onReady: handleReady,
|
|
161
|
+
onOpen: handleOpen,
|
|
162
|
+
onClose: handleClose,
|
|
163
|
+
onMessage: handleMessage,
|
|
164
|
+
onError: handleError,
|
|
165
|
+
};
|
|
166
|
+
// Initialize the widget
|
|
167
|
+
const instance = await IhoomanChat.init(config);
|
|
168
|
+
if (!isMounted) {
|
|
169
|
+
// Component unmounted during initialization, clean up
|
|
170
|
+
instance?.destroy();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (instance) {
|
|
174
|
+
widgetInstanceRef.current = instance;
|
|
175
|
+
context.setWidgetRef(instance);
|
|
176
|
+
isInitializedRef.current = true;
|
|
177
|
+
// Set user info if provided
|
|
178
|
+
if (user) {
|
|
179
|
+
instance.setUser(user);
|
|
180
|
+
}
|
|
181
|
+
// Sync initial state
|
|
182
|
+
const state = instance.getState();
|
|
183
|
+
context.setIsOpen(state.isOpen);
|
|
184
|
+
context.setIsConnected(state.isConnected);
|
|
185
|
+
context.setMessages(state.messages);
|
|
186
|
+
context.setUnreadCount(state.unreadCount);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
console.error('Failed to initialize Ihooman Chat Widget:', error);
|
|
191
|
+
handleError(error);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
initWidget();
|
|
195
|
+
// Cleanup on unmount
|
|
196
|
+
return () => {
|
|
197
|
+
isMounted = false;
|
|
198
|
+
if (widgetInstanceRef.current) {
|
|
199
|
+
widgetInstanceRef.current.destroy();
|
|
200
|
+
widgetInstanceRef.current = null;
|
|
201
|
+
context.setWidgetRef(null);
|
|
202
|
+
context.setIsReady(false);
|
|
203
|
+
context.setIsOpen(false);
|
|
204
|
+
context.setIsConnected(false);
|
|
205
|
+
context.setMessages([]);
|
|
206
|
+
context.setUnreadCount(0);
|
|
207
|
+
isInitializedRef.current = false;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
// Note: We intentionally only run this effect once on mount
|
|
211
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
212
|
+
}, [widgetId]);
|
|
213
|
+
// Update user info when it changes
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
if (widgetInstanceRef.current && user) {
|
|
216
|
+
widgetInstanceRef.current.setUser(user);
|
|
217
|
+
}
|
|
218
|
+
}, [user]);
|
|
219
|
+
// This component doesn't render any DOM elements
|
|
220
|
+
// The widget injects its own DOM elements
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Provider component for the Chat Widget context
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```tsx
|
|
229
|
+
* import { ChatWidgetProvider, ChatWidget } from '@ihooman/react-chat';
|
|
230
|
+
*
|
|
231
|
+
* function App() {
|
|
232
|
+
* return (
|
|
233
|
+
* <ChatWidgetProvider>
|
|
234
|
+
* <ChatWidget widgetId="wgt_abc123def456" />
|
|
235
|
+
* <YourApp />
|
|
236
|
+
* </ChatWidgetProvider>
|
|
237
|
+
* );
|
|
238
|
+
* }
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
function ChatWidgetProvider({ children }) {
|
|
242
|
+
const [widgetRef, setWidgetRefState] = useState(null);
|
|
243
|
+
const [isReady, setIsReady] = useState(false);
|
|
244
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
245
|
+
const [isConnected, setIsConnected] = useState(false);
|
|
246
|
+
const [messages, setMessages] = useState([]);
|
|
247
|
+
const [unreadCount, setUnreadCount] = useState(0);
|
|
248
|
+
const setWidgetRef = useCallback((widget) => {
|
|
249
|
+
setWidgetRefState(widget);
|
|
250
|
+
}, []);
|
|
251
|
+
const contextValue = useMemo(() => ({
|
|
252
|
+
widgetRef,
|
|
253
|
+
setWidgetRef,
|
|
254
|
+
isReady,
|
|
255
|
+
setIsReady,
|
|
256
|
+
isOpen,
|
|
257
|
+
setIsOpen,
|
|
258
|
+
isConnected,
|
|
259
|
+
setIsConnected,
|
|
260
|
+
messages,
|
|
261
|
+
setMessages,
|
|
262
|
+
unreadCount,
|
|
263
|
+
setUnreadCount,
|
|
264
|
+
}), [widgetRef, setWidgetRef, isReady, isOpen, isConnected, messages, unreadCount]);
|
|
265
|
+
return (jsx(ChatWidgetContext.Provider, { value: contextValue, children: children }));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* useChatWidget Hook
|
|
270
|
+
*
|
|
271
|
+
* Provides programmatic control over the Ihooman Chat Widget
|
|
272
|
+
* from any component within the ChatWidgetProvider.
|
|
273
|
+
*
|
|
274
|
+
* @module @ihooman/react-chat
|
|
275
|
+
*/
|
|
276
|
+
/**
|
|
277
|
+
* Hook for controlling the Ihooman Chat Widget
|
|
278
|
+
*
|
|
279
|
+
* Must be used within a ChatWidgetProvider. Provides access to
|
|
280
|
+
* widget state and control functions.
|
|
281
|
+
*
|
|
282
|
+
* @returns Object containing widget state and control functions
|
|
283
|
+
*
|
|
284
|
+
* @example Basic usage
|
|
285
|
+
* ```tsx
|
|
286
|
+
* import { useChatWidget } from '@ihooman/react-chat';
|
|
287
|
+
*
|
|
288
|
+
* function SupportButton() {
|
|
289
|
+
* const { open, isReady } = useChatWidget();
|
|
290
|
+
*
|
|
291
|
+
* return (
|
|
292
|
+
* <button onClick={open} disabled={!isReady}>
|
|
293
|
+
* Need Help?
|
|
294
|
+
* </button>
|
|
295
|
+
* );
|
|
296
|
+
* }
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* @example Sending messages programmatically
|
|
300
|
+
* ```tsx
|
|
301
|
+
* function QuickActions() {
|
|
302
|
+
* const { sendMessage, isReady } = useChatWidget();
|
|
303
|
+
*
|
|
304
|
+
* const handleOrderHelp = () => {
|
|
305
|
+
* sendMessage('I need help with my order');
|
|
306
|
+
* };
|
|
307
|
+
*
|
|
308
|
+
* return (
|
|
309
|
+
* <button onClick={handleOrderHelp} disabled={!isReady}>
|
|
310
|
+
* Order Help
|
|
311
|
+
* </button>
|
|
312
|
+
* );
|
|
313
|
+
* }
|
|
314
|
+
* ```
|
|
315
|
+
*
|
|
316
|
+
* @example Accessing widget state
|
|
317
|
+
* ```tsx
|
|
318
|
+
* function ChatStatus() {
|
|
319
|
+
* const { isOpen, isConnected, unreadCount } = useChatWidget();
|
|
320
|
+
*
|
|
321
|
+
* return (
|
|
322
|
+
* <div>
|
|
323
|
+
* <span>Chat: {isOpen ? 'Open' : 'Closed'}</span>
|
|
324
|
+
* <span>Status: {isConnected ? 'Connected' : 'Disconnected'}</span>
|
|
325
|
+
* {unreadCount > 0 && <span>({unreadCount} unread)</span>}
|
|
326
|
+
* </div>
|
|
327
|
+
* );
|
|
328
|
+
* }
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
function useChatWidget() {
|
|
332
|
+
const context = useChatWidgetContext();
|
|
333
|
+
/**
|
|
334
|
+
* Open the chat widget window
|
|
335
|
+
*/
|
|
336
|
+
const open = useCallback(() => {
|
|
337
|
+
if (isWidgetAvailable(context.widgetRef)) {
|
|
338
|
+
context.widgetRef.open();
|
|
339
|
+
}
|
|
340
|
+
}, [context.widgetRef]);
|
|
341
|
+
/**
|
|
342
|
+
* Close the chat widget window
|
|
343
|
+
*/
|
|
344
|
+
const close = useCallback(() => {
|
|
345
|
+
if (isWidgetAvailable(context.widgetRef)) {
|
|
346
|
+
context.widgetRef.close();
|
|
347
|
+
}
|
|
348
|
+
}, [context.widgetRef]);
|
|
349
|
+
/**
|
|
350
|
+
* Toggle the chat widget window open/closed
|
|
351
|
+
*/
|
|
352
|
+
const toggle = useCallback(() => {
|
|
353
|
+
if (isWidgetAvailable(context.widgetRef)) {
|
|
354
|
+
context.widgetRef.toggle();
|
|
355
|
+
}
|
|
356
|
+
}, [context.widgetRef]);
|
|
357
|
+
/**
|
|
358
|
+
* Send a message programmatically
|
|
359
|
+
*/
|
|
360
|
+
const sendMessage = useCallback((content) => {
|
|
361
|
+
if (isWidgetAvailable(context.widgetRef)) {
|
|
362
|
+
context.widgetRef.sendMessage(content);
|
|
363
|
+
}
|
|
364
|
+
}, [context.widgetRef]);
|
|
365
|
+
/**
|
|
366
|
+
* Set user information for personalization
|
|
367
|
+
*/
|
|
368
|
+
const setUser = useCallback((user) => {
|
|
369
|
+
if (isWidgetAvailable(context.widgetRef)) {
|
|
370
|
+
context.widgetRef.setUser(user);
|
|
371
|
+
}
|
|
372
|
+
}, [context.widgetRef]);
|
|
373
|
+
/**
|
|
374
|
+
* Clear chat history and start a new conversation
|
|
375
|
+
*/
|
|
376
|
+
const clearHistory = useCallback(() => {
|
|
377
|
+
if (isWidgetAvailable(context.widgetRef)) {
|
|
378
|
+
context.widgetRef.clearHistory();
|
|
379
|
+
context.setMessages([]);
|
|
380
|
+
context.setUnreadCount(0);
|
|
381
|
+
}
|
|
382
|
+
}, [context]);
|
|
383
|
+
return {
|
|
384
|
+
isOpen: context.isOpen,
|
|
385
|
+
isReady: context.isReady,
|
|
386
|
+
isConnected: context.isConnected,
|
|
387
|
+
open,
|
|
388
|
+
close,
|
|
389
|
+
toggle,
|
|
390
|
+
sendMessage,
|
|
391
|
+
setUser,
|
|
392
|
+
clearHistory,
|
|
393
|
+
messages: context.messages,
|
|
394
|
+
unreadCount: context.unreadCount,
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export { ChatWidget, ChatWidgetContext, ChatWidgetProvider, useChatWidget, useChatWidgetContext };
|
|
399
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/context.tsx","../src/ChatWidget.tsx","../src/ChatWidgetProvider.tsx","../src/useChatWidget.ts"],"sourcesContent":[null,null,null,null],"names":["_jsx"],"mappings":";;;;;;;;;;AAAA;;;;;AAKG;AAmCH;;AAEG;AACH,MAAM,mBAAmB,GAA2B;AAClD,IAAA,SAAS,EAAE,IAAI;IACf,YAAY,EAAE,MAAK;AACjB,QAAA,OAAO,CAAC,IAAI,CAAC,wEAAwE,CAAC;IACxF,CAAC;AACD,IAAA,OAAO,EAAE,KAAK;AACd,IAAA,UAAU,EAAE,MAAK,EAAE,CAAC;AACpB,IAAA,MAAM,EAAE,KAAK;AACb,IAAA,SAAS,EAAE,MAAK,EA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B,YAAA,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;QAC3B;AACF,IAAA,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IAEb,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,IAAI;QACJ,KAAK;QACL,MAAM;QACN,WAAW;QACX,OAAO;QACP,YAAY;QACZ,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;KACjC;AACH;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createContext as e,useContext as t,useRef as s,useCallback as n,useEffect as r,useState as o,useMemo as i}from"react";import{jsx as d}from"react/jsx-runtime";const a=e({widgetRef:null,setWidgetRef:()=>{console.warn("ChatWidgetProvider not found. Wrap your app with <ChatWidgetProvider>.")},isReady:!1,setIsReady:()=>{},isOpen:!1,setIsOpen:()=>{},isConnected:!1,setIsConnected:()=>{},messages:[],setMessages:()=>{},unreadCount:0,setUnreadCount:()=>{}});function u(){return t(a)}function g(e){return null!==e}function l({widgetId:e,serverUrl:t,theme:o,position:i,startOpen:d,user:a,title:g,subtitle:l,welcomeMessage:c,placeholder:p,primaryColor:f,gradientFrom:w,gradientTo:R,showTimestamps:m,showTypingIndicator:C,enableSounds:h,enableFileUpload:y,persistSession:I,zIndex:U,width:O,height:M,buttonSize:b,borderRadius:v,fontFamily:S,avatarUrl:W,poweredBy:F,onReady:T,onOpen:z,onClose:x,onMessage:P,onError:B}){const E=s(null),H=s(!1),j=u(),k=n(()=>{j.setIsReady(!0),T?.()},[j,T]),q=n(()=>{j.setIsOpen(!0),z?.()},[j,z]),A=n(()=>{j.setIsOpen(!1),x?.()},[j,x]),D=n(e=>{if(E.current){const e=E.current.getState();j.setMessages(e.messages),j.setUnreadCount(e.unreadCount)}P?.(e)},[j,P]),G=n(e=>{B?.(e)},[B]);return r(()=>{if(H.current||"undefined"==typeof window)return;let s=!0;return(async()=>{try{const{IhoomanChat:n}=await import("@ihooman/chat-widget");if(!s)return;const r={widgetId:e,serverUrl:t,theme:o,position:i,startOpen:d,title:g,subtitle:l,welcomeMessage:c,placeholder:p,primaryColor:f,gradientFrom:w,gradientTo:R,showTimestamps:m,showTypingIndicator:C,enableSounds:h,enableFileUpload:y,persistSession:I,zIndex:U,width:O,height:M,buttonSize:b,borderRadius:v,fontFamily:S,avatarUrl:W,poweredBy:F,onReady:k,onOpen:q,onClose:A,onMessage:D,onError:G},u=await n.init(r);if(!s)return void u?.destroy();if(u){E.current=u,j.setWidgetRef(u),H.current=!0,a&&u.setUser(a);const e=u.getState();j.setIsOpen(e.isOpen),j.setIsConnected(e.isConnected),j.setMessages(e.messages),j.setUnreadCount(e.unreadCount)}}catch(e){console.error("Failed to initialize Ihooman Chat Widget:",e),G(e)}})(),()=>{s=!1,E.current&&(E.current.destroy(),E.current=null,j.setWidgetRef(null),j.setIsReady(!1),j.setIsOpen(!1),j.setIsConnected(!1),j.setMessages([]),j.setUnreadCount(0),H.current=!1)}},[e]),r(()=>{E.current&&a&&E.current.setUser(a)},[a]),null}function c({children:e}){const[t,s]=o(null),[r,u]=o(!1),[g,l]=o(!1),[c,p]=o(!1),[f,w]=o([]),[R,m]=o(0),C=n(e=>{s(e)},[]),h=i(()=>({widgetRef:t,setWidgetRef:C,isReady:r,setIsReady:u,isOpen:g,setIsOpen:l,isConnected:c,setIsConnected:p,messages:f,setMessages:w,unreadCount:R,setUnreadCount:m}),[t,C,r,g,c,f,R]);return d(a.Provider,{value:h,children:e})}function p(){const e=u(),t=n(()=>{g(e.widgetRef)&&e.widgetRef.open()},[e.widgetRef]),s=n(()=>{g(e.widgetRef)&&e.widgetRef.close()},[e.widgetRef]),r=n(()=>{g(e.widgetRef)&&e.widgetRef.toggle()},[e.widgetRef]),o=n(t=>{g(e.widgetRef)&&e.widgetRef.sendMessage(t)},[e.widgetRef]),i=n(t=>{g(e.widgetRef)&&e.widgetRef.setUser(t)},[e.widgetRef]),d=n(()=>{g(e.widgetRef)&&(e.widgetRef.clearHistory(),e.setMessages([]),e.setUnreadCount(0))},[e]);return{isOpen:e.isOpen,isReady:e.isReady,isConnected:e.isConnected,open:t,close:s,toggle:r,sendMessage:o,setUser:i,clearHistory:d,messages:e.messages,unreadCount:e.unreadCount}}export{l as ChatWidget,a as ChatWidgetContext,c as ChatWidgetProvider,p as useChatWidget,u as useChatWidgetContext};
|
|
2
|
+
//# sourceMappingURL=index.esm.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.min.js","sources":["../src/context.tsx","../src/ChatWidget.tsx","../src/ChatWidgetProvider.tsx","../src/useChatWidget.ts"],"sourcesContent":[null,null,null,null],"names":["ChatWidgetContext","createContext","widgetRef","setWidgetRef","console","warn","isReady","setIsReady","isOpen","setIsOpen","isConnected","setIsConnected","messages","setMessages","unreadCount","setUnreadCount","useChatWidgetContext","useContext","isWidgetAvailable","widget","ChatWidget","widgetId","serverUrl","theme","position","startOpen","user","title","subtitle","welcomeMessage","placeholder","primaryColor","gradientFrom","gradientTo","showTimestamps","showTypingIndicator","enableSounds","enableFileUpload","persistSession","zIndex","width","height","buttonSize","borderRadius","fontFamily","avatarUrl","poweredBy","onReady","onOpen","onClose","onMessage","onError","widgetInstanceRef","useRef","isInitializedRef","context","handleReady","useCallback","handleOpen","handleClose","handleMessage","message","current","state","getState","handleError","error","useEffect","window","isMounted","async","IhoomanChat","import","config","instance","init","destroy","setUser","initWidget","ChatWidgetProvider","children","setWidgetRefState","useState","contextValue","useMemo","_jsx","Provider","value","useChatWidget","open","close","toggle","sendMessage","content","clearHistory"],"mappings":"qKA2CA,MAoBaA,EAAoBC,EApBmB,CAClDC,UAAW,KACXC,aAAc,KACZC,QAAQC,KAAK,2EAEfC,SAAS,EACTC,WAAY,OACZC,QAAQ,EACRC,UAAW,OACXC,aAAa,EACbC,eAAgB,OAChBC,SAAU,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**
|
|
2
|
+
* Type definitions for @ihooman/react-chat
|
|
3
|
+
*
|
|
4
|
+
* Re-exports core types from @ihooman/chat-widget and defines
|
|
5
|
+
* React-specific types for components and hooks.
|
|
6
|
+
*/
|
|
7
|
+
export type { WidgetConfig, UserInfo, Message, WidgetState, WidgetEvent, EventCallback, ThemeConfig, BehaviorConfig, BrandingConfig, IhoomanChatAPI, } from '@ihooman/chat-widget';
|
|
8
|
+
/**
|
|
9
|
+
* Props for the ChatWidget React component
|
|
10
|
+
*/
|
|
11
|
+
export interface ChatWidgetProps {
|
|
12
|
+
/**
|
|
13
|
+
* Widget ID for initialization (required)
|
|
14
|
+
* Format: wgt_[12-alphanumeric-characters]
|
|
15
|
+
* Obtain from your Ihooman dashboard
|
|
16
|
+
*/
|
|
17
|
+
widgetId: string;
|
|
18
|
+
/**
|
|
19
|
+
* Server URL for the widget API
|
|
20
|
+
* Defaults to production Ihooman API
|
|
21
|
+
*/
|
|
22
|
+
serverUrl?: string;
|
|
23
|
+
/** Widget color theme */
|
|
24
|
+
theme?: 'light' | 'dark';
|
|
25
|
+
/** Widget position on the page */
|
|
26
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
27
|
+
/** Start with widget open */
|
|
28
|
+
startOpen?: boolean;
|
|
29
|
+
/** User information for personalization */
|
|
30
|
+
user?: {
|
|
31
|
+
name?: string;
|
|
32
|
+
email?: string;
|
|
33
|
+
metadata?: Record<string, string>;
|
|
34
|
+
};
|
|
35
|
+
/** Widget title displayed in header */
|
|
36
|
+
title?: string;
|
|
37
|
+
/** Subtitle displayed in header */
|
|
38
|
+
subtitle?: string;
|
|
39
|
+
/** Welcome message shown when chat opens */
|
|
40
|
+
welcomeMessage?: string;
|
|
41
|
+
/** Placeholder text for input field */
|
|
42
|
+
placeholder?: string;
|
|
43
|
+
/** Primary brand color */
|
|
44
|
+
primaryColor?: string;
|
|
45
|
+
/** Gradient start color */
|
|
46
|
+
gradientFrom?: string;
|
|
47
|
+
/** Gradient end color */
|
|
48
|
+
gradientTo?: string;
|
|
49
|
+
/** Show timestamps on messages */
|
|
50
|
+
showTimestamps?: boolean;
|
|
51
|
+
/** Show typing indicator */
|
|
52
|
+
showTypingIndicator?: boolean;
|
|
53
|
+
/** Enable notification sounds */
|
|
54
|
+
enableSounds?: boolean;
|
|
55
|
+
/** Enable file upload */
|
|
56
|
+
enableFileUpload?: boolean;
|
|
57
|
+
/** Persist session across page reloads */
|
|
58
|
+
persistSession?: boolean;
|
|
59
|
+
/** Z-index for widget positioning */
|
|
60
|
+
zIndex?: number;
|
|
61
|
+
/** Widget width in pixels */
|
|
62
|
+
width?: number;
|
|
63
|
+
/** Widget height in pixels */
|
|
64
|
+
height?: number;
|
|
65
|
+
/** Toggle button size in pixels */
|
|
66
|
+
buttonSize?: number;
|
|
67
|
+
/** Border radius in pixels */
|
|
68
|
+
borderRadius?: number;
|
|
69
|
+
/** Font family */
|
|
70
|
+
fontFamily?: string;
|
|
71
|
+
/** Custom avatar URL */
|
|
72
|
+
avatarUrl?: string;
|
|
73
|
+
/** Show powered by branding */
|
|
74
|
+
poweredBy?: boolean;
|
|
75
|
+
/** Callback when widget is ready */
|
|
76
|
+
onReady?: () => void;
|
|
77
|
+
/** Callback when widget opens */
|
|
78
|
+
onOpen?: () => void;
|
|
79
|
+
/** Callback when widget closes */
|
|
80
|
+
onClose?: () => void;
|
|
81
|
+
/** Callback when a message is sent or received */
|
|
82
|
+
onMessage?: (message: import('@ihooman/chat-widget').Message) => void;
|
|
83
|
+
/** Callback when an error occurs */
|
|
84
|
+
onError?: (error: Error) => void;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Return type for the useChatWidget hook
|
|
88
|
+
*/
|
|
89
|
+
export interface UseChatWidgetReturn {
|
|
90
|
+
/** Whether the widget window is currently open */
|
|
91
|
+
isOpen: boolean;
|
|
92
|
+
/** Whether the widget is initialized and ready */
|
|
93
|
+
isReady: boolean;
|
|
94
|
+
/** Whether connected to the server */
|
|
95
|
+
isConnected: boolean;
|
|
96
|
+
/** Open the chat widget window */
|
|
97
|
+
open: () => void;
|
|
98
|
+
/** Close the chat widget window */
|
|
99
|
+
close: () => void;
|
|
100
|
+
/** Toggle the chat widget window open/closed */
|
|
101
|
+
toggle: () => void;
|
|
102
|
+
/** Send a message programmatically */
|
|
103
|
+
sendMessage: (content: string) => void;
|
|
104
|
+
/** Set user information for personalization */
|
|
105
|
+
setUser: (user: {
|
|
106
|
+
name?: string;
|
|
107
|
+
email?: string;
|
|
108
|
+
metadata?: Record<string, string>;
|
|
109
|
+
}) => void;
|
|
110
|
+
/** Clear chat history and start a new conversation */
|
|
111
|
+
clearHistory: () => void;
|
|
112
|
+
/** Current chat messages */
|
|
113
|
+
messages: import('@ihooman/chat-widget').Message[];
|
|
114
|
+
/** Number of unread messages */
|
|
115
|
+
unreadCount: number;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Props for the ChatWidgetProvider component
|
|
119
|
+
*/
|
|
120
|
+
export interface ChatWidgetProviderProps {
|
|
121
|
+
/** Child components */
|
|
122
|
+
children: React.ReactNode;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EACV,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,GACf,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,yBAAyB;IACzB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAEzB,kCAAkC;IAClC,QAAQ,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C;IAChC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,uBAAuB;IACvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useChatWidget Hook
|
|
3
|
+
*
|
|
4
|
+
* Provides programmatic control over the Ihooman Chat Widget
|
|
5
|
+
* from any component within the ChatWidgetProvider.
|
|
6
|
+
*
|
|
7
|
+
* @module @ihooman/react-chat
|
|
8
|
+
*/
|
|
9
|
+
import type { UseChatWidgetReturn } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Hook for controlling the Ihooman Chat Widget
|
|
12
|
+
*
|
|
13
|
+
* Must be used within a ChatWidgetProvider. Provides access to
|
|
14
|
+
* widget state and control functions.
|
|
15
|
+
*
|
|
16
|
+
* @returns Object containing widget state and control functions
|
|
17
|
+
*
|
|
18
|
+
* @example Basic usage
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { useChatWidget } from '@ihooman/react-chat';
|
|
21
|
+
*
|
|
22
|
+
* function SupportButton() {
|
|
23
|
+
* const { open, isReady } = useChatWidget();
|
|
24
|
+
*
|
|
25
|
+
* return (
|
|
26
|
+
* <button onClick={open} disabled={!isReady}>
|
|
27
|
+
* Need Help?
|
|
28
|
+
* </button>
|
|
29
|
+
* );
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example Sending messages programmatically
|
|
34
|
+
* ```tsx
|
|
35
|
+
* function QuickActions() {
|
|
36
|
+
* const { sendMessage, isReady } = useChatWidget();
|
|
37
|
+
*
|
|
38
|
+
* const handleOrderHelp = () => {
|
|
39
|
+
* sendMessage('I need help with my order');
|
|
40
|
+
* };
|
|
41
|
+
*
|
|
42
|
+
* return (
|
|
43
|
+
* <button onClick={handleOrderHelp} disabled={!isReady}>
|
|
44
|
+
* Order Help
|
|
45
|
+
* </button>
|
|
46
|
+
* );
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example Accessing widget state
|
|
51
|
+
* ```tsx
|
|
52
|
+
* function ChatStatus() {
|
|
53
|
+
* const { isOpen, isConnected, unreadCount } = useChatWidget();
|
|
54
|
+
*
|
|
55
|
+
* return (
|
|
56
|
+
* <div>
|
|
57
|
+
* <span>Chat: {isOpen ? 'Open' : 'Closed'}</span>
|
|
58
|
+
* <span>Status: {isConnected ? 'Connected' : 'Disconnected'}</span>
|
|
59
|
+
* {unreadCount > 0 && <span>({unreadCount} unread)</span>}
|
|
60
|
+
* </div>
|
|
61
|
+
* );
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function useChatWidget(): UseChatWidgetReturn;
|
|
66
|
+
export default useChatWidget;
|
|
67
|
+
//# sourceMappingURL=useChatWidget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChatWidget.d.ts","sourceRoot":"","sources":["../src/useChatWidget.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,aAAa,IAAI,mBAAmB,CA8EnD;AAED,eAAe,aAAa,CAAC"}
|