Skip to content

Commit 4194e8f

Browse files
committed
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/IgniteUI/igniteui-webcomponents into dmdimitrov/chat-ai-component
2 parents 1e704e3 + c201da2 commit 4194e8f

File tree

3 files changed

+82
-9
lines changed

3 files changed

+82
-9
lines changed

src/components/chat/chat-message-list.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default class IgcChatMessageListComponent extends LitElement {
6565
* @param messageId - The id of the message to scroll to
6666
* @private
6767
*/
68-
private scrollToMessage(messageId: string) {
68+
public scrollToMessage(messageId: string) {
6969
const messageElement = this.shadowRoot?.querySelector(
7070
`#message-${messageId}`
7171
);
@@ -133,7 +133,10 @@ export default class IgcChatMessageListComponent extends LitElement {
133133
id=${messageId}
134134
role="option"
135135
part="message-item"
136+
data-role=${message.sender}
136137
.message=${message}
138+
exportparts="message-container, bubble, message-text, message-attachments, message-actions,
139+
attachments-container, attachment, attachment-header, attachment-content, attachment-icon, file-name, actions: attachment-actions"
137140
>
138141
</igc-chat-message>
139142
`;

src/components/chat/chat-message.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { consume } from '@lit/context';
2-
import DOMPurify from 'dompurify';
2+
// import DOMPurify from 'dompurify';
33
import { html, LitElement, nothing } from 'lit';
44
import { property } from 'lit/decorators.js';
55
import { addThemingController } from '../../theming/theming-controller.js';
@@ -79,7 +79,7 @@ export default class IgcChatMessageComponent extends LitElement {
7979
* @private
8080
*/
8181
private sanitizeMessageText(text: string): string {
82-
return DOMPurify.sanitize(text);
82+
return text.trim();
8383
}
8484

8585
constructor() {
@@ -96,7 +96,7 @@ export default class IgcChatMessageComponent extends LitElement {
9696
return this.message?.sender !== 'user' &&
9797
this.message?.text.trim() &&
9898
(!isLastMessage || !this._chatState?.options?.isTyping)
99-
? html`<div>
99+
? html`<div part="message-actions">
100100
<igc-icon-button
101101
name="copy"
102102
collection="material"
@@ -152,10 +152,16 @@ export default class IgcChatMessageComponent extends LitElement {
152152
${this._chatState?.options?.templates?.messageTemplate && this.message
153153
? this._chatState.options.templates.messageTemplate(this.message)
154154
: html`${sanitizedMessageText
155-
? html`<div>${renderer(sanitizedMessageText)}</div>`
155+
? html`<div part="message-text">
156+
${renderer(sanitizedMessageText)}
157+
</div>`
156158
: nothing}`}
157159
${this.message?.attachments && this.message?.attachments.length > 0
158-
? html`<igc-message-attachments .message=${this.message}>
160+
? html` <igc-message-attachments
161+
.message=${this.message}
162+
part="message-attachments"
163+
exportparts="message-attachments,attachments-container, attachment, attachment-header, attachment-content, attachment-icon, file-name, actions: attachment-actions"
164+
>
159165
</igc-message-attachments>`
160166
: nothing}
161167
${this._chatState?.options?.templates?.messageActionsTemplate &&

src/components/chat/chat.ts

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,21 +366,85 @@ export default class IgcChatComponent extends EventEmitterMixin<
366366
this._chatState.options?.suggestions &&
367367
this._chatState.options.suggestions.length > 0;
368368
return html`
369-
<div part="chat-container">
369+
<div
370+
part="chat-container"
371+
exportparts="
372+
chat-container,
373+
header,
374+
prefix,
375+
title,
376+
actions,
377+
chat-wrapper,
378+
chat-messages,
379+
empty-state,
380+
suggestions-container,
381+
suggestions-header,
382+
suggestions,
383+
suggestions-actions,
384+
suggestion,
385+
message-container,
386+
message-list,
387+
message-item,
388+
message,
389+
bubble,
390+
message-text,
391+
message-attachments,
392+
message-actions,
393+
typing-indicator,
394+
attachments-container,
395+
attachment,
396+
attachment-header,
397+
attachment-content,
398+
attachment-icon,
399+
file-name,
400+
attachment-actions
401+
"
402+
>
370403
${this.renderHeader()}
371404
<div part="chat-wrapper">
372405
${this.messages.length === 0
373406
? html`<div part="empty-state">
374407
<slot name="empty-state"> </slot>
375408
</div>`
376-
: html`<igc-chat-message-list part="chat-messages">
409+
: html` <igc-chat-message-list
410+
part="chat-messages"
411+
exportparts="
412+
message-container,
413+
message-list,
414+
message-item,
415+
message,
416+
bubble,
417+
message-text,
418+
message-attachments,
419+
message-actions,
420+
typing-indicator,
421+
attachments-container,
422+
attachment,
423+
attachment-header,
424+
attachment-content,
425+
attachment-icon,
426+
file-name,
427+
actions: attachment-actions"
428+
>
377429
</igc-chat-message-list>`}
378430
${hasSuggestions &&
379431
this._chatState.suggestionsPosition === 'below-messages'
380432
? this.renderSuggestions()
381433
: nothing}
382434
</div>
383-
<igc-chat-input> </igc-chat-input>
435+
<igc-chat-input
436+
exportparts="
437+
input-container,
438+
input-wrapper,
439+
attachments: input-attachments-container,
440+
attachments-wrapper: input-attachment,
441+
attachment-name: input-attachment-name,
442+
text-input,
443+
buttons-container: input-buttons-container,
444+
upload-button,
445+
send-button"
446+
>
447+
</igc-chat-input>
384448
${hasSuggestions &&
385449
this._chatState.suggestionsPosition === 'below-input'
386450
? this.renderSuggestions()

0 commit comments

Comments
 (0)