@webitel/ui-chats 0.1.39 → 0.1.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/package.json +17 -1
  2. package/src/adapters/chat-web-sdk/toChatMessage.ts +111 -0
  3. package/src/adapters/index.ts +12 -0
  4. package/src/types/index.ts +15 -0
  5. package/src/ui/index.ts +2 -0
  6. package/src/ui/messaging/components/chat-date-divider.vue +1 -1
  7. package/src/ui/messaging/components/scroll-to-bottom-btn.vue +0 -2
  8. package/src/ui/messaging/components/the-messages-container.vue +58 -46
  9. package/src/ui/messaging/composables/useChatScroll.ts +161 -81
  10. package/src/ui/messaging/composables/useObserveHeightUntilStable.ts +49 -0
  11. package/src/ui/messaging/composables/useScrollToBottomBtn.ts +51 -0
  12. package/src/ui/messaging/modules/message/components/chat-message.vue +1 -2
  13. package/src/ui/messaging/modules/message/components/details/chat-message-document.vue +1 -2
  14. package/src/ui/messaging/modules/message/components/details/chat-message-image.vue +0 -2
  15. package/src/ui/messaging/modules/message/components/details/chat-message-player.vue +1 -2
  16. package/src/ui/messaging/modules/message/components/details/chat-message-size-exceeded-error.vue +1 -1
  17. package/src/ui/messaging/modules/message/components/details/chat-message-time.vue +1 -1
  18. package/src/ui/messaging/types/ChatMessage.types.ts +3 -2
  19. package/src/ui/the-chat-container.vue +10 -1
  20. package/src/ui/utils/ResultCallbacks.types.ts +1 -1
  21. package/src/ui/utils/emitter.ts +1 -1
  22. package/types/adapters/chat-web-sdk/toChatMessage.d.ts +23 -0
  23. package/types/adapters/index.d.ts +8 -0
  24. package/types/types/index.d.ts +8 -0
  25. package/types/ui/chat-footer/modules/user-input/enums/ChatAction.enum.d.ts +6 -5
  26. package/types/ui/index.d.ts +7 -3
  27. package/types/ui/messaging/components/the-messages-container.vue.d.ts +7 -1
  28. package/types/ui/messaging/composables/useChatScroll.d.ts +13 -3
  29. package/types/ui/messaging/composables/useObserveHeightUntilStable.d.ts +11 -0
  30. package/types/ui/messaging/composables/useScrollToBottomBtn.d.ts +9 -0
  31. package/types/ui/messaging/modules/message/composables/useChatMessageFile.d.ts +2 -0
  32. package/types/ui/messaging/types/ChatMessage.types.d.ts +33 -32
  33. package/types/ui/the-chat-container.vue.d.ts +39 -49
  34. package/types/ui/utils/ResultCallbacks.types.d.ts +1 -1
  35. package/types/ui/utils/emitter.d.ts +1 -1
  36. package/types/ui/chat-container.vue.d.ts +0 -76
  37. package/types/ui/chat-footer/modules/user-input/types/ChatAction.types.d.ts +0 -10
  38. package/types/ui/chat-input/components/actions/attach-files-action.vue.d.ts +0 -29
  39. package/types/ui/chat-input/components/actions/emoji-picker-action.vue.d.ts +0 -24
  40. package/types/ui/chat-input/components/actions/send-message-action.vue.d.ts +0 -29
  41. package/types/ui/chat-input/components/chat-input-actions-bar.vue.d.ts +0 -43
  42. package/types/ui/chat-input/components/chat-input-actions-wrapper.vue.d.ts +0 -34
  43. package/types/ui/chat-input/components/chat-input.vue.d.ts +0 -42
  44. package/types/ui/chat-input/components/chat-text-field.vue.d.ts +0 -32
  45. package/types/ui/chat-input/enums/ChatAction.enum.d.ts +0 -6
  46. package/types/ui/media-viewer/media-viewer.vue.d.ts +0 -11
  47. package/types/ui/messaging/components/chat-messages-container.vue.d.ts +0 -11
  48. package/types/ui/messaging/components/the-chat-messages-container.vue.d.ts +0 -40
  49. package/types/ui/messaging/composebles/useChatScroll.d.ts +0 -12
  50. package/types/ui/messaging/modules/message/components/details/chat-message-avatar.vue.d.ts +0 -10
