@customerhero/react 2.1.1 → 2.3.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 +19 -0
- package/dist/chunk-BB2DI7WR.js +2932 -0
- package/dist/index.cjs +523 -183
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +20 -2592
- package/dist/preview.cjs +2976 -0
- package/dist/preview.d.cts +32 -0
- package/dist/preview.d.ts +32 -0
- package/dist/preview.js +53 -0
- package/package.json +12 -2
package/dist/preview.cjs
ADDED
|
@@ -0,0 +1,2976 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/preview.tsx
|
|
21
|
+
var preview_exports = {};
|
|
22
|
+
__export(preview_exports, {
|
|
23
|
+
PreviewWidget: () => PreviewWidget
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(preview_exports);
|
|
26
|
+
var import_react12 = require("react");
|
|
27
|
+
|
|
28
|
+
// src/context.tsx
|
|
29
|
+
var import_react = require("react");
|
|
30
|
+
var import_js = require("@customerhero/js");
|
|
31
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
var CustomerHeroContext = (0, import_react.createContext)(null);
|
|
33
|
+
function CustomerHeroProvider({
|
|
34
|
+
children,
|
|
35
|
+
disableAutoFetch,
|
|
36
|
+
...config
|
|
37
|
+
}) {
|
|
38
|
+
const clientRef = (0, import_react.useRef)(null);
|
|
39
|
+
if (!clientRef.current) {
|
|
40
|
+
clientRef.current = new import_js.CustomerHeroChat(config);
|
|
41
|
+
}
|
|
42
|
+
(0, import_react.useEffect)(() => {
|
|
43
|
+
if (disableAutoFetch) return;
|
|
44
|
+
clientRef.current?.fetchConfig();
|
|
45
|
+
}, [disableAutoFetch]);
|
|
46
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CustomerHeroContext.Provider, { value: clientRef.current, children });
|
|
47
|
+
}
|
|
48
|
+
function useCustomerHeroClient() {
|
|
49
|
+
const client = (0, import_react.useContext)(CustomerHeroContext);
|
|
50
|
+
if (!client) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
"useCustomerHeroClient must be used within a <CustomerHeroProvider>"
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return client;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/components/chat-bubble.tsx
|
|
59
|
+
var import_react5 = require("react");
|
|
60
|
+
|
|
61
|
+
// src/use-chat.ts
|
|
62
|
+
var import_react2 = require("react");
|
|
63
|
+
function useChat() {
|
|
64
|
+
const client = useCustomerHeroClient();
|
|
65
|
+
const state = (0, import_react2.useSyncExternalStore)(
|
|
66
|
+
(0, import_react2.useCallback)((cb) => client.subscribe(cb), [client]),
|
|
67
|
+
() => client.getState(),
|
|
68
|
+
() => client.getState()
|
|
69
|
+
);
|
|
70
|
+
return {
|
|
71
|
+
...state,
|
|
72
|
+
t: client.t,
|
|
73
|
+
sendMessage: (0, import_react2.useCallback)(
|
|
74
|
+
(message, options) => client.sendMessage(message, options),
|
|
75
|
+
[client]
|
|
76
|
+
),
|
|
77
|
+
uploadAttachment: (0, import_react2.useCallback)(
|
|
78
|
+
(blob, options) => client.uploadAttachment(blob, options),
|
|
79
|
+
[client]
|
|
80
|
+
),
|
|
81
|
+
rateMessage: (0, import_react2.useCallback)(
|
|
82
|
+
(messageId, rating) => client.rateMessage(messageId, rating),
|
|
83
|
+
[client]
|
|
84
|
+
),
|
|
85
|
+
approveAction: (0, import_react2.useCallback)(
|
|
86
|
+
(pendingId) => client.approveAction(pendingId),
|
|
87
|
+
[client]
|
|
88
|
+
),
|
|
89
|
+
cancelAction: (0, import_react2.useCallback)(
|
|
90
|
+
(pendingId) => client.cancelAction(pendingId),
|
|
91
|
+
[client]
|
|
92
|
+
),
|
|
93
|
+
setLocale: (0, import_react2.useCallback)((tag) => client.setLocale(tag), [client]),
|
|
94
|
+
toggle: (0, import_react2.useCallback)(() => client.toggle(), [client]),
|
|
95
|
+
open: (0, import_react2.useCallback)(() => client.open(), [client]),
|
|
96
|
+
close: (0, import_react2.useCallback)(() => client.close(), [client]),
|
|
97
|
+
reset: (0, import_react2.useCallback)(() => client.reset(), [client]),
|
|
98
|
+
identify: (0, import_react2.useCallback)(
|
|
99
|
+
(payload) => client.identify(payload),
|
|
100
|
+
[client]
|
|
101
|
+
),
|
|
102
|
+
setConsent: (0, import_react2.useCallback)(
|
|
103
|
+
(consent) => client.setConsent(consent),
|
|
104
|
+
[client]
|
|
105
|
+
),
|
|
106
|
+
setTraits: (0, import_react2.useCallback)(
|
|
107
|
+
(traits) => client.setTraits(traits),
|
|
108
|
+
[client]
|
|
109
|
+
),
|
|
110
|
+
submitPreChatForm: (0, import_react2.useCallback)(
|
|
111
|
+
(submission) => client.submitPreChatForm(submission),
|
|
112
|
+
[client]
|
|
113
|
+
),
|
|
114
|
+
cancelPreChatForm: (0, import_react2.useCallback)(() => client.cancelPreChatForm(), [client]),
|
|
115
|
+
fireTrigger: (0, import_react2.useCallback)(
|
|
116
|
+
(triggerId) => client.fireTrigger(triggerId),
|
|
117
|
+
[client]
|
|
118
|
+
),
|
|
119
|
+
consumePendingPrefill: (0, import_react2.useCallback)(
|
|
120
|
+
() => client.consumePendingPrefill(),
|
|
121
|
+
[client]
|
|
122
|
+
),
|
|
123
|
+
dismissIncidentBanner: (0, import_react2.useCallback)(
|
|
124
|
+
() => client.dismissIncidentBanner(),
|
|
125
|
+
[client]
|
|
126
|
+
)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/use-reduced-motion.ts
|
|
131
|
+
var import_react3 = require("react");
|
|
132
|
+
function useReducedMotion() {
|
|
133
|
+
const [reduced, setReduced] = (0, import_react3.useState)(() => {
|
|
134
|
+
if (typeof window === "undefined") return false;
|
|
135
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
136
|
+
});
|
|
137
|
+
(0, import_react3.useEffect)(() => {
|
|
138
|
+
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
139
|
+
const handler = (e) => setReduced(e.matches);
|
|
140
|
+
mq.addEventListener("change", handler);
|
|
141
|
+
return () => mq.removeEventListener("change", handler);
|
|
142
|
+
}, []);
|
|
143
|
+
return reduced;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/use-effective-theme.ts
|
|
147
|
+
var import_js2 = require("@customerhero/js");
|
|
148
|
+
|
|
149
|
+
// src/use-prefers-dark.ts
|
|
150
|
+
var import_react4 = require("react");
|
|
151
|
+
function usePrefersDark() {
|
|
152
|
+
const [prefersDark, setPrefersDark] = (0, import_react4.useState)(false);
|
|
153
|
+
(0, import_react4.useEffect)(() => {
|
|
154
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
158
|
+
const update = () => setPrefersDark(mq.matches);
|
|
159
|
+
update();
|
|
160
|
+
if (typeof mq.addEventListener === "function") {
|
|
161
|
+
mq.addEventListener("change", update);
|
|
162
|
+
return () => mq.removeEventListener("change", update);
|
|
163
|
+
}
|
|
164
|
+
mq.addListener(update);
|
|
165
|
+
return () => mq.removeListener(update);
|
|
166
|
+
}, []);
|
|
167
|
+
return prefersDark;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/use-effective-theme.ts
|
|
171
|
+
function useEffectiveTheme() {
|
|
172
|
+
const { config } = useChat();
|
|
173
|
+
const prefersDark = usePrefersDark();
|
|
174
|
+
const scheme = (0, import_js2.resolveScheme)(config.colorScheme, prefersDark);
|
|
175
|
+
const colors = (0, import_js2.effectiveColors)(config, scheme);
|
|
176
|
+
const isDark = scheme === "dark";
|
|
177
|
+
return {
|
|
178
|
+
scheme,
|
|
179
|
+
primary: colors.primary,
|
|
180
|
+
background: colors.background,
|
|
181
|
+
text: colors.text,
|
|
182
|
+
bubbleBackground: isDark ? "rgba(255,255,255,0.08)" : "#f0f0f0",
|
|
183
|
+
divider: isDark ? "rgba(255,255,255,0.12)" : "#e0e0e0",
|
|
184
|
+
size: (0, import_js2.sizePreset)(config.size),
|
|
185
|
+
radius: (0, import_js2.panelRadius)(config.cornerStyle)
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/components/chat-bubble.tsx
|
|
190
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
191
|
+
function ChatBubble({ embedded } = {}) {
|
|
192
|
+
const { toggle, config, t, isRtl } = useChat();
|
|
193
|
+
const reduced = useReducedMotion();
|
|
194
|
+
const theme = useEffectiveTheme();
|
|
195
|
+
const [mounted, setMounted] = (0, import_react5.useState)(false);
|
|
196
|
+
(0, import_react5.useEffect)(() => {
|
|
197
|
+
const id = requestAnimationFrame(() => setMounted(true));
|
|
198
|
+
return () => cancelAnimationFrame(id);
|
|
199
|
+
}, []);
|
|
200
|
+
const visible = mounted;
|
|
201
|
+
const effectivePosition = isRtl ? config.position === "bottom-right" ? "bottom-left" : "bottom-right" : config.position;
|
|
202
|
+
const colors = theme;
|
|
203
|
+
const preset = theme.size;
|
|
204
|
+
const hasLabel = !!config.launcher.label;
|
|
205
|
+
const width = hasLabel ? "auto" : preset.bubble;
|
|
206
|
+
const height = preset.bubble;
|
|
207
|
+
const borderRadius = hasLabel ? preset.bubble / 2 : "50%";
|
|
208
|
+
const style = {
|
|
209
|
+
position: embedded ? "absolute" : "fixed",
|
|
210
|
+
bottom: config.offset.bottom,
|
|
211
|
+
[effectivePosition === "bottom-left" ? "left" : "right"]: config.offset.side,
|
|
212
|
+
width,
|
|
213
|
+
height,
|
|
214
|
+
minWidth: preset.bubble,
|
|
215
|
+
paddingInline: hasLabel ? Math.round(preset.bubble * 0.35) : 0,
|
|
216
|
+
borderRadius,
|
|
217
|
+
background: colors.primary,
|
|
218
|
+
color: "#FFFFFF",
|
|
219
|
+
display: "flex",
|
|
220
|
+
alignItems: "center",
|
|
221
|
+
justifyContent: "center",
|
|
222
|
+
gap: hasLabel ? 8 : 0,
|
|
223
|
+
cursor: "pointer",
|
|
224
|
+
boxShadow: theme.scheme === "dark" ? "0 6px 20px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.06)" : "0 4px 20px rgba(0,0,0,0.15)",
|
|
225
|
+
zIndex: config.zIndex,
|
|
226
|
+
border: "none",
|
|
227
|
+
fontSize: preset.fontSize,
|
|
228
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
229
|
+
fontWeight: 500,
|
|
230
|
+
opacity: visible ? 1 : 0,
|
|
231
|
+
transform: visible ? "scale(1)" : "scale(0.6)",
|
|
232
|
+
transition: reduced ? "none" : "opacity 0.25s ease, transform 0.25s ease",
|
|
233
|
+
pointerEvents: visible ? "auto" : "none"
|
|
234
|
+
};
|
|
235
|
+
const iconSize = Math.round(preset.bubble * 0.43);
|
|
236
|
+
const dotSize = Math.max(10, Math.round(preset.bubble * 0.22));
|
|
237
|
+
const dotOffset = Math.round(preset.bubble * 0.08);
|
|
238
|
+
const dotStyle = {
|
|
239
|
+
position: "absolute",
|
|
240
|
+
top: dotOffset,
|
|
241
|
+
[effectivePosition === "bottom-left" ? "left" : "right"]: dotOffset,
|
|
242
|
+
width: dotSize,
|
|
243
|
+
height: dotSize,
|
|
244
|
+
borderRadius: "50%",
|
|
245
|
+
background: "#22c55e",
|
|
246
|
+
border: "2px solid rgba(255,255,255,0.9)",
|
|
247
|
+
pointerEvents: "none"
|
|
248
|
+
};
|
|
249
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
250
|
+
"button",
|
|
251
|
+
{
|
|
252
|
+
onClick: toggle,
|
|
253
|
+
style,
|
|
254
|
+
dir: isRtl ? "rtl" : "ltr",
|
|
255
|
+
"aria-label": t("open_chat"),
|
|
256
|
+
onMouseEnter: (e) => {
|
|
257
|
+
if (!reduced) e.currentTarget.style.transform = "scale(1.06)";
|
|
258
|
+
},
|
|
259
|
+
onMouseLeave: (e) => {
|
|
260
|
+
if (!reduced) e.currentTarget.style.transform = "scale(1)";
|
|
261
|
+
},
|
|
262
|
+
children: [
|
|
263
|
+
config.launcher.iconUrl ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
264
|
+
"img",
|
|
265
|
+
{
|
|
266
|
+
src: config.launcher.iconUrl,
|
|
267
|
+
alt: "",
|
|
268
|
+
width: iconSize,
|
|
269
|
+
height: iconSize,
|
|
270
|
+
style: { display: "block" }
|
|
271
|
+
}
|
|
272
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
273
|
+
"svg",
|
|
274
|
+
{
|
|
275
|
+
width: iconSize,
|
|
276
|
+
height: iconSize,
|
|
277
|
+
viewBox: "0 0 24 24",
|
|
278
|
+
fill: "none",
|
|
279
|
+
stroke: "currentColor",
|
|
280
|
+
strokeWidth: "2",
|
|
281
|
+
strokeLinecap: "round",
|
|
282
|
+
strokeLinejoin: "round",
|
|
283
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" })
|
|
284
|
+
}
|
|
285
|
+
),
|
|
286
|
+
hasLabel && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: config.launcher.label }),
|
|
287
|
+
config.launcher.showOnlineDot && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: dotStyle, "aria-hidden": true })
|
|
288
|
+
]
|
|
289
|
+
}
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/components/chat-window.tsx
|
|
294
|
+
var import_react11 = require("react");
|
|
295
|
+
|
|
296
|
+
// src/components/chat-header.tsx
|
|
297
|
+
var import_react6 = require("react");
|
|
298
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
299
|
+
function ChatHeader() {
|
|
300
|
+
const { config, close, reset, t } = useChat();
|
|
301
|
+
const reduced = useReducedMotion();
|
|
302
|
+
const theme = useEffectiveTheme();
|
|
303
|
+
const [menuOpen, setMenuOpen] = (0, import_react6.useState)(false);
|
|
304
|
+
const menuRef = (0, import_react6.useRef)(null);
|
|
305
|
+
(0, import_react6.useEffect)(() => {
|
|
306
|
+
if (!menuOpen) return;
|
|
307
|
+
const handleClick = (e) => {
|
|
308
|
+
if (menuRef.current && !menuRef.current.contains(e.target)) {
|
|
309
|
+
setMenuOpen(false);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
document.addEventListener("mousedown", handleClick);
|
|
313
|
+
return () => document.removeEventListener("mousedown", handleClick);
|
|
314
|
+
}, [menuOpen]);
|
|
315
|
+
const headerStyle = {
|
|
316
|
+
background: theme.primary,
|
|
317
|
+
padding: 16,
|
|
318
|
+
display: "flex",
|
|
319
|
+
alignItems: "center",
|
|
320
|
+
gap: 12
|
|
321
|
+
};
|
|
322
|
+
const avatarStyle = {
|
|
323
|
+
width: 36,
|
|
324
|
+
height: 36,
|
|
325
|
+
borderRadius: "50%",
|
|
326
|
+
background: "rgba(255,255,255,0.2)",
|
|
327
|
+
display: "flex",
|
|
328
|
+
alignItems: "center",
|
|
329
|
+
justifyContent: "center",
|
|
330
|
+
flexShrink: 0
|
|
331
|
+
};
|
|
332
|
+
const titleStyle = {
|
|
333
|
+
fontSize: 14,
|
|
334
|
+
fontWeight: 600,
|
|
335
|
+
color: "white",
|
|
336
|
+
margin: 0
|
|
337
|
+
};
|
|
338
|
+
const subtitleStyle = {
|
|
339
|
+
fontSize: 11,
|
|
340
|
+
color: "rgba(255,255,255,0.7)",
|
|
341
|
+
margin: 0
|
|
342
|
+
};
|
|
343
|
+
const headerButtonStyle = {
|
|
344
|
+
background: "none",
|
|
345
|
+
border: "none",
|
|
346
|
+
color: "white",
|
|
347
|
+
cursor: "pointer",
|
|
348
|
+
opacity: 0.7,
|
|
349
|
+
padding: 4
|
|
350
|
+
};
|
|
351
|
+
const isDark = theme.scheme === "dark";
|
|
352
|
+
const menuStyle = {
|
|
353
|
+
position: "absolute",
|
|
354
|
+
top: "100%",
|
|
355
|
+
right: 0,
|
|
356
|
+
marginTop: 4,
|
|
357
|
+
background: theme.background,
|
|
358
|
+
border: `1px solid ${theme.divider}`,
|
|
359
|
+
borderRadius: 8,
|
|
360
|
+
boxShadow: isDark ? "0 4px 16px rgba(0,0,0,0.5)" : "0 4px 16px rgba(0,0,0,0.15)",
|
|
361
|
+
minWidth: 180,
|
|
362
|
+
overflow: "hidden",
|
|
363
|
+
zIndex: 10,
|
|
364
|
+
transformOrigin: "top right",
|
|
365
|
+
animation: reduced ? "none" : "ch-menu-in 0.15s ease"
|
|
366
|
+
};
|
|
367
|
+
const menuItemStyle = {
|
|
368
|
+
display: "flex",
|
|
369
|
+
alignItems: "center",
|
|
370
|
+
gap: 8,
|
|
371
|
+
width: "100%",
|
|
372
|
+
padding: "10px 14px",
|
|
373
|
+
border: "none",
|
|
374
|
+
background: "none",
|
|
375
|
+
cursor: "pointer",
|
|
376
|
+
fontSize: 13,
|
|
377
|
+
color: theme.text,
|
|
378
|
+
textAlign: "left",
|
|
379
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"
|
|
380
|
+
};
|
|
381
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: headerStyle, children: [
|
|
382
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: avatarStyle, children: config.avatarUrl ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
383
|
+
"img",
|
|
384
|
+
{
|
|
385
|
+
src: config.avatarUrl,
|
|
386
|
+
alt: "",
|
|
387
|
+
style: { width: 36, height: 36, borderRadius: "50%" }
|
|
388
|
+
}
|
|
389
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
390
|
+
"svg",
|
|
391
|
+
{
|
|
392
|
+
width: "18",
|
|
393
|
+
height: "18",
|
|
394
|
+
viewBox: "0 0 24 24",
|
|
395
|
+
fill: "none",
|
|
396
|
+
stroke: "white",
|
|
397
|
+
strokeWidth: "2",
|
|
398
|
+
strokeLinecap: "round",
|
|
399
|
+
strokeLinejoin: "round",
|
|
400
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" })
|
|
401
|
+
}
|
|
402
|
+
) }),
|
|
403
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { flex: 1 }, children: [
|
|
404
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { style: titleStyle, children: config.title }),
|
|
405
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { style: subtitleStyle, children: t("online") })
|
|
406
|
+
] }),
|
|
407
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { ref: menuRef, style: { position: "relative" }, children: [
|
|
408
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
409
|
+
"button",
|
|
410
|
+
{
|
|
411
|
+
onClick: () => setMenuOpen(!menuOpen),
|
|
412
|
+
style: headerButtonStyle,
|
|
413
|
+
"aria-label": t("menu"),
|
|
414
|
+
onMouseEnter: (e) => {
|
|
415
|
+
e.currentTarget.style.opacity = "1";
|
|
416
|
+
},
|
|
417
|
+
onMouseLeave: (e) => {
|
|
418
|
+
e.currentTarget.style.opacity = "0.7";
|
|
419
|
+
},
|
|
420
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
421
|
+
"svg",
|
|
422
|
+
{
|
|
423
|
+
width: "18",
|
|
424
|
+
height: "18",
|
|
425
|
+
viewBox: "0 0 24 24",
|
|
426
|
+
fill: "none",
|
|
427
|
+
stroke: "currentColor",
|
|
428
|
+
strokeWidth: "2",
|
|
429
|
+
strokeLinecap: "round",
|
|
430
|
+
strokeLinejoin: "round",
|
|
431
|
+
children: [
|
|
432
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "12", cy: "5", r: "1" }),
|
|
433
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "12", cy: "12", r: "1" }),
|
|
434
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "12", cy: "19", r: "1" })
|
|
435
|
+
]
|
|
436
|
+
}
|
|
437
|
+
)
|
|
438
|
+
}
|
|
439
|
+
),
|
|
440
|
+
menuOpen && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: menuStyle, children: [
|
|
441
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("style", { children: `@keyframes ch-menu-in {
|
|
442
|
+
from { opacity: 0; transform: scale(0.9); }
|
|
443
|
+
to { opacity: 1; transform: scale(1); }
|
|
444
|
+
}` }),
|
|
445
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
446
|
+
"button",
|
|
447
|
+
{
|
|
448
|
+
style: menuItemStyle,
|
|
449
|
+
onClick: () => {
|
|
450
|
+
setMenuOpen(false);
|
|
451
|
+
reset();
|
|
452
|
+
},
|
|
453
|
+
onMouseEnter: (e) => {
|
|
454
|
+
e.currentTarget.style.background = theme.bubbleBackground;
|
|
455
|
+
},
|
|
456
|
+
onMouseLeave: (e) => {
|
|
457
|
+
e.currentTarget.style.background = "none";
|
|
458
|
+
},
|
|
459
|
+
children: [
|
|
460
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
461
|
+
"svg",
|
|
462
|
+
{
|
|
463
|
+
width: "14",
|
|
464
|
+
height: "14",
|
|
465
|
+
viewBox: "0 0 24 24",
|
|
466
|
+
fill: "none",
|
|
467
|
+
stroke: "currentColor",
|
|
468
|
+
strokeWidth: "2",
|
|
469
|
+
strokeLinecap: "round",
|
|
470
|
+
strokeLinejoin: "round",
|
|
471
|
+
children: [
|
|
472
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M12 20h9" }),
|
|
473
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z" })
|
|
474
|
+
]
|
|
475
|
+
}
|
|
476
|
+
),
|
|
477
|
+
t("new_conversation")
|
|
478
|
+
]
|
|
479
|
+
}
|
|
480
|
+
)
|
|
481
|
+
] })
|
|
482
|
+
] }),
|
|
483
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
484
|
+
"button",
|
|
485
|
+
{
|
|
486
|
+
onClick: close,
|
|
487
|
+
style: headerButtonStyle,
|
|
488
|
+
"aria-label": t("close_chat"),
|
|
489
|
+
onMouseEnter: (e) => {
|
|
490
|
+
e.currentTarget.style.opacity = "1";
|
|
491
|
+
},
|
|
492
|
+
onMouseLeave: (e) => {
|
|
493
|
+
e.currentTarget.style.opacity = "0.7";
|
|
494
|
+
},
|
|
495
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
496
|
+
"svg",
|
|
497
|
+
{
|
|
498
|
+
width: "20",
|
|
499
|
+
height: "20",
|
|
500
|
+
viewBox: "0 0 24 24",
|
|
501
|
+
fill: "none",
|
|
502
|
+
stroke: "currentColor",
|
|
503
|
+
strokeWidth: "2",
|
|
504
|
+
children: [
|
|
505
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
506
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
507
|
+
]
|
|
508
|
+
}
|
|
509
|
+
)
|
|
510
|
+
}
|
|
511
|
+
)
|
|
512
|
+
] });
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// src/components/chat-messages.tsx
|
|
516
|
+
var import_react8 = require("react");
|
|
517
|
+
|
|
518
|
+
// src/markdown/render.tsx
|
|
519
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
520
|
+
function parseBlocks(source) {
|
|
521
|
+
const lines = source.replace(/\r\n?/g, "\n").split("\n");
|
|
522
|
+
const blocks = [];
|
|
523
|
+
let i = 0;
|
|
524
|
+
while (i < lines.length) {
|
|
525
|
+
const line = lines[i];
|
|
526
|
+
if (line.trim() === "") {
|
|
527
|
+
i++;
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
const fenceMatch = line.match(/^```(.*)$/);
|
|
531
|
+
if (fenceMatch) {
|
|
532
|
+
const lang = fenceMatch[1].trim() || void 0;
|
|
533
|
+
const body2 = [];
|
|
534
|
+
i++;
|
|
535
|
+
while (i < lines.length && !/^```\s*$/.test(lines[i])) {
|
|
536
|
+
body2.push(lines[i]);
|
|
537
|
+
i++;
|
|
538
|
+
}
|
|
539
|
+
if (i < lines.length) i++;
|
|
540
|
+
blocks.push({ kind: "code", lines: body2, lang });
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
const headingMatch = line.match(/^(#{1,6})\s+(.*?)\s*#*\s*$/);
|
|
544
|
+
if (headingMatch) {
|
|
545
|
+
blocks.push({
|
|
546
|
+
kind: "heading",
|
|
547
|
+
level: headingMatch[1].length,
|
|
548
|
+
lines: [headingMatch[2]]
|
|
549
|
+
});
|
|
550
|
+
i++;
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
if (/^(\s*)[-*+]\s+/.test(line)) {
|
|
554
|
+
const body2 = [];
|
|
555
|
+
while (i < lines.length && /^(\s*)[-*+]\s+/.test(lines[i])) {
|
|
556
|
+
body2.push(lines[i].replace(/^(\s*)[-*+]\s+/, ""));
|
|
557
|
+
i++;
|
|
558
|
+
}
|
|
559
|
+
blocks.push({ kind: "ul", lines: body2 });
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
if (/^(\s*)\d+\.\s+/.test(line)) {
|
|
563
|
+
const body2 = [];
|
|
564
|
+
while (i < lines.length && /^(\s*)\d+\.\s+/.test(lines[i])) {
|
|
565
|
+
body2.push(lines[i].replace(/^(\s*)\d+\.\s+/, ""));
|
|
566
|
+
i++;
|
|
567
|
+
}
|
|
568
|
+
blocks.push({ kind: "ol", lines: body2 });
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
if (/^>\s?/.test(line)) {
|
|
572
|
+
const body2 = [];
|
|
573
|
+
while (i < lines.length && /^>\s?/.test(lines[i])) {
|
|
574
|
+
body2.push(lines[i].replace(/^>\s?/, ""));
|
|
575
|
+
i++;
|
|
576
|
+
}
|
|
577
|
+
blocks.push({ kind: "blockquote", lines: body2 });
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
const body = [line];
|
|
581
|
+
i++;
|
|
582
|
+
while (i < lines.length) {
|
|
583
|
+
const next = lines[i];
|
|
584
|
+
if (next.trim() === "") break;
|
|
585
|
+
if (/^```/.test(next) || /^#{1,6}\s/.test(next) || /^(\s*)[-*+]\s+/.test(next) || /^(\s*)\d+\.\s+/.test(next) || /^>\s?/.test(next)) {
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
body.push(next);
|
|
589
|
+
i++;
|
|
590
|
+
}
|
|
591
|
+
blocks.push({ kind: "paragraph", lines: body });
|
|
592
|
+
}
|
|
593
|
+
return blocks;
|
|
594
|
+
}
|
|
595
|
+
function findClosing(text, from, end) {
|
|
596
|
+
let i = from;
|
|
597
|
+
while (i <= text.length - end.length) {
|
|
598
|
+
const c = text[i];
|
|
599
|
+
if (c === "\\") {
|
|
600
|
+
i += 2;
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
if (text.startsWith(end, i)) return i;
|
|
604
|
+
i++;
|
|
605
|
+
}
|
|
606
|
+
return -1;
|
|
607
|
+
}
|
|
608
|
+
function renderInlineText(text, ctx) {
|
|
609
|
+
const out = [];
|
|
610
|
+
let buffer = "";
|
|
611
|
+
let i = 0;
|
|
612
|
+
const flushBuffer = () => {
|
|
613
|
+
if (buffer.length > 0) {
|
|
614
|
+
out.push(buffer);
|
|
615
|
+
buffer = "";
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
while (i < text.length) {
|
|
619
|
+
const c = text[i];
|
|
620
|
+
if (c === "\\" && i + 1 < text.length) {
|
|
621
|
+
buffer += text[i + 1];
|
|
622
|
+
i += 2;
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
if (c === " " && text[i + 1] === " " && text[i + 2] === "\n") {
|
|
626
|
+
flushBuffer();
|
|
627
|
+
out.push(/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("br", {}, ctx.nextKey()));
|
|
628
|
+
i += 3;
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
if (c === "\n") {
|
|
632
|
+
buffer += " ";
|
|
633
|
+
i++;
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
if (c === "`") {
|
|
637
|
+
const close = findClosing(text, i + 1, "`");
|
|
638
|
+
if (close !== -1) {
|
|
639
|
+
flushBuffer();
|
|
640
|
+
out.push(
|
|
641
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
642
|
+
"code",
|
|
643
|
+
{
|
|
644
|
+
style: {
|
|
645
|
+
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
|
|
646
|
+
fontSize: "0.92em",
|
|
647
|
+
background: "rgba(0,0,0,0.06)",
|
|
648
|
+
padding: "1px 4px",
|
|
649
|
+
borderRadius: 3
|
|
650
|
+
},
|
|
651
|
+
children: text.slice(i + 1, close)
|
|
652
|
+
},
|
|
653
|
+
ctx.nextKey()
|
|
654
|
+
)
|
|
655
|
+
);
|
|
656
|
+
i = close + 1;
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
if ((text.startsWith("**", i) || text.startsWith("__", i)) && i + 2 < text.length) {
|
|
661
|
+
const marker = text.slice(i, i + 2);
|
|
662
|
+
const close = findClosing(text, i + 2, marker);
|
|
663
|
+
if (close !== -1 && close > i + 2) {
|
|
664
|
+
flushBuffer();
|
|
665
|
+
const inner = renderInlineText(text.slice(i + 2, close), ctx);
|
|
666
|
+
out.push(/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("strong", { children: inner }, ctx.nextKey()));
|
|
667
|
+
i = close + 2;
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (c === "*" || c === "_") {
|
|
672
|
+
const prev = i === 0 ? " " : text[i - 1];
|
|
673
|
+
const isWordBoundaryBefore = c === "*" || !/\w/.test(prev);
|
|
674
|
+
if (isWordBoundaryBefore) {
|
|
675
|
+
const close = findClosing(text, i + 1, c);
|
|
676
|
+
const prevOfClose = close === -1 ? " " : close + 1 < text.length ? text[close + 1] : " ";
|
|
677
|
+
const isWordBoundaryAfter = c === "*" || !/\w/.test(prevOfClose);
|
|
678
|
+
if (close !== -1 && close > i + 1 && text[close + 1] !== c && isWordBoundaryAfter) {
|
|
679
|
+
flushBuffer();
|
|
680
|
+
const inner = renderInlineText(text.slice(i + 1, close), ctx);
|
|
681
|
+
out.push(/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("em", { children: inner }, ctx.nextKey()));
|
|
682
|
+
i = close + 1;
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
if (c === "[") {
|
|
688
|
+
const closeLabel = findClosing(text, i + 1, "]");
|
|
689
|
+
if (closeLabel !== -1 && text[closeLabel + 1] === "(") {
|
|
690
|
+
const closeUrl = findClosing(text, closeLabel + 2, ")");
|
|
691
|
+
if (closeUrl !== -1) {
|
|
692
|
+
const label = text.slice(i + 1, closeLabel);
|
|
693
|
+
const url = text.slice(closeLabel + 2, closeUrl).trim();
|
|
694
|
+
if (isSafeUrl(url)) {
|
|
695
|
+
flushBuffer();
|
|
696
|
+
out.push(
|
|
697
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
698
|
+
"a",
|
|
699
|
+
{
|
|
700
|
+
href: url,
|
|
701
|
+
target: "_blank",
|
|
702
|
+
rel: "noopener noreferrer",
|
|
703
|
+
style: { color: ctx.linkColor, textDecoration: "underline" },
|
|
704
|
+
children: renderInlineText(label, ctx)
|
|
705
|
+
},
|
|
706
|
+
ctx.nextKey()
|
|
707
|
+
)
|
|
708
|
+
);
|
|
709
|
+
i = closeUrl + 1;
|
|
710
|
+
continue;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
if (closeLabel !== -1 && ctx.sources && ctx.sources.length > 0) {
|
|
715
|
+
const body = text.slice(i + 1, closeLabel).trim();
|
|
716
|
+
const parts = body.split(/\s*,\s*/).filter((s) => s.length > 0);
|
|
717
|
+
const indices = parts.map((p) => Number(p));
|
|
718
|
+
const allValid = parts.length > 0 && indices.every(
|
|
719
|
+
(n) => Number.isInteger(n) && n >= 1 && n <= (ctx.sources?.length ?? 0)
|
|
720
|
+
);
|
|
721
|
+
if (allValid) {
|
|
722
|
+
flushBuffer();
|
|
723
|
+
out.push(
|
|
724
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("sup", { style: { whiteSpace: "nowrap" }, children: indices.map((n, idx) => {
|
|
725
|
+
const src = ctx.sources[n - 1];
|
|
726
|
+
const content = /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
727
|
+
"span",
|
|
728
|
+
{
|
|
729
|
+
style: {
|
|
730
|
+
fontSize: "0.75em",
|
|
731
|
+
color: ctx.linkColor,
|
|
732
|
+
cursor: src.url ? "pointer" : "default"
|
|
733
|
+
},
|
|
734
|
+
title: src.heading ? `${src.title} \u2014 ${src.heading}` : src.title,
|
|
735
|
+
children: [
|
|
736
|
+
"[",
|
|
737
|
+
n,
|
|
738
|
+
"]"
|
|
739
|
+
]
|
|
740
|
+
}
|
|
741
|
+
);
|
|
742
|
+
const separator = idx > 0 ? " " : null;
|
|
743
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
744
|
+
separator,
|
|
745
|
+
src.url ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
746
|
+
"a",
|
|
747
|
+
{
|
|
748
|
+
href: src.url,
|
|
749
|
+
target: "_blank",
|
|
750
|
+
rel: "noopener noreferrer",
|
|
751
|
+
style: {
|
|
752
|
+
color: ctx.linkColor,
|
|
753
|
+
textDecoration: "none"
|
|
754
|
+
},
|
|
755
|
+
children: content
|
|
756
|
+
}
|
|
757
|
+
) : content
|
|
758
|
+
] }, `${ctx.keyRoot}-cit-${idx}`);
|
|
759
|
+
}) }, ctx.nextKey())
|
|
760
|
+
);
|
|
761
|
+
i = closeLabel + 1;
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
buffer += c;
|
|
767
|
+
i++;
|
|
768
|
+
}
|
|
769
|
+
flushBuffer();
|
|
770
|
+
return out;
|
|
771
|
+
}
|
|
772
|
+
function isSafeUrl(url) {
|
|
773
|
+
if (/^https?:\/\//i.test(url)) return true;
|
|
774
|
+
if (/^mailto:/i.test(url)) return true;
|
|
775
|
+
if (/^tel:/i.test(url)) return true;
|
|
776
|
+
if (/^\/[^/]/.test(url) || /^#/.test(url)) return true;
|
|
777
|
+
return false;
|
|
778
|
+
}
|
|
779
|
+
function renderMarkdown(source, opts = {}) {
|
|
780
|
+
const blocks = parseBlocks(source);
|
|
781
|
+
const linkColor = opts.linkColor ?? "#6C3CE1";
|
|
782
|
+
let keyCounter = 0;
|
|
783
|
+
const ctx = {
|
|
784
|
+
sources: opts.sources,
|
|
785
|
+
linkColor,
|
|
786
|
+
keyRoot: "md",
|
|
787
|
+
nextKey: () => `md-${keyCounter++}`
|
|
788
|
+
};
|
|
789
|
+
const renderInline = (line) => renderInlineText(line, ctx);
|
|
790
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: blocks.map((block, idx) => {
|
|
791
|
+
const key = `b-${idx}`;
|
|
792
|
+
switch (block.kind) {
|
|
793
|
+
case "heading": {
|
|
794
|
+
const level = block.level ?? 1;
|
|
795
|
+
const style = {
|
|
796
|
+
margin: "8px 0 4px",
|
|
797
|
+
fontWeight: 600,
|
|
798
|
+
fontSize: level <= 2 ? "1.15em" : level === 3 ? "1.05em" : "1em"
|
|
799
|
+
};
|
|
800
|
+
const children = renderInline(block.lines[0] ?? "");
|
|
801
|
+
if (level === 1)
|
|
802
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h1", { style, children }, key);
|
|
803
|
+
if (level === 2)
|
|
804
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { style, children }, key);
|
|
805
|
+
if (level === 3)
|
|
806
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h3", { style, children }, key);
|
|
807
|
+
if (level === 4)
|
|
808
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h4", { style, children }, key);
|
|
809
|
+
if (level === 5)
|
|
810
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h5", { style, children }, key);
|
|
811
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h6", { style, children }, key);
|
|
812
|
+
}
|
|
813
|
+
case "paragraph":
|
|
814
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: { margin: "0 0 8px", lineHeight: 1.5 }, children: renderInline(block.lines.join("\n")) }, key);
|
|
815
|
+
case "ul":
|
|
816
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
817
|
+
"ul",
|
|
818
|
+
{
|
|
819
|
+
style: {
|
|
820
|
+
margin: "0 0 8px",
|
|
821
|
+
paddingLeft: 20,
|
|
822
|
+
lineHeight: 1.5,
|
|
823
|
+
listStyleType: "disc",
|
|
824
|
+
listStylePosition: "outside"
|
|
825
|
+
},
|
|
826
|
+
children: block.lines.map((l, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { style: { display: "list-item" }, children: renderInline(l) }, i))
|
|
827
|
+
},
|
|
828
|
+
key
|
|
829
|
+
);
|
|
830
|
+
case "ol":
|
|
831
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
832
|
+
"ol",
|
|
833
|
+
{
|
|
834
|
+
style: {
|
|
835
|
+
margin: "0 0 8px",
|
|
836
|
+
paddingLeft: 22,
|
|
837
|
+
lineHeight: 1.5,
|
|
838
|
+
listStyleType: "decimal",
|
|
839
|
+
listStylePosition: "outside"
|
|
840
|
+
},
|
|
841
|
+
children: block.lines.map((l, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { style: { display: "list-item" }, children: renderInline(l) }, i))
|
|
842
|
+
},
|
|
843
|
+
key
|
|
844
|
+
);
|
|
845
|
+
case "code":
|
|
846
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
847
|
+
"pre",
|
|
848
|
+
{
|
|
849
|
+
style: {
|
|
850
|
+
margin: "0 0 8px",
|
|
851
|
+
padding: "10px 12px",
|
|
852
|
+
background: "rgba(0,0,0,0.06)",
|
|
853
|
+
borderRadius: 6,
|
|
854
|
+
overflowX: "auto",
|
|
855
|
+
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
|
|
856
|
+
fontSize: "0.88em",
|
|
857
|
+
lineHeight: 1.45
|
|
858
|
+
},
|
|
859
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("code", { children: block.lines.join("\n") })
|
|
860
|
+
},
|
|
861
|
+
key
|
|
862
|
+
);
|
|
863
|
+
case "blockquote":
|
|
864
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
865
|
+
"blockquote",
|
|
866
|
+
{
|
|
867
|
+
style: {
|
|
868
|
+
margin: "0 0 8px",
|
|
869
|
+
padding: "4px 0 4px 10px",
|
|
870
|
+
borderLeft: "3px solid rgba(0,0,0,0.15)",
|
|
871
|
+
color: "rgba(0,0,0,0.75)",
|
|
872
|
+
fontStyle: "italic"
|
|
873
|
+
},
|
|
874
|
+
children: renderInline(block.lines.join("\n"))
|
|
875
|
+
},
|
|
876
|
+
key
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
}) });
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// src/components/action-confirmation-card.tsx
|
|
883
|
+
var import_react7 = require("react");
|
|
884
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
885
|
+
function ActionConfirmationCard({
|
|
886
|
+
block,
|
|
887
|
+
primaryColor,
|
|
888
|
+
t,
|
|
889
|
+
onApprove,
|
|
890
|
+
onCancel
|
|
891
|
+
}) {
|
|
892
|
+
const [chosen, setChosen] = (0, import_react7.useState)(null);
|
|
893
|
+
const [showSpinner, setShowSpinner] = (0, import_react7.useState)(false);
|
|
894
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
895
|
+
const [showSummary, setShowSummary] = (0, import_react7.useState)(false);
|
|
896
|
+
const handle = async (choice) => {
|
|
897
|
+
if (chosen) return;
|
|
898
|
+
setChosen(choice);
|
|
899
|
+
setError(null);
|
|
900
|
+
const spinnerTimer = window.setTimeout(() => setShowSpinner(true), 800);
|
|
901
|
+
try {
|
|
902
|
+
const fn = choice === "approve" ? onApprove : onCancel;
|
|
903
|
+
await fn(block.pendingToolCallId);
|
|
904
|
+
} catch (e) {
|
|
905
|
+
const msg = e instanceof Error ? e.message : t("action_failed");
|
|
906
|
+
setError(msg);
|
|
907
|
+
setChosen(null);
|
|
908
|
+
} finally {
|
|
909
|
+
window.clearTimeout(spinnerTimer);
|
|
910
|
+
setShowSpinner(false);
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
const cardStyle = {
|
|
914
|
+
marginTop: 6,
|
|
915
|
+
padding: 12,
|
|
916
|
+
borderRadius: 12,
|
|
917
|
+
border: "1px solid #e0e0e0",
|
|
918
|
+
background: "#fff",
|
|
919
|
+
display: "flex",
|
|
920
|
+
flexDirection: "column",
|
|
921
|
+
gap: 8,
|
|
922
|
+
fontSize: 13,
|
|
923
|
+
lineHeight: 1.4
|
|
924
|
+
};
|
|
925
|
+
const titleStyle = {
|
|
926
|
+
fontWeight: 600,
|
|
927
|
+
color: "#222"
|
|
928
|
+
};
|
|
929
|
+
const disclosureBtn = {
|
|
930
|
+
background: "none",
|
|
931
|
+
border: "none",
|
|
932
|
+
padding: 0,
|
|
933
|
+
color: primaryColor,
|
|
934
|
+
fontSize: 12,
|
|
935
|
+
cursor: "pointer",
|
|
936
|
+
textAlign: "left",
|
|
937
|
+
fontFamily: "inherit"
|
|
938
|
+
};
|
|
939
|
+
const summaryStyle = {
|
|
940
|
+
color: "#555",
|
|
941
|
+
background: "#fafafa",
|
|
942
|
+
padding: 8,
|
|
943
|
+
borderRadius: 8,
|
|
944
|
+
whiteSpace: "pre-wrap"
|
|
945
|
+
};
|
|
946
|
+
const buttonRow = {
|
|
947
|
+
display: "flex",
|
|
948
|
+
gap: 8,
|
|
949
|
+
marginTop: 4
|
|
950
|
+
};
|
|
951
|
+
const baseBtn = (variant) => ({
|
|
952
|
+
flex: 1,
|
|
953
|
+
padding: "8px 12px",
|
|
954
|
+
borderRadius: 8,
|
|
955
|
+
fontSize: 13,
|
|
956
|
+
fontWeight: 500,
|
|
957
|
+
cursor: chosen ? "default" : "pointer",
|
|
958
|
+
border: variant === "primary" ? `1px solid ${primaryColor}` : "1px solid #ddd",
|
|
959
|
+
background: variant === "primary" ? primaryColor : "#fff",
|
|
960
|
+
color: variant === "primary" ? "#fff" : "#333",
|
|
961
|
+
opacity: chosen && chosen !== (variant === "primary" ? "approve" : "cancel") ? 0.5 : 1,
|
|
962
|
+
transition: "opacity 0.15s",
|
|
963
|
+
display: "flex",
|
|
964
|
+
alignItems: "center",
|
|
965
|
+
justifyContent: "center",
|
|
966
|
+
gap: 6,
|
|
967
|
+
fontFamily: "inherit"
|
|
968
|
+
});
|
|
969
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: cardStyle, role: "group", "aria-label": block.title, children: [
|
|
970
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: titleStyle, children: block.title }),
|
|
971
|
+
block.summary && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
972
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
973
|
+
"button",
|
|
974
|
+
{
|
|
975
|
+
type: "button",
|
|
976
|
+
style: disclosureBtn,
|
|
977
|
+
onClick: () => setShowSummary((s) => !s),
|
|
978
|
+
"aria-expanded": showSummary,
|
|
979
|
+
children: [
|
|
980
|
+
showSummary ? "\u25BE" : "\u25B8",
|
|
981
|
+
" ",
|
|
982
|
+
t("action_what_will_happen")
|
|
983
|
+
]
|
|
984
|
+
}
|
|
985
|
+
),
|
|
986
|
+
showSummary && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: summaryStyle, children: block.summary })
|
|
987
|
+
] }),
|
|
988
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: buttonRow, children: [
|
|
989
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
990
|
+
"button",
|
|
991
|
+
{
|
|
992
|
+
type: "button",
|
|
993
|
+
style: baseBtn("ghost"),
|
|
994
|
+
disabled: chosen !== null,
|
|
995
|
+
onClick: () => handle("cancel"),
|
|
996
|
+
children: chosen === "cancel" && showSpinner ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, { color: "#333" }) : t("action_cancel")
|
|
997
|
+
}
|
|
998
|
+
),
|
|
999
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1000
|
+
"button",
|
|
1001
|
+
{
|
|
1002
|
+
type: "button",
|
|
1003
|
+
style: baseBtn("primary"),
|
|
1004
|
+
disabled: chosen !== null,
|
|
1005
|
+
onClick: () => handle("approve"),
|
|
1006
|
+
children: chosen === "approve" && showSpinner ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, { color: "#fff" }) : t("action_approve")
|
|
1007
|
+
}
|
|
1008
|
+
)
|
|
1009
|
+
] }),
|
|
1010
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { role: "alert", style: { color: "#b91c1c", fontSize: 12 }, children: error })
|
|
1011
|
+
] });
|
|
1012
|
+
}
|
|
1013
|
+
function Spinner({ color }) {
|
|
1014
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
1015
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("style", { children: `@keyframes ch-spin { to { transform: rotate(360deg); } }` }),
|
|
1016
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1017
|
+
"span",
|
|
1018
|
+
{
|
|
1019
|
+
"aria-hidden": "true",
|
|
1020
|
+
style: {
|
|
1021
|
+
width: 14,
|
|
1022
|
+
height: 14,
|
|
1023
|
+
borderRadius: "50%",
|
|
1024
|
+
border: `2px solid ${color}`,
|
|
1025
|
+
borderTopColor: "transparent",
|
|
1026
|
+
animation: "ch-spin 0.8s linear infinite",
|
|
1027
|
+
display: "inline-block"
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
)
|
|
1031
|
+
] });
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
// src/components/chat-messages.tsx
|
|
1035
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1036
|
+
function MessageStatusPill({
|
|
1037
|
+
status,
|
|
1038
|
+
t
|
|
1039
|
+
}) {
|
|
1040
|
+
const failed = status === "failed";
|
|
1041
|
+
const containerStyle = {
|
|
1042
|
+
display: "flex",
|
|
1043
|
+
alignItems: "center",
|
|
1044
|
+
justifyContent: "flex-end",
|
|
1045
|
+
gap: 4,
|
|
1046
|
+
marginTop: 2,
|
|
1047
|
+
fontSize: 11,
|
|
1048
|
+
color: failed ? "#b91c1c" : "#888"
|
|
1049
|
+
};
|
|
1050
|
+
const labelKey = status === "sending" ? "status_sending" : status === "sent" ? "status_sent" : "status_failed";
|
|
1051
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: containerStyle, "aria-live": "polite", children: [
|
|
1052
|
+
status === "sending" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ClockIcon, {}),
|
|
1053
|
+
status === "sent" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CheckIcon, {}),
|
|
1054
|
+
status === "failed" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ExclamationIcon, {}),
|
|
1055
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: t(labelKey) })
|
|
1056
|
+
] });
|
|
1057
|
+
}
|
|
1058
|
+
function ClockIcon() {
|
|
1059
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
1060
|
+
"svg",
|
|
1061
|
+
{
|
|
1062
|
+
width: "11",
|
|
1063
|
+
height: "11",
|
|
1064
|
+
viewBox: "0 0 24 24",
|
|
1065
|
+
fill: "none",
|
|
1066
|
+
stroke: "currentColor",
|
|
1067
|
+
strokeWidth: "2",
|
|
1068
|
+
strokeLinecap: "round",
|
|
1069
|
+
strokeLinejoin: "round",
|
|
1070
|
+
"aria-hidden": "true",
|
|
1071
|
+
children: [
|
|
1072
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
1073
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("polyline", { points: "12 6 12 12 16 14" })
|
|
1074
|
+
]
|
|
1075
|
+
}
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
function CheckIcon() {
|
|
1079
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1080
|
+
"svg",
|
|
1081
|
+
{
|
|
1082
|
+
width: "11",
|
|
1083
|
+
height: "11",
|
|
1084
|
+
viewBox: "0 0 24 24",
|
|
1085
|
+
fill: "none",
|
|
1086
|
+
stroke: "currentColor",
|
|
1087
|
+
strokeWidth: "2.5",
|
|
1088
|
+
strokeLinecap: "round",
|
|
1089
|
+
strokeLinejoin: "round",
|
|
1090
|
+
"aria-hidden": "true",
|
|
1091
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("polyline", { points: "20 6 9 17 4 12" })
|
|
1092
|
+
}
|
|
1093
|
+
);
|
|
1094
|
+
}
|
|
1095
|
+
function ExclamationIcon() {
|
|
1096
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
1097
|
+
"svg",
|
|
1098
|
+
{
|
|
1099
|
+
width: "11",
|
|
1100
|
+
height: "11",
|
|
1101
|
+
viewBox: "0 0 24 24",
|
|
1102
|
+
fill: "none",
|
|
1103
|
+
stroke: "currentColor",
|
|
1104
|
+
strokeWidth: "2",
|
|
1105
|
+
strokeLinecap: "round",
|
|
1106
|
+
strokeLinejoin: "round",
|
|
1107
|
+
"aria-hidden": "true",
|
|
1108
|
+
children: [
|
|
1109
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
1110
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("line", { x1: "12", y1: "8", x2: "12", y2: "12" }),
|
|
1111
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })
|
|
1112
|
+
]
|
|
1113
|
+
}
|
|
1114
|
+
);
|
|
1115
|
+
}
|
|
1116
|
+
function MessageRatingButtons({
|
|
1117
|
+
messageId,
|
|
1118
|
+
onRate,
|
|
1119
|
+
primaryColor,
|
|
1120
|
+
t,
|
|
1121
|
+
reduced
|
|
1122
|
+
}) {
|
|
1123
|
+
const [rated, setRated] = (0, import_react8.useState)(null);
|
|
1124
|
+
const handleRate = (rating) => {
|
|
1125
|
+
setRated(rating);
|
|
1126
|
+
onRate(messageId, rating);
|
|
1127
|
+
};
|
|
1128
|
+
const buttonStyle = (isRated) => ({
|
|
1129
|
+
background: isRated ? `${primaryColor}11` : "none",
|
|
1130
|
+
border: `1px solid ${isRated ? primaryColor : "#ddd"}`,
|
|
1131
|
+
borderRadius: 4,
|
|
1132
|
+
padding: "4px 6px",
|
|
1133
|
+
cursor: rated ? "default" : "pointer",
|
|
1134
|
+
color: isRated ? primaryColor : "#888",
|
|
1135
|
+
display: "flex",
|
|
1136
|
+
alignItems: "center",
|
|
1137
|
+
justifyContent: "center",
|
|
1138
|
+
transition: reduced ? "color 0.15s" : "all 0.15s",
|
|
1139
|
+
transform: isRated && !reduced ? "scale(1.15)" : "scale(1)"
|
|
1140
|
+
});
|
|
1141
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { display: "flex", gap: 4, marginTop: 4 }, children: [
|
|
1142
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1143
|
+
"button",
|
|
1144
|
+
{
|
|
1145
|
+
onClick: () => handleRate("positive"),
|
|
1146
|
+
disabled: rated !== null,
|
|
1147
|
+
style: buttonStyle(rated === "positive"),
|
|
1148
|
+
title: t("helpful"),
|
|
1149
|
+
"aria-label": t("helpful"),
|
|
1150
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
1151
|
+
"svg",
|
|
1152
|
+
{
|
|
1153
|
+
width: "14",
|
|
1154
|
+
height: "14",
|
|
1155
|
+
viewBox: "0 0 24 24",
|
|
1156
|
+
fill: "none",
|
|
1157
|
+
stroke: "currentColor",
|
|
1158
|
+
strokeWidth: "2",
|
|
1159
|
+
strokeLinecap: "round",
|
|
1160
|
+
strokeLinejoin: "round",
|
|
1161
|
+
children: [
|
|
1162
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d: "M7 10v12" }),
|
|
1163
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d: "M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2h0a3.13 3.13 0 0 1 3 3.88Z" })
|
|
1164
|
+
]
|
|
1165
|
+
}
|
|
1166
|
+
)
|
|
1167
|
+
}
|
|
1168
|
+
),
|
|
1169
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1170
|
+
"button",
|
|
1171
|
+
{
|
|
1172
|
+
onClick: () => handleRate("negative"),
|
|
1173
|
+
disabled: rated !== null,
|
|
1174
|
+
style: buttonStyle(rated === "negative"),
|
|
1175
|
+
title: t("not_helpful"),
|
|
1176
|
+
"aria-label": t("not_helpful"),
|
|
1177
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
1178
|
+
"svg",
|
|
1179
|
+
{
|
|
1180
|
+
width: "14",
|
|
1181
|
+
height: "14",
|
|
1182
|
+
viewBox: "0 0 24 24",
|
|
1183
|
+
fill: "none",
|
|
1184
|
+
stroke: "currentColor",
|
|
1185
|
+
strokeWidth: "2",
|
|
1186
|
+
strokeLinecap: "round",
|
|
1187
|
+
strokeLinejoin: "round",
|
|
1188
|
+
children: [
|
|
1189
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d: "M17 14V2" }),
|
|
1190
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d: "M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22h0a3.13 3.13 0 0 1-3-3.88Z" })
|
|
1191
|
+
]
|
|
1192
|
+
}
|
|
1193
|
+
)
|
|
1194
|
+
}
|
|
1195
|
+
)
|
|
1196
|
+
] });
|
|
1197
|
+
}
|
|
1198
|
+
function AnimatedMessage({
|
|
1199
|
+
children,
|
|
1200
|
+
isUser,
|
|
1201
|
+
animate,
|
|
1202
|
+
reduced
|
|
1203
|
+
}) {
|
|
1204
|
+
const [visible, setVisible] = (0, import_react8.useState)(!animate);
|
|
1205
|
+
(0, import_react8.useEffect)(() => {
|
|
1206
|
+
if (!animate || reduced) {
|
|
1207
|
+
setVisible(true);
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
const id = requestAnimationFrame(() => setVisible(true));
|
|
1211
|
+
return () => cancelAnimationFrame(id);
|
|
1212
|
+
}, [animate, reduced]);
|
|
1213
|
+
const style = {
|
|
1214
|
+
alignSelf: isUser ? "flex-end" : "flex-start",
|
|
1215
|
+
maxWidth: "80%",
|
|
1216
|
+
opacity: visible ? 1 : 0,
|
|
1217
|
+
transform: visible ? "translateX(0)" : `translateX(${isUser ? "12px" : "-12px"})`,
|
|
1218
|
+
transition: animate && !reduced ? "opacity 0.2s ease, transform 0.2s ease" : "none"
|
|
1219
|
+
};
|
|
1220
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style, children });
|
|
1221
|
+
}
|
|
1222
|
+
function ChipRow({
|
|
1223
|
+
options,
|
|
1224
|
+
onSelect,
|
|
1225
|
+
primaryColor,
|
|
1226
|
+
reduced
|
|
1227
|
+
}) {
|
|
1228
|
+
const chip = {
|
|
1229
|
+
background: "none",
|
|
1230
|
+
border: "1px solid #e0e0e0",
|
|
1231
|
+
borderRadius: 20,
|
|
1232
|
+
padding: "6px 12px",
|
|
1233
|
+
fontSize: 13,
|
|
1234
|
+
color: "#333",
|
|
1235
|
+
cursor: "pointer",
|
|
1236
|
+
textAlign: "left",
|
|
1237
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
1238
|
+
transition: reduced ? "none" : "border-color 0.15s, background 0.15s"
|
|
1239
|
+
};
|
|
1240
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1241
|
+
"div",
|
|
1242
|
+
{
|
|
1243
|
+
style: {
|
|
1244
|
+
display: "flex",
|
|
1245
|
+
flexWrap: "wrap",
|
|
1246
|
+
gap: 6,
|
|
1247
|
+
marginTop: 6
|
|
1248
|
+
},
|
|
1249
|
+
children: options.map((text) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1250
|
+
"button",
|
|
1251
|
+
{
|
|
1252
|
+
style: chip,
|
|
1253
|
+
onClick: () => onSelect(text),
|
|
1254
|
+
onMouseEnter: (e) => {
|
|
1255
|
+
e.currentTarget.style.borderColor = primaryColor;
|
|
1256
|
+
e.currentTarget.style.background = `${primaryColor}08`;
|
|
1257
|
+
},
|
|
1258
|
+
onMouseLeave: (e) => {
|
|
1259
|
+
e.currentTarget.style.borderColor = "#e0e0e0";
|
|
1260
|
+
e.currentTarget.style.background = "none";
|
|
1261
|
+
},
|
|
1262
|
+
children: text
|
|
1263
|
+
},
|
|
1264
|
+
text
|
|
1265
|
+
))
|
|
1266
|
+
}
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
1269
|
+
function BlockRenderer({
|
|
1270
|
+
block,
|
|
1271
|
+
onSend,
|
|
1272
|
+
onApproveAction,
|
|
1273
|
+
onCancelAction,
|
|
1274
|
+
primaryColor,
|
|
1275
|
+
reduced,
|
|
1276
|
+
t
|
|
1277
|
+
}) {
|
|
1278
|
+
switch (block.type) {
|
|
1279
|
+
case "quick_replies":
|
|
1280
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1281
|
+
ChipRow,
|
|
1282
|
+
{
|
|
1283
|
+
options: block.options,
|
|
1284
|
+
onSelect: onSend,
|
|
1285
|
+
primaryColor,
|
|
1286
|
+
reduced
|
|
1287
|
+
}
|
|
1288
|
+
);
|
|
1289
|
+
case "action_confirmation":
|
|
1290
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1291
|
+
ActionConfirmationCard,
|
|
1292
|
+
{
|
|
1293
|
+
block,
|
|
1294
|
+
primaryColor,
|
|
1295
|
+
t,
|
|
1296
|
+
onApprove: onApproveAction,
|
|
1297
|
+
onCancel: onCancelAction
|
|
1298
|
+
}
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
function StreamingCursor({ reduced }) {
|
|
1303
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1304
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("style", { children: `@keyframes ch-caret-blink {
|
|
1305
|
+
0%, 50% { opacity: 1; }
|
|
1306
|
+
50.01%, 100% { opacity: 0; }
|
|
1307
|
+
}` }),
|
|
1308
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1309
|
+
"span",
|
|
1310
|
+
{
|
|
1311
|
+
"aria-hidden": "true",
|
|
1312
|
+
style: {
|
|
1313
|
+
display: "inline-block",
|
|
1314
|
+
width: 2,
|
|
1315
|
+
height: "1em",
|
|
1316
|
+
marginLeft: 2,
|
|
1317
|
+
verticalAlign: "text-bottom",
|
|
1318
|
+
background: "#777",
|
|
1319
|
+
animation: reduced ? "none" : "ch-caret-blink 1s step-start infinite"
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
)
|
|
1323
|
+
] });
|
|
1324
|
+
}
|
|
1325
|
+
function Message({
|
|
1326
|
+
message,
|
|
1327
|
+
config,
|
|
1328
|
+
onRate,
|
|
1329
|
+
onSend,
|
|
1330
|
+
onApproveAction,
|
|
1331
|
+
onCancelAction,
|
|
1332
|
+
hasConversation,
|
|
1333
|
+
t,
|
|
1334
|
+
animate,
|
|
1335
|
+
reduced,
|
|
1336
|
+
showSuggestions
|
|
1337
|
+
}) {
|
|
1338
|
+
const isUser = message.role === "user";
|
|
1339
|
+
const bubbleStyle = {
|
|
1340
|
+
padding: "10px 14px",
|
|
1341
|
+
borderRadius: 16,
|
|
1342
|
+
fontSize: 14,
|
|
1343
|
+
lineHeight: 1.5,
|
|
1344
|
+
wordBreak: "break-word",
|
|
1345
|
+
...isUser ? {
|
|
1346
|
+
background: config.primaryColor,
|
|
1347
|
+
color: "white",
|
|
1348
|
+
borderBottomRightRadius: 4
|
|
1349
|
+
} : {
|
|
1350
|
+
background: config.bubbleBackground,
|
|
1351
|
+
color: config.textColor,
|
|
1352
|
+
borderBottomLeftRadius: 4
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
const linkColor = isUser ? "#ffffff" : config.primaryColor;
|
|
1356
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(AnimatedMessage, { isUser, animate, reduced, children: [
|
|
1357
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1358
|
+
"div",
|
|
1359
|
+
{
|
|
1360
|
+
style: bubbleStyle,
|
|
1361
|
+
"data-streaming-bubble": !isUser && message.streaming ? "true" : void 0,
|
|
1362
|
+
children: isUser ? message.content : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1363
|
+
renderMarkdown(message.content, {
|
|
1364
|
+
sources: message.sources,
|
|
1365
|
+
linkColor
|
|
1366
|
+
}),
|
|
1367
|
+
message.streaming && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StreamingCursor, { reduced })
|
|
1368
|
+
] })
|
|
1369
|
+
}
|
|
1370
|
+
),
|
|
1371
|
+
isUser && message.status && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MessageStatusPill, { status: message.status, t }),
|
|
1372
|
+
!isUser && message.blocks?.map((block, i) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1373
|
+
BlockRenderer,
|
|
1374
|
+
{
|
|
1375
|
+
block,
|
|
1376
|
+
onSend,
|
|
1377
|
+
onApproveAction,
|
|
1378
|
+
onCancelAction,
|
|
1379
|
+
primaryColor: config.primaryColor,
|
|
1380
|
+
reduced,
|
|
1381
|
+
t
|
|
1382
|
+
},
|
|
1383
|
+
i
|
|
1384
|
+
)),
|
|
1385
|
+
!isUser && showSuggestions && message.suggestions?.length ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1386
|
+
ChipRow,
|
|
1387
|
+
{
|
|
1388
|
+
options: message.suggestions,
|
|
1389
|
+
onSelect: onSend,
|
|
1390
|
+
primaryColor: config.primaryColor,
|
|
1391
|
+
reduced
|
|
1392
|
+
}
|
|
1393
|
+
) : null,
|
|
1394
|
+
message.role === "bot" && message.id && hasConversation && !message.streaming && !message.blocks?.some((b) => b.type === "action_confirmation") && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1395
|
+
MessageRatingButtons,
|
|
1396
|
+
{
|
|
1397
|
+
messageId: message.id,
|
|
1398
|
+
onRate,
|
|
1399
|
+
primaryColor: config.primaryColor,
|
|
1400
|
+
t,
|
|
1401
|
+
reduced
|
|
1402
|
+
}
|
|
1403
|
+
)
|
|
1404
|
+
] });
|
|
1405
|
+
}
|
|
1406
|
+
function TypingDots({ reduced }) {
|
|
1407
|
+
const dotStyle = (delay) => ({
|
|
1408
|
+
width: 6,
|
|
1409
|
+
height: 6,
|
|
1410
|
+
borderRadius: "50%",
|
|
1411
|
+
background: "#999",
|
|
1412
|
+
animation: reduced ? "none" : `ch-dot-pulse 1.2s ease-in-out ${delay}s infinite`
|
|
1413
|
+
});
|
|
1414
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1415
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("style", { children: `@keyframes ch-dot-pulse {
|
|
1416
|
+
0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
|
|
1417
|
+
40% { opacity: 1; transform: scale(1); }
|
|
1418
|
+
}` }),
|
|
1419
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
1420
|
+
"div",
|
|
1421
|
+
{
|
|
1422
|
+
style: {
|
|
1423
|
+
alignSelf: "flex-start",
|
|
1424
|
+
padding: "12px 16px",
|
|
1425
|
+
borderRadius: 16,
|
|
1426
|
+
borderBottomLeftRadius: 4,
|
|
1427
|
+
background: "#f0f0f0",
|
|
1428
|
+
display: "flex",
|
|
1429
|
+
gap: 4,
|
|
1430
|
+
alignItems: "center"
|
|
1431
|
+
},
|
|
1432
|
+
children: [
|
|
1433
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style: dotStyle(0) }),
|
|
1434
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style: dotStyle(0.2) }),
|
|
1435
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style: dotStyle(0.4) })
|
|
1436
|
+
]
|
|
1437
|
+
}
|
|
1438
|
+
)
|
|
1439
|
+
] });
|
|
1440
|
+
}
|
|
1441
|
+
function ChatMessages() {
|
|
1442
|
+
const {
|
|
1443
|
+
messages,
|
|
1444
|
+
isLoading,
|
|
1445
|
+
error,
|
|
1446
|
+
conversationId,
|
|
1447
|
+
rateMessage,
|
|
1448
|
+
sendMessage,
|
|
1449
|
+
approveAction,
|
|
1450
|
+
cancelAction,
|
|
1451
|
+
t
|
|
1452
|
+
} = useChat();
|
|
1453
|
+
const theme = useEffectiveTheme();
|
|
1454
|
+
const themedConfig = {
|
|
1455
|
+
primaryColor: theme.primary,
|
|
1456
|
+
textColor: theme.text,
|
|
1457
|
+
bubbleBackground: theme.bubbleBackground
|
|
1458
|
+
};
|
|
1459
|
+
const reduced = useReducedMotion();
|
|
1460
|
+
const containerRef = (0, import_react8.useRef)(null);
|
|
1461
|
+
const messagesEndRef = (0, import_react8.useRef)(null);
|
|
1462
|
+
const isFirstRender = (0, import_react8.useRef)(true);
|
|
1463
|
+
const prevMessageCount = (0, import_react8.useRef)(0);
|
|
1464
|
+
const stickRef = (0, import_react8.useRef)(true);
|
|
1465
|
+
const suppressScrollRef = (0, import_react8.useRef)(false);
|
|
1466
|
+
const autoScrollTo = (top) => {
|
|
1467
|
+
const el = containerRef.current;
|
|
1468
|
+
if (!el) return;
|
|
1469
|
+
suppressScrollRef.current = true;
|
|
1470
|
+
el.scrollTop = top;
|
|
1471
|
+
requestAnimationFrame(() => {
|
|
1472
|
+
suppressScrollRef.current = false;
|
|
1473
|
+
});
|
|
1474
|
+
};
|
|
1475
|
+
const handleScroll = () => {
|
|
1476
|
+
if (suppressScrollRef.current) return;
|
|
1477
|
+
const el = containerRef.current;
|
|
1478
|
+
if (!el) return;
|
|
1479
|
+
const distFromBottom = el.scrollHeight - el.scrollTop - el.clientHeight;
|
|
1480
|
+
stickRef.current = distFromBottom < 60;
|
|
1481
|
+
};
|
|
1482
|
+
(0, import_react8.useEffect)(() => {
|
|
1483
|
+
const el = containerRef.current;
|
|
1484
|
+
if (!el) return;
|
|
1485
|
+
const lastMsg2 = messages[messages.length - 1];
|
|
1486
|
+
if (messages.length > prevMessageCount.current && lastMsg2?.role === "user") {
|
|
1487
|
+
stickRef.current = true;
|
|
1488
|
+
}
|
|
1489
|
+
if (!stickRef.current && !isFirstRender.current) {
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
const streamingBubble = el.querySelector(
|
|
1493
|
+
"[data-streaming-bubble='true']"
|
|
1494
|
+
);
|
|
1495
|
+
let target = el.scrollHeight - el.clientHeight;
|
|
1496
|
+
if (streamingBubble && streamingBubble.offsetHeight > el.clientHeight - 24) {
|
|
1497
|
+
const containerTop = el.getBoundingClientRect().top;
|
|
1498
|
+
const bubbleTop = streamingBubble.getBoundingClientRect().top;
|
|
1499
|
+
const TOP_GAP = 16;
|
|
1500
|
+
target = el.scrollTop + (bubbleTop - containerTop) - TOP_GAP;
|
|
1501
|
+
stickRef.current = false;
|
|
1502
|
+
}
|
|
1503
|
+
autoScrollTo(target);
|
|
1504
|
+
isFirstRender.current = false;
|
|
1505
|
+
}, [messages, isLoading, reduced]);
|
|
1506
|
+
const newStartIndex = isFirstRender.current ? messages.length : prevMessageCount.current;
|
|
1507
|
+
(0, import_react8.useEffect)(() => {
|
|
1508
|
+
prevMessageCount.current = messages.length;
|
|
1509
|
+
}, [messages.length]);
|
|
1510
|
+
let lastBotIndex = -1;
|
|
1511
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1512
|
+
if (messages[i].role === "bot") {
|
|
1513
|
+
lastBotIndex = i;
|
|
1514
|
+
break;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
const containerStyle = {
|
|
1518
|
+
flex: 1,
|
|
1519
|
+
overflowY: "auto",
|
|
1520
|
+
padding: 16,
|
|
1521
|
+
display: "flex",
|
|
1522
|
+
flexDirection: "column",
|
|
1523
|
+
gap: 12
|
|
1524
|
+
};
|
|
1525
|
+
const lastMsg = messages[messages.length - 1];
|
|
1526
|
+
const waitingForFirstToken = isLoading && (lastMsg?.role !== "bot" || lastMsg.streaming !== true);
|
|
1527
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { ref: containerRef, style: containerStyle, onScroll: handleScroll, children: [
|
|
1528
|
+
messages.map((msg, i) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1529
|
+
Message,
|
|
1530
|
+
{
|
|
1531
|
+
message: msg,
|
|
1532
|
+
config: themedConfig,
|
|
1533
|
+
onRate: rateMessage,
|
|
1534
|
+
onSend: sendMessage,
|
|
1535
|
+
onApproveAction: approveAction,
|
|
1536
|
+
onCancelAction: cancelAction,
|
|
1537
|
+
hasConversation: conversationId !== null,
|
|
1538
|
+
t,
|
|
1539
|
+
animate: i >= newStartIndex,
|
|
1540
|
+
reduced,
|
|
1541
|
+
showSuggestions: i === lastBotIndex && !isLoading && msg.streaming !== true
|
|
1542
|
+
},
|
|
1543
|
+
i
|
|
1544
|
+
)),
|
|
1545
|
+
waitingForFirstToken && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TypingDots, { reduced }),
|
|
1546
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1547
|
+
"div",
|
|
1548
|
+
{
|
|
1549
|
+
role: "alert",
|
|
1550
|
+
style: {
|
|
1551
|
+
alignSelf: "flex-start",
|
|
1552
|
+
padding: "10px 14px",
|
|
1553
|
+
borderRadius: 16,
|
|
1554
|
+
borderBottomLeftRadius: 4,
|
|
1555
|
+
fontSize: 13,
|
|
1556
|
+
background: "#fee2e2",
|
|
1557
|
+
color: "#b91c1c"
|
|
1558
|
+
},
|
|
1559
|
+
children: error
|
|
1560
|
+
}
|
|
1561
|
+
),
|
|
1562
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { ref: messagesEndRef })
|
|
1563
|
+
] });
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
// src/components/chat-suggestions.tsx
|
|
1567
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1568
|
+
function ChatSuggestions() {
|
|
1569
|
+
const { messages, isLoading, config, sendMessage } = useChat();
|
|
1570
|
+
const reduced = useReducedMotion();
|
|
1571
|
+
const theme = useEffectiveTheme();
|
|
1572
|
+
const hasUserMessage = messages.some((m) => m.role === "user");
|
|
1573
|
+
if (config.suggestedMessages.length === 0 || hasUserMessage || isLoading) {
|
|
1574
|
+
return null;
|
|
1575
|
+
}
|
|
1576
|
+
const isDark = theme.scheme === "dark";
|
|
1577
|
+
const idleBorder = isDark ? "rgba(255,255,255,0.18)" : "#e0e0e0";
|
|
1578
|
+
const containerStyle = {
|
|
1579
|
+
padding: "8px 16px",
|
|
1580
|
+
display: "flex",
|
|
1581
|
+
flexWrap: "wrap",
|
|
1582
|
+
gap: 6,
|
|
1583
|
+
justifyContent: "flex-end"
|
|
1584
|
+
};
|
|
1585
|
+
const chipStyle = {
|
|
1586
|
+
background: "none",
|
|
1587
|
+
border: `1px solid ${idleBorder}`,
|
|
1588
|
+
borderRadius: 20,
|
|
1589
|
+
padding: "7px 14px",
|
|
1590
|
+
fontSize: 13,
|
|
1591
|
+
color: theme.text,
|
|
1592
|
+
cursor: "pointer",
|
|
1593
|
+
textAlign: "left",
|
|
1594
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
1595
|
+
transition: reduced ? "none" : "border-color 0.15s, background 0.15s"
|
|
1596
|
+
};
|
|
1597
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: containerStyle, children: config.suggestedMessages.map((text) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1598
|
+
"button",
|
|
1599
|
+
{
|
|
1600
|
+
style: chipStyle,
|
|
1601
|
+
onClick: () => sendMessage(text),
|
|
1602
|
+
onMouseEnter: (e) => {
|
|
1603
|
+
e.currentTarget.style.borderColor = theme.primary;
|
|
1604
|
+
e.currentTarget.style.background = `${theme.primary}14`;
|
|
1605
|
+
},
|
|
1606
|
+
onMouseLeave: (e) => {
|
|
1607
|
+
e.currentTarget.style.borderColor = idleBorder;
|
|
1608
|
+
e.currentTarget.style.background = "none";
|
|
1609
|
+
},
|
|
1610
|
+
children: text
|
|
1611
|
+
},
|
|
1612
|
+
text
|
|
1613
|
+
)) });
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
// src/components/chat-input.tsx
|
|
1617
|
+
var import_react9 = require("react");
|
|
1618
|
+
var import_js3 = require("@customerhero/js");
|
|
1619
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1620
|
+
var MAX_ATTACHMENTS = 3;
|
|
1621
|
+
var ALLOWED_MIME_TYPES = [
|
|
1622
|
+
"image/png",
|
|
1623
|
+
"image/jpeg",
|
|
1624
|
+
"image/webp",
|
|
1625
|
+
"application/pdf"
|
|
1626
|
+
];
|
|
1627
|
+
var ACCEPT_ATTR = ALLOWED_MIME_TYPES.join(",");
|
|
1628
|
+
function isImageMime(mime) {
|
|
1629
|
+
return mime.startsWith("image/");
|
|
1630
|
+
}
|
|
1631
|
+
function ChatInput() {
|
|
1632
|
+
const {
|
|
1633
|
+
sendMessage,
|
|
1634
|
+
uploadAttachment,
|
|
1635
|
+
isLoading,
|
|
1636
|
+
readOnly,
|
|
1637
|
+
config,
|
|
1638
|
+
t,
|
|
1639
|
+
consumePendingPrefill,
|
|
1640
|
+
pendingPrefill
|
|
1641
|
+
} = useChat();
|
|
1642
|
+
const theme = useEffectiveTheme();
|
|
1643
|
+
const isDark = theme.scheme === "dark";
|
|
1644
|
+
const reduced = useReducedMotion();
|
|
1645
|
+
const [value, setValue] = (0, import_react9.useState)("");
|
|
1646
|
+
const [attachments, setAttachments] = (0, import_react9.useState)([]);
|
|
1647
|
+
const [captureSupported, setCaptureSupported] = (0, import_react9.useState)(false);
|
|
1648
|
+
const [menuOpen, setMenuOpen] = (0, import_react9.useState)(false);
|
|
1649
|
+
const [dragActive, setDragActive] = (0, import_react9.useState)(false);
|
|
1650
|
+
const [transientError, setTransientError] = (0, import_react9.useState)(null);
|
|
1651
|
+
const fileInputRef = (0, import_react9.useRef)(null);
|
|
1652
|
+
const textInputRef = (0, import_react9.useRef)(null);
|
|
1653
|
+
const menuRef = (0, import_react9.useRef)(null);
|
|
1654
|
+
const menuButtonRef = (0, import_react9.useRef)(null);
|
|
1655
|
+
const dragCounterRef = (0, import_react9.useRef)(0);
|
|
1656
|
+
(0, import_react9.useEffect)(() => {
|
|
1657
|
+
setCaptureSupported((0, import_js3.canCaptureScreenshot)());
|
|
1658
|
+
}, []);
|
|
1659
|
+
(0, import_react9.useEffect)(() => {
|
|
1660
|
+
const id = requestAnimationFrame(() => textInputRef.current?.focus());
|
|
1661
|
+
return () => cancelAnimationFrame(id);
|
|
1662
|
+
}, []);
|
|
1663
|
+
(0, import_react9.useLayoutEffect)(() => {
|
|
1664
|
+
const el = textInputRef.current;
|
|
1665
|
+
if (!el) return;
|
|
1666
|
+
el.style.height = "auto";
|
|
1667
|
+
el.style.height = `${el.scrollHeight}px`;
|
|
1668
|
+
}, [value]);
|
|
1669
|
+
(0, import_react9.useEffect)(() => {
|
|
1670
|
+
if (pendingPrefill === null) return;
|
|
1671
|
+
const text = consumePendingPrefill();
|
|
1672
|
+
if (text !== null) setValue(text);
|
|
1673
|
+
}, [pendingPrefill, consumePendingPrefill]);
|
|
1674
|
+
(0, import_react9.useEffect)(() => {
|
|
1675
|
+
return () => {
|
|
1676
|
+
for (const a of attachments) URL.revokeObjectURL(a.previewUrl);
|
|
1677
|
+
};
|
|
1678
|
+
}, []);
|
|
1679
|
+
(0, import_react9.useEffect)(() => {
|
|
1680
|
+
if (!menuOpen) return;
|
|
1681
|
+
const onClick = (e) => {
|
|
1682
|
+
const target = e.target;
|
|
1683
|
+
if (menuRef.current?.contains(target) || menuButtonRef.current?.contains(target)) {
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
setMenuOpen(false);
|
|
1687
|
+
};
|
|
1688
|
+
const onKey = (e) => {
|
|
1689
|
+
if (e.key === "Escape") setMenuOpen(false);
|
|
1690
|
+
};
|
|
1691
|
+
document.addEventListener("mousedown", onClick);
|
|
1692
|
+
document.addEventListener("keydown", onKey);
|
|
1693
|
+
return () => {
|
|
1694
|
+
document.removeEventListener("mousedown", onClick);
|
|
1695
|
+
document.removeEventListener("keydown", onKey);
|
|
1696
|
+
};
|
|
1697
|
+
}, [menuOpen]);
|
|
1698
|
+
(0, import_react9.useEffect)(() => {
|
|
1699
|
+
if (!transientError) return;
|
|
1700
|
+
const id = window.setTimeout(() => setTransientError(null), 4e3);
|
|
1701
|
+
return () => window.clearTimeout(id);
|
|
1702
|
+
}, [transientError]);
|
|
1703
|
+
const updateAttachment = (id, patch) => {
|
|
1704
|
+
setAttachments(
|
|
1705
|
+
(current) => current.map(
|
|
1706
|
+
(a) => a.id === id ? { ...a, ...patch } : a
|
|
1707
|
+
)
|
|
1708
|
+
);
|
|
1709
|
+
};
|
|
1710
|
+
const startUpload = async (blob, filename) => {
|
|
1711
|
+
if (attachments.length >= MAX_ATTACHMENTS) return;
|
|
1712
|
+
const id = `att_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
1713
|
+
const previewUrl = URL.createObjectURL(blob);
|
|
1714
|
+
setAttachments((current) => [
|
|
1715
|
+
...current,
|
|
1716
|
+
{ id, status: "uploading", previewUrl, blob, filename }
|
|
1717
|
+
]);
|
|
1718
|
+
try {
|
|
1719
|
+
const { attachmentToken } = await uploadAttachment(blob, { filename });
|
|
1720
|
+
updateAttachment(id, {
|
|
1721
|
+
status: "ready",
|
|
1722
|
+
token: attachmentToken
|
|
1723
|
+
});
|
|
1724
|
+
} catch {
|
|
1725
|
+
updateAttachment(id, { status: "error" });
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1728
|
+
const ingestFiles = (files) => {
|
|
1729
|
+
const remainingSlots = Math.max(0, MAX_ATTACHMENTS - attachments.length);
|
|
1730
|
+
if (remainingSlots === 0) return 0;
|
|
1731
|
+
let queued = 0;
|
|
1732
|
+
let rejectedAny = false;
|
|
1733
|
+
for (const f of Array.from(files)) {
|
|
1734
|
+
if (queued >= remainingSlots) break;
|
|
1735
|
+
const type = f.type;
|
|
1736
|
+
if (!ALLOWED_MIME_TYPES.includes(
|
|
1737
|
+
type
|
|
1738
|
+
)) {
|
|
1739
|
+
rejectedAny = true;
|
|
1740
|
+
continue;
|
|
1741
|
+
}
|
|
1742
|
+
const filename = typeof f.name === "string" && f.name.length > 0 ? f.name : void 0;
|
|
1743
|
+
void startUpload(f, filename);
|
|
1744
|
+
queued += 1;
|
|
1745
|
+
}
|
|
1746
|
+
if (rejectedAny) {
|
|
1747
|
+
setTransientError(t("attachment_unsupported_type"));
|
|
1748
|
+
}
|
|
1749
|
+
return queued;
|
|
1750
|
+
};
|
|
1751
|
+
const handleCapture = async () => {
|
|
1752
|
+
setMenuOpen(false);
|
|
1753
|
+
try {
|
|
1754
|
+
const blob = await (0, import_js3.captureScreenshot)();
|
|
1755
|
+
await startUpload(blob);
|
|
1756
|
+
} catch (e) {
|
|
1757
|
+
if (e instanceof import_js3.ScreenshotCancelled) return;
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1760
|
+
const handlePickFile = () => {
|
|
1761
|
+
setMenuOpen(false);
|
|
1762
|
+
fileInputRef.current?.click();
|
|
1763
|
+
};
|
|
1764
|
+
const handleFileInputChange = (e) => {
|
|
1765
|
+
const files = e.target.files;
|
|
1766
|
+
if (files && files.length > 0) {
|
|
1767
|
+
ingestFiles(files);
|
|
1768
|
+
}
|
|
1769
|
+
e.target.value = "";
|
|
1770
|
+
};
|
|
1771
|
+
const handleRemove = (id) => {
|
|
1772
|
+
setAttachments((current) => {
|
|
1773
|
+
const target = current.find((a) => a.id === id);
|
|
1774
|
+
if (target) URL.revokeObjectURL(target.previewUrl);
|
|
1775
|
+
return current.filter((a) => a.id !== id);
|
|
1776
|
+
});
|
|
1777
|
+
};
|
|
1778
|
+
const handlePaste = (e) => {
|
|
1779
|
+
const items = e.clipboardData?.items;
|
|
1780
|
+
if (!items || items.length === 0) return;
|
|
1781
|
+
const blobs = [];
|
|
1782
|
+
for (const item of Array.from(items)) {
|
|
1783
|
+
if (item.kind !== "file") continue;
|
|
1784
|
+
const blob = item.getAsFile();
|
|
1785
|
+
if (blob) blobs.push(blob);
|
|
1786
|
+
}
|
|
1787
|
+
if (blobs.length === 0) return;
|
|
1788
|
+
e.preventDefault();
|
|
1789
|
+
ingestFiles(blobs);
|
|
1790
|
+
};
|
|
1791
|
+
const handleDragEnter = (e) => {
|
|
1792
|
+
if (!hasFiles(e)) return;
|
|
1793
|
+
e.preventDefault();
|
|
1794
|
+
dragCounterRef.current += 1;
|
|
1795
|
+
setDragActive(true);
|
|
1796
|
+
};
|
|
1797
|
+
const handleDragOver = (e) => {
|
|
1798
|
+
if (!hasFiles(e)) return;
|
|
1799
|
+
e.preventDefault();
|
|
1800
|
+
};
|
|
1801
|
+
const handleDragLeave = (e) => {
|
|
1802
|
+
if (!hasFiles(e)) return;
|
|
1803
|
+
e.preventDefault();
|
|
1804
|
+
dragCounterRef.current = Math.max(0, dragCounterRef.current - 1);
|
|
1805
|
+
if (dragCounterRef.current === 0) setDragActive(false);
|
|
1806
|
+
};
|
|
1807
|
+
const handleDrop = (e) => {
|
|
1808
|
+
if (!hasFiles(e)) return;
|
|
1809
|
+
e.preventDefault();
|
|
1810
|
+
dragCounterRef.current = 0;
|
|
1811
|
+
setDragActive(false);
|
|
1812
|
+
const files = e.dataTransfer?.files;
|
|
1813
|
+
if (files && files.length > 0) {
|
|
1814
|
+
ingestFiles(files);
|
|
1815
|
+
}
|
|
1816
|
+
};
|
|
1817
|
+
const readyTokens = attachments.filter(
|
|
1818
|
+
(a) => a.status === "ready"
|
|
1819
|
+
).map((a) => a.token);
|
|
1820
|
+
const handleSend = () => {
|
|
1821
|
+
if (!value.trim() || isLoading) return;
|
|
1822
|
+
sendMessage(
|
|
1823
|
+
value,
|
|
1824
|
+
readyTokens.length > 0 ? { attachmentTokens: readyTokens } : void 0
|
|
1825
|
+
);
|
|
1826
|
+
for (const a of attachments) URL.revokeObjectURL(a.previewUrl);
|
|
1827
|
+
setAttachments([]);
|
|
1828
|
+
setValue("");
|
|
1829
|
+
};
|
|
1830
|
+
const handleKeyDown = (e) => {
|
|
1831
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
1832
|
+
e.preventDefault();
|
|
1833
|
+
handleSend();
|
|
1834
|
+
}
|
|
1835
|
+
};
|
|
1836
|
+
const containerStyle = {
|
|
1837
|
+
position: "relative",
|
|
1838
|
+
padding: "12px 16px",
|
|
1839
|
+
borderTop: `1px solid ${theme.divider}`,
|
|
1840
|
+
display: "flex",
|
|
1841
|
+
flexDirection: "column",
|
|
1842
|
+
gap: 8
|
|
1843
|
+
};
|
|
1844
|
+
const rowStyle = {
|
|
1845
|
+
display: "flex",
|
|
1846
|
+
// Anchor the icon buttons to the bottom of the row so a multi-line
|
|
1847
|
+
// textarea grows upward without dragging them along.
|
|
1848
|
+
alignItems: "flex-end",
|
|
1849
|
+
gap: 8
|
|
1850
|
+
};
|
|
1851
|
+
const TEXTAREA_MAX_HEIGHT = 140;
|
|
1852
|
+
const inputStyle = {
|
|
1853
|
+
flex: 1,
|
|
1854
|
+
border: `1px solid ${theme.divider}`,
|
|
1855
|
+
borderRadius: 18,
|
|
1856
|
+
padding: "10px 16px",
|
|
1857
|
+
fontSize: 14,
|
|
1858
|
+
lineHeight: 1.4,
|
|
1859
|
+
outline: "none",
|
|
1860
|
+
background: isDark ? "rgba(255,255,255,0.06)" : "#fafafa",
|
|
1861
|
+
color: theme.text,
|
|
1862
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
1863
|
+
resize: "none",
|
|
1864
|
+
overflowY: "auto",
|
|
1865
|
+
maxHeight: TEXTAREA_MAX_HEIGHT,
|
|
1866
|
+
boxSizing: "border-box"
|
|
1867
|
+
};
|
|
1868
|
+
const sendButtonStyle = {
|
|
1869
|
+
width: 36,
|
|
1870
|
+
height: 36,
|
|
1871
|
+
borderRadius: "50%",
|
|
1872
|
+
background: theme.primary,
|
|
1873
|
+
border: "none",
|
|
1874
|
+
color: "white",
|
|
1875
|
+
cursor: isLoading ? "not-allowed" : "pointer",
|
|
1876
|
+
display: "flex",
|
|
1877
|
+
alignItems: "center",
|
|
1878
|
+
justifyContent: "center",
|
|
1879
|
+
opacity: isLoading ? 0.5 : 1,
|
|
1880
|
+
transition: reduced ? "opacity 0.2s" : "opacity 0.2s, transform 0.15s",
|
|
1881
|
+
flexShrink: 0,
|
|
1882
|
+
transform: "scale(1)"
|
|
1883
|
+
};
|
|
1884
|
+
const iconButtonStyle = (disabled) => ({
|
|
1885
|
+
width: 36,
|
|
1886
|
+
height: 36,
|
|
1887
|
+
borderRadius: "50%",
|
|
1888
|
+
background: "transparent",
|
|
1889
|
+
border: "none",
|
|
1890
|
+
color: disabled ? "#ccc" : "#666",
|
|
1891
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
1892
|
+
display: "flex",
|
|
1893
|
+
alignItems: "center",
|
|
1894
|
+
justifyContent: "center",
|
|
1895
|
+
flexShrink: 0,
|
|
1896
|
+
padding: 0
|
|
1897
|
+
});
|
|
1898
|
+
const menuStyle = {
|
|
1899
|
+
position: "absolute",
|
|
1900
|
+
bottom: "calc(100% + 4px)",
|
|
1901
|
+
left: 0,
|
|
1902
|
+
background: theme.background,
|
|
1903
|
+
border: `1px solid ${theme.divider}`,
|
|
1904
|
+
borderRadius: 8,
|
|
1905
|
+
boxShadow: isDark ? "0 4px 16px rgba(0,0,0,0.5)" : "0 4px 16px rgba(0,0,0,0.12)",
|
|
1906
|
+
padding: 4,
|
|
1907
|
+
minWidth: 180,
|
|
1908
|
+
zIndex: 10,
|
|
1909
|
+
display: "flex",
|
|
1910
|
+
flexDirection: "column"
|
|
1911
|
+
};
|
|
1912
|
+
const menuItemStyle = {
|
|
1913
|
+
display: "flex",
|
|
1914
|
+
alignItems: "center",
|
|
1915
|
+
gap: 10,
|
|
1916
|
+
padding: "8px 12px",
|
|
1917
|
+
background: "transparent",
|
|
1918
|
+
border: "none",
|
|
1919
|
+
borderRadius: 4,
|
|
1920
|
+
cursor: "pointer",
|
|
1921
|
+
fontSize: 14,
|
|
1922
|
+
color: theme.text,
|
|
1923
|
+
textAlign: "left",
|
|
1924
|
+
whiteSpace: "nowrap",
|
|
1925
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"
|
|
1926
|
+
};
|
|
1927
|
+
const dropOverlayStyle = {
|
|
1928
|
+
position: "absolute",
|
|
1929
|
+
inset: 0,
|
|
1930
|
+
background: isDark ? "rgba(15,23,42,0.92)" : "rgba(255,255,255,0.92)",
|
|
1931
|
+
border: `2px dashed ${theme.primary}`,
|
|
1932
|
+
borderRadius: 4,
|
|
1933
|
+
display: "flex",
|
|
1934
|
+
alignItems: "center",
|
|
1935
|
+
justifyContent: "center",
|
|
1936
|
+
color: theme.primary,
|
|
1937
|
+
fontSize: 14,
|
|
1938
|
+
fontWeight: 500,
|
|
1939
|
+
pointerEvents: "none",
|
|
1940
|
+
zIndex: 11
|
|
1941
|
+
};
|
|
1942
|
+
const errorPillStyle = {
|
|
1943
|
+
alignSelf: "flex-start",
|
|
1944
|
+
background: "#fef2f2",
|
|
1945
|
+
color: "#b91c1c",
|
|
1946
|
+
border: "1px solid #fecaca",
|
|
1947
|
+
borderRadius: 12,
|
|
1948
|
+
padding: "4px 10px",
|
|
1949
|
+
fontSize: 12
|
|
1950
|
+
};
|
|
1951
|
+
const attachDisabled = attachments.length >= MAX_ATTACHMENTS || isLoading || readOnly;
|
|
1952
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1953
|
+
"div",
|
|
1954
|
+
{
|
|
1955
|
+
style: containerStyle,
|
|
1956
|
+
onDragEnter: handleDragEnter,
|
|
1957
|
+
onDragOver: handleDragOver,
|
|
1958
|
+
onDragLeave: handleDragLeave,
|
|
1959
|
+
onDrop: handleDrop,
|
|
1960
|
+
children: [
|
|
1961
|
+
dragActive && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { style: dropOverlayStyle, "aria-hidden": "true", children: t("drop_files_here") }),
|
|
1962
|
+
transientError && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { role: "alert", style: errorPillStyle, children: transientError }),
|
|
1963
|
+
attachments.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1964
|
+
"div",
|
|
1965
|
+
{
|
|
1966
|
+
style: { display: "flex", gap: 8, flexWrap: "wrap" },
|
|
1967
|
+
"aria-label": "Attachments",
|
|
1968
|
+
children: attachments.map((a) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1969
|
+
Thumbnail,
|
|
1970
|
+
{
|
|
1971
|
+
attachment: a,
|
|
1972
|
+
onRemove: () => handleRemove(a.id),
|
|
1973
|
+
t
|
|
1974
|
+
},
|
|
1975
|
+
a.id
|
|
1976
|
+
))
|
|
1977
|
+
}
|
|
1978
|
+
),
|
|
1979
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: rowStyle, children: [
|
|
1980
|
+
config.allowAttachments !== false && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: { position: "relative" }, children: [
|
|
1981
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1982
|
+
"button",
|
|
1983
|
+
{
|
|
1984
|
+
ref: menuButtonRef,
|
|
1985
|
+
type: "button",
|
|
1986
|
+
onClick: () => setMenuOpen((o) => !o),
|
|
1987
|
+
disabled: attachDisabled,
|
|
1988
|
+
style: iconButtonStyle(attachDisabled),
|
|
1989
|
+
"aria-label": t("attach_menu_open"),
|
|
1990
|
+
"aria-haspopup": "menu",
|
|
1991
|
+
"aria-expanded": menuOpen,
|
|
1992
|
+
title: t("attach_menu_open"),
|
|
1993
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PaperclipIcon, {})
|
|
1994
|
+
}
|
|
1995
|
+
),
|
|
1996
|
+
menuOpen && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { ref: menuRef, role: "menu", style: menuStyle, children: [
|
|
1997
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1998
|
+
"button",
|
|
1999
|
+
{
|
|
2000
|
+
type: "button",
|
|
2001
|
+
role: "menuitem",
|
|
2002
|
+
onClick: handlePickFile,
|
|
2003
|
+
style: menuItemStyle,
|
|
2004
|
+
onMouseEnter: (e) => {
|
|
2005
|
+
e.currentTarget.style.background = theme.bubbleBackground;
|
|
2006
|
+
},
|
|
2007
|
+
onMouseLeave: (e) => {
|
|
2008
|
+
e.currentTarget.style.background = "transparent";
|
|
2009
|
+
},
|
|
2010
|
+
children: [
|
|
2011
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ImageIcon, {}),
|
|
2012
|
+
t("attach_photo")
|
|
2013
|
+
]
|
|
2014
|
+
}
|
|
2015
|
+
),
|
|
2016
|
+
captureSupported && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
2017
|
+
"button",
|
|
2018
|
+
{
|
|
2019
|
+
type: "button",
|
|
2020
|
+
role: "menuitem",
|
|
2021
|
+
onClick: handleCapture,
|
|
2022
|
+
style: menuItemStyle,
|
|
2023
|
+
onMouseEnter: (e) => {
|
|
2024
|
+
e.currentTarget.style.background = theme.bubbleBackground;
|
|
2025
|
+
},
|
|
2026
|
+
onMouseLeave: (e) => {
|
|
2027
|
+
e.currentTarget.style.background = "transparent";
|
|
2028
|
+
},
|
|
2029
|
+
children: [
|
|
2030
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CameraIcon, {}),
|
|
2031
|
+
t("screenshot_capture")
|
|
2032
|
+
]
|
|
2033
|
+
}
|
|
2034
|
+
)
|
|
2035
|
+
] })
|
|
2036
|
+
] }),
|
|
2037
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2038
|
+
"input",
|
|
2039
|
+
{
|
|
2040
|
+
ref: fileInputRef,
|
|
2041
|
+
type: "file",
|
|
2042
|
+
accept: ACCEPT_ATTR,
|
|
2043
|
+
multiple: true,
|
|
2044
|
+
onChange: handleFileInputChange,
|
|
2045
|
+
style: { display: "none" },
|
|
2046
|
+
"aria-hidden": "true",
|
|
2047
|
+
tabIndex: -1
|
|
2048
|
+
}
|
|
2049
|
+
),
|
|
2050
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2051
|
+
"textarea",
|
|
2052
|
+
{
|
|
2053
|
+
ref: textInputRef,
|
|
2054
|
+
rows: 1,
|
|
2055
|
+
value,
|
|
2056
|
+
onChange: (e) => setValue(e.target.value),
|
|
2057
|
+
onKeyDown: handleKeyDown,
|
|
2058
|
+
onPaste: handlePaste,
|
|
2059
|
+
placeholder: config.placeholderText,
|
|
2060
|
+
style: inputStyle,
|
|
2061
|
+
disabled: isLoading || readOnly
|
|
2062
|
+
}
|
|
2063
|
+
),
|
|
2064
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2065
|
+
"button",
|
|
2066
|
+
{
|
|
2067
|
+
onClick: handleSend,
|
|
2068
|
+
disabled: isLoading || readOnly || !value.trim(),
|
|
2069
|
+
style: sendButtonStyle,
|
|
2070
|
+
"aria-label": t("send_message"),
|
|
2071
|
+
onMouseEnter: (e) => {
|
|
2072
|
+
if (!reduced && !isLoading)
|
|
2073
|
+
e.currentTarget.style.transform = "scale(1.1)";
|
|
2074
|
+
},
|
|
2075
|
+
onMouseLeave: (e) => {
|
|
2076
|
+
if (!reduced) e.currentTarget.style.transform = "scale(1)";
|
|
2077
|
+
},
|
|
2078
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
2079
|
+
"svg",
|
|
2080
|
+
{
|
|
2081
|
+
width: "16",
|
|
2082
|
+
height: "16",
|
|
2083
|
+
viewBox: "0 0 24 24",
|
|
2084
|
+
fill: "none",
|
|
2085
|
+
stroke: "currentColor",
|
|
2086
|
+
strokeWidth: "2",
|
|
2087
|
+
strokeLinecap: "round",
|
|
2088
|
+
strokeLinejoin: "round",
|
|
2089
|
+
children: [
|
|
2090
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("line", { x1: "22", y1: "2", x2: "11", y2: "13" }),
|
|
2091
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("polygon", { points: "22 2 15 22 11 13 2 9 22 2" })
|
|
2092
|
+
]
|
|
2093
|
+
}
|
|
2094
|
+
)
|
|
2095
|
+
}
|
|
2096
|
+
)
|
|
2097
|
+
] })
|
|
2098
|
+
]
|
|
2099
|
+
}
|
|
2100
|
+
);
|
|
2101
|
+
}
|
|
2102
|
+
function hasFiles(e) {
|
|
2103
|
+
const types = e.dataTransfer?.types;
|
|
2104
|
+
if (!types) return false;
|
|
2105
|
+
for (let i = 0; i < types.length; i++) {
|
|
2106
|
+
if (types[i] === "Files") return true;
|
|
2107
|
+
}
|
|
2108
|
+
return false;
|
|
2109
|
+
}
|
|
2110
|
+
function Thumbnail({
|
|
2111
|
+
attachment,
|
|
2112
|
+
onRemove,
|
|
2113
|
+
t
|
|
2114
|
+
}) {
|
|
2115
|
+
const { status, previewUrl, blob, filename } = attachment;
|
|
2116
|
+
const isImage = isImageMime(blob.type);
|
|
2117
|
+
const wrap = {
|
|
2118
|
+
position: "relative",
|
|
2119
|
+
width: isImage ? 56 : 160,
|
|
2120
|
+
height: 56,
|
|
2121
|
+
borderRadius: 8,
|
|
2122
|
+
overflow: "hidden",
|
|
2123
|
+
border: status === "error" ? "2px solid #b91c1c" : "1px solid #e0e0e0",
|
|
2124
|
+
background: "#f5f5f5",
|
|
2125
|
+
display: "flex",
|
|
2126
|
+
alignItems: "center",
|
|
2127
|
+
justifyContent: isImage ? "stretch" : "flex-start",
|
|
2128
|
+
gap: isImage ? 0 : 8,
|
|
2129
|
+
padding: isImage ? 0 : "0 8px"
|
|
2130
|
+
};
|
|
2131
|
+
const img = {
|
|
2132
|
+
width: "100%",
|
|
2133
|
+
height: "100%",
|
|
2134
|
+
objectFit: "cover"
|
|
2135
|
+
};
|
|
2136
|
+
const removeBtn = {
|
|
2137
|
+
position: "absolute",
|
|
2138
|
+
top: 2,
|
|
2139
|
+
right: 2,
|
|
2140
|
+
width: 18,
|
|
2141
|
+
height: 18,
|
|
2142
|
+
borderRadius: "50%",
|
|
2143
|
+
border: "none",
|
|
2144
|
+
background: "rgba(0,0,0,0.6)",
|
|
2145
|
+
color: "white",
|
|
2146
|
+
fontSize: 11,
|
|
2147
|
+
lineHeight: "18px",
|
|
2148
|
+
padding: 0,
|
|
2149
|
+
cursor: "pointer",
|
|
2150
|
+
textAlign: "center"
|
|
2151
|
+
};
|
|
2152
|
+
const overlay = {
|
|
2153
|
+
position: "absolute",
|
|
2154
|
+
inset: 0,
|
|
2155
|
+
background: "rgba(255,255,255,0.7)",
|
|
2156
|
+
display: "flex",
|
|
2157
|
+
alignItems: "center",
|
|
2158
|
+
justifyContent: "center"
|
|
2159
|
+
};
|
|
2160
|
+
const docName = {
|
|
2161
|
+
fontSize: 12,
|
|
2162
|
+
fontWeight: 500,
|
|
2163
|
+
color: "#333",
|
|
2164
|
+
overflow: "hidden",
|
|
2165
|
+
textOverflow: "ellipsis",
|
|
2166
|
+
whiteSpace: "nowrap",
|
|
2167
|
+
maxWidth: 110,
|
|
2168
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"
|
|
2169
|
+
};
|
|
2170
|
+
const docMeta = {
|
|
2171
|
+
fontSize: 11,
|
|
2172
|
+
color: "#888",
|
|
2173
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"
|
|
2174
|
+
};
|
|
2175
|
+
const displayName = filename ?? (isImage ? "" : "Document");
|
|
2176
|
+
const sizeLabel = formatBytes(blob.size);
|
|
2177
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: wrap, children: [
|
|
2178
|
+
isImage ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { src: previewUrl, alt: "", style: img }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
2179
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(DocIcon, {}),
|
|
2180
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
2181
|
+
"div",
|
|
2182
|
+
{
|
|
2183
|
+
style: {
|
|
2184
|
+
display: "flex",
|
|
2185
|
+
flexDirection: "column",
|
|
2186
|
+
minWidth: 0,
|
|
2187
|
+
flex: 1
|
|
2188
|
+
},
|
|
2189
|
+
children: [
|
|
2190
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { style: docName, title: displayName, children: displayName }),
|
|
2191
|
+
sizeLabel && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { style: docMeta, children: sizeLabel })
|
|
2192
|
+
]
|
|
2193
|
+
}
|
|
2194
|
+
)
|
|
2195
|
+
] }),
|
|
2196
|
+
status === "uploading" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { style: overlay, "aria-label": "Uploading", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Spinner2, {}) }),
|
|
2197
|
+
status === "error" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2198
|
+
"div",
|
|
2199
|
+
{
|
|
2200
|
+
style: { ...overlay, background: "rgba(255,255,255,0.85)" },
|
|
2201
|
+
"aria-label": t("status_failed"),
|
|
2202
|
+
title: t("status_failed"),
|
|
2203
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { style: { color: "#b91c1c", fontSize: 11, fontWeight: 600 }, children: "!" })
|
|
2204
|
+
}
|
|
2205
|
+
),
|
|
2206
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2207
|
+
"button",
|
|
2208
|
+
{
|
|
2209
|
+
type: "button",
|
|
2210
|
+
style: removeBtn,
|
|
2211
|
+
onClick: onRemove,
|
|
2212
|
+
"aria-label": t("attachment_remove"),
|
|
2213
|
+
children: "\xD7"
|
|
2214
|
+
}
|
|
2215
|
+
)
|
|
2216
|
+
] });
|
|
2217
|
+
}
|
|
2218
|
+
function PaperclipIcon() {
|
|
2219
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2220
|
+
"svg",
|
|
2221
|
+
{
|
|
2222
|
+
width: "20",
|
|
2223
|
+
height: "20",
|
|
2224
|
+
viewBox: "0 0 24 24",
|
|
2225
|
+
fill: "none",
|
|
2226
|
+
stroke: "currentColor",
|
|
2227
|
+
strokeWidth: "2",
|
|
2228
|
+
strokeLinecap: "round",
|
|
2229
|
+
strokeLinejoin: "round",
|
|
2230
|
+
"aria-hidden": "true",
|
|
2231
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48" })
|
|
2232
|
+
}
|
|
2233
|
+
);
|
|
2234
|
+
}
|
|
2235
|
+
function ImageIcon() {
|
|
2236
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
2237
|
+
"svg",
|
|
2238
|
+
{
|
|
2239
|
+
width: "18",
|
|
2240
|
+
height: "18",
|
|
2241
|
+
viewBox: "0 0 24 24",
|
|
2242
|
+
fill: "none",
|
|
2243
|
+
stroke: "currentColor",
|
|
2244
|
+
strokeWidth: "2",
|
|
2245
|
+
strokeLinecap: "round",
|
|
2246
|
+
strokeLinejoin: "round",
|
|
2247
|
+
"aria-hidden": "true",
|
|
2248
|
+
children: [
|
|
2249
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2", ry: "2" }),
|
|
2250
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("circle", { cx: "8.5", cy: "8.5", r: "1.5" }),
|
|
2251
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("polyline", { points: "21 15 16 10 5 21" })
|
|
2252
|
+
]
|
|
2253
|
+
}
|
|
2254
|
+
);
|
|
2255
|
+
}
|
|
2256
|
+
function DocIcon() {
|
|
2257
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
2258
|
+
"svg",
|
|
2259
|
+
{
|
|
2260
|
+
width: "20",
|
|
2261
|
+
height: "20",
|
|
2262
|
+
viewBox: "0 0 24 24",
|
|
2263
|
+
fill: "none",
|
|
2264
|
+
stroke: "currentColor",
|
|
2265
|
+
strokeWidth: "2",
|
|
2266
|
+
strokeLinecap: "round",
|
|
2267
|
+
strokeLinejoin: "round",
|
|
2268
|
+
"aria-hidden": "true",
|
|
2269
|
+
style: { color: "#666", flexShrink: 0 },
|
|
2270
|
+
children: [
|
|
2271
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
|
|
2272
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("polyline", { points: "14 2 14 8 20 8" }),
|
|
2273
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("line", { x1: "16", y1: "13", x2: "8", y2: "13" }),
|
|
2274
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("line", { x1: "16", y1: "17", x2: "8", y2: "17" }),
|
|
2275
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("polyline", { points: "10 9 9 9 8 9" })
|
|
2276
|
+
]
|
|
2277
|
+
}
|
|
2278
|
+
);
|
|
2279
|
+
}
|
|
2280
|
+
function formatBytes(bytes) {
|
|
2281
|
+
if (!Number.isFinite(bytes) || bytes <= 0) return "";
|
|
2282
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
2283
|
+
if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;
|
|
2284
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
2285
|
+
}
|
|
2286
|
+
function CameraIcon() {
|
|
2287
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
2288
|
+
"svg",
|
|
2289
|
+
{
|
|
2290
|
+
width: "18",
|
|
2291
|
+
height: "18",
|
|
2292
|
+
viewBox: "0 0 24 24",
|
|
2293
|
+
fill: "none",
|
|
2294
|
+
stroke: "currentColor",
|
|
2295
|
+
strokeWidth: "2",
|
|
2296
|
+
strokeLinecap: "round",
|
|
2297
|
+
strokeLinejoin: "round",
|
|
2298
|
+
"aria-hidden": "true",
|
|
2299
|
+
children: [
|
|
2300
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z" }),
|
|
2301
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("circle", { cx: "12", cy: "13", r: "4" })
|
|
2302
|
+
]
|
|
2303
|
+
}
|
|
2304
|
+
);
|
|
2305
|
+
}
|
|
2306
|
+
function Spinner2() {
|
|
2307
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
2308
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("style", { children: `@keyframes ch-att-spin { to { transform: rotate(360deg); } }` }),
|
|
2309
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2310
|
+
"span",
|
|
2311
|
+
{
|
|
2312
|
+
"aria-hidden": "true",
|
|
2313
|
+
style: {
|
|
2314
|
+
width: 16,
|
|
2315
|
+
height: 16,
|
|
2316
|
+
borderRadius: "50%",
|
|
2317
|
+
border: "2px solid #888",
|
|
2318
|
+
borderTopColor: "transparent",
|
|
2319
|
+
animation: "ch-att-spin 0.8s linear infinite",
|
|
2320
|
+
display: "inline-block"
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
)
|
|
2324
|
+
] });
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
// src/components/incident-banner.tsx
|
|
2328
|
+
var import_react10 = require("react");
|
|
2329
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
2330
|
+
var PALETTE = {
|
|
2331
|
+
info: {
|
|
2332
|
+
bg: "#EFF6FF",
|
|
2333
|
+
fg: "#1E3A8A",
|
|
2334
|
+
fgMuted: "#3B5BA9",
|
|
2335
|
+
accent: "#2563EB",
|
|
2336
|
+
iconBg: "#DBEAFE",
|
|
2337
|
+
iconFg: "#2563EB"
|
|
2338
|
+
},
|
|
2339
|
+
warning: {
|
|
2340
|
+
bg: "#FFFBEB",
|
|
2341
|
+
fg: "#78350F",
|
|
2342
|
+
fgMuted: "#92541A",
|
|
2343
|
+
accent: "#B45309",
|
|
2344
|
+
iconBg: "#FEF3C7",
|
|
2345
|
+
iconFg: "#B45309"
|
|
2346
|
+
},
|
|
2347
|
+
outage: {
|
|
2348
|
+
bg: "#FEF2F2",
|
|
2349
|
+
fg: "#991B1B",
|
|
2350
|
+
fgMuted: "#B23A3A",
|
|
2351
|
+
accent: "#DC2626",
|
|
2352
|
+
iconBg: "#FEE2E2",
|
|
2353
|
+
iconFg: "#DC2626"
|
|
2354
|
+
}
|
|
2355
|
+
};
|
|
2356
|
+
function SeverityIcon({
|
|
2357
|
+
severity,
|
|
2358
|
+
color
|
|
2359
|
+
}) {
|
|
2360
|
+
const props = {
|
|
2361
|
+
width: 14,
|
|
2362
|
+
height: 14,
|
|
2363
|
+
viewBox: "0 0 24 24",
|
|
2364
|
+
fill: "none",
|
|
2365
|
+
stroke: color,
|
|
2366
|
+
strokeWidth: 2.25,
|
|
2367
|
+
strokeLinecap: "round",
|
|
2368
|
+
strokeLinejoin: "round",
|
|
2369
|
+
"aria-hidden": true
|
|
2370
|
+
};
|
|
2371
|
+
if (severity === "outage") {
|
|
2372
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("svg", { ...props, children: [
|
|
2373
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
2374
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("line", { x1: "12", y1: "8", x2: "12", y2: "12" }),
|
|
2375
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })
|
|
2376
|
+
] });
|
|
2377
|
+
}
|
|
2378
|
+
if (severity === "warning") {
|
|
2379
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("svg", { ...props, children: [
|
|
2380
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("path", { d: "M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z" }),
|
|
2381
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("line", { x1: "12", y1: "9", x2: "12", y2: "13" }),
|
|
2382
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("line", { x1: "12", y1: "17", x2: "12.01", y2: "17" })
|
|
2383
|
+
] });
|
|
2384
|
+
}
|
|
2385
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("svg", { ...props, children: [
|
|
2386
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
2387
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("line", { x1: "12", y1: "16", x2: "12", y2: "12" }),
|
|
2388
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("line", { x1: "12", y1: "8", x2: "12.01", y2: "8" })
|
|
2389
|
+
] });
|
|
2390
|
+
}
|
|
2391
|
+
function IncidentBanner() {
|
|
2392
|
+
const { incidentBanner, incidentBannerDismissed, dismissIncidentBanner, t } = useChat();
|
|
2393
|
+
const [linkHover, setLinkHover] = (0, import_react10.useState)(false);
|
|
2394
|
+
const [closeHover, setCloseHover] = (0, import_react10.useState)(false);
|
|
2395
|
+
if (!incidentBanner || incidentBannerDismissed) return null;
|
|
2396
|
+
const palette = PALETTE[incidentBanner.severity];
|
|
2397
|
+
const wrap = {
|
|
2398
|
+
background: palette.bg,
|
|
2399
|
+
color: palette.fg,
|
|
2400
|
+
padding: "12px 14px 12px 12px",
|
|
2401
|
+
display: "flex",
|
|
2402
|
+
gap: 10,
|
|
2403
|
+
alignItems: "flex-start",
|
|
2404
|
+
fontSize: 13,
|
|
2405
|
+
lineHeight: 1.45,
|
|
2406
|
+
boxShadow: "inset 0 -1px 0 rgba(0,0,0,0.04)"
|
|
2407
|
+
};
|
|
2408
|
+
const iconBadge = {
|
|
2409
|
+
width: 22,
|
|
2410
|
+
height: 22,
|
|
2411
|
+
borderRadius: "50%",
|
|
2412
|
+
background: palette.iconBg,
|
|
2413
|
+
display: "flex",
|
|
2414
|
+
alignItems: "center",
|
|
2415
|
+
justifyContent: "center",
|
|
2416
|
+
flexShrink: 0,
|
|
2417
|
+
marginTop: 1
|
|
2418
|
+
};
|
|
2419
|
+
const titleStyle = {
|
|
2420
|
+
margin: 0,
|
|
2421
|
+
fontSize: 13,
|
|
2422
|
+
fontWeight: 600,
|
|
2423
|
+
letterSpacing: "-0.005em"
|
|
2424
|
+
};
|
|
2425
|
+
const bodyStyle = {
|
|
2426
|
+
margin: "3px 0 0",
|
|
2427
|
+
fontSize: 12.5,
|
|
2428
|
+
color: palette.fgMuted
|
|
2429
|
+
};
|
|
2430
|
+
const footerRowStyle = {
|
|
2431
|
+
display: "flex",
|
|
2432
|
+
flexWrap: "wrap",
|
|
2433
|
+
alignItems: "center",
|
|
2434
|
+
gap: 10,
|
|
2435
|
+
marginTop: 8
|
|
2436
|
+
};
|
|
2437
|
+
const etaStyle = {
|
|
2438
|
+
display: "inline-block",
|
|
2439
|
+
padding: "2px 8px",
|
|
2440
|
+
borderRadius: 4,
|
|
2441
|
+
fontSize: 11,
|
|
2442
|
+
fontWeight: 500,
|
|
2443
|
+
color: palette.accent,
|
|
2444
|
+
background: palette.iconBg,
|
|
2445
|
+
lineHeight: 1.4
|
|
2446
|
+
};
|
|
2447
|
+
const linkStyle = {
|
|
2448
|
+
display: "inline-flex",
|
|
2449
|
+
alignItems: "center",
|
|
2450
|
+
gap: 4,
|
|
2451
|
+
color: palette.accent,
|
|
2452
|
+
textDecoration: linkHover ? "underline" : "none",
|
|
2453
|
+
textUnderlineOffset: 3,
|
|
2454
|
+
fontSize: 12.5,
|
|
2455
|
+
fontWeight: 600
|
|
2456
|
+
};
|
|
2457
|
+
const closeButtonStyle = {
|
|
2458
|
+
background: closeHover ? "rgba(0,0,0,0.06)" : "transparent",
|
|
2459
|
+
border: "none",
|
|
2460
|
+
color: palette.fgMuted,
|
|
2461
|
+
cursor: "pointer",
|
|
2462
|
+
padding: 4,
|
|
2463
|
+
borderRadius: 6,
|
|
2464
|
+
flexShrink: 0,
|
|
2465
|
+
lineHeight: 0,
|
|
2466
|
+
marginTop: -2,
|
|
2467
|
+
marginRight: -2,
|
|
2468
|
+
transition: "background-color 0.12s ease"
|
|
2469
|
+
};
|
|
2470
|
+
const role = incidentBanner.severity === "outage" ? "alert" : "status";
|
|
2471
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { role, style: wrap, children: [
|
|
2472
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { style: iconBadge, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2473
|
+
SeverityIcon,
|
|
2474
|
+
{
|
|
2475
|
+
severity: incidentBanner.severity,
|
|
2476
|
+
color: palette.iconFg
|
|
2477
|
+
}
|
|
2478
|
+
) }),
|
|
2479
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { style: { flex: 1, minWidth: 0 }, children: [
|
|
2480
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { style: titleStyle, children: incidentBanner.title }),
|
|
2481
|
+
incidentBanner.body ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { style: bodyStyle, children: incidentBanner.body }) : null,
|
|
2482
|
+
incidentBanner.eta || incidentBanner.link ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { style: footerRowStyle, children: [
|
|
2483
|
+
incidentBanner.eta ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { style: etaStyle, children: incidentBanner.eta }) : null,
|
|
2484
|
+
incidentBanner.link ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
2485
|
+
"a",
|
|
2486
|
+
{
|
|
2487
|
+
href: incidentBanner.link.url,
|
|
2488
|
+
target: "_blank",
|
|
2489
|
+
rel: "noopener noreferrer",
|
|
2490
|
+
style: linkStyle,
|
|
2491
|
+
onMouseEnter: () => setLinkHover(true),
|
|
2492
|
+
onMouseLeave: () => setLinkHover(false),
|
|
2493
|
+
children: [
|
|
2494
|
+
incidentBanner.link.label ?? t("incident_default_link_label"),
|
|
2495
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
2496
|
+
"svg",
|
|
2497
|
+
{
|
|
2498
|
+
width: "12",
|
|
2499
|
+
height: "12",
|
|
2500
|
+
viewBox: "0 0 24 24",
|
|
2501
|
+
fill: "none",
|
|
2502
|
+
stroke: "currentColor",
|
|
2503
|
+
strokeWidth: "2.5",
|
|
2504
|
+
strokeLinecap: "round",
|
|
2505
|
+
strokeLinejoin: "round",
|
|
2506
|
+
"aria-hidden": "true",
|
|
2507
|
+
children: [
|
|
2508
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("line", { x1: "5", y1: "12", x2: "19", y2: "12" }),
|
|
2509
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("polyline", { points: "12 5 19 12 12 19" })
|
|
2510
|
+
]
|
|
2511
|
+
}
|
|
2512
|
+
)
|
|
2513
|
+
]
|
|
2514
|
+
}
|
|
2515
|
+
) : null
|
|
2516
|
+
] }) : null
|
|
2517
|
+
] }),
|
|
2518
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2519
|
+
"button",
|
|
2520
|
+
{
|
|
2521
|
+
type: "button",
|
|
2522
|
+
onClick: dismissIncidentBanner,
|
|
2523
|
+
"aria-label": t("incident_dismiss"),
|
|
2524
|
+
style: closeButtonStyle,
|
|
2525
|
+
onMouseEnter: () => setCloseHover(true),
|
|
2526
|
+
onMouseLeave: () => setCloseHover(false),
|
|
2527
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
2528
|
+
"svg",
|
|
2529
|
+
{
|
|
2530
|
+
width: "14",
|
|
2531
|
+
height: "14",
|
|
2532
|
+
viewBox: "0 0 24 24",
|
|
2533
|
+
fill: "none",
|
|
2534
|
+
stroke: "currentColor",
|
|
2535
|
+
strokeWidth: "2",
|
|
2536
|
+
strokeLinecap: "round",
|
|
2537
|
+
strokeLinejoin: "round",
|
|
2538
|
+
"aria-hidden": "true",
|
|
2539
|
+
children: [
|
|
2540
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
2541
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
2542
|
+
]
|
|
2543
|
+
}
|
|
2544
|
+
)
|
|
2545
|
+
}
|
|
2546
|
+
)
|
|
2547
|
+
] });
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
// src/components/chat-window.tsx
|
|
2551
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
2552
|
+
function ConfigError({ message, title }) {
|
|
2553
|
+
const errorStyle = {
|
|
2554
|
+
flex: 1,
|
|
2555
|
+
display: "flex",
|
|
2556
|
+
flexDirection: "column",
|
|
2557
|
+
alignItems: "center",
|
|
2558
|
+
justifyContent: "center",
|
|
2559
|
+
padding: 24,
|
|
2560
|
+
textAlign: "center",
|
|
2561
|
+
gap: 8
|
|
2562
|
+
};
|
|
2563
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { style: errorStyle, children: [
|
|
2564
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2565
|
+
"svg",
|
|
2566
|
+
{
|
|
2567
|
+
width: "32",
|
|
2568
|
+
height: "32",
|
|
2569
|
+
viewBox: "0 0 24 24",
|
|
2570
|
+
fill: "none",
|
|
2571
|
+
stroke: "#999",
|
|
2572
|
+
strokeWidth: "2",
|
|
2573
|
+
strokeLinecap: "round",
|
|
2574
|
+
strokeLinejoin: "round",
|
|
2575
|
+
children: [
|
|
2576
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
2577
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("line", { x1: "12", y1: "8", x2: "12", y2: "12" }),
|
|
2578
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })
|
|
2579
|
+
]
|
|
2580
|
+
}
|
|
2581
|
+
),
|
|
2582
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { style: { fontSize: 14, fontWeight: 500, color: "#333", margin: 0 }, children: title }),
|
|
2583
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { style: { fontSize: 12, color: "#999", margin: 0 }, children: message })
|
|
2584
|
+
] });
|
|
2585
|
+
}
|
|
2586
|
+
function fieldKey(field) {
|
|
2587
|
+
if (field.kind === "name" || field.kind === "email" || field.kind === "phone") {
|
|
2588
|
+
return field.kind;
|
|
2589
|
+
}
|
|
2590
|
+
return field.key;
|
|
2591
|
+
}
|
|
2592
|
+
function fieldLabel(field) {
|
|
2593
|
+
if (field.kind === "name") return field.label ?? "Name";
|
|
2594
|
+
if (field.kind === "email") return field.label ?? "Email";
|
|
2595
|
+
if (field.kind === "phone") return field.label ?? "Phone";
|
|
2596
|
+
return field.label;
|
|
2597
|
+
}
|
|
2598
|
+
function validateField(field, value) {
|
|
2599
|
+
const required = "required" in field ? !!field.required : false;
|
|
2600
|
+
if (required && (value === void 0 || value === "" || value === false)) {
|
|
2601
|
+
return "Required";
|
|
2602
|
+
}
|
|
2603
|
+
if (field.kind === "email" && typeof value === "string" && value !== "") {
|
|
2604
|
+
if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(value)) return "Invalid email";
|
|
2605
|
+
}
|
|
2606
|
+
return null;
|
|
2607
|
+
}
|
|
2608
|
+
function PreChatFormView() {
|
|
2609
|
+
const { preChatForm, submitPreChatForm, cancelPreChatForm, config, t } = useChat();
|
|
2610
|
+
const [values, setValues] = (0, import_react11.useState)({});
|
|
2611
|
+
const [errors, setErrors] = (0, import_react11.useState)({});
|
|
2612
|
+
const [submitting, setSubmitting] = (0, import_react11.useState)(false);
|
|
2613
|
+
if (!preChatForm) return null;
|
|
2614
|
+
function setValue(key, value) {
|
|
2615
|
+
setValues((prev) => ({ ...prev, [key]: value }));
|
|
2616
|
+
setErrors((prev) => ({ ...prev, [key]: null }));
|
|
2617
|
+
}
|
|
2618
|
+
async function handleSubmit(e) {
|
|
2619
|
+
e.preventDefault();
|
|
2620
|
+
if (!preChatForm) return;
|
|
2621
|
+
const nextErrors = {};
|
|
2622
|
+
let hasError = false;
|
|
2623
|
+
for (const f of preChatForm.fields) {
|
|
2624
|
+
const k = fieldKey(f);
|
|
2625
|
+
const err = validateField(f, values[k]);
|
|
2626
|
+
nextErrors[k] = err;
|
|
2627
|
+
if (err) hasError = true;
|
|
2628
|
+
}
|
|
2629
|
+
setErrors(nextErrors);
|
|
2630
|
+
if (hasError) return;
|
|
2631
|
+
const submission = {};
|
|
2632
|
+
const properties = {};
|
|
2633
|
+
for (const f of preChatForm.fields) {
|
|
2634
|
+
const k = fieldKey(f);
|
|
2635
|
+
const v = values[k];
|
|
2636
|
+
if (v === void 0 || v === "") continue;
|
|
2637
|
+
if (f.kind === "name" && typeof v === "string") submission.name = v;
|
|
2638
|
+
else if (f.kind === "email" && typeof v === "string")
|
|
2639
|
+
submission.email = v;
|
|
2640
|
+
else if (f.kind === "phone" && typeof v === "string")
|
|
2641
|
+
submission.phone = v;
|
|
2642
|
+
else if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
|
|
2643
|
+
properties[k] = v;
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
if (Object.keys(properties).length > 0) submission.properties = properties;
|
|
2647
|
+
setSubmitting(true);
|
|
2648
|
+
try {
|
|
2649
|
+
await submitPreChatForm(submission);
|
|
2650
|
+
} finally {
|
|
2651
|
+
setSubmitting(false);
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
const containerStyle = {
|
|
2655
|
+
flex: 1,
|
|
2656
|
+
overflowY: "auto",
|
|
2657
|
+
padding: 20,
|
|
2658
|
+
display: "flex",
|
|
2659
|
+
flexDirection: "column",
|
|
2660
|
+
gap: 12,
|
|
2661
|
+
background: config.backgroundColor,
|
|
2662
|
+
color: config.textColor
|
|
2663
|
+
};
|
|
2664
|
+
const labelStyle = {
|
|
2665
|
+
fontSize: 13,
|
|
2666
|
+
fontWeight: 500,
|
|
2667
|
+
display: "flex",
|
|
2668
|
+
flexDirection: "column",
|
|
2669
|
+
gap: 4
|
|
2670
|
+
};
|
|
2671
|
+
const inputStyle = {
|
|
2672
|
+
width: "100%",
|
|
2673
|
+
border: "1px solid #d4d4d8",
|
|
2674
|
+
borderRadius: 8,
|
|
2675
|
+
padding: "8px 10px",
|
|
2676
|
+
fontSize: 14,
|
|
2677
|
+
background: "white",
|
|
2678
|
+
color: "#111",
|
|
2679
|
+
boxSizing: "border-box"
|
|
2680
|
+
};
|
|
2681
|
+
const errorStyle = { color: "#dc2626", fontSize: 12 };
|
|
2682
|
+
const buttonRowStyle = {
|
|
2683
|
+
display: "flex",
|
|
2684
|
+
gap: 8,
|
|
2685
|
+
marginTop: 8
|
|
2686
|
+
};
|
|
2687
|
+
const submitStyle = {
|
|
2688
|
+
flex: 1,
|
|
2689
|
+
background: config.primaryColor,
|
|
2690
|
+
color: "white",
|
|
2691
|
+
border: "none",
|
|
2692
|
+
borderRadius: 8,
|
|
2693
|
+
padding: "10px 14px",
|
|
2694
|
+
fontSize: 14,
|
|
2695
|
+
fontWeight: 600,
|
|
2696
|
+
cursor: submitting ? "not-allowed" : "pointer",
|
|
2697
|
+
opacity: submitting ? 0.7 : 1
|
|
2698
|
+
};
|
|
2699
|
+
const cancelStyle = {
|
|
2700
|
+
background: "transparent",
|
|
2701
|
+
color: config.textColor,
|
|
2702
|
+
border: "1px solid #d4d4d8",
|
|
2703
|
+
borderRadius: 8,
|
|
2704
|
+
padding: "10px 14px",
|
|
2705
|
+
fontSize: 14,
|
|
2706
|
+
cursor: "pointer"
|
|
2707
|
+
};
|
|
2708
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2709
|
+
"form",
|
|
2710
|
+
{
|
|
2711
|
+
style: containerStyle,
|
|
2712
|
+
onSubmit: handleSubmit,
|
|
2713
|
+
"data-customerhero-prechat-form": true,
|
|
2714
|
+
children: [
|
|
2715
|
+
preChatForm.title && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("h3", { style: { fontSize: 16, fontWeight: 600, margin: 0 }, children: preChatForm.title }),
|
|
2716
|
+
preChatForm.description && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { style: { fontSize: 13, margin: 0, opacity: 0.8 }, children: preChatForm.description }),
|
|
2717
|
+
preChatForm.fields.map((field) => {
|
|
2718
|
+
const k = fieldKey(field);
|
|
2719
|
+
const v = values[k];
|
|
2720
|
+
const err = errors[k];
|
|
2721
|
+
const required = "required" in field ? !!field.required : false;
|
|
2722
|
+
const label = fieldLabel(field);
|
|
2723
|
+
if (field.kind === "textarea") {
|
|
2724
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("label", { style: labelStyle, children: [
|
|
2725
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { children: [
|
|
2726
|
+
label,
|
|
2727
|
+
required && " *"
|
|
2728
|
+
] }),
|
|
2729
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2730
|
+
"textarea",
|
|
2731
|
+
{
|
|
2732
|
+
style: { ...inputStyle, minHeight: 80, resize: "vertical" },
|
|
2733
|
+
value: v ?? "",
|
|
2734
|
+
maxLength: field.maxLength,
|
|
2735
|
+
onChange: (e) => setValue(k, e.target.value)
|
|
2736
|
+
}
|
|
2737
|
+
),
|
|
2738
|
+
err && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { style: errorStyle, children: err })
|
|
2739
|
+
] }, k);
|
|
2740
|
+
}
|
|
2741
|
+
if (field.kind === "select") {
|
|
2742
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("label", { style: labelStyle, children: [
|
|
2743
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { children: [
|
|
2744
|
+
label,
|
|
2745
|
+
required && " *"
|
|
2746
|
+
] }),
|
|
2747
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2748
|
+
"select",
|
|
2749
|
+
{
|
|
2750
|
+
style: inputStyle,
|
|
2751
|
+
value: v ?? "",
|
|
2752
|
+
onChange: (e) => setValue(k, e.target.value),
|
|
2753
|
+
children: [
|
|
2754
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("option", { value: "", children: "\u2014" }),
|
|
2755
|
+
field.options.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("option", { value: opt.value, children: opt.label }, opt.value))
|
|
2756
|
+
]
|
|
2757
|
+
}
|
|
2758
|
+
),
|
|
2759
|
+
err && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { style: errorStyle, children: err })
|
|
2760
|
+
] }, k);
|
|
2761
|
+
}
|
|
2762
|
+
if (field.kind === "consent") {
|
|
2763
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2764
|
+
"label",
|
|
2765
|
+
{
|
|
2766
|
+
style: {
|
|
2767
|
+
...labelStyle,
|
|
2768
|
+
flexDirection: "row",
|
|
2769
|
+
alignItems: "flex-start",
|
|
2770
|
+
gap: 8
|
|
2771
|
+
},
|
|
2772
|
+
children: [
|
|
2773
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2774
|
+
"input",
|
|
2775
|
+
{
|
|
2776
|
+
type: "checkbox",
|
|
2777
|
+
checked: v === true,
|
|
2778
|
+
onChange: (e) => setValue(k, e.target.checked),
|
|
2779
|
+
style: { marginTop: 3 }
|
|
2780
|
+
}
|
|
2781
|
+
),
|
|
2782
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { style: { fontSize: 13, fontWeight: 400 }, children: [
|
|
2783
|
+
field.label,
|
|
2784
|
+
field.url && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
|
|
2785
|
+
" ",
|
|
2786
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2787
|
+
"a",
|
|
2788
|
+
{
|
|
2789
|
+
href: field.url,
|
|
2790
|
+
target: "_blank",
|
|
2791
|
+
rel: "noopener noreferrer",
|
|
2792
|
+
style: { color: config.primaryColor },
|
|
2793
|
+
children: "\u2197"
|
|
2794
|
+
}
|
|
2795
|
+
)
|
|
2796
|
+
] })
|
|
2797
|
+
] }),
|
|
2798
|
+
err && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { style: errorStyle, children: err })
|
|
2799
|
+
]
|
|
2800
|
+
},
|
|
2801
|
+
k
|
|
2802
|
+
);
|
|
2803
|
+
}
|
|
2804
|
+
const inputType = field.kind === "email" ? "email" : field.kind === "phone" ? "tel" : "text";
|
|
2805
|
+
const maxLength = field.kind === "text" ? field.maxLength : void 0;
|
|
2806
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("label", { style: labelStyle, children: [
|
|
2807
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { children: [
|
|
2808
|
+
label,
|
|
2809
|
+
required && " *"
|
|
2810
|
+
] }),
|
|
2811
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2812
|
+
"input",
|
|
2813
|
+
{
|
|
2814
|
+
type: inputType,
|
|
2815
|
+
style: inputStyle,
|
|
2816
|
+
value: v ?? "",
|
|
2817
|
+
maxLength,
|
|
2818
|
+
onChange: (e) => setValue(k, e.target.value)
|
|
2819
|
+
}
|
|
2820
|
+
),
|
|
2821
|
+
err && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { style: errorStyle, children: err })
|
|
2822
|
+
] }, k);
|
|
2823
|
+
}),
|
|
2824
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { style: buttonRowStyle, children: [
|
|
2825
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2826
|
+
"button",
|
|
2827
|
+
{
|
|
2828
|
+
type: "button",
|
|
2829
|
+
onClick: cancelPreChatForm,
|
|
2830
|
+
style: cancelStyle,
|
|
2831
|
+
disabled: submitting,
|
|
2832
|
+
children: t("action_cancel")
|
|
2833
|
+
}
|
|
2834
|
+
),
|
|
2835
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "submit", style: submitStyle, disabled: submitting, children: preChatForm.submitLabel })
|
|
2836
|
+
] })
|
|
2837
|
+
]
|
|
2838
|
+
}
|
|
2839
|
+
);
|
|
2840
|
+
}
|
|
2841
|
+
function ChatWindow({ embedded } = {}) {
|
|
2842
|
+
const { isOpen, config, configError, t, isRtl, preChatFormVisible } = useChat();
|
|
2843
|
+
const reduced = useReducedMotion();
|
|
2844
|
+
const theme = useEffectiveTheme();
|
|
2845
|
+
const [visible, setVisible] = (0, import_react11.useState)(false);
|
|
2846
|
+
const [shouldRender, setShouldRender] = (0, import_react11.useState)(false);
|
|
2847
|
+
(0, import_react11.useEffect)(() => {
|
|
2848
|
+
if (isOpen) {
|
|
2849
|
+
setShouldRender(true);
|
|
2850
|
+
requestAnimationFrame(() => {
|
|
2851
|
+
requestAnimationFrame(() => setVisible(true));
|
|
2852
|
+
});
|
|
2853
|
+
} else {
|
|
2854
|
+
setVisible(false);
|
|
2855
|
+
if (reduced) {
|
|
2856
|
+
setShouldRender(false);
|
|
2857
|
+
} else {
|
|
2858
|
+
const timer = setTimeout(() => setShouldRender(false), 250);
|
|
2859
|
+
return () => clearTimeout(timer);
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
}, [isOpen, reduced]);
|
|
2863
|
+
if (!shouldRender) return null;
|
|
2864
|
+
const effectivePosition = isRtl ? config.position === "bottom-right" ? "bottom-left" : "bottom-right" : config.position;
|
|
2865
|
+
const colors = theme;
|
|
2866
|
+
const preset = theme.size;
|
|
2867
|
+
const radius = theme.radius;
|
|
2868
|
+
const panelBottom = config.offset.bottom + preset.bubble + 14;
|
|
2869
|
+
const style = {
|
|
2870
|
+
position: embedded ? "absolute" : "fixed",
|
|
2871
|
+
bottom: panelBottom,
|
|
2872
|
+
[effectivePosition === "bottom-left" ? "left" : "right"]: config.offset.side,
|
|
2873
|
+
width: preset.width,
|
|
2874
|
+
maxWidth: embedded ? "calc(100% - 16px)" : "calc(100vw - 40px)",
|
|
2875
|
+
height: preset.height,
|
|
2876
|
+
maxHeight: embedded ? `calc(100% - ${panelBottom + 16}px)` : `calc(100vh - ${panelBottom + 30}px)`,
|
|
2877
|
+
borderRadius: radius,
|
|
2878
|
+
overflow: "hidden",
|
|
2879
|
+
display: "flex",
|
|
2880
|
+
flexDirection: "column",
|
|
2881
|
+
// In dark mode the default 0.15 opacity black shadow is invisible
|
|
2882
|
+
// against a dark page; switch to a stronger shadow plus a subtle 1px
|
|
2883
|
+
// light outline so the panel still reads as a separated surface.
|
|
2884
|
+
boxShadow: theme.scheme === "dark" ? "0 12px 40px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.06)" : "0 8px 40px rgba(0,0,0,0.15)",
|
|
2885
|
+
zIndex: config.zIndex,
|
|
2886
|
+
background: colors.background,
|
|
2887
|
+
color: colors.text,
|
|
2888
|
+
fontSize: preset.fontSize,
|
|
2889
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
2890
|
+
opacity: visible ? 1 : 0,
|
|
2891
|
+
transform: visible ? "translateY(0) scale(1)" : "translateY(16px) scale(0.97)",
|
|
2892
|
+
transition: reduced ? "none" : "opacity 0.25s ease, transform 0.25s ease"
|
|
2893
|
+
};
|
|
2894
|
+
const isDark = theme.scheme === "dark";
|
|
2895
|
+
const poweredStyle = {
|
|
2896
|
+
textAlign: "center",
|
|
2897
|
+
padding: 6,
|
|
2898
|
+
fontSize: 10,
|
|
2899
|
+
color: isDark ? "rgba(255,255,255,0.45)" : "#aaa"
|
|
2900
|
+
};
|
|
2901
|
+
const linkStyle = {
|
|
2902
|
+
color: isDark ? "rgba(255,255,255,0.6)" : "#888",
|
|
2903
|
+
textDecoration: "underline",
|
|
2904
|
+
textUnderlineOffset: 2
|
|
2905
|
+
};
|
|
2906
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { style, dir: isRtl ? "rtl" : "ltr", children: [
|
|
2907
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ChatHeader, {}),
|
|
2908
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(IncidentBanner, {}),
|
|
2909
|
+
configError ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ConfigError, { title: t("unable_to_load"), message: configError }) : preChatFormVisible ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PreChatFormView, {}) : /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
|
|
2910
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ChatMessages, {}),
|
|
2911
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ChatSuggestions, {}),
|
|
2912
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ChatInput, {})
|
|
2913
|
+
] }),
|
|
2914
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { style: poweredStyle, children: [
|
|
2915
|
+
t("powered_by"),
|
|
2916
|
+
" ",
|
|
2917
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2918
|
+
"a",
|
|
2919
|
+
{
|
|
2920
|
+
href: "https://customerhero.app",
|
|
2921
|
+
target: "_blank",
|
|
2922
|
+
rel: "noopener noreferrer",
|
|
2923
|
+
style: linkStyle,
|
|
2924
|
+
children: "CustomerHero"
|
|
2925
|
+
}
|
|
2926
|
+
)
|
|
2927
|
+
] })
|
|
2928
|
+
] });
|
|
2929
|
+
}
|
|
2930
|
+
|
|
2931
|
+
// src/preview.tsx
|
|
2932
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2933
|
+
function PreviewBootstrap({
|
|
2934
|
+
config,
|
|
2935
|
+
banner
|
|
2936
|
+
}) {
|
|
2937
|
+
const client = useCustomerHeroClient();
|
|
2938
|
+
(0, import_react12.useEffect)(() => {
|
|
2939
|
+
client.__seedForPreview(config, { banner: banner ?? null });
|
|
2940
|
+
}, [client]);
|
|
2941
|
+
const configKey = JSON.stringify(config);
|
|
2942
|
+
const bannerKey = JSON.stringify(banner ?? null);
|
|
2943
|
+
(0, import_react12.useEffect)(() => {
|
|
2944
|
+
client.__seedForPreview(config, { banner: banner ?? null });
|
|
2945
|
+
}, [client, configKey, bannerKey]);
|
|
2946
|
+
return null;
|
|
2947
|
+
}
|
|
2948
|
+
var wrapperStyleBase = {
|
|
2949
|
+
position: "relative",
|
|
2950
|
+
overflow: "hidden"
|
|
2951
|
+
};
|
|
2952
|
+
function PreviewWidget({
|
|
2953
|
+
style,
|
|
2954
|
+
className,
|
|
2955
|
+
banner,
|
|
2956
|
+
...config
|
|
2957
|
+
}) {
|
|
2958
|
+
const initialConfig = (0, import_react12.useMemo)(() => config, []);
|
|
2959
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2960
|
+
"div",
|
|
2961
|
+
{
|
|
2962
|
+
className,
|
|
2963
|
+
style: { ...wrapperStyleBase, ...style },
|
|
2964
|
+
"data-customerhero-preview": "true",
|
|
2965
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(CustomerHeroProvider, { disableAutoFetch: true, ...initialConfig, children: [
|
|
2966
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(PreviewBootstrap, { config, banner }),
|
|
2967
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ChatBubble, { embedded: true }),
|
|
2968
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ChatWindow, { embedded: true })
|
|
2969
|
+
] })
|
|
2970
|
+
}
|
|
2971
|
+
);
|
|
2972
|
+
}
|
|
2973
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2974
|
+
0 && (module.exports = {
|
|
2975
|
+
PreviewWidget
|
|
2976
|
+
});
|