@diffsome/react 1.2.15 → 1.2.18
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/chat.css +45 -0
- package/dist/index.d.mts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.js +41 -23
- package/dist/index.mjs +41 -23
- package/package.json +1 -1
package/dist/chat.css
CHANGED
|
@@ -230,6 +230,22 @@
|
|
|
230
230
|
border-bottom-left-radius: 4px;
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
/* Bot Message */
|
|
234
|
+
.diffsome-chat-message-bot {
|
|
235
|
+
align-self: flex-start;
|
|
236
|
+
align-items: flex-start;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.diffsome-chat-message-bot .diffsome-chat-message-bubble {
|
|
240
|
+
background: linear-gradient(135deg, #dbeafe 0%, #e0e7ff 100%);
|
|
241
|
+
color: #1e40af;
|
|
242
|
+
border-bottom-left-radius: 4px;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.diffsome-chat-bot-icon {
|
|
246
|
+
font-size: 11px;
|
|
247
|
+
}
|
|
248
|
+
|
|
233
249
|
.diffsome-chat-message-content {
|
|
234
250
|
font-size: 14px;
|
|
235
251
|
line-height: 1.4;
|
|
@@ -316,6 +332,35 @@
|
|
|
316
332
|
background: var(--diffsome-chat-primary-dark);
|
|
317
333
|
}
|
|
318
334
|
|
|
335
|
+
/* Login Prompt */
|
|
336
|
+
.diffsome-chat-login-prompt {
|
|
337
|
+
display: flex;
|
|
338
|
+
align-items: center;
|
|
339
|
+
justify-content: space-between;
|
|
340
|
+
gap: 12px;
|
|
341
|
+
padding: 10px 16px;
|
|
342
|
+
background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
|
|
343
|
+
border-top: 1px solid #bae6fd;
|
|
344
|
+
font-size: 13px;
|
|
345
|
+
color: #0369a1;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.diffsome-chat-login-btn {
|
|
349
|
+
background: var(--diffsome-chat-primary);
|
|
350
|
+
color: white;
|
|
351
|
+
text-decoration: none;
|
|
352
|
+
padding: 6px 14px;
|
|
353
|
+
border-radius: 16px;
|
|
354
|
+
font-size: 12px;
|
|
355
|
+
font-weight: 500;
|
|
356
|
+
white-space: nowrap;
|
|
357
|
+
transition: background-color 0.2s ease;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
.diffsome-chat-login-btn:hover {
|
|
361
|
+
background: var(--diffsome-chat-primary-dark);
|
|
362
|
+
}
|
|
363
|
+
|
|
319
364
|
/* System Message */
|
|
320
365
|
.diffsome-chat-message-system {
|
|
321
366
|
align-self: center;
|
package/dist/index.d.mts
CHANGED
|
@@ -872,13 +872,19 @@ interface ChatBubbleProps {
|
|
|
872
872
|
onClose?: () => void;
|
|
873
873
|
/** Member auth token for logged-in users (optional) */
|
|
874
874
|
memberToken?: string;
|
|
875
|
+
/** Show login prompt for non-logged-in users */
|
|
876
|
+
showLoginPrompt?: boolean;
|
|
877
|
+
/** Login page URL (used when showLoginPrompt is true) */
|
|
878
|
+
loginUrl?: string;
|
|
879
|
+
/** Custom login prompt message */
|
|
880
|
+
loginPromptMessage?: string;
|
|
875
881
|
}
|
|
876
882
|
declare const ChatBubble: React__default.FC<ChatBubbleProps>;
|
|
877
883
|
|
|
878
884
|
interface Message {
|
|
879
885
|
id: number;
|
|
880
886
|
content: string;
|
|
881
|
-
sender_type: 'visitor' | 'agent' | 'system';
|
|
887
|
+
sender_type: 'visitor' | 'agent' | 'bot' | 'system';
|
|
882
888
|
sender_name?: string;
|
|
883
889
|
created_at?: string;
|
|
884
890
|
is_read?: boolean;
|
|
@@ -899,12 +905,20 @@ interface ChatWidgetProps {
|
|
|
899
905
|
typing?: boolean;
|
|
900
906
|
ended?: boolean;
|
|
901
907
|
className?: string;
|
|
908
|
+
/** Whether user is logged in */
|
|
909
|
+
isLoggedIn?: boolean;
|
|
910
|
+
/** Show login prompt for non-logged-in users */
|
|
911
|
+
showLoginPrompt?: boolean;
|
|
912
|
+
/** Login page URL */
|
|
913
|
+
loginUrl?: string;
|
|
914
|
+
/** Custom login prompt message */
|
|
915
|
+
loginPromptMessage?: string;
|
|
902
916
|
}
|
|
903
917
|
declare const ChatWidget: React__default.FC<ChatWidgetProps>;
|
|
904
918
|
|
|
905
919
|
interface ChatMessageProps {
|
|
906
920
|
content: string;
|
|
907
|
-
senderType: 'visitor' | 'agent' | 'system';
|
|
921
|
+
senderType: 'visitor' | 'agent' | 'bot' | 'system';
|
|
908
922
|
senderName?: string;
|
|
909
923
|
timestamp?: string;
|
|
910
924
|
isRead?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -872,13 +872,19 @@ interface ChatBubbleProps {
|
|
|
872
872
|
onClose?: () => void;
|
|
873
873
|
/** Member auth token for logged-in users (optional) */
|
|
874
874
|
memberToken?: string;
|
|
875
|
+
/** Show login prompt for non-logged-in users */
|
|
876
|
+
showLoginPrompt?: boolean;
|
|
877
|
+
/** Login page URL (used when showLoginPrompt is true) */
|
|
878
|
+
loginUrl?: string;
|
|
879
|
+
/** Custom login prompt message */
|
|
880
|
+
loginPromptMessage?: string;
|
|
875
881
|
}
|
|
876
882
|
declare const ChatBubble: React__default.FC<ChatBubbleProps>;
|
|
877
883
|
|
|
878
884
|
interface Message {
|
|
879
885
|
id: number;
|
|
880
886
|
content: string;
|
|
881
|
-
sender_type: 'visitor' | 'agent' | 'system';
|
|
887
|
+
sender_type: 'visitor' | 'agent' | 'bot' | 'system';
|
|
882
888
|
sender_name?: string;
|
|
883
889
|
created_at?: string;
|
|
884
890
|
is_read?: boolean;
|
|
@@ -899,12 +905,20 @@ interface ChatWidgetProps {
|
|
|
899
905
|
typing?: boolean;
|
|
900
906
|
ended?: boolean;
|
|
901
907
|
className?: string;
|
|
908
|
+
/** Whether user is logged in */
|
|
909
|
+
isLoggedIn?: boolean;
|
|
910
|
+
/** Show login prompt for non-logged-in users */
|
|
911
|
+
showLoginPrompt?: boolean;
|
|
912
|
+
/** Login page URL */
|
|
913
|
+
loginUrl?: string;
|
|
914
|
+
/** Custom login prompt message */
|
|
915
|
+
loginPromptMessage?: string;
|
|
902
916
|
}
|
|
903
917
|
declare const ChatWidget: React__default.FC<ChatWidgetProps>;
|
|
904
918
|
|
|
905
919
|
interface ChatMessageProps {
|
|
906
920
|
content: string;
|
|
907
|
-
senderType: 'visitor' | 'agent' | 'system';
|
|
921
|
+
senderType: 'visitor' | 'agent' | 'bot' | 'system';
|
|
908
922
|
senderName?: string;
|
|
909
923
|
timestamp?: string;
|
|
910
924
|
isRead?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -2612,25 +2612,24 @@ var ChatMessage = ({
|
|
|
2612
2612
|
}) => {
|
|
2613
2613
|
const isVisitor = senderType === "visitor";
|
|
2614
2614
|
const isSystem = senderType === "system";
|
|
2615
|
+
const isBot = senderType === "bot";
|
|
2615
2616
|
if (isSystem) {
|
|
2616
2617
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: `diffsome-chat-message-system ${className}`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: content }) });
|
|
2617
2618
|
}
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
{
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
}
|
|
2633
|
-
);
|
|
2619
|
+
const messageClass = isVisitor ? "diffsome-chat-message-visitor" : isBot ? "diffsome-chat-message-bot" : "diffsome-chat-message-agent";
|
|
2620
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `diffsome-chat-message ${messageClass} ${className}`, children: [
|
|
2621
|
+
!isVisitor && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "diffsome-chat-message-sender", children: [
|
|
2622
|
+
isBot && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "diffsome-chat-bot-icon", children: "\u{1F916} " }),
|
|
2623
|
+
senderName || (isBot ? "AI Assistant" : "Agent")
|
|
2624
|
+
] }),
|
|
2625
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `diffsome-chat-message-bubble ${isPending ? "diffsome-chat-message-pending" : ""} ${isFailed ? "diffsome-chat-message-failed" : ""}`, children: [
|
|
2626
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "diffsome-chat-message-content", children: content }),
|
|
2627
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "diffsome-chat-message-time", children: isPending ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "diffsome-chat-message-status", children: "Sending..." }) : isFailed ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "diffsome-chat-message-status diffsome-chat-message-error", children: "Failed" }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
2628
|
+
timestamp,
|
|
2629
|
+
isVisitor && isRead && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "diffsome-chat-message-read", children: " \u2713" })
|
|
2630
|
+
] }) })
|
|
2631
|
+
] })
|
|
2632
|
+
] });
|
|
2634
2633
|
};
|
|
2635
2634
|
|
|
2636
2635
|
// src/components/chat/ChatInput.tsx
|
|
@@ -2738,7 +2737,11 @@ var ChatWidget = ({
|
|
|
2738
2737
|
loading = false,
|
|
2739
2738
|
typing = false,
|
|
2740
2739
|
ended = false,
|
|
2741
|
-
className = ""
|
|
2740
|
+
className = "",
|
|
2741
|
+
isLoggedIn = false,
|
|
2742
|
+
showLoginPrompt = false,
|
|
2743
|
+
loginUrl = "/auth/login",
|
|
2744
|
+
loginPromptMessage = "Login to save your chat history across devices"
|
|
2742
2745
|
}) => {
|
|
2743
2746
|
const messagesEndRef = (0, import_react23.useRef)(null);
|
|
2744
2747
|
const scrollToBottom = () => {
|
|
@@ -2816,6 +2819,10 @@ var ChatWidget = ({
|
|
|
2816
2819
|
}
|
|
2817
2820
|
)
|
|
2818
2821
|
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
2822
|
+
showLoginPrompt && !isLoggedIn && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "diffsome-chat-login-prompt", children: [
|
|
2823
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: loginPromptMessage }),
|
|
2824
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", { href: loginUrl, className: "diffsome-chat-login-btn", children: "Login" })
|
|
2825
|
+
] }),
|
|
2819
2826
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2820
2827
|
ChatInput,
|
|
2821
2828
|
{
|
|
@@ -2856,7 +2863,10 @@ var ChatBubble = ({
|
|
|
2856
2863
|
className = "",
|
|
2857
2864
|
onOpen,
|
|
2858
2865
|
onClose,
|
|
2859
|
-
memberToken
|
|
2866
|
+
memberToken,
|
|
2867
|
+
showLoginPrompt = false,
|
|
2868
|
+
loginUrl = "/auth/login",
|
|
2869
|
+
loginPromptMessage = "Login to save your chat history across devices"
|
|
2860
2870
|
}) => {
|
|
2861
2871
|
(0, import_react24.useEffect)(() => {
|
|
2862
2872
|
if (memberToken) {
|
|
@@ -2987,12 +2997,16 @@ var ChatBubble = ({
|
|
|
2987
2997
|
};
|
|
2988
2998
|
setMessages((prev) => [...prev, pendingMessage]);
|
|
2989
2999
|
try {
|
|
2990
|
-
const
|
|
2991
|
-
if (
|
|
2992
|
-
seenMessageIds.current.add(
|
|
3000
|
+
const response = await conn.send(content);
|
|
3001
|
+
if (response) {
|
|
3002
|
+
seenMessageIds.current.add(response.id);
|
|
2993
3003
|
setMessages(
|
|
2994
|
-
(prev) => prev.map((m) => m.id === tempId ? { ...
|
|
3004
|
+
(prev) => prev.map((m) => m.id === tempId ? { ...response, is_pending: false } : m)
|
|
2995
3005
|
);
|
|
3006
|
+
if (response.bot_response) {
|
|
3007
|
+
seenMessageIds.current.add(response.bot_response.id);
|
|
3008
|
+
setMessages((prev) => [...prev, response.bot_response]);
|
|
3009
|
+
}
|
|
2996
3010
|
}
|
|
2997
3011
|
} catch (error) {
|
|
2998
3012
|
console.error("Failed to send message:", error);
|
|
@@ -3054,7 +3068,11 @@ var ChatBubble = ({
|
|
|
3054
3068
|
placeholder,
|
|
3055
3069
|
loading,
|
|
3056
3070
|
typing,
|
|
3057
|
-
ended
|
|
3071
|
+
ended,
|
|
3072
|
+
isLoggedIn: !!memberToken,
|
|
3073
|
+
showLoginPrompt,
|
|
3074
|
+
loginUrl,
|
|
3075
|
+
loginPromptMessage
|
|
3058
3076
|
}
|
|
3059
3077
|
),
|
|
3060
3078
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
package/dist/index.mjs
CHANGED
|
@@ -2520,25 +2520,24 @@ var ChatMessage = ({
|
|
|
2520
2520
|
}) => {
|
|
2521
2521
|
const isVisitor = senderType === "visitor";
|
|
2522
2522
|
const isSystem = senderType === "system";
|
|
2523
|
+
const isBot = senderType === "bot";
|
|
2523
2524
|
if (isSystem) {
|
|
2524
2525
|
return /* @__PURE__ */ jsx3("div", { className: `diffsome-chat-message-system ${className}`, children: /* @__PURE__ */ jsx3("span", { children: content }) });
|
|
2525
2526
|
}
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
{
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
}
|
|
2541
|
-
);
|
|
2527
|
+
const messageClass = isVisitor ? "diffsome-chat-message-visitor" : isBot ? "diffsome-chat-message-bot" : "diffsome-chat-message-agent";
|
|
2528
|
+
return /* @__PURE__ */ jsxs2("div", { className: `diffsome-chat-message ${messageClass} ${className}`, children: [
|
|
2529
|
+
!isVisitor && /* @__PURE__ */ jsxs2("div", { className: "diffsome-chat-message-sender", children: [
|
|
2530
|
+
isBot && /* @__PURE__ */ jsx3("span", { className: "diffsome-chat-bot-icon", children: "\u{1F916} " }),
|
|
2531
|
+
senderName || (isBot ? "AI Assistant" : "Agent")
|
|
2532
|
+
] }),
|
|
2533
|
+
/* @__PURE__ */ jsxs2("div", { className: `diffsome-chat-message-bubble ${isPending ? "diffsome-chat-message-pending" : ""} ${isFailed ? "diffsome-chat-message-failed" : ""}`, children: [
|
|
2534
|
+
/* @__PURE__ */ jsx3("div", { className: "diffsome-chat-message-content", children: content }),
|
|
2535
|
+
/* @__PURE__ */ jsx3("div", { className: "diffsome-chat-message-time", children: isPending ? /* @__PURE__ */ jsx3("span", { className: "diffsome-chat-message-status", children: "Sending..." }) : isFailed ? /* @__PURE__ */ jsx3("span", { className: "diffsome-chat-message-status diffsome-chat-message-error", children: "Failed" }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
2536
|
+
timestamp,
|
|
2537
|
+
isVisitor && isRead && /* @__PURE__ */ jsx3("span", { className: "diffsome-chat-message-read", children: " \u2713" })
|
|
2538
|
+
] }) })
|
|
2539
|
+
] })
|
|
2540
|
+
] });
|
|
2542
2541
|
};
|
|
2543
2542
|
|
|
2544
2543
|
// src/components/chat/ChatInput.tsx
|
|
@@ -2646,7 +2645,11 @@ var ChatWidget = ({
|
|
|
2646
2645
|
loading = false,
|
|
2647
2646
|
typing = false,
|
|
2648
2647
|
ended = false,
|
|
2649
|
-
className = ""
|
|
2648
|
+
className = "",
|
|
2649
|
+
isLoggedIn = false,
|
|
2650
|
+
showLoginPrompt = false,
|
|
2651
|
+
loginUrl = "/auth/login",
|
|
2652
|
+
loginPromptMessage = "Login to save your chat history across devices"
|
|
2650
2653
|
}) => {
|
|
2651
2654
|
const messagesEndRef = useRef2(null);
|
|
2652
2655
|
const scrollToBottom = () => {
|
|
@@ -2724,6 +2727,10 @@ var ChatWidget = ({
|
|
|
2724
2727
|
}
|
|
2725
2728
|
)
|
|
2726
2729
|
] }) : /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
2730
|
+
showLoginPrompt && !isLoggedIn && /* @__PURE__ */ jsxs4("div", { className: "diffsome-chat-login-prompt", children: [
|
|
2731
|
+
/* @__PURE__ */ jsx5("span", { children: loginPromptMessage }),
|
|
2732
|
+
/* @__PURE__ */ jsx5("a", { href: loginUrl, className: "diffsome-chat-login-btn", children: "Login" })
|
|
2733
|
+
] }),
|
|
2727
2734
|
/* @__PURE__ */ jsx5(
|
|
2728
2735
|
ChatInput,
|
|
2729
2736
|
{
|
|
@@ -2764,7 +2771,10 @@ var ChatBubble = ({
|
|
|
2764
2771
|
className = "",
|
|
2765
2772
|
onOpen,
|
|
2766
2773
|
onClose,
|
|
2767
|
-
memberToken
|
|
2774
|
+
memberToken,
|
|
2775
|
+
showLoginPrompt = false,
|
|
2776
|
+
loginUrl = "/auth/login",
|
|
2777
|
+
loginPromptMessage = "Login to save your chat history across devices"
|
|
2768
2778
|
}) => {
|
|
2769
2779
|
useEffect20(() => {
|
|
2770
2780
|
if (memberToken) {
|
|
@@ -2895,12 +2905,16 @@ var ChatBubble = ({
|
|
|
2895
2905
|
};
|
|
2896
2906
|
setMessages((prev) => [...prev, pendingMessage]);
|
|
2897
2907
|
try {
|
|
2898
|
-
const
|
|
2899
|
-
if (
|
|
2900
|
-
seenMessageIds.current.add(
|
|
2908
|
+
const response = await conn.send(content);
|
|
2909
|
+
if (response) {
|
|
2910
|
+
seenMessageIds.current.add(response.id);
|
|
2901
2911
|
setMessages(
|
|
2902
|
-
(prev) => prev.map((m) => m.id === tempId ? { ...
|
|
2912
|
+
(prev) => prev.map((m) => m.id === tempId ? { ...response, is_pending: false } : m)
|
|
2903
2913
|
);
|
|
2914
|
+
if (response.bot_response) {
|
|
2915
|
+
seenMessageIds.current.add(response.bot_response.id);
|
|
2916
|
+
setMessages((prev) => [...prev, response.bot_response]);
|
|
2917
|
+
}
|
|
2904
2918
|
}
|
|
2905
2919
|
} catch (error) {
|
|
2906
2920
|
console.error("Failed to send message:", error);
|
|
@@ -2962,7 +2976,11 @@ var ChatBubble = ({
|
|
|
2962
2976
|
placeholder,
|
|
2963
2977
|
loading,
|
|
2964
2978
|
typing,
|
|
2965
|
-
ended
|
|
2979
|
+
ended,
|
|
2980
|
+
isLoggedIn: !!memberToken,
|
|
2981
|
+
showLoginPrompt,
|
|
2982
|
+
loginUrl,
|
|
2983
|
+
loginPromptMessage
|
|
2966
2984
|
}
|
|
2967
2985
|
),
|
|
2968
2986
|
/* @__PURE__ */ jsxs5(
|