@convokit/widget 0.0.11 → 0.1.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/index.esm.js CHANGED
@@ -1,615 +1,6 @@
1
1
  (function(){"use strict";try{if(typeof document!="undefined"){var o=document.createElement("style");o.appendChild(document.createTextNode(":root{--convokit-primary: #000;--convokit-header-bg: #000;--convokit-font-family: Inter, system-ui, sans-serif;--convokit-font-size: 14px;--convokit-border-radius: 18px;--convokit-chat-bg: #ffffff;--convokit-user-msg-bg: #000;--convokit-assistant-msg-bg: #f3f4f6;--convokit-input-bg: #ffffff;--convokit-input-border: #d1d5db}.convokit-widget{position:fixed;top:0;left:0;right:0;bottom:0;pointer-events:none;font-family:var(--convokit-font-family);-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.convokit-button{width:56px;height:56px;border-radius:50%;border:2px solid var(--convokit-primary);color:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:0 2px 8px #0000001a;z-index:10000;transition:all .2s ease;background:var(--convokit-primary)}.convokit-button:hover{transform:translateY(-2px);box-shadow:0 4px 12px #00000026}.convokit-button:active{transform:translateY(0)}.convokit-button-hidden{opacity:0;transform:scale(0);pointer-events:none;transition:all .2s ease-in-out}.convokit-chat-window{width:380px;height:600px;background:#fff;border-radius:12px;box-shadow:0 4px 16px #0000001a;display:flex;flex-direction:column;overflow:hidden;position:absolute;bottom:0;right:0;z-index:9999;transform-origin:bottom right;border:2px solid #000;overscroll-behavior:contain}.convokit-chat-window-body{width:100%;height:100%;background:#fff;display:flex;flex-direction:column;overflow:hidden}.convokit-chat-wrapper{display:flex;flex-direction:column;flex:1;background:var(--convokit-chat-bg);overflow:hidden}.convokit-header{padding:16px 20px;color:#fff;display:flex;justify-content:space-between;align-items:center;min-height:60px;background:var(--convokit-header-bg);position:relative;border-bottom:2px solid var(--convokit-header-bg)}.convokit-header-subtitle{margin:0;font-size:12px;opacity:.85;line-height:1.3}.convokit-header-left{display:flex;align-items:center;gap:12px;flex:1}.convokit-avatar{display:none}.convokit-header-text{display:flex;flex-direction:column;gap:4px}.convokit-header-text h3{margin:0;font-size:16px;font-weight:600;line-height:1.3}.convokit-header-actions{display:flex;align-items:center;gap:4px}.convokit-header-icon{background:none;border:none;color:#fff;cursor:pointer;padding:4px;display:flex;align-items:center;justify-content:center;border-radius:4px;transition:opacity .2s ease}.convokit-header-icon:hover{opacity:.7}.convokit-header-icon:active{opacity:.5}.convokit-chat-window-content{display:flex;flex-direction:column;flex:1;overflow:hidden;min-height:0}.convokit-chat-container{display:flex;flex-direction:column;flex:1;padding:16px;border:none;overflow:hidden;background:transparent;overscroll-behavior:contain}.convokit-messages{flex:1;overflow-y:auto;padding:8px 0;display:flex;flex-direction:column;gap:16px;background:transparent;scrollbar-width:none;-ms-overflow-style:none;overscroll-behavior:contain}.convokit-messages::-webkit-scrollbar{display:none}.convokit-welcome{text-align:center;color:#666;padding:20px;font-size:14px}.convokit-message{display:flex;align-items:flex-end;gap:0;max-width:75%}.convokit-message-user{align-self:flex-end}.convokit-message-assistant{align-self:flex-start}.convokit-bot-icon{display:none}.convokit-message-content{padding:10px 14px;border-radius:var(--convokit-border-radius);word-wrap:break-word;font-size:var(--convokit-font-size);line-height:1.5;position:relative;text-align:left}.convokit-message-user .convokit-message-content{background:var(--convokit-user-msg-bg);color:#fff;border-bottom-right-radius:4px}.convokit-message-assistant .convokit-message-content{background:var(--convokit-assistant-msg-bg);color:#000;border-bottom-left-radius:4px}.convokit-message-content strong{font-weight:600}.convokit-message-content em{font-style:italic}.convokit-message-content a{text-decoration:underline}.convokit-typing{display:flex;gap:6px;padding:4px 0;align-items:center}.convokit-typing span{width:8px;height:8px;border-radius:50%;background:#6b7280;animation:typing-bounce 1.4s ease-in-out infinite}.convokit-typing span:nth-child(1){animation-delay:0s}.convokit-typing span:nth-child(2){animation-delay:.2s}.convokit-typing span:nth-child(3){animation-delay:.4s}@keyframes typing-bounce{0%,60%,to{transform:translateY(0)}30%{transform:translateY(-8px)}}.convokit-input-form{display:flex;align-items:center;padding:12px 0 0;gap:8px;flex-shrink:0;background:transparent;border-bottom:none}.convokit-input{flex:1;padding:11px 14px;border:1px solid color-mix(in srgb,var(--convokit-primary) 35%,transparent);background:var(--convokit-input-bg);border-radius:20px;font-size:var(--convokit-font-size);outline:none;color:#000;font-family:var(--convokit-font-family);transition:border-color .2s ease,box-shadow .2s ease}.convokit-input:focus{border-color:var(--convokit-primary);box-shadow:none}.convokit-input::placeholder{color:#9ca3af}.convokit-input:disabled{background:#f9fafb;color:#9ca3af;border-color:#e5e7eb}.convokit-send-button{width:40px;height:40px;border-radius:50%;border:none;color:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;background:var(--convokit-primary);transition:opacity .2s ease;position:relative}.convokit-send-button svg{display:block;width:18px;height:18px;stroke:#fff;fill:none;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round;pointer-events:none}.convokit-send-button:hover:not(:disabled){opacity:.8}.convokit-send-button:active:not(:disabled){opacity:.6}.convokit-send-button:disabled{opacity:.3;cursor:not-allowed;background:var(--convokit-primary)}.convokit-send-button:disabled svg{opacity:.5}.convokit-footer{padding:10px 16px;text-align:center;background:var(--convokit-chat-bg);font-size:11px;color:#6b7280}.convokit-footer a{color:var(--convokit-primary);text-decoration:none;font-weight:500;transition:opacity .2s ease}.convokit-footer a:hover{opacity:.7}.convokit-rating-prompt{padding:16px;border-top:1px solid #e5e7eb;background-color:#f9fafb;border-bottom-left-radius:12px;border-bottom-right-radius:12px}.convokit-rating-question{margin:0 0 12px;font-size:14px;font-weight:500;color:#374151;text-align:center}.convokit-rating-buttons{display:flex;gap:12px;justify-content:center;margin-bottom:12px}.convokit-rating-button{width:48px;height:48px;border-radius:50%;border:2px solid #d1d5db;background-color:#fff;color:#6b7280;cursor:pointer;transition:all .2s ease;display:flex;align-items:center;justify-content:center;padding:0}.convokit-rating-button:hover:not(:disabled){border-color:#9ca3af;transform:scale(1.05)}.convokit-rating-button:disabled{opacity:.5;cursor:not-allowed}.convokit-rating-button.convokit-rating-selected{color:#fff;border-width:2px}.convokit-rating-feedback{margin-top:12px;animation:slideDown .3s ease}@keyframes slideDown{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}.convokit-rating-textarea{width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:8px;font-size:14px;font-family:inherit;resize:vertical;min-height:60px;margin-bottom:8px;box-sizing:border-box}.convokit-rating-textarea:focus{outline:none;border-color:#3b82f6;box-shadow:0 0 0 3px #3b82f61a}.convokit-rating-textarea:disabled{background-color:#f3f4f6;cursor:not-allowed}.convokit-rating-submit{width:100%;padding:10px 16px;border:none;border-radius:8px;font-size:14px;font-weight:500;color:#fff;cursor:pointer;transition:opacity .2s ease}.convokit-rating-submit:hover:not(:disabled){opacity:.9}.convokit-rating-submit:disabled{opacity:.6;cursor:not-allowed}.convokit-rating-thankyou{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:24px 16px;animation:fadeIn .3s ease}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}.convokit-rating-icon{width:48px;height:48px;border-radius:50%;background-color:#10b981;color:#fff;display:flex;align-items:center;justify-content:center;font-size:24px;font-weight:700;margin-bottom:12px}.convokit-rating-message{margin:0;font-size:14px;font-weight:500;color:#374151}@media (max-width: 480px){.convokit-widget{bottom:10px;right:10px}.convokit-chat-window{width:calc(100vw - 20px);height:calc(100vh - 20px);max-width:calc(100vw - 20px);max-height:calc(100vh - 20px);bottom:0;right:0;border-radius:16px}.convokit-message{max-width:85%}.convokit-header{padding:16px 16px 12px;min-height:64px}.convokit-chat-container{padding:12px}}")),document.head.appendChild(o)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
2
  /* empty css */
3
- import { M as L, r as _, f as R, i as $, s as G, c as Y, a as q, g as A, b as U, d as V, e as J } from "./PopupWidget-DhKUzzJD.js";
4
- import { P as me } from "./PopupWidget-DhKUzzJD.js";
5
- import { jsx as t, jsxs as n } from "react/jsx-runtime";
6
- import { useState as u, useRef as F, useEffect as N } from "react";
7
- const Q = "convokit-widget", X = ({ config: e, onBack: c, backLabel: r = "Back to editor" }) => {
8
- const k = e.widgetId ?? Q, [I, C] = u(!0), [m, x] = u([]), [g, B] = u(""), [v, D] = u(!1), [S, P] = u(null), [o, l] = u(null), T = F(null), a = `convokit_messages_${k}`;
9
- N(() => {
10
- if (e.persistMessages)
11
- try {
12
- const i = localStorage.getItem(a);
13
- i && x(JSON.parse(i));
14
- } catch (i) {
15
- console.error("Failed to load messages from localStorage:", i);
16
- }
17
- }, [e.persistMessages, a]), N(() => {
18
- if (e.persistMessages && m.length > 0)
19
- try {
20
- localStorage.setItem(a, JSON.stringify(m));
21
- } catch (i) {
22
- console.error("Failed to save messages to localStorage:", i);
23
- }
24
- }, [e.persistMessages, m, a]), N(() => {
25
- (async () => {
26
- if (!e.key) return;
27
- const s = `convokit_theme_${k}`;
28
- try {
29
- const f = sessionStorage.getItem(s);
30
- if (f) {
31
- l(JSON.parse(f));
32
- return;
33
- }
34
- } catch {
35
- }
36
- const h = await R(e.key);
37
- if (h) {
38
- l(h);
39
- try {
40
- sessionStorage.setItem(s, JSON.stringify(h));
41
- } catch {
42
- }
43
- }
44
- })();
45
- }, [k, e.key]);
46
- const p = {
47
- ...e,
48
- primaryColor: e.primaryColor || (o == null ? void 0 : o.primaryColor) || "#000",
49
- title: e.title || (o == null ? void 0 : o.headerTitle) || "Chat",
50
- subtitle: e.subtitle || (o == null ? void 0 : o.headerSubtitle),
51
- welcomeMessage: e.welcomeMessage || (o == null ? void 0 : o.welcomeMessage) || "How can I help you today?",
52
- placeholder: e.placeholder || (o == null ? void 0 : o.placeholder) || "Type a message..."
53
- };
54
- N(() => {
55
- if (typeof document > "u") return;
56
- const i = document.documentElement;
57
- i.style.setProperty("--convokit-primary", p.primaryColor), i.style.setProperty("--convokit-header-bg", e.headerBg ?? (o == null ? void 0 : o.headerBg) ?? p.primaryColor ?? "#000"), i.style.setProperty("--convokit-font-family", (o == null ? void 0 : o.fontFamily) || "Inter, system-ui, sans-serif"), i.style.setProperty("--convokit-font-size", (o == null ? void 0 : o.fontSize) || "14px"), i.style.setProperty("--convokit-border-radius", (o == null ? void 0 : o.borderRadius) || "18px"), i.style.setProperty("--convokit-chat-bg", e.chatBg ?? (o == null ? void 0 : o.chatBg) ?? "#ffffff"), i.style.setProperty("--convokit-user-msg-bg", e.userMsgBg ?? (o == null ? void 0 : o.userMsgBg) ?? p.primaryColor ?? "#000"), i.style.setProperty("--convokit-assistant-msg-bg", e.assistantMsgBg ?? (o == null ? void 0 : o.assistantMsgBg) ?? "#f3f4f6"), i.style.setProperty("--convokit-input-bg", e.inputBg ?? (o == null ? void 0 : o.inputBg) ?? "#ffffff");
58
- }, [o, p.primaryColor, e.headerBg, e.chatBg, e.userMsgBg, e.assistantMsgBg, e.inputBg]), N(() => {
59
- var i;
60
- (i = T.current) == null || i.scrollIntoView({ behavior: "smooth" });
61
- }, [m, v]);
62
- const E = async (i) => {
63
- if (i.preventDefault(), !g.trim() || v) return;
64
- const s = g.trim();
65
- B(""), P(null);
66
- const h = { role: "user", content: s, timestamp: /* @__PURE__ */ new Date() }, f = [...m, h];
67
- x(f), D(!0);
68
- try {
69
- const d = m.map((H) => ({ role: H.role, content: H.content })), b = typeof window < "u" ? localStorage.getItem("widget_jwt") : null, M = typeof window < "u" ? localStorage.getItem("conversation_id") : null;
70
- let y;
71
- b && M && !$() ? y = await G(s, d) : (b && M && $() && Y(), y = await q(e.key, s, void 0, k));
72
- const j = { role: "assistant", content: typeof (y == null ? void 0 : y.reply) == "string" ? y.reply : (y == null ? void 0 : y.reply) != null ? String(y.reply) : "", timestamp: /* @__PURE__ */ new Date() };
73
- x([...f, j]);
74
- } catch (d) {
75
- console.error("Chat error:", d);
76
- const b = d instanceof Error ? d.message : "Sorry, something went wrong.";
77
- P(b), x([...f, { role: "assistant", content: `Error: ${b}`, timestamp: /* @__PURE__ */ new Date() }]);
78
- } finally {
79
- D(!1);
80
- }
81
- };
82
- return I ? /* @__PURE__ */ n(
83
- L,
84
- {
85
- className: "convokit-widget",
86
- initial: { opacity: 0 },
87
- animate: { opacity: 1 },
88
- exit: { opacity: 0 },
89
- transition: { duration: 0.2 },
90
- style: {
91
- position: "fixed",
92
- inset: 0,
93
- zIndex: 1e4,
94
- display: "flex",
95
- flexDirection: "column",
96
- background: "var(--convokit-chat-bg)",
97
- fontFamily: "var(--convokit-font-family)",
98
- pointerEvents: "auto"
99
- },
100
- children: [
101
- /* @__PURE__ */ n("div", { className: "convokit-header", style: { flexShrink: 0 }, children: [
102
- /* @__PURE__ */ t("div", { className: "convokit-header-left", children: /* @__PURE__ */ n("div", { className: "convokit-header-text", children: [
103
- /* @__PURE__ */ t("h3", { children: p.title }),
104
- p.subtitle && /* @__PURE__ */ t("p", { className: "convokit-header-subtitle", children: p.subtitle })
105
- ] }) }),
106
- /* @__PURE__ */ t("div", { className: "convokit-header-actions", children: c ? /* @__PURE__ */ n("button", { type: "button", onClick: c, className: "convokit-header-icon", "aria-label": r, style: { fontSize: 14, gap: 6, display: "flex", alignItems: "center" }, children: [
107
- /* @__PURE__ */ t("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ t("path", { d: "M19 12H5M12 19l-7-7 7-7" }) }),
108
- r
109
- ] }) : /* @__PURE__ */ t("button", { type: "button", onClick: () => C(!1), className: "convokit-header-icon", "aria-label": "Close chat", children: /* @__PURE__ */ n("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
110
- /* @__PURE__ */ t("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
111
- /* @__PURE__ */ t("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
112
- ] }) }) })
113
- ] }),
114
- /* @__PURE__ */ t("div", { className: "convokit-chat-wrapper", style: { flex: 1, minHeight: 0, overflow: "hidden", display: "flex", flexDirection: "column" }, children: /* @__PURE__ */ t("div", { className: "convokit-chat-window-content", style: { flex: 1, minHeight: 0, overflow: "hidden", display: "flex", flexDirection: "column" }, children: /* @__PURE__ */ n("div", { className: "convokit-chat-container", style: { flex: 1, minHeight: 0, display: "flex", flexDirection: "column", padding: 16 }, children: [
115
- /* @__PURE__ */ n("div", { className: "convokit-messages", style: { flex: 1, overflowY: "auto", padding: "8px 0" }, children: [
116
- S && /* @__PURE__ */ n("div", { style: { padding: 12, margin: 8, background: "#fee", color: "#c33", borderRadius: 8, fontSize: 14 }, children: [
117
- "⚠️ ",
118
- S
119
- ] }),
120
- m.length === 0 && /* @__PURE__ */ t("div", { className: "convokit-message convokit-message-assistant", children: /* @__PURE__ */ t("div", { className: "convokit-message-content", dangerouslySetInnerHTML: { __html: _(p.welcomeMessage) } }) }),
121
- m.map((i, s) => /* @__PURE__ */ t("div", { className: `convokit-message convokit-message-${i.role}`, children: /* @__PURE__ */ t("div", { className: "convokit-message-content", dangerouslySetInnerHTML: { __html: _(i.content) } }) }, s)),
122
- v && /* @__PURE__ */ t("div", { className: "convokit-message convokit-message-assistant", children: /* @__PURE__ */ t("div", { className: "convokit-message-content", children: /* @__PURE__ */ n("div", { className: "convokit-typing", "aria-hidden": "true", children: [
123
- /* @__PURE__ */ t("span", {}),
124
- /* @__PURE__ */ t("span", {}),
125
- /* @__PURE__ */ t("span", {})
126
- ] }) }) }),
127
- /* @__PURE__ */ t("div", { ref: T })
128
- ] }),
129
- /* @__PURE__ */ n("form", { onSubmit: E, className: "convokit-input-form", children: [
130
- /* @__PURE__ */ t(
131
- "input",
132
- {
133
- type: "text",
134
- value: g,
135
- onChange: (i) => B(i.target.value),
136
- placeholder: p.placeholder,
137
- disabled: v,
138
- className: "convokit-input"
139
- }
140
- ),
141
- /* @__PURE__ */ t("button", { type: "submit", disabled: v || !g.trim(), className: "convokit-send-button", "aria-label": "Send message", children: /* @__PURE__ */ n("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
142
- /* @__PURE__ */ t("path", { d: "M22 2L11 13" }),
143
- /* @__PURE__ */ t("path", { d: "M22 2l-7 20-4-9-9-4z" })
144
- ] }) })
145
- ] }),
146
- /* @__PURE__ */ n("div", { className: "convokit-footer", children: [
147
- "Powered by ",
148
- /* @__PURE__ */ t("a", { href: "https://convokit.com", target: "_blank", rel: "noopener noreferrer", children: "ConvoKit" })
149
- ] })
150
- ] }) }) })
151
- ]
152
- }
153
- ) : /* @__PURE__ */ t(
154
- L,
155
- {
156
- initial: { opacity: 0 },
157
- animate: { opacity: 1 },
158
- style: {
159
- position: "fixed",
160
- inset: 0,
161
- zIndex: 1e4,
162
- display: "flex",
163
- alignItems: "center",
164
- justifyContent: "center",
165
- background: "var(--convokit-chat-bg)",
166
- pointerEvents: "auto"
167
- },
168
- children: /* @__PURE__ */ n(
169
- "button",
170
- {
171
- type: "button",
172
- onClick: () => C(!0),
173
- "aria-label": "Open chat",
174
- style: {
175
- padding: "14px 28px",
176
- borderRadius: 12,
177
- border: "none",
178
- background: p.primaryColor,
179
- color: "white",
180
- fontSize: 16,
181
- fontWeight: 500,
182
- cursor: "pointer",
183
- display: "flex",
184
- alignItems: "center",
185
- gap: 10,
186
- boxShadow: "0 4px 14px rgba(0,0,0,0.15)"
187
- },
188
- children: [
189
- /* @__PURE__ */ t("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ t("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) }),
190
- "Open chat"
191
- ]
192
- }
193
- )
194
- }
195
- );
196
- }, W = {
197
- title: "Support",
198
- welcomeMessage: "Hi! How can we help?"
199
- }, ae = (e) => {
200
- const c = e.apiKey;
201
- if (!c || typeof c != "string" || c.trim() === "")
202
- return null;
203
- const r = {
204
- ...W,
205
- key: c.trim(),
206
- widgetId: e.widgetId,
207
- title: e.title ?? W.title,
208
- welcomeMessage: e.welcomeMessage ?? W.welcomeMessage,
209
- persistMessages: e.persistMessages,
210
- primaryColor: e.primaryColor
211
- };
212
- return /* @__PURE__ */ t(
213
- X,
214
- {
215
- config: r,
216
- onBack: e.onBack,
217
- backLabel: e.backLabel ?? "Back"
218
- }
219
- );
220
- }, Z = "convokit-widget", ee = ({ config: e }) => {
221
- const c = e.widgetId ?? Z, [r, k] = u(!1), [I, C] = u([]), [m, x] = u(""), [g, B] = u(!1), [v, D] = u(!1), [S, P] = u(null), o = F(null), l = {
222
- ...e,
223
- primaryColor: e.primaryColor || "#000",
224
- title: e.title || "Chat",
225
- subtitle: e.subtitle,
226
- welcomeMessage: e.welcomeMessage || "How can I help you today?",
227
- placeholder: e.placeholder || "Type a message...",
228
- position: e.position || "bottom-right"
229
- };
230
- N(() => {
231
- if (typeof document > "u") return;
232
- const s = document.documentElement;
233
- s.style.setProperty("--convokit-primary", l.primaryColor), s.style.setProperty("--convokit-header-bg", e.headerBg ?? l.primaryColor ?? "#000"), s.style.setProperty("--convokit-font-family", "Inter, system-ui, sans-serif"), s.style.setProperty("--convokit-font-size", "14px"), s.style.setProperty("--convokit-border-radius", "18px"), s.style.setProperty("--convokit-chat-bg", e.chatBg ?? "#ffffff"), s.style.setProperty("--convokit-user-msg-bg", e.userMsgBg ?? l.primaryColor ?? "#000"), s.style.setProperty("--convokit-assistant-msg-bg", e.assistantMsgBg ?? "#f3f4f6"), s.style.setProperty("--convokit-input-bg", e.inputBg ?? "#ffffff");
234
- }, [l.primaryColor, e.headerBg, e.chatBg, e.userMsgBg, e.assistantMsgBg, e.inputBg]), N(() => {
235
- const s = setTimeout(() => D(!0), 100);
236
- return () => clearTimeout(s);
237
- }, []), N(() => {
238
- var s;
239
- (s = o.current) == null || s.scrollIntoView({ behavior: "smooth" });
240
- }, [I, g]);
241
- const T = () => k(!r), a = l.position, p = () => {
242
- const s = { position: "absolute", zIndex: 9999 }, h = {
243
- "bottom-right": { ...s, bottom: 20, right: 20 },
244
- "bottom-left": { ...s, bottom: 20, left: 20 },
245
- "bottom-middle": { ...s, bottom: 20, left: "50%" },
246
- "top-right": { ...s, top: 20, right: 20 },
247
- "top-left": { ...s, top: 20, left: 20 },
248
- "top-middle": { ...s, top: 20, left: "50%" }
249
- };
250
- return h[a] || h["bottom-right"];
251
- }, E = () => ({
252
- "bottom-right": "bottom right",
253
- "bottom-left": "bottom left",
254
- "bottom-middle": "bottom center",
255
- "top-right": "top right",
256
- "top-left": "top left",
257
- "top-middle": "top center"
258
- })[a] || "bottom right", i = async (s) => {
259
- if (s.preventDefault(), !m.trim() || g) return;
260
- const h = m.trim();
261
- x(""), P(null);
262
- const f = { role: "user", content: h, timestamp: /* @__PURE__ */ new Date() }, d = [...I, f];
263
- C(d), B(!0);
264
- try {
265
- const b = I.map((K) => ({ role: K.role, content: K.content })), M = typeof e.getAuthToken == "function" ? await Promise.resolve(e.getAuthToken()) : e.authToken, y = A(c);
266
- let w;
267
- y ? w = await U(
268
- e.apiUrl,
269
- h,
270
- b,
271
- y,
272
- M,
273
- e.apiKey
274
- ) : w = await V(
275
- e.apiUrl,
276
- h,
277
- c,
278
- b,
279
- M,
280
- e.apiKey
281
- ), w.conversation_id && typeof window < "u" && J(c, w.conversation_id);
282
- const H = { role: "assistant", content: typeof (w == null ? void 0 : w.reply) == "string" ? w.reply : (w == null ? void 0 : w.reply) != null ? String(w.reply) : "", timestamp: /* @__PURE__ */ new Date() };
283
- C([...d, H]);
284
- } catch (b) {
285
- console.error("[ConvoKit Connect] Chat error:", b);
286
- const M = b instanceof Error ? b.message : "Sorry, something went wrong.";
287
- P(M), C([...d, { role: "assistant", content: `Error: ${M}`, timestamp: /* @__PURE__ */ new Date() }]);
288
- } finally {
289
- B(!1);
290
- }
291
- };
292
- return /* @__PURE__ */ t("div", { className: "convokit-widget", children: /* @__PURE__ */ n(
293
- L,
294
- {
295
- className: "convokit-morph-container",
296
- initial: { opacity: 0, scale: 0, width: 60, height: 60, borderRadius: 50, x: a === "bottom-middle" || a === "top-middle" ? "-50%" : 0 },
297
- animate: {
298
- opacity: 1,
299
- scale: 1,
300
- width: r ? 380 : 60,
301
- height: r ? 600 : 60,
302
- borderRadius: r ? 16 : 50,
303
- x: a === "bottom-middle" || a === "top-middle" ? "-50%" : 0
304
- },
305
- transition: {
306
- duration: 0.4,
307
- scale: { type: "spring", visualDuration: 0.4, bounce: 0.5 },
308
- width: v ? { type: "spring", stiffness: 300, damping: 30 } : { duration: 0 },
309
- height: v ? { type: "spring", stiffness: 300, damping: 30 } : { duration: 0 },
310
- borderRadius: v ? { type: "spring", stiffness: 300, damping: 30 } : { duration: 0 },
311
- x: { duration: 0 }
312
- },
313
- style: {
314
- backgroundColor: l.primaryColor,
315
- ...p(),
316
- transformOrigin: E(),
317
- cursor: r ? "default" : "pointer",
318
- overflow: "hidden",
319
- boxShadow: r ? "0 12px 40px rgba(0, 0, 0, 0.2)" : "0 4px 20px rgba(0, 0, 0, 0.2)",
320
- pointerEvents: "auto"
321
- },
322
- onClick: r ? void 0 : T,
323
- children: [
324
- /* @__PURE__ */ t(
325
- L,
326
- {
327
- style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0, display: "flex", alignItems: "center", justifyContent: "center", pointerEvents: "none" },
328
- animate: { opacity: r ? 0 : 1, scale: r ? 0 : 1 },
329
- transition: { duration: 0.2 },
330
- children: e.bubbleIconUrl ? /* @__PURE__ */ t("img", { src: e.bubbleIconUrl, alt: "", width: 24, height: 24, style: { objectFit: "contain" } }) : /* @__PURE__ */ t("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ t("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) })
331
- }
332
- ),
333
- /* @__PURE__ */ t(
334
- L,
335
- {
336
- style: { width: "100%", height: "100%", opacity: r ? 1 : 0, pointerEvents: r ? "all" : "none" },
337
- animate: { opacity: r ? 1 : 0 },
338
- transition: { duration: 0.2, delay: r ? 0.2 : 0 },
339
- children: /* @__PURE__ */ t("div", { className: "convokit-chat-window-body", style: { background: "#ffffff", width: "100%", height: "100%", display: "flex", flexDirection: "column", overflow: "hidden" }, children: /* @__PURE__ */ n("div", { className: "convokit-chat-wrapper", children: [
340
- /* @__PURE__ */ n("div", { className: "convokit-header", children: [
341
- /* @__PURE__ */ n("div", { className: "convokit-header-left", children: [
342
- /* @__PURE__ */ t("div", { className: "convokit-avatar", children: /* @__PURE__ */ n("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: [
343
- /* @__PURE__ */ t("circle", { cx: "12", cy: "8", r: "4", fill: "white", opacity: "0.9" }),
344
- /* @__PURE__ */ t("path", { d: "M6 20c0-4 2.5-6 6-6s6 2 6 6", stroke: "white", strokeWidth: "2", strokeLinecap: "round" })
345
- ] }) }),
346
- /* @__PURE__ */ n("div", { className: "convokit-header-text", children: [
347
- /* @__PURE__ */ t("h3", { children: l.title }),
348
- l.subtitle && /* @__PURE__ */ t("p", { className: "convokit-header-subtitle", children: l.subtitle })
349
- ] })
350
- ] }),
351
- /* @__PURE__ */ t("div", { className: "convokit-header-actions", children: /* @__PURE__ */ t("button", { onClick: T, className: "convokit-header-icon", "aria-label": "Close chat", children: /* @__PURE__ */ n("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
352
- /* @__PURE__ */ t("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
353
- /* @__PURE__ */ t("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
354
- ] }) }) })
355
- ] }),
356
- /* @__PURE__ */ t("div", { className: "convokit-chat-window-content", children: /* @__PURE__ */ n("div", { className: "convokit-chat-container", children: [
357
- /* @__PURE__ */ n("div", { className: "convokit-messages", children: [
358
- S && /* @__PURE__ */ n("div", { style: { padding: 12, margin: 8, background: "#fee", color: "#c33", borderRadius: 8, fontSize: 14 }, children: [
359
- "⚠️ ",
360
- S
361
- ] }),
362
- I.length === 0 && /* @__PURE__ */ t("div", { className: "convokit-message convokit-message-assistant", children: /* @__PURE__ */ t("div", { className: "convokit-message-content", dangerouslySetInnerHTML: { __html: _(l.welcomeMessage) } }) }),
363
- I.map((s, h) => /* @__PURE__ */ t("div", { className: `convokit-message convokit-message-${s.role}`, children: /* @__PURE__ */ t("div", { className: "convokit-message-content", dangerouslySetInnerHTML: { __html: _(s.content) } }) }, h)),
364
- g && /* @__PURE__ */ t("div", { className: "convokit-message convokit-message-assistant", children: /* @__PURE__ */ t("div", { className: "convokit-message-content", children: /* @__PURE__ */ n("div", { className: "convokit-typing", "aria-hidden": "true", children: [
365
- /* @__PURE__ */ t("span", {}),
366
- /* @__PURE__ */ t("span", {}),
367
- /* @__PURE__ */ t("span", {})
368
- ] }) }) }),
369
- /* @__PURE__ */ t("div", { ref: o })
370
- ] }),
371
- /* @__PURE__ */ n("form", { onSubmit: i, className: "convokit-input-form", children: [
372
- /* @__PURE__ */ t(
373
- "input",
374
- {
375
- type: "text",
376
- value: m,
377
- onChange: (s) => x(s.target.value),
378
- placeholder: l.placeholder,
379
- disabled: g,
380
- className: "convokit-input"
381
- }
382
- ),
383
- /* @__PURE__ */ t("button", { type: "submit", disabled: g || !m.trim(), className: "convokit-send-button", "aria-label": "Send message", children: /* @__PURE__ */ n("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
384
- /* @__PURE__ */ t("path", { d: "M22 2L11 13" }),
385
- /* @__PURE__ */ t("path", { d: "M22 2l-7 20-4-9-9-4z" })
386
- ] }) })
387
- ] }),
388
- /* @__PURE__ */ n("div", { className: "convokit-footer", children: [
389
- "Powered by ",
390
- /* @__PURE__ */ t("a", { href: "https://convokit.com", target: "_blank", rel: "noopener noreferrer", children: "ConvoKit" })
391
- ] })
392
- ] }) })
393
- ] }) })
394
- }
395
- )
396
- ]
397
- }
398
- ) });
399
- }, z = {
400
- title: "Chat",
401
- welcomeMessage: "How can I help you today?",
402
- position: "bottom-right"
403
- }, le = (e) => {
404
- const { apiUrl: c, apiKey: r } = e;
405
- if (!(c != null && c.trim()) || !(r != null && r.trim()))
406
- return null;
407
- const k = {
408
- ...z,
409
- apiUrl: c.trim(),
410
- apiKey: r.trim(),
411
- authToken: e.authToken,
412
- widgetId: e.widgetId,
413
- title: e.title ?? z.title,
414
- welcomeMessage: e.welcomeMessage ?? z.welcomeMessage,
415
- position: e.position ?? z.position,
416
- primaryColor: e.primaryColor
417
- };
418
- return /* @__PURE__ */ t(ee, { config: k });
419
- }, te = "convokit-widget", oe = ({ config: e, onBack: c, backLabel: r = "Back to editor" }) => {
420
- const k = e.widgetId ?? te, [I, C] = u(!0), [m, x] = u([]), [g, B] = u(""), [v, D] = u(!1), [S, P] = u(null), o = F(null), l = {
421
- ...e,
422
- primaryColor: e.primaryColor || "#000",
423
- title: e.title || "Chat",
424
- subtitle: e.subtitle,
425
- welcomeMessage: e.welcomeMessage || "How can I help you today?",
426
- placeholder: e.placeholder || "Type a message..."
427
- };
428
- N(() => {
429
- if (typeof document > "u") return;
430
- const a = document.documentElement;
431
- a.style.setProperty("--convokit-primary", l.primaryColor), a.style.setProperty("--convokit-header-bg", e.headerBg ?? l.primaryColor ?? "#000"), a.style.setProperty("--convokit-font-family", "Inter, system-ui, sans-serif"), a.style.setProperty("--convokit-font-size", "14px"), a.style.setProperty("--convokit-border-radius", "18px"), a.style.setProperty("--convokit-chat-bg", e.chatBg ?? "#ffffff"), a.style.setProperty("--convokit-user-msg-bg", e.userMsgBg ?? l.primaryColor ?? "#000"), a.style.setProperty("--convokit-assistant-msg-bg", e.assistantMsgBg ?? "#f3f4f6"), a.style.setProperty("--convokit-input-bg", e.inputBg ?? "#ffffff");
432
- }, [l.primaryColor, e.headerBg, e.chatBg, e.userMsgBg, e.assistantMsgBg, e.inputBg]), N(() => {
433
- var a;
434
- (a = o.current) == null || a.scrollIntoView({ behavior: "smooth" });
435
- }, [m, v]);
436
- const T = async (a) => {
437
- if (a.preventDefault(), !g.trim() || v) return;
438
- const p = g.trim();
439
- B(""), P(null);
440
- const E = { role: "user", content: p, timestamp: /* @__PURE__ */ new Date() }, i = [...m, E];
441
- x(i), D(!0);
442
- try {
443
- const s = m.map((y) => ({ role: y.role, content: y.content })), h = typeof e.getAuthToken == "function" ? await Promise.resolve(e.getAuthToken()) : e.authToken, f = A(k);
444
- let d;
445
- f ? d = await U(
446
- e.apiUrl,
447
- p,
448
- s,
449
- f,
450
- h,
451
- e.apiKey
452
- ) : d = await V(
453
- e.apiUrl,
454
- p,
455
- k,
456
- s,
457
- h,
458
- e.apiKey
459
- ), d.conversation_id && typeof window < "u" && J(k, d.conversation_id);
460
- const M = { role: "assistant", content: typeof (d == null ? void 0 : d.reply) == "string" ? d.reply : (d == null ? void 0 : d.reply) != null ? String(d.reply) : "", timestamp: /* @__PURE__ */ new Date() };
461
- x([...i, M]);
462
- } catch (s) {
463
- console.error("[ConvoKit Connect] Chat error:", s);
464
- const h = s instanceof Error ? s.message : "Sorry, something went wrong.";
465
- P(h), x([...i, { role: "assistant", content: `Error: ${h}`, timestamp: /* @__PURE__ */ new Date() }]);
466
- } finally {
467
- D(!1);
468
- }
469
- };
470
- return I ? /* @__PURE__ */ n(
471
- L,
472
- {
473
- className: "convokit-widget",
474
- initial: { opacity: 0 },
475
- animate: { opacity: 1 },
476
- exit: { opacity: 0 },
477
- transition: { duration: 0.2 },
478
- style: {
479
- position: "fixed",
480
- inset: 0,
481
- zIndex: 1e4,
482
- display: "flex",
483
- flexDirection: "column",
484
- background: "var(--convokit-chat-bg)",
485
- fontFamily: "var(--convokit-font-family)",
486
- pointerEvents: "auto"
487
- },
488
- children: [
489
- /* @__PURE__ */ n("div", { className: "convokit-header", style: { flexShrink: 0 }, children: [
490
- /* @__PURE__ */ t("div", { className: "convokit-header-left", children: /* @__PURE__ */ n("div", { className: "convokit-header-text", children: [
491
- /* @__PURE__ */ t("h3", { children: l.title }),
492
- l.subtitle && /* @__PURE__ */ t("p", { className: "convokit-header-subtitle", children: l.subtitle })
493
- ] }) }),
494
- /* @__PURE__ */ t("div", { className: "convokit-header-actions", children: c ? /* @__PURE__ */ n("button", { type: "button", onClick: c, className: "convokit-header-icon", "aria-label": r, style: { fontSize: 14, gap: 6, display: "flex", alignItems: "center" }, children: [
495
- /* @__PURE__ */ t("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ t("path", { d: "M19 12H5M12 19l-7-7 7-7" }) }),
496
- r
497
- ] }) : /* @__PURE__ */ t("button", { type: "button", onClick: () => C(!1), className: "convokit-header-icon", "aria-label": "Close chat", children: /* @__PURE__ */ n("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
498
- /* @__PURE__ */ t("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
499
- /* @__PURE__ */ t("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
500
- ] }) }) })
501
- ] }),
502
- /* @__PURE__ */ t("div", { className: "convokit-chat-wrapper", style: { flex: 1, minHeight: 0, overflow: "hidden", display: "flex", flexDirection: "column" }, children: /* @__PURE__ */ t("div", { className: "convokit-chat-window-content", style: { flex: 1, minHeight: 0, overflow: "hidden", display: "flex", flexDirection: "column" }, children: /* @__PURE__ */ n("div", { className: "convokit-chat-container", style: { flex: 1, minHeight: 0, display: "flex", flexDirection: "column", padding: 16 }, children: [
503
- /* @__PURE__ */ n("div", { className: "convokit-messages", style: { flex: 1, overflowY: "auto", padding: "8px 0" }, children: [
504
- S && /* @__PURE__ */ n("div", { style: { padding: 12, margin: 8, background: "#fee", color: "#c33", borderRadius: 8, fontSize: 14 }, children: [
505
- "⚠️ ",
506
- S
507
- ] }),
508
- m.length === 0 && /* @__PURE__ */ t("div", { className: "convokit-message convokit-message-assistant", children: /* @__PURE__ */ t("div", { className: "convokit-message-content", dangerouslySetInnerHTML: { __html: _(l.welcomeMessage) } }) }),
509
- m.map((a, p) => /* @__PURE__ */ t("div", { className: `convokit-message convokit-message-${a.role}`, children: /* @__PURE__ */ t("div", { className: "convokit-message-content", dangerouslySetInnerHTML: { __html: _(a.content) } }) }, p)),
510
- v && /* @__PURE__ */ t("div", { className: "convokit-message convokit-message-assistant", children: /* @__PURE__ */ t("div", { className: "convokit-message-content", children: /* @__PURE__ */ n("div", { className: "convokit-typing", "aria-hidden": "true", children: [
511
- /* @__PURE__ */ t("span", {}),
512
- /* @__PURE__ */ t("span", {}),
513
- /* @__PURE__ */ t("span", {})
514
- ] }) }) }),
515
- /* @__PURE__ */ t("div", { ref: o })
516
- ] }),
517
- /* @__PURE__ */ n("form", { onSubmit: T, className: "convokit-input-form", children: [
518
- /* @__PURE__ */ t(
519
- "input",
520
- {
521
- type: "text",
522
- value: g,
523
- onChange: (a) => B(a.target.value),
524
- placeholder: l.placeholder,
525
- disabled: v,
526
- className: "convokit-input"
527
- }
528
- ),
529
- /* @__PURE__ */ t("button", { type: "submit", disabled: v || !g.trim(), className: "convokit-send-button", "aria-label": "Send message", children: /* @__PURE__ */ n("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
530
- /* @__PURE__ */ t("path", { d: "M22 2L11 13" }),
531
- /* @__PURE__ */ t("path", { d: "M22 2l-7 20-4-9-9-4z" })
532
- ] }) })
533
- ] }),
534
- /* @__PURE__ */ n("div", { className: "convokit-footer", children: [
535
- "Powered by ",
536
- /* @__PURE__ */ t("a", { href: "https://convokit.com", target: "_blank", rel: "noopener noreferrer", children: "ConvoKit" })
537
- ] })
538
- ] }) }) })
539
- ]
540
- }
541
- ) : /* @__PURE__ */ t(
542
- L,
543
- {
544
- initial: { opacity: 0 },
545
- animate: { opacity: 1 },
546
- style: {
547
- position: "fixed",
548
- inset: 0,
549
- zIndex: 1e4,
550
- display: "flex",
551
- alignItems: "center",
552
- justifyContent: "center",
553
- background: "var(--convokit-chat-bg)",
554
- pointerEvents: "auto"
555
- },
556
- children: /* @__PURE__ */ n(
557
- "button",
558
- {
559
- type: "button",
560
- onClick: () => C(!0),
561
- "aria-label": "Open chat",
562
- style: {
563
- padding: "14px 28px",
564
- borderRadius: 12,
565
- border: "none",
566
- background: l.primaryColor,
567
- color: "white",
568
- fontSize: 16,
569
- fontWeight: 500,
570
- cursor: "pointer",
571
- display: "flex",
572
- alignItems: "center",
573
- gap: 10,
574
- boxShadow: "0 4px 14px rgba(0,0,0,0.15)"
575
- },
576
- children: [
577
- /* @__PURE__ */ t("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ t("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) }),
578
- "Open chat"
579
- ]
580
- }
581
- )
582
- }
583
- );
584
- }, O = {
585
- title: "Chat",
586
- welcomeMessage: "How can I help you today?"
587
- }, ce = (e) => {
588
- const { apiUrl: c, apiKey: r } = e;
589
- if (!(c != null && c.trim()) || !(r != null && r.trim()))
590
- return null;
591
- const k = {
592
- ...O,
593
- apiUrl: c.trim(),
594
- apiKey: r.trim(),
595
- authToken: e.authToken,
596
- widgetId: e.widgetId,
597
- title: e.title ?? O.title,
598
- welcomeMessage: e.welcomeMessage ?? O.welcomeMessage,
599
- primaryColor: e.primaryColor
600
- };
601
- return /* @__PURE__ */ t(
602
- oe,
603
- {
604
- config: k,
605
- onBack: e.onBack,
606
- backLabel: e.backLabel ?? "Back"
607
- }
608
- );
609
- };
3
+ import { PopupWidget as t } from "./PopupWidget-sIgNr_Yy.js";
610
4
  export {
611
- ce as FullScreenBackendWidget,
612
- ae as FullScreenWidget,
613
- le as PopupBackendWidget,
614
- me as PopupWidget
5
+ t as PopupWidget
615
6
  };
package/dist/next.esm.js CHANGED
@@ -3,7 +3,7 @@ import { jsx as o } from "react/jsx-runtime";
3
3
  import i from "next/dynamic";
4
4
  /* empty css */
5
5
  const n = i(
6
- () => import("./PopupWidget-DhKUzzJD.js").then((e) => e.h).then((e) => e.PopupWidget),
6
+ () => import("./PopupWidget-sIgNr_Yy.js").then((e) => e.PopupWidget),
7
7
  { ssr: !1 }
8
8
  ), s = () => {
9
9
  var e;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@convokit/widget",
3
- "version": "0.0.11",
3
+ "version": "0.1.0",
4
4
  "description": "AI chat widget for your website",
5
5
  "type": "module",
6
6
  "main": "dist/index.esm.js",