@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.
- package/LICENSE +21 -0
- package/dist/chatleo/chatleo.esm.js +1 -0
- package/dist/chatleo/index.esm.js +1 -0
- package/dist/chatleo/p-43ada232.entry.js +1 -0
- package/dist/chatleo/p-4485e141.entry.js +1 -0
- package/dist/chatleo/p-BnCPdbII.js +1 -0
- package/dist/chatleo/p-C-l90Wre.js +1 -0
- package/dist/chatleo/p-DQuL1Twl.js +1 -0
- package/dist/chatleo/p-DmL518NK.js +3 -0
- package/dist/chatleo/p-aed60255.entry.js +1 -0
- package/dist/cjs/app-globals-V2Kpy_OQ.js +5 -0
- package/dist/cjs/chatleo-avatar_13.cjs.entry.js +2986 -0
- package/dist/cjs/chatleo-call-adapter-B2OfC0VZ.js +35 -0
- package/dist/cjs/chatleo-chat-input.cjs.entry.js +67 -0
- package/dist/cjs/chatleo.cjs.js +25 -0
- package/dist/cjs/index-DkSDLR0y.js +56 -0
- package/dist/cjs/index-Dxw4YCA_.js +1741 -0
- package/dist/cjs/index.cjs.js +7 -0
- package/dist/cjs/loader.cjs.js +13 -0
- package/dist/cjs/my-component.cjs.entry.js +33 -0
- package/dist/collection/__mocks__/stencil-core.js +26 -0
- package/dist/collection/collection-manifest.json +27 -0
- package/dist/collection/components/chatleo-avatar/chatleo-avatar.css +40 -0
- package/dist/collection/components/chatleo-avatar/chatleo-avatar.js +116 -0
- package/dist/collection/components/chatleo-chat/chatleo-chat.css +108 -0
- package/dist/collection/components/chatleo-chat/chatleo-chat.js +459 -0
- package/dist/collection/components/chatleo-chat-header/chatleo-chat-header.css +22 -0
- package/dist/collection/components/chatleo-chat-header/chatleo-chat-header.js +105 -0
- package/dist/collection/components/chatleo-chat-input/chatleo-chat-input.css +84 -0
- package/dist/collection/components/chatleo-chat-input/chatleo-chat-input.js +141 -0
- package/dist/collection/components/chatleo-chat-message/chatleo-chat-message.css +149 -0
- package/dist/collection/components/chatleo-chat-message/chatleo-chat-message.js +259 -0
- package/dist/collection/components/chatleo-component/chatleo-component.css +271 -0
- package/dist/collection/components/chatleo-component/chatleo-component.js +1366 -0
- package/dist/collection/components/chatleo-new-message-selector/chatleo-new-message-selector.css +96 -0
- package/dist/collection/components/chatleo-new-message-selector/chatleo-new-message-selector.js +231 -0
- package/dist/collection/components/chatleo-rich-input/chatleo-rich-input.css +352 -0
- package/dist/collection/components/chatleo-rich-input/chatleo-rich-input.js +976 -0
- package/dist/collection/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.css +169 -0
- package/dist/collection/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.js +400 -0
- package/dist/collection/components/chatleo-room-list/chatleo-room-list.css +111 -0
- package/dist/collection/components/chatleo-room-list/chatleo-room-list.js +180 -0
- package/dist/collection/components/chatleo-room-tile-component/chatleo-room-tile-component.css +110 -0
- package/dist/collection/components/chatleo-room-tile-component/chatleo-room-tile-component.js +241 -0
- package/dist/collection/components/chatleo-room-view/chatleo-room-view.css +93 -0
- package/dist/collection/components/chatleo-room-view/chatleo-room-view.js +593 -0
- package/dist/collection/components/chatleo-tray-component/chatleo-tray-component.css +284 -0
- package/dist/collection/components/chatleo-tray-component/chatleo-tray-component.js +391 -0
- package/dist/collection/components/chatleo-user-tile/chatleo-user-tile.css +56 -0
- package/dist/collection/components/chatleo-user-tile/chatleo-user-tile.js +149 -0
- package/dist/collection/components/my-component/my-component.css +4 -0
- package/dist/collection/components/my-component/my-component.js +95 -0
- package/dist/collection/index.js +10 -0
- package/dist/collection/utils/call-entry.js +34 -0
- package/dist/collection/utils/delivery.js +7 -0
- package/dist/collection/utils/utils.js +51 -0
- package/dist/components/chatleo-avatar.d.ts +11 -0
- package/dist/components/chatleo-avatar.js +1 -0
- package/dist/components/chatleo-chat-header.d.ts +11 -0
- package/dist/components/chatleo-chat-header.js +1 -0
- package/dist/components/chatleo-chat-input.d.ts +11 -0
- package/dist/components/chatleo-chat-input.js +1 -0
- package/dist/components/chatleo-chat-message.d.ts +11 -0
- package/dist/components/chatleo-chat-message.js +1 -0
- package/dist/components/chatleo-chat.d.ts +11 -0
- package/dist/components/chatleo-chat.js +1 -0
- package/dist/components/chatleo-component.d.ts +11 -0
- package/dist/components/chatleo-component.js +1 -0
- package/dist/components/chatleo-new-message-selector.d.ts +11 -0
- package/dist/components/chatleo-new-message-selector.js +1 -0
- package/dist/components/chatleo-rich-input.d.ts +11 -0
- package/dist/components/chatleo-rich-input.js +1 -0
- package/dist/components/chatleo-rich-message-renderer.d.ts +11 -0
- package/dist/components/chatleo-rich-message-renderer.js +1 -0
- package/dist/components/chatleo-room-list.d.ts +11 -0
- package/dist/components/chatleo-room-list.js +1 -0
- package/dist/components/chatleo-room-tile-component.d.ts +11 -0
- package/dist/components/chatleo-room-tile-component.js +1 -0
- package/dist/components/chatleo-room-view.d.ts +11 -0
- package/dist/components/chatleo-room-view.js +1 -0
- package/dist/components/chatleo-tray-component.d.ts +11 -0
- package/dist/components/chatleo-tray-component.js +1 -0
- package/dist/components/chatleo-user-tile.d.ts +11 -0
- package/dist/components/chatleo-user-tile.js +1 -0
- package/dist/components/index.d.ts +35 -0
- package/dist/components/index.js +1 -0
- package/dist/components/my-component.d.ts +11 -0
- package/dist/components/my-component.js +1 -0
- package/dist/components/p-8kvQ-Uh-.js +1 -0
- package/dist/components/p-B7cdqAgv.js +1 -0
- package/dist/components/p-BdiOcOYZ.js +1 -0
- package/dist/components/p-BlbDSb7D.js +1 -0
- package/dist/components/p-BnCPdbII.js +1 -0
- package/dist/components/p-C-v19aUJ.js +1 -0
- package/dist/components/p-C1mF0s8g.js +1 -0
- package/dist/components/p-CRtBdzP3.js +1 -0
- package/dist/components/p-CfayCm9O.js +1 -0
- package/dist/components/p-DGjAxoQy.js +1 -0
- package/dist/components/p-Exj_2-yI.js +1 -0
- package/dist/components/p-XlwGxsqT.js +1 -0
- package/dist/components/p-fjMaTJam.js +1 -0
- package/dist/components/p-xt4kzz3B.js +1 -0
- package/dist/esm/app-globals-DQuL1Twl.js +3 -0
- package/dist/esm/chatleo-avatar_13.entry.js +2972 -0
- package/dist/esm/chatleo-call-adapter-BnCPdbII.js +33 -0
- package/dist/esm/chatleo-chat-input.entry.js +65 -0
- package/dist/esm/chatleo.js +21 -0
- package/dist/esm/index-C-l90Wre.js +53 -0
- package/dist/esm/index-DmL518NK.js +1733 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/loader.js +11 -0
- package/dist/esm/my-component.entry.js +31 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/types/__mocks__/stencil-core.d.ts +24 -0
- package/dist/types/components/chatleo-avatar/chatleo-avatar.d.ts +27 -0
- package/dist/types/components/chatleo-chat/chatleo-chat.d.ts +75 -0
- package/dist/types/components/chatleo-chat-header/chatleo-chat-header.d.ts +27 -0
- package/dist/types/components/chatleo-chat-input/chatleo-chat-input.d.ts +31 -0
- package/dist/types/components/chatleo-chat-message/chatleo-chat-message.d.ts +22 -0
- package/dist/types/components/chatleo-component/chatleo-component.d.ts +278 -0
- package/dist/types/components/chatleo-new-message-selector/chatleo-new-message-selector.d.ts +68 -0
- package/dist/types/components/chatleo-rich-input/chatleo-rich-input.d.ts +216 -0
- package/dist/types/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.d.ts +77 -0
- package/dist/types/components/chatleo-room-list/chatleo-room-list.d.ts +52 -0
- package/dist/types/components/chatleo-room-tile-component/chatleo-room-tile-component.d.ts +59 -0
- package/dist/types/components/chatleo-room-view/chatleo-room-view.d.ts +91 -0
- package/dist/types/components/chatleo-tray-component/chatleo-tray-component.d.ts +112 -0
- package/dist/types/components/chatleo-user-tile/chatleo-user-tile.d.ts +36 -0
- package/dist/types/components/my-component/my-component.d.ts +16 -0
- package/dist/types/components.d.ts +1593 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/stencil-public-runtime.d.ts +1879 -0
- package/dist/types/utils/call-entry.d.ts +9 -0
- package/dist/types/utils/delivery.d.ts +7 -0
- package/dist/types/utils/utils.d.ts +24 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/package.json +70 -3
- package/readme.md +111 -0
- package/README.md +0 -3
package/dist/collection/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.css
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: block;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.rich-message-content {
|
|
6
|
+
width: 100%;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.rich-message-content.left {
|
|
10
|
+
text-align: left;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.rich-message-content.right {
|
|
14
|
+
text-align: right;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.rich-message-content p {
|
|
18
|
+
margin: 0.5em 0;
|
|
19
|
+
line-height: 1.4;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.rich-message-content p:first-child {
|
|
23
|
+
margin-top: 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.rich-message-content p:last-child {
|
|
27
|
+
margin-bottom: 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* Attachment container styling */
|
|
31
|
+
.attachment-container {
|
|
32
|
+
display: flex;
|
|
33
|
+
gap: 8px;
|
|
34
|
+
overflow-x: auto;
|
|
35
|
+
padding: 4px 0;
|
|
36
|
+
scrollbar-width: thin;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.attachment-container::-webkit-scrollbar {
|
|
40
|
+
height: 4px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.attachment-container::-webkit-scrollbar-track {
|
|
44
|
+
background: #f1f1f1;
|
|
45
|
+
border-radius: 2px;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.attachment-container::-webkit-scrollbar-thumb {
|
|
49
|
+
background: #c1c1c1;
|
|
50
|
+
border-radius: 2px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.attachment-container::-webkit-scrollbar-thumb:hover {
|
|
54
|
+
background: #a8a8a8;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* Individual attachment item */
|
|
58
|
+
.attachment-item {
|
|
59
|
+
position: relative;
|
|
60
|
+
flex-shrink: 0;
|
|
61
|
+
width: 80px;
|
|
62
|
+
height: 80px;
|
|
63
|
+
border-radius: 8px;
|
|
64
|
+
overflow: hidden;
|
|
65
|
+
background-color: #f5f5f5;
|
|
66
|
+
border: 1px solid #e5e5e5;
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.attachment-item:hover {
|
|
72
|
+
transform: scale(1.05);
|
|
73
|
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.attachment-thumbnail {
|
|
77
|
+
width: 100%;
|
|
78
|
+
height: 100%;
|
|
79
|
+
display: flex;
|
|
80
|
+
align-items: center;
|
|
81
|
+
justify-content: center;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.attachment-thumbnail img {
|
|
85
|
+
width: 100%;
|
|
86
|
+
height: 100%;
|
|
87
|
+
object-fit: cover;
|
|
88
|
+
border-radius: 7px;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.image-container {
|
|
92
|
+
width: 100%;
|
|
93
|
+
height: 100%;
|
|
94
|
+
display: flex;
|
|
95
|
+
align-items: center;
|
|
96
|
+
justify-content: center;
|
|
97
|
+
position: relative;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* Loading spinner styles */
|
|
101
|
+
.loading-spinner {
|
|
102
|
+
display: flex;
|
|
103
|
+
align-items: center;
|
|
104
|
+
justify-content: center;
|
|
105
|
+
width: 100%;
|
|
106
|
+
height: 100%;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.spinner-circle {
|
|
110
|
+
animation: spin 1s linear infinite;
|
|
111
|
+
transform-origin: center;
|
|
112
|
+
stroke-dasharray: 50;
|
|
113
|
+
stroke-dashoffset: 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@keyframes spin {
|
|
117
|
+
0% {
|
|
118
|
+
transform: rotate(0deg);
|
|
119
|
+
stroke-dashoffset: 0;
|
|
120
|
+
}
|
|
121
|
+
50% {
|
|
122
|
+
stroke-dashoffset: 25;
|
|
123
|
+
}
|
|
124
|
+
100% {
|
|
125
|
+
transform: rotate(360deg);
|
|
126
|
+
stroke-dashoffset: 50;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* Overlay for download link */
|
|
131
|
+
.attachment-overlay {
|
|
132
|
+
position: absolute;
|
|
133
|
+
top: 0;
|
|
134
|
+
left: 0;
|
|
135
|
+
right: 0;
|
|
136
|
+
bottom: 0;
|
|
137
|
+
background: rgba(0, 0, 0, 0.3);
|
|
138
|
+
display: flex;
|
|
139
|
+
align-items: center;
|
|
140
|
+
justify-content: center;
|
|
141
|
+
opacity: 0;
|
|
142
|
+
transition: opacity 0.2s ease;
|
|
143
|
+
border-radius: 7px;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.attachment-item:hover .attachment-overlay {
|
|
147
|
+
opacity: 1;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.attachment-overlay a {
|
|
151
|
+
display: flex;
|
|
152
|
+
align-items: center;
|
|
153
|
+
justify-content: center;
|
|
154
|
+
width: 32px;
|
|
155
|
+
height: 32px;
|
|
156
|
+
background: rgba(0, 0, 0, 0.6);
|
|
157
|
+
border-radius: 50%;
|
|
158
|
+
text-decoration: none;
|
|
159
|
+
transition: background 0.2s ease;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.attachment-overlay a:hover {
|
|
163
|
+
background: rgba(0, 0, 0, 0.8);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* Right alignment specific styles */
|
|
167
|
+
.rich-message-content.right .attachment-container {
|
|
168
|
+
justify-content: flex-end;
|
|
169
|
+
}
|
package/dist/collection/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.js
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { h } from "@stencil/core";
|
|
2
|
+
/**
|
|
3
|
+
* @component ChatleoRichMessageRenderer
|
|
4
|
+
* @description This component is responsible for rendering structured message content, which can include text and attachments. It takes a `StructuredMessageContent` object and renders it as a series of blocks.
|
|
5
|
+
* @property {StructuredMessageContent} content - The structured message content object to be rendered. This object contains an array of blocks, each of which can be a text or attachment block.
|
|
6
|
+
* @property {Record<string, AttachmentDownloadInfo>} downloadUrls - A map where keys are attachment IDs and values are objects containing download information for those attachments, such as the download URL.
|
|
7
|
+
* @property {'left' | 'right'} alignment - This property determines the text alignment of the message content. It can be either `'left'` or `'right'`.
|
|
8
|
+
*/
|
|
9
|
+
export class ChatleoRichMessageRenderer {
|
|
10
|
+
/**
|
|
11
|
+
* The structured message content object to be rendered. This object contains an array of blocks, each of which can be a text or attachment block.
|
|
12
|
+
*/
|
|
13
|
+
content;
|
|
14
|
+
/**
|
|
15
|
+
* A map where keys are attachment IDs and values are objects containing download information for those attachments, such as the download URL.
|
|
16
|
+
*/
|
|
17
|
+
downloadUrls = {};
|
|
18
|
+
/**
|
|
19
|
+
* This property determines the text alignment of the message content. It can be either `'left'` or `'right'`.
|
|
20
|
+
*/
|
|
21
|
+
alignment = 'left';
|
|
22
|
+
/**
|
|
23
|
+
* Optional translations overriding the default UI strings (e.g. `unsupported_content`).
|
|
24
|
+
*/
|
|
25
|
+
translations = {};
|
|
26
|
+
/**
|
|
27
|
+
* State to track loading status and retry attempts for each attachment
|
|
28
|
+
*/
|
|
29
|
+
attachmentStates = {};
|
|
30
|
+
MAX_RETRIES = 3;
|
|
31
|
+
INITIAL_RETRY_DELAY_MS = 1000; // 1 second
|
|
32
|
+
FETCH_TIMEOUT_MS = 5000; // 5 seconds timeout for HEAD request
|
|
33
|
+
/**
|
|
34
|
+
* Initialize attachment state if it doesn't exist
|
|
35
|
+
*/
|
|
36
|
+
initAttachmentState(attachmentId) {
|
|
37
|
+
if (!this.attachmentStates[attachmentId]) {
|
|
38
|
+
this.attachmentStates = {
|
|
39
|
+
...this.attachmentStates,
|
|
40
|
+
[attachmentId]: {
|
|
41
|
+
isLoading: false,
|
|
42
|
+
retryCount: 0,
|
|
43
|
+
hasError: false,
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Handle image load error with retry logic
|
|
50
|
+
*/
|
|
51
|
+
async handleImageError(attachmentId, mimeType, imgElement) {
|
|
52
|
+
this.initAttachmentState(attachmentId);
|
|
53
|
+
const state = this.attachmentStates[attachmentId];
|
|
54
|
+
console.log("handleImageError", attachmentId, state);
|
|
55
|
+
// Only retry for 404 errors and image types
|
|
56
|
+
if (!mimeType.startsWith('image/') || state.retryCount >= this.MAX_RETRIES) {
|
|
57
|
+
// Set error state and use placeholder
|
|
58
|
+
this.attachmentStates = {
|
|
59
|
+
...this.attachmentStates,
|
|
60
|
+
[attachmentId]: {
|
|
61
|
+
...state,
|
|
62
|
+
isLoading: false,
|
|
63
|
+
hasError: true,
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
imgElement.src = this.getPlaceholderIcon(mimeType);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Check if it's a 404 error by trying to fetch the image
|
|
70
|
+
const downloadInfo = this.downloadUrls[attachmentId];
|
|
71
|
+
if (!downloadInfo) {
|
|
72
|
+
this.attachmentStates = {
|
|
73
|
+
...this.attachmentStates,
|
|
74
|
+
[attachmentId]: {
|
|
75
|
+
...state,
|
|
76
|
+
isLoading: false,
|
|
77
|
+
hasError: true,
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
imgElement.src = this.getPlaceholderIcon(mimeType);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
// Create AbortController for timeout handling
|
|
85
|
+
const abortController = new AbortController();
|
|
86
|
+
const timeoutId = setTimeout(() => abortController.abort(), this.FETCH_TIMEOUT_MS);
|
|
87
|
+
try {
|
|
88
|
+
const response = await fetch(downloadInfo.download_url, {
|
|
89
|
+
method: 'HEAD',
|
|
90
|
+
signal: abortController.signal
|
|
91
|
+
});
|
|
92
|
+
clearTimeout(timeoutId);
|
|
93
|
+
console.debug(`HEAD response`, response);
|
|
94
|
+
// Only retry on 404 errors
|
|
95
|
+
if (response.status === 404) {
|
|
96
|
+
// Set loading state
|
|
97
|
+
this.attachmentStates = {
|
|
98
|
+
...this.attachmentStates,
|
|
99
|
+
[attachmentId]: {
|
|
100
|
+
...state,
|
|
101
|
+
isLoading: true,
|
|
102
|
+
retryCount: state.retryCount + 1,
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
// Calculate exponential backoff delay
|
|
106
|
+
const delay = this.INITIAL_RETRY_DELAY_MS * Math.pow(2, state.retryCount);
|
|
107
|
+
// Wait for backoff delay and retry
|
|
108
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
109
|
+
// Retry loading the image
|
|
110
|
+
this.attachmentStates = {
|
|
111
|
+
...this.attachmentStates,
|
|
112
|
+
[attachmentId]: {
|
|
113
|
+
...this.attachmentStates[attachmentId],
|
|
114
|
+
isLoading: false,
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
// Force reload by appending a timestamp to prevent caching
|
|
118
|
+
const url = new URL(downloadInfo.download_url);
|
|
119
|
+
url.searchParams.set('retry', String(Date.now()));
|
|
120
|
+
imgElement.src = url.toString();
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// Not a 404, just use placeholder
|
|
124
|
+
this.attachmentStates = {
|
|
125
|
+
...this.attachmentStates,
|
|
126
|
+
[attachmentId]: {
|
|
127
|
+
...state,
|
|
128
|
+
isLoading: false,
|
|
129
|
+
hasError: true,
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
imgElement.src = this.getPlaceholderIcon(mimeType);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (fetchError) {
|
|
136
|
+
// Clear timeout on fetch error
|
|
137
|
+
clearTimeout(timeoutId);
|
|
138
|
+
// Handle timeout or fetch error, use placeholder
|
|
139
|
+
this.attachmentStates = {
|
|
140
|
+
...this.attachmentStates,
|
|
141
|
+
[attachmentId]: {
|
|
142
|
+
...state,
|
|
143
|
+
isLoading: false,
|
|
144
|
+
hasError: true,
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
imgElement.src = this.getPlaceholderIcon(mimeType);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
// Network error or other issue, use placeholder
|
|
152
|
+
this.attachmentStates = {
|
|
153
|
+
...this.attachmentStates,
|
|
154
|
+
[attachmentId]: {
|
|
155
|
+
...state,
|
|
156
|
+
isLoading: false,
|
|
157
|
+
hasError: true,
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
imgElement.src = this.getPlaceholderIcon(mimeType);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Render a loading spinner
|
|
165
|
+
*/
|
|
166
|
+
renderLoadingSpinner() {
|
|
167
|
+
return (h("div", { class: "loading-spinner" }, h("svg", { width: "24", height: "24", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, h("circle", { class: "spinner-circle", cx: "12", cy: "12", r: "10", fill: "none", stroke: "#6b7280", "stroke-width": "2" }))));
|
|
168
|
+
}
|
|
169
|
+
defaultTranslations = {
|
|
170
|
+
unsupported_content: 'Unsupported content',
|
|
171
|
+
};
|
|
172
|
+
t(key) {
|
|
173
|
+
return this.translations[key] || this.defaultTranslations[key] || key;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Renders text as text nodes separated by <br/> elements. Never uses innerHTML,
|
|
177
|
+
* so markup in block text is displayed literally.
|
|
178
|
+
*/
|
|
179
|
+
renderPlainText(text) {
|
|
180
|
+
const parts = text.split('\n');
|
|
181
|
+
const nodes = [];
|
|
182
|
+
parts.forEach((part, i) => {
|
|
183
|
+
if (part)
|
|
184
|
+
nodes.push(part);
|
|
185
|
+
if (i < parts.length - 1)
|
|
186
|
+
nodes.push(h("br", null));
|
|
187
|
+
});
|
|
188
|
+
return nodes;
|
|
189
|
+
}
|
|
190
|
+
renderTextBlock(block) {
|
|
191
|
+
if (!block.content)
|
|
192
|
+
return null;
|
|
193
|
+
return h("p", null, this.renderPlainText(String(block.content)));
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Fallback for unknown block types: show `fallback_text` if provided, otherwise a
|
|
197
|
+
* neutral notice, so a message is never rendered empty.
|
|
198
|
+
*/
|
|
199
|
+
renderUnknownBlock(block) {
|
|
200
|
+
if (typeof block?.fallback_text === 'string' && block.fallback_text.length > 0) {
|
|
201
|
+
return h("p", null, this.renderPlainText(block.fallback_text));
|
|
202
|
+
}
|
|
203
|
+
return h("p", { class: "unsupported-content" }, this.t('unsupported_content'));
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Registry of block renderers keyed by block type.
|
|
207
|
+
*/
|
|
208
|
+
blockRenderers = {
|
|
209
|
+
text: (block) => this.renderTextBlock(block),
|
|
210
|
+
attachment: (block) => this.renderAttachmentBlock(block),
|
|
211
|
+
};
|
|
212
|
+
generateThumbnail(attachmentId, mimeType) {
|
|
213
|
+
const downloadInfo = this.downloadUrls[attachmentId];
|
|
214
|
+
console.debug("generateThumbnail", { downloadUrls: this.downloadUrls, attachmentId, downloadInfo });
|
|
215
|
+
if (downloadInfo && downloadInfo.mime_type.startsWith('image/')) {
|
|
216
|
+
// Return the download URL for images - in a real implementation,
|
|
217
|
+
// we might want to create a thumbnail endpoint or use the full image
|
|
218
|
+
return downloadInfo.download_url;
|
|
219
|
+
}
|
|
220
|
+
// Return a placeholder for non-images or missing download info
|
|
221
|
+
return this.getPlaceholderIcon(mimeType);
|
|
222
|
+
}
|
|
223
|
+
getPlaceholderIcon(mimeType) {
|
|
224
|
+
// Return SVG data URL for different file types
|
|
225
|
+
const iconColor = '#6b7280';
|
|
226
|
+
if (mimeType.startsWith('image/')) {
|
|
227
|
+
return `data:image/svg+xml,${encodeURIComponent(`
|
|
228
|
+
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
229
|
+
<rect x="3" y="3" width="18" height="18" rx="2" ry="2" stroke="${iconColor}" stroke-width="2" fill="none"/>
|
|
230
|
+
<circle cx="8.5" cy="8.5" r="1.5" fill="${iconColor}"/>
|
|
231
|
+
<polyline points="21,15 16,10 5,21" stroke="${iconColor}" stroke-width="2" fill="none"/>
|
|
232
|
+
</svg>
|
|
233
|
+
`)}`;
|
|
234
|
+
}
|
|
235
|
+
if (mimeType.includes('pdf')) {
|
|
236
|
+
return `data:image/svg+xml,${encodeURIComponent(`
|
|
237
|
+
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
238
|
+
<path d="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20Z" fill="${iconColor}"/>
|
|
239
|
+
</svg>
|
|
240
|
+
`)}`;
|
|
241
|
+
}
|
|
242
|
+
// Default file icon
|
|
243
|
+
return `data:image/svg+xml,${encodeURIComponent(`
|
|
244
|
+
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
245
|
+
<path d="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20Z" stroke="${iconColor}" stroke-width="2" fill="none"/>
|
|
246
|
+
<polyline points="14,2 14,8 20,8" stroke="${iconColor}" stroke-width="2" fill="none"/>
|
|
247
|
+
</svg>
|
|
248
|
+
`)}`;
|
|
249
|
+
}
|
|
250
|
+
renderAttachmentBlock(block) {
|
|
251
|
+
if (!block.attachments || block.attachments.length === 0) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
const attachmentItems = block.attachments.map((attachment) => {
|
|
255
|
+
const thumbnailSrc = this.generateThumbnail(attachment.id, attachment.mime_type);
|
|
256
|
+
const downloadInfo = this.downloadUrls[attachment.id];
|
|
257
|
+
// Initialize state for this attachment
|
|
258
|
+
this.initAttachmentState(attachment.id);
|
|
259
|
+
const state = this.attachmentStates[attachment.id];
|
|
260
|
+
return (h("div", { class: "attachment-item", key: attachment.id }, h("div", { class: "attachment-thumbnail" }, attachment.mime_type.startsWith('image/') ? (h("div", { class: "image-container" }, h("img", { src: thumbnailSrc, alt: "Image attachment", onError: (e) => {
|
|
261
|
+
this.handleImageError(attachment.id, attachment.mime_type, e.target);
|
|
262
|
+
}, style: { display: state.isLoading ? 'none' : 'block' } }), state.isLoading && this.renderLoadingSpinner())) : (h("img", { src: thumbnailSrc, alt: "File attachment" }))), downloadInfo && (h("div", { class: "attachment-overlay" }, h("a", { href: downloadInfo.download_url, target: "_blank", rel: "noopener noreferrer" }, h("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, h("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4", stroke: "white", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }), h("polyline", { points: "7,10 12,15 17,10", stroke: "white", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }), h("line", { x1: "12", y1: "15", x2: "12", y2: "3", stroke: "white", "stroke-width": "2", "stroke-linecap": "round" })))))));
|
|
263
|
+
});
|
|
264
|
+
return (h("p", null, h("div", { class: "attachment-container" }, attachmentItems)));
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* @function render
|
|
268
|
+
* @description The render method for the `ChatleoRichMessageRenderer` component. It iterates over the blocks in the `content` prop and renders each one using the appropriate rendering method (looked up in the `blockRenderers` registry, with `renderUnknownBlock` as fallback).
|
|
269
|
+
* @returns {any} A VNode representing the component's UI.
|
|
270
|
+
*/
|
|
271
|
+
render() {
|
|
272
|
+
if (!this.content || !this.content.blocks) {
|
|
273
|
+
return h("div", { class: `rich-message-content ${this.alignment}` });
|
|
274
|
+
}
|
|
275
|
+
const blockElements = this.content.blocks.map((block) => {
|
|
276
|
+
const renderer = Object.prototype.hasOwnProperty.call(this.blockRenderers, block?.type)
|
|
277
|
+
? this.blockRenderers[block.type]
|
|
278
|
+
: undefined;
|
|
279
|
+
return renderer ? renderer(block) : this.renderUnknownBlock(block);
|
|
280
|
+
});
|
|
281
|
+
return (h("div", { class: `rich-message-content ${this.alignment}` }, blockElements));
|
|
282
|
+
}
|
|
283
|
+
static get is() { return "chatleo-rich-message-renderer"; }
|
|
284
|
+
static get encapsulation() { return "shadow"; }
|
|
285
|
+
static get originalStyleUrls() {
|
|
286
|
+
return {
|
|
287
|
+
"$": ["chatleo-rich-message-renderer.css"]
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
static get styleUrls() {
|
|
291
|
+
return {
|
|
292
|
+
"$": ["chatleo-rich-message-renderer.css"]
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
static get properties() {
|
|
296
|
+
return {
|
|
297
|
+
"content": {
|
|
298
|
+
"type": "unknown",
|
|
299
|
+
"mutable": false,
|
|
300
|
+
"complexType": {
|
|
301
|
+
"original": "StructuredMessageContent",
|
|
302
|
+
"resolved": "StructuredMessageContent",
|
|
303
|
+
"references": {
|
|
304
|
+
"StructuredMessageContent": {
|
|
305
|
+
"location": "import",
|
|
306
|
+
"path": "@chat-leo/chatleolib",
|
|
307
|
+
"id": "../chatleolib/dist/index.d.ts::StructuredMessageContent",
|
|
308
|
+
"referenceLocation": "StructuredMessageContent"
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
"required": false,
|
|
313
|
+
"optional": false,
|
|
314
|
+
"docs": {
|
|
315
|
+
"tags": [],
|
|
316
|
+
"text": "The structured message content object to be rendered. This object contains an array of blocks, each of which can be a text or attachment block."
|
|
317
|
+
},
|
|
318
|
+
"getter": false,
|
|
319
|
+
"setter": false
|
|
320
|
+
},
|
|
321
|
+
"downloadUrls": {
|
|
322
|
+
"type": "unknown",
|
|
323
|
+
"mutable": false,
|
|
324
|
+
"complexType": {
|
|
325
|
+
"original": "Record<string, AttachmentDownloadInfo>",
|
|
326
|
+
"resolved": "AttachmentDownloadInfo | string",
|
|
327
|
+
"references": {
|
|
328
|
+
"Record": {
|
|
329
|
+
"location": "global",
|
|
330
|
+
"id": "global::Record"
|
|
331
|
+
},
|
|
332
|
+
"AttachmentDownloadInfo": {
|
|
333
|
+
"location": "import",
|
|
334
|
+
"path": "@chat-leo/chatleolib",
|
|
335
|
+
"id": "../chatleolib/dist/index.d.ts::AttachmentDownloadInfo",
|
|
336
|
+
"referenceLocation": "AttachmentDownloadInfo"
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
"required": false,
|
|
341
|
+
"optional": false,
|
|
342
|
+
"docs": {
|
|
343
|
+
"tags": [],
|
|
344
|
+
"text": "A map where keys are attachment IDs and values are objects containing download information for those attachments, such as the download URL."
|
|
345
|
+
},
|
|
346
|
+
"getter": false,
|
|
347
|
+
"setter": false,
|
|
348
|
+
"defaultValue": "{}"
|
|
349
|
+
},
|
|
350
|
+
"alignment": {
|
|
351
|
+
"type": "string",
|
|
352
|
+
"mutable": false,
|
|
353
|
+
"complexType": {
|
|
354
|
+
"original": "'left' | 'right'",
|
|
355
|
+
"resolved": "\"left\" | \"right\"",
|
|
356
|
+
"references": {}
|
|
357
|
+
},
|
|
358
|
+
"required": false,
|
|
359
|
+
"optional": false,
|
|
360
|
+
"docs": {
|
|
361
|
+
"tags": [],
|
|
362
|
+
"text": "This property determines the text alignment of the message content. It can be either `'left'` or `'right'`."
|
|
363
|
+
},
|
|
364
|
+
"getter": false,
|
|
365
|
+
"setter": false,
|
|
366
|
+
"reflect": false,
|
|
367
|
+
"attribute": "alignment",
|
|
368
|
+
"defaultValue": "'left'"
|
|
369
|
+
},
|
|
370
|
+
"translations": {
|
|
371
|
+
"type": "unknown",
|
|
372
|
+
"mutable": false,
|
|
373
|
+
"complexType": {
|
|
374
|
+
"original": "Record<string, string>",
|
|
375
|
+
"resolved": "string",
|
|
376
|
+
"references": {
|
|
377
|
+
"Record": {
|
|
378
|
+
"location": "global",
|
|
379
|
+
"id": "global::Record"
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
"required": false,
|
|
384
|
+
"optional": false,
|
|
385
|
+
"docs": {
|
|
386
|
+
"tags": [],
|
|
387
|
+
"text": "Optional translations overriding the default UI strings (e.g. `unsupported_content`)."
|
|
388
|
+
},
|
|
389
|
+
"getter": false,
|
|
390
|
+
"setter": false,
|
|
391
|
+
"defaultValue": "{}"
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
static get states() {
|
|
396
|
+
return {
|
|
397
|
+
"attachmentStates": {}
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
--room-list-width: 250px;
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
max-height: 100%;
|
|
6
|
+
min-height: 0;
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.room-list-container {
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
flex: 1;
|
|
14
|
+
min-height: 0;
|
|
15
|
+
min-width: var(--room-list-width);
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.room-list-header {
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
justify-content: space-between;
|
|
23
|
+
gap: 8px;
|
|
24
|
+
padding: 12px 16px;
|
|
25
|
+
border-bottom: 1px solid var(--border-light);
|
|
26
|
+
flex-shrink: 0;
|
|
27
|
+
font-family: var(--font-primary), sans-serif;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.room-list-title {
|
|
31
|
+
font-weight: 700;
|
|
32
|
+
font-size: 16px;
|
|
33
|
+
color: var(--text-primary, #171A1F);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.new-chat-btn {
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
justify-content: center;
|
|
40
|
+
width: 28px;
|
|
41
|
+
height: 28px;
|
|
42
|
+
border: 1px solid var(--border-light);
|
|
43
|
+
border-radius: 6px;
|
|
44
|
+
background: transparent;
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
padding: 0;
|
|
47
|
+
margin: 0;
|
|
48
|
+
flex: 0 0 auto;
|
|
49
|
+
color: #565D6D;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.new-chat-btn:hover {
|
|
53
|
+
color: var(--text-primary, #171A1F);
|
|
54
|
+
background-color: var(--hover-color, #f3f4f6);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.room-list {
|
|
58
|
+
min-width: var(--room-list-width);
|
|
59
|
+
max-height: 100%;
|
|
60
|
+
max-width: 100%;
|
|
61
|
+
display: flex;
|
|
62
|
+
flex-direction: column;
|
|
63
|
+
overflow-y: auto;
|
|
64
|
+
overflow-x: hidden;
|
|
65
|
+
font-family: var(--font-primary), sans-serif;
|
|
66
|
+
min-height: 0;
|
|
67
|
+
flex: 1;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.room-list-empty {
|
|
71
|
+
display: flex;
|
|
72
|
+
flex-direction: column;
|
|
73
|
+
align-items: flex-start;
|
|
74
|
+
gap: 8px;
|
|
75
|
+
padding: 16px;
|
|
76
|
+
font-family: var(--font-primary), sans-serif;
|
|
77
|
+
color: var(--text-secondary, #565D6D);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.room-list-empty p {
|
|
81
|
+
margin: 0;
|
|
82
|
+
font-size: 14px;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.empty-new-chat-btn {
|
|
86
|
+
border: 1px solid var(--border-light);
|
|
87
|
+
background: transparent;
|
|
88
|
+
color: var(--text-primary, #171A1F);
|
|
89
|
+
border-radius: var(--border-radius, 6px);
|
|
90
|
+
padding: 6px 12px;
|
|
91
|
+
cursor: pointer;
|
|
92
|
+
font-size: 14px;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.empty-new-chat-btn:hover {
|
|
96
|
+
background-color: var(--hover-color, #f3f4f6);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.active {
|
|
100
|
+
background-color: var(--bg-secondary, #f0f0f0);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.room-list > * {
|
|
104
|
+
flex-shrink: 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
chatleo-new-message-selector {
|
|
108
|
+
flex: 1;
|
|
109
|
+
min-height: 0;
|
|
110
|
+
overflow-y: auto;
|
|
111
|
+
}
|