vue-wiguet-chatweb 0.1.37 → 0.1.39
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/dist/components/Chat.vue.d.ts +1 -0
- package/dist/style.css +1 -1
- package/dist/vue-wiguet-chatweb.js +2385 -2318
- package/dist/vue-wiguet-chatweb.umd.cjs +10 -10
- package/package.json +1 -1
- package/src/components/Chat.vue +124 -30
package/package.json
CHANGED
package/src/components/Chat.vue
CHANGED
@@ -1,35 +1,61 @@
|
|
1
1
|
<template>
|
2
2
|
<div class="widget">
|
3
|
-
<div class="header-widget">
|
3
|
+
<div class="header-widget flex-0">
|
4
4
|
<h4 class="title-chat">{{ titlePrincipal }}</h4>
|
5
5
|
<button @click="() => toggleChat()" class="btn-close">
|
6
6
|
<IconClose class="pointer" />
|
7
7
|
</button>
|
8
8
|
</div>
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
9
|
+
|
10
|
+
<div class="flex-1" style="position: relative; height: 0;">
|
11
|
+
<div
|
12
|
+
ref="dropZoneRef"
|
13
|
+
@drop.self.prevent="
|
14
|
+
(e) => {
|
15
|
+
dropHandler(e);
|
16
|
+
(e.target as HTMLElement)?.classList?.remove('drop-over');
|
17
|
+
(e.target as HTMLElement).style.zIndex = '-1';
|
18
|
+
}
|
19
|
+
"
|
20
|
+
@dragenter.self="
|
21
|
+
(e) => {
|
22
|
+
(e.target as HTMLElement)?.classList?.add('drop-over');
|
23
|
+
}
|
24
|
+
"
|
25
|
+
@dragleave.self="
|
26
|
+
(e) => {
|
27
|
+
(e.target as HTMLElement)?.classList?.remove('drop-over');
|
28
|
+
(e.target as HTMLElement).style.zIndex = '-1';
|
29
|
+
}
|
30
|
+
"
|
31
|
+
@dragover.prevent
|
32
|
+
style="position: absolute; bottom: 0; left: 0; right: 0; top: 0; z-index: -1;"
|
33
|
+
></div>
|
34
|
+
<div class="messages-container" ref="messageContainerRef" @dragenter.prevent="dropZoneRef!.style.zIndex = '1'">
|
35
|
+
<div class="loader" v-if="isLoading">
|
36
|
+
<Loader />
|
37
|
+
</div>
|
38
|
+
<MessageList
|
39
|
+
v-if="messagesData.data.length > 0"
|
40
|
+
:messages="messagesData.data"
|
41
|
+
:canLoadMoreMessages="messagesData.canLoadMoreMessages"
|
42
|
+
@loadMore="getMessages"
|
43
|
+
@retry="retryMessage"
|
44
|
+
@on-qualifying="(args) => onQualifying(args)"
|
45
|
+
@see="(message: Message) => {
|
46
|
+
currentDialogView = DIALOG_VIEWS.SEE
|
47
|
+
urlFileMessage = message.urlFile
|
48
|
+
dialog.title = 'Imagen'
|
49
|
+
dialog.modelValue = true
|
50
|
+
}"
|
51
|
+
/>
|
52
|
+
<div class="fit" v-else>
|
53
|
+
<span class="center">No tienes mensajes</span>
|
54
|
+
</div>
|
29
55
|
</div>
|
30
56
|
</div>
|
31
57
|
|
32
|
-
<div class="w-full">
|
58
|
+
<div class="w-full flex-0">
|
33
59
|
<form v-if="!isDisabledBoxMessage" class="message-send" @submit.prevent="(event) => submitMessage()">
|
34
60
|
<div class="form-message">
|
35
61
|
<div class="jl-inputgroup-chat">
|
@@ -46,6 +72,7 @@
|
|
46
72
|
}
|
47
73
|
"
|
48
74
|
@keyup.enter="saltoDeLineaOEnviar"
|
75
|
+
@paste="handlePaste"
|
49
76
|
/>
|
50
77
|
|
51
78
|
<input
|
@@ -84,7 +111,7 @@
|
|
84
111
|
|
85
112
|
<ODialog v-bind="dialog">
|
86
113
|
<div v-if="currentDialogView === DIALOG_VIEWS.UPLOAD" class="flex flex-col justify-center items-center">
|
87
|
-
<img v-for="(urlFile, i) in
|
114
|
+
<img v-for="(urlFile, i) in urlFilesPreview" :key="i" :src="urlFile.toString()" alt="Image" width="400" />
|
88
115
|
|
89
116
|
<form
|
90
117
|
class="message-send"
|
@@ -176,6 +203,7 @@ const notViewed = ref(0);
|
|
176
203
|
const fileInputRef = ref();
|
177
204
|
const currentDialogView = ref(DIALOG_VIEWS.SEE)
|
178
205
|
const urlFileMessage = ref<string>()
|
206
|
+
const dropZoneRef = ref<InstanceType<typeof HTMLElement>>();
|
179
207
|
|
180
208
|
const messagesData = ref<{ data: Message[]; canLoadMoreMessages: boolean }>({
|
181
209
|
data: [],
|
@@ -291,7 +319,7 @@ function createMessage(message: string, codigoTipoMensaje?: TypeMessageTypeCodes
|
|
291
319
|
createdAt: new Date().toISOString(),
|
292
320
|
updatedAt: new Date().toISOString(),
|
293
321
|
file: inputFiles.value?.[0],
|
294
|
-
urlFile:
|
322
|
+
urlFile: urlFilesPreview.value?.[0],
|
295
323
|
messageType,
|
296
324
|
sender: {
|
297
325
|
nombreCompleto: props.user.nombreCompleto,
|
@@ -583,10 +611,11 @@ function onQualifying({ message: messageParam, emoji }: { message: Message, emoj
|
|
583
611
|
|
584
612
|
const isDisabledBoxMessage = ref(false);
|
585
613
|
|
614
|
+
const tiposArchivosPermitidos = ['image/png', 'image/jpeg', 'image/jpg', 'image/webp'];
|
586
615
|
// Adjuntar
|
587
616
|
function onFileSelect() {
|
588
617
|
inputFiles.value = [];
|
589
|
-
|
618
|
+
urlFilesPreview.value = [];
|
590
619
|
|
591
620
|
const filesParam: File[] = Array.from(fileInputRef.value?.files) ?? []
|
592
621
|
|
@@ -596,7 +625,7 @@ function onFileSelect() {
|
|
596
625
|
|
597
626
|
if (!file) return;
|
598
627
|
|
599
|
-
if (!(
|
628
|
+
if (!(tiposArchivosPermitidos.includes(file.type))) {
|
600
629
|
emit('show-toast', {
|
601
630
|
severity: "warn",
|
602
631
|
summary: "Error",
|
@@ -616,10 +645,10 @@ function onFileSelect() {
|
|
616
645
|
return
|
617
646
|
}
|
618
647
|
|
619
|
-
|
648
|
+
urlFilesPreview.value.push(URL.createObjectURL(file))
|
620
649
|
|
621
650
|
currentDialogView.value = DIALOG_VIEWS.UPLOAD;
|
622
|
-
dialog.title = '
|
651
|
+
dialog.title = 'Vista previa';
|
623
652
|
dialog.modelValue = true;
|
624
653
|
|
625
654
|
nextTick(()=>{
|
@@ -627,10 +656,70 @@ function onFileSelect() {
|
|
627
656
|
})
|
628
657
|
}
|
629
658
|
|
659
|
+
|
660
|
+
const handlePaste = (e: ClipboardEvent) => {
|
661
|
+
const files = e.clipboardData?.files ?? (window as any).clipboardData?.files ?? [];
|
662
|
+
|
663
|
+
if (files.length === 0) return;
|
664
|
+
|
665
|
+
const file = files?.[0];
|
666
|
+
|
667
|
+
if (!file) return;
|
668
|
+
|
669
|
+
if (!tiposArchivosPermitidos.includes(file?.type)) return;
|
670
|
+
|
671
|
+
e.preventDefault();
|
672
|
+
currentDialogView.value = DIALOG_VIEWS.UPLOAD;
|
673
|
+
urlFilesPreview.value = [];
|
674
|
+
|
675
|
+
inputFiles.value = [file];
|
676
|
+
urlFilesPreview.value.push(URL.createObjectURL(file));
|
677
|
+
dialog.modelValue = true;
|
678
|
+
|
679
|
+
nextTick(()=>{
|
680
|
+
textAreaRef.value?.focus()
|
681
|
+
})
|
682
|
+
};
|
683
|
+
|
684
|
+
function dropHandler(ev: DragEvent) {
|
685
|
+
if (!ev.dataTransfer?.items) return;
|
686
|
+
|
687
|
+
currentDialogView.value = DIALOG_VIEWS.UPLOAD;
|
688
|
+
|
689
|
+
Array.from(ev.dataTransfer.items).forEach((item) => {
|
690
|
+
if (item.kind === 'file') {
|
691
|
+
const file = item.getAsFile();
|
692
|
+
|
693
|
+
if (!file) return;
|
694
|
+
|
695
|
+
if (!tiposArchivosPermitidos.includes(file.type)) {
|
696
|
+
emit('show-toast',{
|
697
|
+
severity: 'error',
|
698
|
+
summary: 'Error',
|
699
|
+
detail: 'El archivo debe ser una imagen',
|
700
|
+
life: 5000,
|
701
|
+
});
|
702
|
+
|
703
|
+
return;
|
704
|
+
}
|
705
|
+
|
706
|
+
inputFiles.value = [file];
|
707
|
+
|
708
|
+
urlFilesPreview.value = [];
|
709
|
+
urlFilesPreview.value.push(URL.createObjectURL(file));
|
710
|
+
dialog.modelValue = true;
|
711
|
+
}
|
712
|
+
});
|
713
|
+
|
714
|
+
nextTick(()=>{
|
715
|
+
textAreaRef.value?.focus()
|
716
|
+
})
|
717
|
+
}
|
718
|
+
|
630
719
|
// Dialog
|
631
720
|
|
632
721
|
const inputFiles = ref<File[]>([]);
|
633
|
-
const
|
722
|
+
const urlFilesPreview = ref<Array<string>>([]);
|
634
723
|
|
635
724
|
const dialog = reactive<IPropsDialog>({
|
636
725
|
modelValue: false,
|
@@ -639,7 +728,7 @@ const dialog = reactive<IPropsDialog>({
|
|
639
728
|
|
640
729
|
if (args) return;
|
641
730
|
|
642
|
-
|
731
|
+
urlFilesPreview.value = [];
|
643
732
|
inputFiles.value = [];
|
644
733
|
},
|
645
734
|
title: 'Preparar imagen'
|
@@ -690,6 +779,7 @@ onUnmounted(() => {
|
|
690
779
|
|
691
780
|
.messages-container {
|
692
781
|
position: relative;
|
782
|
+
height: 100%;
|
693
783
|
}
|
694
784
|
.loader {
|
695
785
|
position: absolute;
|
@@ -716,4 +806,8 @@ onUnmounted(() => {
|
|
716
806
|
margin: 1.5rem;
|
717
807
|
text-align: center;
|
718
808
|
}
|
809
|
+
|
810
|
+
.drop-over {
|
811
|
+
border: 2px dashed #007bff !important;
|
812
|
+
}
|
719
813
|
</style>
|