tchao 0.1.2 → 1.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 +143 -100
- package/dist/npm.d.mts +106 -69
- package/dist/npm.d.ts +106 -69
- package/dist/npm.js +1 -1440
- package/dist/npm.js.map +1 -1
- package/dist/npm.mjs +1 -1440
- package/dist/npm.mjs.map +1 -1
- package/dist/react.d.mts +68 -0
- package/dist/react.d.ts +68 -0
- package/dist/react.js +2 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +2 -0
- package/dist/react.mjs.map +1 -0
- package/package.json +17 -13
package/dist/react.d.mts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { TchaoConfig, VisitorInfo, TchaoEvent, TchaoEventMap } from './npm.mjs';
|
|
2
|
+
export { TchaoInstance, init, tchao } from './npm.mjs';
|
|
3
|
+
|
|
4
|
+
type UseTchaoOptions = TchaoConfig;
|
|
5
|
+
type UseTchaoReturn = {
|
|
6
|
+
/** Whether the widget is ready */
|
|
7
|
+
isReady: boolean;
|
|
8
|
+
/** Whether the widget is currently loading */
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
/** Error if initialization failed */
|
|
11
|
+
error: Error | null;
|
|
12
|
+
/** Show the widget launcher */
|
|
13
|
+
show: () => void;
|
|
14
|
+
/** Hide the widget launcher */
|
|
15
|
+
hide: () => void;
|
|
16
|
+
/** Toggle the chat window */
|
|
17
|
+
toggle: () => void;
|
|
18
|
+
/** Open the chat window with optional pre-filled message */
|
|
19
|
+
open: (message?: string) => void;
|
|
20
|
+
/** Identify the visitor */
|
|
21
|
+
identify: (info: VisitorInfo) => void;
|
|
22
|
+
/** Get current widget configuration */
|
|
23
|
+
config: () => Partial<TchaoConfig>;
|
|
24
|
+
/** Subscribe to widget events */
|
|
25
|
+
on: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;
|
|
26
|
+
/** Unsubscribe from widget events */
|
|
27
|
+
off: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* React hook for using the Tchao chat widget.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* function App() {
|
|
35
|
+
* const { isReady, open, identify } = useTchao({
|
|
36
|
+
* websiteId: "your-website-id",
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* useEffect(() => {
|
|
40
|
+
* if (isReady) {
|
|
41
|
+
* identify({ email: user.email, name: user.name });
|
|
42
|
+
* }
|
|
43
|
+
* }, [isReady, identify]);
|
|
44
|
+
*
|
|
45
|
+
* return <button onClick={() => open()}>Chat with us</button>;
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
declare function useTchao(options: UseTchaoOptions): UseTchaoReturn;
|
|
50
|
+
/**
|
|
51
|
+
* Simple component that initializes Tchao and optionally identifies the user.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* // In your layout or root component
|
|
56
|
+
* <TchaoProvider
|
|
57
|
+
* websiteId="your-website-id"
|
|
58
|
+
* visitor={{ email: user?.email, name: user?.name }}
|
|
59
|
+
* />
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare function TchaoProvider({ visitor, onReady, onError, ...config }: TchaoConfig & {
|
|
63
|
+
visitor?: VisitorInfo;
|
|
64
|
+
onReady?: () => void;
|
|
65
|
+
onError?: (error: Error) => void;
|
|
66
|
+
}): null;
|
|
67
|
+
|
|
68
|
+
export { TchaoConfig, TchaoEvent, TchaoEventMap, TchaoProvider, type UseTchaoOptions, type UseTchaoReturn, VisitorInfo, useTchao };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { TchaoConfig, VisitorInfo, TchaoEvent, TchaoEventMap } from './npm.js';
|
|
2
|
+
export { TchaoInstance, init, tchao } from './npm.js';
|
|
3
|
+
|
|
4
|
+
type UseTchaoOptions = TchaoConfig;
|
|
5
|
+
type UseTchaoReturn = {
|
|
6
|
+
/** Whether the widget is ready */
|
|
7
|
+
isReady: boolean;
|
|
8
|
+
/** Whether the widget is currently loading */
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
/** Error if initialization failed */
|
|
11
|
+
error: Error | null;
|
|
12
|
+
/** Show the widget launcher */
|
|
13
|
+
show: () => void;
|
|
14
|
+
/** Hide the widget launcher */
|
|
15
|
+
hide: () => void;
|
|
16
|
+
/** Toggle the chat window */
|
|
17
|
+
toggle: () => void;
|
|
18
|
+
/** Open the chat window with optional pre-filled message */
|
|
19
|
+
open: (message?: string) => void;
|
|
20
|
+
/** Identify the visitor */
|
|
21
|
+
identify: (info: VisitorInfo) => void;
|
|
22
|
+
/** Get current widget configuration */
|
|
23
|
+
config: () => Partial<TchaoConfig>;
|
|
24
|
+
/** Subscribe to widget events */
|
|
25
|
+
on: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;
|
|
26
|
+
/** Unsubscribe from widget events */
|
|
27
|
+
off: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* React hook for using the Tchao chat widget.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* function App() {
|
|
35
|
+
* const { isReady, open, identify } = useTchao({
|
|
36
|
+
* websiteId: "your-website-id",
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* useEffect(() => {
|
|
40
|
+
* if (isReady) {
|
|
41
|
+
* identify({ email: user.email, name: user.name });
|
|
42
|
+
* }
|
|
43
|
+
* }, [isReady, identify]);
|
|
44
|
+
*
|
|
45
|
+
* return <button onClick={() => open()}>Chat with us</button>;
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
declare function useTchao(options: UseTchaoOptions): UseTchaoReturn;
|
|
50
|
+
/**
|
|
51
|
+
* Simple component that initializes Tchao and optionally identifies the user.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* // In your layout or root component
|
|
56
|
+
* <TchaoProvider
|
|
57
|
+
* websiteId="your-website-id"
|
|
58
|
+
* visitor={{ email: user?.email, name: user?.name }}
|
|
59
|
+
* />
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare function TchaoProvider({ visitor, onReady, onError, ...config }: TchaoConfig & {
|
|
63
|
+
visitor?: VisitorInfo;
|
|
64
|
+
onReady?: () => void;
|
|
65
|
+
onError?: (error: Error) => void;
|
|
66
|
+
}): null;
|
|
67
|
+
|
|
68
|
+
export { TchaoConfig, TchaoEvent, TchaoEventMap, TchaoProvider, type UseTchaoOptions, type UseTchaoReturn, VisitorInfo, useTchao };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var E=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var W=(e,o)=>{for(var i in o)E(e,i,{get:o[i],enumerable:!0})},O=(e,o,i,c)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of S(o))!V.call(e,t)&&t!==i&&E(e,t,{get:()=>o[t],enumerable:!(c=P(o,t))||c.enumerable});return e};var L=e=>O(E({},"__esModule",{value:!0}),e);var Q={};W(Q,{TchaoProvider:()=>H,init:()=>v,tchao:()=>s,useTchao:()=>m});module.exports=L(Q);var n=require("react");var U="https://tchao.app/widget.js",T=!1,f=null,w=!1,h=null,r=[];function q(){for(;r.length>0;){let e=r.shift();if(!(!e||!window.Tchao))try{switch(e.type){case"show":window.Tchao.show();break;case"hide":window.Tchao.hide();break;case"toggle":window.Tchao.toggle();break;case"open":window.Tchao.open(e.message);break;case"identify":window.Tchao.identify(e.info);break;case"on":window.Tchao.on(e.event,e.callback);break;case"off":window.Tchao.off(e.event,e.callback);break}}catch{}}}async function F(e){return f||(f=new Promise((o,i)=>{if(T&&window.Tchao){o();return}if(document.querySelector("script[data-tchao-widget]")){T=!0,o();return}window.__TCHAO_CONFIG__=e;let t=document.createElement("script");t.src=e.host?`${e.host}/widget.js`:U,t.async=!0,t.dataset.websiteId=e.websiteId,t.dataset.tchaoWidget="true",t.onload=()=>{T=!0,o()},t.onerror=()=>{i(new Error("Failed to load Tchao widget script"))},document.head.appendChild(t)}),f)}async function N(){return new Promise((e,o)=>{let i=0,c=()=>{window.Tchao?e():i>=50?o(new Error("Tchao widget failed to initialize")):(i++,setTimeout(c,100))};c()})}async function v(e){if(!e.websiteId)throw new Error("websiteId is required");if(w&&window.Tchao&&h)return h;if(await F(e),await N(),!window.Tchao)throw new Error("Tchao widget failed to initialize");return w=!0,h=G(),q(),h}function G(){return{show:()=>{try{window.Tchao?.show()}catch{}},hide:()=>{try{window.Tchao?.hide()}catch{}},toggle:()=>{try{window.Tchao?.toggle()}catch{}},open:e=>{try{window.Tchao?.open(e)}catch{}},identify:e=>{try{window.Tchao?.identify(e)}catch{}},config:()=>{try{return window.Tchao?.config()??{}}catch{return{}}},on:(e,o)=>{try{window.Tchao?.on(e,o)}catch{}},off:(e,o)=>{try{window.Tchao?.off(e,o)}catch{}},isReady:()=>w&&!!window.Tchao,destroy:()=>{try{let e=document.querySelector("script[data-tchao-widget]");e&&e.remove();let o=document.getElementById("tchao-widget-root");o&&o.remove(),T=!1,f=null,w=!1,h=null,r.length=0,delete window.__TCHAO_CONFIG__,delete window.Tchao}catch{}}}}function d(e,o){try{return e()}catch{return o}}var s={init:v,show:()=>{window.Tchao?d(()=>window.Tchao?.show(),void 0):r.push({type:"show"})},hide:()=>{window.Tchao?d(()=>window.Tchao?.hide(),void 0):r.push({type:"hide"})},toggle:()=>{window.Tchao?d(()=>window.Tchao?.toggle(),void 0):r.push({type:"toggle"})},open:e=>{window.Tchao?d(()=>window.Tchao?.open(e),void 0):r.push({type:"open",message:e})},identify:e=>{window.Tchao?d(()=>window.Tchao?.identify(e),void 0):r.push({type:"identify",info:e})},config:()=>d(()=>window.Tchao?.config()??{},{}),on:(e,o)=>{window.Tchao?d(()=>window.Tchao?.on(e,o),void 0):r.push({type:"on",event:e,callback:o})},off:(e,o)=>{window.Tchao?d(()=>window.Tchao?.off(e,o),void 0):r.push({type:"off",event:e,callback:o})},destroy:()=>{h&&h.destroy()},isReady:()=>w&&!!window.Tchao,getInstance:()=>h};function m(e){let[o,i]=(0,n.useState)(!1),[c,t]=(0,n.useState)(!0),[l,g]=(0,n.useState)(null),u=(0,n.useRef)(null),p=(0,n.useRef)(!0);(0,n.useEffect)(()=>(p.current=!0,v(e).then(a=>{p.current&&(u.current=a,i(!0),t(!1))}).catch(a=>{p.current&&(g(a instanceof Error?a:new Error(String(a))),t(!1))}),()=>{p.current=!1,u.current&&(u.current.destroy(),u.current=null)}),[e.websiteId]);let b=(0,n.useCallback)(()=>s.show(),[]),I=(0,n.useCallback)(()=>s.hide(),[]),k=(0,n.useCallback)(()=>s.toggle(),[]),x=(0,n.useCallback)(a=>s.open(a),[]),C=(0,n.useCallback)(a=>s.identify(a),[]),M=(0,n.useCallback)(()=>s.config(),[]),_=(0,n.useCallback)((a,y)=>s.on(a,y),[]),R=(0,n.useCallback)((a,y)=>s.off(a,y),[]);return{isReady:o,isLoading:c,error:l,show:b,hide:I,toggle:k,open:x,identify:C,config:M,on:_,off:R}}function H({visitor:e,onReady:o,onError:i,...c}){let{isReady:t,error:l,identify:g}=m(c);return(0,n.useEffect)(()=>{t&&e&&g(e)},[t,e,g]),(0,n.useEffect)(()=>{t&&o&&o()},[t,o]),(0,n.useEffect)(()=>{l&&i&&i(l)},[l,i]),null}0&&(module.exports={TchaoProvider,init,tchao,useTchao});
|
|
2
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/widget/react.ts","../../../src/widget/npm.ts"],"sourcesContent":["import { useEffect, useRef, useState, useCallback } from \"react\";\nimport {\n tchao,\n init,\n type TchaoConfig,\n type TchaoInstance,\n type VisitorInfo,\n type TchaoEvent,\n type TchaoEventMap,\n} from \"./npm\";\n\nexport type { TchaoConfig, TchaoInstance, VisitorInfo, TchaoEvent, TchaoEventMap };\n\nexport type UseTchaoOptions = TchaoConfig;\n\nexport type UseTchaoReturn = {\n /** Whether the widget is ready */\n isReady: boolean;\n /** Whether the widget is currently loading */\n isLoading: boolean;\n /** Error if initialization failed */\n error: Error | null;\n /** Show the widget launcher */\n show: () => void;\n /** Hide the widget launcher */\n hide: () => void;\n /** Toggle the chat window */\n toggle: () => void;\n /** Open the chat window with optional pre-filled message */\n open: (message?: string) => void;\n /** Identify the visitor */\n identify: (info: VisitorInfo) => void;\n /** Get current widget configuration */\n config: () => Partial<TchaoConfig>;\n /** Subscribe to widget events */\n on: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;\n /** Unsubscribe from widget events */\n off: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;\n};\n\n/**\n * React hook for using the Tchao chat widget.\n *\n * @example\n * ```tsx\n * function App() {\n * const { isReady, open, identify } = useTchao({\n * websiteId: \"your-website-id\",\n * });\n *\n * useEffect(() => {\n * if (isReady) {\n * identify({ email: user.email, name: user.name });\n * }\n * }, [isReady, identify]);\n *\n * return <button onClick={() => open()}>Chat with us</button>;\n * }\n * ```\n */\nexport function useTchao(options: UseTchaoOptions): UseTchaoReturn {\n const [isReady, setIsReady] = useState(false);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const instanceRef = useRef<TchaoInstance | null>(null);\n const mountedRef = useRef(true);\n\n useEffect(() => {\n mountedRef.current = true;\n\n init(options)\n .then((instance) => {\n if (!mountedRef.current) return;\n instanceRef.current = instance;\n setIsReady(true);\n setIsLoading(false);\n })\n .catch((err) => {\n if (!mountedRef.current) return;\n setError(err instanceof Error ? err : new Error(String(err)));\n setIsLoading(false);\n });\n\n return () => {\n mountedRef.current = false;\n if (instanceRef.current) {\n instanceRef.current.destroy();\n instanceRef.current = null;\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- Only re-init when websiteId changes\n }, [options.websiteId]);\n\n const show = useCallback(() => tchao.show(), []);\n const hide = useCallback(() => tchao.hide(), []);\n const toggle = useCallback(() => tchao.toggle(), []);\n const open = useCallback((message?: string) => tchao.open(message), []);\n const identify = useCallback((info: VisitorInfo) => tchao.identify(info), []);\n const config = useCallback(() => tchao.config(), []);\n const on = useCallback(\n <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) =>\n tchao.on(event, callback),\n []\n );\n const off = useCallback(\n <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) =>\n tchao.off(event, callback),\n []\n );\n\n return {\n isReady,\n isLoading,\n error,\n show,\n hide,\n toggle,\n open,\n identify,\n config,\n on,\n off,\n };\n}\n\n/**\n * Simple component that initializes Tchao and optionally identifies the user.\n *\n * @example\n * ```tsx\n * // In your layout or root component\n * <TchaoProvider\n * websiteId=\"your-website-id\"\n * visitor={{ email: user?.email, name: user?.name }}\n * />\n * ```\n */\nexport function TchaoProvider({\n visitor,\n onReady,\n onError,\n ...config\n}: TchaoConfig & {\n visitor?: VisitorInfo;\n onReady?: () => void;\n onError?: (error: Error) => void;\n}): null {\n const { isReady, error, identify } = useTchao(config);\n\n useEffect(() => {\n if (isReady && visitor) {\n identify(visitor);\n }\n }, [isReady, visitor, identify]);\n\n useEffect(() => {\n if (isReady && onReady) {\n onReady();\n }\n }, [isReady, onReady]);\n\n useEffect(() => {\n if (error && onError) {\n onError(error);\n }\n }, [error, onError]);\n\n return null;\n}\n\nexport { tchao, init };\n","export type VisitorInfo = {\n name?: string;\n email?: string;\n avatar?: string;\n metadata?: Record<string, unknown>;\n};\n\nexport type WidgetConfig = {\n websiteId: string;\n position?: \"bottom-right\" | \"bottom-left\";\n primaryColor?: string;\n widgetStyle?: \"bubble\" | \"name_line\" | \"question_cta\";\n themeMode?: \"light\" | \"dark\" | \"system\";\n agentName?: string;\n agentRole?: string;\n agentImage?: string;\n agentWelcomeMessage?: string;\n hidePoweredBy?: boolean;\n bubbleIcon?: string;\n};\n\nexport type TchaoConfig = {\n websiteId: string;\n host?: string;\n convexUrl?: string;\n position?: \"bottom-right\" | \"bottom-left\";\n primaryColor?: string;\n widgetStyle?: \"bubble\" | \"name_line\" | \"question_cta\";\n themeMode?: \"light\" | \"dark\" | \"system\";\n agentName?: string;\n agentRole?: string;\n agentImage?: string;\n agentWelcomeMessage?: string;\n hidePoweredBy?: boolean;\n bubbleIcon?: string;\n};\n\nexport type Message = {\n content: string;\n sender: string;\n timestamp: number;\n};\n\nexport type TchaoEventMap = {\n message: (message: Message) => void;\n open: () => void;\n close: () => void;\n ready: () => void;\n};\n\nexport type TchaoEvent = keyof TchaoEventMap;\n\nexport type TchaoInstance = {\n show: () => void;\n hide: () => void;\n toggle: () => void;\n open: (message?: string) => void;\n identify: (info: VisitorInfo) => void;\n config: () => Partial<WidgetConfig>;\n on: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;\n off: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;\n destroy: () => void;\n isReady: () => boolean;\n};\n\ntype InternalTchaoInstance = {\n show: () => void;\n hide: () => void;\n toggle: () => void;\n open: (message?: string) => void;\n identify: (info: VisitorInfo) => void;\n config: () => Partial<WidgetConfig>;\n on: (event: string, callback: (...args: unknown[]) => void) => void;\n off: (event: string, callback: (...args: unknown[]) => void) => void;\n};\n\ndeclare global {\n interface Window {\n Tchao?: InternalTchaoInstance;\n __TCHAO_CONFIG__?: TchaoConfig;\n }\n}\n\nconst WIDGET_SCRIPT_URL = \"https://tchao.app/widget.js\";\n\nlet scriptLoaded = false;\nlet scriptPromise: Promise<void> | null = null;\nlet initialized = false;\nlet currentInstance: TchaoInstance | null = null;\n\ntype QueuedCall =\n | { type: \"show\" }\n | { type: \"hide\" }\n | { type: \"toggle\" }\n | { type: \"open\"; message?: string }\n | { type: \"identify\"; info: VisitorInfo }\n | { type: \"on\"; event: string; callback: (...args: unknown[]) => void }\n | { type: \"off\"; event: string; callback: (...args: unknown[]) => void };\n\nconst callQueue: QueuedCall[] = [];\n\nfunction flushQueue(): void {\n while (callQueue.length > 0) {\n const call = callQueue.shift();\n if (!call || !window.Tchao) continue;\n\n try {\n switch (call.type) {\n case \"show\":\n window.Tchao.show();\n break;\n case \"hide\":\n window.Tchao.hide();\n break;\n case \"toggle\":\n window.Tchao.toggle();\n break;\n case \"open\":\n window.Tchao.open(call.message);\n break;\n case \"identify\":\n window.Tchao.identify(call.info);\n break;\n case \"on\":\n window.Tchao.on(call.event, call.callback);\n break;\n case \"off\":\n window.Tchao.off(call.event, call.callback);\n break;\n }\n } catch {\n // Silent fail\n }\n }\n}\n\nasync function loadScript(config: TchaoConfig): Promise<void> {\n if (scriptPromise) return scriptPromise;\n\n scriptPromise = new Promise((resolve, reject) => {\n if (scriptLoaded && window.Tchao) {\n resolve();\n return;\n }\n\n const existingScript = document.querySelector(\n 'script[data-tchao-widget]'\n ) as HTMLScriptElement | null;\n\n if (existingScript) {\n scriptLoaded = true;\n resolve();\n return;\n }\n\n window.__TCHAO_CONFIG__ = config;\n\n const script = document.createElement(\"script\");\n script.src = config.host ? `${config.host}/widget.js` : WIDGET_SCRIPT_URL;\n script.async = true;\n script.dataset.websiteId = config.websiteId;\n script.dataset.tchaoWidget = \"true\";\n\n script.onload = () => {\n scriptLoaded = true;\n resolve();\n };\n\n script.onerror = () => {\n reject(new Error(\"Failed to load Tchao widget script\"));\n };\n\n document.head.appendChild(script);\n });\n\n return scriptPromise;\n}\n\nasync function waitForTchao(): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n const check = () => {\n if (window.Tchao) {\n resolve();\n } else if (attempts >= 50) {\n reject(new Error(\"Tchao widget failed to initialize\"));\n } else {\n attempts++;\n setTimeout(check, 100);\n }\n };\n check();\n });\n}\n\nasync function init(config: TchaoConfig): Promise<TchaoInstance> {\n if (!config.websiteId) {\n throw new Error(\"websiteId is required\");\n }\n\n if (initialized && window.Tchao && currentInstance) {\n return currentInstance;\n }\n\n await loadScript(config);\n await waitForTchao();\n\n if (!window.Tchao) {\n throw new Error(\"Tchao widget failed to initialize\");\n }\n\n initialized = true;\n currentInstance = createInstance();\n flushQueue();\n return currentInstance;\n}\n\nfunction createInstance(): TchaoInstance {\n return {\n show: () => {\n try {\n window.Tchao?.show();\n } catch {\n // Silent fail\n }\n },\n hide: () => {\n try {\n window.Tchao?.hide();\n } catch {\n // Silent fail\n }\n },\n toggle: () => {\n try {\n window.Tchao?.toggle();\n } catch {\n // Silent fail\n }\n },\n open: (message?: string) => {\n try {\n window.Tchao?.open(message);\n } catch {\n // Silent fail\n }\n },\n identify: (info: VisitorInfo) => {\n try {\n window.Tchao?.identify(info);\n } catch {\n // Silent fail\n }\n },\n config: () => {\n try {\n return window.Tchao?.config() ?? {};\n } catch {\n return {};\n }\n },\n on: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => {\n try {\n window.Tchao?.on(event, callback as (...args: unknown[]) => void);\n } catch {\n // Silent fail\n }\n },\n off: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => {\n try {\n window.Tchao?.off(event, callback as (...args: unknown[]) => void);\n } catch {\n // Silent fail\n }\n },\n isReady: () => initialized && !!window.Tchao,\n destroy: () => {\n try {\n const script = document.querySelector('script[data-tchao-widget]');\n if (script) script.remove();\n const widget = document.getElementById(\"tchao-widget-root\");\n if (widget) widget.remove();\n scriptLoaded = false;\n scriptPromise = null;\n initialized = false;\n currentInstance = null;\n callQueue.length = 0;\n delete window.__TCHAO_CONFIG__;\n delete window.Tchao;\n } catch {\n // Silent fail\n }\n },\n };\n}\n\nfunction safeCall<T>(fn: () => T, fallback: T): T {\n try {\n return fn();\n } catch {\n return fallback;\n }\n}\n\n/**\n * Safe API that works before initialization.\n * Calls are queued and executed once the widget is ready.\n */\nexport const tchao = {\n /**\n * Initialize the widget. Returns a promise that resolves with the instance.\n */\n init,\n\n /**\n * Show the widget launcher. Safe to call before init.\n */\n show: (): void => {\n if (window.Tchao) {\n safeCall(() => window.Tchao?.show(), undefined);\n } else {\n callQueue.push({ type: \"show\" });\n }\n },\n\n /**\n * Hide the widget launcher. Safe to call before init.\n */\n hide: (): void => {\n if (window.Tchao) {\n safeCall(() => window.Tchao?.hide(), undefined);\n } else {\n callQueue.push({ type: \"hide\" });\n }\n },\n\n /**\n * Toggle the chat window. Safe to call before init.\n */\n toggle: (): void => {\n if (window.Tchao) {\n safeCall(() => window.Tchao?.toggle(), undefined);\n } else {\n callQueue.push({ type: \"toggle\" });\n }\n },\n\n /**\n * Open the chat window. Safe to call before init.\n */\n open: (message?: string): void => {\n if (window.Tchao) {\n safeCall(() => window.Tchao?.open(message), undefined);\n } else {\n callQueue.push({ type: \"open\", message });\n }\n },\n\n /**\n * Identify the visitor. Safe to call before init.\n */\n identify: (info: VisitorInfo): void => {\n if (window.Tchao) {\n safeCall(() => window.Tchao?.identify(info), undefined);\n } else {\n callQueue.push({ type: \"identify\", info });\n }\n },\n\n /**\n * Get the current widget configuration.\n */\n config: (): Partial<WidgetConfig> => {\n return safeCall(() => window.Tchao?.config() ?? {}, {});\n },\n\n /**\n * Subscribe to widget events. Safe to call before init.\n */\n on: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]): void => {\n if (window.Tchao) {\n safeCall(\n () => window.Tchao?.on(event, callback as (...args: unknown[]) => void),\n undefined\n );\n } else {\n callQueue.push({\n type: \"on\",\n event,\n callback: callback as (...args: unknown[]) => void,\n });\n }\n },\n\n /**\n * Unsubscribe from widget events.\n */\n off: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]): void => {\n if (window.Tchao) {\n safeCall(\n () =>\n window.Tchao?.off(event, callback as (...args: unknown[]) => void),\n undefined\n );\n } else {\n callQueue.push({\n type: \"off\",\n event,\n callback: callback as (...args: unknown[]) => void,\n });\n }\n },\n\n /**\n * Destroy the widget and clean up resources.\n */\n destroy: (): void => {\n if (currentInstance) {\n currentInstance.destroy();\n }\n },\n\n /**\n * Check if the widget is ready.\n */\n isReady: (): boolean => initialized && !!window.Tchao,\n\n /**\n * Get the current instance (null if not initialized).\n */\n getInstance: (): TchaoInstance | null => currentInstance,\n};\n\nexport const Tchao = {\n init,\n};\n\nexport { init };\nexport default Tchao;\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,SAAAC,EAAA,UAAAC,EAAA,aAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAAyD,iBCmFzD,IAAMC,EAAoB,8BAEtBC,EAAe,GACfC,EAAsC,KACtCC,EAAc,GACdC,EAAwC,KAWtCC,EAA0B,CAAC,EAEjC,SAASC,GAAmB,CAC1B,KAAOD,EAAU,OAAS,GAAG,CAC3B,IAAME,EAAOF,EAAU,MAAM,EAC7B,GAAI,GAACE,GAAQ,CAAC,OAAO,OAErB,GAAI,CACF,OAAQA,EAAK,KAAM,CACjB,IAAK,OACH,OAAO,MAAM,KAAK,EAClB,MACF,IAAK,OACH,OAAO,MAAM,KAAK,EAClB,MACF,IAAK,SACH,OAAO,MAAM,OAAO,EACpB,MACF,IAAK,OACH,OAAO,MAAM,KAAKA,EAAK,OAAO,EAC9B,MACF,IAAK,WACH,OAAO,MAAM,SAASA,EAAK,IAAI,EAC/B,MACF,IAAK,KACH,OAAO,MAAM,GAAGA,EAAK,MAAOA,EAAK,QAAQ,EACzC,MACF,IAAK,MACH,OAAO,MAAM,IAAIA,EAAK,MAAOA,EAAK,QAAQ,EAC1C,KACJ,CACF,MAAQ,CAER,CACF,CACF,CAEA,eAAeC,EAAWC,EAAoC,CAC5D,OAAIP,IAEJA,EAAgB,IAAI,QAAQ,CAACQ,EAASC,IAAW,CAC/C,GAAIV,GAAgB,OAAO,MAAO,CAChCS,EAAQ,EACR,MACF,CAMA,GAJuB,SAAS,cAC9B,2BACF,EAEoB,CAClBT,EAAe,GACfS,EAA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AM,EAEpD,sBAAU,IAAM,CACVnB,GAAWyB,GACbR,EAASQ,CAAO,CAEpB,EAAG,CAACzB,EAASyB,EAASR,CAAQ,CAAC,KAE/B,aAAU,IAAM,CACVjB,GAAW0B,GACbA,EAAQ,CAEZ,EAAG,CAAC1B,EAAS0B,CAAO,CAAC,KAErB,aAAU,IAAM,CACVtB,GAASuB,GACXA,EAAQvB,CAAK,CAEjB,EAAG,CAACA,EAAOuB,CAAO,CAAC,EAEZ,IACT","names":["react_exports","__export","TchaoProvider","init","tchao","useTchao","__toCommonJS","import_react","WIDGET_SCRIPT_URL","scriptLoaded","scriptPromise","initialized","currentInstance","callQueue","flushQueue","call","loadScript","config","resolve","reject","script","waitForTchao","attempts","check","init","createInstance","message","info","event","callback","widget","safeCall","fn","fallback","tchao","useTchao","options","isReady","setIsReady","isLoading","setIsLoading","error","setError","instanceRef","mountedRef","init","instance","err","show","tchao","hide","toggle","open","message","identify","info","config","on","event","callback","off","TchaoProvider","visitor","onReady","onError"]}
|
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{useEffect as v,useRef as b,useState as m,useCallback as d}from"react";var S="https://tchao.app/widget.js",T=!1,f=null,w=!1,s=null,a=[];function V(){for(;a.length>0;){let e=a.shift();if(!(!e||!window.Tchao))try{switch(e.type){case"show":window.Tchao.show();break;case"hide":window.Tchao.hide();break;case"toggle":window.Tchao.toggle();break;case"open":window.Tchao.open(e.message);break;case"identify":window.Tchao.identify(e.info);break;case"on":window.Tchao.on(e.event,e.callback);break;case"off":window.Tchao.off(e.event,e.callback);break}}catch{}}}async function W(e){return f||(f=new Promise((o,i)=>{if(T&&window.Tchao){o();return}if(document.querySelector("script[data-tchao-widget]")){T=!0,o();return}window.__TCHAO_CONFIG__=e;let t=document.createElement("script");t.src=e.host?`${e.host}/widget.js`:S,t.async=!0,t.dataset.websiteId=e.websiteId,t.dataset.tchaoWidget="true",t.onload=()=>{T=!0,o()},t.onerror=()=>{i(new Error("Failed to load Tchao widget script"))},document.head.appendChild(t)}),f)}async function O(){return new Promise((e,o)=>{let i=0,h=()=>{window.Tchao?e():i>=50?o(new Error("Tchao widget failed to initialize")):(i++,setTimeout(h,100))};h()})}async function E(e){if(!e.websiteId)throw new Error("websiteId is required");if(w&&window.Tchao&&s)return s;if(await W(e),await O(),!window.Tchao)throw new Error("Tchao widget failed to initialize");return w=!0,s=L(),V(),s}function L(){return{show:()=>{try{window.Tchao?.show()}catch{}},hide:()=>{try{window.Tchao?.hide()}catch{}},toggle:()=>{try{window.Tchao?.toggle()}catch{}},open:e=>{try{window.Tchao?.open(e)}catch{}},identify:e=>{try{window.Tchao?.identify(e)}catch{}},config:()=>{try{return window.Tchao?.config()??{}}catch{return{}}},on:(e,o)=>{try{window.Tchao?.on(e,o)}catch{}},off:(e,o)=>{try{window.Tchao?.off(e,o)}catch{}},isReady:()=>w&&!!window.Tchao,destroy:()=>{try{let e=document.querySelector("script[data-tchao-widget]");e&&e.remove();let o=document.getElementById("tchao-widget-root");o&&o.remove(),T=!1,f=null,w=!1,s=null,a.length=0,delete window.__TCHAO_CONFIG__,delete window.Tchao}catch{}}}}function r(e,o){try{return e()}catch{return o}}var c={init:E,show:()=>{window.Tchao?r(()=>window.Tchao?.show(),void 0):a.push({type:"show"})},hide:()=>{window.Tchao?r(()=>window.Tchao?.hide(),void 0):a.push({type:"hide"})},toggle:()=>{window.Tchao?r(()=>window.Tchao?.toggle(),void 0):a.push({type:"toggle"})},open:e=>{window.Tchao?r(()=>window.Tchao?.open(e),void 0):a.push({type:"open",message:e})},identify:e=>{window.Tchao?r(()=>window.Tchao?.identify(e),void 0):a.push({type:"identify",info:e})},config:()=>r(()=>window.Tchao?.config()??{},{}),on:(e,o)=>{window.Tchao?r(()=>window.Tchao?.on(e,o),void 0):a.push({type:"on",event:e,callback:o})},off:(e,o)=>{window.Tchao?r(()=>window.Tchao?.off(e,o),void 0):a.push({type:"off",event:e,callback:o})},destroy:()=>{s&&s.destroy()},isReady:()=>w&&!!window.Tchao,getInstance:()=>s};function U(e){let[o,i]=m(!1),[h,t]=m(!0),[l,g]=m(null),u=b(null),p=b(!0);v(()=>(p.current=!0,E(e).then(n=>{p.current&&(u.current=n,i(!0),t(!1))}).catch(n=>{p.current&&(g(n instanceof Error?n:new Error(String(n))),t(!1))}),()=>{p.current=!1,u.current&&(u.current.destroy(),u.current=null)}),[e.websiteId]);let I=d(()=>c.show(),[]),k=d(()=>c.hide(),[]),x=d(()=>c.toggle(),[]),C=d(n=>c.open(n),[]),M=d(n=>c.identify(n),[]),_=d(()=>c.config(),[]),R=d((n,y)=>c.on(n,y),[]),P=d((n,y)=>c.off(n,y),[]);return{isReady:o,isLoading:h,error:l,show:I,hide:k,toggle:x,open:C,identify:M,config:_,on:R,off:P}}function G({visitor:e,onReady:o,onError:i,...h}){let{isReady:t,error:l,identify:g}=U(h);return v(()=>{t&&e&&g(e)},[t,e,g]),v(()=>{t&&o&&o()},[t,o]),v(()=>{l&&i&&i(l)},[l,i]),null}export{G as TchaoProvider,E as init,c as tchao,U as useTchao};
|
|
2
|
+
//# sourceMappingURL=react.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/widget/react.ts","../../../src/widget/npm.ts"],"sourcesContent":["import { useEffect, useRef, useState, useCallback } from \"react\";\nimport {\n tchao,\n init,\n type TchaoConfig,\n type TchaoInstance,\n type VisitorInfo,\n type TchaoEvent,\n type TchaoEventMap,\n} from \"./npm\";\n\nexport type { TchaoConfig, TchaoInstance, VisitorInfo, TchaoEvent, TchaoEventMap };\n\nexport type UseTchaoOptions = TchaoConfig;\n\nexport type UseTchaoReturn = {\n /** Whether the widget is ready */\n isReady: boolean;\n /** Whether the widget is currently loading */\n isLoading: boolean;\n /** Error if initialization failed */\n error: Error | null;\n /** Show the widget launcher */\n show: () => void;\n /** Hide the widget launcher */\n hide: () => void;\n /** Toggle the chat window */\n toggle: () => void;\n /** Open the chat window with optional pre-filled message */\n open: (message?: string) => void;\n /** Identify the visitor */\n identify: (info: VisitorInfo) => void;\n /** Get current widget configuration */\n config: () => Partial<TchaoConfig>;\n /** Subscribe to widget events */\n on: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;\n /** Unsubscribe from widget events */\n off: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;\n};\n\n/**\n * React hook for using the Tchao chat widget.\n *\n * @example\n * ```tsx\n * function App() {\n * const { isReady, open, identify } = useTchao({\n * websiteId: \"your-website-id\",\n * });\n *\n * useEffect(() => {\n * if (isReady) {\n * identify({ email: user.email, name: user.name });\n * }\n * }, [isReady, identify]);\n *\n * return <button onClick={() => open()}>Chat with us</button>;\n * }\n * ```\n */\nexport function useTchao(options: UseTchaoOptions): UseTchaoReturn {\n const [isReady, setIsReady] = useState(false);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const instanceRef = useRef<TchaoInstance | null>(null);\n const mountedRef = useRef(true);\n\n useEffect(() => {\n mountedRef.current = true;\n\n init(options)\n .then((instance) => {\n if (!mountedRef.current) return;\n instanceRef.current = instance;\n setIsReady(true);\n setIsLoading(false);\n })\n .catch((err) => {\n if (!mountedRef.current) return;\n setError(err instanceof Error ? err : new Error(String(err)));\n setIsLoading(false);\n });\n\n return () => {\n mountedRef.current = false;\n if (instanceRef.current) {\n instanceRef.current.destroy();\n instanceRef.current = null;\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- Only re-init when websiteId changes\n }, [options.websiteId]);\n\n const show = useCallback(() => tchao.show(), []);\n const hide = useCallback(() => tchao.hide(), []);\n const toggle = useCallback(() => tchao.toggle(), []);\n const open = useCallback((message?: string) => tchao.open(message), []);\n const identify = useCallback((info: VisitorInfo) => tchao.identify(info), []);\n const config = useCallback(() => tchao.config(), []);\n const on = useCallback(\n <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) =>\n tchao.on(event, callback),\n []\n );\n const off = useCallback(\n <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) =>\n tchao.off(event, callback),\n []\n );\n\n return {\n isReady,\n isLoading,\n error,\n show,\n hide,\n toggle,\n open,\n identify,\n config,\n on,\n off,\n };\n}\n\n/**\n * Simple component that initializes Tchao and optionally identifies the user.\n *\n * @example\n * ```tsx\n * // In your layout or root component\n * <TchaoProvider\n * websiteId=\"your-website-id\"\n * visitor={{ email: user?.email, name: user?.name }}\n * />\n * ```\n */\nexport function TchaoProvider({\n visitor,\n onReady,\n onError,\n ...config\n}: TchaoConfig & {\n visitor?: VisitorInfo;\n onReady?: () => void;\n onError?: (error: Error) => void;\n}): null {\n const { isReady, error, identify } = useTchao(config);\n\n useEffect(() => {\n if (isReady && visitor) {\n identify(visitor);\n }\n }, [isReady, visitor, identify]);\n\n useEffect(() => {\n if (isReady && onReady) {\n onReady();\n }\n }, [isReady, onReady]);\n\n useEffect(() => {\n if (error && onError) {\n onError(error);\n }\n }, [error, onError]);\n\n return null;\n}\n\nexport { tchao, init };\n","export type VisitorInfo = {\n name?: string;\n email?: string;\n avatar?: string;\n metadata?: Record<string, unknown>;\n};\n\nexport type WidgetConfig = {\n websiteId: string;\n position?: \"bottom-right\" | \"bottom-left\";\n primaryColor?: string;\n widgetStyle?: \"bubble\" | \"name_line\" | \"question_cta\";\n themeMode?: \"light\" | \"dark\" | \"system\";\n agentName?: string;\n agentRole?: string;\n agentImage?: string;\n agentWelcomeMessage?: string;\n hidePoweredBy?: boolean;\n bubbleIcon?: string;\n};\n\nexport type TchaoConfig = {\n websiteId: string;\n host?: string;\n convexUrl?: string;\n position?: \"bottom-right\" | \"bottom-left\";\n primaryColor?: string;\n widgetStyle?: \"bubble\" | \"name_line\" | \"question_cta\";\n themeMode?: \"light\" | \"dark\" | \"system\";\n agentName?: string;\n agentRole?: string;\n agentImage?: string;\n agentWelcomeMessage?: string;\n hidePoweredBy?: boolean;\n bubbleIcon?: string;\n};\n\nexport type Message = {\n content: string;\n sender: string;\n timestamp: number;\n};\n\nexport type TchaoEventMap = {\n message: (message: Message) => void;\n open: () => void;\n close: () => void;\n ready: () => void;\n};\n\nexport type TchaoEvent = keyof TchaoEventMap;\n\nexport type TchaoInstance = {\n show: () => void;\n hide: () => void;\n toggle: () => void;\n open: (message?: string) => void;\n identify: (info: VisitorInfo) => void;\n config: () => Partial<WidgetConfig>;\n on: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;\n off: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;\n destroy: () => void;\n isReady: () => boolean;\n};\n\ntype InternalTchaoInstance = {\n show: () => void;\n hide: () => void;\n toggle: () => void;\n open: (message?: string) => void;\n identify: (info: VisitorInfo) => void;\n config: () => Partial<WidgetConfig>;\n on: (event: string, callback: (...args: unknown[]) => void) => void;\n off: (event: string, callback: (...args: unknown[]) => void) => void;\n};\n\ndeclare global {\n interface Window {\n Tchao?: InternalTchaoInstance;\n __TCHAO_CONFIG__?: TchaoConfig;\n }\n}\n\nconst WIDGET_SCRIPT_URL = \"https://tchao.app/widget.js\";\n\nlet scriptLoaded = false;\nlet scriptPromise: Promise<void> | null = null;\nlet initialized = false;\nlet currentInstance: TchaoInstance | null = null;\n\ntype QueuedCall =\n | { type: \"show\" }\n | { type: \"hide\" }\n | { type: \"toggle\" }\n | { type: \"open\"; message?: string }\n | { type: \"identify\"; info: VisitorInfo }\n | { type: \"on\"; event: string; callback: (...args: unknown[]) => void }\n | { type: \"off\"; event: string; callback: (...args: unknown[]) => void };\n\nconst callQueue: QueuedCall[] = [];\n\nfunction flushQueue(): void {\n while (callQueue.length > 0) {\n const call = callQueue.shift();\n if (!call || !window.Tchao) continue;\n\n try {\n switch (call.type) {\n case \"show\":\n window.Tchao.show();\n break;\n case \"hide\":\n window.Tchao.hide();\n break;\n case \"toggle\":\n window.Tchao.toggle();\n break;\n case \"open\":\n window.Tchao.open(call.message);\n break;\n case \"identify\":\n window.Tchao.identify(call.info);\n break;\n case \"on\":\n window.Tchao.on(call.event, call.callback);\n break;\n case \"off\":\n window.Tchao.off(call.event, call.callback);\n break;\n }\n } catch {\n // Silent fail\n }\n }\n}\n\nasync function loadScript(config: TchaoConfig): Promise<void> {\n if (scriptPromise) return scriptPromise;\n\n scriptPromise = new Promise((resolve, reject) => {\n if (scriptLoaded && window.Tchao) {\n resolve();\n return;\n }\n\n const existingScript = document.querySelector(\n 'script[data-tchao-widget]'\n ) as HTMLScriptElement | null;\n\n if (existingScript) {\n scriptLoaded = true;\n resolve();\n return;\n }\n\n window.__TCHAO_CONFIG__ = config;\n\n const script = document.createElement(\"script\");\n script.src = config.host ? `${config.host}/widget.js` : WIDGET_SCRIPT_URL;\n script.async = true;\n script.dataset.websiteId = config.websiteId;\n script.dataset.tchaoWidget = \"true\";\n\n script.onload = () => {\n scriptLoaded = true;\n resolve();\n };\n\n script.onerror = () => {\n reject(new Error(\"Failed to load Tchao widget script\"));\n };\n\n document.head.appendChild(script);\n });\n\n return scriptPromise;\n}\n\nasync function waitForTchao(): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n const check = () => {\n if (window.Tchao) {\n resolve();\n } else if (attempts >= 50) {\n reject(new Error(\"Tchao widget failed to initialize\"));\n } else {\n attempts++;\n setTimeout(check, 100);\n }\n };\n check();\n });\n}\n\nasync function init(config: TchaoConfig): Promise<TchaoInstance> {\n if (!config.websiteId) {\n throw new Error(\"websiteId is required\");\n }\n\n if (initialized && window.Tchao && currentInstance) {\n return currentInstance;\n }\n\n await loadScript(config);\n await waitForTchao();\n\n if (!window.Tchao) {\n throw new Error(\"Tchao widget failed to initialize\");\n }\n\n initialized = true;\n currentInstance = createInstance();\n flushQueue();\n return currentInstance;\n}\n\nfunction createInstance(): TchaoInstance {\n return {\n show: () => {\n try {\n window.Tchao?.show();\n } catch {\n // Silent fail\n }\n },\n hide: () => {\n try {\n window.Tchao?.hide();\n } catch {\n // Silent fail\n }\n },\n toggle: () => {\n try {\n window.Tchao?.toggle();\n } catch {\n // Silent fail\n }\n },\n open: (message?: string) => {\n try {\n window.Tchao?.open(message);\n } catch {\n // Silent fail\n }\n },\n identify: (info: VisitorInfo) => {\n try {\n window.Tchao?.identify(info);\n } catch {\n // Silent fail\n }\n },\n config: () => {\n try {\n return window.Tchao?.config() ?? {};\n } catch {\n return {};\n }\n },\n on: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => {\n try {\n window.Tchao?.on(event, callback as (...args: unknown[]) => void);\n } catch {\n // Silent fail\n }\n },\n off: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => {\n try {\n window.Tchao?.off(event, callback as (...args: unknown[]) => void);\n } catch {\n // Silent fail\n }\n },\n isReady: () => initialized && !!window.Tchao,\n destroy: () => {\n try {\n const script = document.querySelector('script[data-tchao-widget]');\n if (script) script.remove();\n const widget = document.getElementById(\"tchao-widget-root\");\n if (widget) widget.remove();\n scriptLoaded = false;\n scriptPromise = null;\n initialized = false;\n currentInstance = null;\n callQueue.length = 0;\n delete window.__TCHAO_CONFIG__;\n delete window.Tchao;\n } catch {\n // Silent fail\n }\n },\n };\n}\n\nfunction safeCall<T>(fn: () => T, fallback: T): T {\n try {\n return fn();\n } catch {\n return fallback;\n }\n}\n\n/**\n * Safe API that works before initialization.\n * Calls are queued and executed once the widget is ready.\n */\nexport const tchao = {\n /**\n * Initialize the widget. Returns a promise that resolves with the instance.\n */\n init,\n\n /**\n * Show the widget launcher. Safe to call before init.\n */\n show: (): void => {\n if (window.Tchao) {\n safeCall(() => window.Tchao?.show(), undefined);\n } else {\n callQueue.push({ type: \"show\" });\n }\n },\n\n /**\n * Hide the widget launcher. Safe to call before init.\n */\n hide: (): void => {\n if (window.Tchao) {\n safeCall(() => window.Tchao?.hide(), undefined);\n } else {\n callQueue.push({ type: \"hide\" });\n }\n },\n\n /**\n * Toggle the chat window. Safe to call before init.\n */\n toggle: (): void => {\n if (window.Tchao) {\n safeCall(() => window.Tchao?.toggle(), undefined);\n } else {\n callQueue.push({ type: \"toggle\" });\n }\n },\n\n /**\n * Open the chat window. Safe to call before init.\n */\n open: (message?: string): void => {\n if (window.Tchao) {\n safeCall(() => window.Tchao?.open(message), undefined);\n } else {\n callQueue.push({ type: \"open\", message });\n }\n },\n\n /**\n * Identify the visitor. Safe to call before init.\n */\n identify: (info: VisitorInfo): void => {\n if (window.Tchao) {\n safeCall(() => window.Tchao?.identify(info), undefined);\n } else {\n callQueue.push({ type: \"identify\", info });\n }\n },\n\n /**\n * Get the current widget configuration.\n */\n config: (): Partial<WidgetConfig> => {\n return safeCall(() => window.Tchao?.config() ?? {}, {});\n },\n\n /**\n * Subscribe to widget events. Safe to call before init.\n */\n on: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]): void => {\n if (window.Tchao) {\n safeCall(\n () => window.Tchao?.on(event, callback as (...args: unknown[]) => void),\n undefined\n );\n } else {\n callQueue.push({\n type: \"on\",\n event,\n callback: callback as (...args: unknown[]) => void,\n });\n }\n },\n\n /**\n * Unsubscribe from widget events.\n */\n off: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]): void => {\n if (window.Tchao) {\n safeCall(\n () =>\n window.Tchao?.off(event, callback as (...args: unknown[]) => void),\n undefined\n );\n } else {\n callQueue.push({\n type: \"off\",\n event,\n callback: callback as (...args: unknown[]) => void,\n });\n }\n },\n\n /**\n * Destroy the widget and clean up resources.\n */\n destroy: (): void => {\n if (currentInstance) {\n currentInstance.destroy();\n }\n },\n\n /**\n * Check if the widget is ready.\n */\n isReady: (): boolean => initialized && !!window.Tchao,\n\n /**\n * Get the current instance (null if not initialized).\n */\n getInstance: (): TchaoInstance | null => currentInstance,\n};\n\nexport const Tchao = {\n init,\n};\n\nexport { init };\nexport default Tchao;\n"],"mappings":"AAAA,OAAS,aAAAA,EAAW,UAAAC,EAAQ,YAAAC,EAAU,eAAAC,MAAmB,QCmFzD,IAAMC,EAAoB,8BAEtBC,EAAe,GACfC,EAAsC,KACtCC,EAAc,GACdC,EAAwC,KAWtCC,EAA0B,CAAC,EAEjC,SAASC,GAAmB,CA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AAK,EAAG,CAAC,CAAC,EACzCE,EAASH,EAAY,IAAMC,EAAM,OAAO,EAAG,CAAC,CAAC,EAC7CG,EAAOJ,EAAaK,GAAqBJ,EAAM,KAAKI,CAAO,EAAG,CAAC,CAAC,EAChEC,EAAWN,EAAaO,GAAsBN,EAAM,SAASM,CAAI,EAAG,CAAC,CAAC,EACtEC,EAASR,EAAY,IAAMC,EAAM,OAAO,EAAG,CAAC,CAAC,EAC7CQ,EAAKT,EACT,CAAuBU,EAAUC,IAC/BV,EAAM,GAAGS,EAAOC,CAAQ,EAC1B,CAAC,CACH,EACMC,EAAMZ,EACV,CAAuBU,EAAUC,IAC/BV,EAAM,IAAIS,EAAOC,CAAQ,EAC3B,CAAC,CACH,EAEA,MAAO,CACL,QAAA1B,EACA,UAAAG,EACA,MAAAE,EACA,KAAAS,EACA,KAAAG,EACA,OAAAC,EACA,KAAAC,EACA,SAAAE,EACA,OAAAE,EACA,GAAAC,EACA,IAAAG,CACF,CACF,CAcO,SAASC,EAAc,CAC5B,QAAAC,EACA,QAAAC,EACA,QAAAC,EACA,GAAGR,CACL,EAIS,CACP,GAAM,CAAE,QAAAvB,EAAS,MAAAK,EAAO,SAAAgB,CAAS,EAAIvB,EAASyB,CAAM,EAEpD,OAAAb,EAAU,IAAM,CACVV,GAAW6B,GACbR,EAASQ,CAAO,CAEpB,EAAG,CAAC7B,EAAS6B,EAASR,CAAQ,CAAC,EAE/BX,EAAU,IAAM,CACVV,GAAW8B,GACbA,EAAQ,CAEZ,EAAG,CAAC9B,EAAS8B,CAAO,CAAC,EAErBpB,EAAU,IAAM,CACVL,GAAS0B,GACXA,EAAQ1B,CAAK,CAEjB,EAAG,CAACA,EAAO0B,CAAO,CAAC,EAEZ,IACT","names":["useEffect","useRef","useState","useCallback","WIDGET_SCRIPT_URL","scriptLoaded","scriptPromise","initialized","currentInstance","callQueue","flushQueue","call","loadScript","config","resolve","reject","script","waitForTchao","attempts","check","init","createInstance","message","info","event","callback","widget","safeCall","fn","fallback","tchao","useTchao","options","isReady","setIsReady","useState","isLoading","setIsLoading","error","setError","instanceRef","useRef","mountedRef","useEffect","init","instance","err","show","useCallback","tchao","hide","toggle","open","message","identify","info","config","on","event","callback","off","TchaoProvider","visitor","onReady","onError"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tchao",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "JavaScript SDK for Tchao chat widget",
|
|
5
5
|
"main": "./dist/npm.js",
|
|
6
6
|
"module": "./dist/npm.mjs",
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
"types": "./dist/npm.d.ts",
|
|
11
11
|
"import": "./dist/npm.mjs",
|
|
12
12
|
"require": "./dist/npm.js"
|
|
13
|
+
},
|
|
14
|
+
"./react": {
|
|
15
|
+
"types": "./dist/react.d.ts",
|
|
16
|
+
"import": "./dist/react.mjs",
|
|
17
|
+
"require": "./dist/react.js"
|
|
13
18
|
}
|
|
14
19
|
},
|
|
15
20
|
"files": [
|
|
@@ -21,15 +26,22 @@
|
|
|
21
26
|
"widget",
|
|
22
27
|
"sdk",
|
|
23
28
|
"customer-support",
|
|
24
|
-
"live-chat"
|
|
29
|
+
"live-chat",
|
|
30
|
+
"react"
|
|
25
31
|
],
|
|
26
32
|
"author": "Tchao",
|
|
27
33
|
"license": "MIT",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": ">=17.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"react": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
31
41
|
},
|
|
32
42
|
"devDependencies": {
|
|
43
|
+
"@types/react": "^19.1.8",
|
|
44
|
+
"react": "^19.1.0",
|
|
33
45
|
"tsup": "^8.5.0",
|
|
34
46
|
"typescript": "^5.9.3"
|
|
35
47
|
},
|
|
@@ -37,14 +49,6 @@
|
|
|
37
49
|
"type": "git",
|
|
38
50
|
"url": "https://github.com/tchao-app/tchao"
|
|
39
51
|
},
|
|
40
|
-
"peerDependencies": {
|
|
41
|
-
"convex": ">=1.0.0"
|
|
42
|
-
},
|
|
43
|
-
"peerDependenciesMeta": {
|
|
44
|
-
"convex": {
|
|
45
|
-
"optional": true
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
52
|
"scripts": {
|
|
49
53
|
"build": "tsup",
|
|
50
54
|
"dev": "tsup --watch",
|