@sevenfold/setto-client 0.22.2 → 0.23.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/setto-client.js +36 -2
- package/dist/setto-client.js.map +1 -1
- package/package.json +1 -1
package/dist/setto-client.js
CHANGED
|
@@ -22094,6 +22094,34 @@ function SettoChat() {
|
|
|
22094
22094
|
useEffect(() => {
|
|
22095
22095
|
if (open) logRef.current?.scrollTo({ top: logRef.current.scrollHeight });
|
|
22096
22096
|
}, [messages, open]);
|
|
22097
|
+
useEffect(() => {
|
|
22098
|
+
if (!open || !conversationId.current || !visitor.current || sending) return;
|
|
22099
|
+
let cancelled = false;
|
|
22100
|
+
const refresh = async () => {
|
|
22101
|
+
try {
|
|
22102
|
+
const query = new URLSearchParams({ visitorId: visitor.current });
|
|
22103
|
+
const response = await fetch(
|
|
22104
|
+
`${apiUrl}/sites/${encodeURIComponent(config.siteId)}/chat/conversations/${encodeURIComponent(conversationId.current)}/public?${query}`,
|
|
22105
|
+
{ headers: { Accept: "application/json" } }
|
|
22106
|
+
);
|
|
22107
|
+
if (!response.ok) return;
|
|
22108
|
+
const next = await response.json();
|
|
22109
|
+
if (cancelled) return;
|
|
22110
|
+
const serverMessages = next.messages.map(({ role, content }) => ({ role, content }));
|
|
22111
|
+
setMessages((previous) => {
|
|
22112
|
+
const greeting = previous[0]?.role === "assistant" && !serverMessages.some((message) => message.content === previous[0]?.content) ? [previous[0]] : [];
|
|
22113
|
+
return [...greeting, ...serverMessages];
|
|
22114
|
+
});
|
|
22115
|
+
} catch {
|
|
22116
|
+
}
|
|
22117
|
+
};
|
|
22118
|
+
void refresh();
|
|
22119
|
+
const timer = window.setInterval(() => void refresh(), 5e3);
|
|
22120
|
+
return () => {
|
|
22121
|
+
cancelled = true;
|
|
22122
|
+
window.clearInterval(timer);
|
|
22123
|
+
};
|
|
22124
|
+
}, [apiUrl, config.siteId, open, sending]);
|
|
22097
22125
|
if (!settings || window.location.pathname.startsWith("/setto")) return null;
|
|
22098
22126
|
const locale = i18n.language || "no";
|
|
22099
22127
|
const siteName = settings.displayName?.trim() || null;
|
|
@@ -22231,7 +22259,10 @@ function SettoChat() {
|
|
|
22231
22259
|
] }),
|
|
22232
22260
|
/* @__PURE__ */ jsx("button", { className: "setto-chat__close", type: "button", onClick: () => setOpen(false), "aria-label": labels.close, children: "×" })
|
|
22233
22261
|
] }),
|
|
22234
|
-
/* @__PURE__ */ jsx("div", { className: "setto-chat__log", ref: logRef, "aria-live": "polite", children: messages.map((item, index) => /* @__PURE__ */
|
|
22262
|
+
/* @__PURE__ */ jsx("div", { className: "setto-chat__log", ref: logRef, "aria-live": "polite", children: messages.map((item, index) => /* @__PURE__ */ jsxs("div", { className: `setto-chat__message setto-chat__message--${item.role}`, children: [
|
|
22263
|
+
item.role === "human" ? /* @__PURE__ */ jsx("span", { className: "setto-chat__speaker", children: "Teamet" }) : null,
|
|
22264
|
+
item.content || /* @__PURE__ */ jsx("span", { className: "setto-chat__typing", children: "···" })
|
|
22265
|
+
] }, `${item.role}-${index}`)) }),
|
|
22235
22266
|
/* @__PURE__ */ jsxs("div", { className: "setto-chat__contact", children: [
|
|
22236
22267
|
/* @__PURE__ */ jsxs("button", { type: "button", onClick: contactTeam, children: [
|
|
22237
22268
|
labels.contact,
|
|
@@ -22318,7 +22349,7 @@ function useChatStyles() {
|
|
|
22318
22349
|
style.textContent = `
|
|
22319
22350
|
.setto-chat { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 2147483000; color: #231d17; font-family: Archivo, ui-sans-serif, sans-serif; }
|
|
22320
22351
|
.setto-chat *, .setto-chat *::before, .setto-chat *::after { box-sizing: border-box; }
|
|
22321
|
-
.setto-chat--open { inset: 0; right: 0; bottom: 0; display: block; background: #fffaf1; }
|
|
22352
|
+
.setto-chat--open { inset: 0; right: 0; bottom: 0; width: 100vw; height: 100dvh; display: block; background: #fffaf1; }
|
|
22322
22353
|
.setto-chat__launcher { border: 0; min-height: 54px; max-width: min(290px, calc(100vw - 32px)); border-radius: 999px; padding: 8px 18px 8px 9px; display: flex; align-items: center; gap: 10px; background: #251d16; color: #fff9ef; box-shadow: 0 14px 40px rgba(35,29,23,.28); font: 600 14px/1 Archivo, ui-sans-serif, sans-serif; cursor: pointer; transition: transform .18s ease, box-shadow .18s ease; }
|
|
22323
22354
|
.setto-chat__launcher:hover { transform: translateY(-2px); box-shadow: 0 18px 46px rgba(35,29,23,.36); }
|
|
22324
22355
|
.setto-chat__launcher-mark { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: #df6540; color: #fff8eb; font-size: 18px; }
|
|
@@ -22334,6 +22365,9 @@ function useChatStyles() {
|
|
|
22334
22365
|
.setto-chat__message { max-width: 88%; padding: 11px 13px; border-radius: 14px; font-size: 14px; line-height: 1.48; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
22335
22366
|
.setto-chat__message--assistant { align-self: flex-start; background: #efe7da; color: #302820; border-bottom-left-radius: 3px; }
|
|
22336
22367
|
.setto-chat__message--visitor { align-self: flex-end; background: #2b221b; color: #fffaf1; border-bottom-right-radius: 3px; }
|
|
22368
|
+
.setto-chat__message--human { align-self: flex-start; background: #f5d3c7; color: #48261d; border-bottom-left-radius: 3px; }
|
|
22369
|
+
.setto-chat__message--system { align-self: center; max-width: 100%; padding: 2px 8px; background: transparent; color: #817568; font-size: 11px; text-align: center; }
|
|
22370
|
+
.setto-chat__speaker { display: block; margin-bottom: 3px; color: #a13e24; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
|
|
22337
22371
|
.setto-chat__typing { display: inline-block; min-width: 24px; animation: setto-chat-pulse 1.1s ease-in-out infinite; letter-spacing: 2px; }
|
|
22338
22372
|
@keyframes setto-chat-pulse { 50% { opacity: .3; } }
|
|
22339
22373
|
.setto-chat__contact { padding: 0 18px 12px; display: flex; gap: 14px; flex-wrap: wrap; }
|