@sevenfold/setto-client 0.22.0 → 0.22.2
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 +18 -12
- package/dist/setto-client.js.map +1 -1
- package/package.json +1 -1
package/dist/setto-client.js
CHANGED
|
@@ -22060,6 +22060,7 @@ function contactTeam() {
|
|
|
22060
22060
|
function SettoChat() {
|
|
22061
22061
|
const { config } = useSetto();
|
|
22062
22062
|
const { i18n } = useTranslation();
|
|
22063
|
+
const apiUrl = config.apiUrl.replace(/\/+$/, "");
|
|
22063
22064
|
const [settings, setSettings] = useState(null);
|
|
22064
22065
|
const [open, setOpen] = useState(false);
|
|
22065
22066
|
const [messages, setMessages] = useState([]);
|
|
@@ -22076,7 +22077,7 @@ function SettoChat() {
|
|
|
22076
22077
|
useEffect(() => {
|
|
22077
22078
|
if (window.location.pathname.startsWith("/setto")) return;
|
|
22078
22079
|
let cancelled = false;
|
|
22079
|
-
fetch(`${
|
|
22080
|
+
fetch(`${apiUrl}/sites/${encodeURIComponent(config.siteId)}/chat/settings/public`, {
|
|
22080
22081
|
headers: { Accept: "application/json" }
|
|
22081
22082
|
}).then(async (response) => response.ok ? await response.json() : null).then((next) => {
|
|
22082
22083
|
if (!cancelled && next?.enabled) setSettings(next);
|
|
@@ -22085,18 +22086,19 @@ function SettoChat() {
|
|
|
22085
22086
|
return () => {
|
|
22086
22087
|
cancelled = true;
|
|
22087
22088
|
};
|
|
22088
|
-
}, [
|
|
22089
|
+
}, [apiUrl, config.siteId]);
|
|
22089
22090
|
useEffect(() => {
|
|
22090
22091
|
if (!open || messages.length > 0 || !settings) return;
|
|
22091
|
-
setMessages([{ role: "assistant", content: intro(i18n.language, settings.displayName) }]);
|
|
22092
|
+
setMessages([{ role: "assistant", content: intro(i18n.language, settings.displayName ?? void 0) }]);
|
|
22092
22093
|
}, [open, messages.length, settings, i18n.language]);
|
|
22093
22094
|
useEffect(() => {
|
|
22094
22095
|
if (open) logRef.current?.scrollTo({ top: logRef.current.scrollHeight });
|
|
22095
22096
|
}, [messages, open]);
|
|
22096
22097
|
if (!settings || window.location.pathname.startsWith("/setto")) return null;
|
|
22097
22098
|
const locale = i18n.language || "no";
|
|
22099
|
+
const siteName = settings.displayName?.trim() || null;
|
|
22098
22100
|
const labels = norwegian(locale) ? {
|
|
22099
|
-
open: `Snakk med ${
|
|
22101
|
+
open: siteName ? `Snakk med ${siteName}` : "Snakk med oss",
|
|
22100
22102
|
close: "Lukk chatten",
|
|
22101
22103
|
title: "Spør Barista",
|
|
22102
22104
|
disclosure: "AI-assistent · svarer fra nettstedets godkjente informasjon",
|
|
@@ -22118,7 +22120,7 @@ function SettoChat() {
|
|
|
22118
22120
|
leadConversation: "Still et spørsmål først, så kan vi knytte oppfølgingen til samtalen.",
|
|
22119
22121
|
failed: "Jeg får ikke svart akkurat nå. Kontakt gjerne teamet direkte."
|
|
22120
22122
|
} : {
|
|
22121
|
-
open: `Chat with ${
|
|
22123
|
+
open: siteName ? `Chat with ${siteName}` : "Chat with us",
|
|
22122
22124
|
close: "Close chat",
|
|
22123
22125
|
title: "Ask Barista",
|
|
22124
22126
|
disclosure: "AI assistant · answers from this website’s approved information",
|
|
@@ -22150,7 +22152,7 @@ function SettoChat() {
|
|
|
22150
22152
|
visitor.current ??= visitorId();
|
|
22151
22153
|
try {
|
|
22152
22154
|
const response = await fetch(
|
|
22153
|
-
`${
|
|
22155
|
+
`${apiUrl}/sites/${encodeURIComponent(config.siteId)}/chat/messages`,
|
|
22154
22156
|
{
|
|
22155
22157
|
method: "POST",
|
|
22156
22158
|
headers: { "Content-Type": "application/json", Accept: "text/plain, application/json" },
|
|
@@ -22200,7 +22202,7 @@ function SettoChat() {
|
|
|
22200
22202
|
}
|
|
22201
22203
|
setLeadStatus("sending");
|
|
22202
22204
|
try {
|
|
22203
|
-
const response = await fetch(`${
|
|
22205
|
+
const response = await fetch(`${apiUrl}/sites/${encodeURIComponent(config.siteId)}/chat/leads`, {
|
|
22204
22206
|
method: "POST",
|
|
22205
22207
|
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
22206
22208
|
body: JSON.stringify({
|
|
@@ -22219,8 +22221,8 @@ function SettoChat() {
|
|
|
22219
22221
|
setLeadStatus("failed");
|
|
22220
22222
|
}
|
|
22221
22223
|
};
|
|
22222
|
-
return /* @__PURE__ */ jsxs("aside", { className: "setto-chat"
|
|
22223
|
-
open ? /* @__PURE__ */ jsxs("section", { className: "setto-chat__panel", role: "dialog", "aria-modal": "
|
|
22224
|
+
return /* @__PURE__ */ jsxs("aside", { className: `setto-chat${open ? " setto-chat--open" : ""}`, "aria-label": labels.title, "data-setto-ui": true, children: [
|
|
22225
|
+
open ? /* @__PURE__ */ jsxs("section", { className: "setto-chat__panel", role: "dialog", "aria-modal": "true", "aria-labelledby": `${formId}-title`, children: [
|
|
22224
22226
|
/* @__PURE__ */ jsxs("header", { className: "setto-chat__header", children: [
|
|
22225
22227
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
22226
22228
|
/* @__PURE__ */ jsx("p", { className: "setto-chat__eyebrow", children: "BARISTA" }),
|
|
@@ -22293,10 +22295,10 @@ function SettoChat() {
|
|
|
22293
22295
|
/* @__PURE__ */ jsx("button", { type: "submit", disabled: !draft.trim() || sending, children: sending ? labels.sending : labels.send })
|
|
22294
22296
|
] })
|
|
22295
22297
|
] }) : null,
|
|
22296
|
-
/* @__PURE__ */ jsxs("button", { className: "setto-chat__launcher", type: "button", onClick: () => setOpen(true), "aria-expanded":
|
|
22298
|
+
!open ? /* @__PURE__ */ jsxs("button", { className: "setto-chat__launcher", type: "button", onClick: () => setOpen(true), "aria-expanded": "false", children: [
|
|
22297
22299
|
/* @__PURE__ */ jsx("span", { className: "setto-chat__launcher-mark", "aria-hidden": "true", children: "✦" }),
|
|
22298
22300
|
/* @__PURE__ */ jsx("span", { children: labels.open })
|
|
22299
|
-
] })
|
|
22301
|
+
] }) : null
|
|
22300
22302
|
] });
|
|
22301
22303
|
}
|
|
22302
22304
|
function replaceLastAssistant(messages, content) {
|
|
@@ -22316,11 +22318,14 @@ function useChatStyles() {
|
|
|
22316
22318
|
style.textContent = `
|
|
22317
22319
|
.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; }
|
|
22318
22320
|
.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; }
|
|
22319
22322
|
.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; }
|
|
22320
22323
|
.setto-chat__launcher:hover { transform: translateY(-2px); box-shadow: 0 18px 46px rgba(35,29,23,.36); }
|
|
22321
22324
|
.setto-chat__launcher-mark { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: #df6540; color: #fff8eb; font-size: 18px; }
|
|
22322
22325
|
.setto-chat__panel { width: min(390px, calc(100vw - 32px)); height: min(590px, calc(100dvh - 104px)); margin-bottom: 12px; overflow: hidden; display: grid; grid-template-rows: auto 1fr auto auto auto; border: 1px solid rgba(37,29,22,.15); border-radius: 20px; background: #fffaf1; box-shadow: 0 22px 70px rgba(35,29,23,.3); }
|
|
22326
|
+
.setto-chat--open .setto-chat__panel { width: 100%; height: 100%; margin: 0; border: 0; border-radius: 0; box-shadow: none; }
|
|
22323
22327
|
.setto-chat__header { padding: 20px 20px 16px; display: flex; justify-content: space-between; gap: 14px; border-bottom: 1px solid #eadfce; background: radial-gradient(circle at 0 0, #f4d4a9, transparent 52%), #fffaf1; }
|
|
22328
|
+
.setto-chat--open .setto-chat__header { padding-top: max(20px, env(safe-area-inset-top)); padding-right: max(20px, env(safe-area-inset-right)); padding-left: max(20px, env(safe-area-inset-left)); }
|
|
22324
22329
|
.setto-chat__eyebrow { margin: 0 0 4px; color: #b54628; font-size: 10px; font-weight: 700; letter-spacing: .14em; }
|
|
22325
22330
|
.setto-chat__header h2 { margin: 0; color: #211a14; font-family: "Instrument Serif", Georgia, serif; font-size: 29px; font-weight: 400; line-height: 1; }
|
|
22326
22331
|
.setto-chat__header p:not(.setto-chat__eyebrow) { margin: 7px 0 0; max-width: 280px; color: #70665a; font-size: 12px; line-height: 1.35; }
|
|
@@ -22344,12 +22349,13 @@ function useChatStyles() {
|
|
|
22344
22349
|
.setto-chat__lead-success { color: #30683d !important; font-weight: 600; }
|
|
22345
22350
|
.setto-chat__lead-error { color: #9b2f1e !important; font-weight: 600; }
|
|
22346
22351
|
.setto-chat__composer { padding: 12px; display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 8px; border-top: 1px solid #eadfce; background: #fffdf8; }
|
|
22352
|
+
.setto-chat--open .setto-chat__composer { padding-right: max(12px, env(safe-area-inset-right)); padding-bottom: max(12px, env(safe-area-inset-bottom)); padding-left: max(12px, env(safe-area-inset-left)); }
|
|
22347
22353
|
.setto-chat__composer textarea { width: 100%; max-height: 100px; resize: none; border: 1px solid #d8ccba; border-radius: 10px; background: #fffaf1; color: #231d17; padding: 10px; font: 14px/1.35 Archivo, ui-sans-serif, sans-serif; outline: none; }
|
|
22348
22354
|
.setto-chat__composer textarea:focus { border-color: #b54628; box-shadow: 0 0 0 3px rgba(181,70,40,.12); }
|
|
22349
22355
|
.setto-chat__composer button { min-height: 40px; border: 0; border-radius: 9px; padding: 0 13px; background: #b54628; color: #fffaf1; font: 600 13px Archivo, ui-sans-serif, sans-serif; cursor: pointer; }
|
|
22350
22356
|
.setto-chat__composer button:disabled { opacity: .5; cursor: default; }
|
|
22351
22357
|
.setto-chat__sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
|
|
22352
|
-
@media (max-width: 480px) { .setto-chat { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); } .setto-chat__panel { width: calc(100vw - 24px); height: min(610px, calc(100dvh - 88px)); } .setto-chat__launcher { min-height: 50px; } .setto-chat__lead-grid { grid-template-columns: 1fr; } }
|
|
22358
|
+
@media (max-width: 480px) { .setto-chat:not(.setto-chat--open) { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); } .setto-chat:not(.setto-chat--open) .setto-chat__panel { width: calc(100vw - 24px); height: min(610px, calc(100dvh - 88px)); } .setto-chat__launcher { min-height: 50px; } .setto-chat__lead-grid { grid-template-columns: 1fr; } }
|
|
22353
22359
|
@media (prefers-reduced-motion: reduce) { .setto-chat *, .setto-chat *::before, .setto-chat *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
|
|
22354
22360
|
`;
|
|
22355
22361
|
document.head.appendChild(style);
|