@bcc-code/vue-bcc-chat-ui 1.6.3 → 2.0.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": "1.6.3",
5
+ "version": "2.0.1",
6
6
  "type": "module",
7
7
  "private": false,
8
8
  "files": [
@@ -22,7 +22,6 @@
22
22
  "vue": "^3.0.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@types/lodash-es": "^4.17.12",
26
25
  "@types/node": "^20.11.25",
27
26
  "@vitejs/plugin-vue": "^4.6.2",
28
27
  "path": "^0.12.7",
@@ -37,8 +36,7 @@
37
36
  "@cometchat/chat-uikit-vue": "^4.2.1",
38
37
  "@cometchat/uikit-resources": "^4.2.2",
39
38
  "@cometchat/uikit-shared": "^4.2.2",
40
- "jwt-decode": "^4.0.0",
41
- "lodash-es": "^4.17.21"
39
+ "jwt-decode": "^4.0.0"
42
40
  },
43
41
  "scripts": {
44
42
  "dev": "vite",
@@ -1,23 +1,22 @@
1
1
  <script setup lang="ts">
2
- import { onBeforeMount, onMounted, onUnmounted, ref, nextTick, watch, Ref } from "vue";
2
+ import {
3
+ nextTick,
4
+ onBeforeMount,
5
+ onMounted,
6
+ onUnmounted,
7
+ ref,
8
+ watchEffect,
9
+ } from "vue";
3
10
  import chat from "../chat";
4
- import { connect, disconnect, connected } from "../chat/connection";
11
+ import { connect, disconnect } from "../chat/connection";
5
12
  import { loggedIn } from "../chat/login";
6
-
7
- import {
8
- CometChatMessages,
9
- CometChatMessageTemplate,
10
- CometChatUIKit,
11
- ImageBubbleStyle,
12
- MessageBubbleAlignment,
13
- } from "@cometchat/chat-uikit-vue";
13
+ import { CometChatMessages } from "@cometchat/chat-uikit-vue";
14
+ import { Group } from "@cometchat/chat-sdk-javascript";
15
+ import { watchAndApplyStyle } from "../chat/styleFix";
14
16
  import {
15
- MessageListConfiguration,
16
- MessageComposerConfiguration,
17
- } from "@cometchat/uikit-shared";
18
- import { CometChatTheme } from "@cometchat/uikit-resources";
19
- import { BaseMessage, Group, User } from "@cometchat/chat-sdk-javascript";
20
- import { watchAndApplyStyle } from "../chat/mobileView";
17
+ messageComposerConfiguration,
18
+ messageListConfiguration,
19
+ } from "../chat/uiKit";
21
20
 
