@bcc-code/vue-bcc-chat-ui 2.0.2 → 2.1.1

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
@@ -2,7 +2,7 @@
2
2
  "name": "@bcc-code/vue-bcc-chat-ui",
3
3
  "author": "bcc-code",
4
4
  "license": "Apache-2.0",
5
- "version": "2.0.2",
5
+ "version": "2.1.1",
6
6
  "type": "module",
7
7
  "private": false,
8
8
  "files": [
@@ -36,7 +36,8 @@
36
36
  "@cometchat/chat-uikit-vue": "^4.2.1",
37
37
  "@cometchat/uikit-resources": "^4.2.2",
38
38
  "@cometchat/uikit-shared": "^4.2.2",
39
- "jwt-decode": "^4.0.0"
39
+ "jwt-decode": "^4.0.0",
40
+ "vue-markdown-render": "^2.1.1"
40
41
  },
41
42
  "scripts": {
42
43
  "dev": "vite",
@@ -0,0 +1,67 @@
1
+ <script setup lang="ts">
2
+ import VueMarkdown from 'vue-markdown-render'
3
+
4
+ defineProps<{
5
+ text: string
6
+ }>()
7
+
8
+ // Replacing URLs in the string with Markdown links
9
+ function linkify(str: string) {
10
+ // Regex to match URLs that may or may not start with "www." and are not already part of a Markdown link
11
+ const urlRegex = /(?<!\]\()((?:https?|ftp):\/\/[^\s\]\)]*|www\.[^\s\]\)]+)(?=[\s\]\)](?!\()|$)/g;
12
+
13
+ // Function to format a URL into a Markdown link
14
+ const formatUrlToMarkdown = (match: string) => {
15
+ let url = match;
16
+ // Prepend "http://" to URLs starting with "www."
17
+ if (url.startsWith('www.')) {
18
+ url = 'http://' + url;
19
+ }
20
+ const hostname = new URL(url).hostname;
21
+ return `[${hostname}](${url})`;
22
+ };
23
+
24
+ return str.replace(urlRegex, formatUrlToMarkdown);
25
+ }
26
+ </script>
27
+
28
+ <template>
29
+ <vue-markdown :source="linkify(text)" :options="{
30
+ typographer: true,
31
+ }" class="bcc-chat-msg-bubble" />
32
+ </template>
33
+
34
+ <style lang="scss">
35
+ .bcc-chat-msg-bubble {
36
+ padding: 8px 12px;
37
+ width: auto;
38
+ max-width: 500px;
39
+ line-height: 1.2;
40
+ font: 400 14px Archivo, sans-serif, Inter;
41
+
42
+ p {
43
+ color: var(--cc__text-color);
44
+ line-height: 1.2;
45
+ word-break: break-word;
46
+ text-align: left;
47
+ white-space: pre-line;
48
+ }
49
+
50
+ p:first-child {
51
+ margin-top: 0;
52
+ }
53
+ p:last-child {
54
+ margin-bottom: 0;
55
+ }
56
+
57
+ a {
58
+ color: var(--cc__link-color);
59
+ text-decoration: underline;
60
+ font-weight: 500;
61
+ }
62
+
63
+ ul {
64
+ padding-left: 16px;
65
+ }
66
+ }
67
+ </style>
@@ -1,11 +1,9 @@
1
1
  <script setup lang="ts">
2
2
  import {
3
- nextTick,
4
- onBeforeMount,
5
3
  onMounted,
6
4
  onUnmounted,
7
5
  ref,
8
- watchEffect,
6
+ watch,
9
7
  } from "vue";
10
8
  import chat from "../chat";
11
9
  import { connect, disconnect } from "../chat/connection";
@@ -17,6 +15,7 @@ import {
17
15
  messageComposerConfiguration,
18
16
  messageListConfiguration,
19
17
  } from "../chat/uiKit";
18
+ import { OnlineStatus } from "../offline/types";
20
19
 
