@uptrademedia/site-kit 1.0.0 → 1.0.3
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/blog/index.js.map +1 -1
- package/dist/blog/index.mjs.map +1 -1
- package/dist/chunk-5R4R3WDP.js +1451 -0
- package/dist/chunk-5R4R3WDP.js.map +1 -0
- package/dist/{chunk-COI6GOX2.mjs → chunk-63JNO4QN.mjs} +3 -3
- package/dist/chunk-63JNO4QN.mjs.map +1 -0
- package/dist/chunk-6EXHT7PS.mjs +330 -0
- package/dist/chunk-6EXHT7PS.mjs.map +1 -0
- package/dist/{chunk-RV7H3I6J.js → chunk-ADHVEFWD.js} +68 -2
- package/dist/chunk-ADHVEFWD.js.map +1 -0
- package/dist/chunk-BGJLOJ7T.mjs +605 -0
- package/dist/chunk-BGJLOJ7T.mjs.map +1 -0
- package/dist/chunk-BZBJVG5Y.js +88 -0
- package/dist/chunk-BZBJVG5Y.js.map +1 -0
- package/dist/chunk-DRFTRTKV.js +809 -0
- package/dist/chunk-DRFTRTKV.js.map +1 -0
- package/dist/chunk-EL5QTAA3.mjs +805 -0
- package/dist/chunk-EL5QTAA3.mjs.map +1 -0
- package/dist/chunk-JG2K4S2I.js +997 -0
- package/dist/chunk-JG2K4S2I.js.map +1 -0
- package/dist/chunk-P7LGOKGI.mjs +981 -0
- package/dist/chunk-P7LGOKGI.mjs.map +1 -0
- package/dist/{chunk-3MUOUXHV.js → chunk-PYYEPAHL.js} +3 -3
- package/dist/chunk-PYYEPAHL.js.map +1 -0
- package/dist/chunk-QAYJV4KK.js +608 -0
- package/dist/chunk-QAYJV4KK.js.map +1 -0
- package/dist/{chunk-FEBYQGY4 2.mjs → chunk-SMUFNQLM.mjs} +67 -3
- package/dist/chunk-SMUFNQLM.mjs.map +1 -0
- package/dist/chunk-VDMZZL2O.mjs +83 -0
- package/dist/chunk-VDMZZL2O.mjs.map +1 -0
- package/dist/chunk-XFRPT5ZX.mjs +1449 -0
- package/dist/chunk-XFRPT5ZX.mjs.map +1 -0
- package/dist/chunk-YKMCG3DS.js +332 -0
- package/dist/chunk-YKMCG3DS.js.map +1 -0
- package/dist/commerce/index.js +38 -38
- package/dist/commerce/index.mjs +1 -1
- package/dist/engage/index.js +7 -40
- package/dist/engage/index.js.map +1 -1
- package/dist/engage/index.mjs +1 -41
- package/dist/engage/index.mjs.map +1 -1
- package/dist/forms/index.js +13 -5
- package/dist/forms/index.js.map +1 -1
- package/dist/forms/index.mjs +2 -2
- package/dist/forms/index.mjs.map +1 -1
- package/dist/{generators-7Y5ABRYV 2.mjs → generators-TO2FKJR6.mjs} +134 -3
- package/dist/generators-TO2FKJR6.mjs.map +1 -0
- package/dist/{generators-GWIYCA5M.js → generators-YZWIGHCO.js} +135 -2
- package/dist/generators-YZWIGHCO.js.map +1 -0
- package/dist/images/index.js +41 -0
- package/dist/images/index.js.map +1 -0
- package/dist/images/index.mjs +8 -0
- package/dist/images/index.mjs.map +1 -0
- package/dist/index.js +1355 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1242 -76
- package/dist/index.mjs.map +1 -1
- package/dist/redirects/index.js +25 -0
- package/dist/redirects/index.js.map +1 -0
- package/dist/redirects/index.mjs +4 -0
- package/dist/redirects/index.mjs.map +1 -0
- package/dist/{scanner-MF7P3CDE 2.mjs → scanner-AZV5I6US.mjs} +123 -4
- package/dist/scanner-AZV5I6US.mjs.map +1 -0
- package/dist/{scanner-NT6YG4TD 2.js → scanner-ETJAMIT7.js} +124 -3
- package/dist/scanner-ETJAMIT7.js.map +1 -0
- package/dist/setup/client.js +30 -0
- package/dist/setup/client.js.map +1 -0
- package/dist/setup/client.mjs +5 -0
- package/dist/setup/client.mjs.map +1 -0
- package/dist/setup/index.js +28 -1043
- package/dist/setup/index.js.map +1 -1
- package/dist/setup/index.mjs +3 -1043
- package/dist/setup/index.mjs.map +1 -1
- package/dist/setup/server.js +13 -0
- package/dist/setup/server.js.map +1 -0
- package/dist/setup/server.mjs +4 -0
- package/dist/setup/server.mjs.map +1 -0
- package/package.json +21 -1
- package/dist/chunk-3MUOUXHV.js.map +0 -1
- package/dist/chunk-4HVYXYQL 2.mjs +0 -255
- package/dist/chunk-4HVYXYQL.mjs +0 -255
- package/dist/chunk-4HVYXYQL.mjs.map +0 -1
- package/dist/chunk-COI6GOX2.mjs.map +0 -1
- package/dist/chunk-EQCVQC35.js 2.map +0 -1
- package/dist/chunk-FEBYQGY4.mjs +0 -251
- package/dist/chunk-FEBYQGY4.mjs.map +0 -1
- package/dist/chunk-NYKRE2FL 2.mjs +0 -31
- package/dist/chunk-NYKRE2FL.mjs 2.map +0 -1
- package/dist/chunk-RV7H3I6J.js 2.map +0 -1
- package/dist/chunk-RV7H3I6J.js.map +0 -1
- package/dist/chunk-TUKGA3UK.js +0 -257
- package/dist/chunk-TUKGA3UK.js 2.map +0 -1
- package/dist/chunk-TUKGA3UK.js.map +0 -1
- package/dist/generators-7Y5ABRYV.mjs +0 -161
- package/dist/generators-7Y5ABRYV.mjs 2.map +0 -1
- package/dist/generators-7Y5ABRYV.mjs.map +0 -1
- package/dist/generators-GWIYCA5M.js 2.map +0 -1
- package/dist/generators-GWIYCA5M.js.map +0 -1
- package/dist/index 2.mjs +0 -74
- package/dist/index.js 2.map +0 -1
- package/dist/migrator-V6KS75EA 2.mjs +0 -265
- package/dist/migrator-V6KS75EA.mjs 2.map +0 -1
- package/dist/migrator-XKM7YQCY.js 2.map +0 -1
- package/dist/scanner-MF7P3CDE.mjs +0 -14386
- package/dist/scanner-MF7P3CDE.mjs 2.map +0 -1
- package/dist/scanner-MF7P3CDE.mjs.map +0 -1
- package/dist/scanner-NT6YG4TD.js +0 -14397
- package/dist/scanner-NT6YG4TD.js 2.map +0 -1
- package/dist/scanner-NT6YG4TD.js.map +0 -1
- package/dist/web-vitals-BH55V7EJ.js 2.map +0 -1
- package/dist/web-vitals-RJYPWAR3 2.mjs +0 -241
- package/dist/web-vitals-RJYPWAR3.mjs 2.map +0 -1
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
2
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import { usePathname } from 'next/navigation';
|
|
4
|
+
|
|
5
|
+
// src/engage/ChatWidget.tsx
|
|
6
|
+
function getApiConfig() {
|
|
7
|
+
const signalUrl = typeof window !== "undefined" ? window.__SITE_KIT_SIGNAL_URL__ || "https://signal.uptrademedia.com" : "https://signal.uptrademedia.com";
|
|
8
|
+
const apiKey = typeof window !== "undefined" ? window.__SITE_KIT_API_KEY__ : void 0;
|
|
9
|
+
return { signalUrl, apiKey };
|
|
10
|
+
}
|
|
11
|
+
function ChatWidget({ projectId, config, signalApiUrl }) {
|
|
12
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
13
|
+
const [messages, setMessages] = useState([]);
|
|
14
|
+
const [inputValue, setInputValue] = useState("");
|
|
15
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
16
|
+
const [showWelcome, setShowWelcome] = useState(true);
|
|
17
|
+
const messagesEndRef = useRef(null);
|
|
18
|
+
const inputRef = useRef(null);
|
|
19
|
+
const position = config?.position || "bottom-right";
|
|
20
|
+
const buttonColor = config?.buttonColor || "#00afab";
|
|
21
|
+
const welcomeMessage = config?.welcomeMessage || "Hi! How can I help you today?";
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
24
|
+
}, [messages]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (isOpen && inputRef.current) {
|
|
27
|
+
inputRef.current.focus();
|
|
28
|
+
}
|
|
29
|
+
}, [isOpen]);
|
|
30
|
+
const handleToggle = useCallback(() => {
|
|
31
|
+
setIsOpen((prev) => !prev);
|
|
32
|
+
if (!isOpen && messages.length === 0) {
|
|
33
|
+
setMessages([{
|
|
34
|
+
id: "welcome",
|
|
35
|
+
role: "assistant",
|
|
36
|
+
content: welcomeMessage,
|
|
37
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
38
|
+
}]);
|
|
39
|
+
}
|
|
40
|
+
}, [isOpen, messages.length, welcomeMessage]);
|
|
41
|
+
const handleSubmit = useCallback(async (e) => {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
if (!inputValue.trim() || isLoading) return;
|
|
44
|
+
const userMessage = {
|
|
45
|
+
id: `user-${Date.now()}`,
|
|
46
|
+
role: "user",
|
|
47
|
+
content: inputValue.trim(),
|
|
48
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
49
|
+
};
|
|
50
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
51
|
+
setInputValue("");
|
|
52
|
+
setIsLoading(true);
|
|
53
|
+
setShowWelcome(false);
|
|
54
|
+
try {
|
|
55
|
+
const { signalUrl, apiKey } = getApiConfig();
|
|
56
|
+
const apiUrl = typeof window !== "undefined" ? window.__SITE_KIT_API_URL__ || "https://api.uptrademedia.com" : "https://api.uptrademedia.com";
|
|
57
|
+
const response = await fetch(`${apiUrl}/api/public/engage/chat`, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: {
|
|
60
|
+
"Content-Type": "application/json",
|
|
61
|
+
...apiKey && { "x-api-key": apiKey }
|
|
62
|
+
},
|
|
63
|
+
body: JSON.stringify({
|
|
64
|
+
message: userMessage.content,
|
|
65
|
+
projectId,
|
|
66
|
+
context: {
|
|
67
|
+
pageUrl: typeof window !== "undefined" ? window.location.href : "",
|
|
68
|
+
pageTitle: typeof document !== "undefined" ? document.title : ""
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
throw new Error("Failed to get response");
|
|
74
|
+
}
|
|
75
|
+
const data = await response.json();
|
|
76
|
+
const assistantMessage = {
|
|
77
|
+
id: `assistant-${Date.now()}`,
|
|
78
|
+
role: "assistant",
|
|
79
|
+
content: data.response || data.message || "I'm sorry, I couldn't process that request.",
|
|
80
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
81
|
+
};
|
|
82
|
+
setMessages((prev) => [...prev, assistantMessage]);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error("[ChatWidget] Error:", error);
|
|
85
|
+
const errorMessage = {
|
|
86
|
+
id: `error-${Date.now()}`,
|
|
87
|
+
role: "assistant",
|
|
88
|
+
content: "I'm sorry, I'm having trouble connecting right now. Please try again later.",
|
|
89
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
90
|
+
};
|
|
91
|
+
setMessages((prev) => [...prev, errorMessage]);
|
|
92
|
+
} finally {
|
|
93
|
+
setIsLoading(false);
|
|
94
|
+
}
|
|
95
|
+
}, [inputValue, isLoading, projectId, signalApiUrl]);
|
|
96
|
+
const handleKeyDown = useCallback((e) => {
|
|
97
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
handleSubmit(e);
|
|
100
|
+
}
|
|
101
|
+
}, [handleSubmit]);
|
|
102
|
+
const ChatButton = /* @__PURE__ */ jsx(
|
|
103
|
+
"button",
|
|
104
|
+
{
|
|
105
|
+
onClick: handleToggle,
|
|
106
|
+
"aria-label": isOpen ? "Close chat" : "Open chat",
|
|
107
|
+
style: {
|
|
108
|
+
position: "fixed",
|
|
109
|
+
[position === "bottom-left" ? "left" : "right"]: 20,
|
|
110
|
+
bottom: 20,
|
|
111
|
+
width: 60,
|
|
112
|
+
height: 60,
|
|
113
|
+
borderRadius: "50%",
|
|
114
|
+
backgroundColor: buttonColor,
|
|
115
|
+
border: "none",
|
|
116
|
+
display: "flex",
|
|
117
|
+
alignItems: "center",
|
|
118
|
+
justifyContent: "center",
|
|
119
|
+
cursor: "pointer",
|
|
120
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.25)",
|
|
121
|
+
transition: "transform 0.2s, box-shadow 0.2s",
|
|
122
|
+
zIndex: 9999
|
|
123
|
+
},
|
|
124
|
+
onMouseEnter: (e) => {
|
|
125
|
+
e.currentTarget.style.transform = "scale(1.05)";
|
|
126
|
+
e.currentTarget.style.boxShadow = "0 6px 16px rgba(0, 0, 0, 0.3)";
|
|
127
|
+
},
|
|
128
|
+
onMouseLeave: (e) => {
|
|
129
|
+
e.currentTarget.style.transform = "scale(1)";
|
|
130
|
+
e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.25)";
|
|
131
|
+
},
|
|
132
|
+
children: isOpen ? (
|
|
133
|
+
// Close icon (X)
|
|
134
|
+
/* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
135
|
+
/* @__PURE__ */ jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
136
|
+
/* @__PURE__ */ jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
137
|
+
] })
|
|
138
|
+
) : (
|
|
139
|
+
// Chat icon
|
|
140
|
+
/* @__PURE__ */ jsx("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ 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" }) })
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
const ChatPopup = isOpen && /* @__PURE__ */ jsxs(
|
|
145
|
+
"div",
|
|
146
|
+
{
|
|
147
|
+
style: {
|
|
148
|
+
position: "fixed",
|
|
149
|
+
[position === "bottom-left" ? "left" : "right"]: 20,
|
|
150
|
+
bottom: 90,
|
|
151
|
+
width: 380,
|
|
152
|
+
maxWidth: "calc(100vw - 40px)",
|
|
153
|
+
height: 500,
|
|
154
|
+
maxHeight: "calc(100vh - 120px)",
|
|
155
|
+
backgroundColor: "#ffffff",
|
|
156
|
+
borderRadius: 16,
|
|
157
|
+
boxShadow: "0 8px 32px rgba(0, 0, 0, 0.2)",
|
|
158
|
+
display: "flex",
|
|
159
|
+
flexDirection: "column",
|
|
160
|
+
overflow: "hidden",
|
|
161
|
+
zIndex: 9998,
|
|
162
|
+
animation: "chatSlideUp 0.3s ease-out"
|
|
163
|
+
},
|
|
164
|
+
children: [
|
|
165
|
+
/* @__PURE__ */ jsxs(
|
|
166
|
+
"div",
|
|
167
|
+
{
|
|
168
|
+
style: {
|
|
169
|
+
padding: "16px 20px",
|
|
170
|
+
background: `linear-gradient(135deg, ${buttonColor}, ${adjustColor(buttonColor, -20)})`,
|
|
171
|
+
color: "white",
|
|
172
|
+
display: "flex",
|
|
173
|
+
alignItems: "center",
|
|
174
|
+
gap: 12
|
|
175
|
+
},
|
|
176
|
+
children: [
|
|
177
|
+
/* @__PURE__ */ jsx(
|
|
178
|
+
"div",
|
|
179
|
+
{
|
|
180
|
+
style: {
|
|
181
|
+
width: 40,
|
|
182
|
+
height: 40,
|
|
183
|
+
borderRadius: "50%",
|
|
184
|
+
backgroundColor: "rgba(255,255,255,0.2)",
|
|
185
|
+
display: "flex",
|
|
186
|
+
alignItems: "center",
|
|
187
|
+
justifyContent: "center"
|
|
188
|
+
},
|
|
189
|
+
children: /* @__PURE__ */ jsx("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ 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" }) })
|
|
190
|
+
}
|
|
191
|
+
),
|
|
192
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
193
|
+
/* @__PURE__ */ jsx("div", { style: { fontWeight: 600, fontSize: 16 }, children: "Chat with us" }),
|
|
194
|
+
/* @__PURE__ */ jsx("div", { style: { fontSize: 13, opacity: 0.9 }, children: "We typically reply instantly" })
|
|
195
|
+
] })
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
),
|
|
199
|
+
/* @__PURE__ */ jsxs(
|
|
200
|
+
"div",
|
|
201
|
+
{
|
|
202
|
+
style: {
|
|
203
|
+
flex: 1,
|
|
204
|
+
overflowY: "auto",
|
|
205
|
+
padding: 16,
|
|
206
|
+
display: "flex",
|
|
207
|
+
flexDirection: "column",
|
|
208
|
+
gap: 12,
|
|
209
|
+
backgroundColor: "#f8f9fa"
|
|
210
|
+
},
|
|
211
|
+
children: [
|
|
212
|
+
messages.map((message) => /* @__PURE__ */ jsx(
|
|
213
|
+
"div",
|
|
214
|
+
{
|
|
215
|
+
style: {
|
|
216
|
+
display: "flex",
|
|
217
|
+
justifyContent: message.role === "user" ? "flex-end" : "flex-start"
|
|
218
|
+
},
|
|
219
|
+
children: /* @__PURE__ */ jsx(
|
|
220
|
+
"div",
|
|
221
|
+
{
|
|
222
|
+
style: {
|
|
223
|
+
maxWidth: "80%",
|
|
224
|
+
padding: "10px 14px",
|
|
225
|
+
borderRadius: message.role === "user" ? "16px 16px 4px 16px" : "16px 16px 16px 4px",
|
|
226
|
+
backgroundColor: message.role === "user" ? buttonColor : "#ffffff",
|
|
227
|
+
color: message.role === "user" ? "white" : "#1a1a1a",
|
|
228
|
+
boxShadow: "0 1px 2px rgba(0,0,0,0.1)",
|
|
229
|
+
fontSize: 14,
|
|
230
|
+
lineHeight: 1.5,
|
|
231
|
+
whiteSpace: "pre-wrap",
|
|
232
|
+
wordBreak: "break-word"
|
|
233
|
+
},
|
|
234
|
+
children: message.content
|
|
235
|
+
}
|
|
236
|
+
)
|
|
237
|
+
},
|
|
238
|
+
message.id
|
|
239
|
+
)),
|
|
240
|
+
isLoading && /* @__PURE__ */ jsx("div", { style: { display: "flex", justifyContent: "flex-start" }, children: /* @__PURE__ */ jsxs(
|
|
241
|
+
"div",
|
|
242
|
+
{
|
|
243
|
+
style: {
|
|
244
|
+
padding: "10px 14px",
|
|
245
|
+
borderRadius: "16px 16px 16px 4px",
|
|
246
|
+
backgroundColor: "#ffffff",
|
|
247
|
+
boxShadow: "0 1px 2px rgba(0,0,0,0.1)",
|
|
248
|
+
display: "flex",
|
|
249
|
+
gap: 4
|
|
250
|
+
},
|
|
251
|
+
children: [
|
|
252
|
+
/* @__PURE__ */ jsx("span", { style: { animation: "chatDot 1.4s infinite ease-in-out", animationDelay: "0s" }, children: "\u25CF" }),
|
|
253
|
+
/* @__PURE__ */ jsx("span", { style: { animation: "chatDot 1.4s infinite ease-in-out", animationDelay: "0.2s" }, children: "\u25CF" }),
|
|
254
|
+
/* @__PURE__ */ jsx("span", { style: { animation: "chatDot 1.4s infinite ease-in-out", animationDelay: "0.4s" }, children: "\u25CF" })
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
) }),
|
|
258
|
+
/* @__PURE__ */ jsx("div", { ref: messagesEndRef })
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
),
|
|
262
|
+
/* @__PURE__ */ jsx("form", { onSubmit: handleSubmit, style: { padding: 12, borderTop: "1px solid #e5e7eb", backgroundColor: "#ffffff" }, children: /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 8 }, children: [
|
|
263
|
+
/* @__PURE__ */ jsx(
|
|
264
|
+
"input",
|
|
265
|
+
{
|
|
266
|
+
ref: inputRef,
|
|
267
|
+
type: "text",
|
|
268
|
+
value: inputValue,
|
|
269
|
+
onChange: (e) => setInputValue(e.target.value),
|
|
270
|
+
onKeyDown: handleKeyDown,
|
|
271
|
+
placeholder: "Type a message...",
|
|
272
|
+
disabled: isLoading,
|
|
273
|
+
style: {
|
|
274
|
+
flex: 1,
|
|
275
|
+
padding: "10px 14px",
|
|
276
|
+
borderRadius: 24,
|
|
277
|
+
border: "1px solid #e5e7eb",
|
|
278
|
+
fontSize: 14,
|
|
279
|
+
outline: "none",
|
|
280
|
+
transition: "border-color 0.2s"
|
|
281
|
+
},
|
|
282
|
+
onFocus: (e) => e.currentTarget.style.borderColor = buttonColor,
|
|
283
|
+
onBlur: (e) => e.currentTarget.style.borderColor = "#e5e7eb"
|
|
284
|
+
}
|
|
285
|
+
),
|
|
286
|
+
/* @__PURE__ */ jsx(
|
|
287
|
+
"button",
|
|
288
|
+
{
|
|
289
|
+
type: "submit",
|
|
290
|
+
disabled: !inputValue.trim() || isLoading,
|
|
291
|
+
style: {
|
|
292
|
+
width: 40,
|
|
293
|
+
height: 40,
|
|
294
|
+
borderRadius: "50%",
|
|
295
|
+
border: "none",
|
|
296
|
+
backgroundColor: inputValue.trim() && !isLoading ? buttonColor : "#e5e7eb",
|
|
297
|
+
color: "white",
|
|
298
|
+
cursor: inputValue.trim() && !isLoading ? "pointer" : "not-allowed",
|
|
299
|
+
display: "flex",
|
|
300
|
+
alignItems: "center",
|
|
301
|
+
justifyContent: "center",
|
|
302
|
+
transition: "background-color 0.2s"
|
|
303
|
+
},
|
|
304
|
+
children: /* @__PURE__ */ jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" }) })
|
|
305
|
+
}
|
|
306
|
+
)
|
|
307
|
+
] }) }),
|
|
308
|
+
/* @__PURE__ */ jsx("style", { children: `
|
|
309
|
+
@keyframes chatSlideUp {
|
|
310
|
+
from {
|
|
311
|
+
opacity: 0;
|
|
312
|
+
transform: translateY(20px);
|
|
313
|
+
}
|
|
314
|
+
to {
|
|
315
|
+
opacity: 1;
|
|
316
|
+
transform: translateY(0);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
@keyframes chatDot {
|
|
320
|
+
0%, 80%, 100% {
|
|
321
|
+
opacity: 0.3;
|
|
322
|
+
}
|
|
323
|
+
40% {
|
|
324
|
+
opacity: 1;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
` })
|
|
328
|
+
]
|
|
329
|
+
}
|
|
330
|
+
);
|
|
331
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
332
|
+
ChatPopup,
|
|
333
|
+
ChatButton
|
|
334
|
+
] });
|
|
335
|
+
}
|
|
336
|
+
function adjustColor(hex, amount) {
|
|
337
|
+
const num = parseInt(hex.replace("#", ""), 16);
|
|
338
|
+
const r = Math.min(255, Math.max(0, (num >> 16) + amount));
|
|
339
|
+
const g = Math.min(255, Math.max(0, (num >> 8 & 255) + amount));
|
|
340
|
+
const b = Math.min(255, Math.max(0, (num & 255) + amount));
|
|
341
|
+
return `#${(1 << 24 | r << 16 | g << 8 | b).toString(16).slice(1)}`;
|
|
342
|
+
}
|
|
343
|
+
function getApiConfig2() {
|
|
344
|
+
const apiUrl = typeof window !== "undefined" ? window.__SITE_KIT_API_URL__ || "https://api.uptrademedia.com" : "https://api.uptrademedia.com";
|
|
345
|
+
const apiKey = typeof window !== "undefined" ? window.__SITE_KIT_API_KEY__ : void 0;
|
|
346
|
+
return { apiUrl, apiKey };
|
|
347
|
+
}
|
|
348
|
+
function EngageWidget({
|
|
349
|
+
apiUrl: propApiUrl,
|
|
350
|
+
apiKey: propApiKey,
|
|
351
|
+
position = "bottom-right",
|
|
352
|
+
zIndex = 9999,
|
|
353
|
+
chatEnabled = true,
|
|
354
|
+
debug = false
|
|
355
|
+
}) {
|
|
356
|
+
const pathname = usePathname();
|
|
357
|
+
const [elements, setElements] = useState([]);
|
|
358
|
+
const [activeElements, setActiveElements] = useState([]);
|
|
359
|
+
const [dismissedElements, setDismissedElements] = useState(/* @__PURE__ */ new Set());
|
|
360
|
+
useEffect(() => {
|
|
361
|
+
async function loadElements() {
|
|
362
|
+
const { apiUrl: globalApiUrl, apiKey: globalApiKey } = getApiConfig2();
|
|
363
|
+
const apiUrl = propApiUrl || globalApiUrl;
|
|
364
|
+
const apiKey = propApiKey || globalApiKey;
|
|
365
|
+
if (!apiKey) {
|
|
366
|
+
if (debug) console.warn("[Engage] No API key configured");
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
try {
|
|
370
|
+
const response = await fetch(`${apiUrl}/api/public/engage/elements`, {
|
|
371
|
+
method: "POST",
|
|
372
|
+
headers: {
|
|
373
|
+
"Content-Type": "application/json",
|
|
374
|
+
"x-api-key": apiKey
|
|
375
|
+
},
|
|
376
|
+
body: JSON.stringify({})
|
|
377
|
+
});
|
|
378
|
+
if (!response.ok) {
|
|
379
|
+
if (debug) console.error("[Engage] Error loading elements:", response.statusText);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const data = await response.json();
|
|
383
|
+
if (debug) console.log("[Engage] Loaded elements:", data.elements);
|
|
384
|
+
setElements(data.elements || []);
|
|
385
|
+
} catch (error) {
|
|
386
|
+
if (debug) console.error("[Engage] Error loading elements:", error);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
loadElements();
|
|
390
|
+
}, [propApiUrl, propApiKey, debug]);
|
|
391
|
+
useEffect(() => {
|
|
392
|
+
if (!elements.length) return;
|
|
393
|
+
const checkElement = (element) => {
|
|
394
|
+
if (dismissedElements.has(element.id)) return false;
|
|
395
|
+
if (element.targeting?.pages) {
|
|
396
|
+
const { include, exclude } = element.targeting.pages;
|
|
397
|
+
if (exclude?.some((p) => matchPath(pathname, p))) return false;
|
|
398
|
+
if (include && !include.some((p) => matchPath(pathname, p))) return false;
|
|
399
|
+
}
|
|
400
|
+
if (element.targeting?.devices) {
|
|
401
|
+
const device = getDeviceType();
|
|
402
|
+
if (!element.targeting.devices.includes(device)) return false;
|
|
403
|
+
}
|
|
404
|
+
if (element.trigger?.frequency) {
|
|
405
|
+
const { type, days } = element.trigger.frequency;
|
|
406
|
+
const key = `_engage_${element.id}`;
|
|
407
|
+
if (type === "once") {
|
|
408
|
+
if (localStorage.getItem(key)) return false;
|
|
409
|
+
} else if (type === "once-per-session") {
|
|
410
|
+
if (sessionStorage.getItem(key)) return false;
|
|
411
|
+
} else if (type === "every-n-days" && days) {
|
|
412
|
+
const lastShown = localStorage.getItem(key);
|
|
413
|
+
if (lastShown) {
|
|
414
|
+
const elapsed = Date.now() - parseInt(lastShown, 10);
|
|
415
|
+
if (elapsed < days * 24 * 60 * 60 * 1e3) return false;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return true;
|
|
420
|
+
};
|
|
421
|
+
const eligible = elements.filter(checkElement);
|
|
422
|
+
if (debug) console.log("[Engage] Eligible elements:", eligible);
|
|
423
|
+
eligible.forEach((element) => {
|
|
424
|
+
const trigger = element.trigger;
|
|
425
|
+
if (trigger?.type === "immediate" || !trigger?.type) {
|
|
426
|
+
setActiveElements((prev) => [...prev, element.id]);
|
|
427
|
+
} else if (trigger?.type === "delay" && trigger.delay) {
|
|
428
|
+
setTimeout(() => {
|
|
429
|
+
setActiveElements((prev) => [...prev, element.id]);
|
|
430
|
+
}, trigger.delay * 1e3);
|
|
431
|
+
} else if (trigger?.type === "exit-intent") {
|
|
432
|
+
const handleMouseLeave = (e) => {
|
|
433
|
+
if (e.clientY < 10) {
|
|
434
|
+
setActiveElements((prev) => [...prev, element.id]);
|
|
435
|
+
document.removeEventListener("mouseleave", handleMouseLeave);
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
document.addEventListener("mouseleave", handleMouseLeave);
|
|
439
|
+
} else if (trigger?.type === "scroll" && trigger.scrollPercentage) {
|
|
440
|
+
const handleScroll = () => {
|
|
441
|
+
const scrollPercent = window.scrollY / (document.body.scrollHeight - window.innerHeight) * 100;
|
|
442
|
+
if (scrollPercent >= (trigger.scrollPercentage || 50)) {
|
|
443
|
+
setActiveElements((prev) => [...prev, element.id]);
|
|
444
|
+
window.removeEventListener("scroll", handleScroll);
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
window.addEventListener("scroll", handleScroll);
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
}, [elements, pathname, dismissedElements, debug]);
|
|
451
|
+
const handleDismiss = useCallback((elementId) => {
|
|
452
|
+
setDismissedElements((prev) => /* @__PURE__ */ new Set([...prev, elementId]));
|
|
453
|
+
setActiveElements((prev) => prev.filter((id) => id !== elementId));
|
|
454
|
+
const element = elements.find((e) => e.id === elementId);
|
|
455
|
+
if (element?.trigger?.frequency) {
|
|
456
|
+
const key = `_engage_${elementId}`;
|
|
457
|
+
if (element.trigger.frequency.type === "once-per-session") {
|
|
458
|
+
sessionStorage.setItem(key, "true");
|
|
459
|
+
} else {
|
|
460
|
+
localStorage.setItem(key, Date.now().toString());
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}, [elements]);
|
|
464
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
465
|
+
activeElements.map((elementId) => {
|
|
466
|
+
const element = elements.find((e) => e.id === elementId);
|
|
467
|
+
if (!element) return null;
|
|
468
|
+
return /* @__PURE__ */ jsx(
|
|
469
|
+
EngageElementRenderer,
|
|
470
|
+
{
|
|
471
|
+
element,
|
|
472
|
+
onDismiss: () => handleDismiss(element.id),
|
|
473
|
+
zIndex
|
|
474
|
+
},
|
|
475
|
+
element.id
|
|
476
|
+
);
|
|
477
|
+
}),
|
|
478
|
+
chatEnabled && /* @__PURE__ */ jsx(
|
|
479
|
+
ChatWidget,
|
|
480
|
+
{
|
|
481
|
+
projectId: propApiKey || "",
|
|
482
|
+
config: {
|
|
483
|
+
position,
|
|
484
|
+
buttonColor: "#00afab"
|
|
485
|
+
// Default teal, can be customized later
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
)
|
|
489
|
+
] });
|
|
490
|
+
}
|
|
491
|
+
function EngageElementRenderer({
|
|
492
|
+
element,
|
|
493
|
+
onDismiss,
|
|
494
|
+
zIndex
|
|
495
|
+
}) {
|
|
496
|
+
if (element.type === "popup") {
|
|
497
|
+
return /* @__PURE__ */ jsx(
|
|
498
|
+
"div",
|
|
499
|
+
{
|
|
500
|
+
style: {
|
|
501
|
+
position: "fixed",
|
|
502
|
+
top: 0,
|
|
503
|
+
left: 0,
|
|
504
|
+
right: 0,
|
|
505
|
+
bottom: 0,
|
|
506
|
+
backgroundColor: "rgba(0,0,0,0.5)",
|
|
507
|
+
display: "flex",
|
|
508
|
+
alignItems: "center",
|
|
509
|
+
justifyContent: "center",
|
|
510
|
+
zIndex
|
|
511
|
+
},
|
|
512
|
+
onClick: onDismiss,
|
|
513
|
+
children: /* @__PURE__ */ jsxs(
|
|
514
|
+
"div",
|
|
515
|
+
{
|
|
516
|
+
style: {
|
|
517
|
+
backgroundColor: "white",
|
|
518
|
+
padding: 24,
|
|
519
|
+
borderRadius: 8,
|
|
520
|
+
maxWidth: 500,
|
|
521
|
+
width: "90%"
|
|
522
|
+
},
|
|
523
|
+
onClick: (e) => e.stopPropagation(),
|
|
524
|
+
children: [
|
|
525
|
+
/* @__PURE__ */ jsx(
|
|
526
|
+
"button",
|
|
527
|
+
{
|
|
528
|
+
onClick: onDismiss,
|
|
529
|
+
style: {
|
|
530
|
+
position: "absolute",
|
|
531
|
+
top: 8,
|
|
532
|
+
right: 8,
|
|
533
|
+
background: "none",
|
|
534
|
+
border: "none",
|
|
535
|
+
fontSize: 24,
|
|
536
|
+
cursor: "pointer"
|
|
537
|
+
},
|
|
538
|
+
children: "\xD7"
|
|
539
|
+
}
|
|
540
|
+
),
|
|
541
|
+
element.config?.title && /* @__PURE__ */ jsx("h2", { children: element.config.title }),
|
|
542
|
+
element.config?.message && /* @__PURE__ */ jsx("p", { children: element.config.message })
|
|
543
|
+
]
|
|
544
|
+
}
|
|
545
|
+
)
|
|
546
|
+
}
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
if (element.type === "bar") {
|
|
550
|
+
return /* @__PURE__ */ jsxs(
|
|
551
|
+
"div",
|
|
552
|
+
{
|
|
553
|
+
style: {
|
|
554
|
+
position: "fixed",
|
|
555
|
+
top: 0,
|
|
556
|
+
left: 0,
|
|
557
|
+
right: 0,
|
|
558
|
+
backgroundColor: element.config?.backgroundColor || "#3b82f6",
|
|
559
|
+
color: element.config?.textColor || "white",
|
|
560
|
+
padding: "12px 24px",
|
|
561
|
+
display: "flex",
|
|
562
|
+
alignItems: "center",
|
|
563
|
+
justifyContent: "center",
|
|
564
|
+
gap: 16,
|
|
565
|
+
zIndex
|
|
566
|
+
},
|
|
567
|
+
children: [
|
|
568
|
+
/* @__PURE__ */ jsx("span", { children: element.config?.message }),
|
|
569
|
+
/* @__PURE__ */ jsx(
|
|
570
|
+
"button",
|
|
571
|
+
{
|
|
572
|
+
onClick: onDismiss,
|
|
573
|
+
style: {
|
|
574
|
+
background: "none",
|
|
575
|
+
border: "none",
|
|
576
|
+
color: "inherit",
|
|
577
|
+
fontSize: 20,
|
|
578
|
+
cursor: "pointer"
|
|
579
|
+
},
|
|
580
|
+
children: "\xD7"
|
|
581
|
+
}
|
|
582
|
+
)
|
|
583
|
+
]
|
|
584
|
+
}
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
return null;
|
|
588
|
+
}
|
|
589
|
+
function matchPath(pathname, pattern) {
|
|
590
|
+
if (pattern.endsWith("*")) {
|
|
591
|
+
return pathname.startsWith(pattern.slice(0, -1));
|
|
592
|
+
}
|
|
593
|
+
return pathname === pattern;
|
|
594
|
+
}
|
|
595
|
+
function getDeviceType() {
|
|
596
|
+
if (typeof window === "undefined") return "desktop";
|
|
597
|
+
const ua = navigator.userAgent;
|
|
598
|
+
if (/tablet|ipad|playbook|silk/i.test(ua)) return "tablet";
|
|
599
|
+
if (/mobile|iphone|ipod|android|blackberry|opera mini|iemobile/i.test(ua)) return "mobile";
|
|
600
|
+
return "desktop";
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export { ChatWidget, EngageWidget };
|
|
604
|
+
//# sourceMappingURL=chunk-BGJLOJ7T.mjs.map
|
|
605
|
+
//# sourceMappingURL=chunk-BGJLOJ7T.mjs.map
|