@webitel/ui-chats 0.1.48 → 0.1.50

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/ui-chats",
3
- "version": "0.1.48",
3
+ "version": "0.1.50",
4
4
  "description": "Reusable Webitel Frontend Code for Chats UI",
5
5
  "workspaces": [
6
6
  "../../",
@@ -41,7 +41,7 @@
41
41
  "@webitel/api-services": "^0.1.0",
42
42
  "@webitel/chat-web-sdk": "^0.0.19",
43
43
  "@webitel/styleguide": "~26.2",
44
- "@webitel/ui-sdk": "~26.8",
44
+ "@webitel/ui-sdk": "~26.6",
45
45
  "mitt": "^3",
46
46
  "vue": "^3.5"
47
47
  },
@@ -1,17 +1,13 @@
1
+ import type { I18n } from 'vue-i18n';
1
2
  import { messages } from '../locale';
2
3
 
3
- /** Minimal i18n surface ui-chats needs — avoids vue-i18n schema variance issues. */
4
- export type UiChatsI18n = {
5
- global: {
6
- mergeLocaleMessage: (locale: string, message: unknown) => void;
7
- };
8
- };
9
-
10
4
  export type UiChatsConfig = {
11
- i18n?: UiChatsI18n;
5
+ i18n?: I18n;
12
6
  };
13
7
 
14
- export const defaultConfig: UiChatsConfig = {};
8
+ export const defaultConfig: UiChatsConfig = {
9
+ i18n: null,
10
+ };
15
11
 
16
12
  export const setConfig = (conf: UiChatsConfig) => {
17
13
  Object.assign(defaultConfig, conf);
@@ -21,6 +17,6 @@ export const setConfig = (conf: UiChatsConfig) => {
21
17
  }
22
18
 
23
19
  Object.entries(messages).forEach(([locale, localeMessages]) => {
24
- conf.i18n!.global.mergeLocaleMessage(locale, localeMessages);
20
+ conf.i18n.global.mergeLocaleMessage(locale, localeMessages);
25
21
  });
26
22
  };
@@ -181,7 +181,7 @@ export const useChatScroll = ({
181
181
  viewportTransitionTimer = setTimeout(() => {
182
182
  isViewportTransition = false;
183
183
  viewportTransitionTimer = null;
184
- }, 1000);
184
+ }, 500);
185
185
  };
186
186
 
187
187
  /**
@@ -3,15 +3,17 @@ import { onUnmounted, type Ref } from 'vue';
3
3
  /**
4
4
  * @author PolinaSukhorukova-webitel
5
5
  *
6
- * Fires the callback on every resize and disconnects itself
7
- * once clientHeight is unchanged twice in a row.
6
+ * Fires the callback on every resize of the target element and stops
7
+ * either after the given timeout or on unmount.
8
8
  */
9
9
 
10
10
  export const useObserveHeightUntilStable = (
11
- chatContainer: Ref<HTMLElement | null>,
11
+ target: Ref<HTMLElement | null>,
12
12
  callback: () => void,
13
+ timeout?: number,
13
14
  ) => {
14
15
  let observer: ResizeObserver | null = null;
16
+ let stopTimer: ReturnType<typeof setTimeout> | null = null;
15
17
  let isViewportTransition = false;
16
18
  let viewportTransitionTimer: ReturnType<typeof setTimeout> | null = null;
17
19
 
@@ -23,35 +25,31 @@ export const useObserveHeightUntilStable = (
23
25
  viewportTransitionTimer = setTimeout(() => {
24
26
  isViewportTransition = false;
25
27
  viewportTransitionTimer = null;
26
- }, 1000);
28
+ }, 500);
27
29
  };
28
30
 
29
31
  const stopObserve = () => {
30
32
  observer?.disconnect();
31
33
  observer = null;
34
+
35
+ if (stopTimer) {
36
+ clearTimeout(stopTimer);
37
+ stopTimer = null;
38
+ }
32
39
  };
33
40
 
