@webitel/ui-chats 0.0.23 → 0.0.24

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.0.23",
3
+ "version": "0.0.24",
4
4
  "description": "Reusable Webitel Frontend Code for Chats UI",
5
5
  "workspaces": [
6
6
  "../../",
@@ -6,6 +6,7 @@
6
6
  :size="size"
7
7
  autoresize
8
8
  @update:model-value="send"
9
+ @enter="emit('enter')"
9
10
  />
10
11
  </template>
11
12
 
@@ -28,6 +29,10 @@ const uiChatsEmitter = inject<Emitter<UiChatsEmitterEvents>>("uiChatsEmitter");
28
29
  uiChatsEmitter!.on("insertAtCursor", ({ text }) => insertAtCursor(text));
29
30
  uiChatsEmitter!.on("focusOnTextField", focus);
30
31
 
32
+ const emit = defineEmits<{
33
+ enter: [];
34
+ }>();
35
+
31
36
  const chatTextFieldInputRef =
32
37
  useTemplateRef<typeof WtTextarea>("chatTextFieldInput");
33
38
 
@@ -41,7 +41,14 @@
41
41
 
42
42
  <script setup lang="ts">
43
43
  import type { Emitter } from "mitt";
44
- import { computed, inject, nextTick, onMounted, useTemplateRef } from "vue";
44
+ import {
45
+ computed,
46
+ defineProps,
47
+ inject,
48
+ nextTick,
49
+ onMounted,
50
+ useTemplateRef,
51
+ } from "vue";
45
52
 
46
53
  import { ChatAction } from "../../chat-footer/modules/user-input/enums/ChatAction.enum";
47
54
  import type { UiChatsEmitterEvents } from "../../utils/emitter";
@@ -74,7 +81,9 @@ const emit = defineEmits<(e: typeof ChatAction.LoadNextMessages) => void>();
74
81
 
75
82
  const messagesContainer = useTemplateRef("messages-container");
76
83
 
77
- const { showAvatar, showChatDate } = useChatMessages(props.messages);
84
+ const { showAvatar, showChatDate } = useChatMessages(
85
+ computed(() => props.messages),
86
+ ); // props values reactivity https://stackoverflow.com/questions/72408463/use-props-in-composables-vue3 @author ye.pohranichna
78
87
 
79
88
  const {
80
89
  showScrollToBottomBtn,
@@ -84,7 +93,7 @@ const {
84
93
  handleChatResize,
85
94
  } = useChatScroll(
86
95
  messagesContainer,
87
- computed(() => props.messages),
96
+ computed(() => props.messages), // props values reactivity https://stackoverflow.com/questions/72408463/use-props-in-composables-vue3 @author ye.pohranichna
88
97
  );
89
98
 
90
99
  function focusOnInput() {
@@ -1,6 +1,6 @@
1
1
  import { FormatDateMode } from "@webitel/ui-sdk/enums";
2
2
  import { formatDate } from "@webitel/ui-sdk/utils";
3
- import { type Ref, ref } from "vue";
3
+ import { type ComputedRef, type Ref } from "vue";
4
4
 
5
5
  import type { ChatMessageType } from "../../../types/ChatMessage.types";
6
6
 
@@ -10,9 +10,9 @@ interface GetMessageResult {
10
10
  nextMessage?: ChatMessageType;
11
11
  }
12
12
 
13
- export const useChatMessages = (chatMessages: ChatMessageType[]) => {
14
- const messages: Ref<ChatMessageType[]> = ref(chatMessages);
15
-
13
+ export const useChatMessages = (
14
+ messages: Ref<ChatMessageType[]> | ComputedRef<ChatMessageType[]>,
15
+ ) => {
16
16
  function showChatDate(index: number): boolean {
17
17
  const { prevMessage, message } = getMessage(index);
18
18
  const prevDate = +prevMessage?.createdAt || 0;
@@ -24,6 +24,7 @@
24
24
  <template #default>
25
25
  <chat-text-field
26
26
  v-model:text="draft"
27
+ @enter="sendMessage"
27
28
  />
28
29
  <chat-input-actions-bar
29
30
  :actions="props.chatActions"
@@ -3,8 +3,10 @@ type __VLS_ModelProps = {
3
3
  "text": MaybeRef<string>;
4
4
  };
5
5
  declare const __VLS_export: import("vue").DefineComponent<__VLS_ModelProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ enter: () => any;
6
7
  "update:text": (value: MaybeRef<string>) => any;
7
8
  }, string, import("vue").PublicProps, Readonly<__VLS_ModelProps> & Readonly<{
9
+ onEnter?: () => any;
8
10
  "onUpdate:text"?: (value: MaybeRef<string>) => any;
9
11
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
12
  declare const _default: typeof __VLS_export;
@@ -1,10 +1,11 @@
1
+ import { type ComputedRef, type Ref } from "vue";
1
2
  import type { ChatMessageType } from "../../../types/ChatMessage.types";
2
3
  interface GetMessageResult {
3
4
  prevMessage?: ChatMessageType;
4
5
  message?: ChatMessageType;
5
6
  nextMessage?: ChatMessageType;
6
7
  }
7
- export declare const useChatMessages: (chatMessages: ChatMessageType[]) => {
8
+ export declare const useChatMessages: (messages: Ref<ChatMessageType[]> | ComputedRef<ChatMessageType[]>) => {
8
9
  showAvatar: (index: number) => boolean;
9
10
  getMessage: (index: number) => GetMessageResult;
10
11
  showChatDate: (index: number) => boolean;