21
20
  const props = defineProps({
22
21
  chatUid: { type: String, required: true },
@@ -26,6 +25,23 @@ const componentId = ref(
26
25
  `component-${Math.random().toString(36).substring(2, 11)}`
27
26
  );
28
27
  const chatGroup = ref<Group>();
28
+ const chatReady = ref(false);
29
+
30
+ watch([loggedIn, ()=>props.chatUid, chat.initialized], async ([_loggedIn, _chatUid, _initialized]) => {
31
+ if (_loggedIn && _chatUid && _initialized) {
32
+ chatGroup.value = (await chat.getGroup(props.chatUid)) ?? undefined;
33
+ await chat.clearGroupChatCount(props.chatUid);
34
+ } else if (chatGroup.value) {
35
+ chatGroup.value = undefined;
36
+ }
37
+ }, { immediate: true });
38
+
39
+ watch(chat.onlineStatus, async (status: OnlineStatus) => {
40
+ if (status === "online") {
41
+ await connect(componentId.value);
42
+ }
43
+ if (!chatReady.value) chatReady.value = true;
44
+ }, { immediate: true });
29
45
 
30
46
  onMounted(() => {
31
47
  watchAndApplyStyle(".bcc-chat-message-list-wrapper", [
@@ -39,11 +55,21 @@ onMounted(() => {
39
55
  style: { color: "var(--cc__text-color)" },
40
56
  shadowDomSelector: "cometchat-text-bubble",
41
57
  },
58
+ {
59
+ selector: ".cc__linkpreview",
60
+ style: { height: "auto" },
61
+ shadowDomSelector: "link-preview",
62
+ },
42
63
  {
43
64
  selector: ".cc__linkpreview-title",
44
65
  style: { color: "var(--cc__text-color)" },
45
66
  shadowDomSelector: "link-preview",
46
67
  },
68
+ {
69
+ selector: ".cc__linkpreview-favicon",
70
+ style: { 'flex-shrink': '0' },
71
+ shadowDomSelector: "link-preview",
72
+ },
47
73
  {
48
74
  selector: ".cc__messageinput",
49
75
  style: {
@@ -66,27 +92,15 @@ onMounted(() => {
66
92
  ]);
67
93
  });
68
94
 
69
- onBeforeMount(async () => {
70
- await connect(componentId.value);
71
- });
72
-
73
95
  onUnmounted(async () => {
74
96
  await disconnect(componentId.value);
75
97
  });
76
98
 
77
- watchEffect(async () => {
78
- if (loggedIn.value && props.chatUid && chat.initialized.value) {
79
- chatGroup.value = (await chat.getGroup(props.chatUid)) ?? undefined;
80
- await chat.clearGroupChatCount(props.chatUid);
81
- } else {
82
- chatGroup.value = undefined;
83
- }
84
- });
85
99
  </script>
86
100
 
87
101
  <template>
88
102
  <div class="bcc-chat-message-list-wrapper">
89
- <div v-if="chatGroup" class="bcc-chat-message-list">
103
+ <div v-if="chatGroup && chatReady" class="bcc-chat-message-list">
90
104
  <CometChatMessages
91
105
  :hideMessageHeader="true"
92
106
  :disableSoundForMessages="true"
@@ -96,6 +110,9 @@ watchEffect(async () => {
96
110
  :hideDetails="true"
97
111
  :group="chatGroup"
98
112
  />
113
+ <div v-if="chat.onlineStatus.value === 'offline' || !chat.connected.value" class="bcc-chat-message-composer-offline">
114
+ <span>Waiting for connection...</span>
115
+ </div>
99
116
  </div>
100
117
  <div class="bcc-chat-message-list-offline">
101
118
  <span>Waiting for connection...</span>
@@ -147,6 +164,7 @@ accent900: text in avatar
147
164
  --cc__accent800: rgba(62, 142, 117, 0.82);
148
165
  --cc__accent900: #f3faf7;
149
166
  --cc__text-color: #000;
167
+ --cc__link-color: #57639e;
150
168
 
151
169
  @media (prefers-color-scheme: dark) {
152
170
  --cc__primary: #57639e;
@@ -164,6 +182,7 @@ accent900: text in avatar
164
182
  --cc__accent800: rgba(98, 116, 174, 0.92);
165
183
  --cc__accent900: #f3faf7;
166
184
  --cc__text-color: #fff;
185
+ --cc__link-color: #cfeac8;
167
186
  }
168
187
 
169
188
  /* 1. Wrapper for Messages component */
@@ -194,8 +213,6 @@ accent900: text in avatar
194
213
  top: -96px;
195
214
  height: 96px;
196
215
  width: 100%;
197
- box-sizing: border-box;
198
- padding: 16px 14px;
199
216
  color: rgb(176, 176, 176);
200
217
  font: 700 1rem sans-serif;
201
218
 
@@ -207,7 +224,7 @@ accent900: text in avatar
207
224
  justify-content: center;
208
225
  align-items: center;
209
226
  background: rgba(255, 255, 255, 0.75);
210
- border-radius: 12px;
227
+ border-radius: 8px 8px 0 0;
211
228
  }
212
229
  }
213
230
  }