@@ -1,8 +1,9 @@
1
- import { useScroll } from '@vueuse/core';
1
+ import { useResizeObserver, useScroll } from '@vueuse/core';
2
2
  import {
3
3
  type ComputedRef,
4
4
  computed,
5
5
  nextTick,
6
+ onUnmounted,
6
7
  type Ref,
7
8
  ref,
8
9
  watch,
@@ -10,105 +11,152 @@ import {
10
11
 
11
12
  import type { ChatMessageType } from '../types/ChatMessage.types';
12
13
 
13
- export const useChatScroll = (
14
- element: Ref<HTMLElement | null> = null,
15
- messages: Ref<ChatMessageType[]> | ComputedRef<ChatMessageType[]>,
16
- isLoading?: Ref<boolean> | ComputedRef<boolean>,
17
- ) => {
18
- /* @author ye.pohranichna
19
- why 136px? because: https://webitel.atlassian.net/browse/WTEL-7136 */
20
- const defaultThreshold = 136;
21
- const { arrivedState } = useScroll(element);
22
-
23
- const newUnseenMessagesCount = ref<number>(0);
24
- const showScrollToBottomBtn = ref<boolean>(false);
25
- /* @author ye.pohranichna
26
- the distance where the scrollToBottomBtn must be shown/hide. */
27
- const threshold = ref<number>(defaultThreshold);
28
- const isLoadingNextMessages = ref<boolean>(false);
29
- const lastVisibleMessageEl = ref<HTMLElement | null>(null);
30
-
31
- const isLastMessageIsMy = computed<boolean>(
32
- () => lastMessage.value?.member?.self,
33
- );
34
- const lastMessage = computed<ChatMessageType>(() => messages.value?.at(-1));
35
- const handleChatScroll = () => {
36
- const wrapper = element.value;
37
- if (!wrapper) return;
38
-
39
- handleShowScrollToBottomBtn(wrapper);
40
- };
41
-
42
- const handleChatResize = () => {
43
- const wrapper = element.value;
44
- if (!wrapper) return;
45
-
46
- updateThreshold(wrapper);
47
- handleShowScrollToBottomBtn(wrapper);
48
- };
49
-
50
- const handleShowScrollToBottomBtn = (el: HTMLElement) => {
51
- if (arrivedState.bottom) {
52
- resetScrollToBottomBtn();
53
- return;
54
- /* @author ye.pohranichna
55
- quit the function because we are already at the bottom */
56
- }
57
-
58
- const { scrollTop, scrollHeight, clientHeight } = el;
59
- const distanceFromBottom = scrollHeight - (scrollTop + clientHeight);
60
- showScrollToBottomBtn.value = distanceFromBottom > threshold.value;
61
- };
62
-
63
- const resetScrollToBottomBtn = (): void => {
64
- newUnseenMessagesCount.value = 0;
65
- showScrollToBottomBtn.value = false;
66
- };
67
-
68
- const updateThreshold = (el: HTMLElement) => {
69
- /* @author ye.pohranichna
70
- need to update if clientHeight was changed
71
- https://webitel.atlassian.net/browse/WTEL-7136 */
72
- threshold.value = Math.max(defaultThreshold, el.clientHeight * 0.3);
73
- };
14
+ import { useScrollToBottomBtn } from './useScrollToBottomBtn';
15
+
16
+ export interface UseChatScrollOptions {
17
+ chatContainer: Ref<HTMLElement | null>;
18
+ chatContent: Ref<HTMLElement | null>;
19
+ messages: Ref<ChatMessageType[]> | ComputedRef<ChatMessageType[]>;
20
+ chatId: ComputedRef<string>;
21
+ isChatClosed: ComputedRef<boolean>;
22
+ isLoading?: Ref<boolean> | ComputedRef<boolean>;
23
+ onBeforeStart?: (options: {
24
+ scrollToBottom: (behavior?: ScrollBehavior) => void;
25
+ }) => void;
26
+ }
27
+
28
+ export const useChatScroll = ({
29
+ chatContainer,
30
+ chatContent,
31
+ messages,
32
+ chatId,
33
+ isChatClosed,
34
+ isLoading,
35
+ onBeforeStart = (options) => {
36
+ options.scrollToBottom();
37
+ },
38
+ }: UseChatScrollOptions) => {
39
+ const { arrivedState } = useScroll(chatContainer);
40
+
41
+ const {
42
+ showScrollToBottomBtn,
43
+ handleChatScroll,
44
+ resetScrollToBottomBtn,
45
+ updateScrollToBottomBtnVisibility,
46
+ updateThreshold,
47
+ } = useScrollToBottomBtn(chatContainer, arrivedState);
48
+
49
+ let isLoadingNextMessages = false;
50
+ let lastVisibleMessageEl: HTMLElement | null = null;
51
+ let prevScrollHeight = 0;
52
+ let resizeObserver: ResizeObserver | null = null;
53
+ /**
54
+ * @author PolinaSukhorukova-webitel
55
+ *
56
+ * 2 tolerates subpixel scrollTop/clientHeight rounding that can leave
57
+ * their sum a fraction short of scrollHeight at the very bottom.
58
+ */
59
+ const bottomThreshold = 2;
60
+
61
+ const newUnseenMessagesCount = ref(0);
62
+
63
+ const lastMessage = computed(() => messages.value?.at(-1));
64
+ const isLastMessageMy = computed(() => !!lastMessage.value?.member?.self);
74
65
 
75
66
  const handleBtnAfterNewMessage = () => {
76
- if (arrivedState.bottom || isLastMessageIsMy.value) {
77
- scrollToBottom('smooth');
78
- } else {
67
+ if (isLastMessageMy.value) {
68
+ scrollToBottom('instant');
69
+ } else if (!arrivedState.bottom) {
79
70
  newUnseenMessagesCount.value += 1;
80
71
  }
81
72
  };
82
73
 
83
74
  const scrollToBottom = (behavior: ScrollBehavior = 'instant') => {
84
- element?.value.scrollTo({
85
- top: element?.value.scrollHeight,
86
- behavior: behavior === 'instant' ? 'auto' : behavior,
75
+ chatContainer.value?.scrollTo({
76
+ top: chatContainer.value?.scrollHeight,
77
+ behavior,
87
78
  });
88
79
 
89
80
  newUnseenMessagesCount.value = 0;
90
- showScrollToBottomBtn.value = false;
91
- };
92
81
 
82
+ resetScrollToBottomBtn();
83
+ };
93
84
  const getTopMessageEl = () => {
94
85
  // help to fix chat viewing position when new messages was loaded
95
- if (!element.value?.children) return;
96
- lastVisibleMessageEl.value =
97
- element.value?.getElementsByClassName('chat-message')[0] ?? null;
86
+ if (!chatContainer.value?.children) return;
87
+ lastVisibleMessageEl =
88
+ (chatContainer.value?.getElementsByClassName(
89
+ 'chat-message',
90
+ )[0] as HTMLElement) ?? null;
98
91
  };
99
92
 
100
93
  const loadNextMessages = (
101
- canLoadMore: boolean | undefined,
94
+ canLoadMore: boolean,
102
95
  onLoadNextMessages: () => void,
103
96
  ) => {
104
- if (isLoadingNextMessages.value || isLoading?.value || !canLoadMore) return;
97
+ if (isLoadingNextMessages || isLoading?.value || !canLoadMore) return;
105
98
 
106
- isLoadingNextMessages.value = true;
99
+ isLoadingNextMessages = true;
107
100
  getTopMessageEl();
108
101
 
109
102
  onLoadNextMessages();
110
103
  };
111
104
 
105
+ const startStickToBottomObserving = () => {
106
+ if (!chatContent.value) return;
107
+
108
+ prevScrollHeight = chatContainer.value?.scrollHeight ?? 0;
109
+
110
+ resizeObserver = new ResizeObserver(() => {
111
+ const el = chatContainer.value;
112
+ if (!el) return;
113
+
114
+ const newScrollHeight = el.scrollHeight;
115
+
116
+ const wasNearBottom =
117
+ el.scrollTop + el.clientHeight >= prevScrollHeight - bottomThreshold;
118
+ const contentGrown = newScrollHeight > prevScrollHeight;
119
+
120
+ /**
121
+ * @author PolinaSukhorukova-webitel
122
+ *
123
+ * arrivedState.bottom lags after programmatic scrollTo,
124
+ * so the distance is also checked manually.
125
+ */
126
+ const shouldScrollToBottom =
127
+ contentGrown && (arrivedState.bottom || wasNearBottom);
128
+
129
+ if (shouldScrollToBottom) {
130
+ scrollToBottom('instant');
131
+ }
132
+
133
+ prevScrollHeight = newScrollHeight;
134
+ updateScrollToBottomBtnVisibility(el);
135
+ });
136
+
137
+ resizeObserver.observe(chatContent.value);
138
+ };
139
+
140
+ const stopStickToBottomObserving = () => {
141
+ resizeObserver?.disconnect();
142
+ resizeObserver = null;
143
+ };
144
+
145
+ useResizeObserver(chatContainer, () => {
146
+ const el = chatContainer.value;
147
+ if (!el) return;
148
+
149
+ updateThreshold(el.clientHeight);
150
+ updateScrollToBottomBtnVisibility(el);
151
+ });
152
+
153
+ const resetScrollState = () => {
154
+ stopStickToBottomObserving();
155
+ prevScrollHeight = 0;
156
+ newUnseenMessagesCount.value = 0;
157
+ resetScrollToBottomBtn();
158
+ };
159
+
112
160
  watch(
113
161
  () => messages.value?.length,
114
162
  (newValue, oldValue) => {
@@ -123,25 +171,57 @@ export const useChatScroll = (
123
171
  watch(
124
172
  () => isLoading?.value,
125
173
  async (loading) => {
126
- if (loading || !isLoadingNextMessages.value) return;
174
+ // restore scroll position after older messages are prepended:
175
+ // scroll to the previously top message so the view doesn't jump
176
+ if (loading || !isLoadingNextMessages) return;
127
177
 
128
178
  await nextTick();
129
179
 
130
- element.value?.scrollTo({
131
- top: lastVisibleMessageEl.value?.offsetTop,
180
+ chatContainer.value?.scrollTo({
181
+ top: lastVisibleMessageEl?.offsetTop,
132
182
  behavior: 'auto',
133
183
  });
134
184
 
135
- isLoadingNextMessages.value = false;
185
+ isLoadingNextMessages = false;
136
186
  },
137
187
  );
138
188
 
189
+ watch(
190
+ () => chatId.value,
191
+ async () => {
192
+ resetScrollState();
193
+
194
+ if (isChatClosed.value) return;
195
+
196
+ await nextTick();
197
+
198
+ onBeforeStart?.({
199
+ scrollToBottom,
200
+ });
201
+
202
+ startStickToBottomObserving();
203
+ },
204
+ {
205
+ immediate: true,
206
+ },
207
+ );
208
+
209
+ watch(
210
+ () => arrivedState.bottom,
211
+ (bottom) => {
212
+ if (bottom) newUnseenMessagesCount.value = 0;
213
+ },
214
+ );
215
+
216
+ onUnmounted(() => {
217
+ stopStickToBottomObserving();
218
+ });
219
+
139
220
  return {
140
221
  showScrollToBottomBtn,
141
222
  newUnseenMessagesCount,
142
223
  scrollToBottom,
143
224
  loadNextMessages,
144
225
  handleChatScroll,
145
- handleChatResize,
146
226
  };
147
227
  };
@@ -0,0 +1,49 @@
1
+ import { onUnmounted, type Ref } from 'vue';
2
+
3
+ /**
4
+ * @author PolinaSukhorukova-webitel
5
+ *
6
+ * Fires the callback on every resize and disconnects itself
7
+ * once clientHeight is unchanged twice in a row.
8
+ */
9
+
10
+ export const useObserveHeightUntilStable = (
11
+ chatContainer: Ref<HTMLElement | null>,
12
+ callback: () => void,
13
+ ) => {
14
+ let observer: ResizeObserver | null = null;
15
+
16
+ const stopObserve = () => {
17
+ observer?.disconnect();
18
+ observer = null;
19
+ };
20
+
21
+ const startObserve = () => {
22
+ if (!chatContainer.value) return;
23
+
24
+ let lastClientHeight = chatContainer.value.clientHeight;
25
+ let stableCount = 0;
26
+
27
+ observer = new ResizeObserver(() => {
28
+ const currentClientHeight = chatContainer.value?.clientHeight;
29
+ callback();
30
+
31
+ if (currentClientHeight === lastClientHeight) {
32
+ stableCount++;
33
+ if (stableCount >= 2) stopObserve();
34
+ } else {
35
+ stableCount = 0;
36
+ lastClientHeight = currentClientHeight;
37
+ }
38
+ });
39
+
40
+ observer.observe(chatContainer.value);
41
+ };
42
+
43
+ onUnmounted(stopObserve);
44
+
45
+ return {
46
+ startObserve,
47
+ stopObserve,
48
+ };
49
+ };
@@ -0,0 +1,51 @@
1
+ import type { UseScrollReturn } from '@vueuse/core';
2
+ import { type Ref, ref } from 'vue';
3
+
4
+ export const useScrollToBottomBtn = (
5
+ chatContainer: Ref<HTMLElement | null>,
6
+ arrivedState: UseScrollReturn['arrivedState'],
7
+ ) => {
8
+ const showScrollToBottomBtn = ref(false);
9
+ /* @author ye.pohranichna
10
+ why 136px? because: https://webitel.atlassian.net/browse/WTEL-7136 */
11
+ const defaultThreshold = 136;
12
+ /* @author ye.pohranichna
13
+ the distance where the scrollToBottomBtn must be shown/hide. */
14
+ const threshold = ref(defaultThreshold);
15
+
16
+ const handleChatScroll = () => {
17
+ const wrapper = chatContainer.value;
18
+ if (!wrapper) return;
19
+
20
+ updateScrollToBottomBtnVisibility(wrapper);
21
+ };
22
+
23
+ const resetScrollToBottomBtn = () => {
24
+ showScrollToBottomBtn.value = false;
25
+ };
26
+
27
+ const updateScrollToBottomBtnVisibility = (el: HTMLElement) => {
28
+ if (arrivedState.bottom) {
29
+ resetScrollToBottomBtn();
30
+ return;
31
+ /* @author ye.pohranichna
32
+ quit the function because we are already at the bottom */
33
+ }
34
+
35
+ const { scrollTop, scrollHeight, clientHeight } = el;
36
+ const distanceFromBottom = scrollHeight - (scrollTop + clientHeight);
37
+ showScrollToBottomBtn.value = distanceFromBottom > threshold.value;
38
+ };
39
+
40
+ const updateThreshold = (clientHeight: number) => {
41
+ threshold.value = Math.max(defaultThreshold, clientHeight * 0.3);
42
+ };
43
+
44
+ return {
45
+ showScrollToBottomBtn,
46
+ handleChatScroll,
47
+ resetScrollToBottomBtn,
48
+ updateScrollToBottomBtnVisibility,
49
+ updateThreshold,
50
+ };
51
+ };
@@ -72,8 +72,7 @@
72
72
 
73
73
  <script setup lang="ts">
74
74
  import { ComponentSize } from '@webitel/ui-sdk/enums';
75
- import { computed, defineEmits, defineProps, inject } from 'vue';
76
-
75
+ import { computed, inject } from 'vue';
77
76
  import type { ChatMessageType } from '../../../types/ChatMessage.types';
78
77
  import { useChatMessageFile } from '../composables/useChatMessageFile';
79
78
  import { MessageAction } from '../enums/MessageAction.enum';
@@ -20,8 +20,7 @@
20
20
 
21
21
  <script setup lang="ts">
22
22
  import { prettifyFileSize } from '@webitel/ui-sdk/scripts';
23
- import { computed, defineProps } from 'vue';
24
-
23
+ import { computed } from 'vue';
25
24
  import type { ChatMessageFile } from '../../../../types/ChatMessage.types';
26
25
 
27
26
  const props = withDefaults(
@@ -17,8 +17,6 @@
17
17
  setup
18
18
  lang="ts"
19
19
  >
20
- import { defineEmits, defineProps } from 'vue';
21
-
22
20
  import type { ChatMessageFile } from '../../../../types/ChatMessage.types';
23
21
 
24
22
  const props = defineProps<{
@@ -30,8 +30,7 @@
30
30
  <script setup lang="ts">
31
31
  import { WtPlayer, WtVidstackPlayer } from '@webitel/ui-sdk/components';
32
32
  import { ComponentSize } from '@webitel/ui-sdk/enums';
33
- import { computed, defineEmits, defineProps } from 'vue';
34
-
33
+ import { computed } from 'vue';
35
34
  import type { ChatMessageFile } from '../../../../types/ChatMessage.types';
36
35
 
37
36
  const props = defineProps<{
@@ -24,7 +24,7 @@ interface IChatMessageSizeExceededErrorProps {
24
24
  selfSide?: boolean;
25
25
  }
26
26
 
27
- const props = withDefaults(defineProps<IChatMessageSizeExceededErrorProps>(), {
27
+ withDefaults(defineProps<IChatMessageSizeExceededErrorProps>(), {
28
28
  selfSide: false,
29
29
  });
30
30
  </script>
@@ -12,7 +12,7 @@
12
12
  lang="ts"
13
13
  >
14
14
  import { prettifyTime } from '@webitel/ui-sdk/scripts';
15
- import { computed, defineProps } from 'vue';
15
+ import { computed } from 'vue';
16
16
 
17
17
  const props = withDefaults(
18
18
  defineProps<{
@@ -1,5 +1,5 @@
1
1
  export interface ChatMessageType {
2
- id: number;
2
+ id: number | string;
3
3
  date?: number;
4
4
  file?: ChatMessageFile;
5
5
  member: ChatMember;
@@ -24,10 +24,11 @@ export type ChatMessageFile = {
24
24
  mime?: string;
25
25
  url?: string;
26
26
  streamUrl?: string;
27
+ malware?: boolean;
27
28
  };
28
29
 
29
30
  export type ChatMember = {
30
- id: number;
31
+ id: number | string;
31
32
  name: string;
32
33
  type: string;
33
34
  userId?: number;
@@ -17,6 +17,9 @@
17
17
  :is-loading="props.isNextMessagesLoading"
18
18
  :without-avatars="props.withoutAvatars"
19
19
  :agent-name="props.agentName"
20
+ :contact="props.contact"
21
+ :chat-id="props.chatId"
22
+ :is-chat-closed="props.isChatClosed"
20
23
  @[ChatAction.LoadNextMessages]="emit(ChatAction.LoadNextMessages)"
21
24
  />
22
25
  </slot>
@@ -50,9 +53,9 @@
50
53
  </template>
51
54
 
52
55
  <script setup lang="ts">
56
+ import { WebitelContactsContact } from '@webitel/api-services/gen/models';
53
57
  import { ComponentSize } from '@webitel/ui-sdk/enums';
54
58
  import { computed, provide, ref } from 'vue';
55
-
56
59
  import ChatFooterWrapper from './chat-footer/components/chat-footer-wrapper.vue';
57
60
  import ChatInputActionsBar from './chat-footer/modules/user-input/components/chat-input-actions-bar.vue';
58
61
  import ChatTextField from './chat-footer/modules/user-input/components/chat-text-field.vue';
@@ -81,6 +84,9 @@ const props = withDefaults(
81
84
  withoutAvatars?: boolean;
82
85
  readonly?: boolean; // hide chat footer with textarea and action-buttons
83
86
  agentName?: string;
87
+ contact?: WebitelContactsContact;
88
+ chatId?: string;
89
+ isChatClosed?: boolean;
84
90
  }>(),
85
91
  {
86
92
  size: ComponentSize.MD,
@@ -89,6 +95,8 @@ const props = withDefaults(
89
95
  canLoadNextMessages: false,
90
96
  isNextMessagesLoading: false,
91
97
  readonly: false,
98
+ chatId: '',
99
+ isChatClosed: false,
92
100
  },
93
101
  );
94
102
 
@@ -161,5 +169,6 @@ function sendFile(files: File[]) {
161
169
  flex-direction: column;
162
170
  height: 100%;
163
171
  width: 100%;
172
+ gap: var(--spacing-2xs);
164
173
  }
165
174
  </style>
@@ -1 +1 @@
1
- export { ResultCallbacks } from '@webitel/ui-sdk/src/types';
1
+ export type { ResultCallbacks } from '@webitel/ui-sdk/src/types';
@@ -1,6 +1,6 @@
1
1
  import mitt from 'mitt';
2
2
 
3
- import type { ChatMessageType } from '../../../types/ui';
3
+ import type { ChatMessageType } from '../messaging/types/ChatMessage.types';
4
4
 
5
5
  export type UiChatsEmitterEvents = {
6
6
  insertAtCursor: {
@@ -0,0 +1,23 @@
1
+ import type { IMessage } from '@webitel/chat-web-sdk';
2
+ import type { ChatMessageType } from '../../types';
3
+ export interface ToChatMessageOptions {
4
+ /**
5
+ * Decide whether a message is authored by the current agent / "self" side.
6
+ * Result is written to `ChatMember.self`, which drives outgoing-bubble
7
+ * alignment in the UI. The message alone cannot know who "self" is — that
8
+ * is presentation context the caller owns (e.g. compare `sender.contact`
9
+ * against the logged-in account).
10
+ */
11
+ isSelf?: (message: IMessage) => boolean;
12
+ }
13
+ /**
14
+ * Map a single `@webitel/chat-web-sdk` message (`IMessage`) into the
15
+ * `@webitel/ui-chats` presentation contract (`ChatMessageType`).
16
+ *
17
+ * Anti-corruption layer: keeps `ui-chats` free of any backend/SDK coupling.
18
+ */
19
+ export declare const mapMessageToChatMessage: (message: IMessage, options?: ToChatMessageOptions) => ChatMessageType;
20
+ /**
21
+ * Batch variant of {@link mapMessageToChatMessage} for message history pages.
22
+ */
23
+ export declare const mapMessagesToChatMessages: (messages: readonly IMessage[], options?: ToChatMessageOptions) => ChatMessageType[];
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Adapters mapping external data sources into the `@webitel/ui-chats`
3
+ * presentation contract (`ChatMessageType`, …).
4
+ *
5
+ * Consuming this entry pulls `@webitel/chat-web-sdk` (declared as an optional
6
+ * peerDependency). The core `@webitel/ui-chats/ui` entry stays free of it.
7
+ */
8
+ export { mapMessagesToChatMessages, mapMessageToChatMessage, type ToChatMessageOptions, } from './chat-web-sdk/toChatMessage';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Public data contract of `@webitel/ui-chats`.
3
+ *
4
+ * These are the plain, transport-agnostic shapes the UI components accept.
5
+ * External data sources (e.g. `@webitel/chat-web-sdk`) must be mapped into
6
+ * them — see `@webitel/ui-chats/adapters`.
7
+ */
8
+ export type { ChatMember, ChatMessageChatInfo, ChatMessageFile, ChatMessageType, ChatVia, ContactInfo, } from '../ui/messaging/types/ChatMessage.types';
@@ -1,10 +1,11 @@
1
1
  export declare const ChatAction: {
2
- readonly SendMessage: "sendMessage";
3
- readonly AttachFiles: "attachFiles";
4
- readonly EmojiPicker: "emojiPicker";
5
- readonly QuickReplies: "quickReplies";
2
+ readonly SendMessage: "sendMessage";
3
+ readonly AttachFiles: "attachFiles";
4
+ readonly EmojiPicker: "emojiPicker";
5
+ readonly QuickReplies: "quickReplies";
6
+ readonly LoadNextMessages: "loadNextMessages";
6
7
  };
7
8
  export type ChatAction = (typeof ChatAction)[keyof typeof ChatAction];
8
9
  export type SharedActionSlots = {
9
- [key in `action:${ChatAction}`]?: () => any;
10
+ [key in `action:${ChatAction}`]?: () => unknown;
10
11
  };
@@ -1,3 +1,7 @@
1
- export { ChatAction } from "./chat-footer/modules/user-input/enums/ChatAction.enum";
2
- export type { ChatMessageType } from "./messaging/types/ChatMessage.types";
3
- export { default as ChatContainer } from "./the-chat-container.vue";
1
+ export { ChatAction } from './chat-footer/modules/user-input/enums/ChatAction.enum';
2
+ export { useChatScroll } from './messaging/composables/useChatScroll';
3
+ export { useObserveHeightUntilStable } from './messaging/composables/useObserveHeightUntilStable';
4
+ export { useChatMessageFile } from './messaging/modules/message/composables/useChatMessageFile';
5
+ export { MessageAction } from './messaging/modules/message/enums/MessageAction.enum';
6
+ export type { ChatMessageFile, ChatMessageType, } from './messaging/types/ChatMessage.types';
7
+ export { default as ChatContainer } from './the-chat-container.vue';
@@ -1,3 +1,4 @@
1
+ import { WebitelContactsContact } from '@webitel/api-services/gen/models';
1
2
  import type { ChatMessageType } from '../types/ChatMessage.types';
2
3
  type __VLS_Props = {
3
4
  messages: ChatMessageType[];
@@ -5,15 +6,20 @@ type __VLS_Props = {
5
6
  isLoading?: boolean;
6
7
  withoutAvatars?: boolean;
7
8
  agentName?: string;
9
+ contact?: WebitelContactsContact;
10
+ chatId?: string;
11
+ isChatClosed?: boolean;
8
12
  };
9
13
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
10
14
  loadNextMessages: () => any;
11
15
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
12
16
  onLoadNextMessages?: () => any;
13
17
  }>, {
18
+ chatId: string;
19
+ isChatClosed: boolean;
20
+ isLoading: boolean;
14
21
  withoutAvatars: boolean;
15
22
  next: boolean;
16
- isLoading: boolean;
17
23
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
18
24
  declare const _default: typeof __VLS_export;
19
25
  export default _default;
@@ -1,10 +1,20 @@
1
1
  import { type ComputedRef, type Ref } from 'vue';
2
2
  import type { ChatMessageType } from '../types/ChatMessage.types';
3
- export declare const useChatScroll: (element: Ref<HTMLElement | null>, messages: Ref<ChatMessageType[]> | ComputedRef<ChatMessageType[]>, isLoading?: Ref<boolean> | ComputedRef<boolean>) => {
3
+ export interface UseChatScrollOptions {
4
+ chatContainer: Ref<HTMLElement | null>;
5
+ chatContent: Ref<HTMLElement | null>;
6
+ messages: Ref<ChatMessageType[]> | ComputedRef<ChatMessageType[]>;
7
+ chatId: ComputedRef<string>;
8
+ isChatClosed: ComputedRef<boolean>;
9
+ isLoading?: Ref<boolean> | ComputedRef<boolean>;
10
+ onBeforeStart?: (options: {
11
+ scrollToBottom: (behavior?: ScrollBehavior) => void;
12
+ }) => void;
13
+ }
14
+ export declare const useChatScroll: ({ chatContainer, chatContent, messages, chatId, isChatClosed, isLoading, onBeforeStart, }: UseChatScrollOptions) => {
4
15
  showScrollToBottomBtn: Ref<boolean, boolean>;
5
16
  newUnseenMessagesCount: Ref<number, number>;
6
17
  scrollToBottom: (behavior?: ScrollBehavior) => void;
7
- loadNextMessages: (canLoadMore: boolean | undefined, onLoadNextMessages: () => void) => void;
18
+ loadNextMessages: (canLoadMore: boolean, onLoadNextMessages: () => void) => void;
8
19
  handleChatScroll: () => void;
9
- handleChatResize: () => void;
10
20
  };