@diffsome/react 1.2.13 → 1.2.14
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 +20 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +46 -7
- package/dist/index.mjs +46 -7
- package/package.json +1 -1
package/dist/chat.css
CHANGED
|
@@ -294,6 +294,26 @@
|
|
|
294
294
|
font-size: 14px;
|
|
295
295
|
border-top: 1px solid var(--diffsome-chat-border);
|
|
296
296
|
background: var(--diffsome-chat-bg);
|
|
297
|
+
display: flex;
|
|
298
|
+
flex-direction: column;
|
|
299
|
+
align-items: center;
|
|
300
|
+
gap: 12px;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.diffsome-chat-new-btn {
|
|
304
|
+
background: var(--diffsome-chat-primary);
|
|
305
|
+
color: white;
|
|
306
|
+
border: none;
|
|
307
|
+
padding: 8px 20px;
|
|
308
|
+
border-radius: 20px;
|
|
309
|
+
font-size: 14px;
|
|
310
|
+
font-weight: 500;
|
|
311
|
+
cursor: pointer;
|
|
312
|
+
transition: background-color 0.2s ease;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
.diffsome-chat-new-btn:hover {
|
|
316
|
+
background: var(--diffsome-chat-primary-dark);
|
|
297
317
|
}
|
|
298
318
|
|
|
299
319
|
/* System Message */
|
package/dist/index.d.mts
CHANGED
|
@@ -866,6 +866,8 @@ interface ChatBubbleProps {
|
|
|
866
866
|
onOpen?: () => void;
|
|
867
867
|
/** Callback when chat is closed */
|
|
868
868
|
onClose?: () => void;
|
|
869
|
+
/** Member auth token for logged-in users (optional) */
|
|
870
|
+
memberToken?: string;
|
|
869
871
|
}
|
|
870
872
|
declare const ChatBubble: React__default.FC<ChatBubbleProps>;
|
|
871
873
|
|
|
@@ -885,6 +887,7 @@ interface ChatWidgetProps {
|
|
|
885
887
|
onTyping?: () => void;
|
|
886
888
|
onClose?: () => void;
|
|
887
889
|
onEndChat?: () => void;
|
|
890
|
+
onStartNewChat?: () => void;
|
|
888
891
|
title?: string;
|
|
889
892
|
subtitle?: string;
|
|
890
893
|
placeholder?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -866,6 +866,8 @@ interface ChatBubbleProps {
|
|
|
866
866
|
onOpen?: () => void;
|
|
867
867
|
/** Callback when chat is closed */
|
|
868
868
|
onClose?: () => void;
|
|
869
|
+
/** Member auth token for logged-in users (optional) */
|
|
870
|
+
memberToken?: string;
|
|
869
871
|
}
|
|
870
872
|
declare const ChatBubble: React__default.FC<ChatBubbleProps>;
|
|
871
873
|
|
|
@@ -885,6 +887,7 @@ interface ChatWidgetProps {
|
|
|
885
887
|
onTyping?: () => void;
|
|
886
888
|
onClose?: () => void;
|
|
887
889
|
onEndChat?: () => void;
|
|
890
|
+
onStartNewChat?: () => void;
|
|
888
891
|
title?: string;
|
|
889
892
|
subtitle?: string;
|
|
890
893
|
placeholder?: string;
|
package/dist/index.js
CHANGED
|
@@ -2720,6 +2720,7 @@ var ChatWidget = ({
|
|
|
2720
2720
|
onTyping,
|
|
2721
2721
|
onClose,
|
|
2722
2722
|
onEndChat,
|
|
2723
|
+
onStartNewChat,
|
|
2723
2724
|
title = "Chat Support",
|
|
2724
2725
|
subtitle = "We typically reply within a few minutes",
|
|
2725
2726
|
placeholder = "Type a message...",
|
|
@@ -2793,7 +2794,17 @@ var ChatWidget = ({
|
|
|
2793
2794
|
] }),
|
|
2794
2795
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ref: messagesEndRef })
|
|
2795
2796
|
] }) }),
|
|
2796
|
-
ended ? /* @__PURE__ */ (0, import_jsx_runtime5.
|
|
2797
|
+
ended ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "diffsome-chat-ended", children: [
|
|
2798
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "Chat ended. Thank you!" }),
|
|
2799
|
+
onStartNewChat && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2800
|
+
"button",
|
|
2801
|
+
{
|
|
2802
|
+
className: "diffsome-chat-new-btn",
|
|
2803
|
+
onClick: onStartNewChat,
|
|
2804
|
+
children: "Start New Chat"
|
|
2805
|
+
}
|
|
2806
|
+
)
|
|
2807
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
2797
2808
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2798
2809
|
ChatInput,
|
|
2799
2810
|
{
|
|
@@ -2818,6 +2829,7 @@ var ChatWidget = ({
|
|
|
2818
2829
|
// src/components/chat/ChatBubble.tsx
|
|
2819
2830
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
2820
2831
|
var STORAGE_KEY = "diffsome_conversation_id";
|
|
2832
|
+
var MEMBER_STORAGE_PREFIX = "diffsome_member_conversation_";
|
|
2821
2833
|
var ChatBubble = ({
|
|
2822
2834
|
client,
|
|
2823
2835
|
title = "Chat Support",
|
|
@@ -2832,8 +2844,33 @@ var ChatBubble = ({
|
|
|
2832
2844
|
showUnreadBadge = true,
|
|
2833
2845
|
className = "",
|
|
2834
2846
|
onOpen,
|
|
2835
|
-
onClose
|
|
2847
|
+
onClose,
|
|
2848
|
+
memberToken
|
|
2836
2849
|
}) => {
|
|
2850
|
+
(0, import_react24.useEffect)(() => {
|
|
2851
|
+
if (memberToken) {
|
|
2852
|
+
client.setToken(memberToken);
|
|
2853
|
+
} else {
|
|
2854
|
+
client.setToken(null);
|
|
2855
|
+
}
|
|
2856
|
+
if (initialized) {
|
|
2857
|
+
connectionRef.current?.disconnect();
|
|
2858
|
+
connectionRef.current = null;
|
|
2859
|
+
setConnection(null);
|
|
2860
|
+
setMessages([]);
|
|
2861
|
+
setConversationId(null);
|
|
2862
|
+
setInitialized(false);
|
|
2863
|
+
setEnded(false);
|
|
2864
|
+
seenMessageIds.current.clear();
|
|
2865
|
+
}
|
|
2866
|
+
}, [client, memberToken]);
|
|
2867
|
+
const getStorageKey = (0, import_react24.useCallback)(() => {
|
|
2868
|
+
if (memberToken) {
|
|
2869
|
+
const hash = memberToken.slice(-8);
|
|
2870
|
+
return `${MEMBER_STORAGE_PREFIX}${hash}`;
|
|
2871
|
+
}
|
|
2872
|
+
return STORAGE_KEY;
|
|
2873
|
+
}, [memberToken]);
|
|
2837
2874
|
const [isOpen, setIsOpen] = (0, import_react24.useState)(false);
|
|
2838
2875
|
const [messages, setMessages] = (0, import_react24.useState)([]);
|
|
2839
2876
|
const [conversationId, setConversationId] = (0, import_react24.useState)(null);
|
|
@@ -2866,10 +2903,11 @@ var ChatBubble = ({
|
|
|
2866
2903
|
const initChat = (0, import_react24.useCallback)(async () => {
|
|
2867
2904
|
if (initialized || connectionRef.current) return;
|
|
2868
2905
|
setLoading(true);
|
|
2906
|
+
const storageKey = getStorageKey();
|
|
2869
2907
|
try {
|
|
2870
2908
|
let savedConvId = null;
|
|
2871
2909
|
if (typeof localStorage !== "undefined") {
|
|
2872
|
-
const saved = localStorage.getItem(
|
|
2910
|
+
const saved = localStorage.getItem(storageKey);
|
|
2873
2911
|
if (saved) {
|
|
2874
2912
|
savedConvId = parseInt(saved, 10);
|
|
2875
2913
|
}
|
|
@@ -2888,7 +2926,7 @@ var ChatBubble = ({
|
|
|
2888
2926
|
return;
|
|
2889
2927
|
} catch (error) {
|
|
2890
2928
|
console.log("Could not restore conversation, starting new one");
|
|
2891
|
-
localStorage.removeItem(
|
|
2929
|
+
localStorage.removeItem(storageKey);
|
|
2892
2930
|
}
|
|
2893
2931
|
}
|
|
2894
2932
|
const result = await client.chat.start({
|
|
@@ -2899,7 +2937,7 @@ var ChatBubble = ({
|
|
|
2899
2937
|
const newConvId = result.conversation_id;
|
|
2900
2938
|
setConversationId(newConvId);
|
|
2901
2939
|
if (typeof localStorage !== "undefined") {
|
|
2902
|
-
localStorage.setItem(
|
|
2940
|
+
localStorage.setItem(storageKey, newConvId.toString());
|
|
2903
2941
|
}
|
|
2904
2942
|
const conn = client.chat.connect(newConvId);
|
|
2905
2943
|
connectionRef.current = conn;
|
|
@@ -2914,7 +2952,7 @@ var ChatBubble = ({
|
|
|
2914
2952
|
} finally {
|
|
2915
2953
|
setLoading(false);
|
|
2916
2954
|
}
|
|
2917
|
-
}, [client.chat, initialized, setupListeners, visitorName, visitorEmail, greeting]);
|
|
2955
|
+
}, [client.chat, initialized, setupListeners, visitorName, visitorEmail, greeting, getStorageKey]);
|
|
2918
2956
|
const handleOpen = () => {
|
|
2919
2957
|
setIsOpen(true);
|
|
2920
2958
|
setUnreadCount(0);
|
|
@@ -2964,7 +3002,7 @@ var ChatBubble = ({
|
|
|
2964
3002
|
console.error("Failed to close chat:", error);
|
|
2965
3003
|
}
|
|
2966
3004
|
if (typeof localStorage !== "undefined") {
|
|
2967
|
-
localStorage.removeItem(
|
|
3005
|
+
localStorage.removeItem(getStorageKey());
|
|
2968
3006
|
}
|
|
2969
3007
|
setEnded(true);
|
|
2970
3008
|
connectionRef.current?.disconnect();
|
|
@@ -2999,6 +3037,7 @@ var ChatBubble = ({
|
|
|
2999
3037
|
onTyping: handleTyping,
|
|
3000
3038
|
onClose: handleClose,
|
|
3001
3039
|
onEndChat: handleEndChat,
|
|
3040
|
+
onStartNewChat: handleStartNewChat,
|
|
3002
3041
|
title,
|
|
3003
3042
|
subtitle,
|
|
3004
3043
|
placeholder,
|
package/dist/index.mjs
CHANGED
|
@@ -2628,6 +2628,7 @@ var ChatWidget = ({
|
|
|
2628
2628
|
onTyping,
|
|
2629
2629
|
onClose,
|
|
2630
2630
|
onEndChat,
|
|
2631
|
+
onStartNewChat,
|
|
2631
2632
|
title = "Chat Support",
|
|
2632
2633
|
subtitle = "We typically reply within a few minutes",
|
|
2633
2634
|
placeholder = "Type a message...",
|
|
@@ -2701,7 +2702,17 @@ var ChatWidget = ({
|
|
|
2701
2702
|
] }),
|
|
2702
2703
|
/* @__PURE__ */ jsx5("div", { ref: messagesEndRef })
|
|
2703
2704
|
] }) }),
|
|
2704
|
-
ended ? /* @__PURE__ */
|
|
2705
|
+
ended ? /* @__PURE__ */ jsxs4("div", { className: "diffsome-chat-ended", children: [
|
|
2706
|
+
/* @__PURE__ */ jsx5("span", { children: "Chat ended. Thank you!" }),
|
|
2707
|
+
onStartNewChat && /* @__PURE__ */ jsx5(
|
|
2708
|
+
"button",
|
|
2709
|
+
{
|
|
2710
|
+
className: "diffsome-chat-new-btn",
|
|
2711
|
+
onClick: onStartNewChat,
|
|
2712
|
+
children: "Start New Chat"
|
|
2713
|
+
}
|
|
2714
|
+
)
|
|
2715
|
+
] }) : /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
2705
2716
|
/* @__PURE__ */ jsx5(
|
|
2706
2717
|
ChatInput,
|
|
2707
2718
|
{
|
|
@@ -2726,6 +2737,7 @@ var ChatWidget = ({
|
|
|
2726
2737
|
// src/components/chat/ChatBubble.tsx
|
|
2727
2738
|
import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
2728
2739
|
var STORAGE_KEY = "diffsome_conversation_id";
|
|
2740
|
+
var MEMBER_STORAGE_PREFIX = "diffsome_member_conversation_";
|
|
2729
2741
|
var ChatBubble = ({
|
|
2730
2742
|
client,
|
|
2731
2743
|
title = "Chat Support",
|
|
@@ -2740,8 +2752,33 @@ var ChatBubble = ({
|
|
|
2740
2752
|
showUnreadBadge = true,
|
|
2741
2753
|
className = "",
|
|
2742
2754
|
onOpen,
|
|
2743
|
-
onClose
|
|
2755
|
+
onClose,
|
|
2756
|
+
memberToken
|
|
2744
2757
|
}) => {
|
|
2758
|
+
useEffect21(() => {
|
|
2759
|
+
if (memberToken) {
|
|
2760
|
+
client.setToken(memberToken);
|
|
2761
|
+
} else {
|
|
2762
|
+
client.setToken(null);
|
|
2763
|
+
}
|
|
2764
|
+
if (initialized) {
|
|
2765
|
+
connectionRef.current?.disconnect();
|
|
2766
|
+
connectionRef.current = null;
|
|
2767
|
+
setConnection(null);
|
|
2768
|
+
setMessages([]);
|
|
2769
|
+
setConversationId(null);
|
|
2770
|
+
setInitialized(false);
|
|
2771
|
+
setEnded(false);
|
|
2772
|
+
seenMessageIds.current.clear();
|
|
2773
|
+
}
|
|
2774
|
+
}, [client, memberToken]);
|
|
2775
|
+
const getStorageKey = useCallback22(() => {
|
|
2776
|
+
if (memberToken) {
|
|
2777
|
+
const hash = memberToken.slice(-8);
|
|
2778
|
+
return `${MEMBER_STORAGE_PREFIX}${hash}`;
|
|
2779
|
+
}
|
|
2780
|
+
return STORAGE_KEY;
|
|
2781
|
+
}, [memberToken]);
|
|
2745
2782
|
const [isOpen, setIsOpen] = useState22(false);
|
|
2746
2783
|
const [messages, setMessages] = useState22([]);
|
|
2747
2784
|
const [conversationId, setConversationId] = useState22(null);
|
|
@@ -2774,10 +2811,11 @@ var ChatBubble = ({
|
|
|
2774
2811
|
const initChat = useCallback22(async () => {
|
|
2775
2812
|
if (initialized || connectionRef.current) return;
|
|
2776
2813
|
setLoading(true);
|
|
2814
|
+
const storageKey = getStorageKey();
|
|
2777
2815
|
try {
|
|
2778
2816
|
let savedConvId = null;
|
|
2779
2817
|
if (typeof localStorage !== "undefined") {
|
|
2780
|
-
const saved = localStorage.getItem(
|
|
2818
|
+
const saved = localStorage.getItem(storageKey);
|
|
2781
2819
|
if (saved) {
|
|
2782
2820
|
savedConvId = parseInt(saved, 10);
|
|
2783
2821
|
}
|
|
@@ -2796,7 +2834,7 @@ var ChatBubble = ({
|
|
|
2796
2834
|
return;
|
|
2797
2835
|
} catch (error) {
|
|
2798
2836
|
console.log("Could not restore conversation, starting new one");
|
|
2799
|
-
localStorage.removeItem(
|
|
2837
|
+
localStorage.removeItem(storageKey);
|
|
2800
2838
|
}
|
|
2801
2839
|
}
|
|
2802
2840
|
const result = await client.chat.start({
|
|
@@ -2807,7 +2845,7 @@ var ChatBubble = ({
|
|
|
2807
2845
|
const newConvId = result.conversation_id;
|
|
2808
2846
|
setConversationId(newConvId);
|
|
2809
2847
|
if (typeof localStorage !== "undefined") {
|
|
2810
|
-
localStorage.setItem(
|
|
2848
|
+
localStorage.setItem(storageKey, newConvId.toString());
|
|
2811
2849
|
}
|
|
2812
2850
|
const conn = client.chat.connect(newConvId);
|
|
2813
2851
|
connectionRef.current = conn;
|
|
@@ -2822,7 +2860,7 @@ var ChatBubble = ({
|
|
|
2822
2860
|
} finally {
|
|
2823
2861
|
setLoading(false);
|
|
2824
2862
|
}
|
|
2825
|
-
}, [client.chat, initialized, setupListeners, visitorName, visitorEmail, greeting]);
|
|
2863
|
+
}, [client.chat, initialized, setupListeners, visitorName, visitorEmail, greeting, getStorageKey]);
|
|
2826
2864
|
const handleOpen = () => {
|
|
2827
2865
|
setIsOpen(true);
|
|
2828
2866
|
setUnreadCount(0);
|
|
@@ -2872,7 +2910,7 @@ var ChatBubble = ({
|
|
|
2872
2910
|
console.error("Failed to close chat:", error);
|
|
2873
2911
|
}
|
|
2874
2912
|
if (typeof localStorage !== "undefined") {
|
|
2875
|
-
localStorage.removeItem(
|
|
2913
|
+
localStorage.removeItem(getStorageKey());
|
|
2876
2914
|
}
|
|
2877
2915
|
setEnded(true);
|
|
2878
2916
|
connectionRef.current?.disconnect();
|
|
@@ -2907,6 +2945,7 @@ var ChatBubble = ({
|
|
|
2907
2945
|
onTyping: handleTyping,
|
|
2908
2946
|
onClose: handleClose,
|
|
2909
2947
|
onEndChat: handleEndChat,
|
|
2948
|
+
onStartNewChat: handleStartNewChat,
|
|
2910
2949
|
title,
|
|
2911
2950
|
subtitle,
|
|
2912
2951
|
placeholder,
|