@chat-leo/chatleo 0.0.0-stage → 2.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.
Files changed (144) hide show
  1. package/LICENSE +21 -0
  2. package/dist/chatleo/chatleo.esm.js +1 -0
  3. package/dist/chatleo/index.esm.js +1 -0
  4. package/dist/chatleo/p-43ada232.entry.js +1 -0
  5. package/dist/chatleo/p-4485e141.entry.js +1 -0
  6. package/dist/chatleo/p-BnCPdbII.js +1 -0
  7. package/dist/chatleo/p-C-l90Wre.js +1 -0
  8. package/dist/chatleo/p-DQuL1Twl.js +1 -0
  9. package/dist/chatleo/p-DmL518NK.js +3 -0
  10. package/dist/chatleo/p-aed60255.entry.js +1 -0
  11. package/dist/cjs/app-globals-V2Kpy_OQ.js +5 -0
  12. package/dist/cjs/chatleo-avatar_13.cjs.entry.js +2986 -0
  13. package/dist/cjs/chatleo-call-adapter-B2OfC0VZ.js +35 -0
  14. package/dist/cjs/chatleo-chat-input.cjs.entry.js +67 -0
  15. package/dist/cjs/chatleo.cjs.js +25 -0
  16. package/dist/cjs/index-DkSDLR0y.js +56 -0
  17. package/dist/cjs/index-Dxw4YCA_.js +1741 -0
  18. package/dist/cjs/index.cjs.js +7 -0
  19. package/dist/cjs/loader.cjs.js +13 -0
  20. package/dist/cjs/my-component.cjs.entry.js +33 -0
  21. package/dist/collection/__mocks__/stencil-core.js +26 -0
  22. package/dist/collection/collection-manifest.json +27 -0
  23. package/dist/collection/components/chatleo-avatar/chatleo-avatar.css +40 -0
  24. package/dist/collection/components/chatleo-avatar/chatleo-avatar.js +116 -0
  25. package/dist/collection/components/chatleo-chat/chatleo-chat.css +108 -0
  26. package/dist/collection/components/chatleo-chat/chatleo-chat.js +459 -0
  27. package/dist/collection/components/chatleo-chat-header/chatleo-chat-header.css +22 -0
  28. package/dist/collection/components/chatleo-chat-header/chatleo-chat-header.js +105 -0
  29. package/dist/collection/components/chatleo-chat-input/chatleo-chat-input.css +84 -0
  30. package/dist/collection/components/chatleo-chat-input/chatleo-chat-input.js +141 -0
  31. package/dist/collection/components/chatleo-chat-message/chatleo-chat-message.css +149 -0
  32. package/dist/collection/components/chatleo-chat-message/chatleo-chat-message.js +259 -0
  33. package/dist/collection/components/chatleo-component/chatleo-component.css +271 -0
  34. package/dist/collection/components/chatleo-component/chatleo-component.js +1366 -0
  35. package/dist/collection/components/chatleo-new-message-selector/chatleo-new-message-selector.css +96 -0
  36. package/dist/collection/components/chatleo-new-message-selector/chatleo-new-message-selector.js +231 -0
  37. package/dist/collection/components/chatleo-rich-input/chatleo-rich-input.css +352 -0
  38. package/dist/collection/components/chatleo-rich-input/chatleo-rich-input.js +976 -0
  39. package/dist/collection/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.css +169 -0
  40. package/dist/collection/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.js +400 -0
  41. package/dist/collection/components/chatleo-room-list/chatleo-room-list.css +111 -0
  42. package/dist/collection/components/chatleo-room-list/chatleo-room-list.js +180 -0
  43. package/dist/collection/components/chatleo-room-tile-component/chatleo-room-tile-component.css +110 -0
  44. package/dist/collection/components/chatleo-room-tile-component/chatleo-room-tile-component.js +241 -0
  45. package/dist/collection/components/chatleo-room-view/chatleo-room-view.css +93 -0
  46. package/dist/collection/components/chatleo-room-view/chatleo-room-view.js +593 -0
  47. package/dist/collection/components/chatleo-tray-component/chatleo-tray-component.css +284 -0
  48. package/dist/collection/components/chatleo-tray-component/chatleo-tray-component.js +391 -0
  49. package/dist/collection/components/chatleo-user-tile/chatleo-user-tile.css +56 -0
  50. package/dist/collection/components/chatleo-user-tile/chatleo-user-tile.js +149 -0
  51. package/dist/collection/components/my-component/my-component.css +4 -0
  52. package/dist/collection/components/my-component/my-component.js +95 -0
  53. package/dist/collection/index.js +10 -0
  54. package/dist/collection/utils/call-entry.js +34 -0
  55. package/dist/collection/utils/delivery.js +7 -0
  56. package/dist/collection/utils/utils.js +51 -0
  57. package/dist/components/chatleo-avatar.d.ts +11 -0
  58. package/dist/components/chatleo-avatar.js +1 -0
  59. package/dist/components/chatleo-chat-header.d.ts +11 -0
  60. package/dist/components/chatleo-chat-header.js +1 -0
  61. package/dist/components/chatleo-chat-input.d.ts +11 -0
  62. package/dist/components/chatleo-chat-input.js +1 -0
  63. package/dist/components/chatleo-chat-message.d.ts +11 -0
  64. package/dist/components/chatleo-chat-message.js +1 -0
  65. package/dist/components/chatleo-chat.d.ts +11 -0
  66. package/dist/components/chatleo-chat.js +1 -0
  67. package/dist/components/chatleo-component.d.ts +11 -0
  68. package/dist/components/chatleo-component.js +1 -0
  69. package/dist/components/chatleo-new-message-selector.d.ts +11 -0
  70. package/dist/components/chatleo-new-message-selector.js +1 -0
  71. package/dist/components/chatleo-rich-input.d.ts +11 -0
  72. package/dist/components/chatleo-rich-input.js +1 -0
  73. package/dist/components/chatleo-rich-message-renderer.d.ts +11 -0
  74. package/dist/components/chatleo-rich-message-renderer.js +1 -0
  75. package/dist/components/chatleo-room-list.d.ts +11 -0
  76. package/dist/components/chatleo-room-list.js +1 -0
  77. package/dist/components/chatleo-room-tile-component.d.ts +11 -0
  78. package/dist/components/chatleo-room-tile-component.js +1 -0
  79. package/dist/components/chatleo-room-view.d.ts +11 -0
  80. package/dist/components/chatleo-room-view.js +1 -0
  81. package/dist/components/chatleo-tray-component.d.ts +11 -0
  82. package/dist/components/chatleo-tray-component.js +1 -0
  83. package/dist/components/chatleo-user-tile.d.ts +11 -0
  84. package/dist/components/chatleo-user-tile.js +1 -0
  85. package/dist/components/index.d.ts +35 -0
  86. package/dist/components/index.js +1 -0
  87. package/dist/components/my-component.d.ts +11 -0
  88. package/dist/components/my-component.js +1 -0
  89. package/dist/components/p-8kvQ-Uh-.js +1 -0
  90. package/dist/components/p-B7cdqAgv.js +1 -0
  91. package/dist/components/p-BdiOcOYZ.js +1 -0
  92. package/dist/components/p-BlbDSb7D.js +1 -0
  93. package/dist/components/p-BnCPdbII.js +1 -0
  94. package/dist/components/p-C-v19aUJ.js +1 -0
  95. package/dist/components/p-C1mF0s8g.js +1 -0
  96. package/dist/components/p-CRtBdzP3.js +1 -0
  97. package/dist/components/p-CfayCm9O.js +1 -0
  98. package/dist/components/p-DGjAxoQy.js +1 -0
  99. package/dist/components/p-Exj_2-yI.js +1 -0
  100. package/dist/components/p-XlwGxsqT.js +1 -0
  101. package/dist/components/p-fjMaTJam.js +1 -0
  102. package/dist/components/p-xt4kzz3B.js +1 -0
  103. package/dist/esm/app-globals-DQuL1Twl.js +3 -0
  104. package/dist/esm/chatleo-avatar_13.entry.js +2972 -0
  105. package/dist/esm/chatleo-call-adapter-BnCPdbII.js +33 -0
  106. package/dist/esm/chatleo-chat-input.entry.js +65 -0
  107. package/dist/esm/chatleo.js +21 -0
  108. package/dist/esm/index-C-l90Wre.js +53 -0
  109. package/dist/esm/index-DmL518NK.js +1733 -0
  110. package/dist/esm/index.js +1 -0
  111. package/dist/esm/loader.js +11 -0
  112. package/dist/esm/my-component.entry.js +31 -0
  113. package/dist/index.cjs.js +1 -0
  114. package/dist/index.js +1 -0
  115. package/dist/types/__mocks__/stencil-core.d.ts +24 -0
  116. package/dist/types/components/chatleo-avatar/chatleo-avatar.d.ts +27 -0
  117. package/dist/types/components/chatleo-chat/chatleo-chat.d.ts +75 -0
  118. package/dist/types/components/chatleo-chat-header/chatleo-chat-header.d.ts +27 -0
  119. package/dist/types/components/chatleo-chat-input/chatleo-chat-input.d.ts +31 -0
  120. package/dist/types/components/chatleo-chat-message/chatleo-chat-message.d.ts +22 -0
  121. package/dist/types/components/chatleo-component/chatleo-component.d.ts +278 -0
  122. package/dist/types/components/chatleo-new-message-selector/chatleo-new-message-selector.d.ts +68 -0
  123. package/dist/types/components/chatleo-rich-input/chatleo-rich-input.d.ts +216 -0
  124. package/dist/types/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.d.ts +77 -0
  125. package/dist/types/components/chatleo-room-list/chatleo-room-list.d.ts +52 -0
  126. package/dist/types/components/chatleo-room-tile-component/chatleo-room-tile-component.d.ts +59 -0
  127. package/dist/types/components/chatleo-room-view/chatleo-room-view.d.ts +91 -0
  128. package/dist/types/components/chatleo-tray-component/chatleo-tray-component.d.ts +112 -0
  129. package/dist/types/components/chatleo-user-tile/chatleo-user-tile.d.ts +36 -0
  130. package/dist/types/components/my-component/my-component.d.ts +16 -0
  131. package/dist/types/components.d.ts +1593 -0
  132. package/dist/types/index.d.ts +12 -0
  133. package/dist/types/stencil-public-runtime.d.ts +1879 -0
  134. package/dist/types/utils/call-entry.d.ts +9 -0
  135. package/dist/types/utils/delivery.d.ts +7 -0
  136. package/dist/types/utils/utils.d.ts +24 -0
  137. package/loader/cdn.js +1 -0
  138. package/loader/index.cjs.js +1 -0
  139. package/loader/index.d.ts +24 -0
  140. package/loader/index.es2017.js +1 -0
  141. package/loader/index.js +2 -0
  142. package/package.json +70 -3
  143. package/readme.md +111 -0
  144. package/README.md +0 -3
