@alliance-droid/chat-widget 0.1.1 → 0.1.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.
@@ -40,16 +40,45 @@
40
40
  return position === 'bottom-left' ? 'left-4' : 'right-4';
41
41
  });
42
42
 
43
+ // Flex alignment based on position
44
+ const alignmentClass = $derived(() => {
45
+ return position === 'bottom-left' ? 'items-start' : 'items-end';
46
+ });
47
+
43
48
  // Theme class
44
49
  const themeClass = $derived(() => {
45
50
  if (theme === 'auto') return '';
46
51
  return theme;
47
52
  });
48
53
 
54
+ let hasConnected = $state(false);
55
+
49
56
  function toggleOpen() {
50
57
  isOpen = !isOpen;
51
58
  if (isOpen) {
52
59
  unreadCount = 0;
60
+ // Connect on first open
61
+ if (!hasConnected) {
62
+ hasConnected = true;
63
+ connect({
64
+ serverUrl,
65
+ apiKey,
66
+ reconnect,
67
+ reconnectInterval,
68
+ userId,
69
+ userMeta
70
+ });
71
+
72
+ // Add greeting message if provided
73
+ if (greeting) {
74
+ chatStore.addMessage({
75
+ id: 'greeting',
76
+ content: greeting,
77
+ sender: 'system',
78
+ timestamp: Date.now()
79
+ });
80
+ }
81
+ }
53
82
  }
54
83
  }
55
84
 
@@ -66,24 +95,7 @@
66
95
  }
67
96
 
68
97
  onMount(() => {
69
- connect({
70
- serverUrl,
71
- apiKey,
72
- reconnect,
73
- reconnectInterval,
74
- userId,
75
- userMeta
76
- });
77
-
78
- // Add greeting message if provided
79
- if (greeting) {
80
- chatStore.addMessage({
81
- id: 'greeting',
82
- content: greeting,
83
- sender: 'system',
84
- timestamp: Date.now()
85
- });
86
- }
98
+ // Connection is now deferred until widget is opened
87
99
  });
88
100
 
89
101
  onDestroy(() => {
@@ -91,10 +103,10 @@
91
103
  });
92
104
  </script>
93
105
 
94
- <div class="fixed bottom-4 {positionClasses()} z-50 {themeClass()} {className}">
106
+ <div class="fixed bottom-4 {positionClasses()} z-50 flex flex-col {alignmentClass()} {themeClass()} {className}">
95
107
  {#if isOpen}
96
108
  <div
97
- class="w-[380px] h-[600px] max-h-[80vh] mb-4 animate-in fade-in slide-in-from-bottom-4 duration-200"
109
+ class="w-[380px] max-w-[calc(100vw-2rem)] h-[600px] max-h-[80vh] mb-4 overflow-hidden animate-in fade-in slide-in-from-bottom-4 duration-200"
98
110
  >
99
111
  <ChatPanel
100
112
  messages={$messages}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alliance-droid/chat-widget",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Svelte chat widget with AI support and human escalation",
5
5
  "type": "module",
6
6
  "scripts": {