@paramms/chat-widget 1.6.1 → 1.6.3
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/dist/chatlist.js +2 -245
- package/dist/chatlist.js.map +1 -1
- package/dist/chatlist2.js +1417 -0
- package/dist/chatlist2.js.map +1 -0
- package/dist/core.js +10 -11
- package/dist/core.js.map +1 -1
- package/dist/embed-lite.js +5 -5
- package/dist/embed-lite.js.map +1 -1
- package/dist/embed.js +5 -5
- package/dist/embed.js.map +1 -1
- package/dist/hooks.js +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +453 -412
- package/dist/index.js.map +1 -1
- package/dist/outbox.js +1 -1
- package/dist/react.js +331 -299
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
- package/dist/codec.js +0 -1174
- package/dist/codec.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var Be = Object.defineProperty;
|
|
2
|
-
var $e = (t, e,
|
|
3
|
-
var C = (t, e,
|
|
4
|
-
import { l as Re, b as ve, p as Me, r as Ae, a as qe } from "./
|
|
5
|
-
import { h as
|
|
6
|
-
import { P as
|
|
7
|
-
import { e as
|
|
8
|
-
import { E2ESession as
|
|
9
|
-
const
|
|
2
|
+
var $e = (t, e, l) => e in t ? Be(t, e, { enumerable: !0, configurable: !0, writable: !0, value: l }) : t[e] = l;
|
|
3
|
+
var C = (t, e, l) => $e(t, typeof e != "symbol" ? e + "" : e, l);
|
|
4
|
+
import { l as Re, b as ve, p as Me, r as Ae, a as qe, m as Ne } from "./chatlist2.js";
|
|
5
|
+
import { h as dt } from "./chatlist2.js";
|
|
6
|
+
import { P as Oe, C as De, b as He } from "./outbox.js";
|
|
7
|
+
import { e as ut } from "./outbox.js";
|
|
8
|
+
import { E2ESession as _e, extractX3DHInit as Ue } from "./e2e.js";
|
|
9
|
+
const Fe = `
|
|
10
10
|
.ocw { ${Re("ocw")}
|
|
11
11
|
position:relative;
|
|
12
12
|
display:flex; flex-direction:column; height:100%; min-height:320px; background:var(--ocw-bg);
|
|
@@ -197,30 +197,30 @@ const Ue = `
|
|
|
197
197
|
.ocw-bubble-wrap:hover .ocw-translate-btn { opacity:1; }
|
|
198
198
|
.ocw-translation { margin-top:6px; padding-top:6px; border-top:1px solid var(--ocw-line); font-size:13px; line-height:1.45; }
|
|
199
199
|
.ocw-translation::before { content:'🌐 '; opacity:.75; }
|
|
200
|
-
`, ke = "objectchat-widget-styles",
|
|
201
|
-
function
|
|
200
|
+
`, ke = "objectchat-widget-styles", We = ["👍", "❤️", "😂", "😮", "😢", "🙏"], Ge = 400, Ke = '<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M22 2 11 13M22 2l-7 20-4-9-9-4 20-7z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
|
201
|
+
function Ve() {
|
|
202
202
|
if (typeof document > "u" || document.getElementById(ke)) return;
|
|
203
203
|
const t = document.createElement("style");
|
|
204
|
-
t.id = ke, t.textContent =
|
|
204
|
+
t.id = ke, t.textContent = Fe, document.head.appendChild(t);
|
|
205
205
|
}
|
|
206
206
|
const Ce = "ocw-webfont";
|
|
207
|
-
function
|
|
207
|
+
function Ye() {
|
|
208
208
|
if (typeof document > "u" || document.getElementById(Ce)) return;
|
|
209
209
|
const t = document.createElement("link");
|
|
210
210
|
t.id = Ce, t.rel = "stylesheet", t.href = "https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700&family=Nunito:wght@400;500;600;700&display=swap", document.head.appendChild(t);
|
|
211
211
|
}
|
|
212
|
-
function n(t, e,
|
|
213
|
-
const
|
|
214
|
-
return e && (
|
|
212
|
+
function n(t, e, l) {
|
|
213
|
+
const r = document.createElement(t);
|
|
214
|
+
return e && (r.className = e), l !== void 0 && (r.textContent = l), r;
|
|
215
215
|
}
|
|
216
|
-
function
|
|
216
|
+
function Xe(t) {
|
|
217
217
|
try {
|
|
218
218
|
return new Date(t).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
|
219
219
|
} catch {
|
|
220
220
|
return "";
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
|
-
function
|
|
223
|
+
function se(t) {
|
|
224
224
|
var e;
|
|
225
225
|
switch (t.kind) {
|
|
226
226
|
case "text":
|
|
@@ -237,9 +237,9 @@ function ce(t) {
|
|
|
237
237
|
return `📅 ${t.title} — ${new Date(t.startIso).toLocaleString()}`;
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
class
|
|
240
|
+
class Qe {
|
|
241
241
|
/** Last seq the guest has seen per conversationId — used to compute unread badges. */
|
|
242
|
-
constructor(e,
|
|
242
|
+
constructor(e, l, r, s = {}) {
|
|
243
243
|
C(this, "scroll");
|
|
244
244
|
C(this, "chips");
|
|
245
245
|
C(this, "typing");
|
|
@@ -274,59 +274,59 @@ class Xe {
|
|
|
274
274
|
/** Whether the subject card (server Subject entity, mount config fallback)
|
|
275
275
|
* has been built — built once when data first arrives. */
|
|
276
276
|
C(this, "subjectBuilt", !1);
|
|
277
|
-
var z, O,
|
|
278
|
-
this.root = e, this.me =
|
|
279
|
-
const w =
|
|
280
|
-
w && e.style.setProperty("--ocw-accent2", w), this.cfgAccent2 =
|
|
277
|
+
var z, O, T, _, a, i, v, u, x, k, S;
|
|
278
|
+
this.root = e, this.me = l, this.h = r, this.cfg = s, Ve(), s.webfont !== !1 && Ye(), e.replaceChildren(), e.classList.add("ocw"), s.accent && e.style.setProperty("--ocw-accent", s.accent);
|
|
279
|
+
const w = s.accent2 ?? s.accent;
|
|
280
|
+
w && e.style.setProperty("--ocw-accent2", w), this.cfgAccent2 = s.accent2, e.dataset.theme = s.theme ?? "light";
|
|
281
281
|
const b = n("div", "ocw-head");
|
|
282
282
|
if (this.h.onBack) {
|
|
283
283
|
const f = n("button", "ocw-back", "‹");
|
|
284
284
|
f.type = "button", f.setAttribute("aria-label", "Back"), f.addEventListener("click", () => this.h.onBack()), b.append(f);
|
|
285
285
|
}
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
const
|
|
289
|
-
this.headerName = n("div", "ocw-head-name", ((
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
for (const f of
|
|
293
|
-
const
|
|
294
|
-
|
|
286
|
+
const y = ((z = s.subject) == null ? void 0 : z.ownerLabel) ?? ((O = s.subject) == null ? void 0 : O.title) ?? "", d = n("div", "ocw-avatar");
|
|
287
|
+
y.trim() && (d.textContent = y.trim()[0].toUpperCase(), b.append(d));
|
|
288
|
+
const h = n("div", "ocw-head-main");
|
|
289
|
+
this.headerName = n("div", "ocw-head-name", ((T = s.subject) == null ? void 0 : T.ownerLabel) ?? ((_ = s.subject) == null ? void 0 : _.title) ?? ""), h.append(this.headerName), this.headStatus = n("div", "ocw-head-status"), this.headStatus.style.display = "none", h.append(this.headStatus), (a = s.subject) != null && a.subtitle && h.append(n("div", "ocw-head-meta", s.subject.subtitle)), b.append(h), this.statusBadge = n("span", "ocw-badge", ((i = s.subject) == null ? void 0 : i.status) ?? ""), (v = s.subject) != null && v.status || (this.statusBadge.style.display = "none"), b.append(this.statusBadge), this.e2eBadge = n("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", b.append(this.e2eBadge), this.connStatus = n("span", "ocw-conn-status"), this.connStatus.style.display = "none", b.append(this.connStatus), b.append(n("button", "ocw-menu", "⋯")), this.chips = n("div", "ocw-chiprow"), this.scroll = n("div", "ocw-scroll"), this.subjectCard = n("div", "ocw-subject"), this.typing = n("div", "ocw-typing");
|
|
290
|
+
const m = n("div", "ocw-typing-bubble");
|
|
291
|
+
m.append(n("div", "ocw-typing-dot"), n("div", "ocw-typing-dot"), n("div", "ocw-typing-dot")), this.typing.append(m), this.quick = n("div", "ocw-quick");
|
|
292
|
+
for (const f of s.quickReplies ?? []) {
|
|
293
|
+
const I = n("button", void 0, f);
|
|
294
|
+
I.addEventListener("click", () => {
|
|
295
295
|
this.h.onSend(f), this.quick.style.display = "none";
|
|
296
|
-
}), this.quick.append(
|
|
296
|
+
}), this.quick.append(I);
|
|
297
297
|
}
|
|
298
|
-
this.formHost = n("div", "ocw-form-host"), this.csatPanel = n("div", "ocw-csat"), this.csatPanel.style.display = "none", this.awayNotice = n("div", "ocw-away"), this.awayNotice.style.display = "none", this.preChatPanel = n("div", "ocw-prechat"), this.preChatPanel.style.display = "none", this.deflectPanel = n("div", "ocw-deflect"), this.deflectPanel.style.display = "none", this.input = n("textarea", void 0), this.input.rows = 1, this.input.placeholder = ((
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
var f,
|
|
304
|
-
this.sendBtn.disabled = this.input.value.trim().length === 0, this.autoGrowInput(), this.storeRef && !this.storeRef.messages().some((N) => N.senderRole === "guest") ? (
|
|
298
|
+
this.formHost = n("div", "ocw-form-host"), this.csatPanel = n("div", "ocw-csat"), this.csatPanel.style.display = "none", this.awayNotice = n("div", "ocw-away"), this.awayNotice.style.display = "none", this.preChatPanel = n("div", "ocw-prechat"), this.preChatPanel.style.display = "none", this.deflectPanel = n("div", "ocw-deflect"), this.deflectPanel.style.display = "none", this.input = n("textarea", void 0), this.input.rows = 1, this.input.placeholder = ((u = s.i18n) == null ? void 0 : u.placeholder) ?? "Message…";
|
|
299
|
+
const c = n("button", "ocw-sendbtn");
|
|
300
|
+
c.type = "button";
|
|
301
|
+
const j = (x = s.i18n) == null ? void 0 : x.send;
|
|
302
|
+
j ? (c.textContent = j, c.classList.add("ocw-sendbtn-label"), c.setAttribute("aria-label", j)) : (c.innerHTML = Ke, c.setAttribute("aria-label", "Send message")), c.disabled = !0, this.sendBtn = c, c.addEventListener("click", () => this.flushSend()), this.input.addEventListener("input", () => {
|
|
303
|
+
var f, I;
|
|
304
|
+
this.sendBtn.disabled = this.input.value.trim().length === 0, this.autoGrowInput(), this.storeRef && !this.storeRef.messages().some((N) => N.senderRole === "guest") ? (I = (f = this.h).onDeflectQuery) == null || I.call(f, this.input.value) : this.hideDeflection();
|
|
305
305
|
}), this.input.addEventListener("keydown", (f) => {
|
|
306
306
|
f.isComposing || f.keyCode === 229 || (f.key === "Enter" && !f.shiftKey ? (f.preventDefault(), this.flushSend()) : this.signalTyping());
|
|
307
307
|
});
|
|
308
308
|
const R = n("button", "ocw-attach", "📎");
|
|
309
309
|
R.title = "Attach image or file";
|
|
310
|
-
const
|
|
311
|
-
|
|
310
|
+
const E = document.createElement("input");
|
|
311
|
+
E.type = "file", E.accept = "image/*,.pdf,.txt,.doc,.docx", E.style.display = "none", R.addEventListener("click", () => E.click()), E.addEventListener("change", () => {
|
|
312
312
|
var f;
|
|
313
|
-
(f =
|
|
313
|
+
(f = E.files) != null && f[0] && this.h.onAttach && this.h.onAttach(E.files[0]), E.value = "";
|
|
314
314
|
});
|
|
315
315
|
const A = n("div", "ocw-input");
|
|
316
|
-
A.append(R,
|
|
317
|
-
const
|
|
318
|
-
((k =
|
|
316
|
+
A.append(R, E, this.input, c);
|
|
317
|
+
const P = n("div", "ocw-footer");
|
|
318
|
+
((k = s.i18n) == null ? void 0 : k.poweredBy) !== void 0 ? P.textContent = s.i18n.poweredBy : P.innerHTML = 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = P, this.reopenBtn = n("button", "ocw-reopen", ((S = this.cfg.i18n) == null ? void 0 : S.reopen) ?? "Reopen conversation"), this.reopenBtn.type = "button", this.reopenBtn.addEventListener("click", () => {
|
|
319
319
|
this.reopenBtn.style.display = "none";
|
|
320
320
|
const f = this.root.querySelector(".ocw-input textarea");
|
|
321
321
|
f == null || f.focus();
|
|
322
322
|
}), e.append(b, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.preChatPanel, this.deflectPanel, this.awayNotice, A, this.reopenBtn, this.footer);
|
|
323
|
-
const
|
|
324
|
-
e.classList.toggle("ocw-compact", f > 0 && f <
|
|
323
|
+
const B = (f) => {
|
|
324
|
+
e.classList.toggle("ocw-compact", f > 0 && f < Ge);
|
|
325
325
|
};
|
|
326
|
-
|
|
326
|
+
B(e.clientWidth), typeof ResizeObserver < "u" && (this.compactObserver = new ResizeObserver((f) => {
|
|
327
327
|
var N;
|
|
328
|
-
const
|
|
329
|
-
|
|
328
|
+
const I = ((N = f[0]) == null ? void 0 : N.contentRect.width) ?? e.clientWidth;
|
|
329
|
+
B(I);
|
|
330
330
|
}), this.compactObserver.observe(e));
|
|
331
331
|
}
|
|
332
332
|
/** Returns the scroll container so history.ts can attach scroll listeners. */
|
|
@@ -335,13 +335,13 @@ class Xe {
|
|
|
335
335
|
}
|
|
336
336
|
/** Registers a cleanup fn removed on destroy() to prevent listener leaks. */
|
|
337
337
|
setScrollCleanup(e) {
|
|
338
|
-
var
|
|
339
|
-
(
|
|
338
|
+
var l;
|
|
339
|
+
(l = this.scrollCleanup) == null || l.call(this), this.scrollCleanup = e;
|
|
340
340
|
}
|
|
341
341
|
/** Call when the widget is unmounted. Disconnects scroll listeners and clears timers. */
|
|
342
342
|
destroy() {
|
|
343
|
-
var e,
|
|
344
|
-
(e = this.scrollCleanup) == null || e.call(this), this.scrollCleanup = null, this.typingTimer && (clearTimeout(this.typingTimer), this.typingTimer = null), (
|
|
343
|
+
var e, l;
|
|
344
|
+
(e = this.scrollCleanup) == null || e.call(this), this.scrollCleanup = null, this.typingTimer && (clearTimeout(this.typingTimer), this.typingTimer = null), (l = this.compactObserver) == null || l.disconnect(), this.compactObserver = null;
|
|
345
345
|
}
|
|
346
346
|
flushSend() {
|
|
347
347
|
this.hideDeflection();
|
|
@@ -365,110 +365,110 @@ class Xe {
|
|
|
365
365
|
this.cfg.i18n = { ...this.cfg.i18n ?? {}, aiAssistant: e };
|
|
366
366
|
}
|
|
367
367
|
render(e) {
|
|
368
|
-
var
|
|
368
|
+
var E, A, P, B, z, O, T, _;
|
|
369
369
|
if (this.storeRef = e, e.accent && (this.root.style.setProperty("--ocw-accent", e.accent), this.root.style.setProperty("--ocw-accent2", this.cfgAccent2 ?? e.accent)), this.e2eBadge.style.display = e.e2e ? "inline-flex" : "none", this.buildSubjectCard(e), e.subject) {
|
|
370
|
-
const a = (
|
|
370
|
+
const a = (E = this.cfg.subject) == null ? void 0 : E.ownerLabel;
|
|
371
371
|
a && (this.headerName.textContent = a);
|
|
372
372
|
}
|
|
373
373
|
this.quick.style.display = e.messages().length === 0 ? "flex" : "none", this.chips.replaceChildren();
|
|
374
|
-
const
|
|
375
|
-
this.chips.style.display =
|
|
376
|
-
for (const a of
|
|
377
|
-
const
|
|
374
|
+
const l = e.visibleActions();
|
|
375
|
+
this.chips.style.display = l.length ? "flex" : "none";
|
|
376
|
+
for (const a of l) this.chips.append(this.chipEl(a));
|
|
377
|
+
const r = this.scroll.scrollHeight, s = this.scroll.scrollTop;
|
|
378
378
|
if (this.scroll.replaceChildren(), this.subjectCard.childNodes.length && this.scroll.append(this.subjectCard), e.hasMoreHistory) {
|
|
379
379
|
const a = n("div", "ocw-load-more");
|
|
380
380
|
a.textContent = "↑ Loading earlier messages…", a.style.pointerEvents = "none", this.scroll.append(a);
|
|
381
381
|
}
|
|
382
382
|
let w = 0, b = null;
|
|
383
|
-
const
|
|
384
|
-
for (let a = 0; a <
|
|
385
|
-
const i =
|
|
386
|
-
this.scroll.append(this.messageEl(i, e,
|
|
383
|
+
const y = [...e.messages()];
|
|
384
|
+
for (let a = 0; a < y.length; a++) {
|
|
385
|
+
const i = y[a], v = i.senderRole !== "system" && i.senderId !== this.me && !i.internal && i.senderId !== b;
|
|
386
|
+
this.scroll.append(this.messageEl(i, e, v, a === y.length - 1)), i.senderRole !== "system" && (b = i.senderId), i.senderId !== this.me && i.seq > w && (w = i.seq);
|
|
387
387
|
}
|
|
388
|
-
|
|
389
|
-
const
|
|
390
|
-
this.typing.classList.toggle("active",
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
const
|
|
394
|
-
if (!!((A = e.preChat) != null && A.enabled) && !this.preChatDone && !
|
|
395
|
-
this.preChatBuilt || this.buildPreChatPanel(e.preChat), this.preChatPanel.style.display = "block", this.awayNotice.style.display = "none", (
|
|
388
|
+
s > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - r + s : this.scroll.scrollTop = this.scroll.scrollHeight, w > 0 && this.h.onReadUpTo(w);
|
|
389
|
+
const d = [...e.typing];
|
|
390
|
+
this.typing.classList.toggle("active", d.length > 0);
|
|
391
|
+
const h = this.typing.querySelector(".ocw-typing-bubble");
|
|
392
|
+
h && h.setAttribute("aria-label", d.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block";
|
|
393
|
+
const m = e.messages().some((a) => a.senderRole === "guest");
|
|
394
|
+
if (!!((A = e.preChat) != null && A.enabled) && !this.preChatDone && !m && (e.preChat.showWhen !== "offline" || e.offline))
|
|
395
|
+
this.preChatBuilt || this.buildPreChatPanel(e.preChat), this.preChatPanel.style.display = "block", this.awayNotice.style.display = "none", (P = this.root.querySelector(".ocw-input")) == null || P.style.setProperty("display", "none");
|
|
396
396
|
else {
|
|
397
397
|
if (this.preChatPanel.style.display = "none", e.offline) {
|
|
398
398
|
this.awayNotice.firstChild || this.awayNotice.append(n("span", "ocw-away-icon", "🌙"), n("span", "", ""));
|
|
399
399
|
const a = this.awayNotice.lastChild;
|
|
400
|
-
a.textContent = e.offlineMessage || ((
|
|
400
|
+
a.textContent = e.offlineMessage || ((B = this.cfg.i18n) == null ? void 0 : B.offline) || "We're away right now — send your message and we'll reply as soon as we're back.", this.awayNotice.style.display = "flex";
|
|
401
401
|
} else
|
|
402
402
|
this.awayNotice.style.display = "none";
|
|
403
403
|
(z = this.root.querySelector(".ocw-input")) == null || z.style.removeProperty("display");
|
|
404
404
|
}
|
|
405
|
-
const
|
|
406
|
-
this.h.onCsat && !this.csatSubmitted &&
|
|
407
|
-
const R =
|
|
408
|
-
if (e.offline ? (this.headStatus.textContent = `● ${e.offlineMessage || ((O = this.cfg.i18n) == null ? void 0 : O.away) || "Away"}`, this.headStatus.className = "ocw-head-status away", this.headStatus.style.display = "") : e.conversationId ? (this.headStatus.textContent = `● ${((
|
|
405
|
+
const j = ["resolved", "closed", "sold", "issued", "checked_out"];
|
|
406
|
+
this.h.onCsat && !this.csatSubmitted && j.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
|
|
407
|
+
const R = j.includes(e.state);
|
|
408
|
+
if (e.offline ? (this.headStatus.textContent = `● ${e.offlineMessage || ((O = this.cfg.i18n) == null ? void 0 : O.away) || "Away"}`, this.headStatus.className = "ocw-head-status away", this.headStatus.style.display = "") : e.conversationId ? (this.headStatus.textContent = `● ${((T = this.cfg.i18n) == null ? void 0 : T.online) ?? "Online"}`, this.headStatus.className = "ocw-head-status online", this.headStatus.style.display = "") : this.headStatus.style.display = "none", R && e.messages().length > 0) {
|
|
409
409
|
const a = n("div", "ocw-resolved-note", `— ${((_ = this.cfg.i18n) == null ? void 0 : _.resolved) ?? "Marked as resolved"} —`);
|
|
410
410
|
this.scroll.append(a), this.reopenBtn.style.display = "block";
|
|
411
411
|
} else
|
|
412
412
|
this.reopenBtn.style.display = "none";
|
|
413
413
|
}
|
|
414
|
-
setConnStatus(e,
|
|
414
|
+
setConnStatus(e, l) {
|
|
415
415
|
if (e === "open") {
|
|
416
416
|
this.connStatus.style.display = "none";
|
|
417
417
|
return;
|
|
418
418
|
}
|
|
419
419
|
this.connStatus.style.display = "";
|
|
420
|
-
const
|
|
421
|
-
this.connStatus.className = `ocw-conn-status${
|
|
420
|
+
const r = e === "error";
|
|
421
|
+
this.connStatus.className = `ocw-conn-status${r ? " err" : e === "reconnecting" ? " warn" : ""}`, this.connStatus.textContent = r ? `⚠ ${l ?? "Chat unavailable"}` : e === "reconnecting" ? l ?? "↻ reconnecting…" : "● connecting…";
|
|
422
422
|
}
|
|
423
423
|
buildPreChatPanel(e) {
|
|
424
|
-
var
|
|
424
|
+
var d;
|
|
425
425
|
this.preChatBuilt = !0, this.preChatPanel.replaceChildren(), this.preChatPanel.append(n("div", "ocw-prechat-title", e.title ?? "Before we start…"));
|
|
426
|
-
const
|
|
427
|
-
for (const
|
|
428
|
-
const
|
|
429
|
-
|
|
426
|
+
const l = n("div", "ocw-offline-form"), r = {};
|
|
427
|
+
for (const h of e.fields ?? ["name", "email"]) {
|
|
428
|
+
const m = n("input", "ocw-offline-input");
|
|
429
|
+
m.type = h === "email" ? "email" : h === "phone" ? "tel" : "text", m.placeholder = h === "name" ? "Your name" : h === "email" ? "Your email" : "Your phone number", r[h] = m, l.append(m);
|
|
430
430
|
}
|
|
431
|
-
let
|
|
432
|
-
if ((
|
|
433
|
-
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
for (const
|
|
437
|
-
const
|
|
438
|
-
|
|
431
|
+
let s = null;
|
|
432
|
+
if ((d = e.topics) != null && d.length) {
|
|
433
|
+
s = n("select", void 0);
|
|
434
|
+
const h = document.createElement("option");
|
|
435
|
+
h.value = "", h.textContent = "What is this about?", s.append(h);
|
|
436
|
+
for (const m of e.topics) {
|
|
437
|
+
const c = document.createElement("option");
|
|
438
|
+
c.value = m, c.textContent = m, s.append(c);
|
|
439
439
|
}
|
|
440
|
-
|
|
440
|
+
l.append(s);
|
|
441
441
|
}
|
|
442
442
|
let w = null, b = null;
|
|
443
443
|
if (e.callbackOption) {
|
|
444
|
-
const
|
|
445
|
-
w = document.createElement("input"), w.type = "checkbox",
|
|
444
|
+
const h = n("label", "ocw-prechat-cb");
|
|
445
|
+
w = document.createElement("input"), w.type = "checkbox", h.append(w, document.createTextNode("📞 Request a call back")), l.append(h), r.phone || (b = n("input", "ocw-offline-input"), b.type = "tel", b.placeholder = "Phone number for the call", b.style.display = "none", w.addEventListener("change", () => b.style.setProperty("display", w.checked ? "block" : "none")), l.append(b));
|
|
446
446
|
}
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
var
|
|
450
|
-
const
|
|
451
|
-
if (
|
|
452
|
-
|
|
447
|
+
const y = n("button", "ocw-offline-submit", "Start chat");
|
|
448
|
+
y.type = "button", y.addEventListener("click", () => {
|
|
449
|
+
var j, R, E, A, P, B, z;
|
|
450
|
+
const h = (j = r.email) == null ? void 0 : j.value.trim();
|
|
451
|
+
if (r.email && (!h || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(h))) {
|
|
452
|
+
r.email.focus();
|
|
453
453
|
return;
|
|
454
454
|
}
|
|
455
|
-
const
|
|
456
|
-
if (
|
|
457
|
-
(
|
|
455
|
+
const m = !!(w != null && w.checked), c = (((R = r.phone) == null ? void 0 : R.value) ?? (b == null ? void 0 : b.value) ?? "").trim();
|
|
456
|
+
if (m && !c) {
|
|
457
|
+
(E = r.phone ?? b) == null || E.focus();
|
|
458
458
|
return;
|
|
459
459
|
}
|
|
460
|
-
if (
|
|
461
|
-
|
|
460
|
+
if (s && ((A = e.topics) != null && A.length) && !s.value) {
|
|
461
|
+
s.focus();
|
|
462
462
|
return;
|
|
463
463
|
}
|
|
464
|
-
|
|
465
|
-
...(
|
|
466
|
-
...
|
|
467
|
-
...
|
|
468
|
-
...
|
|
469
|
-
...
|
|
464
|
+
y.disabled = !0, this.completePreChat(), (z = (B = this.h).onPreChat) == null || z.call(B, {
|
|
465
|
+
...(P = r.name) != null && P.value.trim() ? { name: r.name.value.trim() } : {},
|
|
466
|
+
...h ? { email: h } : {},
|
|
467
|
+
...c ? { phone: c } : {},
|
|
468
|
+
...s != null && s.value ? { topic: s.value } : {},
|
|
469
|
+
...m ? { callback: !0 } : {}
|
|
470
470
|
});
|
|
471
|
-
}),
|
|
471
|
+
}), l.append(y), this.preChatPanel.append(l);
|
|
472
472
|
}
|
|
473
473
|
/** Mark pre-chat complete (submitted now or in a previous session). */
|
|
474
474
|
completePreChat() {
|
|
@@ -478,9 +478,9 @@ class Xe {
|
|
|
478
478
|
showDeflection(e) {
|
|
479
479
|
if (!e.length) return this.hideDeflection();
|
|
480
480
|
this.deflectPanel.replaceChildren(), this.deflectPanel.append(n("div", "ocw-deflect-hint", "Instant answers — tap to expand"));
|
|
481
|
-
for (const
|
|
482
|
-
const
|
|
483
|
-
|
|
481
|
+
for (const l of e.slice(0, 3)) {
|
|
482
|
+
const r = n("button", "ocw-deflect-card");
|
|
483
|
+
r.append(n("div", "ocw-deflect-q", l.title), n("div", "ocw-deflect-a", l.answer)), r.addEventListener("click", () => r.classList.toggle("open")), this.deflectPanel.append(r);
|
|
484
484
|
}
|
|
485
485
|
this.deflectPanel.style.display = "flex";
|
|
486
486
|
}
|
|
@@ -489,192 +489,192 @@ class Xe {
|
|
|
489
489
|
}
|
|
490
490
|
buildCsatPanel() {
|
|
491
491
|
this.csatPanel.replaceChildren(), this.csatPanel.append(n("div", "ocw-csat-title", "How did we do?"));
|
|
492
|
-
const e = n("div", "ocw-csat-stars"),
|
|
493
|
-
for (let
|
|
494
|
-
const
|
|
495
|
-
|
|
492
|
+
const e = n("div", "ocw-csat-stars"), l = [];
|
|
493
|
+
for (let r = 1; r <= 5; r++) {
|
|
494
|
+
const s = n("button", "ocw-csat-star", "★");
|
|
495
|
+
s.dataset.score = String(r), s.addEventListener("mouseenter", () => l.forEach((w, b) => w.classList.toggle("lit", b < r))), s.addEventListener("mouseleave", () => l.forEach((w) => w.classList.remove("lit"))), s.addEventListener("click", () => {
|
|
496
496
|
var w, b;
|
|
497
|
-
this.csatSubmitted = !0, this.csatPanel.replaceChildren(n("div", "ocw-csat-done", `Thanks for your ${
|
|
498
|
-
}),
|
|
497
|
+
this.csatSubmitted = !0, this.csatPanel.replaceChildren(n("div", "ocw-csat-done", `Thanks for your ${r}★ rating!`)), (b = (w = this.h).onCsat) == null || b.call(w, r);
|
|
498
|
+
}), l.push(s), e.append(s);
|
|
499
499
|
}
|
|
500
500
|
this.csatPanel.append(e);
|
|
501
501
|
}
|
|
502
502
|
buildSubjectCard(e) {
|
|
503
503
|
if (this.subjectBuilt) return;
|
|
504
|
-
const
|
|
505
|
-
if (!
|
|
506
|
-
this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(n("div", "ocw-subject-title",
|
|
504
|
+
const l = e.subject, r = this.cfg.subject, s = (l == null ? void 0 : l.title) ?? (r == null ? void 0 : r.title);
|
|
505
|
+
if (!s) return;
|
|
506
|
+
this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(n("div", "ocw-subject-title", s)), r != null && r.subtitle && this.subjectCard.append(n("div", "ocw-subject-sub", r.subtitle));
|
|
507
507
|
const w = n("div", "ocw-tags");
|
|
508
|
-
if (
|
|
509
|
-
else for (const
|
|
508
|
+
if (l) for (const [y, d] of Object.entries(l.fields)) w.append(n("span", "ocw-tag", `${y}: ${d}`));
|
|
509
|
+
else for (const y of (r == null ? void 0 : r.tags) ?? []) w.append(n("span", "ocw-tag", y));
|
|
510
510
|
w.childNodes.length && this.subjectCard.append(w);
|
|
511
|
-
const b = (
|
|
511
|
+
const b = (l == null ? void 0 : l.state) ?? (r == null ? void 0 : r.status);
|
|
512
512
|
b && (this.statusBadge.textContent = b, this.statusBadge.style.display = "inline-flex");
|
|
513
513
|
}
|
|
514
514
|
chipEl(e) {
|
|
515
|
-
const
|
|
516
|
-
return
|
|
517
|
-
var
|
|
518
|
-
e.confirm && !await this.confirm(e.label) || ((
|
|
519
|
-
}),
|
|
515
|
+
const l = n("button", "ocw-chip", e.icon ? `${e.icon} ${e.label}` : e.label);
|
|
516
|
+
return l.dataset.actionId = e.id, l.addEventListener("click", async () => {
|
|
517
|
+
var r;
|
|
518
|
+
e.confirm && !await this.confirm(e.label) || ((r = e.input) != null && r.length ? this.openForm(e) : this.h.onInvoke(e.id));
|
|
519
|
+
}), l;
|
|
520
520
|
}
|
|
521
521
|
/** In-widget confirmation modal (replaces window.confirm). */
|
|
522
522
|
confirm(e) {
|
|
523
|
-
return new Promise((
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
const w = n("div", "ocw-modal-actions"), b = n("button", "ocw-modal-cancel", "Cancel"),
|
|
527
|
-
|
|
523
|
+
return new Promise((l) => {
|
|
524
|
+
const r = n("div", "ocw-modal"), s = n("div", "ocw-modal-card");
|
|
525
|
+
s.append(n("div", "ocw-modal-title", e)), s.append(n("div", "ocw-modal-body", `Confirm “${e}”?`));
|
|
526
|
+
const w = n("div", "ocw-modal-actions"), b = n("button", "ocw-modal-cancel", "Cancel"), y = n("button", "ocw-modal-ok", "Confirm"), d = (h) => {
|
|
527
|
+
r.remove(), l(h);
|
|
528
528
|
};
|
|
529
|
-
b.addEventListener("click", () =>
|
|
530
|
-
|
|
531
|
-
}), w.append(b,
|
|
529
|
+
b.addEventListener("click", () => d(!1)), y.addEventListener("click", () => d(!0)), r.addEventListener("click", (h) => {
|
|
530
|
+
h.target === r && d(!1);
|
|
531
|
+
}), w.append(b, y), s.append(w), r.append(s), this.root.append(r), y.focus();
|
|
532
532
|
});
|
|
533
533
|
}
|
|
534
534
|
/** Inline form for a form-effect action: typed inputs (date picker, number,
|
|
535
535
|
* text) rendered above the composer — no browser prompts. */
|
|
536
536
|
openForm(e) {
|
|
537
|
-
var
|
|
537
|
+
var y, d;
|
|
538
538
|
this.formHost.replaceChildren();
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
const
|
|
542
|
-
for (const
|
|
543
|
-
const
|
|
544
|
-
if (
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
for (const
|
|
539
|
+
const l = n("div", "ocw-form");
|
|
540
|
+
l.append(n("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
|
|
541
|
+
const r = /* @__PURE__ */ new Map();
|
|
542
|
+
for (const h of e.input ?? []) {
|
|
543
|
+
const m = n("label", "ocw-form-row");
|
|
544
|
+
if (m.append(n("span", "ocw-form-lbl", h.label)), h.type === "select" && ((y = h.options) != null && y.length)) {
|
|
545
|
+
const c = n("select", "ocw-form-input");
|
|
546
|
+
h.required || c.append(n("option", void 0, "— select —"));
|
|
547
|
+
for (const j of h.options) {
|
|
548
548
|
const R = n("option");
|
|
549
|
-
R.value =
|
|
549
|
+
R.value = j, R.textContent = j, c.append(R);
|
|
550
550
|
}
|
|
551
|
-
|
|
551
|
+
h.required && (c.required = !0), m.append(c), r.set(h.name, c);
|
|
552
552
|
} else {
|
|
553
|
-
const
|
|
554
|
-
|
|
553
|
+
const c = n("input", "ocw-form-input");
|
|
554
|
+
c.type = h.type === "number" ? "number" : h.type === "date" ? "datetime-local" : "text", h.required && (c.required = !0), m.append(c), r.set(h.name, c);
|
|
555
555
|
}
|
|
556
|
-
|
|
556
|
+
l.append(m);
|
|
557
557
|
}
|
|
558
|
-
const
|
|
558
|
+
const s = n("div", "ocw-form-actions"), w = n("button", "ocw-form-cancel", "Cancel"), b = n("button", "ocw-form-submit", "Send");
|
|
559
559
|
w.addEventListener("click", () => this.formHost.replaceChildren()), b.addEventListener("click", () => {
|
|
560
|
-
const
|
|
561
|
-
for (const [
|
|
562
|
-
if (
|
|
563
|
-
|
|
560
|
+
const h = {};
|
|
561
|
+
for (const [m, c] of r) {
|
|
562
|
+
if (c.required && !c.value) {
|
|
563
|
+
c.style.borderColor = "#e5484d";
|
|
564
564
|
return;
|
|
565
565
|
}
|
|
566
|
-
|
|
566
|
+
h[m] = c.type === "number" ? Number(c.value) : c.value;
|
|
567
567
|
}
|
|
568
|
-
this.formHost.replaceChildren(), this.h.onInvoke(e.id,
|
|
569
|
-
}),
|
|
568
|
+
this.formHost.replaceChildren(), this.h.onInvoke(e.id, h);
|
|
569
|
+
}), s.append(w, b), l.append(s), this.formHost.append(l), (d = r.values().next().value) == null || d.focus();
|
|
570
570
|
}
|
|
571
|
-
messageEl(e,
|
|
572
|
-
var R,
|
|
571
|
+
messageEl(e, l, r = !1, s = !1) {
|
|
572
|
+
var R, E, A, P, B, z, O, T, _;
|
|
573
573
|
if (e.senderRole === "system") {
|
|
574
574
|
const a = n("div", "ocw-sys");
|
|
575
|
-
return a.textContent = e.deletedAt ? "message deleted" :
|
|
575
|
+
return a.textContent = e.deletedAt ? "message deleted" : se(e.content), a;
|
|
576
576
|
}
|
|
577
|
-
const w = e.senderId === this.me, b = !!e.internal,
|
|
578
|
-
if (
|
|
579
|
-
const a = e.senderRole === "bot" ? ((R = this.cfg.i18n) == null ? void 0 : R.aiAssistant) ?? "AI Assistant" : ((
|
|
580
|
-
|
|
577
|
+
const w = e.senderId === this.me, b = !!e.internal, y = n("div", `ocw-row ${b ? "ocw-note mine" : w ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`), d = n("div");
|
|
578
|
+
if (r) {
|
|
579
|
+
const a = e.senderRole === "bot" ? ((R = this.cfg.i18n) == null ? void 0 : R.aiAssistant) ?? "AI Assistant" : ((E = this.cfg.subject) == null ? void 0 : E.ownerLabel) ?? ((A = this.cfg.subject) == null ? void 0 : A.title) ?? "Support";
|
|
580
|
+
d.append(n("div", "ocw-msg-sender", a));
|
|
581
581
|
}
|
|
582
|
-
const
|
|
582
|
+
const h = n("div", "ocw-bubble-wrap");
|
|
583
583
|
if (e.replyToId) {
|
|
584
584
|
const a = n("div", "ocw-reply-to", "↩ replying to a message");
|
|
585
|
-
a.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic",
|
|
585
|
+
a.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", d.append(a);
|
|
586
586
|
}
|
|
587
|
-
const
|
|
588
|
-
let
|
|
589
|
-
if (e.deletedAt)
|
|
587
|
+
const m = n("div", "ocw-bubble");
|
|
588
|
+
let c = null;
|
|
589
|
+
if (e.deletedAt) m.append(n("span", "ocw-deleted", "message deleted"));
|
|
590
590
|
else if (e.content.kind === "attachment") {
|
|
591
591
|
const a = e.content;
|
|
592
|
-
if ((
|
|
592
|
+
if ((P = a.mime) != null && P.startsWith("image/")) {
|
|
593
593
|
const i = document.createElement("img");
|
|
594
|
-
i.src = a.url, i.alt = a.name ?? "image", i.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", i.addEventListener("click", () => window.open(a.url, "_blank")),
|
|
595
|
-
} else if ((
|
|
594
|
+
i.src = a.url, i.alt = a.name ?? "image", i.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", i.addEventListener("click", () => window.open(a.url, "_blank")), m.append(i);
|
|
595
|
+
} else if ((B = a.mime) != null && B.startsWith("video/")) {
|
|
596
596
|
const i = document.createElement("video");
|
|
597
|
-
i.src = a.url, i.controls = !0, i.style.cssText = "max-width:240px;max-height:180px;border-radius:10px;display:block",
|
|
597
|
+
i.src = a.url, i.controls = !0, i.style.cssText = "max-width:240px;max-height:180px;border-radius:10px;display:block", m.append(i);
|
|
598
598
|
} else {
|
|
599
599
|
const i = document.createElement("a");
|
|
600
|
-
i.href = a.url, i.target = "_blank", i.rel = "noopener", i.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", i.append(n("span", void 0, "📄"), n("span", void 0, a.name ?? "file")),
|
|
600
|
+
i.href = a.url, i.target = "_blank", i.rel = "noopener", i.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", i.append(n("span", void 0, "📄"), n("span", void 0, a.name ?? "file")), m.append(i);
|
|
601
601
|
}
|
|
602
602
|
} else if (e.content.kind === "appointment") {
|
|
603
603
|
const a = e.content, i = n("div", "ocw-appt");
|
|
604
604
|
i.append(n("div", "ocw-appt-title", `📅 ${a.title}`)), i.append(n("div", "ocw-appt-time", new Date(a.startIso).toLocaleString() + " – " + new Date(a.endIso).toLocaleTimeString())), a.location && i.append(n("div", "ocw-appt-loc", `📍 ${a.location}`)), a.description && i.append(n("div", "ocw-appt-desc", a.description));
|
|
605
|
-
const
|
|
606
|
-
|
|
605
|
+
const v = n("div", "ocw-appt-links"), u = document.createElement("a");
|
|
606
|
+
u.href = a.googleUrl, u.target = "_blank", u.rel = "noopener", u.className = "ocw-appt-btn", u.textContent = "📅 Add to Google Calendar";
|
|
607
607
|
const x = document.createElement("a");
|
|
608
|
-
x.href = a.icalUrl, x.download = `${a.title}.ics`, x.className = "ocw-appt-btn ocw-appt-btn-sec", x.textContent = "🍎 Apple / iCal",
|
|
608
|
+
x.href = a.icalUrl, x.download = `${a.title}.ics`, x.className = "ocw-appt-btn ocw-appt-btn-sec", x.textContent = "🍎 Apple / iCal", v.append(u, x), i.append(v), m.append(i);
|
|
609
609
|
} else
|
|
610
|
-
|
|
611
|
-
if (
|
|
610
|
+
c = document.createTextNode(se(e.content)), m.append(c), e.editedAt && m.append(n("span", "ocw-edited", "(edited)"));
|
|
611
|
+
if (h.append(m), s && !e.deletedAt && e.content.kind === "text" && ((z = e.content.quickReplies) != null && z.length)) {
|
|
612
612
|
const a = n("div", "ocw-flow-choices");
|
|
613
613
|
a.style.cssText = "display:flex;flex-wrap:wrap;gap:6px;margin-top:6px";
|
|
614
614
|
for (const i of e.content.quickReplies) {
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
a.querySelectorAll("button").forEach((
|
|
618
|
-
}), a.append(
|
|
615
|
+
const v = n("button", "ocw-flow-choice", i);
|
|
616
|
+
v.type = "button", v.style.cssText = "border:1px solid var(--ocw-bd,rgba(0,0,0,.12));background:var(--ocw-bg,#fff);color:inherit;border-radius:14px;padding:5px 12px;font:inherit;font-size:13px;cursor:pointer", v.addEventListener("click", () => {
|
|
617
|
+
a.querySelectorAll("button").forEach((u) => u.disabled = !0), a.style.opacity = "0.5", this.h.onSend(i);
|
|
618
|
+
}), a.append(v);
|
|
619
619
|
}
|
|
620
|
-
|
|
620
|
+
h.append(a);
|
|
621
621
|
}
|
|
622
|
-
if (!w && !b && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 &&
|
|
622
|
+
if (!w && !b && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && c) {
|
|
623
623
|
const a = e.content.text;
|
|
624
624
|
if (a.trim()) {
|
|
625
625
|
const i = n("button", "ocw-translate-btn", "🌐");
|
|
626
626
|
i.type = "button", i.title = "Translate";
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
const
|
|
630
|
-
|
|
627
|
+
const v = n("div", "ocw-translation");
|
|
628
|
+
v.style.display = "none", m.append(v);
|
|
629
|
+
const u = (S) => {
|
|
630
|
+
v.textContent = S, v.style.display = "", this.showingTranslation.add(e.id), i.textContent = "↩", i.title = "Show original";
|
|
631
631
|
}, x = () => {
|
|
632
|
-
|
|
632
|
+
v.style.display = "none", this.showingTranslation.delete(e.id), i.textContent = "🌐", i.title = "Translate";
|
|
633
633
|
};
|
|
634
|
-
i.addEventListener("click", (
|
|
635
|
-
if (
|
|
634
|
+
i.addEventListener("click", (S) => {
|
|
635
|
+
if (S.stopPropagation(), this.showingTranslation.has(e.id)) {
|
|
636
636
|
x();
|
|
637
637
|
return;
|
|
638
638
|
}
|
|
639
639
|
const f = this.translationCache.get(e.id);
|
|
640
640
|
if (f !== void 0) {
|
|
641
|
-
|
|
641
|
+
u(f);
|
|
642
642
|
return;
|
|
643
643
|
}
|
|
644
|
-
i.textContent = "⏳", this.h.onTranslate(a).then((
|
|
645
|
-
if (
|
|
644
|
+
i.textContent = "⏳", this.h.onTranslate(a).then((I) => {
|
|
645
|
+
if (I === null) {
|
|
646
646
|
i.textContent = "⚠️", i.title = "Translation unavailable", setTimeout(() => {
|
|
647
647
|
i.textContent = "🌐", i.title = "Translate";
|
|
648
648
|
}, 1500);
|
|
649
649
|
return;
|
|
650
650
|
}
|
|
651
|
-
this.translationCache.set(e.id,
|
|
651
|
+
this.translationCache.set(e.id, I), u(I);
|
|
652
652
|
});
|
|
653
|
-
}),
|
|
653
|
+
}), h.append(i);
|
|
654
654
|
const k = this.translationCache.get(e.id);
|
|
655
|
-
this.showingTranslation.has(e.id) && k !== void 0 &&
|
|
655
|
+
this.showingTranslation.has(e.id) && k !== void 0 && u(k);
|
|
656
656
|
}
|
|
657
657
|
}
|
|
658
658
|
if (w && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
|
|
659
659
|
const a = n("div", "ocw-msg-menu");
|
|
660
660
|
if (this.h.onEdit) {
|
|
661
661
|
const i = n("button", void 0, "✏️");
|
|
662
|
-
i.title = "Edit", i.addEventListener("click", (
|
|
663
|
-
|
|
664
|
-
const
|
|
665
|
-
x.value =
|
|
662
|
+
i.title = "Edit", i.addEventListener("click", (v) => {
|
|
663
|
+
v.stopPropagation();
|
|
664
|
+
const u = se(e.content), x = document.createElement("textarea");
|
|
665
|
+
x.value = u, x.rows = Math.min(4, Math.ceil(u.length / 40) + 1), x.style.cssText = "width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:var(--ocw-card);color:#1c1b1a;box-sizing:border-box";
|
|
666
666
|
const k = n("button", "ocw-form-submit", "Save");
|
|
667
667
|
k.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
|
|
668
|
-
const
|
|
669
|
-
|
|
668
|
+
const S = n("button", "ocw-form-cancel", "Cancel");
|
|
669
|
+
S.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
|
|
670
670
|
const f = n("div");
|
|
671
|
-
f.style.cssText = "display:flex;gap:6px;justify-content:flex-end", f.append(
|
|
672
|
-
const
|
|
673
|
-
|
|
674
|
-
const N = () =>
|
|
675
|
-
|
|
671
|
+
f.style.cssText = "display:flex;gap:6px;justify-content:flex-end", f.append(S, k);
|
|
672
|
+
const I = n("div");
|
|
673
|
+
I.append(x, f), m.replaceChildren(I), x.focus(), x.select();
|
|
674
|
+
const N = () => m.replaceChildren(c ?? document.createTextNode(u));
|
|
675
|
+
S.addEventListener("click", N), k.addEventListener("click", () => {
|
|
676
676
|
const D = x.value.trim();
|
|
677
|
-
D && D !==
|
|
677
|
+
D && D !== u && this.h.onEdit(e.id, D), N();
|
|
678
678
|
}), x.addEventListener("keydown", (D) => {
|
|
679
679
|
D.key === "Enter" && !D.shiftKey && (D.preventDefault(), k.click()), D.key === "Escape" && N();
|
|
680
680
|
});
|
|
@@ -682,73 +682,73 @@ class Xe {
|
|
|
682
682
|
}
|
|
683
683
|
if (this.h.onDelete) {
|
|
684
684
|
const i = n("button", "del", "🗑");
|
|
685
|
-
i.title = "Delete", i.addEventListener("click", (
|
|
686
|
-
|
|
685
|
+
i.title = "Delete", i.addEventListener("click", (v) => {
|
|
686
|
+
v.stopPropagation(), this.h.onDelete(e.id);
|
|
687
687
|
}), a.append(i);
|
|
688
688
|
}
|
|
689
|
-
|
|
689
|
+
h.append(a);
|
|
690
690
|
}
|
|
691
|
-
if (
|
|
691
|
+
if (d.append(h), e.senderRole === "bot" && !e.deletedAt && e.seq > 0 && e.content.kind === "text") {
|
|
692
692
|
const a = e.content.citations;
|
|
693
693
|
if (a != null && a.length) {
|
|
694
694
|
const i = n("div", "ocw-cites");
|
|
695
|
-
i.style.cssText = "margin-top:4px;font-size:11px;color:var(--ocw-mut,#667)", i.textContent = `${((O = this.cfg.i18n) == null ? void 0 : O.sources) ?? "Sources"}: ${a.map((
|
|
695
|
+
i.style.cssText = "margin-top:4px;font-size:11px;color:var(--ocw-mut,#667)", i.textContent = `${((O = this.cfg.i18n) == null ? void 0 : O.sources) ?? "Sources"}: ${a.map((v) => v.source).join(", ")}`, d.append(i);
|
|
696
696
|
}
|
|
697
697
|
if (this.h.onReact) {
|
|
698
698
|
const i = n("div", "ocw-bot-feedback");
|
|
699
699
|
i.style.cssText = "display:flex;gap:6px;margin-top:4px";
|
|
700
|
-
const
|
|
701
|
-
const k = n("button", "ocw-fb-btn",
|
|
700
|
+
const v = (u, x) => {
|
|
701
|
+
const k = n("button", "ocw-fb-btn", u);
|
|
702
702
|
k.type = "button", k.title = x, k.style.cssText = "border:1px solid var(--ocw-bd,rgba(0,0,0,.12));background:transparent;border-radius:12px;padding:1px 8px;font-size:12px;cursor:pointer;opacity:.7";
|
|
703
|
-
const
|
|
704
|
-
var f,
|
|
705
|
-
return !!((
|
|
703
|
+
const S = () => {
|
|
704
|
+
var f, I;
|
|
705
|
+
return !!((I = (f = e.reactions) == null ? void 0 : f[u]) != null && I.includes(this.me));
|
|
706
706
|
};
|
|
707
|
-
return
|
|
708
|
-
var f,
|
|
709
|
-
(
|
|
707
|
+
return S() && (k.style.opacity = "1"), k.addEventListener("click", () => {
|
|
708
|
+
var f, I;
|
|
709
|
+
(I = (f = this.h).onReact) == null || I.call(f, e.id, u, S()), k.style.opacity = "1";
|
|
710
710
|
}), k;
|
|
711
711
|
};
|
|
712
|
-
i.append(
|
|
712
|
+
i.append(v("👍", ((T = this.cfg.i18n) == null ? void 0 : T.helpful) ?? "Helpful"), v("👎", ((_ = this.cfg.i18n) == null ? void 0 : _.notHelpful) ?? "Not helpful")), d.append(i);
|
|
713
713
|
}
|
|
714
714
|
}
|
|
715
715
|
if (this.h.onReact && !e.deletedAt && e.seq > 0) {
|
|
716
716
|
const a = n("div", "ocw-react-wrap"), i = n("div", "ocw-react");
|
|
717
717
|
if (e.reactions && Object.keys(e.reactions).length)
|
|
718
718
|
for (const [x, k] of Object.entries(e.reactions)) {
|
|
719
|
-
const
|
|
720
|
-
|
|
721
|
-
var f,
|
|
722
|
-
return (
|
|
723
|
-
}), i.append(
|
|
719
|
+
const S = n("button", `ocw-react-pill${k.includes(this.me) ? " mine" : ""}`, `${x} ${k.length}`);
|
|
720
|
+
S.addEventListener("click", () => {
|
|
721
|
+
var f, I;
|
|
722
|
+
return (I = (f = this.h).onReact) == null ? void 0 : I.call(f, e.id, x, k.includes(this.me));
|
|
723
|
+
}), i.append(S);
|
|
724
724
|
}
|
|
725
|
-
const
|
|
726
|
-
for (const x of
|
|
725
|
+
const v = n("button", "ocw-react-btn", "+"), u = n("div", "ocw-react-picker");
|
|
726
|
+
for (const x of We) {
|
|
727
727
|
const k = n("button", void 0, x);
|
|
728
|
-
k.addEventListener("click", (
|
|
729
|
-
var
|
|
730
|
-
|
|
731
|
-
const f = (N = (
|
|
732
|
-
(X = (D = this.h).onReact) == null || X.call(D, e.id, x, !!f),
|
|
733
|
-
}),
|
|
728
|
+
k.addEventListener("click", (S) => {
|
|
729
|
+
var I, N, D, X;
|
|
730
|
+
S.stopPropagation();
|
|
731
|
+
const f = (N = (I = e.reactions) == null ? void 0 : I[x]) == null ? void 0 : N.includes(this.me);
|
|
732
|
+
(X = (D = this.h).onReact) == null || X.call(D, e.id, x, !!f), u.style.display = "none";
|
|
733
|
+
}), u.append(k);
|
|
734
734
|
}
|
|
735
|
-
|
|
735
|
+
u.style.display = "none", v.addEventListener("click", (x) => {
|
|
736
736
|
x.stopPropagation();
|
|
737
|
-
const k =
|
|
738
|
-
|
|
739
|
-
|
|
737
|
+
const k = u.style.display === "none";
|
|
738
|
+
u.style.display = k ? "flex" : "none", k && document.addEventListener("click", () => {
|
|
739
|
+
u.style.display = "none";
|
|
740
740
|
}, { once: !0 });
|
|
741
|
-
}), i.append(
|
|
742
|
-
} else e.reactions && Object.keys(e.reactions).length &&
|
|
743
|
-
const
|
|
741
|
+
}), i.append(v), a.append(i, u), d.append(a);
|
|
742
|
+
} else e.reactions && Object.keys(e.reactions).length && d.append(n("div", "ocw-react", Object.entries(e.reactions).map(([a, i]) => `${a}${i.length}`).join(" ")));
|
|
743
|
+
const j = n("div", "ocw-time ocw-meta", Xe(e.ts));
|
|
744
744
|
if (w && e.status) {
|
|
745
|
-
const a = n("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`,
|
|
746
|
-
|
|
745
|
+
const a = n("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Je(e.status));
|
|
746
|
+
j.append(a);
|
|
747
747
|
}
|
|
748
|
-
return w && e.seq > 0 &&
|
|
748
|
+
return w && e.seq > 0 && l.lastReadByOthers >= e.seq && j.append(n("span", "ocw-seen", " · Seen")), d.append(j), y.append(d), y;
|
|
749
749
|
}
|
|
750
750
|
}
|
|
751
|
-
function
|
|
751
|
+
function Je(t) {
|
|
752
752
|
switch (t) {
|
|
753
753
|
case "read":
|
|
754
754
|
return "✓✓";
|
|
@@ -761,11 +761,11 @@ function Qe(t) {
|
|
|
761
761
|
}
|
|
762
762
|
}
|
|
763
763
|
const F = /* @__PURE__ */ new WeakMap(), ne = /* @__PURE__ */ new Map();
|
|
764
|
-
function
|
|
764
|
+
function Ie(t) {
|
|
765
765
|
return `relay-launcher::${t.profileId}::${t.subjectId ?? ""}`;
|
|
766
766
|
}
|
|
767
767
|
let Y = null;
|
|
768
|
-
function
|
|
768
|
+
function Ze() {
|
|
769
769
|
if (Y && Y.state !== "closed") return Y;
|
|
770
770
|
try {
|
|
771
771
|
return Y = new AudioContext(), Y;
|
|
@@ -773,27 +773,68 @@ function Je() {
|
|
|
773
773
|
return null;
|
|
774
774
|
}
|
|
775
775
|
}
|
|
776
|
-
function
|
|
776
|
+
function st(t) {
|
|
777
777
|
var e;
|
|
778
778
|
(e = F.get(t)) == null || e.close(), F.delete(t);
|
|
779
779
|
}
|
|
780
|
-
function
|
|
781
|
-
|
|
782
|
-
|
|
780
|
+
function et(t) {
|
|
781
|
+
const e = t.el;
|
|
782
|
+
let l = null, r = null, s = !1;
|
|
783
|
+
const w = () => {
|
|
784
|
+
l == null || l.close(), l = null, r == null || r.close(), r = null, e.innerHTML = "";
|
|
785
|
+
};
|
|
786
|
+
function b() {
|
|
787
|
+
s || (w(), r = Ne({
|
|
788
|
+
el: e,
|
|
789
|
+
url: t.url,
|
|
790
|
+
...t.apiUrl ? { apiUrl: t.apiUrl } : {},
|
|
791
|
+
...t.profileId ? { profileId: t.profileId } : {},
|
|
792
|
+
scope: t.inboxScope ?? "tenant",
|
|
793
|
+
...t.token ? { token: t.token } : {},
|
|
794
|
+
...t.userId ? { userId: t.userId } : {},
|
|
795
|
+
...t.accent ? { accent: t.accent } : {},
|
|
796
|
+
...t.theme ? { theme: t.theme } : {},
|
|
797
|
+
...t.webfont === !1 ? { webfont: !1 } : {},
|
|
798
|
+
onSelect: (d) => y(d)
|
|
799
|
+
}));
|
|
800
|
+
}
|
|
801
|
+
function y(d) {
|
|
802
|
+
if (s) return;
|
|
803
|
+
w();
|
|
804
|
+
const { subjectId: h, kind: m, peerId: c, ...j } = t;
|
|
805
|
+
l = tt({
|
|
806
|
+
...j,
|
|
807
|
+
inbox: !1,
|
|
808
|
+
launcher: !1,
|
|
809
|
+
el: e,
|
|
810
|
+
...d.profileId ? { profileId: d.profileId } : {},
|
|
811
|
+
...d.subjectId ? { subjectId: d.subjectId } : {},
|
|
812
|
+
...d.kind === "direct" && d.peerId ? { kind: "direct", peerId: d.peerId } : {},
|
|
813
|
+
onBack: b
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
return b(), { close() {
|
|
817
|
+
s = !0, w();
|
|
818
|
+
} };
|
|
819
|
+
}
|
|
820
|
+
function tt(t) {
|
|
821
|
+
var de, pe, ue, he, fe, we, be, xe;
|
|
822
|
+
if (t.inbox) return et(t);
|
|
823
|
+
F.has(t.el) && (F.get(t.el).close(), F.delete(t.el)), t.launcher && ((de = ne.get(Ie(t))) == null || de.close());
|
|
783
824
|
const e = Me();
|
|
784
|
-
let
|
|
785
|
-
const
|
|
786
|
-
let
|
|
787
|
-
const
|
|
788
|
-
let
|
|
825
|
+
let l, r = !1;
|
|
826
|
+
const s = t.token ?? t.userId ?? e, w = s !== e ? e : void 0, { wsUrl: b, httpBase: y } = Ae(t.url, t.apiUrl);
|
|
827
|
+
let d = new De(s);
|
|
828
|
+
const h = t.subjectId ? `${s}::${t.subjectId}` : s, m = new Oe(h);
|
|
829
|
+
let c, j = !1, R = null, E = null, A = null, P = null;
|
|
789
830
|
!t.launcher && !t.el.style.height && t.el.clientHeight === 0 && (t.el.style.width = t.el.style.width || "100%", t.el.style.height = "600px");
|
|
790
|
-
for (const o of
|
|
791
|
-
let
|
|
831
|
+
for (const o of m.load()) d.addOptimistic(o.clientMsgId, o.content);
|
|
832
|
+
let B = null, z = null, O = 0, T = !t.launcher;
|
|
792
833
|
if (t.launcher) {
|
|
793
|
-
const
|
|
794
|
-
|
|
795
|
-
const
|
|
796
|
-
t.el.classList.toggle("ocw-fs",
|
|
834
|
+
const p = (t.position ?? "bottom-right").includes("right");
|
|
835
|
+
B = document.createElement("div"), B.style.cssText = `position:fixed;${p ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${p ? "flex-end" : "flex-start"};gap:12px`;
|
|
836
|
+
const g = document.createElement("div"), M = typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(max-width: 479px)") : null, K = ($) => {
|
|
837
|
+
t.el.classList.toggle("ocw-fs", $), g.style.cssText = $ ? [
|
|
797
838
|
"position:fixed",
|
|
798
839
|
"inset:0",
|
|
799
840
|
"width:100%",
|
|
@@ -816,15 +857,15 @@ function at(t) {
|
|
|
816
857
|
"display:none",
|
|
817
858
|
"flex-direction:column",
|
|
818
859
|
"background:#fff",
|
|
819
|
-
"transform-origin:bottom " + (
|
|
860
|
+
"transform-origin:bottom " + (p ? "right" : "left"),
|
|
820
861
|
"transition:opacity .18s,transform .18s",
|
|
821
862
|
"opacity:0",
|
|
822
863
|
"transform:scale(.95)"
|
|
823
864
|
].join(";");
|
|
824
865
|
};
|
|
825
866
|
K((M == null ? void 0 : M.matches) ?? !1);
|
|
826
|
-
const V = (
|
|
827
|
-
M == null || M.addEventListener("change", V), R = M,
|
|
867
|
+
const V = ($) => K($.matches);
|
|
868
|
+
M == null || M.addEventListener("change", V), R = M, E = V, t.el.style.cssText = "width:100%;height:100%;overflow:hidden", g.append(t.el);
|
|
828
869
|
const J = '<svg viewBox="0 0 24 24" width="26" height="26" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>', Z = '<svg viewBox="0 0 24 24" width="22" height="22" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>', H = document.createElement("button");
|
|
829
870
|
H.type = "button", H.style.cssText = [
|
|
830
871
|
"width:56px;height:56px;border-radius:50%",
|
|
@@ -840,25 +881,25 @@ function at(t) {
|
|
|
840
881
|
H.style.transform = "scale(1)";
|
|
841
882
|
}, z = document.createElement("span"), z.style.cssText = "position:absolute;top:-4px;right:-4px;background:#4c6fff;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center";
|
|
842
883
|
const ee = () => {
|
|
843
|
-
H.innerHTML =
|
|
884
|
+
H.innerHTML = T ? Z : J, H.setAttribute("aria-label", T ? "Close chat" : "Open chat"), H.setAttribute("aria-expanded", String(T)), H.append(z);
|
|
844
885
|
};
|
|
845
|
-
ee(),
|
|
886
|
+
ee(), B.append(g, H), document.body.append(B);
|
|
846
887
|
const oe = `ocw-teaser-dismissed::${t.profileId}`, te = typeof t.launcherMessage == "string" ? { title: t.launcherMessage } : t.launcherMessage;
|
|
847
888
|
let L = null;
|
|
848
|
-
const
|
|
889
|
+
const Le = () => {
|
|
849
890
|
try {
|
|
850
891
|
return sessionStorage.getItem(oe) === "1";
|
|
851
892
|
} catch {
|
|
852
893
|
return !1;
|
|
853
894
|
}
|
|
854
895
|
}, Pe = '<svg viewBox="0 0 24 24" width="15" height="15" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>', me = () => {
|
|
855
|
-
const
|
|
856
|
-
if (!(!!(
|
|
896
|
+
const $ = te != null && te.title ? te : d.launcherMessage ?? void 0;
|
|
897
|
+
if (!(!!($ != null && $.title) && !T && !Le())) {
|
|
857
898
|
L && (L.remove(), L = null);
|
|
858
899
|
return;
|
|
859
900
|
}
|
|
860
901
|
if (L) return;
|
|
861
|
-
L = document.createElement("div"), L.setAttribute("role", "button"), L.setAttribute("tabindex", "0"), L.setAttribute("aria-label",
|
|
902
|
+
L = document.createElement("div"), L.setAttribute("role", "button"), L.setAttribute("tabindex", "0"), L.setAttribute("aria-label", $.title), L.style.cssText = [
|
|
862
903
|
"max-width:280px",
|
|
863
904
|
"background:#fff",
|
|
864
905
|
"border-radius:16px",
|
|
@@ -867,17 +908,17 @@ function at(t) {
|
|
|
867
908
|
"position:relative",
|
|
868
909
|
"cursor:pointer",
|
|
869
910
|
"font-family:inherit",
|
|
870
|
-
`align-self:${
|
|
911
|
+
`align-self:${p ? "flex-end" : "flex-start"}`,
|
|
871
912
|
"animation:ocw-teaser-in .22s ease-out"
|
|
872
913
|
].join(";");
|
|
873
914
|
const ae = document.createElement("div");
|
|
874
|
-
if (ae.textContent =
|
|
915
|
+
if (ae.textContent = $.title, ae.style.cssText = "font-size:15px;font-weight:600;color:#111;line-height:1.35", L.append(ae), $.subtitle) {
|
|
875
916
|
const U = document.createElement("div");
|
|
876
917
|
U.style.cssText = "display:flex;align-items:center;gap:6px;margin-top:6px;font-size:13px;color:#6b7280";
|
|
877
|
-
const
|
|
878
|
-
|
|
918
|
+
const ce = document.createElement("span");
|
|
919
|
+
ce.innerHTML = Pe, ce.style.cssText = `color:${t.accent ?? "#6c5ce7"};display:inline-flex`;
|
|
879
920
|
const ye = document.createElement("span");
|
|
880
|
-
ye.textContent =
|
|
921
|
+
ye.textContent = $.subtitle, U.append(ce, ye), L.append(U);
|
|
881
922
|
}
|
|
882
923
|
const W = document.createElement("button");
|
|
883
924
|
W.type = "button", W.setAttribute("aria-label", "Dismiss"), W.innerHTML = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>', W.style.cssText = "position:absolute;top:8px;right:8px;width:24px;height:24px;border:none;border-radius:50%;background:#f3f4f6;color:#6b7280;cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0", W.addEventListener("click", (U) => {
|
|
@@ -889,120 +930,120 @@ function at(t) {
|
|
|
889
930
|
L && (L.remove(), L = null);
|
|
890
931
|
}), L.append(W);
|
|
891
932
|
const ge = () => {
|
|
892
|
-
|
|
933
|
+
T || (T = !0, ie(!0), ee(), O = 0, z && (z.style.display = "none"), L && (L.remove(), L = null));
|
|
893
934
|
};
|
|
894
935
|
L.addEventListener("click", ge), L.addEventListener("keydown", (U) => {
|
|
895
936
|
(U.key === "Enter" || U.key === " ") && (U.preventDefault(), ge());
|
|
896
|
-
}),
|
|
937
|
+
}), B.insertBefore(L, H);
|
|
897
938
|
};
|
|
898
939
|
if (!document.getElementById("ocw-teaser-style")) {
|
|
899
|
-
const
|
|
900
|
-
|
|
940
|
+
const $ = document.createElement("style");
|
|
941
|
+
$.id = "ocw-teaser-style", $.textContent = "@keyframes ocw-teaser-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}", document.head.append($);
|
|
901
942
|
}
|
|
902
|
-
|
|
903
|
-
const ie = (
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
})) : (
|
|
907
|
-
|
|
943
|
+
P = me, me();
|
|
944
|
+
const ie = ($) => {
|
|
945
|
+
$ ? (g.style.display = "flex", requestAnimationFrame(() => {
|
|
946
|
+
g.style.opacity = "1", g.style.transform = "scale(1)";
|
|
947
|
+
})) : (g.style.opacity = "0", g.style.transform = "scale(.95)", setTimeout(() => {
|
|
948
|
+
T || (g.style.display = "none");
|
|
908
949
|
}, 180));
|
|
909
950
|
};
|
|
910
951
|
H.addEventListener("click", () => {
|
|
911
|
-
if (
|
|
952
|
+
if (T = !T, ie(T), ee(), T) {
|
|
912
953
|
O = 0, z && (z.style.display = "none");
|
|
913
954
|
try {
|
|
914
955
|
sessionStorage.setItem(oe, "1");
|
|
915
956
|
} catch {
|
|
916
957
|
}
|
|
917
958
|
}
|
|
918
|
-
|
|
919
|
-
}), A = (
|
|
920
|
-
|
|
959
|
+
P == null || P();
|
|
960
|
+
}), A = ($) => {
|
|
961
|
+
$.key === "Escape" && T && (T = !1, ie(!1), ee());
|
|
921
962
|
}, document.addEventListener("keydown", A);
|
|
922
963
|
}
|
|
923
964
|
const _ = () => {
|
|
924
|
-
|
|
965
|
+
T || (O++, z && (z.textContent = String(O), z.style.display = "flex"));
|
|
925
966
|
}, a = () => {
|
|
926
967
|
try {
|
|
927
|
-
const o =
|
|
968
|
+
const o = Ze();
|
|
928
969
|
if (!o) return;
|
|
929
970
|
o.state === "suspended" && o.resume().catch(() => {
|
|
930
971
|
});
|
|
931
|
-
const
|
|
932
|
-
|
|
972
|
+
const p = o.createOscillator(), g = o.createGain();
|
|
973
|
+
p.connect(g), g.connect(o.destination), p.frequency.setValueAtTime(880, o.currentTime), p.frequency.exponentialRampToValueAtTime(440, o.currentTime + 0.15), g.gain.setValueAtTime(0.3, o.currentTime), g.gain.exponentialRampToValueAtTime(1e-3, o.currentTime + 0.3), p.start(), p.stop(o.currentTime + 0.3);
|
|
933
974
|
} catch {
|
|
934
975
|
}
|
|
935
|
-
}, i = [],
|
|
976
|
+
}, i = [], v = (o) => {
|
|
936
977
|
for (; i.length; ) {
|
|
937
|
-
const
|
|
938
|
-
|
|
978
|
+
const p = i.shift();
|
|
979
|
+
m.add({ clientMsgId: p.clientMsgId, content: p.content, ts: Date.now() }), u.send({ type: "send", conversationId: o, clientMsgId: p.clientMsgId, content: p.content });
|
|
939
980
|
}
|
|
940
981
|
};
|
|
941
|
-
let
|
|
942
|
-
const x = new
|
|
982
|
+
let u;
|
|
983
|
+
const x = new _e(`ocw-e2e-${t.profileId}`);
|
|
943
984
|
let k = !1;
|
|
944
|
-
const
|
|
945
|
-
let
|
|
946
|
-
const N = (o,
|
|
947
|
-
x.sealText(
|
|
948
|
-
|
|
985
|
+
const S = [], f = [];
|
|
986
|
+
let I = !1;
|
|
987
|
+
const N = (o, p) => {
|
|
988
|
+
x.sealText(p).then((g) => {
|
|
989
|
+
c && u.send({ type: "send", conversationId: c, clientMsgId: o, content: g });
|
|
949
990
|
});
|
|
950
|
-
}, D = (o,
|
|
951
|
-
x.sealText(
|
|
952
|
-
|
|
991
|
+
}, D = (o, p, g) => {
|
|
992
|
+
x.sealText(p, g).then((M) => {
|
|
993
|
+
c && u.send({ type: "send", conversationId: c, clientMsgId: o, content: M });
|
|
953
994
|
});
|
|
954
995
|
}, X = () => {
|
|
955
|
-
for (;
|
|
956
|
-
const o =
|
|
996
|
+
for (; S.length; ) {
|
|
997
|
+
const o = S.shift();
|
|
957
998
|
N(o.clientMsgId, o.text);
|
|
958
999
|
}
|
|
959
1000
|
for (; f.length; ) {
|
|
960
1001
|
const o = f.shift();
|
|
961
1002
|
N(o.clientMsgId, o.text);
|
|
962
1003
|
}
|
|
963
|
-
},
|
|
964
|
-
|
|
965
|
-
},
|
|
966
|
-
|
|
967
|
-
const re = `oc_prechat_${t.profileId}_${
|
|
1004
|
+
}, Te = (o) => {
|
|
1005
|
+
u.send({ type: "fetchPrekey", targetUserId: o });
|
|
1006
|
+
}, Se = t.i18n ?? {}, Ee = ["ar", "he", "fa", "ur"], ze = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
|
|
1007
|
+
Ee.includes(ze) && !t.el.dir && (t.el.dir = "rtl", t.el.style.fontFamily = t.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
|
|
1008
|
+
const re = `oc_prechat_${t.profileId}_${s.slice(-8)}`, q = new Qe(t.el, s, {
|
|
968
1009
|
onSend(o) {
|
|
969
|
-
const
|
|
970
|
-
|
|
1010
|
+
const p = `cm_${Math.random().toString(36).slice(2)}`, g = { kind: "text", text: o };
|
|
1011
|
+
d.addOptimistic(p, g), q.render(d), d.e2e ? x.ready ? N(p, o) : I ? f.push({ clientMsgId: p, text: o }) : (S.push({ clientMsgId: p, text: o }), d.assignedAgentId && Te(d.assignedAgentId)) : c ? (m.add({ clientMsgId: p, content: g, ts: Date.now() }), u.send({ type: "send", conversationId: c, clientMsgId: p, content: g })) : i.push({ clientMsgId: p, content: g });
|
|
971
1012
|
},
|
|
972
1013
|
async onAttach(o) {
|
|
973
|
-
if (!
|
|
974
|
-
const
|
|
975
|
-
|
|
1014
|
+
if (!c) return;
|
|
1015
|
+
const p = `${y}/upload?name=${encodeURIComponent(o.name)}`, g = `cm_${Math.random().toString(36).slice(2)}`;
|
|
1016
|
+
d.addOptimistic(g, { kind: "text", text: `📎 Uploading ${o.name}…` }), q.render(d);
|
|
976
1017
|
try {
|
|
977
|
-
const M = await fetch(
|
|
1018
|
+
const M = await fetch(p, {
|
|
978
1019
|
method: "POST",
|
|
979
1020
|
// Use the resolved connection token (a signed JWT, an explicit userId,
|
|
980
1021
|
// or the anonymous persistent uid) — NOT just opts.token. The server
|
|
981
1022
|
// requires an Authorization header, and the verifier accepts an
|
|
982
1023
|
// anonymous id as a guest; keying off opts.token alone meant anonymous
|
|
983
1024
|
// visitors (the common case) sent no auth and every upload 401'd.
|
|
984
|
-
headers: { "content-type": o.type, authorization: `Bearer ${
|
|
1025
|
+
headers: { "content-type": o.type, authorization: `Bearer ${s}` },
|
|
985
1026
|
body: o
|
|
986
1027
|
});
|
|
987
1028
|
if (!M.ok) throw new Error(`Upload failed: ${M.status}`);
|
|
988
1029
|
const { url: K, name: V, mime: J, size: Z } = await M.json();
|
|
989
|
-
|
|
1030
|
+
d.addOptimistic(g, { kind: "attachment", url: K, name: V, mime: J, size: Z }), q.render(d), u.send({ type: "send", conversationId: c, clientMsgId: g, content: { kind: "attachment", url: K, name: V, mime: J, size: Z } });
|
|
990
1031
|
} catch (M) {
|
|
991
|
-
|
|
1032
|
+
d.addOptimistic(g, { kind: "text", text: `⚠️ Upload failed: ${M.message}` }), q.render(d);
|
|
992
1033
|
}
|
|
993
1034
|
},
|
|
994
|
-
onInvoke(o,
|
|
995
|
-
|
|
1035
|
+
onInvoke(o, p) {
|
|
1036
|
+
c && u.send({ type: "invoke", conversationId: c, actionId: o, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...p ? { inputs: p } : {} });
|
|
996
1037
|
},
|
|
997
|
-
onTyping(o,
|
|
998
|
-
|
|
1038
|
+
onTyping(o, p) {
|
|
1039
|
+
c && u.send({ type: "typing", conversationId: c, isTyping: o, ...p ? { preview: p } : {} });
|
|
999
1040
|
},
|
|
1000
1041
|
onPreChat(o) {
|
|
1001
1042
|
try {
|
|
1002
1043
|
localStorage.setItem(re, "1");
|
|
1003
1044
|
} catch {
|
|
1004
1045
|
}
|
|
1005
|
-
|
|
1046
|
+
u.send({
|
|
1006
1047
|
type: "open",
|
|
1007
1048
|
profileId: t.profileId,
|
|
1008
1049
|
...t.subjectId ? { subjectId: t.subjectId } : {},
|
|
@@ -1015,47 +1056,47 @@ function at(t) {
|
|
|
1015
1056
|
} } : {}
|
|
1016
1057
|
}
|
|
1017
1058
|
});
|
|
1018
|
-
const
|
|
1019
|
-
|
|
1059
|
+
const p = o.callback ? `📞 Call-back requested${o.phone ? `: ${o.phone}` : ""}${o.topic ? ` — ${o.topic}` : ""}` : o.topic ? `Topic: ${o.topic}` : "";
|
|
1060
|
+
p && c && !d.e2e && u.send({ type: "send", conversationId: c, clientMsgId: `pc_${Math.random().toString(36).slice(2, 12)}`, content: { kind: "text", text: p } });
|
|
1020
1061
|
},
|
|
1021
1062
|
...((pe = t.features) == null ? void 0 : pe.deflection) !== !1 ? {
|
|
1022
1063
|
onDeflectQuery(o) {
|
|
1023
|
-
if (
|
|
1024
|
-
clearTimeout(
|
|
1025
|
-
const
|
|
1026
|
-
if (
|
|
1064
|
+
if (r) return;
|
|
1065
|
+
clearTimeout(l);
|
|
1066
|
+
const p = o.trim();
|
|
1067
|
+
if (p.length < 3) {
|
|
1027
1068
|
q.hideDeflection();
|
|
1028
1069
|
return;
|
|
1029
1070
|
}
|
|
1030
|
-
|
|
1031
|
-
fetch(`${
|
|
1071
|
+
l = setTimeout(() => {
|
|
1072
|
+
fetch(`${y}/kb/search?profileId=${encodeURIComponent(t.profileId)}&q=${encodeURIComponent(p.slice(0, 200))}`).then((g) => g.ok ? g.json() : { articles: [] }).then((g) => q.showDeflection(g.articles ?? [])).catch(() => q.hideDeflection());
|
|
1032
1073
|
}, 350);
|
|
1033
1074
|
}
|
|
1034
1075
|
} : {},
|
|
1035
1076
|
onReadUpTo(o) {
|
|
1036
|
-
|
|
1077
|
+
c && u.send({ type: "read", conversationId: c, seq: o });
|
|
1037
1078
|
},
|
|
1038
1079
|
onLoadMore() {
|
|
1039
|
-
if (!
|
|
1040
|
-
const o =
|
|
1041
|
-
o &&
|
|
1080
|
+
if (!c || !d.e2e) return;
|
|
1081
|
+
const o = d.messages()[0];
|
|
1082
|
+
o && u.send({ type: "history", conversationId: c, beforeSeq: o.seq, limit: 20 });
|
|
1042
1083
|
},
|
|
1043
|
-
onEdit(o,
|
|
1044
|
-
|
|
1084
|
+
onEdit(o, p) {
|
|
1085
|
+
c && u.send({ type: "edit", conversationId: c, messageId: o, content: { kind: "text", text: p } });
|
|
1045
1086
|
},
|
|
1046
1087
|
onDelete(o) {
|
|
1047
|
-
|
|
1088
|
+
c && u.send({ type: "delete", conversationId: c, messageId: o });
|
|
1048
1089
|
},
|
|
1049
|
-
...((
|
|
1050
|
-
onReact(o,
|
|
1051
|
-
|
|
1090
|
+
...((ue = t.features) == null ? void 0 : ue.reactions) !== !1 ? {
|
|
1091
|
+
onReact(o, p, g) {
|
|
1092
|
+
c && u.send({ type: "react", conversationId: c, messageId: o, emoji: p, remove: g });
|
|
1052
1093
|
}
|
|
1053
1094
|
} : {},
|
|
1054
|
-
...((
|
|
1095
|
+
...((he = t.features) == null ? void 0 : he.csat) !== !1 ? {
|
|
1055
1096
|
onCsat(o) {
|
|
1056
|
-
|
|
1097
|
+
c && fetch(`${y}/conversations/${c}/csat`, {
|
|
1057
1098
|
method: "POST",
|
|
1058
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${
|
|
1099
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${s}` },
|
|
1059
1100
|
body: JSON.stringify({ score: o })
|
|
1060
1101
|
}).catch(() => {
|
|
1061
1102
|
});
|
|
@@ -1064,14 +1105,14 @@ function at(t) {
|
|
|
1064
1105
|
...t.translateLang ? {
|
|
1065
1106
|
async onTranslate(o) {
|
|
1066
1107
|
try {
|
|
1067
|
-
const
|
|
1108
|
+
const p = await fetch(`${y}/translate`, {
|
|
1068
1109
|
method: "POST",
|
|
1069
|
-
headers: { "content-type": "application/json", authorization: `Bearer ${
|
|
1110
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${s}` },
|
|
1070
1111
|
body: JSON.stringify({ text: o, targetLang: t.translateLang })
|
|
1071
1112
|
});
|
|
1072
|
-
if (!
|
|
1073
|
-
const { translated:
|
|
1074
|
-
return
|
|
1113
|
+
if (!p.ok) return null;
|
|
1114
|
+
const { translated: g } = await p.json();
|
|
1115
|
+
return g;
|
|
1075
1116
|
} catch {
|
|
1076
1117
|
return null;
|
|
1077
1118
|
}
|
|
@@ -1086,7 +1127,7 @@ function at(t) {
|
|
|
1086
1127
|
...t.theme ? { theme: t.theme } : {},
|
|
1087
1128
|
...t.webfont === !1 ? { webfont: !1 } : {},
|
|
1088
1129
|
...(fe = t.user) != null && fe.name || (we = t.user) != null && we.avatar ? { userInfo: { ...t.user.name ? { name: t.user.name } : {}, ...t.user.avatar ? { avatar: t.user.avatar } : {} } } : {},
|
|
1089
|
-
i18n:
|
|
1130
|
+
i18n: Se
|
|
1090
1131
|
});
|
|
1091
1132
|
try {
|
|
1092
1133
|
localStorage.getItem(re) && q.completePreChat();
|
|
@@ -1097,7 +1138,7 @@ function at(t) {
|
|
|
1097
1138
|
...t.user.email ? { email: t.user.email } : {},
|
|
1098
1139
|
...t.user.avatar ? { avatar: t.user.avatar } : {},
|
|
1099
1140
|
...t.user.meta ? { meta: t.user.meta } : {}
|
|
1100
|
-
} : void 0,
|
|
1141
|
+
} : void 0, je = {
|
|
1101
1142
|
type: "open",
|
|
1102
1143
|
profileId: t.profileId,
|
|
1103
1144
|
// Direct conversations use the kind/peerId pair; the dm:… subject key is
|
|
@@ -1113,79 +1154,79 @@ function at(t) {
|
|
|
1113
1154
|
...(be = t.subject) != null && be.title ? { subjectTitle: t.subject.title } : {},
|
|
1114
1155
|
...(xe = t.subject) != null && xe.subtitle ? { subjectMeta: t.subject.subtitle } : {}
|
|
1115
1156
|
};
|
|
1116
|
-
|
|
1157
|
+
u = new He({
|
|
1117
1158
|
...t.refreshToken ? { refreshToken: t.refreshToken } : {},
|
|
1118
1159
|
url: b,
|
|
1119
|
-
token:
|
|
1120
|
-
open:
|
|
1121
|
-
getCursor: () =>
|
|
1122
|
-
onStatusChange: (o,
|
|
1160
|
+
token: s,
|
|
1161
|
+
open: je,
|
|
1162
|
+
getCursor: () => d.highestSeq(),
|
|
1163
|
+
onStatusChange: (o, p) => q.setConnStatus(o, p),
|
|
1123
1164
|
onFrame(o) {
|
|
1124
1165
|
if (o.type === "opened") {
|
|
1125
|
-
if (
|
|
1126
|
-
|
|
1127
|
-
for (const
|
|
1128
|
-
|
|
1166
|
+
if (c = o.conversation.id, !j) {
|
|
1167
|
+
j = !0;
|
|
1168
|
+
for (const p of m.load())
|
|
1169
|
+
u.send({ type: "send", conversationId: c, clientMsgId: p.clientMsgId, content: p.content });
|
|
1129
1170
|
}
|
|
1130
|
-
qe(b,
|
|
1171
|
+
qe(b, s, c, d, q, y), i.length && v(c);
|
|
1131
1172
|
}
|
|
1132
|
-
if (o.type === "ack" &&
|
|
1133
|
-
o.bundle && (
|
|
1134
|
-
const
|
|
1135
|
-
for (const M of
|
|
1136
|
-
q.render(
|
|
1173
|
+
if (o.type === "ack" && m.remove(o.clientMsgId), o.type === "prekeyBundle") {
|
|
1174
|
+
o.bundle && (I = !0, x.x3dhSendTo(o.bundle).then((p) => {
|
|
1175
|
+
const g = [...S.splice(0), ...f.splice(0)];
|
|
1176
|
+
for (const M of g) D(M.clientMsgId, M.text, p);
|
|
1177
|
+
q.render(d);
|
|
1137
1178
|
}));
|
|
1138
1179
|
return;
|
|
1139
1180
|
}
|
|
1140
|
-
if (o.type === "message" &&
|
|
1141
|
-
const
|
|
1142
|
-
if (
|
|
1143
|
-
x.x3dhReceiveFrom(
|
|
1144
|
-
await x.openFrame(o),
|
|
1181
|
+
if (o.type === "message" && d.e2e) {
|
|
1182
|
+
const p = Ue(o.message.content);
|
|
1183
|
+
if (p && !x.ready) {
|
|
1184
|
+
x.x3dhReceiveFrom(p.x3dhIK, p.x3dhEK, p.x3dhSPK, p.x3dhOTP).then(async () => {
|
|
1185
|
+
await x.openFrame(o), d.apply(o), q.render(d);
|
|
1145
1186
|
});
|
|
1146
1187
|
return;
|
|
1147
1188
|
}
|
|
1148
1189
|
}
|
|
1149
1190
|
if (o.type === "peerkey") {
|
|
1150
1191
|
x.onPeerKey(o.key).then(() => {
|
|
1151
|
-
X(), q.render(
|
|
1192
|
+
X(), q.render(d);
|
|
1152
1193
|
});
|
|
1153
1194
|
return;
|
|
1154
1195
|
}
|
|
1155
1196
|
(async () => {
|
|
1156
|
-
if (
|
|
1157
|
-
|
|
1158
|
-
const
|
|
1159
|
-
|
|
1197
|
+
if (d.e2e && await x.openFrame(o), d.apply(o), o.type === "manifest") {
|
|
1198
|
+
P == null || P();
|
|
1199
|
+
const p = o.botName;
|
|
1200
|
+
p && q.setBotName(p);
|
|
1160
1201
|
}
|
|
1161
|
-
if (o.type === "message" && o.message.senderId !==
|
|
1202
|
+
if (o.type === "message" && o.message.senderId !== s && !o.message.internal && (_(), a()), d.e2e && c && !k) {
|
|
1162
1203
|
k = !0;
|
|
1163
|
-
const
|
|
1164
|
-
|
|
1165
|
-
const
|
|
1166
|
-
|
|
1204
|
+
const p = await x.initX3DH();
|
|
1205
|
+
u.send({ type: "uploadPrekeys", ...p });
|
|
1206
|
+
const g = await x.begin();
|
|
1207
|
+
u.send({ type: "pubkey", conversationId: c, key: g });
|
|
1167
1208
|
}
|
|
1168
|
-
q.render(
|
|
1209
|
+
q.render(d);
|
|
1169
1210
|
})();
|
|
1170
1211
|
}
|
|
1171
|
-
}),
|
|
1172
|
-
const G = t.launcher ?
|
|
1173
|
-
|
|
1212
|
+
}), u.connect(), q.render(d);
|
|
1213
|
+
const G = t.launcher ? Ie(t) : null, Q = { close: () => {
|
|
1214
|
+
r = !0, clearTimeout(l), u.close(), B == null || B.remove(), q.destroy(), R && E && R.removeEventListener("change", E), A && (document.removeEventListener("keydown", A), A = null), F.delete(t.el), G && ne.get(G) === Q && ne.delete(G);
|
|
1174
1215
|
} };
|
|
1175
1216
|
return F.set(t.el, Q), G && ne.set(G, Q), Q;
|
|
1176
1217
|
}
|
|
1177
1218
|
export {
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1219
|
+
De as ChatStore,
|
|
1220
|
+
He as ConnectionManager,
|
|
1221
|
+
_e as E2ESession,
|
|
1222
|
+
Oe as PersistentOutbox,
|
|
1223
|
+
Qe as Renderer,
|
|
1224
|
+
ut as asConversationId,
|
|
1225
|
+
Ue as extractX3DHInit,
|
|
1226
|
+
dt as httpBaseFromWsUrl,
|
|
1227
|
+
tt as mount,
|
|
1187
1228
|
Ae as resolveRelayUrls,
|
|
1188
1229
|
qe as restoreHistory,
|
|
1189
|
-
|
|
1230
|
+
st as unmount
|
|
1190
1231
|
};
|
|
1191
1232
|
//# sourceMappingURL=index.js.map
|