igniteui-webcomponents 6.3.0-beta.0 → 6.3.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/CHANGELOG.md +14 -0
- package/components/accordion/accordion.js +3 -4
- package/components/accordion/accordion.js.map +1 -1
- package/components/avatar/avatar.js +3 -4
- package/components/avatar/avatar.js.map +1 -1
- package/components/badge/badge.js +3 -4
- package/components/badge/badge.js.map +1 -1
- package/components/banner/banner.js +3 -4
- package/components/banner/banner.js.map +1 -1
- package/components/button/button-base.js +1 -1
- package/components/button/button-base.js.map +1 -1
- package/components/button/button.js +3 -4
- package/components/button/button.js.map +1 -1
- package/components/button/icon-button.js +3 -4
- package/components/button/icon-button.js.map +1 -1
- package/components/button-group/button-group.js +3 -4
- package/components/button-group/button-group.js.map +1 -1
- package/components/button-group/toggle-button.js +4 -3
- package/components/button-group/toggle-button.js.map +1 -1
- package/components/calendar/calendar.js +3 -4
- package/components/calendar/calendar.js.map +1 -1
- package/components/calendar/days-view/days-view.js +4 -3
- package/components/calendar/days-view/days-view.js.map +1 -1
- package/components/calendar/months-view/months-view.js +4 -3
- package/components/calendar/months-view/months-view.js.map +1 -1
- package/components/calendar/years-view/years-view.js +4 -3
- package/components/calendar/years-view/years-view.js.map +1 -1
- package/components/card/card.actions.js +3 -4
- package/components/card/card.actions.js.map +1 -1
- package/components/card/card.content.js +3 -4
- package/components/card/card.content.js.map +1 -1
- package/components/card/card.header.js +3 -4
- package/components/card/card.header.js.map +1 -1
- package/components/card/card.js +3 -4
- package/components/card/card.js.map +1 -1
- package/components/card/card.media.js +3 -4
- package/components/card/card.media.js.map +1 -1
- package/components/carousel/carousel-indicator-container.js +3 -4
- package/components/carousel/carousel-indicator-container.js.map +1 -1
- package/components/carousel/carousel-indicator.js +3 -4
- package/components/carousel/carousel-indicator.js.map +1 -1
- package/components/carousel/carousel-slide.js +3 -4
- package/components/carousel/carousel-slide.js.map +1 -1
- package/components/carousel/carousel.js +3 -4
- package/components/carousel/carousel.js.map +1 -1
- package/components/chat/chat-input.d.ts +8 -20
- package/components/chat/chat-input.js +78 -56
- package/components/chat/chat-input.js.map +1 -1
- package/components/chat/chat-message.d.ts +6 -21
- package/components/chat/chat-message.js +113 -71
- package/components/chat/chat-message.js.map +1 -1
- package/components/chat/chat-state.d.ts +45 -50
- package/components/chat/chat-state.js +82 -91
- package/components/chat/chat-state.js.map +1 -1
- package/components/chat/chat.d.ts +68 -24
- package/components/chat/chat.js +99 -96
- package/components/chat/chat.js.map +1 -1
- package/components/chat/extras/markdown-renderer.d.ts +6 -3
- package/components/chat/extras/markdown-renderer.js +19 -14
- package/components/chat/extras/markdown-renderer.js.map +1 -1
- package/components/chat/message-attachments.d.ts +5 -5
- package/components/chat/message-attachments.js +49 -43
- package/components/chat/message-attachments.js.map +1 -1
- package/components/chat/themes/chat.base.css.js +1 -1
- package/components/chat/themes/chat.base.css.js.map +1 -1
- package/components/chat/themes/dark/chat.bootstrap.css.js +1 -1
- package/components/chat/themes/dark/chat.bootstrap.css.js.map +1 -1
- package/components/chat/themes/dark/chat.fluent.css.js +1 -1
- package/components/chat/themes/dark/chat.fluent.css.js.map +1 -1
- package/components/chat/themes/dark/chat.indigo.css.js +1 -1
- package/components/chat/themes/dark/chat.indigo.css.js.map +1 -1
- package/components/chat/themes/dark/chat.material.css.js +1 -1
- package/components/chat/themes/dark/chat.material.css.js.map +1 -1
- package/components/chat/themes/input.base.css.js +1 -1
- package/components/chat/themes/input.base.css.js.map +1 -1
- package/components/chat/themes/light/chat.bootstrap.css.js +1 -1
- package/components/chat/themes/light/chat.bootstrap.css.js.map +1 -1
- package/components/chat/themes/light/chat.indigo.css.js +1 -1
- package/components/chat/themes/light/chat.indigo.css.js.map +1 -1
- package/components/chat/themes/light/chat.shared.css.js +1 -1
- package/components/chat/themes/light/chat.shared.css.js.map +1 -1
- package/components/chat/themes/message-attachments.base.css.js +1 -1
- package/components/chat/themes/message-attachments.base.css.js.map +1 -1
- package/components/chat/themes/message.base.css.js +1 -1
- package/components/chat/themes/message.base.css.js.map +1 -1
- package/components/chat/themes/shared/chat.bootstrap.css.js +1 -1
- package/components/chat/themes/shared/chat.bootstrap.css.js.map +1 -1
- package/components/chat/themes/shared/chat.fluent.css.js +1 -1
- package/components/chat/themes/shared/chat.fluent.css.js.map +1 -1
- package/components/chat/themes/shared/chat.indigo.css.js +1 -1
- package/components/chat/themes/shared/chat.indigo.css.js.map +1 -1
- package/components/chat/themes/shared/input/input.bootstrap.css.js +1 -1
- package/components/chat/themes/shared/input/input.bootstrap.css.js.map +1 -1
- package/components/chat/themes/shared/input/input.fluent.css.js +1 -1
- package/components/chat/themes/shared/input/input.fluent.css.js.map +1 -1
- package/components/chat/themes/shared/input/input.indigo.css.js +1 -1
- package/components/chat/themes/shared/input/input.indigo.css.js.map +1 -1
- package/components/chat/themes/shared/message-attachments/message-attachments.common.css.js +1 -1
- package/components/chat/themes/shared/message-attachments/message-attachments.common.css.js.map +1 -1
- package/components/chat/types.d.ts +173 -28
- package/components/chat/types.js.map +1 -1
- package/components/chat/utils.d.ts +3 -3
- package/components/chat/utils.js +7 -11
- package/components/chat/utils.js.map +1 -1
- package/components/checkbox/checkbox.js +3 -4
- package/components/checkbox/checkbox.js.map +1 -1
- package/components/checkbox/switch.js +3 -4
- package/components/checkbox/switch.js.map +1 -1
- package/components/checkbox/themes/checkbox.base.css.js +1 -1
- package/components/checkbox/themes/checkbox.base.css.js.map +1 -1
- package/components/checkbox/themes/switch.base.css.js +1 -1
- package/components/checkbox/themes/switch.base.css.js.map +1 -1
- package/components/chip/chip.js +3 -4
- package/components/chip/chip.js.map +1 -1
- package/components/combo/combo-header.js +3 -4
- package/components/combo/combo-header.js.map +1 -1
- package/components/combo/combo-item.js +3 -4
- package/components/combo/combo-item.js.map +1 -1
- package/components/combo/combo-list.js +2 -3
- package/components/combo/combo-list.js.map +1 -1
- package/components/combo/combo.js +4 -3
- package/components/combo/combo.js.map +1 -1
- package/components/common/controllers/focus-ring.js +5 -5
- package/components/common/controllers/focus-ring.js.map +1 -1
- package/components/common/controllers/key-bindings.js +4 -4
- package/components/common/controllers/key-bindings.js.map +1 -1
- package/components/common/i18n/chat.resources.d.ts +3 -0
- package/components/common/i18n/chat.resources.js +3 -0
- package/components/common/i18n/chat.resources.js.map +1 -1
- package/components/common/mixins/forms/associated.js +1 -1
- package/components/common/mixins/forms/associated.js.map +1 -1
- package/components/common/mixins/forms/form-value.js +1 -1
- package/components/common/mixins/forms/form-value.js.map +1 -1
- package/components/common/part-map.d.ts +1 -1
- package/components/common/util.d.ts +3 -0
- package/components/common/util.js +9 -1
- package/components/common/util.js.map +1 -1
- package/components/date-picker/date-picker.js +5 -4
- package/components/date-picker/date-picker.js.map +1 -1
- package/components/date-range-picker/date-range-picker.js +5 -4
- package/components/date-range-picker/date-range-picker.js.map +1 -1
- package/components/date-range-picker/predefined-ranges-area.js +3 -4
- package/components/date-range-picker/predefined-ranges-area.js.map +1 -1
- package/components/date-time-input/date-time-input.js +2 -3
- package/components/date-time-input/date-time-input.js.map +1 -1
- package/components/date-time-input/date-util.js +11 -11
- package/components/date-time-input/date-util.js.map +1 -1
- package/components/dialog/dialog.js +3 -4
- package/components/dialog/dialog.js.map +1 -1
- package/components/divider/divider.js +3 -4
- package/components/divider/divider.js.map +1 -1
- package/components/dropdown/dropdown-group.js +3 -4
- package/components/dropdown/dropdown-group.js.map +1 -1
- package/components/dropdown/dropdown-header.js +3 -4
- package/components/dropdown/dropdown-header.js.map +1 -1
- package/components/dropdown/dropdown-item.js +3 -4
- package/components/dropdown/dropdown-item.js.map +1 -1
- package/components/dropdown/dropdown.js +4 -3
- package/components/dropdown/dropdown.js.map +1 -1
- package/components/expansion-panel/expansion-panel.js +3 -4
- package/components/expansion-panel/expansion-panel.js.map +1 -1
- package/components/file-input/file-input.js +3 -4
- package/components/file-input/file-input.js.map +1 -1
- package/components/focus-trap/focus-trap.js +7 -8
- package/components/focus-trap/focus-trap.js.map +1 -1
- package/components/icon/icon-references.js +78 -0
- package/components/icon/icon-references.js.map +1 -1
- package/components/icon/icon-state.broadcast.js +1 -1
- package/components/icon/icon-state.broadcast.js.map +1 -1
- package/components/icon/icon.js +3 -4
- package/components/icon/icon.js.map +1 -1
- package/components/icon/internal-icons-lib.js +39 -0
- package/components/icon/internal-icons-lib.js.map +1 -1
- package/components/input/input-base.js +4 -3
- package/components/input/input-base.js.map +1 -1
- package/components/input/input.js +2 -3
- package/components/input/input.js.map +1 -1
- package/components/input/themes/shared/input.bootstrap.css.js +1 -1
- package/components/input/themes/shared/input.bootstrap.css.js.map +1 -1
- package/components/input/themes/shared/input.indigo.css.js +1 -1
- package/components/input/themes/shared/input.indigo.css.js.map +1 -1
- package/components/list/list-header.js +3 -4
- package/components/list/list-header.js.map +1 -1
- package/components/list/list-item.js +3 -4
- package/components/list/list-item.js.map +1 -1
- package/components/list/list.js +3 -4
- package/components/list/list.js.map +1 -1
- package/components/list/themes/header.js +2 -28
- package/components/list/themes/header.js.map +1 -1
- package/components/list/themes/item.js +6 -20
- package/components/list/themes/item.js.map +1 -1
- package/components/mask-input/mask-input.js +2 -3
- package/components/mask-input/mask-input.js.map +1 -1
- package/components/nav-drawer/nav-drawer-header-item.js +3 -4
- package/components/nav-drawer/nav-drawer-header-item.js.map +1 -1
- package/components/nav-drawer/nav-drawer-item.js +3 -4
- package/components/nav-drawer/nav-drawer-item.js.map +1 -1
- package/components/nav-drawer/nav-drawer.js +3 -4
- package/components/nav-drawer/nav-drawer.js.map +1 -1
- package/components/navbar/navbar.js +3 -4
- package/components/navbar/navbar.js.map +1 -1
- package/components/popover/popover.js +9 -10
- package/components/popover/popover.js.map +1 -1
- package/components/progress/circular-gradient.js +2 -3
- package/components/progress/circular-gradient.js.map +1 -1
- package/components/progress/circular-progress.js +3 -4
- package/components/progress/circular-progress.js.map +1 -1
- package/components/progress/linear-progress.js +3 -4
- package/components/progress/linear-progress.js.map +1 -1
- package/components/radio/radio.js +3 -4
- package/components/radio/radio.js.map +1 -1
- package/components/radio-group/radio-group.js +3 -4
- package/components/radio-group/radio-group.js.map +1 -1
- package/components/rating/rating-symbol.js +3 -4
- package/components/rating/rating-symbol.js.map +1 -1
- package/components/rating/rating.js +3 -4
- package/components/rating/rating.js.map +1 -1
- package/components/resize-container/resize-container.js +3 -4
- package/components/resize-container/resize-container.js.map +1 -1
- package/components/ripple/ripple.js +3 -4
- package/components/ripple/ripple.js.map +1 -1
- package/components/select/select-group.js +3 -4
- package/components/select/select-group.js.map +1 -1
- package/components/select/select-header.js +3 -4
- package/components/select/select-header.js.map +1 -1
- package/components/select/select-item.js +3 -4
- package/components/select/select-item.js.map +1 -1
- package/components/select/select.js +4 -3
- package/components/select/select.js.map +1 -1
- package/components/slider/range-slider.js +2 -3
- package/components/slider/range-slider.js.map +1 -1
- package/components/slider/slider-base.js +1 -1
- package/components/slider/slider-base.js.map +1 -1
- package/components/slider/slider-label.js +7 -8
- package/components/slider/slider-label.js.map +1 -1
- package/components/slider/slider.js +2 -3
- package/components/slider/slider.js.map +1 -1
- package/components/snackbar/snackbar.js +3 -4
- package/components/snackbar/snackbar.js.map +1 -1
- package/components/stepper/step.js +3 -4
- package/components/stepper/step.js.map +1 -1
- package/components/stepper/stepper.js +3 -4
- package/components/stepper/stepper.js.map +1 -1
- package/components/tabs/tab-dom.js +1 -1
- package/components/tabs/tab-dom.js.map +1 -1
- package/components/tabs/tab.js +4 -5
- package/components/tabs/tab.js.map +1 -1
- package/components/tabs/tabs.js +3 -4
- package/components/tabs/tabs.js.map +1 -1
- package/components/textarea/textarea.js +4 -3
- package/components/textarea/textarea.js.map +1 -1
- package/components/textarea/themes/shared/textarea.bootstrap.css.js +1 -1
- package/components/textarea/themes/shared/textarea.bootstrap.css.js.map +1 -1
- package/components/tile-manager/themes/tile-manager.base.css.js +1 -1
- package/components/tile-manager/themes/tile-manager.base.css.js.map +1 -1
- package/components/tile-manager/tile-manager.js +4 -3
- package/components/tile-manager/tile-manager.js.map +1 -1
- package/components/tile-manager/tile.js +3 -4
- package/components/tile-manager/tile.js.map +1 -1
- package/components/toast/toast.js +3 -4
- package/components/toast/toast.js.map +1 -1
- package/components/tooltip/controller.js +4 -4
- package/components/tooltip/controller.js.map +1 -1
- package/components/tooltip/tooltip.js +3 -4
- package/components/tooltip/tooltip.js.map +1 -1
- package/components/tree/tree-item.js +3 -4
- package/components/tree/tree-item.js.map +1 -1
- package/components/tree/tree.js +4 -3
- package/components/tree/tree.js.map +1 -1
- package/components/validation-container/validation-container.js +3 -4
- package/components/validation-container/validation-container.js.map +1 -1
- package/custom-elements.json +2142 -2029
- package/igniteui-webcomponents.css-data.json +1 -1
- package/igniteui-webcomponents.html-data.json +1 -1
- package/package.json +24 -2
- package/web-types.json +2 -2
- package/components/list/themes/dark/header/list-header.bootstrap.css.d.ts +0 -1
- package/components/list/themes/dark/header/list-header.bootstrap.css.js +0 -3
- package/components/list/themes/dark/header/list-header.bootstrap.css.js.map +0 -1
- package/components/list/themes/dark/header/list-header.fluent.css.d.ts +0 -1
- package/components/list/themes/dark/header/list-header.fluent.css.js +0 -3
- package/components/list/themes/dark/header/list-header.fluent.css.js.map +0 -1
- package/components/list/themes/dark/header/list-header.indigo.css.d.ts +0 -1
- package/components/list/themes/dark/header/list-header.indigo.css.js +0 -3
- package/components/list/themes/dark/header/list-header.indigo.css.js.map +0 -1
- package/components/list/themes/dark/header/list-header.material.css.d.ts +0 -1
- package/components/list/themes/dark/header/list-header.material.css.js +0 -3
- package/components/list/themes/dark/header/list-header.material.css.js.map +0 -1
- package/components/list/themes/dark/item/list-item.bootstrap.css.d.ts +0 -1
- package/components/list/themes/dark/item/list-item.bootstrap.css.js +0 -3
- package/components/list/themes/dark/item/list-item.bootstrap.css.js.map +0 -1
- package/components/list/themes/dark/item/list-item.fluent.css.d.ts +0 -1
- package/components/list/themes/dark/item/list-item.fluent.css.js +0 -3
- package/components/list/themes/dark/item/list-item.fluent.css.js.map +0 -1
- package/components/list/themes/dark/item/list-item.indigo.css.d.ts +0 -1
- package/components/list/themes/dark/item/list-item.indigo.css.js +0 -3
- package/components/list/themes/dark/item/list-item.indigo.css.js.map +0 -1
- package/components/list/themes/dark/item/list-item.material.css.d.ts +0 -1
- package/components/list/themes/dark/item/list-item.material.css.js +0 -3
- package/components/list/themes/dark/item/list-item.material.css.js.map +0 -1
- package/components/list/themes/light/header/list-header.bootstrap.css.d.ts +0 -1
- package/components/list/themes/light/header/list-header.bootstrap.css.js +0 -3
- package/components/list/themes/light/header/list-header.bootstrap.css.js.map +0 -1
- package/components/list/themes/light/header/list-header.fluent.css.d.ts +0 -1
- package/components/list/themes/light/header/list-header.fluent.css.js +0 -3
- package/components/list/themes/light/header/list-header.fluent.css.js.map +0 -1
- package/components/list/themes/light/header/list-header.indigo.css.d.ts +0 -1
- package/components/list/themes/light/header/list-header.indigo.css.js +0 -3
- package/components/list/themes/light/header/list-header.indigo.css.js.map +0 -1
- package/components/list/themes/light/header/list-header.material.css.d.ts +0 -1
- package/components/list/themes/light/header/list-header.material.css.js +0 -3
- package/components/list/themes/light/header/list-header.material.css.js.map +0 -1
- package/components/list/themes/light/item/list-item.bootstrap.css.d.ts +0 -1
- package/components/list/themes/light/item/list-item.bootstrap.css.js +0 -3
- package/components/list/themes/light/item/list-item.bootstrap.css.js.map +0 -1
- package/components/list/themes/light/item/list-item.fluent.css.d.ts +0 -1
- package/components/list/themes/light/item/list-item.fluent.css.js +0 -3
- package/components/list/themes/light/item/list-item.fluent.css.js.map +0 -1
- package/components/list/themes/light/item/list-item.indigo.css.d.ts +0 -1
- package/components/list/themes/light/item/list-item.indigo.css.js +0 -3
- package/components/list/themes/light/item/list-item.indigo.css.js.map +0 -1
- package/components/list/themes/light/item/list-item.material.css.d.ts +0 -1
- package/components/list/themes/light/item/list-item.material.css.js +0 -3
- package/components/list/themes/light/item/list-item.material.css.js.map +0 -1
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { enterKey } from '../common/controllers/key-bindings.js';
|
|
2
1
|
import { IgcChatResourceStringEN } from '../common/i18n/chat.resources.js';
|
|
3
2
|
import { isEmpty, nanoid } from '../common/util.js';
|
|
4
|
-
import
|
|
3
|
+
import IgcToastComponent from '../toast/toast.js';
|
|
4
|
+
import IgcTooltipComponent from '../tooltip/tooltip.js';
|
|
5
|
+
import { isImageAttachment, parseAcceptedFileTypes, } from './utils.js';
|
|
5
6
|
export class ChatState {
|
|
7
|
+
get host() {
|
|
8
|
+
return this._host;
|
|
9
|
+
}
|
|
6
10
|
get acceptedFileTypes() {
|
|
7
11
|
return this._acceptedTypesCache;
|
|
8
12
|
}
|
|
@@ -20,22 +24,17 @@ export class ChatState {
|
|
|
20
24
|
}
|
|
21
25
|
set options(value) {
|
|
22
26
|
this._options = value;
|
|
27
|
+
this._setAcceptedTypesCache();
|
|
23
28
|
this._contextUpdateFn.call(this._host);
|
|
24
29
|
}
|
|
25
30
|
get currentUserId() {
|
|
26
31
|
return this._options?.currentUserId ?? 'user';
|
|
27
32
|
}
|
|
28
33
|
get suggestionsPosition() {
|
|
29
|
-
return this._options?.suggestionsPosition ??
|
|
34
|
+
return this._options?.suggestionsPosition ?? 'below-messages';
|
|
30
35
|
}
|
|
31
36
|
get stopTypingDelay() {
|
|
32
|
-
return this._options?.stopTypingDelay ??
|
|
33
|
-
}
|
|
34
|
-
get textArea() {
|
|
35
|
-
return this._textArea;
|
|
36
|
-
}
|
|
37
|
-
set textArea(value) {
|
|
38
|
-
this._textArea = value;
|
|
37
|
+
return this._options?.stopTypingDelay ?? 3000;
|
|
39
38
|
}
|
|
40
39
|
get inputAttachments() {
|
|
41
40
|
return this._inputAttachments;
|
|
@@ -52,35 +51,26 @@ export class ChatState {
|
|
|
52
51
|
this._userInputContextUpdateFn.call(this._host);
|
|
53
52
|
}
|
|
54
53
|
get hasInputValue() {
|
|
55
|
-
return this._inputValue.trim()
|
|
54
|
+
return !!this._inputValue.trim();
|
|
56
55
|
}
|
|
57
56
|
get hasInputAttachments() {
|
|
58
57
|
return !isEmpty(this._inputAttachments);
|
|
59
58
|
}
|
|
60
59
|
constructor(chat, contextUpdateFn, userInputContextUpdateFn) {
|
|
61
|
-
this._textArea = null;
|
|
62
60
|
this._messages = [];
|
|
63
61
|
this._inputAttachments = [];
|
|
64
62
|
this._inputValue = '';
|
|
65
63
|
this._acceptedTypesCache = null;
|
|
66
|
-
this._suggestionsPosition = 'below-messages';
|
|
67
|
-
this._stopTypingDelay = 3000;
|
|
68
64
|
this._isTyping = false;
|
|
69
65
|
this._lastTyped = Date.now();
|
|
70
66
|
this.resourceStrings = IgcChatResourceStringEN;
|
|
71
|
-
this.handleKeyDown = (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.
|
|
78
|
-
if (!this._isTyping) {
|
|
79
|
-
this.emitEvent('igcTypingChange', {
|
|
80
|
-
detail: { isTyping: true },
|
|
81
|
-
});
|
|
82
|
-
this._isTyping = true;
|
|
83
|
-
}
|
|
67
|
+
this.handleKeyDown = (_) => {
|
|
68
|
+
this._lastTyped = Date.now();
|
|
69
|
+
if (!this._isTyping) {
|
|
70
|
+
this.emitEvent('igcTypingChange', {
|
|
71
|
+
detail: { isTyping: true },
|
|
72
|
+
});
|
|
73
|
+
this._isTyping = true;
|
|
84
74
|
const stopTypingDelay = this.stopTypingDelay;
|
|
85
75
|
setTimeout(() => {
|
|
86
76
|
if (this._isTyping &&
|
|
@@ -94,36 +84,6 @@ export class ChatState {
|
|
|
94
84
|
}, stopTypingDelay);
|
|
95
85
|
}
|
|
96
86
|
};
|
|
97
|
-
this.sendMessage = () => {
|
|
98
|
-
if (!this.inputValue.trim() && this.inputAttachments.length === 0)
|
|
99
|
-
return;
|
|
100
|
-
this.addMessage({
|
|
101
|
-
text: this.inputValue,
|
|
102
|
-
attachments: this.inputAttachments,
|
|
103
|
-
});
|
|
104
|
-
this.inputValue = '';
|
|
105
|
-
if (this._textArea) {
|
|
106
|
-
this._textArea.style.height = 'auto';
|
|
107
|
-
}
|
|
108
|
-
this._host.updateComplete.then(() => {
|
|
109
|
-
this._textArea?.focus();
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
this.removeAttachment = (index) => {
|
|
113
|
-
const allowed = this.emitEvent('igcAttachmentChange', {
|
|
114
|
-
detail: this.inputAttachments.filter((_, i) => i !== index),
|
|
115
|
-
cancelable: true,
|
|
116
|
-
});
|
|
117
|
-
if (allowed) {
|
|
118
|
-
this.inputAttachments = this.inputAttachments.filter((_, i) => i !== index);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
this.handleSuggestionClick = (suggestion) => {
|
|
122
|
-
this.addMessage({ text: suggestion });
|
|
123
|
-
if (this.textArea) {
|
|
124
|
-
this.textArea.focus();
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
87
|
this._host = chat;
|
|
128
88
|
this._contextUpdateFn = contextUpdateFn;
|
|
129
89
|
this._userInputContextUpdateFn = userInputContextUpdateFn;
|
|
@@ -134,63 +94,94 @@ export class ChatState {
|
|
|
134
94
|
emitEvent(name, args) {
|
|
135
95
|
return this._host.emitEvent(name, args);
|
|
136
96
|
}
|
|
137
|
-
|
|
138
|
-
|
|
97
|
+
emitMessageCreated(message) {
|
|
98
|
+
return this._host.emitEvent('igcMessageCreated', {
|
|
99
|
+
detail: message,
|
|
100
|
+
cancelable: true,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
emitAttachmentsAdded(attachments) {
|
|
104
|
+
return this._host.emitEvent('igcAttachmentAdded', {
|
|
105
|
+
detail: attachments,
|
|
106
|
+
cancelable: true,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
emitAttachmentRemoved(attachment) {
|
|
110
|
+
return this._host.emitEvent('igcAttachmentRemoved', {
|
|
111
|
+
detail: attachment,
|
|
112
|
+
cancelable: true,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
emitMessageReaction(reaction) {
|
|
116
|
+
return this._host.emitEvent('igcMessageReact', { detail: reaction });
|
|
117
|
+
}
|
|
118
|
+
showActionsTooltip(target, message) {
|
|
119
|
+
if (!this._actionsTooltip) {
|
|
120
|
+
this._actionsTooltip = document.createElement(IgcTooltipComponent.tagName);
|
|
121
|
+
this._actionsTooltip.hideTriggers = 'pointerleave,click,blur';
|
|
122
|
+
this._actionsTooltip.hideDelay = 100;
|
|
123
|
+
this._host.renderRoot.appendChild(this._actionsTooltip);
|
|
124
|
+
}
|
|
125
|
+
this._actionsTooltip.message = message;
|
|
126
|
+
this._actionsTooltip.show(target);
|
|
127
|
+
}
|
|
128
|
+
showActionToast(content) {
|
|
129
|
+
if (!this._actionToast) {
|
|
130
|
+
this._actionToast = document.createElement(IgcToastComponent.tagName);
|
|
131
|
+
this._actionToast.displayTime = 3000;
|
|
132
|
+
this._host.renderRoot.appendChild(this._actionToast);
|
|
133
|
+
}
|
|
134
|
+
this._actionToast.textContent = content;
|
|
135
|
+
this._actionToast.show();
|
|
136
|
+
}
|
|
137
|
+
_setAcceptedTypesCache() {
|
|
138
|
+
this._acceptedTypesCache = this.options?.acceptedFiles
|
|
139
|
+
? parseAcceptedFileTypes(this.options.acceptedFiles)
|
|
140
|
+
: null;
|
|
141
|
+
}
|
|
142
|
+
_createMessage(message) {
|
|
143
|
+
return {
|
|
139
144
|
id: message.id ?? nanoid(),
|
|
140
145
|
text: message.text ?? '',
|
|
141
146
|
sender: message.sender ?? this.currentUserId,
|
|
142
|
-
timestamp: message.timestamp ??
|
|
147
|
+
timestamp: message.timestamp ?? Date.now().toString(),
|
|
143
148
|
attachments: message.attachments || [],
|
|
144
149
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
this.
|
|
150
|
+
}
|
|
151
|
+
addMessage(message) {
|
|
152
|
+
this.messages.push(this._createMessage(message));
|
|
153
|
+
this._host.requestUpdate('messages');
|
|
154
|
+
}
|
|
155
|
+
addMessageWithEvent(message) {
|
|
156
|
+
const newMessage = this._createMessage(message);
|
|
157
|
+
if (this.emitMessageCreated(newMessage)) {
|
|
158
|
+
this.addMessage(newMessage);
|
|
154
159
|
this.inputValue = '';
|
|
155
160
|
this.inputAttachments = [];
|
|
156
161
|
}
|
|
157
162
|
}
|
|
158
|
-
|
|
163
|
+
attachFilesWithEvent(files) {
|
|
159
164
|
const newAttachments = [];
|
|
160
165
|
const fileNames = new Set(this.inputAttachments.map((attachment) => attachment.file?.name ?? ''));
|
|
161
166
|
for (const file of files) {
|
|
162
167
|
if (fileNames.has(file.name)) {
|
|
163
168
|
continue;
|
|
164
169
|
}
|
|
165
|
-
const isImage = file.type.startsWith('image/');
|
|
166
170
|
const url = URL.createObjectURL(file);
|
|
167
|
-
|
|
171
|
+
const attachment = {
|
|
168
172
|
id: nanoid(),
|
|
169
173
|
url,
|
|
170
174
|
name: file.name,
|
|
171
175
|
file,
|
|
172
|
-
|
|
173
|
-
|
|
176
|
+
};
|
|
177
|
+
if (isImageAttachment(file)) {
|
|
178
|
+
attachment.thumbnail = url;
|
|
179
|
+
}
|
|
180
|
+
newAttachments.push(attachment);
|
|
174
181
|
}
|
|
175
|
-
|
|
176
|
-
detail: [...this.inputAttachments, ...newAttachments],
|
|
177
|
-
cancelable: true,
|
|
178
|
-
});
|
|
179
|
-
if (allowed) {
|
|
182
|
+
if (this.emitAttachmentsAdded(newAttachments)) {
|
|
180
183
|
this.inputAttachments = [...this.inputAttachments, ...newAttachments];
|
|
181
184
|
}
|
|
182
185
|
}
|
|
183
|
-
isImageAttachment(attachment) {
|
|
184
|
-
return (attachment.type === 'image' ||
|
|
185
|
-
!!attachment.file?.type.startsWith('image/'));
|
|
186
|
-
}
|
|
187
|
-
updateOptions(options) {
|
|
188
|
-
this.options = { ...this.options, ...options };
|
|
189
|
-
}
|
|
190
|
-
updateAcceptedTypesCache() {
|
|
191
|
-
this._acceptedTypesCache = this.options?.acceptedFiles
|
|
192
|
-
? parseAcceptedFileTypes(this.options.acceptedFiles)
|
|
193
|
-
: null;
|
|
194
|
-
}
|
|
195
186
|
}
|
|
196
187
|
//# sourceMappingURL=chat-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-state.js","sourceRoot":"","sources":["../../../src/components/chat/chat-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AASpD,OAAO,EAA8B,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAOhF,MAAM,OAAO,SAAS;IAqCpB,IAAW,iBAAiB;QAC1B,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED,IAAW,iBAAiB;QAC1B,OAAO,IAAI,CAAC,QAAQ,EAAE,iBAAiB,IAAI,KAAK,CAAC;IACnD,CAAC;IAKD,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAKD,IAAW,QAAQ,CAAC,KAAmB;QACrC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;IAKD,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAKD,IAAW,OAAO,CAAC,KAAqB;QACtC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAKD,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,QAAQ,EAAE,aAAa,IAAI,MAAM,CAAC;IAChD,CAAC;IAKD,IAAW,mBAAmB;QAC5B,OAAO,IAAI,CAAC,QAAQ,EAAE,mBAAmB,IAAI,IAAI,CAAC,oBAAoB,CAAC;IACzE,CAAC;IAKD,IAAW,eAAe;QACxB,OAAO,IA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;QACnD,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;IACjD,CAAC;IAMM,wBAAwB;QAC7B,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,OAAO,EAAE,aAAa;YACpD,CAAC,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;YACpD,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;CAGF","sourcesContent":["import { enterKey } from '../common/controllers/key-bindings.js';\nimport { IgcChatResourceStringEN } from '../common/i18n/chat.resources.js';\nimport { isEmpty, nanoid } from '../common/util.js';\nimport type IgcTextareaComponent from '../textarea/textarea.js';\nimport type IgcChatComponent from './chat.js';\nimport type { IgcChatComponentEventMap } from './chat.js';\nimport type {\n IgcChatOptions,\n IgcMessage,\n IgcMessageAttachment,\n} from './types.js';\nimport { type ChatAcceptedFileTypes, parseAcceptedFileTypes } from './utils.js';\n\n/**\n * Internal state manager for the `<igc-chat>` component.\n *\n * Manages messages, input value, attachments, options, and event emissions.\n */\nexport class ChatState {\n //#region Internal properties and state /** The host `<igc-chat>` component instance */\n private readonly _host: IgcChatComponent;\n\n private readonly _contextUpdateFn: () => unknown;\n private readonly _userInputContextUpdateFn: () => unknown;\n\n /** Reference to the text area input component */\n private _textArea: IgcTextareaComponent | null = null;\n /** The current list of messages */\n private _messages: IgcMessage[] = [];\n /** Chat options/configuration */\n private _options?: IgcChatOptions;\n\n /** List of current input attachments */\n private _inputAttachments: IgcMessageAttachment[] = [];\n /** Current input text */\n private _inputValue = '';\n /**\n * Cache of accepted file types, organized into extensions, mimeTypes, and wildcardTypes\n */\n private _acceptedTypesCache: ChatAcceptedFileTypes | null = null;\n /** Default position of the suggestions */\n private _suggestionsPosition: 'below-input' | 'below-messages' =\n 'below-messages';\n /** Default time in milliseconds before dispatching stop typing event */\n private _stopTypingDelay = 3000;\n\n public _isTyping = false;\n private _lastTyped = Date.now();\n\n public resourceStrings = IgcChatResourceStringEN;\n\n //#endregion\n\n //#region Public properties\n\n public get acceptedFileTypes() {\n return this._acceptedTypesCache;\n }\n\n public get disableAutoScroll(): boolean {\n return this._options?.disableAutoScroll ?? false;\n }\n\n /**\n * Gets the list of chat messages.\n */\n public get messages(): IgcMessage[] {\n return this._messages;\n }\n\n /**\n * Sets the list of chat messages.\n */\n public set messages(value: IgcMessage[]) {\n this._messages = value;\n }\n\n /**\n * Gets current chat options.\n */\n public get options(): IgcChatOptions | undefined {\n return this._options;\n }\n\n /**\n * Sets chat options and requests host update.\n */\n public set options(value: IgcChatOptions) {\n this._options = value;\n this._contextUpdateFn.call(this._host);\n }\n\n /**\n * Gets the current user ID from options or returns 'user' as fallback.\n */\n public get currentUserId(): string {\n return this._options?.currentUserId ?? 'user';\n }\n\n /**\n * Gets the current suggestionsPosition from options or returns the default value 'below-messages'.\n */\n public get suggestionsPosition(): string {\n return this._options?.suggestionsPosition ?? this._suggestionsPosition;\n }\n\n /**\n * Gets the current stopTypingDelay from options or returns the default value `3000`.\n */\n public get stopTypingDelay(): number {\n return this._options?.stopTypingDelay ?? this._stopTypingDelay;\n }\n\n /**\n * Gets the text area component.\n */\n public get textArea(): IgcTextareaComponent | null {\n return this._textArea;\n }\n\n /**\n * Sets the text area component.\n */\n public set textArea(value: IgcTextareaComponent) {\n this._textArea = value;\n }\n\n /**\n * Gets the list of attachments currently attached to input.\n */\n public get inputAttachments(): IgcMessageAttachment[] {\n return this._inputAttachments;\n }\n\n /**\n * Sets the input attachments and requests host update.\n */\n public set inputAttachments(value: IgcMessageAttachment[]) {\n this._inputAttachments = value;\n this._userInputContextUpdateFn.call(this._host);\n }\n\n /**\n * Gets the current input value.\n */\n public get inputValue(): string {\n return this._inputValue;\n }\n\n /**\n * Sets the current input value and requests host update.\n */\n public set inputValue(value: string) {\n this._inputValue = value;\n this._userInputContextUpdateFn.call(this._host);\n }\n\n public get hasInputValue(): boolean {\n return this._inputValue.trim() !== '';\n }\n\n public get hasInputAttachments(): boolean {\n return !isEmpty(this._inputAttachments);\n }\n\n //#endregion\n\n constructor(\n chat: IgcChatComponent,\n contextUpdateFn: () => unknown,\n userInputContextUpdateFn: () => unknown\n ) {\n this._host = chat;\n this._contextUpdateFn = contextUpdateFn;\n this._userInputContextUpdateFn = userInputContextUpdateFn;\n }\n\n public isCurrentUserMessage(message?: IgcMessage): boolean {\n return this.currentUserId === message?.sender;\n }\n\n //#region Event handlers\n\n public emitEvent(name: keyof IgcChatComponentEventMap, args?: any): boolean {\n return this._host.emitEvent(name, args);\n }\n\n //#endregion\n\n //#region Public API\n\n /**\n * Adds a new chat message.\n * Emits 'igcMessageCreated' event which can be canceled to prevent adding.\n * Clears input value and attachments on success.\n * @param message Partial message object with optional id, sender, timestamp\n */\n public addMessage(message: Partial<IgcMessage>): void {\n const newMessage: IgcMessage = {\n id: message.id ?? nanoid(),\n text: message.text ?? '',\n sender: message.sender ?? this.currentUserId,\n timestamp: message.timestamp ?? new Date(),\n attachments: message.attachments || [],\n };\n\n const allowed = this.emitEvent('igcMessageCreated', {\n detail: newMessage,\n cancelable: true,\n });\n\n if (allowed) {\n if (!this.messages.some((msg) => msg.id === newMessage.id)) {\n this.messages = [...this.messages, newMessage];\n }\n this._host.requestUpdate('messages');\n\n this.inputValue = '';\n this.inputAttachments = [];\n }\n }\n\n /**\n * Adds files as attachments to the input.\n * Emits 'igcAttachmentChange' event which can be canceled to prevent adding.\n * @param files Array of File objects to attach\n */\n public attachFiles(files: File[]) {\n const newAttachments: IgcMessageAttachment[] = [];\n const fileNames = new Set(\n this.inputAttachments.map((attachment) => attachment.file?.name ?? '')\n );\n\n for (const file of files) {\n if (fileNames.has(file.name)) {\n continue;\n }\n\n const isImage = file.type.startsWith('image/');\n const url = URL.createObjectURL(file);\n\n newAttachments.push({\n id: nanoid(),\n url,\n name: file.name,\n file,\n thumbnail: isImage ? url : undefined,\n });\n }\n\n const allowed = this.emitEvent('igcAttachmentChange', {\n detail: [...this.inputAttachments, ...newAttachments],\n cancelable: true,\n });\n if (allowed) {\n this.inputAttachments = [...this.inputAttachments, ...newAttachments];\n }\n }\n\n public isImageAttachment(attachment: IgcMessageAttachment): boolean {\n return (\n attachment.type === 'image' ||\n !!attachment.file?.type.startsWith('image/')\n );\n }\n\n public handleKeyDown = (e: KeyboardEvent) => {\n if (e.key.toLowerCase() === enterKey.toLowerCase() && !e.shiftKey) {\n e.preventDefault();\n this.sendMessage();\n } else {\n this._lastTyped = Date.now();\n if (!this._isTyping) {\n this.emitEvent('igcTypingChange', {\n detail: { isTyping: true },\n });\n this._isTyping = true;\n }\n\n const stopTypingDelay = this.stopTypingDelay;\n setTimeout(() => {\n if (\n this._isTyping &&\n stopTypingDelay &&\n this._lastTyped + stopTypingDelay < Date.now()\n ) {\n this.emitEvent('igcTypingChange', {\n detail: { isTyping: false },\n });\n this._isTyping = false;\n }\n }, stopTypingDelay);\n }\n };\n\n public sendMessage = () => {\n if (!this.inputValue.trim() && this.inputAttachments.length === 0) return;\n\n this.addMessage({\n text: this.inputValue,\n attachments: this.inputAttachments,\n });\n this.inputValue = '';\n\n if (this._textArea) {\n this._textArea.style.height = 'auto';\n }\n\n this._host.updateComplete.then(() => {\n this._textArea?.focus();\n });\n };\n\n /**\n * Removes an attachment by index.\n * Emits 'igcAttachmentChange' event which can be canceled to prevent removal.\n * @param index Index of the attachment to remove\n */\n public removeAttachment = (index: number): void => {\n const allowed = this.emitEvent('igcAttachmentChange', {\n detail: this.inputAttachments.filter((_, i) => i !== index),\n cancelable: true,\n });\n if (allowed) {\n this.inputAttachments = this.inputAttachments.filter(\n (_, i) => i !== index\n );\n }\n };\n\n /**\n * Handles when a suggestion is clicked.\n * Adds the suggestion as a new message and focuses the text area.\n * @param suggestion The suggestion string clicked\n */\n public handleSuggestionClick = (suggestion: string): void => {\n this.addMessage({ text: suggestion });\n if (this.textArea) {\n this.textArea.focus();\n }\n };\n\n /**\n * Updates the chat options partially.\n * @param options Partial options to merge with current options\n */\n public updateOptions(options: Partial<IgcChatOptions>): void {\n this.options = { ...this.options, ...options };\n }\n\n /**\n * Updates the internal cache for accepted file types.\n * Parses the acceptedFiles string option into extensions, mimeTypes, and wildcard types.\n */\n public updateAcceptedTypesCache(): void {\n this._acceptedTypesCache = this.options?.acceptedFiles\n ? parseAcceptedFileTypes(this.options.acceptedFiles)\n : null;\n }\n\n //#endregion\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chat-state.js","sourceRoot":"","sources":["../../../src/components/chat/chat-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,iBAAiB,MAAM,mBAAmB,CAAC;AAClD,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AAUxD,OAAO,EAEL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAOpB,MAAM,OAAO,SAAS;IAiCpB,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAW,iBAAiB;QAC1B,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED,IAAW,iBAAiB;QAC1B,OAAO,IAAI,CAAC,QAAQ,EAAE,iBAAiB,IAAI,KAAK,CAAC;IACnD,CAAC;IAKD,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAKD,IAAW,QAAQ,CAAC,KAAuB;QACzC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;IAKD,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAKD,IAAW,OAAO,CAAC,KAAqB;QACtC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC9B,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAA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,CAAC;YAC5B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;YACrB,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;IAOM,oBAAoB,CAAC,KAAa;QACvC,MAAM,cAAc,GAA+B,EAAE,CAAC;QACtD,MAAM,SAAS,GAAG,IAAI,GAAG,CACvB,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,CACvE,CAAC;QAEF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC7B,SAAS;YACX,CAAC;YAED,MAAM,GAAG,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YACtC,MAAM,UAAU,GAA6B;gBAC3C,EAAE,EAAE,MAAM,EAAE;gBACZ,GAAG;gBACH,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,IAAI;aACL,CAAC;YAEF,IAAI,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC5B,UAAU,CAAC,SAAS,GAAG,GAAG,CAAC;YAC7B,CAAC;YACD,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClC,CAAC;QAED,IAAI,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,gBAAgB,GAAG,CAAC,GAAG,IAAI,CAAC,gBAAgB,EAAE,GAAG,cAAc,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;CA2BF","sourcesContent":["import { IgcChatResourceStringEN } from '../common/i18n/chat.resources.js';\nimport { isEmpty, nanoid } from '../common/util.js';\nimport IgcToastComponent from '../toast/toast.js';\nimport IgcTooltipComponent from '../tooltip/tooltip.js';\nimport type IgcChatComponent from './chat.js';\nimport type { IgcChatComponentEventMap } from './chat.js';\nimport type {\n ChatSuggestionsPosition,\n IgcChatMessage,\n IgcChatMessageAttachment,\n IgcChatMessageReaction,\n IgcChatOptions,\n} from './types.js';\nimport {\n type ChatAcceptedFileTypes,\n isImageAttachment,\n parseAcceptedFileTypes,\n} from './utils.js';\n\n/**\n * Internal state manager for the `<igc-chat>` component.\n *\n * Manages messages, input value, attachments, options, and event emissions.\n */\nexport class ChatState {\n //#region Internal properties and state /** The host `<igc-chat>` component instance */\n private readonly _host: IgcChatComponent;\n\n private readonly _contextUpdateFn: () => unknown;\n private readonly _userInputContextUpdateFn: () => unknown;\n\n private _actionsTooltip?: IgcTooltipComponent;\n private _actionToast?: IgcToastComponent;\n\n /** The current list of messages */\n private _messages: IgcChatMessage[] = [];\n /** Chat options/configuration */\n private _options?: IgcChatOptions;\n\n /** List of current input attachments */\n private _inputAttachments: IgcChatMessageAttachment[] = [];\n /** Current input text */\n private _inputValue = '';\n /**\n * Cache of accepted file types, organized into extensions, mimeTypes, and wildcardTypes\n */\n private _acceptedTypesCache: ChatAcceptedFileTypes | null = null;\n\n public _isTyping = false;\n private _lastTyped = Date.now();\n\n public resourceStrings = IgcChatResourceStringEN;\n\n //#endregion\n\n //#region Public properties\n\n public get host(): IgcChatComponent {\n return this._host;\n }\n\n public get acceptedFileTypes(): ChatAcceptedFileTypes | null {\n return this._acceptedTypesCache;\n }\n\n public get disableAutoScroll(): boolean {\n return this._options?.disableAutoScroll ?? false;\n }\n\n /**\n * Gets the list of chat messages.\n */\n public get messages(): IgcChatMessage[] {\n return this._messages;\n }\n\n /**\n * Sets the list of chat messages.\n */\n public set messages(value: IgcChatMessage[]) {\n this._messages = value;\n }\n\n /**\n * Gets current chat options.\n */\n public get options(): IgcChatOptions | undefined {\n return this._options;\n }\n\n /**\n * Sets chat options and requests host update.\n */\n public set options(value: IgcChatOptions) {\n this._options = value;\n this._setAcceptedTypesCache();\n this._contextUpdateFn.call(this._host);\n }\n\n /**\n * Gets the current user ID from options or returns 'user' as fallback.\n */\n public get currentUserId(): string {\n return this._options?.currentUserId ?? 'user';\n }\n\n /**\n * Gets the current suggestionsPosition from options or returns the default value 'below-messages'.\n */\n public get suggestionsPosition(): ChatSuggestionsPosition {\n return this._options?.suggestionsPosition ?? 'below-messages';\n }\n\n /**\n * Gets the current stopTypingDelay from options or returns the default value `3000`.\n */\n public get stopTypingDelay(): number {\n return this._options?.stopTypingDelay ?? 3000;\n }\n\n /**\n * Gets the list of attachments currently attached to input.\n */\n public get inputAttachments(): IgcChatMessageAttachment[] {\n return this._inputAttachments;\n }\n\n /**\n * Sets the input attachments and requests host update.\n */\n public set inputAttachments(value: IgcChatMessageAttachment[]) {\n this._inputAttachments = value;\n this._userInputContextUpdateFn.call(this._host);\n }\n\n /**\n * Gets the current input value.\n */\n public get inputValue(): string {\n return this._inputValue;\n }\n\n /**\n * Sets the current input value and requests host update.\n */\n public set inputValue(value: string) {\n this._inputValue = value;\n this._userInputContextUpdateFn.call(this._host);\n }\n\n /**\n * Returns whether the default chat input textarea has a trimmed value payload.\n * @internal\n */\n public get hasInputValue(): boolean {\n return !!this._inputValue.trim();\n }\n\n /**\n * Returns whether the default file input of the chat has any attached files.\n * @internal\n */\n public get hasInputAttachments(): boolean {\n return !isEmpty(this._inputAttachments);\n }\n\n //#endregion\n\n constructor(\n chat: IgcChatComponent,\n contextUpdateFn: () => unknown,\n userInputContextUpdateFn: () => unknown\n ) {\n this._host = chat;\n this._contextUpdateFn = contextUpdateFn;\n this._userInputContextUpdateFn = userInputContextUpdateFn;\n }\n\n public isCurrentUserMessage(message?: IgcChatMessage): boolean {\n return this.currentUserId === message?.sender;\n }\n\n //#region Event handlers\n\n public emitEvent(name: keyof IgcChatComponentEventMap, args?: any): boolean {\n return this._host.emitEvent(name, args);\n }\n\n /** @internal */\n public emitMessageCreated(message: IgcChatMessage): boolean {\n return this._host.emitEvent('igcMessageCreated', {\n detail: message,\n cancelable: true,\n });\n }\n\n /** @internal */\n public emitAttachmentsAdded(\n attachments: IgcChatMessageAttachment[]\n ): boolean {\n return this._host.emitEvent('igcAttachmentAdded', {\n detail: attachments,\n cancelable: true,\n });\n }\n\n /** @internal */\n public emitAttachmentRemoved(attachment: IgcChatMessageAttachment): boolean {\n return this._host.emitEvent('igcAttachmentRemoved', {\n detail: attachment,\n cancelable: true,\n });\n }\n\n /** @internal */\n public emitMessageReaction(reaction: IgcChatMessageReaction): boolean {\n return this._host.emitEvent('igcMessageReact', { detail: reaction });\n }\n\n /**\n * @internal\n */\n public showActionsTooltip(target: Element, message: string): void {\n if (!this._actionsTooltip) {\n this._actionsTooltip = document.createElement(\n IgcTooltipComponent.tagName\n );\n this._actionsTooltip.hideTriggers = 'pointerleave,click,blur';\n this._actionsTooltip.hideDelay = 100;\n this._host.renderRoot.appendChild(this._actionsTooltip);\n }\n this._actionsTooltip.message = message;\n this._actionsTooltip.show(target);\n }\n\n /**\n * @internal\n */\n public showActionToast(content: string): void {\n if (!this._actionToast) {\n this._actionToast = document.createElement(IgcToastComponent.tagName);\n this._actionToast.displayTime = 3000;\n this._host.renderRoot.appendChild(this._actionToast);\n }\n this._actionToast.textContent = content;\n this._actionToast.show();\n }\n\n //#endregion\n\n /**\n * Updates the internal cache for accepted file types.\n * Parses the acceptedFiles string option into extensions, mimeTypes, and wildcard types.\n */\n private _setAcceptedTypesCache(): void {\n this._acceptedTypesCache = this.options?.acceptedFiles\n ? parseAcceptedFileTypes(this.options.acceptedFiles)\n : null;\n }\n\n protected _createMessage(message: Partial<IgcChatMessage>): IgcChatMessage {\n return {\n id: message.id ?? nanoid(),\n text: message.text ?? '',\n sender: message.sender ?? this.currentUserId,\n timestamp: message.timestamp ?? Date.now().toString(),\n attachments: message.attachments || [],\n };\n }\n\n public addMessage(message: Partial<IgcChatMessage>) {\n this.messages.push(this._createMessage(message));\n this._host.requestUpdate('messages');\n }\n\n //#region Public API\n\n /**\n * Adds a new chat message.\n * Emits 'igcMessageCreated' event which can be canceled to prevent adding.\n * Clears input value and attachments on success.\n * @internal\n */\n public addMessageWithEvent(message: Partial<IgcChatMessage>): void {\n const newMessage = this._createMessage(message);\n\n if (this.emitMessageCreated(newMessage)) {\n this.addMessage(newMessage);\n this.inputValue = '';\n this.inputAttachments = [];\n }\n }\n\n /**\n * Adds files as attachments to the input.\n * Emits 'igcAttachmentChange' event which can be canceled to prevent adding.\n * @internal\n */\n public attachFilesWithEvent(files: File[]): void {\n const newAttachments: IgcChatMessageAttachment[] = [];\n const fileNames = new Set(\n this.inputAttachments.map((attachment) => attachment.file?.name ?? '')\n );\n\n for (const file of files) {\n if (fileNames.has(file.name)) {\n continue;\n }\n\n const url = URL.createObjectURL(file);\n const attachment: IgcChatMessageAttachment = {\n id: nanoid(),\n url,\n name: file.name,\n file,\n };\n\n if (isImageAttachment(file)) {\n attachment.thumbnail = url;\n }\n newAttachments.push(attachment);\n }\n\n if (this.emitAttachmentsAdded(newAttachments)) {\n this.inputAttachments = [...this.inputAttachments, ...newAttachments];\n }\n }\n\n public handleKeyDown = (_: KeyboardEvent) => {\n this._lastTyped = Date.now();\n if (!this._isTyping) {\n this.emitEvent('igcTypingChange', {\n detail: { isTyping: true },\n });\n this._isTyping = true;\n\n const stopTypingDelay = this.stopTypingDelay;\n setTimeout(() => {\n if (\n this._isTyping &&\n stopTypingDelay &&\n this._lastTyped + stopTypingDelay < Date.now()\n ) {\n this.emitEvent('igcTypingChange', {\n detail: { isTyping: false },\n });\n this._isTyping = false;\n }\n }, stopTypingDelay);\n }\n };\n\n //#endregion\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LitElement, type PropertyValues } from 'lit';
|
|
2
2
|
import type { Constructor } from '../common/mixins/constructor.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { IgcChatMessage, IgcChatMessageAttachment, IgcChatMessageReaction, IgcChatOptions } from './types.js';
|
|
4
4
|
/**
|
|
5
5
|
* Defines the custom events dispatched by the `<igc-chat>` component.
|
|
6
6
|
*/
|
|
@@ -8,22 +8,24 @@ export interface IgcChatComponentEventMap {
|
|
|
8
8
|
/**
|
|
9
9
|
* Dispatched when a new chat message is created (sent).
|
|
10
10
|
*/
|
|
11
|
-
igcMessageCreated: CustomEvent<
|
|
11
|
+
igcMessageCreated: CustomEvent<IgcChatMessage>;
|
|
12
12
|
/**
|
|
13
13
|
* Dispatched when a message is reacted to.
|
|
14
14
|
*/
|
|
15
|
-
igcMessageReact: CustomEvent<
|
|
16
|
-
message: IgcMessage;
|
|
17
|
-
reaction: string;
|
|
18
|
-
}>;
|
|
15
|
+
igcMessageReact: CustomEvent<IgcChatMessageReaction>;
|
|
19
16
|
/**
|
|
20
17
|
* Dispatched when a chat message attachment is clicked.
|
|
21
18
|
*/
|
|
22
|
-
igcAttachmentClick: CustomEvent<
|
|
19
|
+
igcAttachmentClick: CustomEvent<IgcChatMessageAttachment>;
|
|
23
20
|
/**
|
|
24
|
-
* Dispatched when
|
|
21
|
+
* Dispatched when attachment(s) are added either through drag & drop or through
|
|
22
|
+
* the default file input.
|
|
25
23
|
*/
|
|
26
|
-
|
|
24
|
+
igcAttachmentAdded: CustomEvent<IgcChatMessageAttachment[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Dispatched when an attachment is removed by the user.
|
|
27
|
+
*/
|
|
28
|
+
igcAttachmentRemoved: CustomEvent<IgcChatMessageAttachment>;
|
|
27
29
|
/**
|
|
28
30
|
* Dispatched during an attachment drag operation.
|
|
29
31
|
*/
|
|
@@ -58,7 +60,8 @@ declare const IgcChatComponent_base: Constructor<import("../common/mixins/event-
|
|
|
58
60
|
* @fires igcMessageCreated - Dispatched when a new chat message is created (sent).
|
|
59
61
|
* @fires igcMessageReact - Dispatched when a message is reacted to.
|
|
60
62
|
* @fires igcAttachmentClick - Dispatched when a chat message attachment is clicked.
|
|
61
|
-
* @fires
|
|
63
|
+
* @fires igcAttachmentAdded - Dispatched when attachment(s) are added either through drag & drop or through the default file input.
|
|
64
|
+
* @fires igcAttachmentRemoved - Dispatched when an attachment is removed by the user.
|
|
62
65
|
* @fires igcAttachmentDrag - Dispatched during an attachment drag operation.
|
|
63
66
|
* @fires igcAttachmentDrop - Dispatched when an attachment is dropped (e.g., in a drag-and-drop operation).
|
|
64
67
|
* @fires igcTypingChange - Dispatched when the typing status changes (e.g., user starts or stops typing).
|
|
@@ -75,39 +78,85 @@ declare const IgcChatComponent_base: Constructor<import("../common/mixins/event-
|
|
|
75
78
|
* @slot suggestion - Slot for rendering a single suggestion item.
|
|
76
79
|
* @slot empty-state - Slot shown when there are no messages.
|
|
77
80
|
*
|
|
78
|
-
* @csspart
|
|
79
|
-
* @csspart
|
|
81
|
+
* @csspart chat-container - Styles the main chat container.
|
|
82
|
+
* @csspart header - Styles the chat header container.
|
|
83
|
+
* @csspart prefix - Styles the element before the chat title (e.g., avatar).
|
|
80
84
|
* @csspart title - Styles the chat header title.
|
|
81
|
-
*
|
|
85
|
+
*
|
|
86
|
+
* @csspart message-area-container - Styles the container holding the messages and (optional) suggestions.
|
|
87
|
+
* @csspart message-list - Styles the message list container.
|
|
88
|
+
* @csspart message-item - Styles each message wrapper.
|
|
89
|
+
* @csspart typing-indicator - Styles the typing indicator container.
|
|
90
|
+
* @csspart typing-dot - Styles individual typing indicator dots.
|
|
91
|
+
*
|
|
92
|
+
* @csspart suggestions-container - Styles the container holding all suggestions.
|
|
93
|
+
* @csspart suggestions-header - Styles the suggestions header.
|
|
82
94
|
* @csspart suggestion - Styles each suggestion item.
|
|
95
|
+
* @csspart suggestion-prefix - Styles the icon or prefix in a suggestion.
|
|
96
|
+
* @csspart suggestion-title - Styles the text/title of a suggestion.
|
|
97
|
+
*
|
|
98
|
+
* @csspart empty-state - Styles the empty state container when there are no messages.
|
|
99
|
+
*
|
|
100
|
+
* @csspart input-area-container - Styles the wrapper around the chat input area.
|
|
101
|
+
* @csspart input-container - Styles the main input container.
|
|
102
|
+
* @csspart input-attachments-container - Styles the container for attachments in the input.
|
|
103
|
+
* @csspart input-attachment-container - Styles a single attachment in the input area.
|
|
104
|
+
* @csspart input-attachment-name - Styles the file name of an attachment.
|
|
105
|
+
* @csspart input-attachment-icon - Styles the icon of an attachment.
|
|
106
|
+
* @csspart text-input - Styles the text input field for typing messages.
|
|
107
|
+
* @csspart input-actions-container - Styles the container for input actions.
|
|
108
|
+
* @csspart input-actions-start - Styles the group of actions at the start of the input after the default file upload.
|
|
109
|
+
* @csspart input-actions-end - Styles the group of actions at the end of the input.
|
|
110
|
+
* @csspart file-upload-container - Styles the container for the file upload input.
|
|
111
|
+
* @csspart file-upload - Styles the file upload input itself.
|
|
112
|
+
* @csspart send-button-container - Styles the container around the send button.
|
|
113
|
+
* @csspart send-button - Styles the send button.
|
|
114
|
+
*
|
|
115
|
+
* @csspart message-container - Styles the container of a single message.
|
|
116
|
+
* @csspart message-list (forwarded) - Styles the internal list of messages.
|
|
117
|
+
* @csspart message-header - Styles the header of a message (e.g., sender, timestamp).
|
|
118
|
+
* @csspart message-content - Styles the text content of a message.
|
|
119
|
+
* @csspart message-attachments-container - Styles the container for message attachments.
|
|
120
|
+
* @csspart message-attachment - Styles a single message attachment.
|
|
121
|
+
* @csspart message-actions-container - Styles the container holding message actions.
|
|
122
|
+
* @csspart message-sent - Styles messages marked as sent by the current user.
|
|
123
|
+
* @csspart attachment-header - Styles the header of an attachment block.
|
|
124
|
+
* @csspart attachment-content - Styles the content of an attachment block.
|
|
125
|
+
* @csspart attachment-icon - Styles the icon of an attachment.
|
|
126
|
+
* @csspart file-name - Styles the file name shown in an attachment.
|
|
83
127
|
*/
|
|
84
128
|
export default class IgcChatComponent extends IgcChatComponent_base {
|
|
85
129
|
static readonly tagName = "igc-chat";
|
|
86
130
|
static styles: import("lit").CSSResult[];
|
|
87
131
|
static register(): void;
|
|
88
132
|
private readonly _state;
|
|
133
|
+
private readonly _defaults;
|
|
89
134
|
private readonly _slots;
|
|
90
135
|
private readonly _context;
|
|
91
136
|
private readonly _userInputContext;
|
|
137
|
+
private readonly _input?;
|
|
138
|
+
private readonly _typingIndicator?;
|
|
139
|
+
private readonly _suggestionsContainer?;
|
|
140
|
+
private readonly _scrollContainer;
|
|
92
141
|
private _updateContext;
|
|
93
142
|
private _updateUserInputContext;
|
|
94
143
|
/**
|
|
95
144
|
* The list of chat messages currently displayed.
|
|
96
145
|
* Use this property to set or update the message history.
|
|
97
146
|
*/
|
|
98
|
-
set messages(value:
|
|
99
|
-
get messages():
|
|
147
|
+
set messages(value: IgcChatMessage[]);
|
|
148
|
+
get messages(): IgcChatMessage[];
|
|
100
149
|
/**
|
|
101
150
|
* The chat message currently being composed but not yet sent.
|
|
102
151
|
* Includes the draft text and any attachments.
|
|
103
152
|
*/
|
|
104
153
|
set draftMessage(value: {
|
|
105
154
|
text: string;
|
|
106
|
-
attachments?:
|
|
155
|
+
attachments?: IgcChatMessageAttachment[];
|
|
107
156
|
});
|
|
108
157
|
get draftMessage(): {
|
|
109
158
|
text: string;
|
|
110
|
-
attachments?:
|
|
159
|
+
attachments?: IgcChatMessageAttachment[];
|
|
111
160
|
};
|
|
112
161
|
/**
|
|
113
162
|
* Controls the chat behavior and appearance through a configuration object.
|
|
@@ -120,17 +169,12 @@ export default class IgcChatComponent extends IgcChatComponent_base {
|
|
|
120
169
|
*/
|
|
121
170
|
resourceStrings: import("../common/i18n/chat.resources.js").IgcChatResourceStrings;
|
|
122
171
|
constructor();
|
|
123
|
-
|
|
172
|
+
private _getRenderer;
|
|
173
|
+
private _handleSuggestionClick;
|
|
124
174
|
/**
|
|
125
175
|
* Scrolls the view to a specific message by id.
|
|
126
|
-
* @param messageId - The id of the message to scroll to
|
|
127
176
|
*/
|
|
128
177
|
scrollToMessage(messageId: string): void;
|
|
129
|
-
/**
|
|
130
|
-
* Updates the context value to notify all consumers that the chat state has changed.
|
|
131
|
-
* This ensures that components consuming the chat context will re-render.
|
|
132
|
-
*/
|
|
133
|
-
updateContextValue(): void;
|
|
134
178
|
protected updated(properties: PropertyValues<this>): void;
|
|
135
179
|
private _scrollToBottom;
|
|
136
180
|
private _renderHeader;
|