22
21
  const props = defineProps({
23
22
  chatUid: { type: String, required: true },
@@ -26,176 +25,82 @@ const props = defineProps({
26
25
  const componentId = ref(
27
26
  `component-${Math.random().toString(36).substring(2, 11)}`
28
27
  );
29
- const chatGroup = ref<Group | null>(null);
30
-
31
- watch(chatGroup, (exists: null) => {
32
- if (!exists) return;
33
-
34
- nextTick(() => {
35
- watchAndApplyStyle(
36
- ".bcc-chat-message-list",
37
- [{
38
- selector: '.cc__imageviewer__close-button',
39
- style: { "padding-top": "env(safe-area-inset-top)" },
40
- shadowDomSelector: 'cometchat-full-screen-viewer'
41
- }, {
42
- selector: '.cc__text',
43
- style: { color: 'var(--cc__text-color)' },
44
- shadowDomSelector: 'cometchat-text-bubble'
45
- }, {
46
- selector: '.cc__linkpreview-title',
47
- style: { color: 'var(--cc__text-color)' },
48
- shadowDomSelector: 'link-preview'
49
- }]
50
- );
51
- });
52
- })
28
+ const chatGroup = ref<Group>();
29
+
30
+ onMounted(() => {
31
+ watchAndApplyStyle(".bcc-chat-message-list-wrapper", [
32
+ {
33
+ selector: ".cc__imageviewer__close-button",
34
+ style: { "padding-top": "env(safe-area-inset-top)" },
35
+ shadowDomSelector: "cometchat-full-screen-viewer",
36
+ },
37
+ {
38
+ selector: ".cc__text",
39
+ style: { color: "var(--cc__text-color)" },
40
+ shadowDomSelector: "cometchat-text-bubble",
41
+ },
42
+ {
43
+ selector: ".cc__linkpreview-title",
44
+ style: { color: "var(--cc__text-color)" },
45
+ shadowDomSelector: "link-preview",
46
+ },
47
+ {
48
+ selector: ".cc__messageinput",
49
+ style: {
50
+ "border-radius": "8px 8px 0 0",
51
+ "box-shadow":
52
+ "0px -1px 2px 0px rgba(17, 24, 39, 0.05), 1px -1px 3px 0px rgba(17, 24, 39, 0.1)",
53
+ },
54
+ shadowDomSelector: "cometchat-message-input",
55
+ },
56
+ {
57
+ selector: ".cc__messageinput-input",
58
+ style: {
59
+ "font-size": "16px",
60
+ padding: "8px",
61
+ "max-height": "none",
62
+ height: "64px",
63
+ },
64
+ shadowDomSelector: "cometchat-message-input",
65
+ },
66
+ ]);
67
+ });
53
68
 
54
69
  onBeforeMount(async () => {
55
70
  await connect(componentId.value);
56
- await loadData();
57
71
  });
58
72
 
59
73
  onUnmounted(async () => {
60
74
  await disconnect(componentId.value);
61
75
  });
62
76
 
63
- watch(
64
- [loggedIn, connected, chat.initialized, () => props.chatUid],
65
- () => {
66
- loadData();
67
- }
68
- );
69
-
70
- // Loads data if logged in
71
- const loadData = async () => {
72
- if (
73
- loggedIn.value &&
74
- chat.initialized.value
75
- ) {
76
- initTemplates();
77
- if (props.chatUid) {
78
- // Retreive group
79
- chatGroup.value = await chat.data.getGroup(props.chatUid);
80
-
81
- // Clear group chat count - assume user is viewing chat
82
- if (chatGroup.value) {
83
- await chat.data.clearGroupChatCount(props.chatUid);
84
- }
85
- } else {
86
- chatGroup.value = null;
87
- }
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);
88
81
  } else {
89
- if (!loggedIn.value) {
90
- chatGroup.value = null;
91
- }
82
+ chatGroup.value = undefined;
92
83
  }
93
- };
94
-
95
- const messageComposerConfiguration = new MessageComposerConfiguration({
96
- hideLiveReaction: true,
97
- hideVoiceRecording: true,
98
84
  });
99
- const messageListConfiguration: Ref<any> = ref(null);
100
-
101
- // Templates cannot be initialized before CometChat is initiazlied
102
- // CometChatUIKit.getDataSource().getAllMessageTemplates() will return null before cometchat is initialized
103
- // So we postpone overriding the templates until cometchat is logged in
104
- let templatesInitialized = false;
105
- const initTemplates = () => {
106
- if (templatesInitialized) {
107
- return;
108
- }
109
- templatesInitialized = true;
110
- messageListConfiguration.value = getMessageListConfiguration();
111
- };
112
-
113
- // Override message list configuration
114
- function getMessageListConfiguration(): MessageListConfiguration {
115
- let templates = CometChatUIKit.getDataSource()
116
- .getAllMessageTemplates()
117
- .map((template: CometChatMessageTemplate) => {
118
- // Override options
119
- template.options = (
120
- loggedInUser: User,
121
- message: BaseMessage,
122
- theme: CometChatTheme,
123
- group: Group | undefined
124
- ) => {
125
- return getOptionsView(loggedInUser, message, theme, group);
126
- };
127
-
128
- // Override image styling
129
- if (template.category === "message" && template.type === "image") {
130
- template.contentView = getImageMessageContentView;
131
- }
132
- return template;
133
- });
134
-
135
- function getImageMessageContentView(
136
- message: CometChat.BaseMessage,
137
- _alignment: MessageBubbleAlignment
138
- ) {
139
- if (message.getDeletedAt()) {
140
- return CometChatUIKit.getDataSource().getDeleteMessageBubble(
141
- message,
142
- new CometChatTheme({})
143
- );
144
- }
145
- return {
146
- componentName: "CometChatImageBubble",
147
- props: {
148
- src: message.getData().url,
149
- imageStyle: new ImageBubbleStyle({
150
- // you can adjust image styles here
151
- width: "100%",
152
- height: "100%",
153
- }),
154
- },
155
- };
156
- }
157
-
158
- const getOptionsView = (
159
- loggedInUser: User,
160
- message: BaseMessage,
161
- theme: any,
162
- group: Group | undefined
163
- ) => {
164
- const optionsData = CometChatUIKit.getDataSource().getMessageOptions(
165
- loggedInUser,
166
- message,
167
- theme,
168
- group
169
- );
170
- const customOptionsView = optionsData.filter(
171
- (ele) => ele.id !== "sendMessagePrivately"
172
- );
173
- return customOptionsView;
174
- };
175
-
176
- return new MessageListConfiguration({
177
- scrollToBottomOnNewMessages: true,
178
- templates: templates,
179
- });
180
- }
181
85
  </script>
182
86
 
183
87
  <template>
184
- <div v-if="chatGroup" class="bcc-chat-message-list">
185
- <CometChatMessages
186
- :hideMessageHeader="true"
187
- :disableSoundForMessages="true"
188
- :messageComposerConfiguration="messageComposerConfiguration"
189
- :messageListConfiguration="messageListConfiguration"
190
- :hideMessageComposer="false"
191
- :hideDetails="true"
192
- :group="chatGroup"
193
- />
194
- <div v-if="!connected" class="bcc-chat-message-composer-offline">
195
- <span>Offline</span>
88
+ <div class="bcc-chat-message-list-wrapper">
89
+ <div v-if="chatGroup" class="bcc-chat-message-list">
90
+ <CometChatMessages
91
+ :hideMessageHeader="true"
92
+ :disableSoundForMessages="true"
93
+ :messageComposerConfiguration="messageComposerConfiguration"
94
+ :messageListConfiguration="messageListConfiguration"
95
+ :hideMessageComposer="false"
96
+ :hideDetails="true"
97
+ :group="chatGroup"
98
+ />
99
+ </div>
100
+ <div class="bcc-chat-message-list-offline">
101
+ <span>Waiting for connection...</span>
196
102
  </div>
197
103
  </div>
198
- <div class="bcc-chat-message-list-offline"><span>Waiting for connection...</span></div>
199
104
  </template>
200
105
 
201
106
  <style lang="scss">
@@ -205,10 +110,15 @@ body {
205
110
 
206
111
  @media (prefers-color-scheme: dark) {
207
112
  background: #000;
208
- color: #fff;
113
+ color: #fff;
209
114
  }
210
115
  }
211
116
 
117
+ .bcc-chat-message-list-wrapper {
118
+ position: relative;
119
+ height: 100%;
120
+ }
121
+
212
122
  /*
213
123
  primary: my bubble
214
124
  accent: message bar text
@@ -222,37 +132,37 @@ accent900: text in avatar
222
132
 
223
133
  .bcc-chat-message-list {
224
134
  height: 100%;
225
- --cc__primary: #CFEAC8;
226
- --cc__background: #F3FAF7;
135
+ --cc__primary: #cfeac8;
136
+ --cc__background: #f3faf7;
227
137
  --cc__secondary: white;
228
138
  --cc__accent: #004e48;
229
139
  --cc__accent50: rgba(62, 142, 117, 0.04);
230
- --cc__accent100: #FFFFFF;
140
+ --cc__accent100: #ffffff;
231
141
  --cc__accent200: rgba(62, 142, 117, 0.15);
232
142
  --cc__accent300: rgba(62, 142, 117, 0.24);
233
143
  --cc__accent400: rgba(62, 142, 117, 0.33);
234
144
  --cc__accent500: rgba(62, 142, 117, 0.46);
235
- --cc__accent600: #004E48;
236
- --cc__accent700: #254A40;
145
+ --cc__accent600: #004e48;
146
+ --cc__accent700: #254a40;
237
147
  --cc__accent800: rgba(62, 142, 117, 0.82);
238
- --cc__accent900: #F3FAF7;
148
+ --cc__accent900: #f3faf7;
239
149
  --cc__text-color: #000;
240
150
 
241
151
  @media (prefers-color-scheme: dark) {
242
- --cc__primary: #57639E;
152
+ --cc__primary: #57639e;
243
153
  --cc__background: hsl(230, 25%, 15%);
244
154
  --cc__secondary: #111827;
245
- --cc__accent: #6274AE;
155
+ --cc__accent: #6274ae;
246
156
  --cc__accent50: rgba(98, 116, 174, 0.24);
247
157
  --cc__accent100: linear-gradient(45deg, #05070b 0%, #0c111c 100%);
248
158
  --cc__accent200: rgba(98, 116, 174, 0.35);
249
159
  --cc__accent300: rgba(98, 116, 174, 0.44);
250
160
  --cc__accent400: rgba(98, 116, 174, 0.53);
251
161
  --cc__accent500: rgba(98, 116, 174, 0.66);
252
- --cc__accent600: #758ABC;
253
- --cc__accent700: #6274AE;
162
+ --cc__accent600: #758abc;
163
+ --cc__accent700: #6274ae;
254
164
  --cc__accent800: rgba(98, 116, 174, 0.92);
255
- --cc__accent900: #F3FAF7;
165
+ --cc__accent900: #f3faf7;
256
166
  --cc__text-color: #fff;
257
167
  }
258
168
 
@@ -264,6 +174,11 @@ accent900: text in avatar
264
174
  .cc-messages-wrapper__messages-list {
265
175
  height: calc(100% - 96px);
266
176
  }
177
+
178
+ /* 1.1.2 Wrapper for Messages Composer */
179
+ .cc-messagecomposer-wrapper {
180
+ padding: 0;
181
+ }
267
182
  }
268
183
  }
269
184
 
@@ -291,7 +206,7 @@ accent900: text in avatar
291
206
  display: flex;
292
207
  justify-content: center;
293
208
  align-items: center;
294
- background: rgba(255,255,255,0.75);
209
+ background: rgba(255, 255, 255, 0.75);
295
210
  border-radius: 12px;
296
211
  }
297
212
  }