34
41
  const startObserve = () => {
35
- if (!chatContainer.value) return;
36
-
37
- let lastClientHeight: number | undefined = chatContainer.value.clientHeight;
38
- let stableCount = 0;
42
+ if (!target.value) return;
39
43
 
40
44
  observer = new ResizeObserver(() => {
41
- const currentClientHeight = chatContainer.value?.clientHeight;
42
-
43
45
  if (!isViewportTransition) callback();
44
-
45
- if (currentClientHeight === lastClientHeight) {
46
- stableCount++;
47
- if (stableCount >= 2) stopObserve();
48
- } else {
49
- stableCount = 0;
50
- lastClientHeight = currentClientHeight;
51
- }
52
46
  });
53
47
 
54
- observer.observe(chatContainer.value);
48
+ observer.observe(target.value);
49
+
50
+ if (timeout !== undefined) {
51
+ stopTimer = setTimeout(stopObserve, timeout);
52
+ }
55
53
  };
56
54
 
57
55
  /**
@@ -136,7 +136,7 @@ const isTransferAgent = computed(
136
136
 
137
137
  const isBot = computed<boolean>(() => props.message.member?.type === 'bot');
138
138
 
139
- const getClientUsername = computed<string | undefined>(() => {
139
+ const getClientUsername = computed<string>(() => {
140
140
  if (isTransferAgent.value) return props.message.member?.name;
141
141
  if (isSelfSide.value) return props?.agentName;
142
142
 
@@ -38,12 +38,11 @@ const documentSize = computed(() => {
38
38
  });
39
39
 
40
40
  function downloadDocument() {
41
- if (!props.file?.url) return;
41
+ if (!props.file) return;
42
42
  const a = document.createElement('a');
43
43
  a.href = props.file.url;
44
44
  a.target = '_blank';
45
- // empty `download` lets the browser derive the filename from the URL
46
- a.download = props.file.name ?? '';
45
+ a.download = props.file.name;
47
46
  a.click();
48
47
  }
49
48
  </script>
@@ -35,7 +35,7 @@ import type { ChatMessageFile } from '../../../../types/ChatMessage.types';
35
35
 
36
36
  const props = defineProps<{
37
37
  file: ChatMessageFile;
38
- type?: string;
38
+ type: string;
39
39
  }>();
40
40
 
41
41
  const emit = defineEmits<{
@@ -15,8 +15,8 @@ export const useChatMessages = (
15
15
  ) => {
16
16
  function showChatDate(index: number): boolean {
17
17
  const { prevMessage, message } = getMessage(index);
18
- const prevDate = Number(prevMessage?.createdAt) || 0;
19
- const currentDate = Number(message?.createdAt) || 0;
18
+ const prevDate = +prevMessage?.createdAt || 0;
19
+ const currentDate = +message?.createdAt || 0;
20
20
  return (
21
21
  !!prevMessage &&
22
22
  formatDate(prevDate, FormatDateMode.DATE) !==
@@ -3,7 +3,7 @@ import { computed, type Ref, toRef } from 'vue';
3
3
  import type { ChatMessageFile } from '../../../types/ChatMessage.types';
4
4
 
5
5
  export function useChatMessageFile(
6
- file: ChatMessageFile | Ref<ChatMessageFile | undefined> | undefined,
6
+ file: ChatMessageFile | Ref<ChatMessageFile>,
7
7
  ) {
8
8
  const fileRef = toRef(file);
9
9
 
@@ -30,7 +30,7 @@ export function useChatMessageFile(
30
30
  );
31
31
  });
32
32
 
33
- const isMediaType = (value: string | undefined) => {
33
+ const isMediaType = (value: string) => {
34
34
  return !!(value?.includes('audio') || value?.includes('video'));
35
35
  };
36
36
 
@@ -1,7 +1 @@
1
- // Defined locally so consumers (and this package's .d.ts) do not depend on
2
- // @webitel/ui-sdk/src/types package-export resolution.
3
- export type ResultCallbacks = {
4
- onSuccess?: () => void;
5
- onError?: (error: Error) => void;
6
- onComplete?: () => void;
7
- };
1
+ export type { ResultCallbacks } from '@webitel/ui-sdk/src/types';