@diffsome/react 1.2.12 → 1.2.13
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 +33 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +49 -10
- package/dist/index.mjs +49 -10
- package/package.json +1 -1
package/dist/chat.css
CHANGED
|
@@ -263,6 +263,39 @@
|
|
|
263
263
|
color: #ef4444;
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
+
/* End Chat Button */
|
|
267
|
+
.diffsome-chat-end-container {
|
|
268
|
+
padding: 8px 16px 12px;
|
|
269
|
+
text-align: center;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.diffsome-chat-end-btn {
|
|
273
|
+
background: none;
|
|
274
|
+
border: 1px solid var(--diffsome-chat-border);
|
|
275
|
+
color: var(--diffsome-chat-text-muted);
|
|
276
|
+
font-size: 12px;
|
|
277
|
+
padding: 6px 16px;
|
|
278
|
+
border-radius: 16px;
|
|
279
|
+
cursor: pointer;
|
|
280
|
+
transition: all 0.2s ease;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.diffsome-chat-end-btn:hover {
|
|
284
|
+
border-color: #ef4444;
|
|
285
|
+
color: #ef4444;
|
|
286
|
+
background: #fef2f2;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/* Chat Ended Message */
|
|
290
|
+
.diffsome-chat-ended {
|
|
291
|
+
padding: 16px;
|
|
292
|
+
text-align: center;
|
|
293
|
+
color: var(--diffsome-chat-text-muted);
|
|
294
|
+
font-size: 14px;
|
|
295
|
+
border-top: 1px solid var(--diffsome-chat-border);
|
|
296
|
+
background: var(--diffsome-chat-bg);
|
|
297
|
+
}
|
|
298
|
+
|
|
266
299
|
/* System Message */
|
|
267
300
|
.diffsome-chat-message-system {
|
|
268
301
|
align-self: center;
|
package/dist/index.d.mts
CHANGED
|
@@ -884,11 +884,13 @@ interface ChatWidgetProps {
|
|
|
884
884
|
onSend: (message: string) => void;
|
|
885
885
|
onTyping?: () => void;
|
|
886
886
|
onClose?: () => void;
|
|
887
|
+
onEndChat?: () => void;
|
|
887
888
|
title?: string;
|
|
888
889
|
subtitle?: string;
|
|
889
890
|
placeholder?: string;
|
|
890
891
|
loading?: boolean;
|
|
891
892
|
typing?: boolean;
|
|
893
|
+
ended?: boolean;
|
|
892
894
|
className?: string;
|
|
893
895
|
}
|
|
894
896
|
declare const ChatWidget: React__default.FC<ChatWidgetProps>;
|
package/dist/index.d.ts
CHANGED
|
@@ -884,11 +884,13 @@ interface ChatWidgetProps {
|
|
|
884
884
|
onSend: (message: string) => void;
|
|
885
885
|
onTyping?: () => void;
|
|
886
886
|
onClose?: () => void;
|
|
887
|
+
onEndChat?: () => void;
|
|
887
888
|
title?: string;
|
|
888
889
|
subtitle?: string;
|
|
889
890
|
placeholder?: string;
|
|
890
891
|
loading?: boolean;
|
|
891
892
|
typing?: boolean;
|
|
893
|
+
ended?: boolean;
|
|
892
894
|
className?: string;
|
|
893
895
|
}
|
|
894
896
|
declare const ChatWidget: React__default.FC<ChatWidgetProps>;
|
package/dist/index.js
CHANGED
|
@@ -2719,11 +2719,13 @@ var ChatWidget = ({
|
|
|
2719
2719
|
onSend,
|
|
2720
2720
|
onTyping,
|
|
2721
2721
|
onClose,
|
|
2722
|
+
onEndChat,
|
|
2722
2723
|
title = "Chat Support",
|
|
2723
2724
|
subtitle = "We typically reply within a few minutes",
|
|
2724
2725
|
placeholder = "Type a message...",
|
|
2725
2726
|
loading = false,
|
|
2726
2727
|
typing = false,
|
|
2728
|
+
ended = false,
|
|
2727
2729
|
className = ""
|
|
2728
2730
|
}) => {
|
|
2729
2731
|
const messagesEndRef = (0, import_react23.useRef)(null);
|
|
@@ -2791,15 +2793,25 @@ var ChatWidget = ({
|
|
|
2791
2793
|
] }),
|
|
2792
2794
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ref: messagesEndRef })
|
|
2793
2795
|
] }) }),
|
|
2794
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2796
|
+
ended ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "diffsome-chat-ended", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "Chat ended. Thank you!" }) }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
2797
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2798
|
+
ChatInput,
|
|
2799
|
+
{
|
|
2800
|
+
onSend,
|
|
2801
|
+
onTyping,
|
|
2802
|
+
placeholder,
|
|
2803
|
+
disabled: loading
|
|
2804
|
+
}
|
|
2805
|
+
),
|
|
2806
|
+
onEndChat && messages.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "diffsome-chat-end-container", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2807
|
+
"button",
|
|
2808
|
+
{
|
|
2809
|
+
className: "diffsome-chat-end-btn",
|
|
2810
|
+
onClick: onEndChat,
|
|
2811
|
+
children: "End Chat"
|
|
2812
|
+
}
|
|
2813
|
+
) })
|
|
2814
|
+
] })
|
|
2803
2815
|
] });
|
|
2804
2816
|
};
|
|
2805
2817
|
|
|
@@ -2830,6 +2842,7 @@ var ChatBubble = ({
|
|
|
2830
2842
|
const [typing, setTyping] = (0, import_react24.useState)(false);
|
|
2831
2843
|
const [unreadCount, setUnreadCount] = (0, import_react24.useState)(0);
|
|
2832
2844
|
const [initialized, setInitialized] = (0, import_react24.useState)(false);
|
|
2845
|
+
const [ended, setEnded] = (0, import_react24.useState)(false);
|
|
2833
2846
|
const seenMessageIds = (0, import_react24.useRef)(/* @__PURE__ */ new Set());
|
|
2834
2847
|
const connectionRef = (0, import_react24.useRef)(null);
|
|
2835
2848
|
const setupListeners = (0, import_react24.useCallback)((conn) => {
|
|
@@ -2942,6 +2955,30 @@ var ChatBubble = ({
|
|
|
2942
2955
|
const handleTyping = () => {
|
|
2943
2956
|
connectionRef.current?.sendTyping();
|
|
2944
2957
|
};
|
|
2958
|
+
const handleEndChat = async () => {
|
|
2959
|
+
const conn = connectionRef.current;
|
|
2960
|
+
if (!conn) return;
|
|
2961
|
+
try {
|
|
2962
|
+
await conn.close();
|
|
2963
|
+
} catch (error) {
|
|
2964
|
+
console.error("Failed to close chat:", error);
|
|
2965
|
+
}
|
|
2966
|
+
if (typeof localStorage !== "undefined") {
|
|
2967
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
2968
|
+
}
|
|
2969
|
+
setEnded(true);
|
|
2970
|
+
connectionRef.current?.disconnect();
|
|
2971
|
+
connectionRef.current = null;
|
|
2972
|
+
setConnection(null);
|
|
2973
|
+
setInitialized(false);
|
|
2974
|
+
setConversationId(null);
|
|
2975
|
+
};
|
|
2976
|
+
const handleStartNewChat = () => {
|
|
2977
|
+
setEnded(false);
|
|
2978
|
+
setMessages([]);
|
|
2979
|
+
seenMessageIds.current.clear();
|
|
2980
|
+
initChat();
|
|
2981
|
+
};
|
|
2945
2982
|
(0, import_react24.useEffect)(() => {
|
|
2946
2983
|
return () => {
|
|
2947
2984
|
connectionRef.current?.disconnect();
|
|
@@ -2961,11 +2998,13 @@ var ChatBubble = ({
|
|
|
2961
2998
|
onSend: handleSend,
|
|
2962
2999
|
onTyping: handleTyping,
|
|
2963
3000
|
onClose: handleClose,
|
|
3001
|
+
onEndChat: handleEndChat,
|
|
2964
3002
|
title,
|
|
2965
3003
|
subtitle,
|
|
2966
3004
|
placeholder,
|
|
2967
3005
|
loading,
|
|
2968
|
-
typing
|
|
3006
|
+
typing,
|
|
3007
|
+
ended
|
|
2969
3008
|
}
|
|
2970
3009
|
),
|
|
2971
3010
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
package/dist/index.mjs
CHANGED
|
@@ -2627,11 +2627,13 @@ var ChatWidget = ({
|
|
|
2627
2627
|
onSend,
|
|
2628
2628
|
onTyping,
|
|
2629
2629
|
onClose,
|
|
2630
|
+
onEndChat,
|
|
2630
2631
|
title = "Chat Support",
|
|
2631
2632
|
subtitle = "We typically reply within a few minutes",
|
|
2632
2633
|
placeholder = "Type a message...",
|
|
2633
2634
|
loading = false,
|
|
2634
2635
|
typing = false,
|
|
2636
|
+
ended = false,
|
|
2635
2637
|
className = ""
|
|
2636
2638
|
}) => {
|
|
2637
2639
|
const messagesEndRef = useRef2(null);
|
|
@@ -2699,15 +2701,25 @@ var ChatWidget = ({
|
|
|
2699
2701
|
] }),
|
|
2700
2702
|
/* @__PURE__ */ jsx5("div", { ref: messagesEndRef })
|
|
2701
2703
|
] }) }),
|
|
2702
|
-
/* @__PURE__ */ jsx5(
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2704
|
+
ended ? /* @__PURE__ */ jsx5("div", { className: "diffsome-chat-ended", children: /* @__PURE__ */ jsx5("span", { children: "Chat ended. Thank you!" }) }) : /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
2705
|
+
/* @__PURE__ */ jsx5(
|
|
2706
|
+
ChatInput,
|
|
2707
|
+
{
|
|
2708
|
+
onSend,
|
|
2709
|
+
onTyping,
|
|
2710
|
+
placeholder,
|
|
2711
|
+
disabled: loading
|
|
2712
|
+
}
|
|
2713
|
+
),
|
|
2714
|
+
onEndChat && messages.length > 0 && /* @__PURE__ */ jsx5("div", { className: "diffsome-chat-end-container", children: /* @__PURE__ */ jsx5(
|
|
2715
|
+
"button",
|
|
2716
|
+
{
|
|
2717
|
+
className: "diffsome-chat-end-btn",
|
|
2718
|
+
onClick: onEndChat,
|
|
2719
|
+
children: "End Chat"
|
|
2720
|
+
}
|
|
2721
|
+
) })
|
|
2722
|
+
] })
|
|
2711
2723
|
] });
|
|
2712
2724
|
};
|
|
2713
2725
|
|
|
@@ -2738,6 +2750,7 @@ var ChatBubble = ({
|
|
|
2738
2750
|
const [typing, setTyping] = useState22(false);
|
|
2739
2751
|
const [unreadCount, setUnreadCount] = useState22(0);
|
|
2740
2752
|
const [initialized, setInitialized] = useState22(false);
|
|
2753
|
+
const [ended, setEnded] = useState22(false);
|
|
2741
2754
|
const seenMessageIds = useRef3(/* @__PURE__ */ new Set());
|
|
2742
2755
|
const connectionRef = useRef3(null);
|
|
2743
2756
|
const setupListeners = useCallback22((conn) => {
|
|
@@ -2850,6 +2863,30 @@ var ChatBubble = ({
|
|
|
2850
2863
|
const handleTyping = () => {
|
|
2851
2864
|
connectionRef.current?.sendTyping();
|
|
2852
2865
|
};
|
|
2866
|
+
const handleEndChat = async () => {
|
|
2867
|
+
const conn = connectionRef.current;
|
|
2868
|
+
if (!conn) return;
|
|
2869
|
+
try {
|
|
2870
|
+
await conn.close();
|
|
2871
|
+
} catch (error) {
|
|
2872
|
+
console.error("Failed to close chat:", error);
|
|
2873
|
+
}
|
|
2874
|
+
if (typeof localStorage !== "undefined") {
|
|
2875
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
2876
|
+
}
|
|
2877
|
+
setEnded(true);
|
|
2878
|
+
connectionRef.current?.disconnect();
|
|
2879
|
+
connectionRef.current = null;
|
|
2880
|
+
setConnection(null);
|
|
2881
|
+
setInitialized(false);
|
|
2882
|
+
setConversationId(null);
|
|
2883
|
+
};
|
|
2884
|
+
const handleStartNewChat = () => {
|
|
2885
|
+
setEnded(false);
|
|
2886
|
+
setMessages([]);
|
|
2887
|
+
seenMessageIds.current.clear();
|
|
2888
|
+
initChat();
|
|
2889
|
+
};
|
|
2853
2890
|
useEffect21(() => {
|
|
2854
2891
|
return () => {
|
|
2855
2892
|
connectionRef.current?.disconnect();
|
|
@@ -2869,11 +2906,13 @@ var ChatBubble = ({
|
|
|
2869
2906
|
onSend: handleSend,
|
|
2870
2907
|
onTyping: handleTyping,
|
|
2871
2908
|
onClose: handleClose,
|
|
2909
|
+
onEndChat: handleEndChat,
|
|
2872
2910
|
title,
|
|
2873
2911
|
subtitle,
|
|
2874
2912
|
placeholder,
|
|
2875
2913
|
loading,
|
|
2876
|
-
typing
|
|
2914
|
+
typing,
|
|
2915
|
+
ended
|
|
2877
2916
|
}
|
|
2878
2917
|
),
|
|
2879
2918
|
/* @__PURE__ */ jsxs5(
|