@enjoys/react-chatbot-plugin 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/index.cjs +9 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4711 -0
- package/dist/index.mjs +1295 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +44 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1295 @@
|
|
|
1
|
+
import R, { createContext as L, useCallback as y, useContext as z, useEffect as E, useReducer as B, useRef as b, useState as S } from "react";
|
|
2
|
+
import { Fragment as C, jsx as o, jsxs as d } from "react/jsx-runtime";
|
|
3
|
+
function A(e, t) {
|
|
4
|
+
switch (t.type) {
|
|
5
|
+
case "TOGGLE_OPEN":
|
|
6
|
+
return {
|
|
7
|
+
...e,
|
|
8
|
+
isOpen: !e.isOpen
|
|
9
|
+
};
|
|
10
|
+
case "SET_OPEN":
|
|
11
|
+
return {
|
|
12
|
+
...e,
|
|
13
|
+
isOpen: t.payload
|
|
14
|
+
};
|
|
15
|
+
case "ADD_MESSAGE":
|
|
16
|
+
return {
|
|
17
|
+
...e,
|
|
18
|
+
messages: [...e.messages, t.payload]
|
|
19
|
+
};
|
|
20
|
+
case "ADD_MESSAGES":
|
|
21
|
+
return {
|
|
22
|
+
...e,
|
|
23
|
+
messages: [...e.messages, ...t.payload]
|
|
24
|
+
};
|
|
25
|
+
case "SET_TYPING":
|
|
26
|
+
return {
|
|
27
|
+
...e,
|
|
28
|
+
isTyping: t.payload
|
|
29
|
+
};
|
|
30
|
+
case "DISMISS_WELCOME":
|
|
31
|
+
return {
|
|
32
|
+
...e,
|
|
33
|
+
showWelcome: !1
|
|
34
|
+
};
|
|
35
|
+
case "SET_STEP":
|
|
36
|
+
return {
|
|
37
|
+
...e,
|
|
38
|
+
currentStepId: t.payload
|
|
39
|
+
};
|
|
40
|
+
case "SET_DATA":
|
|
41
|
+
return {
|
|
42
|
+
...e,
|
|
43
|
+
collectedData: {
|
|
44
|
+
...e.collectedData,
|
|
45
|
+
...t.payload
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
case "SET_LOGGED_IN":
|
|
49
|
+
return {
|
|
50
|
+
...e,
|
|
51
|
+
isLoggedIn: t.payload
|
|
52
|
+
};
|
|
53
|
+
case "CLEAR_QUICK_REPLIES":
|
|
54
|
+
return {
|
|
55
|
+
...e,
|
|
56
|
+
messages: e.messages.map((n) => n.quickReplies ? {
|
|
57
|
+
...n,
|
|
58
|
+
quickReplies: void 0
|
|
59
|
+
} : n)
|
|
60
|
+
};
|
|
61
|
+
default:
|
|
62
|
+
return e;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
var _ = (e) => ({
|
|
66
|
+
isOpen: e.defaultOpen ?? !1,
|
|
67
|
+
messages: e.initialMessages ?? [],
|
|
68
|
+
isTyping: !1,
|
|
69
|
+
showWelcome: !!e.welcomeScreen,
|
|
70
|
+
currentStepId: null,
|
|
71
|
+
collectedData: {},
|
|
72
|
+
isLoggedIn: !e.loginForm
|
|
73
|
+
}), F = L(null);
|
|
74
|
+
function D() {
|
|
75
|
+
const e = z(F);
|
|
76
|
+
if (!e) throw new Error("useChatContext must be used within ChatProvider");
|
|
77
|
+
return e;
|
|
78
|
+
}
|
|
79
|
+
var W = {
|
|
80
|
+
primaryColor: "#0066FF",
|
|
81
|
+
headerBg: "#0066FF",
|
|
82
|
+
headerText: "#FFFFFF",
|
|
83
|
+
bubbleBg: "#F1F1F1",
|
|
84
|
+
bubbleText: "#333333",
|
|
85
|
+
userBubbleBg: "#0066FF",
|
|
86
|
+
userBubbleText: "#FFFFFF",
|
|
87
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
88
|
+
fontSize: "14px",
|
|
89
|
+
borderRadius: "12px",
|
|
90
|
+
windowWidth: "380px",
|
|
91
|
+
windowHeight: "550px"
|
|
92
|
+
};
|
|
93
|
+
function T(e) {
|
|
94
|
+
return {
|
|
95
|
+
...W,
|
|
96
|
+
...e
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function M(e, t) {
|
|
100
|
+
return {
|
|
101
|
+
root: {
|
|
102
|
+
fontFamily: e.fontFamily,
|
|
103
|
+
fontSize: e.fontSize,
|
|
104
|
+
lineHeight: "1.5"
|
|
105
|
+
},
|
|
106
|
+
launcher: {
|
|
107
|
+
position: "fixed",
|
|
108
|
+
width: "60px",
|
|
109
|
+
height: "60px",
|
|
110
|
+
borderRadius: "50%",
|
|
111
|
+
backgroundColor: e.primaryColor,
|
|
112
|
+
color: "#fff",
|
|
113
|
+
border: "none",
|
|
114
|
+
cursor: "pointer",
|
|
115
|
+
display: "flex",
|
|
116
|
+
alignItems: "center",
|
|
117
|
+
justifyContent: "center",
|
|
118
|
+
boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
|
|
119
|
+
transition: "transform 0.2s ease",
|
|
120
|
+
zIndex: 9998,
|
|
121
|
+
...t?.launcher
|
|
122
|
+
},
|
|
123
|
+
window: {
|
|
124
|
+
position: "fixed",
|
|
125
|
+
width: e.windowWidth,
|
|
126
|
+
height: e.windowHeight,
|
|
127
|
+
maxHeight: "80vh",
|
|
128
|
+
borderRadius: e.borderRadius,
|
|
129
|
+
overflow: "hidden",
|
|
130
|
+
display: "flex",
|
|
131
|
+
flexDirection: "column",
|
|
132
|
+
boxShadow: "0 8px 32px rgba(0,0,0,0.15)",
|
|
133
|
+
backgroundColor: "#FFFFFF",
|
|
134
|
+
zIndex: 9999,
|
|
135
|
+
...t?.window
|
|
136
|
+
},
|
|
137
|
+
header: {
|
|
138
|
+
backgroundColor: e.headerBg,
|
|
139
|
+
color: e.headerText,
|
|
140
|
+
padding: "16px 20px",
|
|
141
|
+
display: "flex",
|
|
142
|
+
alignItems: "center",
|
|
143
|
+
justifyContent: "space-between",
|
|
144
|
+
gap: "12px",
|
|
145
|
+
flexShrink: 0,
|
|
146
|
+
...t?.header
|
|
147
|
+
},
|
|
148
|
+
messageList: {
|
|
149
|
+
flex: 1,
|
|
150
|
+
overflowY: "auto",
|
|
151
|
+
padding: "16px",
|
|
152
|
+
display: "flex",
|
|
153
|
+
flexDirection: "column",
|
|
154
|
+
gap: "8px",
|
|
155
|
+
...t?.messageList
|
|
156
|
+
},
|
|
157
|
+
inputArea: {
|
|
158
|
+
padding: "12px 16px",
|
|
159
|
+
borderTop: "1px solid #E8E8E8",
|
|
160
|
+
display: "flex",
|
|
161
|
+
gap: "8px",
|
|
162
|
+
alignItems: "flex-end",
|
|
163
|
+
flexShrink: 0,
|
|
164
|
+
...t?.inputArea
|
|
165
|
+
},
|
|
166
|
+
botBubble: {
|
|
167
|
+
backgroundColor: e.bubbleBg,
|
|
168
|
+
color: e.bubbleText,
|
|
169
|
+
padding: "10px 14px",
|
|
170
|
+
borderRadius: "16px 16px 16px 4px",
|
|
171
|
+
maxWidth: "80%",
|
|
172
|
+
alignSelf: "flex-start",
|
|
173
|
+
wordBreak: "break-word",
|
|
174
|
+
whiteSpace: "pre-wrap"
|
|
175
|
+
},
|
|
176
|
+
userBubble: {
|
|
177
|
+
backgroundColor: e.userBubbleBg,
|
|
178
|
+
color: e.userBubbleText,
|
|
179
|
+
padding: "10px 14px",
|
|
180
|
+
borderRadius: "16px 16px 4px 16px",
|
|
181
|
+
maxWidth: "80%",
|
|
182
|
+
alignSelf: "flex-end",
|
|
183
|
+
wordBreak: "break-word",
|
|
184
|
+
whiteSpace: "pre-wrap"
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
var O = ({ onClick: e, isOpen: t, position: n, styles: r, icon: i, closeIcon: s, zIndex: u }) => {
|
|
189
|
+
const l = n === "bottom-left" ? {
|
|
190
|
+
bottom: "20px",
|
|
191
|
+
left: "20px"
|
|
192
|
+
} : {
|
|
193
|
+
bottom: "20px",
|
|
194
|
+
right: "20px"
|
|
195
|
+
};
|
|
196
|
+
return /* @__PURE__ */ o("button", {
|
|
197
|
+
onClick: e,
|
|
198
|
+
"aria-label": t ? "Close chat" : "Open chat",
|
|
199
|
+
style: {
|
|
200
|
+
...r.launcher,
|
|
201
|
+
...l,
|
|
202
|
+
...u != null ? { zIndex: u } : {},
|
|
203
|
+
transform: t ? "scale(0.9)" : "scale(1)"
|
|
204
|
+
},
|
|
205
|
+
children: t ? s ?? /* @__PURE__ */ o(G, {}) : i ?? /* @__PURE__ */ o(q, {})
|
|
206
|
+
});
|
|
207
|
+
}, q = () => /* @__PURE__ */ o("svg", {
|
|
208
|
+
width: "28",
|
|
209
|
+
height: "28",
|
|
210
|
+
viewBox: "0 0 24 24",
|
|
211
|
+
fill: "none",
|
|
212
|
+
stroke: "currentColor",
|
|
213
|
+
strokeWidth: "2",
|
|
214
|
+
strokeLinecap: "round",
|
|
215
|
+
strokeLinejoin: "round",
|
|
216
|
+
children: /* @__PURE__ */ o("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" })
|
|
217
|
+
}), G = () => /* @__PURE__ */ d("svg", {
|
|
218
|
+
width: "24",
|
|
219
|
+
height: "24",
|
|
220
|
+
viewBox: "0 0 24 24",
|
|
221
|
+
fill: "none",
|
|
222
|
+
stroke: "currentColor",
|
|
223
|
+
strokeWidth: "2",
|
|
224
|
+
strokeLinecap: "round",
|
|
225
|
+
strokeLinejoin: "round",
|
|
226
|
+
children: [/* @__PURE__ */ o("line", {
|
|
227
|
+
x1: "18",
|
|
228
|
+
y1: "6",
|
|
229
|
+
x2: "6",
|
|
230
|
+
y2: "18"
|
|
231
|
+
}), /* @__PURE__ */ o("line", {
|
|
232
|
+
x1: "6",
|
|
233
|
+
y1: "6",
|
|
234
|
+
x2: "18",
|
|
235
|
+
y2: "18"
|
|
236
|
+
})]
|
|
237
|
+
}), N = ({ config: e, styles: t, onClose: n }) => /* @__PURE__ */ d("div", {
|
|
238
|
+
style: t.header,
|
|
239
|
+
children: [/* @__PURE__ */ d("div", {
|
|
240
|
+
style: {
|
|
241
|
+
display: "flex",
|
|
242
|
+
alignItems: "center",
|
|
243
|
+
gap: "10px",
|
|
244
|
+
flex: 1
|
|
245
|
+
},
|
|
246
|
+
children: [e.avatar && /* @__PURE__ */ o("img", {
|
|
247
|
+
src: e.avatar,
|
|
248
|
+
alt: "",
|
|
249
|
+
style: {
|
|
250
|
+
width: "36px",
|
|
251
|
+
height: "36px",
|
|
252
|
+
borderRadius: "50%",
|
|
253
|
+
objectFit: "cover"
|
|
254
|
+
}
|
|
255
|
+
}), /* @__PURE__ */ d("div", { children: [/* @__PURE__ */ o("div", {
|
|
256
|
+
style: {
|
|
257
|
+
fontWeight: 600,
|
|
258
|
+
fontSize: "15px"
|
|
259
|
+
},
|
|
260
|
+
children: e.title ?? "Chat with us"
|
|
261
|
+
}), e.subtitle && /* @__PURE__ */ o("div", {
|
|
262
|
+
style: {
|
|
263
|
+
fontSize: "12px",
|
|
264
|
+
opacity: 0.85
|
|
265
|
+
},
|
|
266
|
+
children: e.subtitle
|
|
267
|
+
})] })]
|
|
268
|
+
}), e.showClose !== !1 && /* @__PURE__ */ o("button", {
|
|
269
|
+
onClick: n,
|
|
270
|
+
"aria-label": "Close chat",
|
|
271
|
+
style: {
|
|
272
|
+
background: "none",
|
|
273
|
+
border: "none",
|
|
274
|
+
color: "inherit",
|
|
275
|
+
cursor: "pointer",
|
|
276
|
+
padding: "4px",
|
|
277
|
+
display: "flex",
|
|
278
|
+
alignItems: "center"
|
|
279
|
+
},
|
|
280
|
+
children: /* @__PURE__ */ d("svg", {
|
|
281
|
+
width: "20",
|
|
282
|
+
height: "20",
|
|
283
|
+
viewBox: "0 0 24 24",
|
|
284
|
+
fill: "none",
|
|
285
|
+
stroke: "currentColor",
|
|
286
|
+
strokeWidth: "2",
|
|
287
|
+
strokeLinecap: "round",
|
|
288
|
+
strokeLinejoin: "round",
|
|
289
|
+
children: [/* @__PURE__ */ o("line", {
|
|
290
|
+
x1: "18",
|
|
291
|
+
y1: "6",
|
|
292
|
+
x2: "6",
|
|
293
|
+
y2: "18"
|
|
294
|
+
}), /* @__PURE__ */ o("line", {
|
|
295
|
+
x1: "6",
|
|
296
|
+
y1: "6",
|
|
297
|
+
x2: "18",
|
|
298
|
+
y2: "18"
|
|
299
|
+
})]
|
|
300
|
+
})
|
|
301
|
+
})]
|
|
302
|
+
}), P = ({ content: e, onDismiss: t, primaryColor: n }) => /* @__PURE__ */ d("div", {
|
|
303
|
+
style: {
|
|
304
|
+
flex: 1,
|
|
305
|
+
display: "flex",
|
|
306
|
+
flexDirection: "column",
|
|
307
|
+
overflow: "auto"
|
|
308
|
+
},
|
|
309
|
+
children: [/* @__PURE__ */ o("div", {
|
|
310
|
+
style: {
|
|
311
|
+
flex: 1,
|
|
312
|
+
padding: "20px",
|
|
313
|
+
overflow: "auto"
|
|
314
|
+
},
|
|
315
|
+
children: e
|
|
316
|
+
}), /* @__PURE__ */ o("div", {
|
|
317
|
+
style: {
|
|
318
|
+
padding: "12px 16px",
|
|
319
|
+
borderTop: "1px solid #E8E8E8",
|
|
320
|
+
flexShrink: 0
|
|
321
|
+
},
|
|
322
|
+
children: /* @__PURE__ */ o("button", {
|
|
323
|
+
onClick: t,
|
|
324
|
+
style: {
|
|
325
|
+
width: "100%",
|
|
326
|
+
padding: "12px",
|
|
327
|
+
backgroundColor: n,
|
|
328
|
+
color: "#fff",
|
|
329
|
+
border: "none",
|
|
330
|
+
borderRadius: "8px",
|
|
331
|
+
fontSize: "14px",
|
|
332
|
+
fontWeight: 600,
|
|
333
|
+
cursor: "pointer"
|
|
334
|
+
},
|
|
335
|
+
children: "Start Chat"
|
|
336
|
+
})
|
|
337
|
+
})]
|
|
338
|
+
}), j = ({ field: e, value: t, onChange: n, error: r }) => {
|
|
339
|
+
const i = e.type === "textarea", s = e.type === "textarea" ? void 0 : e.type, u = {
|
|
340
|
+
width: "100%",
|
|
341
|
+
padding: "8px 12px",
|
|
342
|
+
border: `1px solid ${r ? "#E53E3E" : "#D1D5DB"}`,
|
|
343
|
+
borderRadius: "8px",
|
|
344
|
+
fontSize: "13px",
|
|
345
|
+
fontFamily: "inherit",
|
|
346
|
+
outline: "none",
|
|
347
|
+
boxSizing: "border-box",
|
|
348
|
+
transition: "border-color 0.15s ease"
|
|
349
|
+
};
|
|
350
|
+
return /* @__PURE__ */ d("div", {
|
|
351
|
+
style: { marginBottom: "12px" },
|
|
352
|
+
children: [
|
|
353
|
+
e.label && /* @__PURE__ */ d("label", {
|
|
354
|
+
style: {
|
|
355
|
+
display: "block",
|
|
356
|
+
marginBottom: "4px",
|
|
357
|
+
fontSize: "13px",
|
|
358
|
+
fontWeight: 500
|
|
359
|
+
},
|
|
360
|
+
children: [e.label, e.required && /* @__PURE__ */ o("span", {
|
|
361
|
+
style: {
|
|
362
|
+
color: "#E53E3E",
|
|
363
|
+
marginLeft: "2px"
|
|
364
|
+
},
|
|
365
|
+
children: "*"
|
|
366
|
+
})]
|
|
367
|
+
}),
|
|
368
|
+
i ? /* @__PURE__ */ o("textarea", {
|
|
369
|
+
value: t,
|
|
370
|
+
onChange: (l) => n(l.target.value),
|
|
371
|
+
placeholder: e.placeholder,
|
|
372
|
+
required: e.required,
|
|
373
|
+
rows: 3,
|
|
374
|
+
style: {
|
|
375
|
+
...u,
|
|
376
|
+
resize: "vertical"
|
|
377
|
+
},
|
|
378
|
+
minLength: e.validation?.minLength,
|
|
379
|
+
maxLength: e.validation?.maxLength
|
|
380
|
+
}) : /* @__PURE__ */ o("input", {
|
|
381
|
+
type: s,
|
|
382
|
+
value: t,
|
|
383
|
+
onChange: (l) => n(l.target.value),
|
|
384
|
+
placeholder: e.placeholder,
|
|
385
|
+
required: e.required,
|
|
386
|
+
style: u,
|
|
387
|
+
min: e.validation?.min,
|
|
388
|
+
max: e.validation?.max,
|
|
389
|
+
minLength: e.validation?.minLength,
|
|
390
|
+
maxLength: e.validation?.maxLength,
|
|
391
|
+
pattern: e.validation?.pattern
|
|
392
|
+
}),
|
|
393
|
+
r && /* @__PURE__ */ o("div", {
|
|
394
|
+
style: {
|
|
395
|
+
color: "#E53E3E",
|
|
396
|
+
fontSize: "12px",
|
|
397
|
+
marginTop: "2px"
|
|
398
|
+
},
|
|
399
|
+
children: r
|
|
400
|
+
})
|
|
401
|
+
]
|
|
402
|
+
});
|
|
403
|
+
}, $ = ({ field: e, value: t, onChange: n, error: r }) => {
|
|
404
|
+
const i = e.type === "multiselect" || e.multiple, s = (l) => {
|
|
405
|
+
n(i ? Array.from(l.target.selectedOptions, (g) => g.value) : l.target.value);
|
|
406
|
+
}, u = i ? Array.isArray(t) ? t : [t].filter(Boolean) : typeof t == "string" ? t : "";
|
|
407
|
+
return /* @__PURE__ */ d("div", {
|
|
408
|
+
style: { marginBottom: "12px" },
|
|
409
|
+
children: [
|
|
410
|
+
e.label && /* @__PURE__ */ d("label", {
|
|
411
|
+
style: {
|
|
412
|
+
display: "block",
|
|
413
|
+
marginBottom: "4px",
|
|
414
|
+
fontSize: "13px",
|
|
415
|
+
fontWeight: 500
|
|
416
|
+
},
|
|
417
|
+
children: [e.label, e.required && /* @__PURE__ */ o("span", {
|
|
418
|
+
style: {
|
|
419
|
+
color: "#E53E3E",
|
|
420
|
+
marginLeft: "2px"
|
|
421
|
+
},
|
|
422
|
+
children: "*"
|
|
423
|
+
})]
|
|
424
|
+
}),
|
|
425
|
+
/* @__PURE__ */ d("select", {
|
|
426
|
+
value: u,
|
|
427
|
+
onChange: s,
|
|
428
|
+
multiple: i,
|
|
429
|
+
required: e.required,
|
|
430
|
+
style: {
|
|
431
|
+
width: "100%",
|
|
432
|
+
padding: "8px 12px",
|
|
433
|
+
border: `1px solid ${r ? "#E53E3E" : "#D1D5DB"}`,
|
|
434
|
+
borderRadius: "8px",
|
|
435
|
+
fontSize: "13px",
|
|
436
|
+
fontFamily: "inherit",
|
|
437
|
+
outline: "none",
|
|
438
|
+
backgroundColor: "#fff",
|
|
439
|
+
boxSizing: "border-box",
|
|
440
|
+
...i ? { minHeight: "80px" } : {}
|
|
441
|
+
},
|
|
442
|
+
children: [!i && /* @__PURE__ */ o("option", {
|
|
443
|
+
value: "",
|
|
444
|
+
children: "Select..."
|
|
445
|
+
}), e.options?.map((l) => /* @__PURE__ */ o("option", {
|
|
446
|
+
value: l.value,
|
|
447
|
+
children: l.label
|
|
448
|
+
}, l.value))]
|
|
449
|
+
}),
|
|
450
|
+
i && /* @__PURE__ */ o("div", {
|
|
451
|
+
style: {
|
|
452
|
+
fontSize: "11px",
|
|
453
|
+
color: "#888",
|
|
454
|
+
marginTop: "2px"
|
|
455
|
+
},
|
|
456
|
+
children: "Hold Ctrl/Cmd to select multiple"
|
|
457
|
+
}),
|
|
458
|
+
r && /* @__PURE__ */ o("div", {
|
|
459
|
+
style: {
|
|
460
|
+
color: "#E53E3E",
|
|
461
|
+
fontSize: "12px",
|
|
462
|
+
marginTop: "2px"
|
|
463
|
+
},
|
|
464
|
+
children: r
|
|
465
|
+
})
|
|
466
|
+
]
|
|
467
|
+
});
|
|
468
|
+
}, H = ({ field: e, value: t, onChange: n, error: r }) => /* @__PURE__ */ d("div", {
|
|
469
|
+
style: { marginBottom: "12px" },
|
|
470
|
+
children: [
|
|
471
|
+
e.label && /* @__PURE__ */ d("label", {
|
|
472
|
+
style: {
|
|
473
|
+
display: "block",
|
|
474
|
+
marginBottom: "6px",
|
|
475
|
+
fontSize: "13px",
|
|
476
|
+
fontWeight: 500
|
|
477
|
+
},
|
|
478
|
+
children: [e.label, e.required && /* @__PURE__ */ o("span", {
|
|
479
|
+
style: {
|
|
480
|
+
color: "#E53E3E",
|
|
481
|
+
marginLeft: "2px"
|
|
482
|
+
},
|
|
483
|
+
children: "*"
|
|
484
|
+
})]
|
|
485
|
+
}),
|
|
486
|
+
/* @__PURE__ */ o("div", {
|
|
487
|
+
style: {
|
|
488
|
+
display: "flex",
|
|
489
|
+
flexDirection: "column",
|
|
490
|
+
gap: "6px"
|
|
491
|
+
},
|
|
492
|
+
children: e.options?.map((i) => /* @__PURE__ */ d("label", {
|
|
493
|
+
style: {
|
|
494
|
+
display: "flex",
|
|
495
|
+
alignItems: "center",
|
|
496
|
+
gap: "8px",
|
|
497
|
+
cursor: "pointer",
|
|
498
|
+
fontSize: "13px"
|
|
499
|
+
},
|
|
500
|
+
children: [/* @__PURE__ */ o("input", {
|
|
501
|
+
type: "radio",
|
|
502
|
+
name: e.name,
|
|
503
|
+
value: i.value,
|
|
504
|
+
checked: t === i.value,
|
|
505
|
+
onChange: () => n(i.value),
|
|
506
|
+
style: { margin: 0 }
|
|
507
|
+
}), i.label]
|
|
508
|
+
}, i.value))
|
|
509
|
+
}),
|
|
510
|
+
r && /* @__PURE__ */ o("div", {
|
|
511
|
+
style: {
|
|
512
|
+
color: "#E53E3E",
|
|
513
|
+
fontSize: "12px",
|
|
514
|
+
marginTop: "2px"
|
|
515
|
+
},
|
|
516
|
+
children: r
|
|
517
|
+
})
|
|
518
|
+
]
|
|
519
|
+
}), Q = ({ field: e, value: t, onChange: n, error: r }) => {
|
|
520
|
+
const i = (s) => {
|
|
521
|
+
t.includes(s) ? n(t.filter((u) => u !== s)) : n([...t, s]);
|
|
522
|
+
};
|
|
523
|
+
return /* @__PURE__ */ d("div", {
|
|
524
|
+
style: { marginBottom: "12px" },
|
|
525
|
+
children: [
|
|
526
|
+
e.label && /* @__PURE__ */ d("label", {
|
|
527
|
+
style: {
|
|
528
|
+
display: "block",
|
|
529
|
+
marginBottom: "6px",
|
|
530
|
+
fontSize: "13px",
|
|
531
|
+
fontWeight: 500
|
|
532
|
+
},
|
|
533
|
+
children: [e.label, e.required && /* @__PURE__ */ o("span", {
|
|
534
|
+
style: {
|
|
535
|
+
color: "#E53E3E",
|
|
536
|
+
marginLeft: "2px"
|
|
537
|
+
},
|
|
538
|
+
children: "*"
|
|
539
|
+
})]
|
|
540
|
+
}),
|
|
541
|
+
/* @__PURE__ */ o("div", {
|
|
542
|
+
style: {
|
|
543
|
+
display: "flex",
|
|
544
|
+
flexDirection: "column",
|
|
545
|
+
gap: "6px"
|
|
546
|
+
},
|
|
547
|
+
children: e.options?.map((s) => /* @__PURE__ */ d("label", {
|
|
548
|
+
style: {
|
|
549
|
+
display: "flex",
|
|
550
|
+
alignItems: "center",
|
|
551
|
+
gap: "8px",
|
|
552
|
+
cursor: "pointer",
|
|
553
|
+
fontSize: "13px"
|
|
554
|
+
},
|
|
555
|
+
children: [/* @__PURE__ */ o("input", {
|
|
556
|
+
type: "checkbox",
|
|
557
|
+
checked: t.includes(s.value),
|
|
558
|
+
onChange: () => i(s.value),
|
|
559
|
+
style: { margin: 0 }
|
|
560
|
+
}), s.label]
|
|
561
|
+
}, s.value))
|
|
562
|
+
}),
|
|
563
|
+
r && /* @__PURE__ */ o("div", {
|
|
564
|
+
style: {
|
|
565
|
+
color: "#E53E3E",
|
|
566
|
+
fontSize: "12px",
|
|
567
|
+
marginTop: "2px"
|
|
568
|
+
},
|
|
569
|
+
children: r
|
|
570
|
+
})
|
|
571
|
+
]
|
|
572
|
+
});
|
|
573
|
+
}, Y = ({ field: e, value: t, onChange: n, error: r, primaryColor: i }) => {
|
|
574
|
+
const s = b(null), u = t ? Array.from(t).map((l) => l.name).join(", ") : "";
|
|
575
|
+
return /* @__PURE__ */ d("div", {
|
|
576
|
+
style: { marginBottom: "12px" },
|
|
577
|
+
children: [
|
|
578
|
+
e.label && /* @__PURE__ */ d("label", {
|
|
579
|
+
style: {
|
|
580
|
+
display: "block",
|
|
581
|
+
marginBottom: "4px",
|
|
582
|
+
fontSize: "13px",
|
|
583
|
+
fontWeight: 500
|
|
584
|
+
},
|
|
585
|
+
children: [e.label, e.required && /* @__PURE__ */ o("span", {
|
|
586
|
+
style: {
|
|
587
|
+
color: "#E53E3E",
|
|
588
|
+
marginLeft: "2px"
|
|
589
|
+
},
|
|
590
|
+
children: "*"
|
|
591
|
+
})]
|
|
592
|
+
}),
|
|
593
|
+
/* @__PURE__ */ o("input", {
|
|
594
|
+
ref: s,
|
|
595
|
+
type: "file",
|
|
596
|
+
accept: e.accept,
|
|
597
|
+
multiple: e.multiple,
|
|
598
|
+
onChange: (l) => n(l.target.files),
|
|
599
|
+
style: { display: "none" }
|
|
600
|
+
}),
|
|
601
|
+
/* @__PURE__ */ o("button", {
|
|
602
|
+
type: "button",
|
|
603
|
+
onClick: () => s.current?.click(),
|
|
604
|
+
style: {
|
|
605
|
+
padding: "8px 16px",
|
|
606
|
+
border: `1px dashed ${r ? "#E53E3E" : "#D1D5DB"}`,
|
|
607
|
+
borderRadius: "8px",
|
|
608
|
+
backgroundColor: "#FAFAFA",
|
|
609
|
+
cursor: "pointer",
|
|
610
|
+
fontSize: "13px",
|
|
611
|
+
color: "#555",
|
|
612
|
+
width: "100%",
|
|
613
|
+
textAlign: "left"
|
|
614
|
+
},
|
|
615
|
+
children: u || e.placeholder || "Choose file(s)..."
|
|
616
|
+
}),
|
|
617
|
+
u && /* @__PURE__ */ d("div", {
|
|
618
|
+
style: {
|
|
619
|
+
fontSize: "12px",
|
|
620
|
+
color: i,
|
|
621
|
+
marginTop: "4px"
|
|
622
|
+
},
|
|
623
|
+
children: [Array.from(t).length, " file(s) selected"]
|
|
624
|
+
}),
|
|
625
|
+
r && /* @__PURE__ */ o("div", {
|
|
626
|
+
style: {
|
|
627
|
+
color: "#E53E3E",
|
|
628
|
+
fontSize: "12px",
|
|
629
|
+
marginTop: "2px"
|
|
630
|
+
},
|
|
631
|
+
children: r
|
|
632
|
+
})
|
|
633
|
+
]
|
|
634
|
+
});
|
|
635
|
+
}, I = ({ config: e, onSubmit: t, primaryColor: n }) => {
|
|
636
|
+
const [r, i] = S(() => {
|
|
637
|
+
const a = {};
|
|
638
|
+
for (const c of e.fields) c.defaultValue !== void 0 ? a[c.name] = c.defaultValue : c.type === "checkbox" || c.type === "multiselect" ? a[c.name] = [] : c.type === "file" ? a[c.name] = null : a[c.name] = "";
|
|
639
|
+
return a;
|
|
640
|
+
}), [s, u] = S({}), [l, g] = S(!1), x = y((a, c) => {
|
|
641
|
+
i((m) => ({
|
|
642
|
+
...m,
|
|
643
|
+
[a]: c
|
|
644
|
+
})), u((m) => {
|
|
645
|
+
const w = { ...m };
|
|
646
|
+
return delete w[a], w;
|
|
647
|
+
});
|
|
648
|
+
}, []), p = () => {
|
|
649
|
+
const a = {};
|
|
650
|
+
for (const c of e.fields) {
|
|
651
|
+
const m = r[c.name];
|
|
652
|
+
if (c.required && (m === "" || m === null || m === void 0 || Array.isArray(m) && m.length === 0)) {
|
|
653
|
+
a[c.name] = c.validation?.message ?? `${c.label || c.name} is required`;
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
c.validation?.pattern && typeof m == "string" && m && (new RegExp(c.validation.pattern).test(m) || (a[c.name] = c.validation.message ?? "Invalid format"));
|
|
657
|
+
}
|
|
658
|
+
return u(a), Object.keys(a).length === 0;
|
|
659
|
+
}, h = (a) => {
|
|
660
|
+
a.preventDefault(), p() && (g(!0), t(r));
|
|
661
|
+
};
|
|
662
|
+
return l ? /* @__PURE__ */ o("div", {
|
|
663
|
+
style: {
|
|
664
|
+
padding: "12px",
|
|
665
|
+
backgroundColor: "#F0FFF4",
|
|
666
|
+
borderRadius: "8px",
|
|
667
|
+
fontSize: "13px",
|
|
668
|
+
color: "#276749",
|
|
669
|
+
textAlign: "center"
|
|
670
|
+
},
|
|
671
|
+
children: "Submitted successfully"
|
|
672
|
+
}) : /* @__PURE__ */ d("form", {
|
|
673
|
+
onSubmit: h,
|
|
674
|
+
style: {
|
|
675
|
+
backgroundColor: "#FAFAFA",
|
|
676
|
+
borderRadius: "10px",
|
|
677
|
+
padding: "16px",
|
|
678
|
+
border: "1px solid #E8E8E8"
|
|
679
|
+
},
|
|
680
|
+
children: [
|
|
681
|
+
e.title && /* @__PURE__ */ o("div", {
|
|
682
|
+
style: {
|
|
683
|
+
fontWeight: 600,
|
|
684
|
+
fontSize: "14px",
|
|
685
|
+
marginBottom: "4px"
|
|
686
|
+
},
|
|
687
|
+
children: e.title
|
|
688
|
+
}),
|
|
689
|
+
e.description && /* @__PURE__ */ o("div", {
|
|
690
|
+
style: {
|
|
691
|
+
fontSize: "12px",
|
|
692
|
+
color: "#888",
|
|
693
|
+
marginBottom: "12px"
|
|
694
|
+
},
|
|
695
|
+
children: e.description
|
|
696
|
+
}),
|
|
697
|
+
e.fields.map((a) => /* @__PURE__ */ o(K, {
|
|
698
|
+
field: a,
|
|
699
|
+
value: r[a.name],
|
|
700
|
+
onChange: (c) => x(a.name, c),
|
|
701
|
+
error: s[a.name],
|
|
702
|
+
primaryColor: n
|
|
703
|
+
}, a.name)),
|
|
704
|
+
/* @__PURE__ */ o("button", {
|
|
705
|
+
type: "submit",
|
|
706
|
+
style: {
|
|
707
|
+
width: "100%",
|
|
708
|
+
padding: "10px",
|
|
709
|
+
backgroundColor: n,
|
|
710
|
+
color: "#fff",
|
|
711
|
+
border: "none",
|
|
712
|
+
borderRadius: "8px",
|
|
713
|
+
fontSize: "14px",
|
|
714
|
+
fontWeight: 600,
|
|
715
|
+
cursor: "pointer",
|
|
716
|
+
marginTop: "4px"
|
|
717
|
+
},
|
|
718
|
+
children: e.submitLabel ?? "Submit"
|
|
719
|
+
})
|
|
720
|
+
]
|
|
721
|
+
});
|
|
722
|
+
}, K = ({ field: e, value: t, onChange: n, error: r, primaryColor: i }) => {
|
|
723
|
+
switch (e.type) {
|
|
724
|
+
case "text":
|
|
725
|
+
case "email":
|
|
726
|
+
case "password":
|
|
727
|
+
case "number":
|
|
728
|
+
case "tel":
|
|
729
|
+
case "url":
|
|
730
|
+
case "textarea":
|
|
731
|
+
case "date":
|
|
732
|
+
case "time":
|
|
733
|
+
return /* @__PURE__ */ o(j, {
|
|
734
|
+
field: e,
|
|
735
|
+
value: String(t ?? ""),
|
|
736
|
+
onChange: n,
|
|
737
|
+
error: r
|
|
738
|
+
});
|
|
739
|
+
case "select":
|
|
740
|
+
case "multiselect":
|
|
741
|
+
return /* @__PURE__ */ o($, {
|
|
742
|
+
field: e,
|
|
743
|
+
value: t,
|
|
744
|
+
onChange: n,
|
|
745
|
+
error: r
|
|
746
|
+
});
|
|
747
|
+
case "radio":
|
|
748
|
+
return /* @__PURE__ */ o(H, {
|
|
749
|
+
field: e,
|
|
750
|
+
value: String(t ?? ""),
|
|
751
|
+
onChange: n,
|
|
752
|
+
error: r
|
|
753
|
+
});
|
|
754
|
+
case "checkbox":
|
|
755
|
+
return /* @__PURE__ */ o(Q, {
|
|
756
|
+
field: e,
|
|
757
|
+
value: t ?? [],
|
|
758
|
+
onChange: n,
|
|
759
|
+
error: r
|
|
760
|
+
});
|
|
761
|
+
case "file":
|
|
762
|
+
return /* @__PURE__ */ o(Y, {
|
|
763
|
+
field: e,
|
|
764
|
+
value: t,
|
|
765
|
+
onChange: n,
|
|
766
|
+
error: r,
|
|
767
|
+
primaryColor: i
|
|
768
|
+
});
|
|
769
|
+
case "hidden":
|
|
770
|
+
return /* @__PURE__ */ o("input", {
|
|
771
|
+
type: "hidden",
|
|
772
|
+
name: e.name,
|
|
773
|
+
value: String(t ?? "")
|
|
774
|
+
});
|
|
775
|
+
default:
|
|
776
|
+
return null;
|
|
777
|
+
}
|
|
778
|
+
}, U = ({ config: e, onLogin: t, primaryColor: n }) => /* @__PURE__ */ o("div", {
|
|
779
|
+
style: {
|
|
780
|
+
flex: 1,
|
|
781
|
+
display: "flex",
|
|
782
|
+
flexDirection: "column",
|
|
783
|
+
justifyContent: "center",
|
|
784
|
+
padding: "20px",
|
|
785
|
+
overflow: "auto"
|
|
786
|
+
},
|
|
787
|
+
children: /* @__PURE__ */ o(I, {
|
|
788
|
+
config: e,
|
|
789
|
+
onSubmit: t,
|
|
790
|
+
primaryColor: n
|
|
791
|
+
})
|
|
792
|
+
}), V = ({ message: e, styles: t }) => {
|
|
793
|
+
const n = e.sender === "bot" ? t.botBubble : t.userBubble;
|
|
794
|
+
return !e.text && !e.attachment ? null : /* @__PURE__ */ d("div", {
|
|
795
|
+
style: n,
|
|
796
|
+
children: [e.text && /* @__PURE__ */ o("span", { children: e.text }), e.attachment && /* @__PURE__ */ o("div", {
|
|
797
|
+
style: { marginTop: e.text ? "6px" : 0 },
|
|
798
|
+
children: /* @__PURE__ */ d("a", {
|
|
799
|
+
href: e.attachment.url,
|
|
800
|
+
target: "_blank",
|
|
801
|
+
rel: "noopener noreferrer",
|
|
802
|
+
style: {
|
|
803
|
+
color: "inherit",
|
|
804
|
+
textDecoration: "underline",
|
|
805
|
+
fontSize: "13px"
|
|
806
|
+
},
|
|
807
|
+
children: ["📎 ", e.attachment.name]
|
|
808
|
+
})
|
|
809
|
+
})]
|
|
810
|
+
});
|
|
811
|
+
}, J = ({ replies: e, onSelect: t, primaryColor: n }) => /* @__PURE__ */ o("div", {
|
|
812
|
+
style: {
|
|
813
|
+
display: "flex",
|
|
814
|
+
flexWrap: "wrap",
|
|
815
|
+
gap: "6px",
|
|
816
|
+
alignSelf: "flex-start",
|
|
817
|
+
maxWidth: "90%"
|
|
818
|
+
},
|
|
819
|
+
children: e.map((r) => /* @__PURE__ */ o("button", {
|
|
820
|
+
onClick: () => t(r.value, r.label),
|
|
821
|
+
style: {
|
|
822
|
+
padding: "6px 14px",
|
|
823
|
+
borderRadius: "18px",
|
|
824
|
+
border: `1px solid ${n}`,
|
|
825
|
+
backgroundColor: "transparent",
|
|
826
|
+
color: n,
|
|
827
|
+
cursor: "pointer",
|
|
828
|
+
fontSize: "13px",
|
|
829
|
+
fontWeight: 500,
|
|
830
|
+
transition: "all 0.15s ease"
|
|
831
|
+
},
|
|
832
|
+
onMouseEnter: (i) => {
|
|
833
|
+
i.currentTarget.style.backgroundColor = n, i.currentTarget.style.color = "#fff";
|
|
834
|
+
},
|
|
835
|
+
onMouseLeave: (i) => {
|
|
836
|
+
i.currentTarget.style.backgroundColor = "transparent", i.currentTarget.style.color = n;
|
|
837
|
+
},
|
|
838
|
+
children: r.label
|
|
839
|
+
}, r.value))
|
|
840
|
+
}), X = ({ color: e }) => {
|
|
841
|
+
const t = {
|
|
842
|
+
width: "8px",
|
|
843
|
+
height: "8px",
|
|
844
|
+
borderRadius: "50%",
|
|
845
|
+
backgroundColor: e,
|
|
846
|
+
opacity: 0.4,
|
|
847
|
+
animation: "chatbot-typing-bounce 1.4s infinite ease-in-out"
|
|
848
|
+
};
|
|
849
|
+
return /* @__PURE__ */ d(C, { children: [/* @__PURE__ */ o("style", { children: `
|
|
850
|
+
@keyframes chatbot-typing-bounce {
|
|
851
|
+
0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
|
|
852
|
+
40% { transform: scale(1); opacity: 1; }
|
|
853
|
+
}
|
|
854
|
+
` }), /* @__PURE__ */ d("div", {
|
|
855
|
+
style: {
|
|
856
|
+
display: "flex",
|
|
857
|
+
gap: "4px",
|
|
858
|
+
padding: "12px 16px",
|
|
859
|
+
backgroundColor: "#F1F1F1",
|
|
860
|
+
borderRadius: "16px 16px 16px 4px",
|
|
861
|
+
alignSelf: "flex-start",
|
|
862
|
+
alignItems: "center"
|
|
863
|
+
},
|
|
864
|
+
children: [
|
|
865
|
+
/* @__PURE__ */ o("span", { style: {
|
|
866
|
+
...t,
|
|
867
|
+
animationDelay: "0s"
|
|
868
|
+
} }),
|
|
869
|
+
/* @__PURE__ */ o("span", { style: {
|
|
870
|
+
...t,
|
|
871
|
+
animationDelay: "0.2s"
|
|
872
|
+
} }),
|
|
873
|
+
/* @__PURE__ */ o("span", { style: {
|
|
874
|
+
...t,
|
|
875
|
+
animationDelay: "0.4s"
|
|
876
|
+
} })
|
|
877
|
+
]
|
|
878
|
+
})] });
|
|
879
|
+
}, Z = ({ messages: e, isTyping: t, styles: n, primaryColor: r, onQuickReply: i, onFormSubmit: s }) => {
|
|
880
|
+
const u = b(null);
|
|
881
|
+
return E(() => {
|
|
882
|
+
u.current?.scrollIntoView({ behavior: "smooth" });
|
|
883
|
+
}, [e, t]), /* @__PURE__ */ d("div", {
|
|
884
|
+
style: n.messageList,
|
|
885
|
+
children: [
|
|
886
|
+
e.map((l) => /* @__PURE__ */ d(R.Fragment, { children: [
|
|
887
|
+
/* @__PURE__ */ o(V, {
|
|
888
|
+
message: l,
|
|
889
|
+
styles: n
|
|
890
|
+
}),
|
|
891
|
+
l.quickReplies && l.quickReplies.length > 0 && /* @__PURE__ */ o(J, {
|
|
892
|
+
replies: l.quickReplies,
|
|
893
|
+
onSelect: i,
|
|
894
|
+
primaryColor: r
|
|
895
|
+
}),
|
|
896
|
+
l.form && /* @__PURE__ */ o("div", {
|
|
897
|
+
style: {
|
|
898
|
+
alignSelf: "flex-start",
|
|
899
|
+
width: "90%"
|
|
900
|
+
},
|
|
901
|
+
children: /* @__PURE__ */ o(I, {
|
|
902
|
+
config: l.form,
|
|
903
|
+
onSubmit: (g) => s(l.form.id, g),
|
|
904
|
+
primaryColor: r
|
|
905
|
+
})
|
|
906
|
+
})
|
|
907
|
+
] }, l.id)),
|
|
908
|
+
t && /* @__PURE__ */ o(X, { color: r }),
|
|
909
|
+
/* @__PURE__ */ o("div", { ref: u })
|
|
910
|
+
]
|
|
911
|
+
});
|
|
912
|
+
}, ee = ({ onSend: e, placeholder: t = "Type a message...", primaryColor: n, disabled: r, styleOverride: i }) => {
|
|
913
|
+
const [s, u] = S(""), l = b(null), g = () => {
|
|
914
|
+
const p = s.trim();
|
|
915
|
+
p && (e(p), u(""), l.current?.focus());
|
|
916
|
+
}, x = (p) => {
|
|
917
|
+
p.key === "Enter" && !p.shiftKey && (p.preventDefault(), g());
|
|
918
|
+
};
|
|
919
|
+
return /* @__PURE__ */ d("div", {
|
|
920
|
+
style: {
|
|
921
|
+
display: "flex",
|
|
922
|
+
gap: "8px",
|
|
923
|
+
alignItems: "flex-end",
|
|
924
|
+
...i
|
|
925
|
+
},
|
|
926
|
+
children: [/* @__PURE__ */ o("textarea", {
|
|
927
|
+
ref: l,
|
|
928
|
+
value: s,
|
|
929
|
+
onChange: (p) => u(p.target.value),
|
|
930
|
+
onKeyDown: x,
|
|
931
|
+
placeholder: t,
|
|
932
|
+
disabled: r,
|
|
933
|
+
rows: 1,
|
|
934
|
+
style: {
|
|
935
|
+
flex: 1,
|
|
936
|
+
padding: "10px 14px",
|
|
937
|
+
border: "1px solid #E0E0E0",
|
|
938
|
+
borderRadius: "20px",
|
|
939
|
+
outline: "none",
|
|
940
|
+
resize: "none",
|
|
941
|
+
fontFamily: "inherit",
|
|
942
|
+
fontSize: "14px",
|
|
943
|
+
lineHeight: "1.4",
|
|
944
|
+
maxHeight: "100px",
|
|
945
|
+
overflowY: "auto"
|
|
946
|
+
}
|
|
947
|
+
}), /* @__PURE__ */ o("button", {
|
|
948
|
+
onClick: g,
|
|
949
|
+
disabled: r || !s.trim(),
|
|
950
|
+
"aria-label": "Send message",
|
|
951
|
+
style: {
|
|
952
|
+
width: "38px",
|
|
953
|
+
height: "38px",
|
|
954
|
+
borderRadius: "50%",
|
|
955
|
+
backgroundColor: s.trim() ? n : "#CCC",
|
|
956
|
+
color: "#fff",
|
|
957
|
+
border: "none",
|
|
958
|
+
cursor: s.trim() ? "pointer" : "default",
|
|
959
|
+
display: "flex",
|
|
960
|
+
alignItems: "center",
|
|
961
|
+
justifyContent: "center",
|
|
962
|
+
flexShrink: 0,
|
|
963
|
+
transition: "background-color 0.15s ease"
|
|
964
|
+
},
|
|
965
|
+
children: /* @__PURE__ */ o("svg", {
|
|
966
|
+
width: "18",
|
|
967
|
+
height: "18",
|
|
968
|
+
viewBox: "0 0 24 24",
|
|
969
|
+
fill: "currentColor",
|
|
970
|
+
children: /* @__PURE__ */ o("path", { d: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" })
|
|
971
|
+
})
|
|
972
|
+
})]
|
|
973
|
+
});
|
|
974
|
+
}, te = 0, k = () => `msg_${Date.now()}_${++te}`, ne = class {
|
|
975
|
+
constructor(e) {
|
|
976
|
+
this.collectedData = {}, this.startStep = e.startStep, this.steps = new Map(e.steps.map((t) => [t.id, t]));
|
|
977
|
+
}
|
|
978
|
+
getStartStepId() {
|
|
979
|
+
return this.startStep;
|
|
980
|
+
}
|
|
981
|
+
getStep(e) {
|
|
982
|
+
return this.steps.get(e);
|
|
983
|
+
}
|
|
984
|
+
getData() {
|
|
985
|
+
return { ...this.collectedData };
|
|
986
|
+
}
|
|
987
|
+
setData(e, t) {
|
|
988
|
+
this.collectedData[e] = t;
|
|
989
|
+
}
|
|
990
|
+
mergeData(e) {
|
|
991
|
+
Object.assign(this.collectedData, e);
|
|
992
|
+
}
|
|
993
|
+
resolveNext(e, t) {
|
|
994
|
+
if (e.condition) {
|
|
995
|
+
const { field: n, operator: r, value: i, then: s, else: u } = e.condition, l = this.collectedData[n];
|
|
996
|
+
return this.evaluate(l, r, i) ? s : u;
|
|
997
|
+
}
|
|
998
|
+
if (t && e.quickReplies) {
|
|
999
|
+
const n = e.quickReplies.find((r) => r.value === t);
|
|
1000
|
+
if (n?.next) return n.next;
|
|
1001
|
+
}
|
|
1002
|
+
return e.next;
|
|
1003
|
+
}
|
|
1004
|
+
buildMessages(e) {
|
|
1005
|
+
const t = [], n = e.messages ?? (e.message ? [e.message] : []);
|
|
1006
|
+
for (const r of n) t.push({
|
|
1007
|
+
id: k(),
|
|
1008
|
+
sender: "bot",
|
|
1009
|
+
text: r,
|
|
1010
|
+
timestamp: Date.now()
|
|
1011
|
+
});
|
|
1012
|
+
return e.quickReplies && t.length > 0 && (t[t.length - 1].quickReplies = e.quickReplies), e.form && t.push({
|
|
1013
|
+
id: k(),
|
|
1014
|
+
sender: "bot",
|
|
1015
|
+
timestamp: Date.now(),
|
|
1016
|
+
form: e.form
|
|
1017
|
+
}), t;
|
|
1018
|
+
}
|
|
1019
|
+
evaluate(e, t, n) {
|
|
1020
|
+
switch (t) {
|
|
1021
|
+
case "eq":
|
|
1022
|
+
return String(e) === String(n);
|
|
1023
|
+
case "neq":
|
|
1024
|
+
return String(e) !== String(n);
|
|
1025
|
+
case "contains":
|
|
1026
|
+
return String(e).includes(String(n));
|
|
1027
|
+
case "gt":
|
|
1028
|
+
return Number(e) > Number(n);
|
|
1029
|
+
case "lt":
|
|
1030
|
+
return Number(e) < Number(n);
|
|
1031
|
+
default:
|
|
1032
|
+
return !1;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
}, re = 0, f = () => `msg_${Date.now()}_${++re}`, v = (e) => new Promise((t) => setTimeout(t, e));
|
|
1036
|
+
function oe() {
|
|
1037
|
+
const { state: e, dispatch: t, props: n } = D(), r = b(null), i = b(!1);
|
|
1038
|
+
E(() => {
|
|
1039
|
+
n.flow && (r.current = new ne(n.flow), i.current = !1);
|
|
1040
|
+
}, [n.flow]);
|
|
1041
|
+
const s = y(async (x, p) => {
|
|
1042
|
+
t({
|
|
1043
|
+
type: "SET_TYPING",
|
|
1044
|
+
payload: !0
|
|
1045
|
+
}), await v(400);
|
|
1046
|
+
const h = {
|
|
1047
|
+
id: f(),
|
|
1048
|
+
sender: "bot",
|
|
1049
|
+
text: x,
|
|
1050
|
+
timestamp: Date.now(),
|
|
1051
|
+
...p
|
|
1052
|
+
};
|
|
1053
|
+
t({
|
|
1054
|
+
type: "SET_TYPING",
|
|
1055
|
+
payload: !1
|
|
1056
|
+
}), t({
|
|
1057
|
+
type: "ADD_MESSAGE",
|
|
1058
|
+
payload: h
|
|
1059
|
+
}), n.callbacks?.onMessageReceive?.(h);
|
|
1060
|
+
}, [t, n.callbacks]), u = y((x) => {
|
|
1061
|
+
const p = {
|
|
1062
|
+
id: f(),
|
|
1063
|
+
sender: "user",
|
|
1064
|
+
text: x,
|
|
1065
|
+
timestamp: Date.now()
|
|
1066
|
+
};
|
|
1067
|
+
if (t({
|
|
1068
|
+
type: "ADD_MESSAGE",
|
|
1069
|
+
payload: p
|
|
1070
|
+
}), n.callbacks?.onMessageSend?.(p), n.callbacks?.onSubmit?.({ message: x }), r.current && e.currentStepId) {
|
|
1071
|
+
const h = r.current.getStep(e.currentStepId);
|
|
1072
|
+
if (h) {
|
|
1073
|
+
r.current.setData(h.id, x);
|
|
1074
|
+
const a = r.current.resolveNext(h, x);
|
|
1075
|
+
a ? l(a) : (n.callbacks?.onFlowEnd?.(r.current.getData()), t({
|
|
1076
|
+
type: "SET_STEP",
|
|
1077
|
+
payload: null
|
|
1078
|
+
}));
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}, [
|
|
1082
|
+
t,
|
|
1083
|
+
n.callbacks,
|
|
1084
|
+
e.currentStepId
|
|
1085
|
+
]), l = y(async (x) => {
|
|
1086
|
+
const p = r.current;
|
|
1087
|
+
if (!p) return;
|
|
1088
|
+
const h = p.getStep(x);
|
|
1089
|
+
if (!h) return;
|
|
1090
|
+
t({
|
|
1091
|
+
type: "SET_STEP",
|
|
1092
|
+
payload: x
|
|
1093
|
+
}), t({
|
|
1094
|
+
type: "SET_TYPING",
|
|
1095
|
+
payload: !0
|
|
1096
|
+
}), await v(h.delay ?? 500);
|
|
1097
|
+
const a = p.buildMessages(h);
|
|
1098
|
+
t({
|
|
1099
|
+
type: "SET_TYPING",
|
|
1100
|
+
payload: !1
|
|
1101
|
+
}), t({
|
|
1102
|
+
type: "ADD_MESSAGES",
|
|
1103
|
+
payload: a
|
|
1104
|
+
}), a.forEach((c) => n.callbacks?.onMessageReceive?.(c)), !h.quickReplies && !h.form && h.next && (await v(300), l(h.next));
|
|
1105
|
+
}, [t, n.callbacks]), g = y(() => {
|
|
1106
|
+
const x = r.current;
|
|
1107
|
+
!x || i.current || (i.current = !0, l(x.getStartStepId()));
|
|
1108
|
+
}, [l]);
|
|
1109
|
+
return E(() => {
|
|
1110
|
+
n.flow && !e.showWelcome && e.isLoggedIn && !i.current && g();
|
|
1111
|
+
}, [
|
|
1112
|
+
n.flow,
|
|
1113
|
+
e.showWelcome,
|
|
1114
|
+
e.isLoggedIn,
|
|
1115
|
+
g
|
|
1116
|
+
]), {
|
|
1117
|
+
state: e,
|
|
1118
|
+
sendMessage: u,
|
|
1119
|
+
addBotMessage: s,
|
|
1120
|
+
handleQuickReply: y((x, p) => {
|
|
1121
|
+
if (t({ type: "CLEAR_QUICK_REPLIES" }), t({
|
|
1122
|
+
type: "ADD_MESSAGE",
|
|
1123
|
+
payload: {
|
|
1124
|
+
id: f(),
|
|
1125
|
+
sender: "user",
|
|
1126
|
+
text: p,
|
|
1127
|
+
timestamp: Date.now()
|
|
1128
|
+
}
|
|
1129
|
+
}), n.callbacks?.onQuickReply?.(x, p), r.current && e.currentStepId) {
|
|
1130
|
+
const h = r.current.getStep(e.currentStepId);
|
|
1131
|
+
if (h) {
|
|
1132
|
+
r.current.setData(h.id, x);
|
|
1133
|
+
const a = r.current.resolveNext(h, x);
|
|
1134
|
+
a ? l(a) : (n.callbacks?.onFlowEnd?.(r.current.getData()), t({
|
|
1135
|
+
type: "SET_STEP",
|
|
1136
|
+
payload: null
|
|
1137
|
+
}));
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}, [
|
|
1141
|
+
t,
|
|
1142
|
+
n.callbacks,
|
|
1143
|
+
e.currentStepId,
|
|
1144
|
+
l
|
|
1145
|
+
]),
|
|
1146
|
+
handleFormSubmit: y(async (x, p) => {
|
|
1147
|
+
t({
|
|
1148
|
+
type: "SET_DATA",
|
|
1149
|
+
payload: p
|
|
1150
|
+
}), r.current && r.current.mergeData(p);
|
|
1151
|
+
const h = Object.entries(p).filter(([, a]) => a !== void 0 && a !== "").map(([a, c]) => `${a}: ${String(c)}`).join(`
|
|
1152
|
+
`);
|
|
1153
|
+
if (t({
|
|
1154
|
+
type: "ADD_MESSAGE",
|
|
1155
|
+
payload: {
|
|
1156
|
+
id: f(),
|
|
1157
|
+
sender: "user",
|
|
1158
|
+
text: h,
|
|
1159
|
+
formData: p,
|
|
1160
|
+
timestamp: Date.now()
|
|
1161
|
+
}
|
|
1162
|
+
}), await n.callbacks?.onFormSubmit?.(x, p), r.current && e.currentStepId) {
|
|
1163
|
+
const a = r.current.getStep(e.currentStepId);
|
|
1164
|
+
if (a) {
|
|
1165
|
+
const c = r.current.resolveNext(a);
|
|
1166
|
+
c ? l(c) : (n.callbacks?.onFlowEnd?.(r.current.getData()), t({
|
|
1167
|
+
type: "SET_STEP",
|
|
1168
|
+
payload: null
|
|
1169
|
+
}));
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
}, [
|
|
1173
|
+
t,
|
|
1174
|
+
n.callbacks,
|
|
1175
|
+
e.currentStepId,
|
|
1176
|
+
l
|
|
1177
|
+
]),
|
|
1178
|
+
handleLogin: y(async (x) => {
|
|
1179
|
+
await n.callbacks?.onLogin?.(x), t({
|
|
1180
|
+
type: "SET_LOGGED_IN",
|
|
1181
|
+
payload: !0
|
|
1182
|
+
});
|
|
1183
|
+
}, [t, n.callbacks]),
|
|
1184
|
+
toggleChat: y(() => {
|
|
1185
|
+
const x = !e.isOpen;
|
|
1186
|
+
t({ type: "TOGGLE_OPEN" }), x ? n.callbacks?.onOpen?.() : n.callbacks?.onClose?.();
|
|
1187
|
+
}, [
|
|
1188
|
+
t,
|
|
1189
|
+
e.isOpen,
|
|
1190
|
+
n.callbacks
|
|
1191
|
+
]),
|
|
1192
|
+
dismissWelcome: y(() => {
|
|
1193
|
+
t({ type: "DISMISS_WELCOME" });
|
|
1194
|
+
}, [t]),
|
|
1195
|
+
startFlow: g,
|
|
1196
|
+
processFlowStep: l
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
var ie = ({ styles: e, position: t, zIndex: n }) => {
|
|
1200
|
+
const { props: r } = D(), i = T(r.theme), { state: s, sendMessage: u, handleQuickReply: l, handleFormSubmit: g, handleLogin: x, toggleChat: p, dismissWelcome: h } = oe(), a = t === "bottom-left" ? {
|
|
1201
|
+
bottom: "90px",
|
|
1202
|
+
left: "20px"
|
|
1203
|
+
} : {
|
|
1204
|
+
bottom: "90px",
|
|
1205
|
+
right: "20px"
|
|
1206
|
+
};
|
|
1207
|
+
return /* @__PURE__ */ d("div", {
|
|
1208
|
+
style: {
|
|
1209
|
+
...e.window,
|
|
1210
|
+
...a,
|
|
1211
|
+
...n != null ? { zIndex: n } : {}
|
|
1212
|
+
},
|
|
1213
|
+
children: [/* @__PURE__ */ o(N, {
|
|
1214
|
+
config: r.header ?? { title: "Chat with us" },
|
|
1215
|
+
styles: e,
|
|
1216
|
+
onClose: p
|
|
1217
|
+
}), s.showWelcome && r.welcomeScreen ? /* @__PURE__ */ o(P, {
|
|
1218
|
+
content: r.welcomeScreen,
|
|
1219
|
+
onDismiss: h,
|
|
1220
|
+
primaryColor: i.primaryColor
|
|
1221
|
+
}) : !s.isLoggedIn && r.loginForm ? /* @__PURE__ */ o(U, {
|
|
1222
|
+
config: r.loginForm,
|
|
1223
|
+
onLogin: x,
|
|
1224
|
+
primaryColor: i.primaryColor
|
|
1225
|
+
}) : /* @__PURE__ */ d(C, { children: [/* @__PURE__ */ o(Z, {
|
|
1226
|
+
messages: s.messages,
|
|
1227
|
+
isTyping: s.isTyping,
|
|
1228
|
+
styles: e,
|
|
1229
|
+
primaryColor: i.primaryColor,
|
|
1230
|
+
onQuickReply: l,
|
|
1231
|
+
onFormSubmit: g
|
|
1232
|
+
}), /* @__PURE__ */ o("div", {
|
|
1233
|
+
style: e.inputArea,
|
|
1234
|
+
children: /* @__PURE__ */ o(ee, {
|
|
1235
|
+
onSend: u,
|
|
1236
|
+
placeholder: r.inputPlaceholder,
|
|
1237
|
+
primaryColor: i.primaryColor
|
|
1238
|
+
})
|
|
1239
|
+
})] })]
|
|
1240
|
+
});
|
|
1241
|
+
}, se = (e) => {
|
|
1242
|
+
const [t, n] = B(A, e, _), r = M(T(e.theme), e.style), i = e.position ?? "bottom-right", s = e.showLauncher !== !1;
|
|
1243
|
+
return /* @__PURE__ */ o(F.Provider, {
|
|
1244
|
+
value: {
|
|
1245
|
+
state: t,
|
|
1246
|
+
dispatch: n,
|
|
1247
|
+
props: e
|
|
1248
|
+
},
|
|
1249
|
+
children: /* @__PURE__ */ d("div", {
|
|
1250
|
+
style: r.root,
|
|
1251
|
+
className: e.className,
|
|
1252
|
+
children: [t.isOpen && /* @__PURE__ */ o(ie, {
|
|
1253
|
+
styles: r,
|
|
1254
|
+
position: i,
|
|
1255
|
+
zIndex: e.zIndex
|
|
1256
|
+
}), s && /* @__PURE__ */ o(O, {
|
|
1257
|
+
onClick: () => {
|
|
1258
|
+
const u = !t.isOpen;
|
|
1259
|
+
n({ type: "TOGGLE_OPEN" }), u ? e.callbacks?.onOpen?.() : e.callbacks?.onClose?.();
|
|
1260
|
+
},
|
|
1261
|
+
isOpen: t.isOpen,
|
|
1262
|
+
position: i,
|
|
1263
|
+
styles: r,
|
|
1264
|
+
icon: e.launcherIcon,
|
|
1265
|
+
closeIcon: e.closeIcon,
|
|
1266
|
+
zIndex: e.zIndex
|
|
1267
|
+
})]
|
|
1268
|
+
})
|
|
1269
|
+
});
|
|
1270
|
+
};
|
|
1271
|
+
export {
|
|
1272
|
+
se as ChatBot,
|
|
1273
|
+
F as ChatContext,
|
|
1274
|
+
N as ChatHeader,
|
|
1275
|
+
ee as ChatInput,
|
|
1276
|
+
ie as ChatWindow,
|
|
1277
|
+
Q as CheckboxField,
|
|
1278
|
+
I as DynamicForm,
|
|
1279
|
+
Y as FileUploadField,
|
|
1280
|
+
ne as FlowEngine,
|
|
1281
|
+
O as Launcher,
|
|
1282
|
+
U as LoginScreen,
|
|
1283
|
+
V as MessageBubble,
|
|
1284
|
+
Z as MessageList,
|
|
1285
|
+
J as QuickReplies,
|
|
1286
|
+
H as RadioField,
|
|
1287
|
+
$ as SelectField,
|
|
1288
|
+
j as TextField,
|
|
1289
|
+
X as TypingIndicator,
|
|
1290
|
+
P as WelcomeScreen,
|
|
1291
|
+
oe as useChat,
|
|
1292
|
+
D as useChatContext
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1295
|
+
//# sourceMappingURL=index.mjs.map
|