@webitel/ui-chats 0.0.17 → 0.0.19

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.17",
3
+ "version": "0.0.19",
4
4
  "description": "Reusable Webitel Frontend Code for Chats UI",
5
5
  "workspaces": [
6
6
  "../../",
@@ -1,6 +1,7 @@
1
1
  <template>
2
2
  <wt-textarea
3
3
  ref="chatTextFieldInput"
4
+ class="chat-text-field"
4
5
  :model-value="textModel"
5
6
  :size="size"
6
7
  autoresize
@@ -48,3 +49,12 @@ function insertAtCursor(text: string) {
48
49
  }
49
50
  </script>
50
51
 
52
+ <style scoped>
53
+ .chat-text-field :deep(textarea) {
54
+ /* https://webitel.atlassian.net/browse/WTEL-7388
55
+ fixed styles after component migrated on vuetify */
56
+ max-height: 100%;
57
+ min-height: auto;
58
+ overflow: auto !important;
59
+ }
60
+ </style>
@@ -3,6 +3,7 @@ export const ChatAction = {
3
3
  AttachFiles: "attachFiles",
4
4
  EmojiPicker: "emojiPicker",
5
5
  QuickReplies: "quickReplies",
6
+ LoadNextMessages: "loadNextMessages",
6
7
  } as const;
7
8
 
8
9
  export type ChatAction = (typeof ChatAction)[keyof typeof ChatAction];
package/src/ui/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { ChatAction } from "./chat-footer/modules/user-input/enums/ChatAction.enum";
2
+ export { MessageAction } from "./messaging/modules/message/enums/MessageAction.enum";
2
3
  export type { ChatMessageType } from "./messaging/types/ChatMessage.types";
3
4
  export { default as ChatContainer } from "./the-chat-container.vue";
@@ -0,0 +1,39 @@
1
+ <template>
2
+ <div class="chat-observer">
3
+ <wt-intersection-observer
4
+ :can-load-more="props.next"
5
+ :loading="props.isLoading"
6
+ @next="emit(ChatAction.LoadNextMessages)"
7
+ />
8
+ </div>
9
+ </template>
10
+
11
+ <script setup lang="ts">
12
+ import { ChatAction } from "../../chat-footer/modules/user-input/enums/ChatAction.enum";
13
+
14
+ const props = withDefaults(
15
+ defineProps<{
16
+ next?: boolean;
17
+ isLoading?: boolean;
18
+ }>(),
19
+ {
20
+ next: false,
21
+ isLoading: false,
22
+ },
23
+ );
24
+
25
+ const emit = defineEmits<(e: typeof ChatAction.LoadNextMessages) => void>();
26
+ </script>
27
+
28
+ <style scoped>
29
+ /* @author ye.pohranichna */
30
+ /* reserve height for the loader to avoid unnecessary chat height changes https://webitel.atlassian.net/browse/WTEL-5366 */
31
+ .chat-observer {
32
+ /* observer loader height @author ye.pohranichna */
33
+ min-height: calc(var(--spacing-lg)*2 + var(--icon-md-size));
34
+ /* @author ye.pohranichna */
35
+ /* to place observer at the bottom of observer wrapper (closer to messages) */
36
+ display: flex;
37
+ align-items: flex-end;
38
+ }
39
+ </style>
@@ -9,12 +9,19 @@
9
9
  @scroll="handleChatScroll"
10
10
  @resize="handleChatResize"
11
11
  >
12
+ <chat-observer
13
+ v-if="props.next"
14
+ :next="props.next"
15
+ :loading="props.isLoading"
16
+ @next="emit(ChatAction.LoadNextMessages)"
17
+ />
12
18
  <chat-message
13
19
  v-for="(message, index) of props.messages"
14
20
  :key="message.id"
15
21
  :message="message"
16
22
  :show-avatar="showAvatar(index)"
17
23
  :without-avatars="props.withoutAvatars"
24
+ @[MessageAction.ClickOnImage]="clickOnImage(message)"
18
25
  >
19
26
  <template #before-message>
20
27
  <chat-date-divider
@@ -36,12 +43,15 @@
36
43
  import type { Emitter } from "mitt";
37
44
  import { computed, inject, nextTick, onMounted, useTemplateRef } from "vue";
38
45
 
46
+ import { ChatAction } from "../../chat-footer/modules/user-input/enums/ChatAction.enum";
39
47
  import type { UiChatsEmitterEvents } from "../../utils/emitter";
40
48
  import { useChatScroll } from "../composables/useChatScroll";
41
49
  import ChatMessage from "../modules/message/components/chat-message.vue";
42
50
  import { useChatMessages } from "../modules/message/composables/useChatMessage";
51
+ import { MessageAction } from "../modules/message/enums/MessageAction.enum";
43
52
  import type { ChatMessageType } from "../types/ChatMessage.types";
44
53
  import ChatDateDivider from "./chat-date-divider.vue";
54
+ import ChatObserver from "./chat-observer.vue";
45
55
  import ScrollToBottomBtn from "./scroll-to-bottom-btn.vue";
46
56
 
47
57
  const uiChatsEmitter = inject<Emitter<UiChatsEmitterEvents>>("uiChatsEmitter");
@@ -49,13 +59,19 @@ const uiChatsEmitter = inject<Emitter<UiChatsEmitterEvents>>("uiChatsEmitter");
49
59
  const props = withDefaults(
50
60
  defineProps<{
51
61
  messages: ChatMessageType[];
62
+ next?: boolean;
63
+ isLoading?: boolean;
52
64
  withoutAvatars?: boolean;
53
65
  }>(),
54
66
  {
67
+ next: false,
68
+ isLoading: false,
55
69
  withoutAvatars: false,
56
70
  },
57
71
  );
58
72
 
73
+ const emit = defineEmits<(e: typeof ChatAction.LoadNextMessages) => void>();
74
+
59
75
  const messagesContainer = useTemplateRef("messages-container");
60
76
 
61
77
  const { showAvatar, showChatDate } = useChatMessages(props.messages);
@@ -75,6 +91,10 @@ function focusOnInput() {
75
91
  uiChatsEmitter?.on("focusOnTextField", focus);
76
92
  }
77
93
 
94
+ function clickOnImage(message: ChatMessageType) {
95
+ uiChatsEmitter!.emit("clickChatMessageImage", message);
96
+ }
97
+
78
98
  onMounted(() => {
79
99
  nextTick(() => {
80
100
  scrollToBottom();
@@ -104,4 +124,5 @@ onMounted(() => {
104
124
  scrollbar-gutter: stable both-edges;
105
125
  gap: var(--spacing-xs);
106
126
  }
127
+
107
128
  </style>
@@ -10,7 +10,7 @@
10
10
 
11
11
  <div class="chat-message__content">
12
12
  <div
13
- v-if="withoutAvatars"
13
+ v-if="!props.withoutAvatars"
14
14
  class="chat-message__avatar-wrapper"
15
15
  >
16
16
  <message-avatar
@@ -32,7 +32,7 @@
32
32
  <message-image
33
33
  v-else-if="image"
34
34
  :file="image"
35
- @open="emit('open-image')"
35
+ @open="emit(MessageAction.ClickOnImage)"
36
36
  />
37
37
  <message-document
38
38
  v-else-if="document"
@@ -58,6 +58,7 @@ import { computed, defineEmits, defineProps, inject } from "vue";
58
58
 
59
59
  import type { ChatMessageType } from "../../../types/ChatMessage.types";
60
60
  import { useChatMessageFile } from "../composables/useChatMessageFile";
61
+ import { MessageAction } from "../enums/MessageAction.enum";
61
62
  import MessageAvatar from "./details/chat-message-avatar.vue";
62
63
  import MessageBlockedError from "./details/chat-message-blocked-error.vue";
63
64
  import MessageDocument from "./details/chat-message-document.vue";
@@ -81,10 +82,8 @@ const props = withDefaults(
81
82
  );
82
83
 
83
84
  const emit = defineEmits<{
84
- "open-image": [];
85
- "initialized-player": [
86
- object,
87
- ];
85
+ (e: typeof MessageAction.ClickOnImage): void;
86
+ (e: typeof MessageAction.InitializedPlayer, player: object): void;
88
87
  }>();
89
88
 
90
89
  const size = inject<ComponentSize>("size");
@@ -108,7 +107,7 @@ const getClientUsername = computed<string>(() => {
108
107
  });
109
108
 
110
109
  function handlePlayerInitialize(player) {
111
- emit("initialized-player", {
110
+ emit(MessageAction.InitializedPlayer, {
112
111
  player,
113
112
  });
114
113
  }
@@ -0,0 +1,6 @@
1
+ export const MessageAction = {
2
+ ClickOnImage: "clickOnImage",
3
+ InitializedPlayer: "initializedPlayer",
4
+ } as const;
5
+
6
+ export type MessageAction = (typeof MessageAction)[keyof typeof MessageAction];
@@ -12,7 +12,10 @@
12
12
  />
13
13
  <chat-messages-container
14
14
  :messages="props.messages"
15
+ :next="props.canLoadNextMessages"
16
+ :is-loading="props.isNextMessagesLoading"
15
17
  :without-avatars="props.withoutAvatars"
18
+ @[ChatAction.LoadNextMessages]="emit(ChatAction.LoadNextMessages)"
16
19
  @[ChatAction.AttachFiles]="sendFile"
17
20
  />
18
21
  </slot>
@@ -58,6 +61,7 @@ import {
58
61
  import Dropzone from "./messaging/components/dropzone.vue";
59
62
  import ChatMessagesContainer from "./messaging/components/the-chat-messages-container.vue";
60
63
  import { useDropzoneHandlers } from "./messaging/composables/useDropzoneHandlers";
64
+ import { MessageAction } from "./messaging/modules/message/enums/MessageAction.enum";
61
65
  import type { ChatMessageType } from "./messaging/types/ChatMessage.types";
62
66
  import { createUiChatsEmitter } from "./utils/emitter";
63
67
  import type { ResultCallbacks } from "./utils/ResultCallbacks.types";
@@ -67,6 +71,8 @@ const props = withDefaults(
67
71
  messages: ChatMessageType[];
68
72
  chatActions?: ChatAction[];
69
73
  size?: ComponentSize;
74
+ canLoadNextMessages?: boolean; // 'next'
75
+ isNextMessagesLoading?: boolean;
70
76
  withoutAvatars?: boolean;
71
77
  }>(),
72
78
  {
@@ -75,6 +81,8 @@ const props = withDefaults(
75
81
  chatActions: () => [
76
82
  ChatAction.SendMessage,
77
83
  ],
84
+ canLoadNextMessages: false,
85
+ isNextMessagesLoading: false,
78
86
  },
79
87
  );
80
88
 
@@ -89,6 +97,8 @@ const emit = defineEmits<{
89
97
  files: File[],
90
98
  options: ResultCallbacks,
91
99
  ): void;
100
+ (e: typeof ChatAction.LoadNextMessages): void;
101
+ (e: typeof MessageAction.ClickOnImage, message: ChatMessageType): void;
92
102
  }>();
93
103
 
94
104
  const slots = defineSlots<
@@ -103,6 +113,9 @@ const uiChatsEmitter = createUiChatsEmitter();
103
113
  provide("size", props.size);
104
114
  provide("uiChatsEmitter", uiChatsEmitter);
105
115
 
116
+ uiChatsEmitter?.on("clickChatMessageImage", (message) => {
117
+ emit(MessageAction.ClickOnImage, message);
118
+ });
106
119
  const { isDropzoneVisible, handleDragLeave } = useDropzoneHandlers();
107
120
 
108
121
  const draft = ref<string>("");
@@ -1,10 +1,13 @@
1
1
  import mitt from "mitt";
2
2
 
3
+ import { ChatMessageType } from "../../../types/ui";
4
+
3
5
  export type UiChatsEmitterEvents = {
4
6
  insertAtCursor: {
5
7
  text: string;
6
8
  };
7
9
  focusOnTextField: undefined;
10
+ clickChatMessageImage: ChatMessageType;
8
11
  };
9
12
 
10
13
  export const createUiChatsEmitter = () => {
@@ -1,10 +1,10 @@
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
6
  };
7
7
  export type ChatAction = (typeof ChatAction)[keyof typeof ChatAction];
8
8
  export type SharedActionSlots = {
9
- [key in `action:${ChatAction}`]?: () => any;
9
+ [key in `action:${ChatAction}`]?: () => any;
10
10
  };
@@ -0,0 +1,14 @@
1
+ type __VLS_Props = {
2
+ next?: boolean;
3
+ isLoading?: boolean;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
6
+ loadNextMessages: () => any;
7
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
8
+ onLoadNextMessages?: () => any;
9
+ }>, {
10
+ next: boolean;
11
+ isLoading: boolean;
12
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
13
+ declare const _default: typeof __VLS_export;
14
+ export default _default;
@@ -1,10 +1,18 @@
1
1
  import type { ChatMessageType } from "../types/ChatMessage.types";
2
2
  type __VLS_Props = {
3
3
  messages: ChatMessageType[];
4
+ next?: boolean;
5
+ isLoading?: boolean;
4
6
  withoutAvatars?: boolean;
5
7
  };
6
- declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
8
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
9
+ loadNextMessages: () => any;
10
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
11
+ onLoadNextMessages?: () => any;
12
+ }>, {
7
13
  withoutAvatars: boolean;
14
+ next: boolean;
15
+ isLoading: boolean;
8
16
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
17
  declare const _default: typeof __VLS_export;
10
18
  export default _default;
@@ -11,12 +11,12 @@ type __VLS_Slots = {} & {
11
11
  } & {
12
12
  'after-message'?: (props: typeof __VLS_44) => any;
13
13
  };
14
- declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
15
- "open-image": () => any;
16
- "initialized-player": (args_0: object) => any;
14
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
15
+ clickOnImage: () => any;
16
+ initializedPlayer: (player: object) => any;
17
17
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
18
- "onOpen-image"?: () => any;
19
- "onInitialized-player"?: (args_0: object) => any;
18
+ onClickOnImage?: () => any;
19
+ onInitializedPlayer?: (player: object) => any;
20
20
  }>, {
21
21
  username: string;
22
22
  showAvatar: boolean;
@@ -0,0 +1,5 @@
1
+ export declare const MessageAction: {
2
+ readonly ClickOnImage: "clickOnImage";
3
+ readonly InitializedPlayer: "initializedPlayer";
4
+ };
5
+ export type MessageAction = (typeof MessageAction)[keyof typeof MessageAction];
@@ -1,44 +1,44 @@
1
1
  export interface ChatMessageType {
2
- id: number;
3
- date?: number;
4
- file?: ChatMessageFile;
5
- member: ChatMember;
6
- peer?: ChatMember;
7
- chat?: ChatMessageChatInfo;
8
- createdAt: number;
9
- channelId?: string;
10
- updatedAt?: number;
11
- contact?: null | ContactInfo;
12
- text?: string;
2
+ id: number;
3
+ date?: number;
4
+ file?: ChatMessageFile;
5
+ member: ChatMember;
6
+ peer?: ChatMember;
7
+ chat?: ChatMessageChatInfo;
8
+ createdAt: number;
9
+ channelId?: string;
10
+ updatedAt?: number;
11
+ contact?: null | ContactInfo;
12
+ text?: string;
13
13
  }
14
14
  export type ContactInfo = {
15
- id: string;
16
- name?: string;
15
+ id: string;
16
+ name?: string;
17
17
  };
18
18
  export type ChatMessageFile = {
19
- id?: string;
20
- name?: string;
21
- size?: string;
22
- mime?: string;
23
- url?: string;
24
- streamUrl?: string;
19
+ id?: string;
20
+ name?: string;
21
+ size?: string;
22
+ mime?: string;
23
+ url?: string;
24
+ streamUrl?: string;
25
25
  };
26
26
  export type ChatMember = {
27
- id: number;
28
- name: string;
29
- type: string;
30
- userId?: number;
31
- externalId?: string;
32
- via?: ChatVia;
33
- self?: boolean;
27
+ id: number;
28
+ name: string;
29
+ type: string;
30
+ userId?: number;
31
+ externalId?: string;
32
+ via?: ChatVia;
33
+ self?: boolean;
34
34
  };
35
35
  export type ChatMessageChatInfo = {
36
- id: string;
37
- via: ChatVia;
36
+ id: string;
37
+ via: ChatVia;
38
38
  };
39
39
  export type ChatVia = {
40
- id: number;
41
- name: string;
42
- type: string;
43
- messenger?: string;
40
+ id: number;
41
+ name: string;
42
+ type: string;
43
+ messenger?: string;
44
44
  };
@@ -1,33 +1,58 @@
1
1
  import { ComponentSize } from "@webitel/ui-sdk/enums";
2
- import { ChatAction, type SharedActionSlots } from "./chat-footer/modules/user-input/enums/ChatAction.enum";
2
+ import {
3
+ ChatAction,
4
+ type SharedActionSlots,
5
+ } from "./chat-footer/modules/user-input/enums/ChatAction.enum";
3
6
  import type { ChatMessageType } from "./messaging/types/ChatMessage.types";
4
7
  import type { ResultCallbacks } from "./utils/ResultCallbacks.types";
5
8
  type __VLS_Props = {
6
- messages: ChatMessageType[];
7
- chatActions?: ChatAction[];
8
- size?: ComponentSize;
9
- withoutAvatars?: boolean;
9
+ messages: ChatMessageType[];
10
+ chatActions?: ChatAction[];
11
+ size?: ComponentSize;
12
+ withoutAvatars?: boolean;
10
13
  };
11
14
  type __VLS_Slots = {
12
- main: () => any;
13
- footer: () => any;
15
+ main: () => any;
16
+ footer: () => any;
14
17
  } & SharedActionSlots;
15
- declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
16
- "action:sendMessage": (text: string, options: ResultCallbacks) => any;
17
- "action:attachFiles": (files: File[], options: ResultCallbacks) => any;
18
- }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
19
- "onAction:sendMessage"?: (text: string, options: ResultCallbacks) => any;
20
- "onAction:attachFiles"?: (files: File[], options: ResultCallbacks) => any;
21
- }>, {
22
- size: ComponentSize;
23
- withoutAvatars: boolean;
24
- chatActions: ChatAction[];
25
- }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
18
+ declare const __VLS_base: import("vue").DefineComponent<
19
+ __VLS_Props,
20
+ {},
21
+ {},
22
+ {},
23
+ {},
24
+ import("vue").ComponentOptionsMixin,
25
+ import("vue").ComponentOptionsMixin,
26
+ {} & {
27
+ "action:sendMessage": (text: string, options: ResultCallbacks) => any;
28
+ "action:attachFiles": (files: File[], options: ResultCallbacks) => any;
29
+ },
30
+ string,
31
+ import("vue").PublicProps,
32
+ Readonly<__VLS_Props> &
33
+ Readonly<{
34
+ "onAction:sendMessage"?: (text: string, options: ResultCallbacks) => any;
35
+ "onAction:attachFiles"?: (files: File[], options: ResultCallbacks) => any;
36
+ }>,
37
+ {
38
+ size: ComponentSize;
39
+ withoutAvatars: boolean;
40
+ chatActions: ChatAction[];
41
+ },
42
+ {},
43
+ {},
44
+ {},
45
+ string,
46
+ import("vue").ComponentProvideOptions,
47
+ false,
48
+ {},
49
+ any
50
+ >;
26
51
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
27
52
  declare const _default: typeof __VLS_export;
28
53
  export default _default;
29
54
  type __VLS_WithSlots<T, S> = T & {
30
- new (): {
31
- $slots: S;
32
- };
55
+ new (): {
56
+ $slots: S;
57
+ };
33
58
  };
@@ -1,7 +1,9 @@
1
+ import { ChatMessageType } from "../../../types/ui";
1
2
  export type UiChatsEmitterEvents = {
2
3
  insertAtCursor: {
3
4
  text: string;
4
5
  };
5
6
  focusOnTextField: undefined;
7
+ clickChatMessageImage: ChatMessageType;
6
8
  };
7
9
  export declare const createUiChatsEmitter: () => import("mitt").Emitter<UiChatsEmitterEvents>;