@uptrademedia/site-kit 1.0.4 → 1.0.7
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/README.md +96 -25
- package/dist/analytics/index.js +7 -7
- package/dist/analytics/index.mjs +3 -3
- package/dist/api-QUIPJJCX.js +77 -0
- package/dist/api-QUIPJJCX.js.map +1 -0
- package/dist/api-V3BA5PMX.mjs +4 -0
- package/dist/api-V3BA5PMX.mjs.map +1 -0
- package/dist/blog/index.d.mts +160 -5
- package/dist/blog/index.d.ts +160 -5
- package/dist/blog/index.js +1166 -18
- package/dist/blog/index.js.map +1 -1
- package/dist/blog/index.mjs +1156 -18
- package/dist/blog/index.mjs.map +1 -1
- package/dist/blog/server.d.mts +229 -0
- package/dist/blog/server.d.ts +229 -0
- package/dist/blog/server.js +692 -0
- package/dist/blog/server.js.map +1 -0
- package/dist/blog/server.mjs +666 -0
- package/dist/blog/server.mjs.map +1 -0
- package/dist/{chunk-FKVJOT2F.mjs → chunk-42EXHJTC.mjs} +196 -7
- package/dist/chunk-42EXHJTC.mjs.map +1 -0
- package/dist/{scanner-AZV5I6US.mjs → chunk-44OMJFCG.mjs} +354 -14
- package/dist/chunk-44OMJFCG.mjs.map +1 -0
- package/dist/chunk-4TGJYNHV.js +981 -0
- package/dist/chunk-4TGJYNHV.js.map +1 -0
- package/dist/chunk-4XPGGLVP.mjs +53 -0
- package/dist/{chunk-NYKRE2FL.mjs.map → chunk-4XPGGLVP.mjs.map} +1 -1
- package/dist/{generators-TO2FKJR6.mjs → chunk-6ONUXZDO.mjs} +26 -9
- package/dist/chunk-6ONUXZDO.mjs.map +1 -0
- package/dist/chunk-CG53ASWX.mjs +729 -0
- package/dist/chunk-CG53ASWX.mjs.map +1 -0
- package/dist/{scanner-ETJAMIT7.js → chunk-DERI27QC.js} +448 -102
- package/dist/chunk-DERI27QC.js.map +1 -0
- package/dist/chunk-DYM5ML2V.mjs +1518 -0
- package/dist/chunk-DYM5ML2V.mjs.map +1 -0
- package/dist/chunk-FLZZOX44.js +1526 -0
- package/dist/chunk-FLZZOX44.js.map +1 -0
- package/dist/{chunk-7H6I3ECV.mjs → chunk-FQVGK746.mjs} +63 -3
- package/dist/chunk-FQVGK746.mjs.map +1 -0
- package/dist/{chunk-GQ6ZOU2N.mjs → chunk-JGQPAXTL.mjs} +4 -4
- package/dist/{chunk-GQ6ZOU2N.mjs.map → chunk-JGQPAXTL.mjs.map} +1 -1
- package/dist/{chunk-V3F5J6CV.js → chunk-JUEVN4Q4.js} +196 -7
- package/dist/chunk-JUEVN4Q4.js.map +1 -0
- package/dist/chunk-KKMGTT7F.mjs +968 -0
- package/dist/chunk-KKMGTT7F.mjs.map +1 -0
- package/dist/{chunk-XQJX252G.mjs → chunk-MB3WR5KJ.mjs} +28 -18
- package/dist/chunk-MB3WR5KJ.mjs.map +1 -0
- package/dist/{chunk-2IHTEKHU.mjs → chunk-QD5CN2OI.mjs} +16 -7
- package/dist/chunk-QD5CN2OI.mjs.map +1 -0
- package/dist/chunk-QD66FTXZ.mjs +278 -0
- package/dist/chunk-QD66FTXZ.mjs.map +1 -0
- package/dist/{chunk-SBVEYCSV.js → chunk-QQB4FO4Q.js} +7 -7
- package/dist/{chunk-SBVEYCSV.js.map → chunk-QQB4FO4Q.js.map} +1 -1
- package/dist/{generators-YZWIGHCO.js → chunk-S2GXR5HY.js} +26 -9
- package/dist/chunk-S2GXR5HY.js.map +1 -0
- package/dist/{chunk-O2OHHBUD.js → chunk-TDK7DLCH.js} +30 -20
- package/dist/chunk-TDK7DLCH.js.map +1 -0
- package/dist/chunk-UJQ73OS6.js +282 -0
- package/dist/chunk-UJQ73OS6.js.map +1 -0
- package/dist/{chunk-QP5NCO2E.js → chunk-VDI7KYME.js} +67 -2
- package/dist/chunk-VDI7KYME.js.map +1 -0
- package/dist/chunk-VOR53RUR.js +753 -0
- package/dist/chunk-VOR53RUR.js.map +1 -0
- package/dist/{chunk-GAJLEDRD.js → chunk-ZKJ7JKFV.js} +16 -7
- package/dist/chunk-ZKJ7JKFV.js.map +1 -0
- package/dist/chunk-ZSMWDLMK.js +63 -0
- package/dist/{chunk-EQCVQC35.js.map → chunk-ZSMWDLMK.js.map} +1 -1
- package/dist/cli/index.js +37269 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/index.mjs +37233 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/commerce/index.js +1 -1
- package/dist/commerce/index.mjs +1 -1
- package/dist/commerce/server.d.mts +12 -3
- package/dist/commerce/server.d.ts +12 -3
- package/dist/commerce/server.js +71 -70
- package/dist/commerce/server.js.map +1 -1
- package/dist/commerce/server.mjs +71 -70
- package/dist/commerce/server.mjs.map +1 -1
- package/dist/engage/index.d.mts +6 -4
- package/dist/engage/index.d.ts +6 -4
- package/dist/engage/index.js +8 -4
- package/dist/engage/index.mjs +2 -2
- package/dist/forms/index.js +1 -1
- package/dist/forms/index.mjs +1 -1
- package/dist/generators-5EU4PTVF.js +33 -0
- package/dist/generators-5EU4PTVF.js.map +1 -0
- package/dist/generators-TYPILCWD.mjs +4 -0
- package/dist/generators-TYPILCWD.mjs.map +1 -0
- package/dist/images/index.js +11 -11
- package/dist/images/index.mjs +4 -4
- package/dist/index.d.mts +155 -5
- package/dist/index.d.ts +155 -5
- package/dist/index.js +979 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +821 -8
- package/dist/index.mjs.map +1 -1
- package/dist/llms/index.d.mts +657 -0
- package/dist/llms/index.d.ts +657 -0
- package/dist/llms/index.js +101 -0
- package/dist/llms/index.js.map +1 -0
- package/dist/llms/index.mjs +4 -0
- package/dist/llms/index.mjs.map +1 -0
- package/dist/migrator-ARLHUNB3.mjs +4 -0
- package/dist/migrator-ARLHUNB3.mjs.map +1 -0
- package/dist/migrator-VZLBH3VY.js +37 -0
- package/dist/migrator-VZLBH3VY.js.map +1 -0
- package/dist/redirects/index.js +1 -1
- package/dist/redirects/index.mjs +1 -1
- package/dist/reputation/index.d.mts +57 -0
- package/dist/reputation/index.d.ts +57 -0
- package/dist/reputation/index.js +21 -0
- package/dist/reputation/index.js.map +1 -0
- package/dist/reputation/index.mjs +4 -0
- package/dist/reputation/index.mjs.map +1 -0
- package/dist/{routing-BWjUF7lp.d.ts → routing-CF91y6NO.d.ts} +1 -1
- package/dist/{routing-CgmRi9tD.d.mts → routing-CIOFpFCB.d.mts} +1 -1
- package/dist/scanner-7ZMUM2P5.mjs +4 -0
- package/dist/scanner-7ZMUM2P5.mjs.map +1 -0
- package/dist/scanner-OY7UF3WA.js +53 -0
- package/dist/scanner-OY7UF3WA.js.map +1 -0
- package/dist/seo/index.d.mts +267 -7
- package/dist/seo/index.d.ts +267 -7
- package/dist/seo/index.js +432 -24
- package/dist/seo/index.js.map +1 -1
- package/dist/seo/index.mjs +400 -11
- package/dist/seo/index.mjs.map +1 -1
- package/dist/seo/server.d.mts +11 -4
- package/dist/seo/server.d.ts +11 -4
- package/dist/seo/server.js +17 -17
- package/dist/seo/server.mjs +3 -3
- package/dist/setup/client.js +1 -1
- package/dist/setup/client.mjs +1 -1
- package/dist/setup/index.js +3 -3
- package/dist/setup/index.mjs +2 -2
- package/dist/setup/server.js +3 -3
- package/dist/setup/server.mjs +2 -2
- package/dist/sitemap/index.js +2 -2
- package/dist/sitemap/index.js.map +1 -1
- package/dist/sitemap/index.mjs +2 -2
- package/dist/sitemap/index.mjs.map +1 -1
- package/dist/{types-C0pJGfbH.d.mts → types-D6FHAVWX.d.mts} +99 -3
- package/dist/{types-C0pJGfbH.d.ts → types-D6FHAVWX.d.ts} +99 -3
- package/dist/{types-BDojCvvL.d.mts → types-DI0jnhjJ.d.mts} +31 -8
- package/dist/{types-BDojCvvL.d.ts → types-DI0jnhjJ.d.ts} +31 -8
- package/dist/{types-BmzutFwy.d.ts → types-j8X4vUhB.d.mts} +19 -2
- package/dist/{types-BmzutFwy.d.mts → types-j8X4vUhB.d.ts} +19 -2
- package/dist/{web-vitals-BH55V7EJ.js → web-vitals-444RLW3B.js} +11 -11
- package/dist/{web-vitals-BH55V7EJ.js.map → web-vitals-444RLW3B.js.map} +1 -1
- package/dist/{web-vitals-RJYPWAR3.mjs → web-vitals-KPICZIEF.mjs} +3 -3
- package/dist/{web-vitals-RJYPWAR3.mjs.map → web-vitals-KPICZIEF.mjs.map} +1 -1
- package/package.json +22 -10
- package/dist/api-N35S3EES.js +0 -57
- package/dist/api-N35S3EES.js.map +0 -1
- package/dist/api-SYBTK7Z7.mjs +0 -4
- package/dist/api-SYBTK7Z7.mjs.map +0 -1
- package/dist/chunk-2IHTEKHU.mjs.map +0 -1
- package/dist/chunk-7H6I3ECV.mjs.map +0 -1
- package/dist/chunk-BGJLOJ7T.mjs +0 -605
- package/dist/chunk-BGJLOJ7T.mjs.map +0 -1
- package/dist/chunk-EQCVQC35.js +0 -35
- package/dist/chunk-FKVJOT2F.mjs.map +0 -1
- package/dist/chunk-GAJLEDRD.js.map +0 -1
- package/dist/chunk-NYKRE2FL.mjs +0 -31
- package/dist/chunk-O2OHHBUD.js.map +0 -1
- package/dist/chunk-QAYJV4KK.js +0 -608
- package/dist/chunk-QAYJV4KK.js.map +0 -1
- package/dist/chunk-QP5NCO2E.js.map +0 -1
- package/dist/chunk-V3F5J6CV.js.map +0 -1
- package/dist/chunk-XQJX252G.mjs.map +0 -1
- package/dist/generators-TO2FKJR6.mjs.map +0 -1
- package/dist/generators-YZWIGHCO.js.map +0 -1
- package/dist/migrator-V6KS75EA.mjs +0 -265
- package/dist/migrator-V6KS75EA.mjs.map +0 -1
- package/dist/migrator-XKM7YQCY.js +0 -272
- package/dist/migrator-XKM7YQCY.js.map +0 -1
- package/dist/scanner-AZV5I6US.mjs.map +0 -1
- package/dist/scanner-ETJAMIT7.js.map +0 -1
|
@@ -0,0 +1,1526 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React2 = require('react');
|
|
4
|
+
var socket_ioClient = require('socket.io-client');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var navigation = require('next/navigation');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var React2__default = /*#__PURE__*/_interopDefault(React2);
|
|
11
|
+
|
|
12
|
+
// src/engage/ChatWidget.tsx
|
|
13
|
+
function getApiConfig() {
|
|
14
|
+
const apiUrl = typeof window !== "undefined" ? window.__SITE_KIT_API_URL__ || "https://api.uptrademedia.com" : "https://api.uptrademedia.com";
|
|
15
|
+
const apiKey = typeof window !== "undefined" ? window.__SITE_KIT_API_KEY__ : void 0;
|
|
16
|
+
return { apiUrl, apiKey };
|
|
17
|
+
}
|
|
18
|
+
function generateVisitorId() {
|
|
19
|
+
const stored = typeof localStorage !== "undefined" ? localStorage.getItem("engage_visitor_id") : null;
|
|
20
|
+
if (stored) return stored;
|
|
21
|
+
const id = `visitor_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
22
|
+
if (typeof localStorage !== "undefined") {
|
|
23
|
+
localStorage.setItem("engage_visitor_id", id);
|
|
24
|
+
}
|
|
25
|
+
return id;
|
|
26
|
+
}
|
|
27
|
+
function ChatWidget({ projectId, config, apiUrl: propApiUrl }) {
|
|
28
|
+
const [isOpen, setIsOpen] = React2.useState(false);
|
|
29
|
+
const [messages, setMessages] = React2.useState([]);
|
|
30
|
+
const [inputValue, setInputValue] = React2.useState("");
|
|
31
|
+
const [isLoading, setIsLoading] = React2.useState(false);
|
|
32
|
+
const [availability, setAvailability] = React2.useState(null);
|
|
33
|
+
const [sessionId, setSessionId] = React2.useState(null);
|
|
34
|
+
const [visitorId] = React2.useState(generateVisitorId);
|
|
35
|
+
const [agentTyping, setAgentTyping] = React2.useState(false);
|
|
36
|
+
const [showOfflineForm, setShowOfflineForm] = React2.useState(false);
|
|
37
|
+
const [offlineForm, setOfflineForm] = React2.useState({ name: "", email: "", phone: "", message: "" });
|
|
38
|
+
const [offlineSubmitted, setOfflineSubmitted] = React2.useState(false);
|
|
39
|
+
const [connectionStatus, setConnectionStatus] = React2.useState("disconnected");
|
|
40
|
+
const [widgetConfig, setWidgetConfig] = React2.useState(null);
|
|
41
|
+
const [handoffOfflinePrompt, setHandoffOfflinePrompt] = React2.useState(null);
|
|
42
|
+
const [pendingFiles, setPendingFiles] = React2.useState([]);
|
|
43
|
+
const [lastFailedSend, setLastFailedSend] = React2.useState(null);
|
|
44
|
+
React2.useRef(null);
|
|
45
|
+
const messagesEndRef = React2.useRef(null);
|
|
46
|
+
const inputRef = React2.useRef(null);
|
|
47
|
+
const socketRef = React2.useRef(null);
|
|
48
|
+
const pollingIntervalRef = React2.useRef(null);
|
|
49
|
+
const position = config?.position || "bottom-right";
|
|
50
|
+
const buttonColor = config?.buttonColor || "#00afab";
|
|
51
|
+
const welcomeMessage = widgetConfig?.initial_message ?? widgetConfig?.welcome_message ?? config?.welcomeMessage ?? "Hi! How can I help you today?";
|
|
52
|
+
const offlineFormPrompt = handoffOfflinePrompt ?? widgetConfig?.form_description ?? widgetConfig?.offline_message ?? config?.offlineMessage ?? "We're currently offline. Leave us a message and we'll get back to you!";
|
|
53
|
+
const baseUrl = propApiUrl || getApiConfig().apiUrl;
|
|
54
|
+
const fetchWidgetConfig = React2.useCallback(async () => {
|
|
55
|
+
try {
|
|
56
|
+
const { apiKey } = getApiConfig();
|
|
57
|
+
const response = await fetch(`${baseUrl}/api/engage/widget/config?projectId=${projectId}`, {
|
|
58
|
+
headers: apiKey ? { "x-api-key": apiKey } : {}
|
|
59
|
+
});
|
|
60
|
+
if (response.ok) {
|
|
61
|
+
const { data } = await response.json();
|
|
62
|
+
setWidgetConfig(data ?? null);
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error("[ChatWidget] Config fetch failed:", error);
|
|
66
|
+
}
|
|
67
|
+
}, [projectId, baseUrl]);
|
|
68
|
+
const checkAvailability = React2.useCallback(async () => {
|
|
69
|
+
try {
|
|
70
|
+
const { apiKey } = getApiConfig();
|
|
71
|
+
const response = await fetch(`${baseUrl}/api/engage/widget/availability?projectId=${projectId}`, {
|
|
72
|
+
headers: apiKey ? { "x-api-key": apiKey } : {}
|
|
73
|
+
});
|
|
74
|
+
if (response.ok) {
|
|
75
|
+
const { data } = await response.json();
|
|
76
|
+
setAvailability(data);
|
|
77
|
+
if (data.mode === "offline" && !sessionId) {
|
|
78
|
+
setShowOfflineForm(true);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error("[ChatWidget] Availability check failed:", error);
|
|
83
|
+
}
|
|
84
|
+
}, [projectId, baseUrl, sessionId]);
|
|
85
|
+
const initSession = React2.useCallback(async () => {
|
|
86
|
+
try {
|
|
87
|
+
const { apiKey } = getApiConfig();
|
|
88
|
+
const response = await fetch(`${baseUrl}/api/engage/widget/session`, {
|
|
89
|
+
method: "POST",
|
|
90
|
+
headers: {
|
|
91
|
+
"Content-Type": "application/json",
|
|
92
|
+
...apiKey && { "x-api-key": apiKey }
|
|
93
|
+
},
|
|
94
|
+
body: JSON.stringify({
|
|
95
|
+
projectId,
|
|
96
|
+
visitorId,
|
|
97
|
+
sourceUrl: typeof window !== "undefined" ? window.location.href : "",
|
|
98
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : ""
|
|
99
|
+
})
|
|
100
|
+
});
|
|
101
|
+
if (response.ok) {
|
|
102
|
+
const { data } = await response.json();
|
|
103
|
+
const sid = data.id || data.session_id;
|
|
104
|
+
setSessionId(sid);
|
|
105
|
+
if (data.messages?.length > 0) {
|
|
106
|
+
setMessages(data.messages.map((m) => ({
|
|
107
|
+
id: m.id,
|
|
108
|
+
role: m.role === "visitor" ? "user" : m.role,
|
|
109
|
+
content: m.content,
|
|
110
|
+
timestamp: new Date(m.created_at),
|
|
111
|
+
agentName: m.sender_name
|
|
112
|
+
})));
|
|
113
|
+
}
|
|
114
|
+
return sid;
|
|
115
|
+
}
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error("[ChatWidget] Session init failed:", error);
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}, [projectId, visitorId, baseUrl]);
|
|
121
|
+
const handleSocketMessage = React2.useCallback((data) => {
|
|
122
|
+
switch (data.type || data.event) {
|
|
123
|
+
case "message": {
|
|
124
|
+
const role = data.role === "visitor" ? "user" : data.role === "ai" ? "assistant" : data.role;
|
|
125
|
+
const newMessage = {
|
|
126
|
+
id: data.id || `msg-${Date.now()}`,
|
|
127
|
+
role,
|
|
128
|
+
content: data.content ?? "",
|
|
129
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
130
|
+
agentName: data.agentName
|
|
131
|
+
};
|
|
132
|
+
const withAttachments = data.attachments?.length ? { ...newMessage, attachments: data.attachments } : newMessage;
|
|
133
|
+
const withSuggestions = data.suggestions?.length ? { ...withAttachments, suggestions: data.suggestions } : withAttachments;
|
|
134
|
+
setMessages((prev) => [...prev, withSuggestions]);
|
|
135
|
+
if (role === "assistant" || role === "agent") {
|
|
136
|
+
setAgentTyping(false);
|
|
137
|
+
setIsLoading(false);
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
case "agent:joined":
|
|
142
|
+
setMessages((prev) => [...prev, {
|
|
143
|
+
id: `system-${Date.now()}`,
|
|
144
|
+
role: "system",
|
|
145
|
+
content: data.agentName ? `${data.agentName} has joined the chat.` : "An agent has joined the chat.",
|
|
146
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
147
|
+
}]);
|
|
148
|
+
break;
|
|
149
|
+
case "typing":
|
|
150
|
+
setAgentTyping(data.isTyping);
|
|
151
|
+
break;
|
|
152
|
+
case "handoff:initiated":
|
|
153
|
+
setMessages((prev) => [...prev, {
|
|
154
|
+
id: `system-${Date.now()}`,
|
|
155
|
+
role: "system",
|
|
156
|
+
content: data.message || "Connecting you with a team member...",
|
|
157
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
158
|
+
}]);
|
|
159
|
+
break;
|
|
160
|
+
case "chat:closed":
|
|
161
|
+
setMessages((prev) => [...prev, {
|
|
162
|
+
id: `system-${Date.now()}`,
|
|
163
|
+
role: "system",
|
|
164
|
+
content: data.message || "This chat has been closed.",
|
|
165
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
166
|
+
}]);
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}, []);
|
|
170
|
+
const connectSocket = React2.useCallback(
|
|
171
|
+
(currentSessionId) => {
|
|
172
|
+
if (socketRef.current?.connected) return;
|
|
173
|
+
const namespaceUrl = `${baseUrl.replace(/\/$/, "")}/engage/chat`;
|
|
174
|
+
const socket = socket_ioClient.io(namespaceUrl, {
|
|
175
|
+
query: { projectId, visitorId, sessionId: currentSessionId },
|
|
176
|
+
transports: ["websocket", "polling"]
|
|
177
|
+
});
|
|
178
|
+
socket.on("connect", () => {
|
|
179
|
+
setConnectionStatus("connected");
|
|
180
|
+
console.log("[ChatWidget] Socket.io connected");
|
|
181
|
+
if (currentSessionId) {
|
|
182
|
+
const { apiKey } = getApiConfig();
|
|
183
|
+
fetch(`${baseUrl}/api/engage/widget/messages?sessionId=${currentSessionId}`, {
|
|
184
|
+
headers: apiKey ? { "x-api-key": apiKey } : {}
|
|
185
|
+
}).then((res) => res.ok ? res.json() : null).then((json) => {
|
|
186
|
+
const data = json?.data ?? json;
|
|
187
|
+
if (Array.isArray(data) && data.length) {
|
|
188
|
+
setMessages((prev) => {
|
|
189
|
+
const byId = new Map(prev.map((m) => [m.id, m]));
|
|
190
|
+
data.forEach((m) => byId.set(m.id, { id: m.id, role: m.role === "visitor" ? "user" : m.role, content: m.content, timestamp: new Date(m.created_at), agentName: m.sender_name, attachments: m.attachments }));
|
|
191
|
+
return Array.from(byId.values()).sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}).catch((err) => console.warn("[ChatWidget] Refetch messages on reconnect failed", err));
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
socket.on("message", (data) => {
|
|
198
|
+
handleSocketMessage({ type: "message", ...data });
|
|
199
|
+
});
|
|
200
|
+
socket.on("agent:joined", (data) => {
|
|
201
|
+
handleSocketMessage({ type: "agent:joined", ...data });
|
|
202
|
+
});
|
|
203
|
+
socket.on("typing", (data) => {
|
|
204
|
+
handleSocketMessage({ type: "typing", ...data });
|
|
205
|
+
});
|
|
206
|
+
socket.on("handoff:initiated", (data) => {
|
|
207
|
+
handleSocketMessage({ type: "handoff:initiated", ...data });
|
|
208
|
+
});
|
|
209
|
+
socket.on("chat:closed", (data) => {
|
|
210
|
+
handleSocketMessage({ type: "chat:closed", ...data });
|
|
211
|
+
});
|
|
212
|
+
socket.on("disconnect", (reason) => {
|
|
213
|
+
setConnectionStatus("disconnected");
|
|
214
|
+
console.log("[ChatWidget] Socket disconnected:", reason);
|
|
215
|
+
});
|
|
216
|
+
socket.on("connect_error", (err) => {
|
|
217
|
+
console.error("[ChatWidget] Socket connect error:", err);
|
|
218
|
+
setConnectionStatus("disconnected");
|
|
219
|
+
if (isOpen && currentSessionId) startPolling(currentSessionId);
|
|
220
|
+
});
|
|
221
|
+
socketRef.current = socket;
|
|
222
|
+
},
|
|
223
|
+
[projectId, visitorId, baseUrl, isOpen, handleSocketMessage, getApiConfig]
|
|
224
|
+
);
|
|
225
|
+
const startPolling = React2.useCallback((currentSessionId) => {
|
|
226
|
+
if (pollingIntervalRef.current) return;
|
|
227
|
+
pollingIntervalRef.current = setInterval(async () => {
|
|
228
|
+
try {
|
|
229
|
+
const { apiKey } = getApiConfig();
|
|
230
|
+
const response = await fetch(
|
|
231
|
+
`${baseUrl}/api/engage/widget/messages?sessionId=${currentSessionId}`,
|
|
232
|
+
{ headers: apiKey ? { "x-api-key": apiKey } : {} }
|
|
233
|
+
);
|
|
234
|
+
if (response.ok) {
|
|
235
|
+
const { data } = await response.json();
|
|
236
|
+
setMessages((prev) => {
|
|
237
|
+
const existingIds = new Set(prev.map((m) => m.id));
|
|
238
|
+
const newMessages = data.filter((m) => !existingIds.has(m.id));
|
|
239
|
+
if (newMessages.length > 0) {
|
|
240
|
+
return [...prev, ...newMessages.map((m) => ({
|
|
241
|
+
id: m.id,
|
|
242
|
+
role: m.role === "visitor" ? "user" : m.role,
|
|
243
|
+
content: m.content,
|
|
244
|
+
timestamp: new Date(m.created_at),
|
|
245
|
+
agentName: m.sender_name
|
|
246
|
+
}))];
|
|
247
|
+
}
|
|
248
|
+
return prev;
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
} catch (error) {
|
|
252
|
+
console.error("[ChatWidget] Polling failed:", error);
|
|
253
|
+
}
|
|
254
|
+
}, 3e3);
|
|
255
|
+
}, [baseUrl]);
|
|
256
|
+
React2.useEffect(() => {
|
|
257
|
+
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
258
|
+
}, [messages, agentTyping]);
|
|
259
|
+
React2.useEffect(() => {
|
|
260
|
+
if (isOpen && inputRef.current) {
|
|
261
|
+
inputRef.current.focus();
|
|
262
|
+
}
|
|
263
|
+
}, [isOpen]);
|
|
264
|
+
React2.useEffect(() => {
|
|
265
|
+
checkAvailability();
|
|
266
|
+
const interval = setInterval(checkAvailability, 6e4);
|
|
267
|
+
return () => {
|
|
268
|
+
clearInterval(interval);
|
|
269
|
+
if (socketRef.current) {
|
|
270
|
+
socketRef.current.disconnect();
|
|
271
|
+
socketRef.current = null;
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}, [checkAvailability]);
|
|
275
|
+
React2.useEffect(() => {
|
|
276
|
+
if (isOpen) fetchWidgetConfig();
|
|
277
|
+
}, [isOpen, fetchWidgetConfig]);
|
|
278
|
+
React2.useEffect(() => {
|
|
279
|
+
if (isOpen && !sessionId && availability?.mode !== "offline") {
|
|
280
|
+
initSession().then((id) => {
|
|
281
|
+
if (id && (availability?.mode === "live" || availability?.mode === "ai")) {
|
|
282
|
+
setConnectionStatus("connecting");
|
|
283
|
+
connectSocket(id);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
return () => {
|
|
288
|
+
if (pollingIntervalRef.current) clearInterval(pollingIntervalRef.current);
|
|
289
|
+
};
|
|
290
|
+
}, [isOpen, sessionId, availability?.mode, initSession, connectSocket]);
|
|
291
|
+
const handleToggle = React2.useCallback(() => {
|
|
292
|
+
setIsOpen((prev) => !prev);
|
|
293
|
+
if (!isOpen && messages.length === 0 && availability?.mode !== "offline") {
|
|
294
|
+
setMessages([{
|
|
295
|
+
id: "welcome",
|
|
296
|
+
role: "assistant",
|
|
297
|
+
content: welcomeMessage,
|
|
298
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
299
|
+
}]);
|
|
300
|
+
}
|
|
301
|
+
}, [isOpen, messages.length, welcomeMessage, availability?.mode]);
|
|
302
|
+
const uploadWidgetFile = React2.useCallback(
|
|
303
|
+
async (file) => {
|
|
304
|
+
if (!sessionId || !visitorId) return null;
|
|
305
|
+
const { apiKey } = getApiConfig();
|
|
306
|
+
const form = new FormData();
|
|
307
|
+
form.append("file", file);
|
|
308
|
+
form.append("sessionId", sessionId);
|
|
309
|
+
form.append("visitorId", visitorId);
|
|
310
|
+
const res = await fetch(`${baseUrl}/api/engage/widget/upload`, {
|
|
311
|
+
method: "POST",
|
|
312
|
+
headers: apiKey ? { "x-api-key": apiKey } : {},
|
|
313
|
+
body: form
|
|
314
|
+
});
|
|
315
|
+
if (!res.ok) throw new Error("Upload failed");
|
|
316
|
+
const json = await res.json();
|
|
317
|
+
const d = json?.data ?? json;
|
|
318
|
+
return d?.url ? { name: d.name ?? file.name, url: d.url, size: d.size, mimeType: d.mimeType } : null;
|
|
319
|
+
},
|
|
320
|
+
[sessionId, visitorId, baseUrl]
|
|
321
|
+
);
|
|
322
|
+
const handleSubmit = React2.useCallback(
|
|
323
|
+
async (e) => {
|
|
324
|
+
e.preventDefault();
|
|
325
|
+
const hasText = !!inputValue.trim();
|
|
326
|
+
const hasFiles = pendingFiles.length > 0;
|
|
327
|
+
if (!hasText && !hasFiles || isLoading) return;
|
|
328
|
+
const content = inputValue.trim() || "";
|
|
329
|
+
let attachments = [];
|
|
330
|
+
if (pendingFiles.length) {
|
|
331
|
+
try {
|
|
332
|
+
for (const file of pendingFiles) {
|
|
333
|
+
const att = await uploadWidgetFile(file);
|
|
334
|
+
if (att) attachments.push(att);
|
|
335
|
+
}
|
|
336
|
+
setPendingFiles([]);
|
|
337
|
+
} catch (err) {
|
|
338
|
+
console.error("[ChatWidget] File upload failed", err);
|
|
339
|
+
setMessages((prev) => [...prev, { id: `err-${Date.now()}`, role: "assistant", content: "Failed to upload file. Please try again.", timestamp: /* @__PURE__ */ new Date() }]);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const userMessage = {
|
|
344
|
+
id: `user-${Date.now()}`,
|
|
345
|
+
role: "user",
|
|
346
|
+
content,
|
|
347
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
348
|
+
...attachments.length ? { attachments } : {}
|
|
349
|
+
};
|
|
350
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
351
|
+
setInputValue("");
|
|
352
|
+
setIsLoading(true);
|
|
353
|
+
const socket = socketRef.current;
|
|
354
|
+
if (socket?.connected) {
|
|
355
|
+
socket.emit("visitor:message", { content: userMessage.content, attachments: attachments.length ? attachments : void 0 });
|
|
356
|
+
setLastFailedSend(null);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
setLastFailedSend({ content: userMessage.content, attachments });
|
|
360
|
+
setMessages((prev) => [
|
|
361
|
+
...prev,
|
|
362
|
+
{ id: `error-${Date.now()}`, role: "assistant", content: "Connection lost.", timestamp: /* @__PURE__ */ new Date(), sendFailed: true }
|
|
363
|
+
]);
|
|
364
|
+
setIsLoading(false);
|
|
365
|
+
},
|
|
366
|
+
[inputValue, isLoading, pendingFiles, uploadWidgetFile, sessionId]
|
|
367
|
+
);
|
|
368
|
+
const retryFailedSend = React2.useCallback(() => {
|
|
369
|
+
if (!lastFailedSend || !sessionId) return;
|
|
370
|
+
const socket = socketRef.current;
|
|
371
|
+
if (socket?.connected) {
|
|
372
|
+
socket.emit("visitor:message", { content: lastFailedSend.content, attachments: lastFailedSend.attachments?.length ? lastFailedSend.attachments : void 0 });
|
|
373
|
+
setLastFailedSend(null);
|
|
374
|
+
setMessages((prev) => prev.filter((m) => !m.sendFailed));
|
|
375
|
+
setIsLoading(true);
|
|
376
|
+
} else {
|
|
377
|
+
connectSocket(sessionId);
|
|
378
|
+
setLastFailedSend(lastFailedSend);
|
|
379
|
+
}
|
|
380
|
+
}, [lastFailedSend, sessionId, connectSocket]);
|
|
381
|
+
const requestHandoff = React2.useCallback(async () => {
|
|
382
|
+
if (!sessionId) return;
|
|
383
|
+
try {
|
|
384
|
+
const { apiKey } = getApiConfig();
|
|
385
|
+
const availRes = await fetch(`${baseUrl}/api/engage/widget/availability?projectId=${projectId}`, {
|
|
386
|
+
headers: apiKey ? { "x-api-key": apiKey } : {}
|
|
387
|
+
});
|
|
388
|
+
const avail = availRes.ok ? (await availRes.json()).data : null;
|
|
389
|
+
if (avail?.agentsOnline === 0) {
|
|
390
|
+
setHandoffOfflinePrompt(
|
|
391
|
+
widgetConfig?.form_description ?? widgetConfig?.offline_message ?? "Nobody is online right now. Leave your details and we'll get back to you."
|
|
392
|
+
);
|
|
393
|
+
setShowOfflineForm(true);
|
|
394
|
+
setMessages((prev) => [
|
|
395
|
+
...prev,
|
|
396
|
+
{
|
|
397
|
+
id: `handoff-offline-${Date.now()}`,
|
|
398
|
+
role: "system",
|
|
399
|
+
content: "We're not available at the moment. Please leave your info below and we'll follow up soon.",
|
|
400
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
401
|
+
}
|
|
402
|
+
]);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
await fetch(`${baseUrl}/api/engage/widget/handoff`, {
|
|
406
|
+
method: "POST",
|
|
407
|
+
headers: {
|
|
408
|
+
"Content-Type": "application/json",
|
|
409
|
+
...apiKey && { "x-api-key": apiKey }
|
|
410
|
+
},
|
|
411
|
+
body: JSON.stringify({ sessionId })
|
|
412
|
+
});
|
|
413
|
+
setMessages((prev) => [
|
|
414
|
+
...prev,
|
|
415
|
+
{
|
|
416
|
+
id: `handoff-${Date.now()}`,
|
|
417
|
+
role: "system",
|
|
418
|
+
content: "Connecting you with a team member. Please hold on!",
|
|
419
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
420
|
+
}
|
|
421
|
+
]);
|
|
422
|
+
} catch (error) {
|
|
423
|
+
console.error("[ChatWidget] Handoff request failed:", error);
|
|
424
|
+
}
|
|
425
|
+
}, [sessionId, baseUrl, projectId, widgetConfig]);
|
|
426
|
+
const handleOfflineSubmit = React2.useCallback(async (e) => {
|
|
427
|
+
e.preventDefault();
|
|
428
|
+
if (!offlineForm.name || !offlineForm.email || !offlineForm.message) return;
|
|
429
|
+
setIsLoading(true);
|
|
430
|
+
try {
|
|
431
|
+
const { apiKey } = getApiConfig();
|
|
432
|
+
const response = await fetch(`${baseUrl}/api/engage/widget/offline-form`, {
|
|
433
|
+
method: "POST",
|
|
434
|
+
headers: {
|
|
435
|
+
"Content-Type": "application/json",
|
|
436
|
+
...apiKey && { "x-api-key": apiKey }
|
|
437
|
+
},
|
|
438
|
+
body: JSON.stringify({
|
|
439
|
+
projectId,
|
|
440
|
+
visitorId,
|
|
441
|
+
...offlineForm,
|
|
442
|
+
pageUrl: typeof window !== "undefined" ? window.location.href : "",
|
|
443
|
+
...widgetConfig?.offlineFormSlug && { formSlug: widgetConfig.offlineFormSlug }
|
|
444
|
+
})
|
|
445
|
+
});
|
|
446
|
+
if (response.ok) {
|
|
447
|
+
setOfflineSubmitted(true);
|
|
448
|
+
}
|
|
449
|
+
} catch (error) {
|
|
450
|
+
console.error("[ChatWidget] Offline form submission failed:", error);
|
|
451
|
+
} finally {
|
|
452
|
+
setIsLoading(false);
|
|
453
|
+
}
|
|
454
|
+
}, [offlineForm, projectId, visitorId, baseUrl]);
|
|
455
|
+
const handleKeyDown = React2.useCallback((e) => {
|
|
456
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
457
|
+
e.preventDefault();
|
|
458
|
+
handleSubmit(e);
|
|
459
|
+
}
|
|
460
|
+
}, [handleSubmit]);
|
|
461
|
+
const handleTyping = React2.useCallback(() => {
|
|
462
|
+
const socket = socketRef.current;
|
|
463
|
+
if (socket?.connected) {
|
|
464
|
+
socket.emit("visitor:typing", { isTyping: true });
|
|
465
|
+
setTimeout(() => {
|
|
466
|
+
if (socketRef.current?.connected) {
|
|
467
|
+
socketRef.current.emit("visitor:typing", { isTyping: false });
|
|
468
|
+
}
|
|
469
|
+
}, 2e3);
|
|
470
|
+
}
|
|
471
|
+
}, []);
|
|
472
|
+
const ChatButton = /* @__PURE__ */ jsxRuntime.jsx(
|
|
473
|
+
"button",
|
|
474
|
+
{
|
|
475
|
+
onClick: handleToggle,
|
|
476
|
+
"aria-label": isOpen ? "Close chat" : "Open chat",
|
|
477
|
+
style: {
|
|
478
|
+
position: "fixed",
|
|
479
|
+
[position === "bottom-left" ? "left" : "right"]: 20,
|
|
480
|
+
bottom: 20,
|
|
481
|
+
width: 60,
|
|
482
|
+
height: 60,
|
|
483
|
+
borderRadius: "50%",
|
|
484
|
+
backgroundColor: buttonColor,
|
|
485
|
+
border: "none",
|
|
486
|
+
display: "flex",
|
|
487
|
+
alignItems: "center",
|
|
488
|
+
justifyContent: "center",
|
|
489
|
+
cursor: "pointer",
|
|
490
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.25)",
|
|
491
|
+
transition: "transform 0.2s, box-shadow 0.2s",
|
|
492
|
+
zIndex: 9999
|
|
493
|
+
},
|
|
494
|
+
onMouseEnter: (e) => {
|
|
495
|
+
e.currentTarget.style.transform = "scale(1.05)";
|
|
496
|
+
e.currentTarget.style.boxShadow = "0 6px 16px rgba(0, 0, 0, 0.3)";
|
|
497
|
+
},
|
|
498
|
+
onMouseLeave: (e) => {
|
|
499
|
+
e.currentTarget.style.transform = "scale(1)";
|
|
500
|
+
e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.25)";
|
|
501
|
+
},
|
|
502
|
+
children: isOpen ? (
|
|
503
|
+
// Close icon (X)
|
|
504
|
+
/* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
505
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
506
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
507
|
+
] })
|
|
508
|
+
) : (
|
|
509
|
+
// Chat icon
|
|
510
|
+
/* @__PURE__ */ jsxRuntime.jsx("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) })
|
|
511
|
+
)
|
|
512
|
+
}
|
|
513
|
+
);
|
|
514
|
+
const ChatPopup = isOpen && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
515
|
+
"div",
|
|
516
|
+
{
|
|
517
|
+
style: {
|
|
518
|
+
position: "fixed",
|
|
519
|
+
[position === "bottom-left" ? "left" : "right"]: 20,
|
|
520
|
+
bottom: 90,
|
|
521
|
+
width: 380,
|
|
522
|
+
maxWidth: "calc(100vw - 40px)",
|
|
523
|
+
height: 500,
|
|
524
|
+
maxHeight: "calc(100vh - 120px)",
|
|
525
|
+
backgroundColor: "#ffffff",
|
|
526
|
+
borderRadius: 16,
|
|
527
|
+
boxShadow: "0 8px 32px rgba(0, 0, 0, 0.2)",
|
|
528
|
+
display: "flex",
|
|
529
|
+
flexDirection: "column",
|
|
530
|
+
overflow: "hidden",
|
|
531
|
+
zIndex: 9998,
|
|
532
|
+
animation: "chatSlideUp 0.3s ease-out"
|
|
533
|
+
},
|
|
534
|
+
children: [
|
|
535
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
536
|
+
"div",
|
|
537
|
+
{
|
|
538
|
+
style: {
|
|
539
|
+
padding: "16px 20px",
|
|
540
|
+
background: `linear-gradient(135deg, ${buttonColor}, ${adjustColor(buttonColor, -20)})`,
|
|
541
|
+
color: "white",
|
|
542
|
+
display: "flex",
|
|
543
|
+
alignItems: "center",
|
|
544
|
+
gap: 12
|
|
545
|
+
},
|
|
546
|
+
children: [
|
|
547
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
548
|
+
"div",
|
|
549
|
+
{
|
|
550
|
+
style: {
|
|
551
|
+
width: 40,
|
|
552
|
+
height: 40,
|
|
553
|
+
borderRadius: "50%",
|
|
554
|
+
backgroundColor: "rgba(255,255,255,0.2)",
|
|
555
|
+
display: "flex",
|
|
556
|
+
alignItems: "center",
|
|
557
|
+
justifyContent: "center"
|
|
558
|
+
},
|
|
559
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) })
|
|
560
|
+
}
|
|
561
|
+
),
|
|
562
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { flex: 1 }, children: [
|
|
563
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontWeight: 600, fontSize: 16 }, children: showOfflineForm ? "Leave a Message" : "Chat with us" }),
|
|
564
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 13, opacity: 0.9, display: "flex", alignItems: "center", gap: 6 }, children: availability?.mode === "live" && availability.agentsOnline > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
565
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { width: 8, height: 8, borderRadius: "50%", backgroundColor: "#22c55e" } }),
|
|
566
|
+
availability.agentsOnline,
|
|
567
|
+
" online"
|
|
568
|
+
] }) : availability?.mode === "ai" ? "AI-powered support" : "We'll respond soon" })
|
|
569
|
+
] }),
|
|
570
|
+
availability?.mode === "offline" && !offlineSubmitted && /* @__PURE__ */ jsxRuntime.jsx(
|
|
571
|
+
"button",
|
|
572
|
+
{
|
|
573
|
+
onClick: () => setShowOfflineForm((prev) => !prev),
|
|
574
|
+
style: {
|
|
575
|
+
background: "rgba(255,255,255,0.2)",
|
|
576
|
+
border: "none",
|
|
577
|
+
borderRadius: 6,
|
|
578
|
+
padding: "4px 8px",
|
|
579
|
+
color: "white",
|
|
580
|
+
fontSize: 12,
|
|
581
|
+
cursor: "pointer"
|
|
582
|
+
},
|
|
583
|
+
children: showOfflineForm ? "Try Chat" : "Leave Message"
|
|
584
|
+
}
|
|
585
|
+
)
|
|
586
|
+
]
|
|
587
|
+
}
|
|
588
|
+
),
|
|
589
|
+
showOfflineForm ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: 20, flex: 1, overflowY: "auto" }, children: offlineSubmitted ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "center", padding: 20 }, children: [
|
|
590
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 48, marginBottom: 16 }, children: "\u2713" }),
|
|
591
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { style: { margin: "0 0 8px", fontSize: 18, fontWeight: 600 }, children: "Message Sent!" }),
|
|
592
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, color: "#666", fontSize: 14 }, children: "We'll get back to you as soon as possible." })
|
|
593
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleOfflineSubmit, children: [
|
|
594
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: "0 0 16px", color: "#666", fontSize: 14 }, children: offlineFormPrompt }),
|
|
595
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: 12 }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
596
|
+
"input",
|
|
597
|
+
{
|
|
598
|
+
type: "text",
|
|
599
|
+
placeholder: "Your name *",
|
|
600
|
+
value: offlineForm.name,
|
|
601
|
+
onChange: (e) => setOfflineForm((prev) => ({ ...prev, name: e.target.value })),
|
|
602
|
+
required: true,
|
|
603
|
+
style: {
|
|
604
|
+
width: "100%",
|
|
605
|
+
padding: "10px 12px",
|
|
606
|
+
borderRadius: 8,
|
|
607
|
+
border: "1px solid #e5e7eb",
|
|
608
|
+
fontSize: 14,
|
|
609
|
+
outline: "none",
|
|
610
|
+
boxSizing: "border-box"
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
) }),
|
|
614
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: 12 }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
615
|
+
"input",
|
|
616
|
+
{
|
|
617
|
+
type: "email",
|
|
618
|
+
placeholder: "Your email *",
|
|
619
|
+
value: offlineForm.email,
|
|
620
|
+
onChange: (e) => setOfflineForm((prev) => ({ ...prev, email: e.target.value })),
|
|
621
|
+
required: true,
|
|
622
|
+
style: {
|
|
623
|
+
width: "100%",
|
|
624
|
+
padding: "10px 12px",
|
|
625
|
+
borderRadius: 8,
|
|
626
|
+
border: "1px solid #e5e7eb",
|
|
627
|
+
fontSize: 14,
|
|
628
|
+
outline: "none",
|
|
629
|
+
boxSizing: "border-box"
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
) }),
|
|
633
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: 12 }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
634
|
+
"input",
|
|
635
|
+
{
|
|
636
|
+
type: "tel",
|
|
637
|
+
placeholder: "Phone (optional)",
|
|
638
|
+
value: offlineForm.phone,
|
|
639
|
+
onChange: (e) => setOfflineForm((prev) => ({ ...prev, phone: e.target.value })),
|
|
640
|
+
style: {
|
|
641
|
+
width: "100%",
|
|
642
|
+
padding: "10px 12px",
|
|
643
|
+
borderRadius: 8,
|
|
644
|
+
border: "1px solid #e5e7eb",
|
|
645
|
+
fontSize: 14,
|
|
646
|
+
outline: "none",
|
|
647
|
+
boxSizing: "border-box"
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
) }),
|
|
651
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: 16 }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
652
|
+
"textarea",
|
|
653
|
+
{
|
|
654
|
+
placeholder: "How can we help? *",
|
|
655
|
+
value: offlineForm.message,
|
|
656
|
+
onChange: (e) => setOfflineForm((prev) => ({ ...prev, message: e.target.value })),
|
|
657
|
+
required: true,
|
|
658
|
+
rows: 4,
|
|
659
|
+
style: {
|
|
660
|
+
width: "100%",
|
|
661
|
+
padding: "10px 12px",
|
|
662
|
+
borderRadius: 8,
|
|
663
|
+
border: "1px solid #e5e7eb",
|
|
664
|
+
fontSize: 14,
|
|
665
|
+
outline: "none",
|
|
666
|
+
resize: "vertical",
|
|
667
|
+
boxSizing: "border-box"
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
) }),
|
|
671
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
672
|
+
"button",
|
|
673
|
+
{
|
|
674
|
+
type: "submit",
|
|
675
|
+
disabled: isLoading,
|
|
676
|
+
style: {
|
|
677
|
+
width: "100%",
|
|
678
|
+
padding: "12px",
|
|
679
|
+
borderRadius: 8,
|
|
680
|
+
border: "none",
|
|
681
|
+
backgroundColor: buttonColor,
|
|
682
|
+
color: "white",
|
|
683
|
+
fontSize: 14,
|
|
684
|
+
fontWeight: 600,
|
|
685
|
+
cursor: isLoading ? "wait" : "pointer",
|
|
686
|
+
opacity: isLoading ? 0.7 : 1
|
|
687
|
+
},
|
|
688
|
+
children: isLoading ? "Sending..." : "Send Message"
|
|
689
|
+
}
|
|
690
|
+
)
|
|
691
|
+
] }) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
692
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
693
|
+
"div",
|
|
694
|
+
{
|
|
695
|
+
style: {
|
|
696
|
+
flex: 1,
|
|
697
|
+
overflowY: "auto",
|
|
698
|
+
padding: 16,
|
|
699
|
+
display: "flex",
|
|
700
|
+
flexDirection: "column",
|
|
701
|
+
gap: 12,
|
|
702
|
+
backgroundColor: "#f8f9fa"
|
|
703
|
+
},
|
|
704
|
+
children: [
|
|
705
|
+
messages.map((message) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
706
|
+
"div",
|
|
707
|
+
{
|
|
708
|
+
style: {
|
|
709
|
+
display: "flex",
|
|
710
|
+
justifyContent: message.role === "user" ? "flex-end" : "flex-start"
|
|
711
|
+
},
|
|
712
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
713
|
+
"div",
|
|
714
|
+
{
|
|
715
|
+
style: {
|
|
716
|
+
maxWidth: "80%",
|
|
717
|
+
padding: message.role === "system" ? "8px 12px" : "10px 14px",
|
|
718
|
+
borderRadius: message.role === "user" ? "16px 16px 4px 16px" : message.role === "system" ? "8px" : "16px 16px 16px 4px",
|
|
719
|
+
backgroundColor: message.role === "user" ? buttonColor : message.role === "system" ? "#e5e7eb" : "#ffffff",
|
|
720
|
+
color: message.role === "user" ? "white" : message.role === "system" ? "#666" : "#1a1a1a",
|
|
721
|
+
boxShadow: message.role === "system" ? "none" : "0 1px 2px rgba(0,0,0,0.1)",
|
|
722
|
+
fontSize: message.role === "system" ? 13 : 14,
|
|
723
|
+
fontStyle: message.role === "system" ? "italic" : "normal",
|
|
724
|
+
lineHeight: 1.5,
|
|
725
|
+
whiteSpace: "pre-wrap",
|
|
726
|
+
wordBreak: "break-word"
|
|
727
|
+
},
|
|
728
|
+
children: [
|
|
729
|
+
message.agentName && message.role === "agent" && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 12, opacity: 0.7, marginBottom: 4 }, children: message.agentName }),
|
|
730
|
+
message.content,
|
|
731
|
+
message.attachments?.length ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: 8, display: "flex", flexDirection: "column", gap: 6 }, children: message.attachments.map((att, i) => att.mimeType?.startsWith("image/") ? /* @__PURE__ */ jsxRuntime.jsx("a", { href: att.url, target: "_blank", rel: "noopener noreferrer", style: { display: "block" }, children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: att.url, alt: att.name, style: { maxWidth: "100%", maxHeight: 200, borderRadius: 8, objectFit: "contain" } }) }, i) : /* @__PURE__ */ jsxRuntime.jsxs("a", { href: att.url, target: "_blank", rel: "noopener noreferrer", style: { fontSize: 13, wordBreak: "break-all" }, children: [
|
|
732
|
+
"\u{1F4CE} ",
|
|
733
|
+
att.name
|
|
734
|
+
] }, i)) }) : null,
|
|
735
|
+
message.suggestions?.length ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", flexWrap: "wrap", gap: 6, marginTop: 8 }, children: message.suggestions.map((s, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
736
|
+
"button",
|
|
737
|
+
{
|
|
738
|
+
type: "button",
|
|
739
|
+
onClick: () => {
|
|
740
|
+
setInputValue(s);
|
|
741
|
+
inputRef.current?.focus();
|
|
742
|
+
},
|
|
743
|
+
style: {
|
|
744
|
+
padding: "6px 12px",
|
|
745
|
+
borderRadius: 16,
|
|
746
|
+
border: `1px solid ${buttonColor}`,
|
|
747
|
+
backgroundColor: "rgba(255,255,255,0.9)",
|
|
748
|
+
color: buttonColor,
|
|
749
|
+
fontSize: 13,
|
|
750
|
+
cursor: "pointer"
|
|
751
|
+
},
|
|
752
|
+
children: s
|
|
753
|
+
},
|
|
754
|
+
i
|
|
755
|
+
)) }) : null,
|
|
756
|
+
message.sendFailed && lastFailedSend && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: 8 }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
757
|
+
"button",
|
|
758
|
+
{
|
|
759
|
+
type: "button",
|
|
760
|
+
onClick: retryFailedSend,
|
|
761
|
+
style: {
|
|
762
|
+
padding: "6px 12px",
|
|
763
|
+
borderRadius: 6,
|
|
764
|
+
border: "1px solid #ef4444",
|
|
765
|
+
backgroundColor: "#fef2f2",
|
|
766
|
+
color: "#dc2626",
|
|
767
|
+
fontSize: 13,
|
|
768
|
+
cursor: "pointer"
|
|
769
|
+
},
|
|
770
|
+
children: "Retry send"
|
|
771
|
+
}
|
|
772
|
+
) }),
|
|
773
|
+
message.content.includes("speak with") && /* @__PURE__ */ jsxRuntime.jsx(
|
|
774
|
+
"button",
|
|
775
|
+
{
|
|
776
|
+
onClick: requestHandoff,
|
|
777
|
+
style: {
|
|
778
|
+
display: "block",
|
|
779
|
+
marginTop: 8,
|
|
780
|
+
padding: "6px 12px",
|
|
781
|
+
borderRadius: 6,
|
|
782
|
+
border: `1px solid ${buttonColor}`,
|
|
783
|
+
backgroundColor: "transparent",
|
|
784
|
+
color: buttonColor,
|
|
785
|
+
fontSize: 13,
|
|
786
|
+
cursor: "pointer"
|
|
787
|
+
},
|
|
788
|
+
children: "Talk to a person"
|
|
789
|
+
}
|
|
790
|
+
)
|
|
791
|
+
]
|
|
792
|
+
}
|
|
793
|
+
)
|
|
794
|
+
},
|
|
795
|
+
message.id
|
|
796
|
+
)),
|
|
797
|
+
(isLoading || agentTyping) && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", justifyContent: "flex-start" }, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
798
|
+
"div",
|
|
799
|
+
{
|
|
800
|
+
style: {
|
|
801
|
+
padding: "10px 14px",
|
|
802
|
+
borderRadius: "16px 16px 16px 4px",
|
|
803
|
+
backgroundColor: "#ffffff",
|
|
804
|
+
boxShadow: "0 1px 2px rgba(0,0,0,0.1)",
|
|
805
|
+
display: "flex",
|
|
806
|
+
gap: 4
|
|
807
|
+
},
|
|
808
|
+
children: [
|
|
809
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { animation: "chatDot 1.4s infinite ease-in-out", animationDelay: "0s" }, children: "\u25CF" }),
|
|
810
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { animation: "chatDot 1.4s infinite ease-in-out", animationDelay: "0.2s" }, children: "\u25CF" }),
|
|
811
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { animation: "chatDot 1.4s infinite ease-in-out", animationDelay: "0.4s" }, children: "\u25CF" })
|
|
812
|
+
]
|
|
813
|
+
}
|
|
814
|
+
) }),
|
|
815
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: messagesEndRef })
|
|
816
|
+
]
|
|
817
|
+
}
|
|
818
|
+
),
|
|
819
|
+
lastFailedSend && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { padding: "8px 12px", backgroundColor: "#fef2f2", borderTop: "1px solid #fecaca", display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8 }, children: [
|
|
820
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: 13, color: "#dc2626" }, children: "Failed to send" }),
|
|
821
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: retryFailedSend, style: { padding: "4px 10px", borderRadius: 6, border: "1px solid #dc2626", background: "#fff", color: "#dc2626", fontSize: 12, cursor: "pointer" }, children: "Retry" })
|
|
822
|
+
] }),
|
|
823
|
+
/* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit: handleSubmit, style: { padding: 12, borderTop: "1px solid #e5e7eb", backgroundColor: "#ffffff" }, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: 8 }, children: [
|
|
824
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
825
|
+
"input",
|
|
826
|
+
{
|
|
827
|
+
ref: inputRef,
|
|
828
|
+
type: "text",
|
|
829
|
+
value: inputValue,
|
|
830
|
+
onChange: (e) => {
|
|
831
|
+
setInputValue(e.target.value);
|
|
832
|
+
handleTyping();
|
|
833
|
+
},
|
|
834
|
+
onKeyDown: handleKeyDown,
|
|
835
|
+
placeholder: "Type a message...",
|
|
836
|
+
disabled: isLoading,
|
|
837
|
+
style: {
|
|
838
|
+
flex: 1,
|
|
839
|
+
padding: "10px 14px",
|
|
840
|
+
borderRadius: 24,
|
|
841
|
+
border: "1px solid #e5e7eb",
|
|
842
|
+
fontSize: 14,
|
|
843
|
+
outline: "none",
|
|
844
|
+
transition: "border-color 0.2s"
|
|
845
|
+
},
|
|
846
|
+
onFocus: (e) => e.currentTarget.style.borderColor = buttonColor,
|
|
847
|
+
onBlur: (e) => e.currentTarget.style.borderColor = "#e5e7eb"
|
|
848
|
+
}
|
|
849
|
+
),
|
|
850
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
851
|
+
"button",
|
|
852
|
+
{
|
|
853
|
+
type: "submit",
|
|
854
|
+
disabled: !inputValue.trim() || isLoading,
|
|
855
|
+
style: {
|
|
856
|
+
width: 40,
|
|
857
|
+
height: 40,
|
|
858
|
+
borderRadius: "50%",
|
|
859
|
+
border: "none",
|
|
860
|
+
backgroundColor: (inputValue.trim() || pendingFiles.length) && !isLoading ? buttonColor : "#e5e7eb",
|
|
861
|
+
color: "white",
|
|
862
|
+
cursor: inputValue.trim() && !isLoading ? "pointer" : "not-allowed",
|
|
863
|
+
display: "flex",
|
|
864
|
+
alignItems: "center",
|
|
865
|
+
justifyContent: "center",
|
|
866
|
+
transition: "background-color 0.2s"
|
|
867
|
+
},
|
|
868
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" }) })
|
|
869
|
+
}
|
|
870
|
+
)
|
|
871
|
+
] }) })
|
|
872
|
+
] }),
|
|
873
|
+
/* @__PURE__ */ jsxRuntime.jsx("style", { children: `
|
|
874
|
+
@keyframes chatSlideUp {
|
|
875
|
+
from {
|
|
876
|
+
opacity: 0;
|
|
877
|
+
transform: translateY(20px);
|
|
878
|
+
}
|
|
879
|
+
to {
|
|
880
|
+
opacity: 1;
|
|
881
|
+
transform: translateY(0);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
@keyframes chatDot {
|
|
885
|
+
0%, 80%, 100% {
|
|
886
|
+
opacity: 0.3;
|
|
887
|
+
}
|
|
888
|
+
40% {
|
|
889
|
+
opacity: 1;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
` })
|
|
893
|
+
]
|
|
894
|
+
}
|
|
895
|
+
);
|
|
896
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
897
|
+
ChatPopup,
|
|
898
|
+
ChatButton
|
|
899
|
+
] });
|
|
900
|
+
}
|
|
901
|
+
function adjustColor(hex, amount) {
|
|
902
|
+
const num = parseInt(hex.replace("#", ""), 16);
|
|
903
|
+
const r = Math.min(255, Math.max(0, (num >> 16) + amount));
|
|
904
|
+
const g = Math.min(255, Math.max(0, (num >> 8 & 255) + amount));
|
|
905
|
+
const b = Math.min(255, Math.max(0, (num & 255) + amount));
|
|
906
|
+
return `#${(1 << 24 | r << 16 | g << 8 | b).toString(16).slice(1)}`;
|
|
907
|
+
}
|
|
908
|
+
function handleAction(action, node, onClose, onAction) {
|
|
909
|
+
if (!action?.action || action.action === "none") return;
|
|
910
|
+
if (onAction) {
|
|
911
|
+
onAction(action, node);
|
|
912
|
+
}
|
|
913
|
+
switch (action.action) {
|
|
914
|
+
case "link":
|
|
915
|
+
if (action.url) {
|
|
916
|
+
if (action.newTab) {
|
|
917
|
+
window.open(action.url, "_blank", "noopener,noreferrer");
|
|
918
|
+
} else {
|
|
919
|
+
window.location.href = action.url;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
break;
|
|
923
|
+
case "scroll":
|
|
924
|
+
if (action.target) {
|
|
925
|
+
const element = document.querySelector(action.target);
|
|
926
|
+
element?.scrollIntoView({ behavior: "smooth" });
|
|
927
|
+
}
|
|
928
|
+
break;
|
|
929
|
+
case "close":
|
|
930
|
+
onClose?.();
|
|
931
|
+
break;
|
|
932
|
+
case "copy":
|
|
933
|
+
if (action.text) {
|
|
934
|
+
navigator.clipboard.writeText(action.text).catch(console.error);
|
|
935
|
+
}
|
|
936
|
+
break;
|
|
937
|
+
case "share":
|
|
938
|
+
if (navigator.share) {
|
|
939
|
+
navigator.share({
|
|
940
|
+
title: document.title,
|
|
941
|
+
url: window.location.href
|
|
942
|
+
}).catch(console.error);
|
|
943
|
+
}
|
|
944
|
+
break;
|
|
945
|
+
case "download":
|
|
946
|
+
if (action.url) {
|
|
947
|
+
const a = document.createElement("a");
|
|
948
|
+
a.href = action.url;
|
|
949
|
+
a.download = "";
|
|
950
|
+
a.click();
|
|
951
|
+
}
|
|
952
|
+
break;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
var animationKeyframes = `
|
|
956
|
+
@keyframes engageFadeIn { from { opacity: 0; } to { opacity: 1; } }
|
|
957
|
+
@keyframes engageFadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
|
|
958
|
+
@keyframes engageFadeInDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
|
|
959
|
+
@keyframes engageSlideInLeft { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }
|
|
960
|
+
@keyframes engageSlideInRight { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
|
|
961
|
+
@keyframes engageSlideInUp { from { opacity: 0; transform: translateY(100%); } to { opacity: 1; transform: translateY(0); } }
|
|
962
|
+
@keyframes engageScaleIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
|
|
963
|
+
@keyframes engageBounceIn { 0% { opacity: 0; transform: scale(0.3); } 50% { transform: scale(1.05); } 70% { transform: scale(0.9); } 100% { opacity: 1; transform: scale(1); } }
|
|
964
|
+
`;
|
|
965
|
+
function getAnimationStyle(animation, delay, duration) {
|
|
966
|
+
if (!animation || animation === "none") return {};
|
|
967
|
+
const animationMap = {
|
|
968
|
+
fadeIn: "engageFadeIn",
|
|
969
|
+
fadeInUp: "engageFadeInUp",
|
|
970
|
+
fadeInDown: "engageFadeInDown",
|
|
971
|
+
slideInLeft: "engageSlideInLeft",
|
|
972
|
+
slideInRight: "engageSlideInRight",
|
|
973
|
+
slideInUp: "engageSlideInUp",
|
|
974
|
+
scaleIn: "engageScaleIn",
|
|
975
|
+
bounceIn: "engageBounceIn"
|
|
976
|
+
};
|
|
977
|
+
const animationName = animationMap[animation];
|
|
978
|
+
if (!animationName) return {};
|
|
979
|
+
return {
|
|
980
|
+
animation: `${animationName} ${duration || 300}ms ease-out ${delay || 0}ms forwards`,
|
|
981
|
+
opacity: 0
|
|
982
|
+
// Start invisible, animation will show it
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
function NodeRenderer({ node, onClose, onAction, context }) {
|
|
986
|
+
const [isHovered, setIsHovered] = React2.useState(false);
|
|
987
|
+
const { type, props = {}, style = {}, children } = node;
|
|
988
|
+
const computedStyle = { ...style };
|
|
989
|
+
if (props.animation) {
|
|
990
|
+
Object.assign(computedStyle, getAnimationStyle(
|
|
991
|
+
props.animation,
|
|
992
|
+
props.animationDelay,
|
|
993
|
+
props.animationDuration
|
|
994
|
+
));
|
|
995
|
+
}
|
|
996
|
+
if (isHovered) {
|
|
997
|
+
if (props.hoverScale && props.hoverScale !== "none") {
|
|
998
|
+
computedStyle.transform = `scale(${props.hoverScale})`;
|
|
999
|
+
computedStyle.transition = "transform 0.2s ease";
|
|
1000
|
+
}
|
|
1001
|
+
if (props.hoverShadow && props.hoverShadow !== "none") {
|
|
1002
|
+
const shadowMap = {
|
|
1003
|
+
sm: "0 1px 2px 0 rgb(0 0 0 / 0.05)",
|
|
1004
|
+
md: "0 4px 6px -1px rgb(0 0 0 / 0.1)",
|
|
1005
|
+
lg: "0 10px 15px -3px rgb(0 0 0 / 0.1)"
|
|
1006
|
+
};
|
|
1007
|
+
computedStyle.boxShadow = shadowMap[props.hoverShadow];
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
const eventHandlers = {
|
|
1011
|
+
onMouseEnter: () => setIsHovered(true),
|
|
1012
|
+
onMouseLeave: () => setIsHovered(false)
|
|
1013
|
+
};
|
|
1014
|
+
if (props.onClick) {
|
|
1015
|
+
eventHandlers.onClick = (e) => {
|
|
1016
|
+
e.preventDefault();
|
|
1017
|
+
handleAction(props.onClick, node, onClose, onAction);
|
|
1018
|
+
};
|
|
1019
|
+
computedStyle.cursor = "pointer";
|
|
1020
|
+
}
|
|
1021
|
+
const renderedChildren = children?.map((child) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1022
|
+
NodeRenderer,
|
|
1023
|
+
{
|
|
1024
|
+
node: child,
|
|
1025
|
+
onClose,
|
|
1026
|
+
onAction,
|
|
1027
|
+
context
|
|
1028
|
+
},
|
|
1029
|
+
child.id
|
|
1030
|
+
));
|
|
1031
|
+
switch (type) {
|
|
1032
|
+
case "Container":
|
|
1033
|
+
case "Box":
|
|
1034
|
+
case "Section":
|
|
1035
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: computedStyle, ...eventHandlers, children: renderedChildren });
|
|
1036
|
+
case "Text":
|
|
1037
|
+
return /* @__PURE__ */ jsxRuntime.jsx("p", { style: computedStyle, ...eventHandlers, children: resolveText(props.text, context) });
|
|
1038
|
+
case "Heading":
|
|
1039
|
+
const HeadingTag = `h${props.level || 2}`;
|
|
1040
|
+
return React2.createElement(
|
|
1041
|
+
HeadingTag,
|
|
1042
|
+
{ style: computedStyle, ...eventHandlers },
|
|
1043
|
+
resolveText(props.text, context)
|
|
1044
|
+
);
|
|
1045
|
+
case "Button":
|
|
1046
|
+
case "BookingButton":
|
|
1047
|
+
case "BuyNow":
|
|
1048
|
+
case "AddToCart":
|
|
1049
|
+
case "EventRSVP":
|
|
1050
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1051
|
+
"button",
|
|
1052
|
+
{
|
|
1053
|
+
style: computedStyle,
|
|
1054
|
+
...eventHandlers,
|
|
1055
|
+
type: "button",
|
|
1056
|
+
children: resolveText(props.text || props.label, context) || "Button"
|
|
1057
|
+
}
|
|
1058
|
+
);
|
|
1059
|
+
case "Image":
|
|
1060
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1061
|
+
"img",
|
|
1062
|
+
{
|
|
1063
|
+
src: props.src,
|
|
1064
|
+
alt: props.alt || "",
|
|
1065
|
+
style: computedStyle,
|
|
1066
|
+
...eventHandlers
|
|
1067
|
+
}
|
|
1068
|
+
);
|
|
1069
|
+
case "Link":
|
|
1070
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1071
|
+
"a",
|
|
1072
|
+
{
|
|
1073
|
+
href: props.href || "#",
|
|
1074
|
+
target: props.newTab ? "_blank" : void 0,
|
|
1075
|
+
rel: props.newTab ? "noopener noreferrer" : void 0,
|
|
1076
|
+
style: computedStyle,
|
|
1077
|
+
...eventHandlers,
|
|
1078
|
+
children: resolveText(props.text, context) || renderedChildren
|
|
1079
|
+
}
|
|
1080
|
+
);
|
|
1081
|
+
case "Input":
|
|
1082
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1083
|
+
"input",
|
|
1084
|
+
{
|
|
1085
|
+
type: props.inputType || "text",
|
|
1086
|
+
placeholder: props.placeholder,
|
|
1087
|
+
style: computedStyle,
|
|
1088
|
+
...eventHandlers
|
|
1089
|
+
}
|
|
1090
|
+
);
|
|
1091
|
+
case "Divider":
|
|
1092
|
+
return /* @__PURE__ */ jsxRuntime.jsx("hr", { style: { border: "none", borderTop: "1px solid #e5e7eb", ...computedStyle } });
|
|
1093
|
+
case "Spacer":
|
|
1094
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { ...computedStyle, width: props.width, height: props.height } });
|
|
1095
|
+
case "Icon":
|
|
1096
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { style: computedStyle, ...eventHandlers, children: props.icon || "\u2605" });
|
|
1097
|
+
case "FormEmbed":
|
|
1098
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1099
|
+
"div",
|
|
1100
|
+
{
|
|
1101
|
+
style: computedStyle,
|
|
1102
|
+
"data-engage-form": props.form_id,
|
|
1103
|
+
...eventHandlers,
|
|
1104
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { padding: "16px", background: "#f5f5f5", borderRadius: "8px", textAlign: "center" }, children: [
|
|
1105
|
+
"Form: ",
|
|
1106
|
+
props.form_id || "Not configured"
|
|
1107
|
+
] })
|
|
1108
|
+
}
|
|
1109
|
+
);
|
|
1110
|
+
case "ProductCard":
|
|
1111
|
+
case "EventCard":
|
|
1112
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1113
|
+
"div",
|
|
1114
|
+
{
|
|
1115
|
+
style: computedStyle,
|
|
1116
|
+
"data-engage-offering": props.offering_id,
|
|
1117
|
+
...eventHandlers,
|
|
1118
|
+
children: renderedChildren
|
|
1119
|
+
}
|
|
1120
|
+
);
|
|
1121
|
+
default:
|
|
1122
|
+
console.warn(`[DesignRenderer] Unknown node type: ${type}`);
|
|
1123
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: computedStyle, ...eventHandlers, children: renderedChildren });
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
function resolveText(text, context) {
|
|
1127
|
+
if (!text) return "";
|
|
1128
|
+
if (!context) return text;
|
|
1129
|
+
return text.replace(/\{\{(\w+(?:\.\w+)*)\}\}/g, (match, path) => {
|
|
1130
|
+
const value = getNestedValue(context, path);
|
|
1131
|
+
return value !== void 0 ? String(value) : match;
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
function getNestedValue(obj, path) {
|
|
1135
|
+
return path.split(".").reduce((acc, key) => acc?.[key], obj);
|
|
1136
|
+
}
|
|
1137
|
+
function DesignRenderer({
|
|
1138
|
+
design,
|
|
1139
|
+
onClose,
|
|
1140
|
+
onAction,
|
|
1141
|
+
context
|
|
1142
|
+
}) {
|
|
1143
|
+
React2__default.default.useEffect(() => {
|
|
1144
|
+
if (typeof document === "undefined") return;
|
|
1145
|
+
const styleId = "engage-design-renderer-animations";
|
|
1146
|
+
if (!document.getElementById(styleId)) {
|
|
1147
|
+
const styleSheet = document.createElement("style");
|
|
1148
|
+
styleSheet.id = styleId;
|
|
1149
|
+
styleSheet.textContent = animationKeyframes;
|
|
1150
|
+
document.head.appendChild(styleSheet);
|
|
1151
|
+
}
|
|
1152
|
+
}, []);
|
|
1153
|
+
const rootStyle = {
|
|
1154
|
+
...design.style
|
|
1155
|
+
};
|
|
1156
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: rootStyle, "data-engage-design": design.id, children: design.children?.map((node) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1157
|
+
NodeRenderer,
|
|
1158
|
+
{
|
|
1159
|
+
node,
|
|
1160
|
+
onClose,
|
|
1161
|
+
onAction,
|
|
1162
|
+
context
|
|
1163
|
+
},
|
|
1164
|
+
node.id
|
|
1165
|
+
)) });
|
|
1166
|
+
}
|
|
1167
|
+
function getApiConfig2() {
|
|
1168
|
+
const apiUrl = typeof window !== "undefined" ? window.__SITE_KIT_API_URL__ || "https://api.uptrademedia.com" : "https://api.uptrademedia.com";
|
|
1169
|
+
const apiKey = typeof window !== "undefined" ? window.__SITE_KIT_API_KEY__ : void 0;
|
|
1170
|
+
return { apiUrl, apiKey };
|
|
1171
|
+
}
|
|
1172
|
+
function EngageWidget({
|
|
1173
|
+
apiUrl: propApiUrl,
|
|
1174
|
+
apiKey: propApiKey,
|
|
1175
|
+
position = "bottom-right",
|
|
1176
|
+
zIndex = 9999,
|
|
1177
|
+
chatEnabled = true,
|
|
1178
|
+
debug = false
|
|
1179
|
+
}) {
|
|
1180
|
+
const pathname = navigation.usePathname();
|
|
1181
|
+
const [elements, setElements] = React2.useState([]);
|
|
1182
|
+
const [activeElements, setActiveElements] = React2.useState([]);
|
|
1183
|
+
const [dismissedElements, setDismissedElements] = React2.useState(/* @__PURE__ */ new Set());
|
|
1184
|
+
React2.useEffect(() => {
|
|
1185
|
+
async function loadElements() {
|
|
1186
|
+
const { apiUrl: globalApiUrl, apiKey: globalApiKey } = getApiConfig2();
|
|
1187
|
+
const apiUrl = propApiUrl || globalApiUrl;
|
|
1188
|
+
const apiKey = propApiKey || globalApiKey;
|
|
1189
|
+
if (!apiKey) {
|
|
1190
|
+
if (debug) console.warn("[Engage] No API key configured");
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
try {
|
|
1194
|
+
const response = await fetch(`${apiUrl}/api/public/engage/elements`, {
|
|
1195
|
+
method: "POST",
|
|
1196
|
+
headers: {
|
|
1197
|
+
"Content-Type": "application/json",
|
|
1198
|
+
"x-api-key": apiKey
|
|
1199
|
+
},
|
|
1200
|
+
body: JSON.stringify({})
|
|
1201
|
+
});
|
|
1202
|
+
if (!response.ok) {
|
|
1203
|
+
if (debug) console.error("[Engage] Error loading elements:", response.statusText);
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
const data = await response.json();
|
|
1207
|
+
if (debug) console.log("[Engage] Loaded elements:", data.elements);
|
|
1208
|
+
setElements(data.elements || []);
|
|
1209
|
+
} catch (error) {
|
|
1210
|
+
if (debug) console.error("[Engage] Error loading elements:", error);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
loadElements();
|
|
1214
|
+
}, [propApiUrl, propApiKey, debug]);
|
|
1215
|
+
React2.useEffect(() => {
|
|
1216
|
+
if (!elements.length) return;
|
|
1217
|
+
const checkElement = (element) => {
|
|
1218
|
+
if (dismissedElements.has(element.id)) return false;
|
|
1219
|
+
if (element.targeting?.pages) {
|
|
1220
|
+
const { include, exclude } = element.targeting.pages;
|
|
1221
|
+
if (exclude?.some((p) => matchPath(pathname, p))) return false;
|
|
1222
|
+
if (include && !include.some((p) => matchPath(pathname, p))) return false;
|
|
1223
|
+
}
|
|
1224
|
+
if (element.targeting?.devices) {
|
|
1225
|
+
const device = getDeviceType();
|
|
1226
|
+
if (!element.targeting.devices.includes(device)) return false;
|
|
1227
|
+
}
|
|
1228
|
+
if (element.trigger?.frequency) {
|
|
1229
|
+
const { type, days } = element.trigger.frequency;
|
|
1230
|
+
const key = `_engage_${element.id}`;
|
|
1231
|
+
if (type === "once") {
|
|
1232
|
+
if (localStorage.getItem(key)) return false;
|
|
1233
|
+
} else if (type === "once-per-session") {
|
|
1234
|
+
if (sessionStorage.getItem(key)) return false;
|
|
1235
|
+
} else if (type === "every-n-days" && days) {
|
|
1236
|
+
const lastShown = localStorage.getItem(key);
|
|
1237
|
+
if (lastShown) {
|
|
1238
|
+
const elapsed = Date.now() - parseInt(lastShown, 10);
|
|
1239
|
+
if (elapsed < days * 24 * 60 * 60 * 1e3) return false;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
return true;
|
|
1244
|
+
};
|
|
1245
|
+
const eligible = elements.filter(checkElement);
|
|
1246
|
+
if (debug) console.log("[Engage] Eligible elements:", eligible);
|
|
1247
|
+
eligible.forEach((element) => {
|
|
1248
|
+
const trigger = element.trigger;
|
|
1249
|
+
if (trigger?.type === "immediate" || !trigger?.type) {
|
|
1250
|
+
setActiveElements((prev) => [...prev, element.id]);
|
|
1251
|
+
} else if (trigger?.type === "delay" && trigger.delay) {
|
|
1252
|
+
setTimeout(() => {
|
|
1253
|
+
setActiveElements((prev) => [...prev, element.id]);
|
|
1254
|
+
}, trigger.delay * 1e3);
|
|
1255
|
+
} else if (trigger?.type === "exit-intent") {
|
|
1256
|
+
const handleMouseLeave = (e) => {
|
|
1257
|
+
if (e.clientY < 10) {
|
|
1258
|
+
setActiveElements((prev) => [...prev, element.id]);
|
|
1259
|
+
document.removeEventListener("mouseleave", handleMouseLeave);
|
|
1260
|
+
}
|
|
1261
|
+
};
|
|
1262
|
+
document.addEventListener("mouseleave", handleMouseLeave);
|
|
1263
|
+
} else if (trigger?.type === "scroll" && trigger.scrollPercentage) {
|
|
1264
|
+
const handleScroll = () => {
|
|
1265
|
+
const scrollPercent = window.scrollY / (document.body.scrollHeight - window.innerHeight) * 100;
|
|
1266
|
+
if (scrollPercent >= (trigger.scrollPercentage || 50)) {
|
|
1267
|
+
setActiveElements((prev) => [...prev, element.id]);
|
|
1268
|
+
window.removeEventListener("scroll", handleScroll);
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
window.addEventListener("scroll", handleScroll);
|
|
1272
|
+
}
|
|
1273
|
+
});
|
|
1274
|
+
}, [elements, pathname, dismissedElements, debug]);
|
|
1275
|
+
const handleDismiss = React2.useCallback((elementId) => {
|
|
1276
|
+
setDismissedElements((prev) => /* @__PURE__ */ new Set([...prev, elementId]));
|
|
1277
|
+
setActiveElements((prev) => prev.filter((id) => id !== elementId));
|
|
1278
|
+
const element = elements.find((e) => e.id === elementId);
|
|
1279
|
+
if (element?.trigger?.frequency) {
|
|
1280
|
+
const key = `_engage_${elementId}`;
|
|
1281
|
+
if (element.trigger.frequency.type === "once-per-session") {
|
|
1282
|
+
sessionStorage.setItem(key, "true");
|
|
1283
|
+
} else {
|
|
1284
|
+
localStorage.setItem(key, Date.now().toString());
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}, [elements]);
|
|
1288
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1289
|
+
activeElements.map((elementId) => {
|
|
1290
|
+
const element = elements.find((e) => e.id === elementId);
|
|
1291
|
+
if (!element) return null;
|
|
1292
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1293
|
+
EngageElementRenderer,
|
|
1294
|
+
{
|
|
1295
|
+
element,
|
|
1296
|
+
onDismiss: () => handleDismiss(element.id),
|
|
1297
|
+
zIndex
|
|
1298
|
+
},
|
|
1299
|
+
element.id
|
|
1300
|
+
);
|
|
1301
|
+
}),
|
|
1302
|
+
chatEnabled && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1303
|
+
ChatWidget,
|
|
1304
|
+
{
|
|
1305
|
+
projectId: propApiKey || "",
|
|
1306
|
+
config: {
|
|
1307
|
+
position,
|
|
1308
|
+
buttonColor: "#00afab"
|
|
1309
|
+
// Default teal, can be customized later
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
)
|
|
1313
|
+
] });
|
|
1314
|
+
}
|
|
1315
|
+
function EngageElementRenderer({
|
|
1316
|
+
element,
|
|
1317
|
+
onDismiss,
|
|
1318
|
+
zIndex
|
|
1319
|
+
}) {
|
|
1320
|
+
if (element.design_json) {
|
|
1321
|
+
if (element.type === "popup") {
|
|
1322
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1323
|
+
"div",
|
|
1324
|
+
{
|
|
1325
|
+
style: {
|
|
1326
|
+
position: "fixed",
|
|
1327
|
+
top: 0,
|
|
1328
|
+
left: 0,
|
|
1329
|
+
right: 0,
|
|
1330
|
+
bottom: 0,
|
|
1331
|
+
backgroundColor: "rgba(0,0,0,0.5)",
|
|
1332
|
+
display: "flex",
|
|
1333
|
+
alignItems: "center",
|
|
1334
|
+
justifyContent: "center",
|
|
1335
|
+
zIndex
|
|
1336
|
+
},
|
|
1337
|
+
onClick: onDismiss,
|
|
1338
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1339
|
+
DesignRenderer,
|
|
1340
|
+
{
|
|
1341
|
+
design: element.design_json,
|
|
1342
|
+
onClose: onDismiss,
|
|
1343
|
+
onAction: (action, node) => {
|
|
1344
|
+
console.log("[Engage] Action:", action, node);
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
) })
|
|
1348
|
+
}
|
|
1349
|
+
);
|
|
1350
|
+
}
|
|
1351
|
+
if (element.type === "bar") {
|
|
1352
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1353
|
+
"div",
|
|
1354
|
+
{
|
|
1355
|
+
style: {
|
|
1356
|
+
position: "fixed",
|
|
1357
|
+
top: 0,
|
|
1358
|
+
left: 0,
|
|
1359
|
+
right: 0,
|
|
1360
|
+
zIndex
|
|
1361
|
+
},
|
|
1362
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1363
|
+
DesignRenderer,
|
|
1364
|
+
{
|
|
1365
|
+
design: element.design_json,
|
|
1366
|
+
onClose: onDismiss,
|
|
1367
|
+
onAction: (action, node) => {
|
|
1368
|
+
console.log("[Engage] Action:", action, node);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
)
|
|
1372
|
+
}
|
|
1373
|
+
);
|
|
1374
|
+
}
|
|
1375
|
+
if (element.type === "nudge" || element.type === "slide-in") {
|
|
1376
|
+
const position = element.config?.position || "bottom-right";
|
|
1377
|
+
const positionStyles = {
|
|
1378
|
+
"bottom-right": { bottom: 20, right: 20 },
|
|
1379
|
+
"bottom-left": { bottom: 20, left: 20 },
|
|
1380
|
+
"top-right": { top: 20, right: 20 },
|
|
1381
|
+
"top-left": { top: 20, left: 20 }
|
|
1382
|
+
};
|
|
1383
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1384
|
+
"div",
|
|
1385
|
+
{
|
|
1386
|
+
style: {
|
|
1387
|
+
position: "fixed",
|
|
1388
|
+
zIndex,
|
|
1389
|
+
...positionStyles[position]
|
|
1390
|
+
},
|
|
1391
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1392
|
+
DesignRenderer,
|
|
1393
|
+
{
|
|
1394
|
+
design: element.design_json,
|
|
1395
|
+
onClose: onDismiss,
|
|
1396
|
+
onAction: (action, node) => {
|
|
1397
|
+
console.log("[Engage] Action:", action, node);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
)
|
|
1401
|
+
}
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1404
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1405
|
+
DesignRenderer,
|
|
1406
|
+
{
|
|
1407
|
+
design: element.design_json,
|
|
1408
|
+
onClose: onDismiss,
|
|
1409
|
+
onAction: (action, node) => {
|
|
1410
|
+
console.log("[Engage] Action:", action, node);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
if (element.type === "popup") {
|
|
1416
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1417
|
+
"div",
|
|
1418
|
+
{
|
|
1419
|
+
style: {
|
|
1420
|
+
position: "fixed",
|
|
1421
|
+
top: 0,
|
|
1422
|
+
left: 0,
|
|
1423
|
+
right: 0,
|
|
1424
|
+
bottom: 0,
|
|
1425
|
+
backgroundColor: "rgba(0,0,0,0.5)",
|
|
1426
|
+
display: "flex",
|
|
1427
|
+
alignItems: "center",
|
|
1428
|
+
justifyContent: "center",
|
|
1429
|
+
zIndex
|
|
1430
|
+
},
|
|
1431
|
+
onClick: onDismiss,
|
|
1432
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1433
|
+
"div",
|
|
1434
|
+
{
|
|
1435
|
+
style: {
|
|
1436
|
+
backgroundColor: "white",
|
|
1437
|
+
padding: 24,
|
|
1438
|
+
borderRadius: 8,
|
|
1439
|
+
maxWidth: 500,
|
|
1440
|
+
width: "90%"
|
|
1441
|
+
},
|
|
1442
|
+
onClick: (e) => e.stopPropagation(),
|
|
1443
|
+
children: [
|
|
1444
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1445
|
+
"button",
|
|
1446
|
+
{
|
|
1447
|
+
onClick: onDismiss,
|
|
1448
|
+
style: {
|
|
1449
|
+
position: "absolute",
|
|
1450
|
+
top: 8,
|
|
1451
|
+
right: 8,
|
|
1452
|
+
background: "none",
|
|
1453
|
+
border: "none",
|
|
1454
|
+
fontSize: 24,
|
|
1455
|
+
cursor: "pointer"
|
|
1456
|
+
},
|
|
1457
|
+
children: "\xD7"
|
|
1458
|
+
}
|
|
1459
|
+
),
|
|
1460
|
+
element.config?.title && /* @__PURE__ */ jsxRuntime.jsx("h2", { children: element.config.title }),
|
|
1461
|
+
element.config?.message && /* @__PURE__ */ jsxRuntime.jsx("p", { children: element.config.message })
|
|
1462
|
+
]
|
|
1463
|
+
}
|
|
1464
|
+
)
|
|
1465
|
+
}
|
|
1466
|
+
);
|
|
1467
|
+
}
|
|
1468
|
+
if (element.type === "bar") {
|
|
1469
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1470
|
+
"div",
|
|
1471
|
+
{
|
|
1472
|
+
style: {
|
|
1473
|
+
position: "fixed",
|
|
1474
|
+
top: 0,
|
|
1475
|
+
left: 0,
|
|
1476
|
+
right: 0,
|
|
1477
|
+
backgroundColor: element.config?.backgroundColor || "#3b82f6",
|
|
1478
|
+
color: element.config?.textColor || "white",
|
|
1479
|
+
padding: "12px 24px",
|
|
1480
|
+
display: "flex",
|
|
1481
|
+
alignItems: "center",
|
|
1482
|
+
justifyContent: "center",
|
|
1483
|
+
gap: 16,
|
|
1484
|
+
zIndex
|
|
1485
|
+
},
|
|
1486
|
+
children: [
|
|
1487
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: element.config?.message }),
|
|
1488
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1489
|
+
"button",
|
|
1490
|
+
{
|
|
1491
|
+
onClick: onDismiss,
|
|
1492
|
+
style: {
|
|
1493
|
+
background: "none",
|
|
1494
|
+
border: "none",
|
|
1495
|
+
color: "inherit",
|
|
1496
|
+
fontSize: 20,
|
|
1497
|
+
cursor: "pointer"
|
|
1498
|
+
},
|
|
1499
|
+
children: "\xD7"
|
|
1500
|
+
}
|
|
1501
|
+
)
|
|
1502
|
+
]
|
|
1503
|
+
}
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1506
|
+
return null;
|
|
1507
|
+
}
|
|
1508
|
+
function matchPath(pathname, pattern) {
|
|
1509
|
+
if (pattern.endsWith("*")) {
|
|
1510
|
+
return pathname.startsWith(pattern.slice(0, -1));
|
|
1511
|
+
}
|
|
1512
|
+
return pathname === pattern;
|
|
1513
|
+
}
|
|
1514
|
+
function getDeviceType() {
|
|
1515
|
+
if (typeof window === "undefined") return "desktop";
|
|
1516
|
+
const ua = navigator.userAgent;
|
|
1517
|
+
if (/tablet|ipad|playbook|silk/i.test(ua)) return "tablet";
|
|
1518
|
+
if (/mobile|iphone|ipod|android|blackberry|opera mini|iemobile/i.test(ua)) return "mobile";
|
|
1519
|
+
return "desktop";
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
exports.ChatWidget = ChatWidget;
|
|
1523
|
+
exports.DesignRenderer = DesignRenderer;
|
|
1524
|
+
exports.EngageWidget = EngageWidget;
|
|
1525
|
+
//# sourceMappingURL=chunk-FLZZOX44.js.map
|
|
1526
|
+
//# sourceMappingURL=chunk-FLZZOX44.js.map
|