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