simple-support-chat 0.1.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/LICENSE +21 -0
- package/README.md +307 -0
- package/dist/client/index.cjs +771 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +168 -0
- package/dist/client/index.d.ts +168 -0
- package/dist/client/index.js +764 -0
- package/dist/client/index.js.map +1 -0
- package/dist/server/index.cjs +153 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +117 -0
- package/dist/server/index.d.ts +117 -0
- package/dist/server/index.js +149 -0
- package/dist/server/index.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/context.ts","../../src/client/useChatEngine.ts","../../src/client/ChatBubble.tsx","../../src/client/SupportChatModal.tsx","../../src/client/useSupportChat.ts"],"names":["useState","useCallback","useRef","useEffect","jsxs","Fragment","jsx"],"mappings":";;;;;;;;AAEA,IAAM,WAAA,GAAc,yBAAA;AAGpB,SAAS,iBAAA,GAA4B;AACnC,EAAA,MAAM,KAAA,GACJ,gEAAA;AACF,EAAA,IAAI,EAAA,GAAK,EAAA;AACT,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,EAAA,EAAI,CAAA,EAAA,EAAK;AAC3B,IAAA,EAAA,IAAM,KAAA,CAAM,OAAO,IAAA,CAAK,KAAA,CAAM,KAAK,MAAA,EAAO,GAAI,KAAA,CAAM,MAAM,CAAC,CAAA;AAAA,EAC7D;AACA,EAAA,OAAO,EAAA;AACT;AAGO,SAAS,YAAA,GAAuB;AACrC,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,EAAa,OAAO,iBAAA,EAAkB;AAE5D,EAAA,IAAI;AACF,IAAA,MAAM,QAAA,GAAW,YAAA,CAAa,OAAA,CAAQ,WAAW,CAAA;AACjD,IAAA,IAAI,UAAU,OAAO,QAAA;AAErB,IA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;AAE1C,EAAA,MAAM,OAAOC,iBAAAA,CAAY,MAAM,UAAU,IAAI,CAAA,EAAG,EAAE,CAAA;AAClD,EAAA,MAAM,QAAQA,iBAAAA,CAAY,MAAM,UAAU,KAAK,CAAA,EAAG,EAAE,CAAA;AACpD,EAAA,MAAM,MAAA,GAASA,iBAAAA,CAAY,MAAM,SAAA,CAAU,CAAC,SAAS,CAAC,IAAI,CAAA,EAAG,EAAE,CAAA;AAE/D,EAAA,OAAO,EAAE,IAAA,EAAM,KAAA,EAAO,MAAA,EAAQ,MAAA,EAAO;AACvC","file":"index.cjs","sourcesContent":["import type { AnonymousContext } from \"./types\";\r\n\r\nconst SESSION_KEY = \"support-chat-session-id\";\r\n\r\n/** Generate a random session ID */\r\nfunction generateSessionId(): string {\r\n const chars =\r\n \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\r\n let id = \"\";\r\n for (let i = 0; i < 16; i++) {\r\n id += chars.charAt(Math.floor(Math.random() * chars.length));\r\n }\r\n return id;\r\n}\r\n\r\n/** Get or create a persistent session ID from localStorage */\r\nexport function getSessionId(): string {\r\n if (typeof window === \"undefined\") return generateSessionId();\r\n\r\n try {\r\n const existing = localStorage.getItem(SESSION_KEY);\r\n if (existing) return existing;\r\n\r\n const newId = generateSessionId();\r\n localStorage.setItem(SESSION_KEY, newId);\r\n return newId;\r\n } catch {\r\n // localStorage may be blocked (private browsing, etc.)\r\n return generateSessionId();\r\n }\r\n}\r\n\r\n/** Collect anonymous browser context */\r\nexport function collectAnonymousContext(): AnonymousContext {\r\n const sessionId = getSessionId();\r\n\r\n if (typeof window === \"undefined\") {\r\n return {\r\n pageUrl: \"\",\r\n referrer: \"\",\r\n userAgent: \"\",\r\n screenSize: \"\",\r\n timezone: \"\",\r\n sessionId,\r\n };\r\n }\r\n\r\n return {\r\n pageUrl: window.location.href,\r\n referrer: document.referrer,\r\n userAgent: navigator.userAgent,\r\n screenSize: `${window.screen.width}x${window.screen.height}`,\r\n timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,\r\n sessionId,\r\n };\r\n}\r\n","import { useState, useCallback } from \"react\";\r\nimport type { ChatMessage, ChatUser } from \"./types\";\r\nimport { collectAnonymousContext, getSessionId } from \"./context\";\r\n\r\n/** Options for initializing the chat engine */\r\nexport interface ChatEngineOptions {\r\n /** URL of the support chat API endpoint */\r\n apiUrl: string;\r\n /** Authenticated user info (optional) */\r\n user?: ChatUser;\r\n}\r\n\r\n/** Return value from useChatEngine */\r\nexport interface ChatEngineState {\r\n /** All chat messages */\r\n messages: ChatMessage[];\r\n /** Current input value */\r\n input: string;\r\n /** Update the input value */\r\n setInput: (value: string) => void;\r\n /** Whether a message is currently being sent */\r\n sending: boolean;\r\n /** Send the current input as a message */\r\n sendMessage: () => Promise<void>;\r\n /** Handle keydown on the input (Enter to send) */\r\n handleKeyDown: (e: React.KeyboardEvent) => void;\r\n}\r\n\r\n/**\r\n * Shared chat engine hook used by both ChatBubble and SupportChatModal.\r\n * Manages message state, input, and API communication.\r\n */\r\nexport function useChatEngine({\r\n apiUrl,\r\n user,\r\n}: ChatEngineOptions): ChatEngineState {\r\n const [messages, setMessages] = useState<ChatMessage[]>([]);\r\n const [input, setInput] = useState(\"\");\r\n const [sending, setSending] = useState(false);\r\n\r\n const sendMessage = useCallback(async () => {\r\n const text = input.trim();\r\n if (!text || sending) return;\r\n\r\n const msg: ChatMessage = {\r\n id: `msg-${Date.now()}`,\r\n text,\r\n sender: \"user\",\r\n timestamp: Date.now(),\r\n };\r\n\r\n setMessages((prev) => [...prev, msg]);\r\n setInput(\"\");\r\n setSending(true);\r\n\r\n try {\r\n const context = collectAnonymousContext();\r\n const response = await fetch(apiUrl, {\r\n method: \"POST\",\r\n headers: { \"Content-Type\": \"application/json\" },\r\n body: JSON.stringify({\r\n message: text,\r\n user: user ?? undefined,\r\n sessionId: user?.id ?? getSessionId(),\r\n context,\r\n }),\r\n });\r\n\r\n if (!response.ok) {\r\n setMessages((prev) => [\r\n ...prev,\r\n {\r\n id: `err-${Date.now()}`,\r\n text: \"Failed to send message. Please try again.\",\r\n sender: \"system\",\r\n timestamp: Date.now(),\r\n },\r\n ]);\r\n }\r\n } catch {\r\n setMessages((prev) => [\r\n ...prev,\r\n {\r\n id: `err-${Date.now()}`,\r\n text: \"Connection error. Please try again.\",\r\n sender: \"system\",\r\n timestamp: Date.now(),\r\n },\r\n ]);\r\n } finally {\r\n setSending(false);\r\n }\r\n }, [input, sending, apiUrl, user]);\r\n\r\n const handleKeyDown = useCallback(\r\n (e: React.KeyboardEvent) => {\r\n if (e.key === \"Enter\" && !e.shiftKey) {\r\n e.preventDefault();\r\n void sendMessage();\r\n }\r\n },\r\n [sendMessage],\r\n );\r\n\r\n return { messages, input, setInput, sending, sendMessage, handleKeyDown };\r\n}\r\n","import { useState, useCallback, useRef, useEffect } from \"react\";\r\nimport type { ChatBubbleProps } from \"./types\";\r\nimport { useChatEngine } from \"./useChatEngine\";\r\n\r\n/**\r\n * Inject a <style> tag for keyframe animations.\r\n * Called once on first mount. Uses a data-attribute to avoid duplicates.\r\n */\r\nfunction injectKeyframes(): void {\r\n if (typeof document === \"undefined\") return;\r\n if (document.querySelector(\"[data-support-chat-keyframes]\")) return;\r\n\r\n const style = document.createElement(\"style\");\r\n style.setAttribute(\"data-support-chat-keyframes\", \"\");\r\n style.textContent = `\r\n @keyframes sc-slide-in {\r\n from { opacity: 0; transform: translateY(12px) scale(0.96); }\r\n to { opacity: 1; transform: translateY(0) scale(1); }\r\n }\r\n @keyframes sc-slide-out {\r\n from { opacity: 1; transform: translateY(0) scale(1); }\r\n to { opacity: 0; transform: translateY(12px) scale(0.96); }\r\n }\r\n `;\r\n document.head.appendChild(style);\r\n}\r\n\r\n/**\r\n * ChatBubble -- floating support chat widget.\r\n *\r\n * Renders a circular button that opens an inline chat panel.\r\n * Messages are sent via POST to the configured `apiUrl`.\r\n *\r\n * @example\r\n * ```tsx\r\n * <ChatBubble apiUrl=\"/api/support\" />\r\n * ```\r\n */\r\nexport function ChatBubble({\r\n apiUrl,\r\n position = \"bottom-right\",\r\n color = \"#2563eb\",\r\n title = \"Support\",\r\n placeholder = \"Type a message...\",\r\n show = true,\r\n user,\r\n}: ChatBubbleProps) {\r\n const [isOpen, setIsOpen] = useState(false);\r\n\r\n // Use shared chat engine for message logic\r\n const { messages, input, setInput, sending, sendMessage, handleKeyDown } =\r\n useChatEngine({ apiUrl, user });\r\n\r\n // Animation state: \"open\" | \"closing\" | \"closed\"\r\n const [panelState, setPanelState] = useState<\"open\" | \"closing\" | \"closed\">(\r\n \"closed\",\r\n );\r\n\r\n const panelRef = useRef<HTMLDivElement>(null);\r\n const messagesEndRef = useRef<HTMLDivElement>(null);\r\n const inputRef = useRef<HTMLInputElement>(null);\r\n\r\n // Inject keyframe animations on first render\r\n useEffect(() => {\r\n injectKeyframes();\r\n }, []);\r\n\r\n // Sync isOpen -> panelState\r\n useEffect(() => {\r\n if (isOpen) {\r\n setPanelState(\"open\");\r\n } else if (panelState === \"open\") {\r\n // Start closing animation\r\n setPanelState(\"closing\");\r\n }\r\n }, [isOpen]);\r\n\r\n // When closing animation ends, set to fully closed\r\n const handleAnimationEnd = useCallback(() => {\r\n if (panelState === \"closing\") {\r\n setPanelState(\"closed\");\r\n }\r\n }, [panelState]);\r\n\r\n // Focus input when panel opens\r\n useEffect(() => {\r\n if (panelState === \"open\" && inputRef.current) {\r\n inputRef.current.focus();\r\n }\r\n }, [panelState]);\r\n\r\n // Auto-scroll to latest message\r\n useEffect(() => {\r\n messagesEndRef.current?.scrollIntoView({ behavior: \"smooth\" });\r\n }, [messages]);\r\n\r\n // Focus trap: keep Tab cycling inside the dialog when open\r\n useEffect(() => {\r\n if (panelState !== \"open\" || !panelRef.current) return;\r\n\r\n const panel = panelRef.current;\r\n\r\n const handleTrapKeyDown = (e: KeyboardEvent) => {\r\n if (e.key === \"Escape\") {\r\n setIsOpen(false);\r\n return;\r\n }\r\n\r\n if (e.key !== \"Tab\") return;\r\n\r\n const focusable = panel.querySelectorAll<HTMLElement>(\r\n 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])',\r\n );\r\n if (focusable.length === 0) return;\r\n\r\n const first = focusable[0]!;\r\n const last = focusable[focusable.length - 1]!;\r\n\r\n if (e.shiftKey) {\r\n if (document.activeElement === first) {\r\n e.preventDefault();\r\n last.focus();\r\n }\r\n } else {\r\n if (document.activeElement === last) {\r\n e.preventDefault();\r\n first.focus();\r\n }\r\n }\r\n };\r\n\r\n document.addEventListener(\"keydown\", handleTrapKeyDown);\r\n return () => document.removeEventListener(\"keydown\", handleTrapKeyDown);\r\n }, [panelState]);\r\n\r\n const toggle = useCallback(() => setIsOpen((o) => !o), []);\r\n\r\n // Position styles for the bubble button\r\n const positionStyles: React.CSSProperties = {\r\n position: \"fixed\",\r\n zIndex: 99999,\r\n ...(position.includes(\"bottom\") ? { bottom: \"20px\" } : { top: \"20px\" }),\r\n ...(position.includes(\"right\") ? { right: \"20px\" } : { left: \"20px\" }),\r\n };\r\n\r\n // Panel position & responsive sizing\r\n // On mobile (<480px viewport), expand to near-full screen\r\n const panelPositionStyles: React.CSSProperties = {\r\n position: \"fixed\",\r\n zIndex: 99999,\r\n width: \"380px\",\r\n maxWidth: \"calc(100vw - 40px)\",\r\n height: \"500px\",\r\n maxHeight: \"calc(100vh - 120px)\",\r\n ...(position.includes(\"bottom\") ? { bottom: \"80px\" } : { top: \"80px\" }),\r\n ...(position.includes(\"right\") ? { right: \"20px\" } : { left: \"20px\" }),\r\n };\r\n\r\n // Check if panel is visible (open or animating out)\r\n const showPanel = panelState === \"open\" || panelState === \"closing\";\r\n\r\n return (\r\n <>\r\n {/* Responsive overrides injected as inline <style> */}\r\n {showPanel && (\r\n <style>{`\r\n @media (max-width: 479px) {\r\n [data-support-chat-panel] {\r\n width: calc(100vw - 16px) !important;\r\n height: calc(100vh - 100px) !important;\r\n max-width: none !important;\r\n max-height: none !important;\r\n left: 8px !important;\r\n right: 8px !important;\r\n bottom: 72px !important;\r\n border-radius: 12px !important;\r\n }\r\n }\r\n `}</style>\r\n )}\r\n\r\n {/* Floating bubble button */}\r\n {show && (\r\n <button\r\n onClick={toggle}\r\n aria-label={isOpen ? \"Close support chat\" : \"Open support chat\"}\r\n aria-expanded={isOpen}\r\n aria-haspopup=\"dialog\"\r\n style={{\r\n ...positionStyles,\r\n width: \"56px\",\r\n height: \"56px\",\r\n borderRadius: \"50%\",\r\n backgroundColor: color,\r\n border: \"none\",\r\n cursor: \"pointer\",\r\n display: \"flex\",\r\n alignItems: \"center\",\r\n justifyContent: \"center\",\r\n boxShadow: \"0 4px 12px rgba(0,0,0,0.15)\",\r\n transition: \"transform 0.2s ease, box-shadow 0.2s ease\",\r\n }}\r\n onMouseEnter={(e) => {\r\n e.currentTarget.style.transform = \"scale(1.1)\";\r\n e.currentTarget.style.boxShadow = \"0 6px 20px rgba(0,0,0,0.2)\";\r\n }}\r\n onMouseLeave={(e) => {\r\n e.currentTarget.style.transform = \"scale(1)\";\r\n e.currentTarget.style.boxShadow = \"0 4px 12px rgba(0,0,0,0.15)\";\r\n }}\r\n >\r\n <svg\r\n width=\"24\"\r\n height=\"24\"\r\n viewBox=\"0 0 24 24\"\r\n fill=\"none\"\r\n stroke=\"white\"\r\n strokeWidth=\"2\"\r\n strokeLinecap=\"round\"\r\n strokeLinejoin=\"round\"\r\n aria-hidden=\"true\"\r\n >\r\n {isOpen ? (\r\n <path d=\"M18 6L6 18M6 6l12 12\" />\r\n ) : (\r\n <path d=\"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z\" />\r\n )}\r\n </svg>\r\n </button>\r\n )}\r\n\r\n {/* Chat panel */}\r\n {showPanel && (\r\n <div\r\n ref={panelRef}\r\n role=\"dialog\"\r\n aria-label=\"Support chat\"\r\n aria-modal=\"true\"\r\n data-support-chat-panel=\"\"\r\n onAnimationEnd={handleAnimationEnd}\r\n style={{\r\n ...panelPositionStyles,\r\n display: \"flex\",\r\n flexDirection: \"column\",\r\n borderRadius: \"12px\",\r\n overflow: \"hidden\",\r\n boxShadow: \"0 8px 30px rgba(0,0,0,0.12)\",\r\n fontFamily:\r\n '-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif',\r\n fontSize: \"14px\",\r\n backgroundColor: \"#fff\",\r\n border: \"1px solid #e5e7eb\",\r\n animation:\r\n panelState === \"open\"\r\n ? \"sc-slide-in 0.25s ease-out forwards\"\r\n : \"sc-slide-out 0.2s ease-in forwards\",\r\n }}\r\n >\r\n {/* Header */}\r\n <div\r\n style={{\r\n backgroundColor: color,\r\n color: \"#fff\",\r\n padding: \"16px\",\r\n display: \"flex\",\r\n alignItems: \"center\",\r\n justifyContent: \"space-between\",\r\n flexShrink: 0,\r\n }}\r\n >\r\n <span style={{ fontWeight: 600, fontSize: \"16px\" }}>{title}</span>\r\n <button\r\n onClick={() => setIsOpen(false)}\r\n aria-label=\"Close chat\"\r\n style={{\r\n background: \"none\",\r\n border: \"none\",\r\n color: \"#fff\",\r\n cursor: \"pointer\",\r\n padding: \"4px\",\r\n lineHeight: 1,\r\n fontSize: \"18px\",\r\n }}\r\n >\r\n ✕\r\n </button>\r\n </div>\r\n\r\n {/* Messages */}\r\n <div\r\n role=\"log\"\r\n aria-live=\"polite\"\r\n aria-label=\"Chat messages\"\r\n style={{\r\n flex: 1,\r\n overflowY: \"auto\",\r\n padding: \"16px\",\r\n display: \"flex\",\r\n flexDirection: \"column\",\r\n gap: \"8px\",\r\n }}\r\n >\r\n {messages.length === 0 && (\r\n <div\r\n style={{\r\n color: \"#9ca3af\",\r\n textAlign: \"center\",\r\n marginTop: \"40px\",\r\n }}\r\n >\r\n Send us a message and we will get back to you!\r\n </div>\r\n )}\r\n {messages.map((msg) => (\r\n <div\r\n key={msg.id}\r\n style={{\r\n alignSelf:\r\n msg.sender === \"user\" ? \"flex-end\" : \"flex-start\",\r\n maxWidth: \"80%\",\r\n padding: \"10px 14px\",\r\n borderRadius:\r\n msg.sender === \"user\"\r\n ? \"16px 16px 4px 16px\"\r\n : \"16px 16px 16px 4px\",\r\n backgroundColor:\r\n msg.sender === \"user\" ? color : \"#f3f4f6\",\r\n color: msg.sender === \"user\" ? \"#fff\" : \"#1f2937\",\r\n wordBreak: \"break-word\",\r\n }}\r\n >\r\n {msg.text}\r\n </div>\r\n ))}\r\n <div ref={messagesEndRef} />\r\n </div>\r\n\r\n {/* Input */}\r\n <div\r\n style={{\r\n borderTop: \"1px solid #e5e7eb\",\r\n padding: \"12px\",\r\n display: \"flex\",\r\n gap: \"8px\",\r\n flexShrink: 0,\r\n }}\r\n >\r\n <input\r\n ref={inputRef}\r\n type=\"text\"\r\n value={input}\r\n onChange={(e) => setInput(e.target.value)}\r\n onKeyDown={handleKeyDown}\r\n placeholder={placeholder}\r\n aria-label=\"Type your message\"\r\n style={{\r\n flex: 1,\r\n border: \"1px solid #d1d5db\",\r\n borderRadius: \"8px\",\r\n padding: \"10px 12px\",\r\n fontSize: \"14px\",\r\n outline: \"none\",\r\n fontFamily: \"inherit\",\r\n }}\r\n />\r\n <button\r\n onClick={() => void sendMessage()}\r\n disabled={sending || !input.trim()}\r\n aria-label=\"Send message\"\r\n style={{\r\n backgroundColor: color,\r\n color: \"#fff\",\r\n border: \"none\",\r\n borderRadius: \"8px\",\r\n padding: \"10px 16px\",\r\n cursor:\r\n sending || !input.trim() ? \"not-allowed\" : \"pointer\",\r\n opacity: sending || !input.trim() ? 0.5 : 1,\r\n fontWeight: 600,\r\n fontSize: \"14px\",\r\n fontFamily: \"inherit\",\r\n transition: \"opacity 0.2s ease\",\r\n }}\r\n >\r\n Send\r\n </button>\r\n </div>\r\n </div>\r\n )}\r\n </>\r\n );\r\n}\r\n","import { useRef, useEffect, useCallback } from \"react\";\r\nimport type { SupportChatModalProps } from \"./types\";\r\nimport { useChatEngine } from \"./useChatEngine\";\r\n\r\n/**\r\n * Inject a <style> tag for modal keyframe animations.\r\n * Called once on first mount. Uses a data-attribute to avoid duplicates.\r\n */\r\nfunction injectModalKeyframes(): void {\r\n if (typeof document === \"undefined\") return;\r\n if (document.querySelector(\"[data-support-chat-modal-keyframes]\")) return;\r\n\r\n const style = document.createElement(\"style\");\r\n style.setAttribute(\"data-support-chat-modal-keyframes\", \"\");\r\n style.textContent = `\r\n @keyframes sc-modal-backdrop-in {\r\n from { opacity: 0; }\r\n to { opacity: 1; }\r\n }\r\n @keyframes sc-modal-backdrop-out {\r\n from { opacity: 1; }\r\n to { opacity: 0; }\r\n }\r\n @keyframes sc-modal-slide-in {\r\n from { opacity: 0; transform: translateY(20px) scale(0.96); }\r\n to { opacity: 1; transform: translateY(0) scale(1); }\r\n }\r\n @keyframes sc-modal-slide-out {\r\n from { opacity: 1; transform: translateY(0) scale(1); }\r\n to { opacity: 0; transform: translateY(20px) scale(0.96); }\r\n }\r\n `;\r\n document.head.appendChild(style);\r\n}\r\n\r\n/**\r\n * SupportChatModal -- modal-based support chat.\r\n *\r\n * Renders a centered modal dialog for support chat, designed to be\r\n * triggered from custom UI elements (e.g., \"Contact Us\" links).\r\n *\r\n * Desktop: centered modal, max-width ~500px, with backdrop overlay.\r\n * Mobile: full-screen modal.\r\n *\r\n * Use with the `useSupportChat()` hook:\r\n *\r\n * @example\r\n * ```tsx\r\n * import { SupportChatModal, useSupportChat } from 'support-chat';\r\n *\r\n * function App() {\r\n * const { open, close, isOpen } = useSupportChat();\r\n * return (\r\n * <>\r\n * <button onClick={open}>Contact Us</button>\r\n * <SupportChatModal\r\n * apiUrl=\"/api/support\"\r\n * isOpen={isOpen}\r\n * onClose={close}\r\n * />\r\n * </>\r\n * );\r\n * }\r\n * ```\r\n */\r\nexport function SupportChatModal({\r\n apiUrl,\r\n isOpen,\r\n onClose,\r\n color = \"#2563eb\",\r\n title = \"Contact Us\",\r\n placeholder = \"Type a message...\",\r\n user,\r\n}: SupportChatModalProps) {\r\n const { messages, input, setInput, sending, sendMessage, handleKeyDown } =\r\n useChatEngine({ apiUrl, user });\r\n\r\n const modalRef = useRef<HTMLDivElement>(null);\r\n const inputRef = useRef<HTMLInputElement>(null);\r\n const messagesEndRef = useRef<HTMLDivElement>(null);\r\n const closingRef = useRef(false);\r\n const backdropRef = useRef<HTMLDivElement>(null);\r\n\r\n // Inject modal keyframes on first render\r\n useEffect(() => {\r\n injectModalKeyframes();\r\n }, []);\r\n\r\n // Focus input when modal opens\r\n useEffect(() => {\r\n if (isOpen && inputRef.current) {\r\n // Small delay to let the modal render before focusing\r\n const timer = setTimeout(() => inputRef.current?.focus(), 50);\r\n return () => clearTimeout(timer);\r\n }\r\n }, [isOpen]);\r\n\r\n // Auto-scroll to latest message\r\n useEffect(() => {\r\n messagesEndRef.current?.scrollIntoView({ behavior: \"smooth\" });\r\n }, [messages]);\r\n\r\n // Prevent body scroll when modal is open\r\n useEffect(() => {\r\n if (isOpen) {\r\n const prev = document.body.style.overflow;\r\n document.body.style.overflow = \"hidden\";\r\n return () => {\r\n document.body.style.overflow = prev;\r\n };\r\n }\r\n }, [isOpen]);\r\n\r\n // Focus trap and Escape key handling\r\n useEffect(() => {\r\n if (!isOpen || !modalRef.current) return;\r\n\r\n const modal = modalRef.current;\r\n\r\n const handleTrapKeyDown = (e: KeyboardEvent) => {\r\n if (e.key === \"Escape\") {\r\n onClose();\r\n return;\r\n }\r\n\r\n if (e.key !== \"Tab\") return;\r\n\r\n const focusable = modal.querySelectorAll<HTMLElement>(\r\n 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])',\r\n );\r\n if (focusable.length === 0) return;\r\n\r\n const first = focusable[0]!;\r\n const last = focusable[focusable.length - 1]!;\r\n\r\n if (e.shiftKey) {\r\n if (document.activeElement === first) {\r\n e.preventDefault();\r\n last.focus();\r\n }\r\n } else {\r\n if (document.activeElement === last) {\r\n e.preventDefault();\r\n first.focus();\r\n }\r\n }\r\n };\r\n\r\n document.addEventListener(\"keydown\", handleTrapKeyDown);\r\n return () => document.removeEventListener(\"keydown\", handleTrapKeyDown);\r\n }, [isOpen, onClose]);\r\n\r\n // Handle close with animation\r\n const handleClose = useCallback(() => {\r\n closingRef.current = true;\r\n onClose();\r\n }, [onClose]);\r\n\r\n // Handle backdrop click\r\n const handleBackdropClick = useCallback(\r\n (e: React.MouseEvent) => {\r\n if (e.target === e.currentTarget) {\r\n handleClose();\r\n }\r\n },\r\n [handleClose],\r\n );\r\n\r\n if (!isOpen) return null;\r\n\r\n return (\r\n <>\r\n {/* Responsive style for full-screen on mobile */}\r\n <style>{`\r\n @media (max-width: 479px) {\r\n [data-support-chat-modal] {\r\n width: 100vw !important;\r\n height: 100vh !important;\r\n max-width: none !important;\r\n max-height: none !important;\r\n border-radius: 0 !important;\r\n margin: 0 !important;\r\n }\r\n [data-support-chat-modal-backdrop] {\r\n align-items: stretch !important;\r\n justify-content: stretch !important;\r\n }\r\n }\r\n `}</style>\r\n\r\n {/* Backdrop overlay */}\r\n <div\r\n ref={backdropRef}\r\n data-support-chat-modal-backdrop=\"\"\r\n onClick={handleBackdropClick}\r\n style={{\r\n position: \"fixed\",\r\n inset: 0,\r\n zIndex: 100000,\r\n backgroundColor: \"rgba(0, 0, 0, 0.5)\",\r\n display: \"flex\",\r\n alignItems: \"center\",\r\n justifyContent: \"center\",\r\n fontFamily:\r\n '-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif',\r\n fontSize: \"14px\",\r\n animation: \"sc-modal-backdrop-in 0.2s ease-out forwards\",\r\n }}\r\n >\r\n {/* Modal dialog */}\r\n <div\r\n ref={modalRef}\r\n role=\"dialog\"\r\n aria-label=\"Support chat\"\r\n aria-modal=\"true\"\r\n data-support-chat-modal=\"\"\r\n style={{\r\n width: \"500px\",\r\n maxWidth: \"calc(100vw - 32px)\",\r\n height: \"600px\",\r\n maxHeight: \"calc(100vh - 64px)\",\r\n backgroundColor: \"#fff\",\r\n borderRadius: \"16px\",\r\n overflow: \"hidden\",\r\n display: \"flex\",\r\n flexDirection: \"column\",\r\n boxShadow: \"0 20px 60px rgba(0, 0, 0, 0.2)\",\r\n animation: \"sc-modal-slide-in 0.3s ease-out forwards\",\r\n }}\r\n >\r\n {/* Header */}\r\n <div\r\n style={{\r\n backgroundColor: color,\r\n color: \"#fff\",\r\n padding: \"20px 24px\",\r\n display: \"flex\",\r\n alignItems: \"center\",\r\n justifyContent: \"space-between\",\r\n flexShrink: 0,\r\n }}\r\n >\r\n <span style={{ fontWeight: 600, fontSize: \"18px\" }}>{title}</span>\r\n <button\r\n onClick={handleClose}\r\n aria-label=\"Close chat\"\r\n style={{\r\n background: \"none\",\r\n border: \"none\",\r\n color: \"#fff\",\r\n cursor: \"pointer\",\r\n padding: \"4px\",\r\n lineHeight: 1,\r\n fontSize: \"20px\",\r\n }}\r\n >\r\n ✕\r\n </button>\r\n </div>\r\n\r\n {/* Messages */}\r\n <div\r\n role=\"log\"\r\n aria-live=\"polite\"\r\n aria-label=\"Chat messages\"\r\n style={{\r\n flex: 1,\r\n overflowY: \"auto\",\r\n padding: \"20px\",\r\n display: \"flex\",\r\n flexDirection: \"column\",\r\n gap: \"8px\",\r\n }}\r\n >\r\n {messages.length === 0 && (\r\n <div\r\n style={{\r\n color: \"#9ca3af\",\r\n textAlign: \"center\",\r\n marginTop: \"60px\",\r\n }}\r\n >\r\n Send us a message and we will get back to you!\r\n </div>\r\n )}\r\n {messages.map((msg) => (\r\n <div\r\n key={msg.id}\r\n style={{\r\n alignSelf:\r\n msg.sender === \"user\" ? \"flex-end\" : \"flex-start\",\r\n maxWidth: \"80%\",\r\n padding: \"10px 14px\",\r\n borderRadius:\r\n msg.sender === \"user\"\r\n ? \"16px 16px 4px 16px\"\r\n : \"16px 16px 16px 4px\",\r\n backgroundColor:\r\n msg.sender === \"user\" ? color : \"#f3f4f6\",\r\n color: msg.sender === \"user\" ? \"#fff\" : \"#1f2937\",\r\n wordBreak: \"break-word\",\r\n }}\r\n >\r\n {msg.text}\r\n </div>\r\n ))}\r\n <div ref={messagesEndRef} />\r\n </div>\r\n\r\n {/* Input */}\r\n <div\r\n style={{\r\n borderTop: \"1px solid #e5e7eb\",\r\n padding: \"16px 20px\",\r\n display: \"flex\",\r\n gap: \"8px\",\r\n flexShrink: 0,\r\n }}\r\n >\r\n <input\r\n ref={inputRef}\r\n type=\"text\"\r\n value={input}\r\n onChange={(e) => setInput(e.target.value)}\r\n onKeyDown={handleKeyDown}\r\n placeholder={placeholder}\r\n aria-label=\"Type your message\"\r\n style={{\r\n flex: 1,\r\n border: \"1px solid #d1d5db\",\r\n borderRadius: \"8px\",\r\n padding: \"12px 14px\",\r\n fontSize: \"14px\",\r\n outline: \"none\",\r\n fontFamily: \"inherit\",\r\n }}\r\n />\r\n <button\r\n onClick={() => void sendMessage()}\r\n disabled={sending || !input.trim()}\r\n aria-label=\"Send message\"\r\n style={{\r\n backgroundColor: color,\r\n color: \"#fff\",\r\n border: \"none\",\r\n borderRadius: \"8px\",\r\n padding: \"12px 20px\",\r\n cursor:\r\n sending || !input.trim() ? \"not-allowed\" : \"pointer\",\r\n opacity: sending || !input.trim() ? 0.5 : 1,\r\n fontWeight: 600,\r\n fontSize: \"14px\",\r\n fontFamily: \"inherit\",\r\n transition: \"opacity 0.2s ease\",\r\n }}\r\n >\r\n Send\r\n </button>\r\n </div>\r\n </div>\r\n </div>\r\n </>\r\n );\r\n}\r\n","import { useState, useCallback } from \"react\";\r\nimport type { SupportChatState } from \"./types\";\r\n\r\n/**\r\n * Hook that returns controls for opening/closing the support chat.\r\n * Use with `<SupportChatModal />` for modal-triggered chat.\r\n *\r\n * @example\r\n * ```tsx\r\n * const { open, close, toggle, isOpen } = useSupportChat();\r\n * return <button onClick={open}>Contact Us</button>;\r\n * ```\r\n */\r\nexport function useSupportChat(): SupportChatState {\r\n const [isOpen, setIsOpen] = useState(false);\r\n\r\n const open = useCallback(() => setIsOpen(true), []);\r\n const close = useCallback(() => setIsOpen(false), []);\r\n const toggle = useCallback(() => setIsOpen((prev) => !prev), []);\r\n\r\n return { open, close, toggle, isOpen };\r\n}\r\n"]}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
/** User identity passed by the host application */
|
|
4
|
+
interface ChatUser {
|
|
5
|
+
/** Unique user ID from your auth system */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Display name */
|
|
8
|
+
name?: string;
|
|
9
|
+
/** Email address */
|
|
10
|
+
email?: string;
|
|
11
|
+
/** Avatar URL */
|
|
12
|
+
avatar?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Position of the chat bubble on screen */
|
|
15
|
+
type BubblePosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
16
|
+
/** Configuration for the ChatBubble component */
|
|
17
|
+
interface ChatBubbleProps {
|
|
18
|
+
/** URL of the support chat API endpoint (e.g., '/api/support') */
|
|
19
|
+
apiUrl: string;
|
|
20
|
+
/** Position of the floating bubble */
|
|
21
|
+
position?: BubblePosition;
|
|
22
|
+
/** Primary color for the bubble and header */
|
|
23
|
+
color?: string;
|
|
24
|
+
/** Title shown in the chat panel header */
|
|
25
|
+
title?: string;
|
|
26
|
+
/** Placeholder text for the message input */
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
/** Whether to show the floating bubble (set false for modal-only mode) */
|
|
29
|
+
show?: boolean;
|
|
30
|
+
/** Authenticated user info (optional) */
|
|
31
|
+
user?: ChatUser;
|
|
32
|
+
}
|
|
33
|
+
/** A single chat message */
|
|
34
|
+
interface ChatMessage {
|
|
35
|
+
id: string;
|
|
36
|
+
text: string;
|
|
37
|
+
sender: "user" | "system";
|
|
38
|
+
timestamp: number;
|
|
39
|
+
}
|
|
40
|
+
/** State returned by useSupportChat hook */
|
|
41
|
+
interface SupportChatState {
|
|
42
|
+
/** Open the chat panel */
|
|
43
|
+
open: () => void;
|
|
44
|
+
/** Close the chat panel */
|
|
45
|
+
close: () => void;
|
|
46
|
+
/** Toggle the chat panel */
|
|
47
|
+
toggle: () => void;
|
|
48
|
+
/** Whether the chat panel is currently open */
|
|
49
|
+
isOpen: boolean;
|
|
50
|
+
}
|
|
51
|
+
/** Configuration for the SupportChatModal component */
|
|
52
|
+
interface SupportChatModalProps {
|
|
53
|
+
/** URL of the support chat API endpoint (e.g., '/api/support') */
|
|
54
|
+
apiUrl: string;
|
|
55
|
+
/** Whether the modal is open */
|
|
56
|
+
isOpen: boolean;
|
|
57
|
+
/** Callback to close the modal */
|
|
58
|
+
onClose: () => void;
|
|
59
|
+
/** Primary color for the header and user messages */
|
|
60
|
+
color?: string;
|
|
61
|
+
/** Title shown in the modal header */
|
|
62
|
+
title?: string;
|
|
63
|
+
/** Placeholder text for the message input */
|
|
64
|
+
placeholder?: string;
|
|
65
|
+
/** Authenticated user info (optional) */
|
|
66
|
+
user?: ChatUser;
|
|
67
|
+
}
|
|
68
|
+
/** Anonymous context collected automatically from the browser */
|
|
69
|
+
interface AnonymousContext {
|
|
70
|
+
pageUrl: string;
|
|
71
|
+
referrer: string;
|
|
72
|
+
userAgent: string;
|
|
73
|
+
screenSize: string;
|
|
74
|
+
timezone: string;
|
|
75
|
+
sessionId: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* ChatBubble -- floating support chat widget.
|
|
80
|
+
*
|
|
81
|
+
* Renders a circular button that opens an inline chat panel.
|
|
82
|
+
* Messages are sent via POST to the configured `apiUrl`.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```tsx
|
|
86
|
+
* <ChatBubble apiUrl="/api/support" />
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare function ChatBubble({ apiUrl, position, color, title, placeholder, show, user, }: ChatBubbleProps): react_jsx_runtime.JSX.Element;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* SupportChatModal -- modal-based support chat.
|
|
93
|
+
*
|
|
94
|
+
* Renders a centered modal dialog for support chat, designed to be
|
|
95
|
+
* triggered from custom UI elements (e.g., "Contact Us" links).
|
|
96
|
+
*
|
|
97
|
+
* Desktop: centered modal, max-width ~500px, with backdrop overlay.
|
|
98
|
+
* Mobile: full-screen modal.
|
|
99
|
+
*
|
|
100
|
+
* Use with the `useSupportChat()` hook:
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```tsx
|
|
104
|
+
* import { SupportChatModal, useSupportChat } from 'support-chat';
|
|
105
|
+
*
|
|
106
|
+
* function App() {
|
|
107
|
+
* const { open, close, isOpen } = useSupportChat();
|
|
108
|
+
* return (
|
|
109
|
+
* <>
|
|
110
|
+
* <button onClick={open}>Contact Us</button>
|
|
111
|
+
* <SupportChatModal
|
|
112
|
+
* apiUrl="/api/support"
|
|
113
|
+
* isOpen={isOpen}
|
|
114
|
+
* onClose={close}
|
|
115
|
+
* />
|
|
116
|
+
* </>
|
|
117
|
+
* );
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
declare function SupportChatModal({ apiUrl, isOpen, onClose, color, title, placeholder, user, }: SupportChatModalProps): react_jsx_runtime.JSX.Element | null;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Hook that returns controls for opening/closing the support chat.
|
|
125
|
+
* Use with `<SupportChatModal />` for modal-triggered chat.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```tsx
|
|
129
|
+
* const { open, close, toggle, isOpen } = useSupportChat();
|
|
130
|
+
* return <button onClick={open}>Contact Us</button>;
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
declare function useSupportChat(): SupportChatState;
|
|
134
|
+
|
|
135
|
+
/** Options for initializing the chat engine */
|
|
136
|
+
interface ChatEngineOptions {
|
|
137
|
+
/** URL of the support chat API endpoint */
|
|
138
|
+
apiUrl: string;
|
|
139
|
+
/** Authenticated user info (optional) */
|
|
140
|
+
user?: ChatUser;
|
|
141
|
+
}
|
|
142
|
+
/** Return value from useChatEngine */
|
|
143
|
+
interface ChatEngineState {
|
|
144
|
+
/** All chat messages */
|
|
145
|
+
messages: ChatMessage[];
|
|
146
|
+
/** Current input value */
|
|
147
|
+
input: string;
|
|
148
|
+
/** Update the input value */
|
|
149
|
+
setInput: (value: string) => void;
|
|
150
|
+
/** Whether a message is currently being sent */
|
|
151
|
+
sending: boolean;
|
|
152
|
+
/** Send the current input as a message */
|
|
153
|
+
sendMessage: () => Promise<void>;
|
|
154
|
+
/** Handle keydown on the input (Enter to send) */
|
|
155
|
+
handleKeyDown: (e: React.KeyboardEvent) => void;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Shared chat engine hook used by both ChatBubble and SupportChatModal.
|
|
159
|
+
* Manages message state, input, and API communication.
|
|
160
|
+
*/
|
|
161
|
+
declare function useChatEngine({ apiUrl, user, }: ChatEngineOptions): ChatEngineState;
|
|
162
|
+
|
|
163
|
+
/** Get or create a persistent session ID from localStorage */
|
|
164
|
+
declare function getSessionId(): string;
|
|
165
|
+
/** Collect anonymous browser context */
|
|
166
|
+
declare function collectAnonymousContext(): AnonymousContext;
|
|
167
|
+
|
|
168
|
+
export { type AnonymousContext, type BubblePosition, ChatBubble, type ChatBubbleProps, type ChatEngineOptions, type ChatEngineState, type ChatMessage, type ChatUser, SupportChatModal, type SupportChatModalProps, type SupportChatState, collectAnonymousContext, getSessionId, useChatEngine, useSupportChat };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
/** User identity passed by the host application */
|
|
4
|
+
interface ChatUser {
|
|
5
|
+
/** Unique user ID from your auth system */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Display name */
|
|
8
|
+
name?: string;
|
|
9
|
+
/** Email address */
|
|
10
|
+
email?: string;
|
|
11
|
+
/** Avatar URL */
|
|
12
|
+
avatar?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Position of the chat bubble on screen */
|
|
15
|
+
type BubblePosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
16
|
+
/** Configuration for the ChatBubble component */
|
|
17
|
+
interface ChatBubbleProps {
|
|
18
|
+
/** URL of the support chat API endpoint (e.g., '/api/support') */
|
|
19
|
+
apiUrl: string;
|
|
20
|
+
/** Position of the floating bubble */
|
|
21
|
+
position?: BubblePosition;
|
|
22
|
+
/** Primary color for the bubble and header */
|
|
23
|
+
color?: string;
|
|
24
|
+
/** Title shown in the chat panel header */
|
|
25
|
+
title?: string;
|
|
26
|
+
/** Placeholder text for the message input */
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
/** Whether to show the floating bubble (set false for modal-only mode) */
|
|
29
|
+
show?: boolean;
|
|
30
|
+
/** Authenticated user info (optional) */
|
|
31
|
+
user?: ChatUser;
|
|
32
|
+
}
|
|
33
|
+
/** A single chat message */
|
|
34
|
+
interface ChatMessage {
|
|
35
|
+
id: string;
|
|
36
|
+
text: string;
|
|
37
|
+
sender: "user" | "system";
|
|
38
|
+
timestamp: number;
|
|
39
|
+
}
|
|
40
|
+
/** State returned by useSupportChat hook */
|
|
41
|
+
interface SupportChatState {
|
|
42
|
+
/** Open the chat panel */
|
|
43
|
+
open: () => void;
|
|
44
|
+
/** Close the chat panel */
|
|
45
|
+
close: () => void;
|
|
46
|
+
/** Toggle the chat panel */
|
|
47
|
+
toggle: () => void;
|
|
48
|
+
/** Whether the chat panel is currently open */
|
|
49
|
+
isOpen: boolean;
|
|
50
|
+
}
|
|
51
|
+
/** Configuration for the SupportChatModal component */
|
|
52
|
+
interface SupportChatModalProps {
|
|
53
|
+
/** URL of the support chat API endpoint (e.g., '/api/support') */
|
|
54
|
+
apiUrl: string;
|
|
55
|
+
/** Whether the modal is open */
|
|
56
|
+
isOpen: boolean;
|
|
57
|
+
/** Callback to close the modal */
|
|
58
|
+
onClose: () => void;
|
|
59
|
+
/** Primary color for the header and user messages */
|
|
60
|
+
color?: string;
|
|
61
|
+
/** Title shown in the modal header */
|
|
62
|
+
title?: string;
|
|
63
|
+
/** Placeholder text for the message input */
|
|
64
|
+
placeholder?: string;
|
|
65
|
+
/** Authenticated user info (optional) */
|
|
66
|
+
user?: ChatUser;
|
|
67
|
+
}
|
|
68
|
+
/** Anonymous context collected automatically from the browser */
|
|
69
|
+
interface AnonymousContext {
|
|
70
|
+
pageUrl: string;
|
|
71
|
+
referrer: string;
|
|
72
|
+
userAgent: string;
|
|
73
|
+
screenSize: string;
|
|
74
|
+
timezone: string;
|
|
75
|
+
sessionId: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* ChatBubble -- floating support chat widget.
|
|
80
|
+
*
|
|
81
|
+
* Renders a circular button that opens an inline chat panel.
|
|
82
|
+
* Messages are sent via POST to the configured `apiUrl`.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```tsx
|
|
86
|
+
* <ChatBubble apiUrl="/api/support" />
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare function ChatBubble({ apiUrl, position, color, title, placeholder, show, user, }: ChatBubbleProps): react_jsx_runtime.JSX.Element;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* SupportChatModal -- modal-based support chat.
|
|
93
|
+
*
|
|
94
|
+
* Renders a centered modal dialog for support chat, designed to be
|
|
95
|
+
* triggered from custom UI elements (e.g., "Contact Us" links).
|
|
96
|
+
*
|
|
97
|
+
* Desktop: centered modal, max-width ~500px, with backdrop overlay.
|
|
98
|
+
* Mobile: full-screen modal.
|
|
99
|
+
*
|
|
100
|
+
* Use with the `useSupportChat()` hook:
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```tsx
|
|
104
|
+
* import { SupportChatModal, useSupportChat } from 'support-chat';
|
|
105
|
+
*
|
|
106
|
+
* function App() {
|
|
107
|
+
* const { open, close, isOpen } = useSupportChat();
|
|
108
|
+
* return (
|
|
109
|
+
* <>
|
|
110
|
+
* <button onClick={open}>Contact Us</button>
|
|
111
|
+
* <SupportChatModal
|
|
112
|
+
* apiUrl="/api/support"
|
|
113
|
+
* isOpen={isOpen}
|
|
114
|
+
* onClose={close}
|
|
115
|
+
* />
|
|
116
|
+
* </>
|
|
117
|
+
* );
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
declare function SupportChatModal({ apiUrl, isOpen, onClose, color, title, placeholder, user, }: SupportChatModalProps): react_jsx_runtime.JSX.Element | null;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Hook that returns controls for opening/closing the support chat.
|
|
125
|
+
* Use with `<SupportChatModal />` for modal-triggered chat.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```tsx
|
|
129
|
+
* const { open, close, toggle, isOpen } = useSupportChat();
|
|
130
|
+
* return <button onClick={open}>Contact Us</button>;
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
declare function useSupportChat(): SupportChatState;
|
|
134
|
+
|
|
135
|
+
/** Options for initializing the chat engine */
|
|
136
|
+
interface ChatEngineOptions {
|
|
137
|
+
/** URL of the support chat API endpoint */
|
|
138
|
+
apiUrl: string;
|
|
139
|
+
/** Authenticated user info (optional) */
|
|
140
|
+
user?: ChatUser;
|
|
141
|
+
}
|
|
142
|
+
/** Return value from useChatEngine */
|
|
143
|
+
interface ChatEngineState {
|
|
144
|
+
/** All chat messages */
|
|
145
|
+
messages: ChatMessage[];
|
|
146
|
+
/** Current input value */
|
|
147
|
+
input: string;
|
|
148
|
+
/** Update the input value */
|
|
149
|
+
setInput: (value: string) => void;
|
|
150
|
+
/** Whether a message is currently being sent */
|
|
151
|
+
sending: boolean;
|
|
152
|
+
/** Send the current input as a message */
|
|
153
|
+
sendMessage: () => Promise<void>;
|
|
154
|
+
/** Handle keydown on the input (Enter to send) */
|
|
155
|
+
handleKeyDown: (e: React.KeyboardEvent) => void;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Shared chat engine hook used by both ChatBubble and SupportChatModal.
|
|
159
|
+
* Manages message state, input, and API communication.
|
|
160
|
+
*/
|
|
161
|
+
declare function useChatEngine({ apiUrl, user, }: ChatEngineOptions): ChatEngineState;
|
|
162
|
+
|
|
163
|
+
/** Get or create a persistent session ID from localStorage */
|
|
164
|
+
declare function getSessionId(): string;
|
|
165
|
+
/** Collect anonymous browser context */
|
|
166
|
+
declare function collectAnonymousContext(): AnonymousContext;
|
|
167
|
+
|
|
168
|
+
export { type AnonymousContext, type BubblePosition, ChatBubble, type ChatBubbleProps, type ChatEngineOptions, type ChatEngineState, type ChatMessage, type ChatUser, SupportChatModal, type SupportChatModalProps, type SupportChatState, collectAnonymousContext, getSessionId, useChatEngine, useSupportChat };
|