Skip to content

Commit ad0e2eb

Browse files
committed
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/IgniteUI/igniteui-webcomponents into dmdimitrov/chat-ai-component
2 parents 8b2d30e + 1b0a763 commit ad0e2eb

File tree

16 files changed

+629
-289
lines changed

16 files changed

+629
-289
lines changed

package-lock.json

Lines changed: 539 additions & 215 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"lit": "^3.3.1"
6060
},
6161
"devDependencies": {
62-
"@biomejs/biome": "~2.2.3",
62+
"@biomejs/biome": "~2.2.4",
6363
"@custom-elements-manifest/analyzer": "^0.10.5",
6464
"@igniteui/material-icons-extended": "^3.1.0",
6565
"@open-wc/testing": "^4.0.0",
@@ -81,7 +81,7 @@
8181
"globby": "^14.1.0",
8282
"husky": "^9.1.7",
8383
"ig-typedoc-theme": "^6.2.3",
84-
"igniteui-theming": "^19.3.0",
84+
"igniteui-theming": "^19.3.1",
8585
"keep-a-changelog": "^2.7.0",
8686
"lint-staged": "^16.1.6",
8787
"lit-analyzer": "^2.0.3",
@@ -91,11 +91,11 @@
9191
"postcss": "^8.5.6",
9292
"prettier": "^3.6.2",
9393
"rimraf": "^6.0.1",
94-
"sass-embedded": "~1.78.0",
94+
"sass-embedded": "~1.92.1",
9595
"sinon": "^21.0.0",
9696
"storybook": "^9.1.5",
9797
"stylelint": "^16.24.0",
98-
"stylelint-config-standard-scss": "^15.0.1",
98+
"stylelint-config-standard-scss": "^16.0.0",
9999
"stylelint-prettier": "^5.0.3",
100100
"stylelint-scss": "^6.12.1",
101101
"ts-lit-plugin": "^2.0.2",

src/components/chat/chat-input.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import type {
2222
ChatInputRenderContext,
2323
ChatRenderContext,
2424
ChatTemplateRenderer,
25-
IgcMessageAttachment,
25+
IgcChatMessageAttachment,
2626
} from './types.js';
2727
import { getChatAcceptedFiles, getIconName } from './utils.js';
2828

2929
type DefaultInputRenderers = {
3030
input: ChatTemplateRenderer<ChatInputRenderContext>;
3131
inputActions: ChatTemplateRenderer<ChatRenderContext>;
32+
inputActionsEnd: ChatTemplateRenderer<ChatRenderContext>;
33+
inputActionsStart: ChatTemplateRenderer<ChatRenderContext>;
3234
inputAttachments: ChatTemplateRenderer<ChatInputRenderContext>;
3335
fileUploadButton: ChatTemplateRenderer<ChatRenderContext>;
3436
sendButton: ChatTemplateRenderer<ChatRenderContext>;
@@ -81,6 +83,8 @@ export default class IgcChatInputComponent extends LitElement {
8183
fileUploadButton: () => this._renderFileUploadButton(),
8284
input: () => this._renderTextArea(),
8385
inputActions: () => this._renderActionsArea(),
86+
inputActionsEnd: () => nothing,
87+
inputActionsStart: () => nothing,
8488
inputAttachments: (ctx) => this._renderAttachmentsArea(ctx.attachments),
8589
sendButton: () => this._renderSendButton(),
8690
});
@@ -213,7 +217,7 @@ export default class IgcChatInputComponent extends LitElement {
213217
* Renders the list of input attachments as chips.
214218
* @returns TemplateResult containing the attachments area
215219
*/
216-
private _renderAttachmentsArea(attachments: IgcMessageAttachment[]) {
220+
private _renderAttachmentsArea(attachments: IgcChatMessageAttachment[]) {
217221
return html`${attachments?.map(
218222
(attachment, index) => html`
219223
<div part="attachment-wrapper" role="listitem">
@@ -314,7 +318,9 @@ export default class IgcChatInputComponent extends LitElement {
314318

315319
return html`
316320
${this._getRenderer('fileUploadButton')(ctx)}
321+
${this._getRenderer('inputActionsStart')(ctx)}
317322
${this._getRenderer('sendButton')(ctx)}
323+
${this._getRenderer('inputActionsEnd')(ctx)}
318324
`;
319325
}
320326

src/components/chat/chat-message.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { styles as shared } from './themes/shared/chat-message/chat-message.comm
1919
import type {
2020
ChatMessageRenderContext,
2121
ChatTemplateRenderer,
22-
IgcMessage,
22+
IgcChatMessage,
2323
} from './types.js';
2424
import { chatMessageAdoptPageStyles } from './utils.js';
2525

@@ -87,7 +87,7 @@ export default class IgcChatMessageComponent extends LitElement {
8787
* The chat message to render.
8888
*/
8989
@property({ attribute: false })
90-
public message?: IgcMessage;
90+
public message?: IgcChatMessage;
9191

9292
constructor() {
9393
super();

src/components/chat/chat-state.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import IgcTooltipComponent from '../tooltip/tooltip.js';
77
import type IgcChatComponent from './chat.js';
88
import type { IgcChatComponentEventMap } from './chat.js';
99
import type {
10+
IgcChatMessage,
11+
IgcChatMessageAttachment,
1012
IgcChatOptions,
11-
IgcMessage,
12-
IgcMessageAttachment,
1313
} from './types.js';
1414
import {
1515
type ChatAcceptedFileTypes,
@@ -35,12 +35,12 @@ export class ChatState {
3535
private _actionsTooltip?: IgcTooltipComponent;
3636
private _actionToast?: IgcToastComponent;
3737
/** The current list of messages */
38-
private _messages: IgcMessage[] = [];
38+
private _messages: IgcChatMessage[] = [];
3939
/** Chat options/configuration */
4040
private _options?: IgcChatOptions;
4141

4242
/** List of current input attachments */
43-
private _inputAttachments: IgcMessageAttachment[] = [];
43+
private _inputAttachments: IgcChatMessageAttachment[] = [];
4444
/** Current input text */
4545
private _inputValue = '';
4646
/**
@@ -77,14 +77,14 @@ export class ChatState {
7777
/**
7878
* Gets the list of chat messages.
7979
*/
80-
public get messages(): IgcMessage[] {
80+
public get messages(): IgcChatMessage[] {
8181
return this._messages;
8282
}
8383

8484
/**
8585
* Sets the list of chat messages.
8686
*/
87-
public set messages(value: IgcMessage[]) {
87+
public set messages(value: IgcChatMessage[]) {
8888
this._messages = value;
8989
}
9090

@@ -141,14 +141,14 @@ export class ChatState {
141141
/**
142142
* Gets the list of attachments currently attached to input.
143143
*/
144-
public get inputAttachments(): IgcMessageAttachment[] {
144+
public get inputAttachments(): IgcChatMessageAttachment[] {
145145
return this._inputAttachments;
146146
}
147147

148148
/**
149149
* Sets the input attachments and requests host update.
150150
*/
151-
public set inputAttachments(value: IgcMessageAttachment[]) {
151+
public set inputAttachments(value: IgcChatMessageAttachment[]) {
152152
this._inputAttachments = value;
153153
this._userInputContextUpdateFn.call(this._host);
154154
}
@@ -188,7 +188,7 @@ export class ChatState {
188188
this._userInputContextUpdateFn = userInputContextUpdateFn;
189189
}
190190

191-
public isCurrentUserMessage(message?: IgcMessage): boolean {
191+
public isCurrentUserMessage(message?: IgcChatMessage): boolean {
192192
return this.currentUserId === message?.sender;
193193
}
194194

@@ -222,7 +222,7 @@ export class ChatState {
222222

223223
//#endregion
224224

225-
protected _createMessage(message: Partial<IgcMessage>): IgcMessage {
225+
protected _createMessage(message: Partial<IgcChatMessage>): IgcChatMessage {
226226
return {
227227
id: message.id ?? nanoid(),
228228
text: message.text ?? '',
@@ -232,7 +232,7 @@ export class ChatState {
232232
};
233233
}
234234

235-
public addMessage(message: Partial<IgcMessage>) {
235+
public addMessage(message: Partial<IgcChatMessage>) {
236236
this.messages.push(this._createMessage(message));
237237
this._host.requestUpdate('messages');
238238
}
@@ -245,7 +245,7 @@ export class ChatState {
245245
* Clears input value and attachments on success.
246246
* @internal
247247
*/
248-
public addMessageWithEvent(message: Partial<IgcMessage>): void {
248+
public addMessageWithEvent(message: Partial<IgcChatMessage>): void {
249249
const newMessage = this._createMessage(message);
250250

251251
if (
@@ -266,7 +266,7 @@ export class ChatState {
266266
* @param files Array of File objects to attach
267267
*/
268268
public attachFiles(files: File[]) {
269-
const newAttachments: IgcMessageAttachment[] = [];
269+
const newAttachments: IgcChatMessageAttachment[] = [];
270270
const fileNames = new Set(
271271
this.inputAttachments.map((attachment) => attachment.file?.name ?? '')
272272
);

src/components/chat/chat.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import { simulateFileUpload } from '../file-input/file-input.spec.js';
2727
import IgcInputComponent from '../input/input.js';
2828
import IgcChatComponent from './chat.js';
29-
import type { IgcMessage, IgcMessageAttachment } from './types.js';
29+
import type { IgcChatMessage, IgcChatMessageAttachment } from './types.js';
3030

3131
describe('Chat', () => {
3232
before(() => {
@@ -52,7 +52,7 @@ describe('Chat', () => {
5252
`;
5353
};
5454

55-
const messageActionsTemplate = (msg: IgcMessage) => {
55+
const messageActionsTemplate = (msg: IgcChatMessage) => {
5656
return msg.sender !== 'user' && msg.text.trim()
5757
? html`
5858
<div style="float: right">
@@ -89,7 +89,9 @@ describe('Chat', () => {
8989
</div>
9090
`;
9191

92-
const textAreaAttachmentsTemplate = (attachments: IgcMessageAttachment[]) => {
92+
const textAreaAttachmentsTemplate = (
93+
attachments: IgcChatMessageAttachment[]
94+
) => {
9395
return html`
9496
<div>
9597
${attachments.map(
@@ -108,7 +110,7 @@ describe('Chat', () => {
108110
`;
109111
};
110112

111-
const messages: IgcMessage[] = [
113+
const messages: IgcChatMessage[] = [
112114
{
113115
id: '1',
114116
text: 'Hello! How can I help you today?',

src/components/chat/chat.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import { all } from './themes/themes.js';
2323
import type {
2424
ChatRenderContext,
2525
ChatTemplateRenderer,
26+
IgcChatMessage,
27+
IgcChatMessageAttachment,
2628
IgcChatOptions,
27-
IgcMessage,
28-
IgcMessageAttachment,
2929
} from './types.js';
3030

3131
type DefaultChatRenderers = {
@@ -40,22 +40,22 @@ export interface IgcChatComponentEventMap {
4040
/**
4141
* Dispatched when a new chat message is created (sent).
4242
*/
43-
igcMessageCreated: CustomEvent<IgcMessage>;
43+
igcMessageCreated: CustomEvent<IgcChatMessage>;
4444

4545
/**
4646
* Dispatched when a message is reacted to.
4747
*/
48-
igcMessageReact: CustomEvent<{ message: IgcMessage; reaction: string }>;
48+
igcMessageReact: CustomEvent<{ message: IgcChatMessage; reaction: string }>;
4949

5050
/**
5151
* Dispatched when a chat message attachment is clicked.
5252
*/
53-
igcAttachmentClick: CustomEvent<IgcMessageAttachment>;
53+
igcAttachmentClick: CustomEvent<IgcChatMessageAttachment>;
5454

5555
/**
5656
* Dispatched when an attachment is changed (e.g., updated or removed).
5757
*/
58-
igcAttachmentChange: CustomEvent<IgcMessageAttachment>;
58+
igcAttachmentChange: CustomEvent<IgcChatMessageAttachment>;
5959

6060
/**
6161
* Dispatched during an attachment drag operation.
@@ -188,11 +188,11 @@ export default class IgcChatComponent extends EventEmitterMixin<
188188
* Use this property to set or update the message history.
189189
*/
190190
@property({ attribute: false })
191-
public set messages(value: IgcMessage[]) {
191+
public set messages(value: IgcChatMessage[]) {
192192
this._state.messages = value;
193193
}
194194

195-
public get messages(): IgcMessage[] {
195+
public get messages(): IgcChatMessage[] {
196196
return this._state.messages;
197197
}
198198

@@ -203,7 +203,7 @@ export default class IgcChatComponent extends EventEmitterMixin<
203203
@property({ attribute: false })
204204
public set draftMessage(value: {
205205
text: string;
206-
attachments?: IgcMessageAttachment[];
206+
attachments?: IgcChatMessageAttachment[];
207207
}) {
208208
if (this._state && value) {
209209
this._state.inputValue = value.text;
@@ -214,7 +214,7 @@ export default class IgcChatComponent extends EventEmitterMixin<
214214

215215
public get draftMessage(): {
216216
text: string;
217-
attachments?: IgcMessageAttachment[];
217+
attachments?: IgcChatMessageAttachment[];
218218
} {
219219
return {
220220
text: this._state.inputValue,
@@ -267,15 +267,15 @@ export default class IgcChatComponent extends EventEmitterMixin<
267267
}
268268

269269
// REVIEW
270-
public addMessage(message: Partial<IgcMessage>): IgcMessage {
270+
public addMessage(message: Partial<IgcChatMessage>): IgcChatMessage {
271271
this._state.addMessage(message);
272272
return last(this.messages);
273273
}
274274

275275
// REVIEW
276276
public updateMessage(
277-
message: IgcMessage,
278-
data: Partial<IgcMessage>,
277+
message: IgcChatMessage,
278+
data: Partial<IgcChatMessage>,
279279
scrollIntoView = false
280280
) {
281281
Object.assign(message, data);

src/components/chat/extras/markdown-renderer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { unsafeHTML } from 'lit/directives/unsafe-html.js';
33
import { Marked } from 'marked';
44
import markedShiki from 'marked-shiki';
55
import { bundledThemes, createHighlighter } from 'shiki/bundle/web';
6-
import type { IgcMessage } from '../types.js';
6+
import type { IgcChatMessage } from '../types.js';
77

88
const DEFAULT_LANGUAGES = ['javascript', 'typescript', 'html', 'css'];
99
const DEFAULT_THEME = {
@@ -79,7 +79,7 @@ export async function createMarkdownRenderer(
7979
);
8080
}
8181

82-
return async (message: IgcMessage): Promise<unknown> => {
82+
return async (message: IgcChatMessage): Promise<unknown> => {
8383
return message.text
8484
? unsafeHTML(sanitizer(await markdown.parse(message.text)))
8585
: '';

0 commit comments

Comments
 (0)