@@ -0,0 +1,284 @@
1
+ :host {
2
+ /* Component-specific variables */
3
+ --hover-color: #f9f9f9;
4
+ --shadow-light: rgba(0, 0, 0, 0.1);
5
+ --z-index-tray: 1000;
6
+ --tray-height: 52px;
7
+ --gap-small: 12px;
8
+ --gap-medium: 16px;
9
+ --transition-duration: 0.3s;
10
+ --gray-black: #171A1F;
11
+ /* Fixed widths to keep layout stable */
12
+ --chat-panel-width: 280px;
13
+ --selector-panel-width: 320px;
14
+ --messages-panel-width: 50vw;
15
+ }
16
+
17
+ .tray-container {
18
+ position: fixed;
19
+ bottom: 0;
20
+ right: 20px;
21
+ z-index: var(--z-index-tray);
22
+ display: flex;
23
+ flex-direction: row;
24
+ align-items: flex-end;
25
+ gap: var(--gap-small);
26
+ font-family: var(--font-primary), sans-serif;
27
+ }
28
+
29
+ .chat-panel {
30
+ width: var(--chat-panel-width);
31
+ flex: 0 0 var(--chat-panel-width);
32
+ box-sizing: border-box;
33
+ position: relative;
34
+ background: var(--bg-primary);
35
+ border: 1px solid var(--border-color);
36
+ border-radius: var(--border-radius) var(--border-radius) 0 0;
37
+ box-shadow: 0 -2px 10px var(--shadow-light);
38
+ overflow: hidden;
39
+ max-height: var(--tray-height); /* Height of just the tray when closed */
40
+ transition: max-height var(--transition-duration) ease-in-out;
41
+ }
42
+
43
+ .chat-panel.open {
44
+ max-height: calc(50vh + var(--tray-height)); /* Chat content height + tray height */
45
+ }
46
+
47
+ .tray {
48
+ display: flex;
49
+ flex-direction: row;
50
+ align-items: center;
51
+ background: var(--bg-primary);
52
+ border-bottom: 1px solid var(--border-light);
53
+ height: var(--tray-height);
54
+ box-sizing: border-box; /* keep padding inside the width */
55
+ width: 100%;
56
+ padding: 0 8px; /* use internal spacing */
57
+ margin: 0; /* remove overflow-causing margins */
58
+ }
59
+
60
+ /* override avatar size */
61
+ chatleo-avatar {
62
+ --avatar-size: 36px;
63
+ }
64
+
65
+ .title {
66
+ margin: 0 8px;
67
+ flex: 1 1 auto; /* grow to take remaining space */
68
+ min-width: 0; /* allow shrinking inside flex */
69
+ overflow: hidden; /* handle long text */
70
+ text-overflow: ellipsis;
71
+ white-space: nowrap;
72
+ color: var(--gray-black, #171A1F);
73
+ font-size: 14px;
74
+ }
75
+
76
+ .selector-panel {
77
+ display: none;
78
+ background: var(--bg-primary);
79
+ border: 1px solid var(--border-color);
80
+ border-radius: var(--border-radius) var(--border-radius) 0 0;
81
+ box-shadow: 0 -2px 10px var(--shadow-light);
82
+ box-sizing: border-box;
83
+ /* give it a real width and prevent shrinking */
84
+ width: var(--selector-panel-width);
85
+ flex: 0 0 var(--selector-panel-width);
86
+ overflow: hidden;
87
+ max-height: var(--tray-height); /* collapsed by default */
88
+ }
89
+
90
+ .selector-panel.open {
91
+ /* stretch inner selector vertically */
92
+ display: flex;
93
+ flex-direction: column;
94
+ max-height: calc(50vh + var(--tray-height));
95
+ }
96
+
97
+ .messages-panel {
98
+ display: none;
99
+ background: var(--bg-primary);
100
+ border: 1px solid var(--border-color);
101
+ border-radius: var(--border-radius) var(--border-radius) 0 0;
102
+ box-shadow: 0 -2px 10px var(--shadow-light);
103
+ box-sizing: border-box;
104
+ /* give it a real width and prevent shrinking */
105
+ width: var(--messages-panel-width);
106
+ overflow: hidden;
107
+ position: relative;
108
+ max-height: 70vh;
109
+ flex-direction: column;
110
+ }
111
+
112
+ .messages-panel.open {
113
+ display: flex;
114
+ }
115
+
116
+ .new-chat-btn {
117
+ border: 0;
118
+ background: transparent;
119
+ cursor: pointer;
120
+ padding: 0;
121
+ margin: 0 8px;
122
+ /* prevent controls from growing */
123
+ flex: 0 0 auto;
124
+ color: #565D6D;
125
+ }
126
+
127
+ .chat-tray-btn {
128
+ border: 0;
129
+ background: transparent;
130
+ cursor: pointer;
131
+ padding: 0;
132
+ margin: 0 8px;
133
+ /* prevent controls from growing */
134
+ flex: 0 0 auto;
135
+ color: #565D6D;
136
+ }
137
+
138
+ .chat-content {
139
+ /*background: var(--bg-primary);*/
140
+ overflow: hidden;
141
+ }
142
+
143
+ .chat-content ul {
144
+ margin: 0;
145
+ padding: 0;
146
+ list-style: none;
147
+ overflow-y: auto;
148
+ max-height: calc(50vh - var(--tray-height)); /* Subtract tray and header height */
149
+ }
150
+
151
+ .chat-content li {
152
+ padding: 16px;
153
+ cursor: pointer;
154
+ }
155
+
156
+ .chat-content li:hover {
157
+ background: var(--hover-color);
158
+ }
159
+
160
+ /* Mobile styles */
161
+ @media (max-width: 768px) {
162
+ .chat-panel.open,
163
+ .selector-panel.open {
164
+ max-height: calc(80vh + 60px);
165
+ }
166
+
167
+ .chat-content ul {
168
+ max-height: calc(80vh - 60px);
169
+ }
170
+ }
171
+
172
+ /* */
173
+ .messages-container-header-closer {
174
+ position: absolute;
175
+ top: 4px;
176
+ right: 4px;
177
+ }
178
+
179
+ .messages-container {
180
+ display: block;
181
+ flex: 1 1 auto; /* consume remaining space */
182
+ min-height: 0; /* required for flex children to allow scrolling */
183
+ overflow-y: auto; /* scroll only here */
184
+ overflow-x: hidden;
185
+ padding-right: 16px;
186
+ overscroll-behavior: contain;
187
+ scrollbar-gutter: stable;
188
+ max-width: 100%;
189
+ }
190
+
191
+ .message-group {
192
+ display: flex;
193
+ flex-direction: column;
194
+ gap: 16px;
195
+ }
196
+
197
+ .date-separator {
198
+ text-align: center;
199
+ font-family: var(--font-primary), sans-serif;
200
+ font-weight: 400;
201
+ font-size: 12px;
202
+ line-height: 1.65;
203
+ color: var(--text-secondary);
204
+ }
205
+
206
+ .close-button {
207
+ background: none;
208
+ border: none;
209
+ cursor: pointer;
210
+ font-size: 16px;
211
+ color: var(--text-secondary);
212
+ }
213
+
214
+ /* Connection status banner inside the tray */
215
+ .connection-status-banner {
216
+ display: flex;
217
+ align-items: center;
218
+ gap: 6px;
219
+ padding: 5px 12px;
220
+ font-family: var(--font-primary), sans-serif;
221
+ font-size: 12px;
222
+ font-weight: 600;
223
+ color: #fff;
224
+ background: #f59e0b;
225
+ }
226
+
227
+ .connection-status-banner--disconnected {
228
+ background: #ef4444;
229
+ }
230
+
231
+ .connection-status-banner__dot {
232
+ width: 6px;
233
+ height: 6px;
234
+ border-radius: 50%;
235
+ background: rgba(255,255,255,0.8);
236
+ flex-shrink: 0;
237
+ animation: tray-pulse-dot 1.4s ease-in-out infinite;
238
+ }
239
+
240
+ .connection-status-banner--disconnected .connection-status-banner__dot {
241
+ animation: none;
242
+ }
243
+
244
+ @keyframes tray-pulse-dot {
245
+ 0%, 100% { opacity: 1; }
246
+ 50% { opacity: 0.3; }
247
+ }
248
+
249
+ /* Session-expired banner inside the tray */
250
+ .session-expired-banner {
251
+ display: flex;
252
+ align-items: center;
253
+ gap: 6px;
254
+ background: #fff8e1;
255
+ border-bottom: 1px solid #ffe082;
256
+ padding: 6px 12px;
257
+ font-family: var(--font-primary), sans-serif;
258
+ font-size: 12px;
259
+ color: #795548;
260
+ }
261
+
262
+ .session-expired-banner-icon {
263
+ flex-shrink: 0;
264
+ color: #f59e0b;
265
+ }
266
+
267
+ .session-expired-banner-btn {
268
+ margin-left: auto;
269
+ padding: 3px 10px;
270
+ background: #f59e0b;
271
+ color: #fff;
272
+ border: none;
273
+ border-radius: 4px;
274
+ font-family: var(--font-primary), sans-serif;
275
+ font-size: 12px;
276
+ font-weight: 600;
277
+ cursor: pointer;
278
+ white-space: nowrap;
279
+ }
280
+
281
+ .session-expired-banner-btn:hover {
282
+ background: #d97706;
283
+ }
284
+
@@ -0,0 +1,391 @@
1
+ import { h } from "@stencil/core";
2
+ import { groupMessagesByDate } from "../../utils/utils";
3
+ /**
4
+ * @component ChatLeoTrayComponent
5
+ * @description This component implements a chat tray that can be opened and closed. It contains a list of chat rooms and can open a message panel for a selected room or a user selector to start a new chat.
6
+ * @property {ChatStore} chatStore - An instance of the `ChatStore` class, which provides the state for the chat application.
7
+ * @fires newChatClicked - This event is emitted when the user clicks the "new chat" button.
8
+ * @fires messageChatSent - This event is emitted when a message is sent from the chat panel.
9
+ */
10
+ export class ChatLeoTrayComponent {
11
+ /**
12
+ * An instance of the `ChatStore` class, which provides the state for the chat application.
13
+ */
14
+ chatStore;
15
+ isChatOpen = false;
16
+ isNewChatSelectorOpen = false;
17
+ isMessagesOpen = false;
18
+ selectedRoomId;
19
+ isPending = false;
20
+ _version = 0;
21
+ isSessionExpired = false;
22
+ connectionStatus = 'disconnected';
23
+ // Reference to the scroll container for messages
24
+ messagesContainerRef;
25
+ // Track the last message count of the currently selected room to detect appends
26
+ lastMessageCount = -1;
27
+ // Store bound listener references so the same function can be removed when chatStore changes
28
+ boundOnPresenceChange = () => this.onPresenceChange();
29
+ boundOnRoomMessageAdded = (e) => this.onRoomMessageAdded(e);
30
+ boundOnSessionExpiredChanged = (e) => this.onSessionExpiredChanged(e);
31
+ boundOnConnectionStatusChanged = (e) => this.onConnectionStatusChanged(e);
32
+ boundOnRoomReadCountChanged = () => { this._version++; };
33
+ /**
34
+ * @function onChatStoreChange
35
+ * @description A Stencil watcher that is called when the `chatStore` prop changes. It attaches event listeners to the new store to handle presence changes and new messages.
36
+ * @param {ChatStore} chatStore - The new `ChatStore` instance.
37
+ * @param {ChatStore} _oldValue - The previous `ChatStore` instance.
38
+ */
39
+ onChatStoreChange(chatStore, oldValue) {
40
+ if (oldValue) {
41
+ oldValue.removeEventListener('presenceChanged', this.boundOnPresenceChange);
42
+ oldValue.removeEventListener('roomMessageAdded', this.boundOnRoomMessageAdded);
43
+ oldValue.removeEventListener('sessionExpiredChanged', this.boundOnSessionExpiredChanged);
44
+ oldValue.removeEventListener('connectionStatusChanged', this.boundOnConnectionStatusChanged);
45
+ oldValue.removeEventListener('roomReadCountChanged', this.boundOnRoomReadCountChanged);
46
+ }
47
+ if (chatStore) {
48
+ chatStore.addEventListener('presenceChanged', this.boundOnPresenceChange);
49
+ chatStore.addEventListener('roomMessageAdded', this.boundOnRoomMessageAdded);
50
+ chatStore.addEventListener('sessionExpiredChanged', this.boundOnSessionExpiredChanged);
51
+ chatStore.addEventListener('connectionStatusChanged', this.boundOnConnectionStatusChanged);
52
+ // Sync initial state
53
+ this.isSessionExpired = chatStore.isSessionExpired;
54
+ this.connectionStatus = chatStore.connectionStatus;
55
+ chatStore.addEventListener('roomReadCountChanged', this.boundOnRoomReadCountChanged);
56
+ }
57
+ }
58
+ /**
59
+ * Reset message count tracking when switching rooms to force a scroll on first render
60
+ */
61
+ onSelectedRoomIdChanged() {
62
+ this.lastMessageCount = -1;
63
+ this._version++;
64
+ this.chatStore?.setActiveRoomId(this.selectedRoomId ?? null);
65
+ }
66
+ /**
67
+ * @function onPresenceChange
68
+ * @description This event handler is called when a user's presence status changes. It increments a version counter to force a re-render of the component.
69
+ */
70
+ onPresenceChange() {
71
+ console.debug('onPresenceChange');
72
+ this._version++;
73
+ }
74
+ /**
75
+ * @function onRoomMessageAdded
76
+ * @description This event handler is called when a new message is added to a room. It increments a version counter to force a re-render and display the new message.
77
+ * @param {CustomEvent<ChatMessageSent>} event - The custom event containing the new message.
78
+ */
79
+ onRoomMessageAdded(event) {
80
+ console.debug('onRoomMessageAdded', event);
81
+ this._version++;
82
+ if (this.isMessagesOpen && event.detail?.roomId === this.selectedRoomId) {
83
+ this.chatStore?.markRoomAsRead(this.selectedRoomId);
84
+ }
85
+ }
86
+ onSessionExpiredChanged(event) {
87
+ this.isSessionExpired = event.detail.isSessionExpired;
88
+ if (this.isSessionExpired) {
89
+ this.isChatOpen = true;
90
+ }
91
+ }
92
+ onConnectionStatusChanged(event) {
93
+ this.connectionStatus = event.detail.status;
94
+ }
95
+ toggleChat = () => {
96
+ this.isChatOpen = !this.isChatOpen;
97
+ this._version++;
98
+ };
99
+ newChatClicked;
100
+ /**
101
+ * @function onNewChatClicked
102
+ * @description This method is called when the "new chat" button is clicked. It toggles the visibility of the new chat selector panel and emits the `newChatClicked` event.
103
+ */
104
+ onNewChatClicked() {
105
+ if (this.isNewChatSelectorOpen) {
106
+ this.isNewChatSelectorOpen = false;
107
+ return;
108
+ }
109
+ this.isNewChatSelectorOpen = true;
110
+ this.isMessagesOpen = false;
111
+ this.newChatClicked.emit();
112
+ }
113
+ // callback for new message selector
114
+ onUserSelected = () => {
115
+ this.isNewChatSelectorOpen = false;
116
+ };
117
+ /* close selector from child "X" button */
118
+ onSelectorClose = () => {
119
+ this.isNewChatSelectorOpen = false;
120
+ };
121
+ /**
122
+ * @function roomClickedHandler
123
+ * @description This listener is triggered when a room is clicked in the room list. It opens the message panel for the selected room.
124
+ * @param {CustomEvent<{ id: string }>} event - The custom event containing the ID of the clicked room.
125
+ */
126
+ roomClickedHandler(event) {
127
+ console.log('Received the roomClicked event: ', event.detail);
128
+ this.isNewChatSelectorOpen = false;
129
+ this.isMessagesOpen = true;
130
+ this.selectedRoomId = event.detail.id;
131
+ this.chatStore?.markRoomAsRead(event.detail.id);
132
+ }
133
+ messageChatSent;
134
+ /**
135
+ * @function messageSendHandler
136
+ * @description This listener handles the `messageSend` event from the rich input component. It sanitizes the message content and emits a `messageChatSent` event.
137
+ * @param {CustomEvent<any>} event - The custom event containing the message content.
138
+ */
139
+ messageSendHandler(event) {
140
+ console.log('Received the messageSend event: ', JSON.stringify(event.detail));
141
+ // Sanitize blocks: remove preview from each attachment object
142
+ const inputBlocks = event.detail?.blocks ?? [];
143
+ const sanitizedBlocks = inputBlocks.map((block) => {
144
+ if (block?.type === 'attachment' && Array.isArray(block.attachments)) {
145
+ const sanitizedAttachments = block.attachments.map((att) => {
146
+ const { preview, ...rest } = att ?? {};
147
+ return rest;
148
+ });
149
+ return { ...block, attachments: sanitizedAttachments };
150
+ }
151
+ return block;
152
+ });
153
+ this.messageChatSent.emit({
154
+ room_id: this.selectedRoomId,
155
+ // TODO: change to ChatMessageSent type
156
+ content: { blocks: sanitizedBlocks, version: event.detail.version },
157
+ content_type: 'application/json+blocks',
158
+ sender: this.chatStore?.profile?.id,
159
+ });
160
+ }
161
+ /**
162
+ * @function openChatPanel
163
+ * @description This method programmatically opens the message panel for a specific room.
164
+ * @param {string} roomId - The ID of the room to open.
165
+ * @param {boolean} pending - If `true`, the panel will be opened in a pending state.
166
+ */
167
+ async openChatPanel(roomId, pending = false) {
168
+ console.debug(`openChatPanel ${roomId} ${pending}`);
169
+ this.selectedRoomId = roomId;
170
+ this.isPending = pending;
171
+ this.isChatOpen = false;
172
+ this.isMessagesOpen = true;
173
+ if (roomId)
174
+ this.chatStore?.markRoomAsRead(roomId);
175
+ this._version++;
176
+ }
177
+ /**
178
+ * @function onDoClose
179
+ * @description This method is called when the close button in the message panel is clicked. It closes the message panel.
180
+ * @param {Event} e - The click event from the close button.
181
+ */
182
+ onDoClose(e) {
183
+ e.preventDefault();
184
+ this.isMessagesOpen = false;
185
+ }
186
+ /**
187
+ * Scroll helpers
188
+ */
189
+ scrollToBottom() {
190
+ if (!this.messagesContainerRef)
191
+ return;
192
+ try {
193
+ this.messagesContainerRef.scrollTop = this.messagesContainerRef.scrollHeight;
194
+ }
195
+ catch (err) {
196
+ // no-op: best-effort scrolling only
197
+ }
198
+ }
199
+ scrollToBottomNextTick() {
200
+ // Ensure DOM is painted before measuring/scrolling
201
+ requestAnimationFrame(() => {
202
+ this.scrollToBottom();
203
+ });
204
+ }
205
+ /**
206
+ * After every render, if messages for the selected room changed, scroll to the bottom
207
+ */
208
+ componentDidRender() {
209
+ if (!this.isMessagesOpen || !this.selectedRoomId)
210
+ return;
211
+ const msgs = this.chatStore?.roomMessages(this.selectedRoomId) ?? [];
212
+ const currentCount = msgs.length;
213
+ if (currentCount !== this.lastMessageCount) {
214
+ this.scrollToBottomNextTick();
215
+ this.lastMessageCount = currentCount;
216
+ }
217
+ }
218
+ /**
219
+ * @function render
220
+ * @description The render method for the `ChatLeoTrayComponent`. It renders the different panels of the tray component based on the component's state.
221
+ * @returns {any} A VNode representing the component's UI.
222
+ */
223
+ render() {
224
+ const groupedMessages = groupMessagesByDate(this.chatStore?.roomMessages(this.selectedRoomId) ?? []);
225
+ return (h("div", { key: '16d13ecf2c8d78c822b66ee140fdf3aedb03d1fa', class: "tray-container" }, h("div", { key: '2087230f83fa231255a127bcf25935c96bb5a89d', class: this.isNewChatSelectorOpen ? 'selector-panel open' : 'selector-panel' }, h("chatleo-new-message-selector", { key: '346f747952e4c2d3872db97adfd9fab7434526cf', chatStore: this.chatStore, onUserSelected: this.onUserSelected, onDoClose: this.onSelectorClose })), h("div", { key: '245326a45ffdea0c3c8a8507a449391635576c95', class: this.isMessagesOpen ? 'messages-panel open' : 'messages-panel' }, h("div", { key: 'b5b82048cbee06bdb73967c2ff342d4bad66a89a', class: "messages-container-header-closer" }, h("button", { key: '0196b861999831d834df3407cc5c350fba9338f9', class: "close-button", onClick: this.onDoClose.bind(this) }, h("svg", { key: '1db85ebbbb9291ecd8674d25a063bcbe215bd6d0', width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, h("path", { key: 'd5f23bc40608fac8577860d6ff03e0e5c47e26cf', d: "M12 4L4 12", stroke: "#565D6D", "stroke-width": "1.37143", "stroke-miterlimit": "10", "stroke-linecap": "square" }), h("path", { key: '6f27dd8b4a9969dd19bdae6059cad74d5e466d6f', d: "M12 12L4 4", stroke: "#565D6D", "stroke-width": "1.37143", "stroke-miterlimit": "10", "stroke-linecap": "square" })))), h("chatleo-chat-header", { key: 'd4320c822ed8ed5e4472c91a8c03508137bb3985', name: this.chatStore?.profile?.display_name, avatar: this.chatStore?.profile?.profile_picture_url ?? 'https://placehold.co/48x48?text=AV', isOnline: this.chatStore?.isConnected }), h("div", { key: 'ffb54f65c17f3ecf51f661aaa2cd1777d57e2468', class: "messages-container", ref: (el) => (this.messagesContainerRef = el) }, Object.entries(groupedMessages)
226
+ .sort(([dateA], [dateB]) => new Date(dateA).getTime() - new Date(dateB).getTime())
227
+ .map(([date, messages]) => (h("div", { class: "message-group" }, h("div", { class: "date-separator" }, date), messages.map(message => (h("chatleo-chat-message", { message: message, sender: this.chatStore?.usernameResolver(message.sender_id), isOwnMessage: message.sender_id === this.chatStore?.profile.id, translations: { 'you': this.chatStore?.usernameResolver(message.sender_id)?.display_name } }))))))), h("chatleo-rich-input", { key: '5db7ffd32df847bbe103659d4f8ededfcc3105b2', disabled: !!!this.selectedRoomId, placeholder: "Nachricht schreiben" })), h("div", { key: 'a4374b9f51b6f4f528ca0099df022272d41e8062', id: "chats", class: this.isChatOpen ? 'chat-panel open' : 'chat-panel' }, this.isSessionExpired && (h("div", { key: '77f04c709823b47590588651b78531fa23d84254', class: "session-expired-banner" }, h("svg", { key: '7a9e8a3baba8576df14229384f67c4e771e4280e', class: "session-expired-banner-icon", xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", viewBox: "0 0 24 24", fill: "none" }, h("path", { key: 'bededb8359f4374f131f914124f89cae938c63f2', d: "M12 9v4M12 17h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" })), h("span", { key: '49ede701a42a2c16954859e5c0443c6c94168376' }, "Session abgelaufen \u2013"), h("button", { key: '1533de4c91c3e496e82781e03e34d8df9cd92bf7', class: "session-expired-banner-btn", onClick: () => window.location.reload() }, "Seite neu laden"))), !this.isSessionExpired && (this.connectionStatus === 'connecting' || this.connectionStatus === 'reconnecting' || this.connectionStatus === 'disconnected') && (h("div", { key: '5f11759ba32e228f990b2866d09e2d25c647315c', class: `connection-status-banner connection-status-banner--${this.connectionStatus}` }, h("span", { key: '55ad4bf597fcf0ee3a1e180ebfac85a8c271da16', class: "connection-status-banner__dot" }), this.connectionStatus === 'connecting' ? 'Verbindung wird hergestellt…'
228
+ : this.connectionStatus === 'reconnecting' ? 'Verbindung wird wiederhergestellt…'
229
+ : 'Offline')), h("div", { key: 'c8adfe1c61695332bef014492c7abe3d641160b0', class: "tray" }, h("chatleo-avatar", { key: 'e5ca63cb0a77c19c75ca8404a0ec92833f9881f2', name: this.chatStore?.profile?.display_name ?? "", url: this.chatStore?.profile?.profile_picture_url, isOnline: this.chatStore?.profile?.id ? (this.chatStore?.isOnline(this.chatStore.profile.id) ?? false) : false }), h("div", { key: 'a7bbd2492328f400a7e349f8296f3c1a499e171e', class: "title" }, "Nachrichten"), h("button", { key: '7c2450e2977563c59a41efc874fc9ca5c6ecbea7', class: "new-chat-btn", onClick: () => this.onNewChatClicked() }, h("svg", { key: 'a7de1919583f9264c85d2f8a0879e8f993ff848c', xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", viewBox: "0 0 16 16", fill: "none" }, h("path", { key: '63e200bbf4038f0ceb626000b53f685318cd19f8', d: "M10.497 2.43838L12.7094 4.62657M12.9439 1.6838L13.4519 2.19178C13.9192 2.6591 13.9192 3.41677 13.4519 3.8841L6.72919 10.6068C6.59783 10.7381 6.43768 10.8371 6.26144 10.8958L3.79663 11.7174C3.56275 11.7954 3.34026 11.5729 3.41821 11.339L4.23982 8.87421C4.29857 8.69797 4.39754 8.53783 4.5289 8.40647L11.2516 1.6838C11.7189 1.21648 12.4766 1.21648 12.9439 1.6838Z", stroke: "#565D6D", "stroke-width": "1.5", "stroke-linecap": "round", "stroke-linejoin": "round" }), h("path", { key: '222831ec61fc41f09ba0296731aed27050ff1b55', d: "M8 2.13312H7.2H1.8C1.35817 2.13312 1 2.49129 1 2.93312V13.7331C1 14.1749 1.35817 14.5331 1.8 14.5331H12.6C13.0418 14.5331 13.4 14.1749 13.4 13.7331V8.33312V6.99998", stroke: "#565D6D", "stroke-width": "1.5", "stroke-linecap": "round" }))), h("button", { key: '51ce8b2bc912659e7347f9eb9bfe1a1c56b23b75', class: "chat-tray-btn", onClick: this.toggleChat }, this.isChatOpen ? (h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", viewBox: "0 0 16 16", fill: "none" }, h("path", { d: "M3.07273 4.66669L2 5.73941L8 11.7394L14 5.73941L12.9273 4.66669L8 9.59393L3.07273 4.66669Z", fill: "#565D6D" }))) : (h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", viewBox: "0 0 16 16", fill: "none" }, h("path", { d: "M12.9273 11.7393L14 10.6665L8 4.66655L2 10.6665L3.07273 11.7393L8 6.81202L12.9273 11.7393Z", fill: "#565D6D" }))))), h("div", { key: '9f46873326aab72ba87cfa6b387de9c5616bb497', class: "chat-content" }, h("ul", { key: 'f1f9da34aab6ae95a9d3910de295e1dc64f31c2c' }, this.chatStore?.rooms.map(room => {
230
+ const online = room.participantIdsWithoutSelf?.filter((id) => this.chatStore.isOnline(id)) ?? [];
231
+ return (h("li", null, h("chatleo-room-tile-component", { chatStore: this.chatStore, room: room, onlineUserIds: online, lastMessage: undefined, timestamp: undefined, unreadCount: room.unreadCount })));
232
+ }))))));
233
+ }
234
+ static get is() { return "chatleo-tray-component"; }
235
+ static get encapsulation() { return "shadow"; }
236
+ static get originalStyleUrls() {
237
+ return {
238
+ "$": ["chatleo-tray-component.css"]
239
+ };
240
+ }
241
+ static get styleUrls() {
242
+ return {
243
+ "$": ["chatleo-tray-component.css"]
244
+ };
245
+ }
246
+ static get properties() {
247
+ return {
248
+ "chatStore": {
249
+ "type": "unknown",
250
+ "mutable": false,
251
+ "complexType": {
252
+ "original": "ChatStore",
253
+ "resolved": "ChatStore",
254
+ "references": {
255
+ "ChatStore": {
256
+ "location": "import",
257
+ "path": "@chat-leo/chatleolib",
258
+ "id": "../chatleolib/dist/ChatStore.d.ts::ChatStore",
259
+ "referenceLocation": "ChatStore"
260
+ }
261
+ }
262
+ },
263
+ "required": false,
264
+ "optional": true,
265
+ "docs": {
266
+ "tags": [],
267
+ "text": "An instance of the `ChatStore` class, which provides the state for the chat application."
268
+ },
269
+ "getter": false,
270
+ "setter": false
271
+ }
272
+ };
273
+ }
274
+ static get states() {
275
+ return {
276
+ "isChatOpen": {},
277
+ "isNewChatSelectorOpen": {},
278
+ "isMessagesOpen": {},
279
+ "selectedRoomId": {},
280
+ "isPending": {},
281
+ "_version": {},
282
+ "isSessionExpired": {},
283
+ "connectionStatus": {}
284
+ };
285
+ }
286
+ static get events() {
287
+ return [{
288
+ "method": "newChatClicked",
289
+ "name": "newChatClicked",
290
+ "bubbles": true,
291
+ "cancelable": true,
292
+ "composed": true,
293
+ "docs": {
294
+ "tags": [],
295
+ "text": ""
296
+ },
297
+ "complexType": {
298
+ "original": "string",
299
+ "resolved": "string",
300
+ "references": {}
301
+ }
302
+ }, {
303
+ "method": "messageChatSent",
304
+ "name": "messageChatSent",
305
+ "bubbles": true,
306
+ "cancelable": true,
307
+ "composed": true,
308
+ "docs": {
309
+ "tags": [],
310
+ "text": ""
311
+ },
312
+ "complexType": {
313
+ "original": "ChatMessageSent",
314
+ "resolved": "{ room_id: string; content: any; content_type: string; sender: string; }",
315
+ "references": {
316
+ "ChatMessageSent": {
317
+ "location": "import",
318
+ "path": "@chat-leo/chatleolib",
319
+ "id": "../chatleolib/dist/index.d.ts::ChatMessageSent",
320
+ "referenceLocation": "ChatMessageSent"
321
+ }
322
+ }
323
+ }
324
+ }];
325
+ }
326
+ static get methods() {
327
+ return {
328
+ "openChatPanel": {
329
+ "complexType": {
330
+ "signature": "(roomId?: string, pending?: boolean) => Promise<void>",
331
+ "parameters": [{
332
+ "name": "roomId",
333
+ "type": "string",
334
+ "docs": "- The ID of the room to open."
335
+ }, {
336
+ "name": "pending",
337
+ "type": "boolean",
338
+ "docs": "- If `true`, the panel will be opened in a pending state."
339
+ }],
340
+ "references": {
341
+ "Promise": {
342
+ "location": "global",
343
+ "id": "global::Promise"
344
+ }
345
+ },
346
+ "return": "Promise<void>"
347
+ },
348
+ "docs": {
349
+ "text": "",
350
+ "tags": [{
351
+ "name": "function",
352
+ "text": "openChatPanel"
353
+ }, {
354
+ "name": "description",
355
+ "text": "This method programmatically opens the message panel for a specific room."
356
+ }, {
357
+ "name": "param",
358
+ "text": "roomId - The ID of the room to open."
359
+ }, {
360
+ "name": "param",
361
+ "text": "pending - If `true`, the panel will be opened in a pending state."
362
+ }]
363
+ }
364
+ }
365
+ };
366
+ }
367
+ static get watchers() {
368
+ return [{
369
+ "propName": "chatStore",
370
+ "methodName": "onChatStoreChange"
371
+ }, {
372
+ "propName": "selectedRoomId",
373
+ "methodName": "onSelectedRoomIdChanged"
374
+ }];
375
+ }
376
+ static get listeners() {
377
+ return [{
378
+ "name": "roomClicked",
379
+ "method": "roomClickedHandler",
380
+ "target": undefined,
381
+ "capture": false,
382
+ "passive": false
383
+ }, {
384
+ "name": "messageSend",
385
+ "method": "messageSendHandler",
386
+ "target": undefined,
387
+ "capture": false,
388
+ "passive": false
389
+ }];
390
+ }
391
+ }