@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,405 @@
|
|
|
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
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
var react = require('react');
|
|
11
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* React Context for Ihooman Chat Widget
|
|
15
|
+
*
|
|
16
|
+
* Provides global access to widget state and controls
|
|
17
|
+
* throughout the React component tree.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Default context value (used when no provider is present)
|
|
21
|
+
*/
|
|
22
|
+
const defaultContextValue = {
|
|
23
|
+
widgetRef: null,
|
|
24
|
+
setWidgetRef: () => {
|
|
25
|
+
console.warn('ChatWidgetProvider not found. Wrap your app with <ChatWidgetProvider>.');
|
|
26
|
+
},
|
|
27
|
+
isReady: false,
|
|
28
|
+
setIsReady: () => { },
|
|
29
|
+
isOpen: false,
|
|
30
|
+
setIsOpen: () => { },
|
|
31
|
+
isConnected: false,
|
|
32
|
+
setIsConnected: () => { },
|
|
33
|
+
messages: [],
|
|
34
|
+
setMessages: () => { },
|
|
35
|
+
unreadCount: 0,
|
|
36
|
+
setUnreadCount: () => { },
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* React Context for the Chat Widget
|
|
40
|
+
*/
|
|
41
|
+
const ChatWidgetContext = react.createContext(defaultContextValue);
|
|
42
|
+
/**
|
|
43
|
+
* Hook to access the ChatWidget context
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
function useChatWidgetContext() {
|
|
47
|
+
return react.useContext(ChatWidgetContext);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Type guard to check if widget is available
|
|
51
|
+
*/
|
|
52
|
+
function isWidgetAvailable(widget) {
|
|
53
|
+
return widget !== null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* ChatWidget React Component
|
|
58
|
+
*
|
|
59
|
+
* A React wrapper for the Ihooman Chat Widget that handles
|
|
60
|
+
* initialization, lifecycle management, and SSR compatibility.
|
|
61
|
+
*
|
|
62
|
+
* @module @ihooman/react-chat
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* ChatWidget Component
|
|
66
|
+
*
|
|
67
|
+
* Renders the Ihooman Chat Widget with React lifecycle management.
|
|
68
|
+
* Supports SSR by deferring initialization to useEffect.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```tsx
|
|
72
|
+
* import { ChatWidget } from '@ihooman/react-chat';
|
|
73
|
+
*
|
|
74
|
+
* function App() {
|
|
75
|
+
* return (
|
|
76
|
+
* <ChatWidget
|
|
77
|
+
* widgetId="wgt_abc123def456"
|
|
78
|
+
* position="bottom-right"
|
|
79
|
+
* onReady={() => console.log('Widget ready!')}
|
|
80
|
+
* />
|
|
81
|
+
* );
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @example With user information
|
|
86
|
+
* ```tsx
|
|
87
|
+
* <ChatWidget
|
|
88
|
+
* widgetId="wgt_abc123def456"
|
|
89
|
+
* user={{ name: 'John Doe', email: 'john@example.com' }}
|
|
90
|
+
* />
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
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, }) {
|
|
94
|
+
const widgetInstanceRef = react.useRef(null);
|
|
95
|
+
const isInitializedRef = react.useRef(false);
|
|
96
|
+
const context = useChatWidgetContext();
|
|
97
|
+
// Memoize callbacks to prevent unnecessary re-initialization
|
|
98
|
+
const handleReady = react.useCallback(() => {
|
|
99
|
+
context.setIsReady(true);
|
|
100
|
+
onReady?.();
|
|
101
|
+
}, [context, onReady]);
|
|
102
|
+
const handleOpen = react.useCallback(() => {
|
|
103
|
+
context.setIsOpen(true);
|
|
104
|
+
onOpen?.();
|
|
105
|
+
}, [context, onOpen]);
|
|
106
|
+
const handleClose = react.useCallback(() => {
|
|
107
|
+
context.setIsOpen(false);
|
|
108
|
+
onClose?.();
|
|
109
|
+
}, [context, onClose]);
|
|
110
|
+
const handleMessage = react.useCallback((message) => {
|
|
111
|
+
// Update messages in context
|
|
112
|
+
if (widgetInstanceRef.current) {
|
|
113
|
+
const state = widgetInstanceRef.current.getState();
|
|
114
|
+
context.setMessages(state.messages);
|
|
115
|
+
context.setUnreadCount(state.unreadCount);
|
|
116
|
+
}
|
|
117
|
+
onMessage?.(message);
|
|
118
|
+
}, [context, onMessage]);
|
|
119
|
+
const handleError = react.useCallback((error) => {
|
|
120
|
+
onError?.(error);
|
|
121
|
+
}, [onError]);
|
|
122
|
+
// Initialize widget on mount (client-side only for SSR compatibility)
|
|
123
|
+
react.useEffect(() => {
|
|
124
|
+
// Skip if already initialized or if we're in SSR
|
|
125
|
+
if (isInitializedRef.current || typeof window === 'undefined') {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
let isMounted = true;
|
|
129
|
+
const initWidget = async () => {
|
|
130
|
+
try {
|
|
131
|
+
// Dynamic import to support SSR
|
|
132
|
+
const { IhoomanChat } = await import('@ihooman/chat-widget');
|
|
133
|
+
if (!isMounted)
|
|
134
|
+
return;
|
|
135
|
+
// Build configuration
|
|
136
|
+
const config = {
|
|
137
|
+
widgetId,
|
|
138
|
+
serverUrl,
|
|
139
|
+
theme,
|
|
140
|
+
position,
|
|
141
|
+
startOpen,
|
|
142
|
+
title,
|
|
143
|
+
subtitle,
|
|
144
|
+
welcomeMessage,
|
|
145
|
+
placeholder,
|
|
146
|
+
primaryColor,
|
|
147
|
+
gradientFrom,
|
|
148
|
+
gradientTo,
|
|
149
|
+
showTimestamps,
|
|
150
|
+
showTypingIndicator,
|
|
151
|
+
enableSounds,
|
|
152
|
+
enableFileUpload,
|
|
153
|
+
persistSession,
|
|
154
|
+
zIndex,
|
|
155
|
+
width,
|
|
156
|
+
height,
|
|
157
|
+
buttonSize,
|
|
158
|
+
borderRadius,
|
|
159
|
+
fontFamily,
|
|
160
|
+
avatarUrl,
|
|
161
|
+
poweredBy,
|
|
162
|
+
onReady: handleReady,
|
|
163
|
+
onOpen: handleOpen,
|
|
164
|
+
onClose: handleClose,
|
|
165
|
+
onMessage: handleMessage,
|
|
166
|
+
onError: handleError,
|
|
167
|
+
};
|
|
168
|
+
// Initialize the widget
|
|
169
|
+
const instance = await IhoomanChat.init(config);
|
|
170
|
+
if (!isMounted) {
|
|
171
|
+
// Component unmounted during initialization, clean up
|
|
172
|
+
instance?.destroy();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (instance) {
|
|
176
|
+
widgetInstanceRef.current = instance;
|
|
177
|
+
context.setWidgetRef(instance);
|
|
178
|
+
isInitializedRef.current = true;
|
|
179
|
+
// Set user info if provided
|
|
180
|
+
if (user) {
|
|
181
|
+
instance.setUser(user);
|
|
182
|
+
}
|
|
183
|
+
// Sync initial state
|
|
184
|
+
const state = instance.getState();
|
|
185
|
+
context.setIsOpen(state.isOpen);
|
|
186
|
+
context.setIsConnected(state.isConnected);
|
|
187
|
+
context.setMessages(state.messages);
|
|
188
|
+
context.setUnreadCount(state.unreadCount);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
console.error('Failed to initialize Ihooman Chat Widget:', error);
|
|
193
|
+
handleError(error);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
initWidget();
|
|
197
|
+
// Cleanup on unmount
|
|
198
|
+
return () => {
|
|
199
|
+
isMounted = false;
|
|
200
|
+
if (widgetInstanceRef.current) {
|
|
201
|
+
widgetInstanceRef.current.destroy();
|
|
202
|
+
widgetInstanceRef.current = null;
|
|
203
|
+
context.setWidgetRef(null);
|
|
204
|
+
context.setIsReady(false);
|
|
205
|
+
context.setIsOpen(false);
|
|
206
|
+
context.setIsConnected(false);
|
|
207
|
+
context.setMessages([]);
|
|
208
|
+
context.setUnreadCount(0);
|
|
209
|
+
isInitializedRef.current = false;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
// Note: We intentionally only run this effect once on mount
|
|
213
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
214
|
+
}, [widgetId]);
|
|
215
|
+
// Update user info when it changes
|
|
216
|
+
react.useEffect(() => {
|
|
217
|
+
if (widgetInstanceRef.current && user) {
|
|
218
|
+
widgetInstanceRef.current.setUser(user);
|
|
219
|
+
}
|
|
220
|
+
}, [user]);
|
|
221
|
+
// This component doesn't render any DOM elements
|
|
222
|
+
// The widget injects its own DOM elements
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Provider component for the Chat Widget context
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```tsx
|
|
231
|
+
* import { ChatWidgetProvider, ChatWidget } from '@ihooman/react-chat';
|
|
232
|
+
*
|
|
233
|
+
* function App() {
|
|
234
|
+
* return (
|
|
235
|
+
* <ChatWidgetProvider>
|
|
236
|
+
* <ChatWidget widgetId="wgt_abc123def456" />
|
|
237
|
+
* <YourApp />
|
|
238
|
+
* </ChatWidgetProvider>
|
|
239
|
+
* );
|
|
240
|
+
* }
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
function ChatWidgetProvider({ children }) {
|
|
244
|
+
const [widgetRef, setWidgetRefState] = react.useState(null);
|
|
245
|
+
const [isReady, setIsReady] = react.useState(false);
|
|
246
|
+
const [isOpen, setIsOpen] = react.useState(false);
|
|
247
|
+
const [isConnected, setIsConnected] = react.useState(false);
|
|
248
|
+
const [messages, setMessages] = react.useState([]);
|
|
249
|
+
const [unreadCount, setUnreadCount] = react.useState(0);
|
|
250
|
+
const setWidgetRef = react.useCallback((widget) => {
|
|
251
|
+
setWidgetRefState(widget);
|
|
252
|
+
}, []);
|
|
253
|
+
const contextValue = react.useMemo(() => ({
|
|
254
|
+
widgetRef,
|
|
255
|
+
setWidgetRef,
|
|
256
|
+
isReady,
|
|
257
|
+
setIsReady,
|
|
258
|
+
isOpen,
|
|
259
|
+
setIsOpen,
|
|
260
|
+
isConnected,
|
|
261
|
+
setIsConnected,
|
|
262
|
+
messages,
|
|
263
|
+
setMessages,
|
|
264
|
+
unreadCount,
|
|
265
|
+
setUnreadCount,
|
|
266
|
+
}), [widgetRef, setWidgetRef, isReady, isOpen, isConnected, messages, unreadCount]);
|
|
267
|
+
return (jsxRuntime.jsx(ChatWidgetContext.Provider, { value: contextValue, children: children }));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* useChatWidget Hook
|
|
272
|
+
*
|
|
273
|
+
* Provides programmatic control over the Ihooman Chat Widget
|
|
274
|
+
* from any component within the ChatWidgetProvider.
|
|
275
|
+
*
|
|
276
|
+
* @module @ihooman/react-chat
|
|
277
|
+
*/
|
|
278
|
+
/**
|
|
279
|
+
* Hook for controlling the Ihooman Chat Widget
|
|
280
|
+
*
|
|
281
|
+
* Must be used within a ChatWidgetProvider. Provides access to
|
|
282
|
+
* widget state and control functions.
|
|
283
|
+
*
|
|
284
|
+
* @returns Object containing widget state and control functions
|
|
285
|
+
*
|
|
286
|
+
* @example Basic usage
|
|
287
|
+
* ```tsx
|
|
288
|
+
* import { useChatWidget } from '@ihooman/react-chat';
|
|
289
|
+
*
|
|
290
|
+
* function SupportButton() {
|
|
291
|
+
* const { open, isReady } = useChatWidget();
|
|
292
|
+
*
|
|
293
|
+
* return (
|
|
294
|
+
* <button onClick={open} disabled={!isReady}>
|
|
295
|
+
* Need Help?
|
|
296
|
+
* </button>
|
|
297
|
+
* );
|
|
298
|
+
* }
|
|
299
|
+
* ```
|
|
300
|
+
*
|
|
301
|
+
* @example Sending messages programmatically
|
|
302
|
+
* ```tsx
|
|
303
|
+
* function QuickActions() {
|
|
304
|
+
* const { sendMessage, isReady } = useChatWidget();
|
|
305
|
+
*
|
|
306
|
+
* const handleOrderHelp = () => {
|
|
307
|
+
* sendMessage('I need help with my order');
|
|
308
|
+
* };
|
|
309
|
+
*
|
|
310
|
+
* return (
|
|
311
|
+
* <button onClick={handleOrderHelp} disabled={!isReady}>
|
|
312
|
+
* Order Help
|
|
313
|
+
* </button>
|
|
314
|
+
* );
|
|
315
|
+
* }
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* @example Accessing widget state
|
|
319
|
+
* ```tsx
|
|
320
|
+
* function ChatStatus() {
|
|
321
|
+
* const { isOpen, isConnected, unreadCount } = useChatWidget();
|
|
322
|
+
*
|
|
323
|
+
* return (
|
|
324
|
+
* <div>
|
|
325
|
+
* <span>Chat: {isOpen ? 'Open' : 'Closed'}</span>
|
|
326
|
+
* <span>Status: {isConnected ? 'Connected' : 'Disconnected'}</span>
|
|
327
|
+
* {unreadCount > 0 && <span>({unreadCount} unread)</span>}
|
|
328
|
+
* </div>
|
|
329
|
+
* );
|
|
330
|
+
* }
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
function useChatWidget() {
|
|
334
|
+
const context = useChatWidgetContext();
|
|
335
|
+
/**
|
|
336
|
+
* Open the chat widget window
|
|
337
|
+
*/
|
|
338
|
+
const open = react.useCallback(() => {
|
|
339
|
+
if (isWidgetAvailable(context.widgetRef)) {
|
|
340
|
+
context.widgetRef.open();
|
|
341
|
+
}
|
|
342
|
+
}, [context.widgetRef]);
|
|
343
|
+
/**
|
|
344
|
+
* Close the chat widget window
|
|
345
|
+
*/
|
|
346
|
+
const close = react.useCallback(() => {
|
|
347
|
+
if (isWidgetAvailable(context.widgetRef)) {
|
|
348
|
+
context.widgetRef.close();
|
|
349
|
+
}
|
|
350
|
+
}, [context.widgetRef]);
|
|
351
|
+
/**
|
|
352
|
+
* Toggle the chat widget window open/closed
|
|
353
|
+
*/
|
|
354
|
+
const toggle = react.useCallback(() => {
|
|
355
|
+
if (isWidgetAvailable(context.widgetRef)) {
|
|
356
|
+
context.widgetRef.toggle();
|
|
357
|
+
}
|
|
358
|
+
}, [context.widgetRef]);
|
|
359
|
+
/**
|
|
360
|
+
* Send a message programmatically
|
|
361
|
+
*/
|
|
362
|
+
const sendMessage = react.useCallback((content) => {
|
|
363
|
+
if (isWidgetAvailable(context.widgetRef)) {
|
|
364
|
+
context.widgetRef.sendMessage(content);
|
|
365
|
+
}
|
|
366
|
+
}, [context.widgetRef]);
|
|
367
|
+
/**
|
|
368
|
+
* Set user information for personalization
|
|
369
|
+
*/
|
|
370
|
+
const setUser = react.useCallback((user) => {
|
|
371
|
+
if (isWidgetAvailable(context.widgetRef)) {
|
|
372
|
+
context.widgetRef.setUser(user);
|
|
373
|
+
}
|
|
374
|
+
}, [context.widgetRef]);
|
|
375
|
+
/**
|
|
376
|
+
* Clear chat history and start a new conversation
|
|
377
|
+
*/
|
|
378
|
+
const clearHistory = react.useCallback(() => {
|
|
379
|
+
if (isWidgetAvailable(context.widgetRef)) {
|
|
380
|
+
context.widgetRef.clearHistory();
|
|
381
|
+
context.setMessages([]);
|
|
382
|
+
context.setUnreadCount(0);
|
|
383
|
+
}
|
|
384
|
+
}, [context]);
|
|
385
|
+
return {
|
|
386
|
+
isOpen: context.isOpen,
|
|
387
|
+
isReady: context.isReady,
|
|
388
|
+
isConnected: context.isConnected,
|
|
389
|
+
open,
|
|
390
|
+
close,
|
|
391
|
+
toggle,
|
|
392
|
+
sendMessage,
|
|
393
|
+
setUser,
|
|
394
|
+
clearHistory,
|
|
395
|
+
messages: context.messages,
|
|
396
|
+
unreadCount: context.unreadCount,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
exports.ChatWidget = ChatWidget;
|
|
401
|
+
exports.ChatWidgetContext = ChatWidgetContext;
|
|
402
|
+
exports.ChatWidgetProvider = ChatWidgetProvider;
|
|
403
|
+
exports.useChatWidget = useChatWidget;
|
|
404
|
+
exports.useChatWidgetContext = useChatWidgetContext;
|
|
405
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/context.tsx","../src/ChatWidget.tsx","../src/ChatWidgetProvider.tsx","../src/useChatWidget.ts"],"sourcesContent":[null,null,null,null],"names":["createContext","useContext","useRef","useCallback","useEffect","useState","useMemo","_jsx"],"mappings":";;;;;;;;;;;;AAAA;;;;;AAKG;AAmCH;;AAEG;AACH,MAAM,mBAAmB,GAA2B;AAClD,IAAA,SAA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F,IAAA,CAAC,EACD,CAAC,OAAO,CAAC,SAAS,CAAC,CACpB;AAED;;AAEG;AACH,IAAA,MAAM,YAAY,GAAGA,iBAAW,CAAC,MAAK;AACpC,QAAA,IAAI,iBAAiB,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;AACxC,YAAA,OAAO,CAAC,SAAS,CAAC,YAAY,EAAE;AAChC,YAAA,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;AACvB,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;;;;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ihooman/react-chat
|
|
3
|
+
*
|
|
4
|
+
* React components and hooks for the Ihooman Chat Widget.
|
|
5
|
+
* Provides native React integration with proper lifecycle management
|
|
6
|
+
* and SSR compatibility.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
* @module @ihooman/react-chat
|
|
10
|
+
*
|
|
11
|
+
* @example Basic usage
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { ChatWidget } from '@ihooman/react-chat';
|
|
14
|
+
*
|
|
15
|
+
* function App() {
|
|
16
|
+
* return (
|
|
17
|
+
* <ChatWidget
|
|
18
|
+
* widgetId="wgt_abc123def456"
|
|
19
|
+
* position="bottom-right"
|
|
20
|
+
* />
|
|
21
|
+
* );
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example With provider and hook
|
|
26
|
+
* ```tsx
|
|
27
|
+
* import { ChatWidgetProvider, ChatWidget, useChatWidget } from '@ihooman/react-chat';
|
|
28
|
+
*
|
|
29
|
+
* function SupportButton() {
|
|
30
|
+
* const { open, isReady } = useChatWidget();
|
|
31
|
+
* return (
|
|
32
|
+
* <button onClick={open} disabled={!isReady}>
|
|
33
|
+
* Need Help?
|
|
34
|
+
* </button>
|
|
35
|
+
* );
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* function App() {
|
|
39
|
+
* return (
|
|
40
|
+
* <ChatWidgetProvider>
|
|
41
|
+
* <ChatWidget widgetId="wgt_abc123def456" />
|
|
42
|
+
* <SupportButton />
|
|
43
|
+
* </ChatWidgetProvider>
|
|
44
|
+
* );
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export { ChatWidget } from './ChatWidget';
|
|
49
|
+
export { ChatWidgetProvider } from './ChatWidgetProvider';
|
|
50
|
+
export { useChatWidget } from './useChatWidget';
|
|
51
|
+
export { ChatWidgetContext, useChatWidgetContext } from './context';
|
|
52
|
+
export type { ChatWidgetProps, UseChatWidgetReturn, ChatWidgetProviderProps, WidgetConfig, UserInfo, Message, WidgetState, WidgetEvent, EventCallback, ThemeConfig, BehaviorConfig, BrandingConfig, IhoomanChatAPI, } from './types';
|
|
53
|
+
export type { ChatWidgetContextValue } from './context';
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAGpE,YAAY,EAEV,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EAEvB,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,GACf,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC"}
|