@botonic/webchat-react 2.23.1
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/CHANGELOG.md +269 -0
- package/README.md +236 -0
- package/index.d.ts +81 -0
- package/index.js +46 -0
- package/lib/components/message/audio-message/audio-message.d.ts +20 -0
- package/lib/components/message/audio-message/index.d.ts +1 -0
- package/lib/components/message/button-message/button-message.d.ts +24 -0
- package/lib/components/message/button-message/index.d.ts +1 -0
- package/lib/components/message/carousel-message/carousel-message.d.ts +18 -0
- package/lib/components/message/carousel-message/index.d.ts +1 -0
- package/lib/components/message/document-message/document-message.d.ts +22 -0
- package/lib/components/message/document-message/index.d.ts +1 -0
- package/lib/components/message/image-message/image-message.d.ts +14 -0
- package/lib/components/message/image-message/index.d.ts +1 -0
- package/lib/components/message/index.d.ts +33 -0
- package/lib/components/message/location-message/index.d.ts +1 -0
- package/lib/components/message/location-message/location-message.d.ts +16 -0
- package/lib/components/message/message/index.d.ts +5 -0
- package/lib/components/message/message/message-avatar/index.d.ts +1 -0
- package/lib/components/message/message/message-avatar/message-avatar.d.ts +24 -0
- package/lib/components/message/message/message-bubble/index.d.ts +1 -0
- package/lib/components/message/message/message-bubble/message-bubble.d.ts +17 -0
- package/lib/components/message/message/message-info/index.d.ts +1 -0
- package/lib/components/message/message/message-info/message-info.d.ts +25 -0
- package/lib/components/message/message/message.d.ts +23 -0
- package/lib/components/message/message/use-message.d.ts +43 -0
- package/lib/components/message/text-message/index.d.ts +1 -0
- package/lib/components/message/text-message/text-message.d.ts +10 -0
- package/lib/components/message/video-message/index.d.ts +1 -0
- package/lib/components/message/video-message/video-message.d.ts +20 -0
- package/lib/components/message-machine-renderer/index.d.ts +3 -0
- package/lib/components/message-machine-renderer/message-machine-renderer.d.ts +28 -0
- package/lib/components/message-machine-renderer/use-avatar.d.ts +34 -0
- package/lib/components/message-machine-renderer/use-message-machine-renderer.d.ts +31 -0
- package/lib/components/shared/button-component/button-component.d.ts +24 -0
- package/lib/components/shared/button-component/index.d.ts +2 -0
- package/lib/components/shared/index.d.ts +2 -0
- package/lib/components/typing-indicator/index.d.ts +1 -0
- package/lib/components/typing-indicator/typing-indicator.d.ts +11 -0
- package/lib/components/webchat-app/index.d.ts +1 -0
- package/lib/components/webchat-app/webchat-app.d.ts +41 -0
- package/lib/components/webchat-container/use-webchat-container.d.ts +26 -0
- package/lib/components/webchat-container/webchat-container.d.ts +2 -0
- package/lib/components/webchat-header/use-webchat-header.d.ts +19 -0
- package/lib/components/webchat-header/webchat-header.d.ts +2 -0
- package/lib/components/webchat-input/use-webchat-input.d.ts +31 -0
- package/lib/components/webchat-input/webchat-input.d.ts +2 -0
- package/lib/components/webchat-messages/use-webchat-messages.d.ts +54 -0
- package/lib/components/webchat-messages/webchat-messages.d.ts +2 -0
- package/lib/components/webchat-overlay/base/confirm-modal/confirm-modal.d.ts +8 -0
- package/lib/components/webchat-overlay/base/confirm-modal/index.d.ts +2 -0
- package/lib/components/webchat-overlay/base/content/content.d.ts +9 -0
- package/lib/components/webchat-overlay/base/content/index.d.ts +2 -0
- package/lib/components/webchat-overlay/base/header/header.d.ts +4 -0
- package/lib/components/webchat-overlay/base/header/index.d.ts +3 -0
- package/lib/components/webchat-overlay/base/header/use-header.d.ts +13 -0
- package/lib/components/webchat-overlay/base/index.d.ts +5 -0
- package/lib/components/webchat-overlay/base/overlay/index.d.ts +3 -0
- package/lib/components/webchat-overlay/base/overlay/overlay.d.ts +18 -0
- package/lib/components/webchat-overlay/base/overlay/use-overlay.d.ts +23 -0
- package/lib/components/webchat-overlay/base/overlay-context.d.ts +25 -0
- package/lib/components/webchat-overlay/cover/frame/cover-frame.d.ts +8 -0
- package/lib/components/webchat-overlay/cover/frame/index.d.ts +2 -0
- package/lib/components/webchat-overlay/cover/index.d.ts +1 -0
- package/lib/components/webchat-overlay/index.d.ts +3 -0
- package/lib/components/webchat-overlay/webview/frame/index.d.ts +2 -0
- package/lib/components/webchat-overlay/webview/frame/webview-frame.d.ts +8 -0
- package/lib/components/webchat-overlay/webview/index.d.ts +1 -0
- package/lib/components/webchat-provider/webchat-provider.d.ts +22 -0
- package/lib/components/webchat-trigger/use-webchat-trigger.d.ts +38 -0
- package/lib/components/webchat-trigger/webchat-trigger-error-boundary.d.ts +19 -0
- package/lib/components/webchat-trigger/webchat-trigger.d.ts +2 -0
- package/lib/hooks/use-webchat-state.d.ts +21 -0
- package/lib/types/primitives.d.ts +15 -0
- package/lib/types/webchat-props.d.ts +103 -0
- package/package.json +37 -0
- package/styles.css +466 -0
- package/trigger.d.ts +40 -0
- package/trigger.js +215 -0
- package/webchat-app-CtAHJapU.js +2285 -0
package/trigger.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @botonic/webchat-react/trigger
|
|
3
|
+
*
|
|
4
|
+
* Lightweight trigger entry point with lazy loading.
|
|
5
|
+
*
|
|
6
|
+
* This entry exports only the WebchatTrigger component (~5kB).
|
|
7
|
+
* The full webchat UI (~66kB) is lazy-loaded when needed.
|
|
8
|
+
*
|
|
9
|
+
* ## Usage
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { WebchatTrigger } from '@botonic/webchat-react/trigger'
|
|
12
|
+
* import '@botonic/webchat-react/styles.css'
|
|
13
|
+
*
|
|
14
|
+
* <WebchatTrigger appId="your-app-id" />
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* ## Custom Composition
|
|
18
|
+
* ```tsx
|
|
19
|
+
* // my-webchat.tsx
|
|
20
|
+
* import { WebchatCompositionProps, WebchatProvider, WebchatContainer } from '@botonic/webchat-react'
|
|
21
|
+
*
|
|
22
|
+
* export default function MyWebchat(props: WebchatCompositionProps) {
|
|
23
|
+
* return (
|
|
24
|
+
* <WebchatProvider {...props}>
|
|
25
|
+
* <WebchatContainer>
|
|
26
|
+
* <MyCustomHeader />
|
|
27
|
+
* <WebchatMessages />
|
|
28
|
+
* <WebchatInput />
|
|
29
|
+
* </WebchatContainer>
|
|
30
|
+
* </WebchatProvider>
|
|
31
|
+
* )
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* // main.tsx
|
|
35
|
+
* import { WebchatTrigger } from '@botonic/webchat-react/trigger'
|
|
36
|
+
* <WebchatTrigger appId="xxx" loader={() => import('./my-webchat')} />
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export { WebchatTrigger } from './lib/components/webchat-trigger/webchat-trigger';
|
|
40
|
+
export type { WebchatCompositionProps, WebchatLoader, WebchatTriggerProps, } from './lib/types/webchat-props';
|
package/trigger.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { jsxs as V, Fragment as q, jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import { cx as D, cva as J } from "class-variance-authority";
|
|
3
|
+
import { useState as s, useRef as h, useMemo as M, lazy as A, useCallback as l, useEffect as E, Component as Z, Suspense as X } from "react";
|
|
4
|
+
import { ensureGlobalWebchatAPI as Y, setupGlobalWebchatAPI as $, signalWebchatReady as ee } from "@botonic/webchat-core";
|
|
5
|
+
A(
|
|
6
|
+
() => import("./webchat-app-CtAHJapU.js").then((i) => i.w).then((i) => ({ default: i.WebchatApp }))
|
|
7
|
+
);
|
|
8
|
+
function te(i, c) {
|
|
9
|
+
const {
|
|
10
|
+
appId: b,
|
|
11
|
+
position: R = "bottom-right",
|
|
12
|
+
isPulsing: _,
|
|
13
|
+
icon: v,
|
|
14
|
+
"aria-label": g,
|
|
15
|
+
className: W,
|
|
16
|
+
webchatConfig: O,
|
|
17
|
+
onReady: u,
|
|
18
|
+
loader: d
|
|
19
|
+
} = i, [a, f] = s(!1), [m, x] = s(!1), [I, P] = s(0), [n, w] = s(!1), [t, F] = s(null), [N, H] = s(!1), [p, C] = s("appearing"), k = h(!1), S = h(null), G = h(!1), z = h(!1);
|
|
20
|
+
z.current || (z.current = !0, Y());
|
|
21
|
+
const K = M(
|
|
22
|
+
() => d ? A(d) : A(
|
|
23
|
+
() => import("./webchat-app-CtAHJapU.js").then((e) => e.w).then((e) => ({
|
|
24
|
+
default: e.WebchatApp
|
|
25
|
+
}))
|
|
26
|
+
),
|
|
27
|
+
[d, I]
|
|
28
|
+
), T = l(
|
|
29
|
+
(e) => {
|
|
30
|
+
e.target === e.currentTarget && p !== null && C(null);
|
|
31
|
+
},
|
|
32
|
+
[p]
|
|
33
|
+
);
|
|
34
|
+
E(() => {
|
|
35
|
+
if (!t) return;
|
|
36
|
+
const e = t.machine.subscribe((L) => {
|
|
37
|
+
H(L.context.connectionStatus === "connected"), w(L.context.isOpen ?? !1);
|
|
38
|
+
});
|
|
39
|
+
return () => e.unsubscribe();
|
|
40
|
+
}, [t]), E(() => {
|
|
41
|
+
const e = k.current, L = t !== null && S.current === null;
|
|
42
|
+
if (k.current = n, S.current = t, !!t) {
|
|
43
|
+
if (L && n) {
|
|
44
|
+
C("opening");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
e === !1 && n ? C("opening") : e === !0 && !n && C("closing");
|
|
48
|
+
}
|
|
49
|
+
}, [n, t]);
|
|
50
|
+
const j = l((e) => {
|
|
51
|
+
F(e), $(e);
|
|
52
|
+
}, []);
|
|
53
|
+
E(() => {
|
|
54
|
+
!t || !N || G.current || (G.current = !0, ee(), u?.(t));
|
|
55
|
+
}, [t, N, u]);
|
|
56
|
+
const y = l(() => {
|
|
57
|
+
m && (x(!1), P((e) => e + 1)), a ? t ? t.open() : w(!0) : (f(!0), w(!0));
|
|
58
|
+
}, [m, a, t]), Q = l(() => {
|
|
59
|
+
t ? n ? t.close() : t.open() : y();
|
|
60
|
+
}, [t, n, y]), B = l(() => {
|
|
61
|
+
x(!1), P((e) => e + 1), f(!0), w(!0);
|
|
62
|
+
}, []), U = l((e) => {
|
|
63
|
+
console.error("Failed to load webchat:", e), x(!0);
|
|
64
|
+
}, []);
|
|
65
|
+
return E(() => {
|
|
66
|
+
if (typeof window > "u") return;
|
|
67
|
+
const e = () => y();
|
|
68
|
+
return window.addEventListener("botonic:open", e), () => window.removeEventListener("botonic:open", e);
|
|
69
|
+
}, [y]), {
|
|
70
|
+
triggerProps: {
|
|
71
|
+
ref: c,
|
|
72
|
+
type: "button",
|
|
73
|
+
onClick: m ? B : Q,
|
|
74
|
+
onAnimationEnd: T,
|
|
75
|
+
"aria-label": g || (n ? "Close chat" : "Open chat"),
|
|
76
|
+
"aria-expanded": n
|
|
77
|
+
},
|
|
78
|
+
icon: v,
|
|
79
|
+
isOpen: n,
|
|
80
|
+
className: W,
|
|
81
|
+
variants: {
|
|
82
|
+
position: R,
|
|
83
|
+
isPulsing: _,
|
|
84
|
+
isAppearing: p === "appearing",
|
|
85
|
+
isOpening: p === "opening",
|
|
86
|
+
isClosing: p === "closing",
|
|
87
|
+
isLoading: a && !t,
|
|
88
|
+
isOpen: n
|
|
89
|
+
},
|
|
90
|
+
webchatProps: {
|
|
91
|
+
appId: b,
|
|
92
|
+
isOpen: n,
|
|
93
|
+
onClose: () => t?.close(),
|
|
94
|
+
onControllerReady: j,
|
|
95
|
+
...O
|
|
96
|
+
},
|
|
97
|
+
shouldRenderWebchat: a,
|
|
98
|
+
LazyWebchat: K,
|
|
99
|
+
loadError: m,
|
|
100
|
+
retryLoad: B,
|
|
101
|
+
handleLoadError: U,
|
|
102
|
+
retryKey: I
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const re = "webchat-trigger-module__base___BpGIN", r = {
|
|
106
|
+
base: re,
|
|
107
|
+
"bottom-right": "webchat-trigger-module__bottom-right___Q9RB7",
|
|
108
|
+
"bottom-left": "webchat-trigger-module__bottom-left___O0h6i",
|
|
109
|
+
"top-right": "webchat-trigger-module__top-right___fRZQ7",
|
|
110
|
+
"top-left": "webchat-trigger-module__top-left___HIH3L",
|
|
111
|
+
"trigger-icon": "webchat-trigger-module__trigger-icon___8oGUm",
|
|
112
|
+
"loading-spinner": "webchat-trigger-module__loading-spinner___UrhIi",
|
|
113
|
+
"is-pulsing": "webchat-trigger-module__is-pulsing___bVsxi",
|
|
114
|
+
"is-appearing": "webchat-trigger-module__is-appearing___WHdbF",
|
|
115
|
+
"is-opening": "webchat-trigger-module__is-opening___NzPKU",
|
|
116
|
+
"is-closing": "webchat-trigger-module__is-closing___Gbp3t",
|
|
117
|
+
"is-loading": "webchat-trigger-module__is-loading___Qnwvi",
|
|
118
|
+
"is-open": "webchat-trigger-module__is-open___qJce6"
|
|
119
|
+
};
|
|
120
|
+
class ne extends Z {
|
|
121
|
+
constructor() {
|
|
122
|
+
super(...arguments), this.state = { hasError: !1 };
|
|
123
|
+
}
|
|
124
|
+
static getDerivedStateFromError() {
|
|
125
|
+
return { hasError: !0 };
|
|
126
|
+
}
|
|
127
|
+
componentDidCatch(c) {
|
|
128
|
+
this.props.onError(c);
|
|
129
|
+
}
|
|
130
|
+
render() {
|
|
131
|
+
return this.state.hasError ? null : this.props.children;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const oe = J(r.base, {
|
|
135
|
+
variants: {
|
|
136
|
+
position: {
|
|
137
|
+
"bottom-right": r["bottom-right"],
|
|
138
|
+
"bottom-left": r["bottom-left"],
|
|
139
|
+
"top-right": r["top-right"],
|
|
140
|
+
"top-left": r["top-left"]
|
|
141
|
+
},
|
|
142
|
+
isPulsing: {
|
|
143
|
+
true: r["is-pulsing"]
|
|
144
|
+
},
|
|
145
|
+
isAppearing: {
|
|
146
|
+
true: r["is-appearing"]
|
|
147
|
+
},
|
|
148
|
+
isOpening: {
|
|
149
|
+
true: r["is-opening"]
|
|
150
|
+
},
|
|
151
|
+
isClosing: {
|
|
152
|
+
true: r["is-closing"]
|
|
153
|
+
},
|
|
154
|
+
isLoading: {
|
|
155
|
+
true: r["is-loading"]
|
|
156
|
+
},
|
|
157
|
+
isOpen: {
|
|
158
|
+
true: r["is-open"]
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
defaultVariants: {
|
|
162
|
+
position: "bottom-right"
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
function ge(i) {
|
|
166
|
+
const c = h(null), {
|
|
167
|
+
triggerProps: b,
|
|
168
|
+
icon: R,
|
|
169
|
+
isOpen: _,
|
|
170
|
+
className: v,
|
|
171
|
+
variants: g,
|
|
172
|
+
webchatProps: W,
|
|
173
|
+
shouldRenderWebchat: O,
|
|
174
|
+
LazyWebchat: u,
|
|
175
|
+
loadError: d,
|
|
176
|
+
handleLoadError: a,
|
|
177
|
+
retryKey: f
|
|
178
|
+
} = te(i, c);
|
|
179
|
+
return /* @__PURE__ */ V(q, { children: [
|
|
180
|
+
/* @__PURE__ */ o(
|
|
181
|
+
"button",
|
|
182
|
+
{
|
|
183
|
+
...b,
|
|
184
|
+
className: D(oe(g), v),
|
|
185
|
+
"data-testid": "webchat-trigger",
|
|
186
|
+
"aria-label": d ? "Retry loading chat" : b["aria-label"],
|
|
187
|
+
children: /* @__PURE__ */ o("div", { className: r["trigger-icon"], children: g.isLoading && _ ? /* @__PURE__ */ o("span", { className: r["loading-spinner"] }) : R || /* @__PURE__ */ o(
|
|
188
|
+
"svg",
|
|
189
|
+
{
|
|
190
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
191
|
+
width: "24",
|
|
192
|
+
height: "24",
|
|
193
|
+
viewBox: "0 0 24 24",
|
|
194
|
+
fill: "none",
|
|
195
|
+
stroke: "currentColor",
|
|
196
|
+
strokeWidth: "2",
|
|
197
|
+
strokeLinejoin: "round",
|
|
198
|
+
"aria-hidden": !0,
|
|
199
|
+
children: /* @__PURE__ */ o("path", { d: "M11.9824 1H12.0068C16.6626 1.00019 20.8294 3.94825 22.3779 8.34766V8.34863C23.9256 12.7351 22.5189 17.6607 18.8877 20.5752L18.8867 20.5762C15.366 23.4132 10.4571 23.7848 6.55273 21.5576C6.37266 21.455 6.16579 21.4117 5.96094 21.4316L5.87305 21.4443L1.80176 22.209L2.56738 18.1328C2.61117 17.8992 2.57029 17.6574 2.45215 17.4512C0.544246 14.1225 0.50971 10.0164 2.38574 6.64258C4.32746 3.1601 8.00376 1.00006 11.9824 1Z" })
|
|
200
|
+
}
|
|
201
|
+
) })
|
|
202
|
+
}
|
|
203
|
+
),
|
|
204
|
+
O && u && /* @__PURE__ */ o(ne, { onError: a, children: /* @__PURE__ */ o(
|
|
205
|
+
X,
|
|
206
|
+
{
|
|
207
|
+
fallback: g.isLoading && _ ? /* @__PURE__ */ o("span", { className: r["loading-spinner"], "aria-hidden": !0 }) : null,
|
|
208
|
+
children: /* @__PURE__ */ o(u, { ...W })
|
|
209
|
+
}
|
|
210
|
+
) }, f)
|
|
211
|
+
] });
|
|
212
|
+
}
|
|
213
|
+
export {
|
|
214
|
+
ge as WebchatTrigger
|
|
215
|
+
};
|