|
|
|
@ -1,52 +1,71 @@
|
|
|
|
|
<script lang="ts" setup> |
|
|
|
|
import type { CarouselApi } from '../../nc/Carousel/interface' |
|
|
|
|
import { useAttachmentCell } from './utils' |
|
|
|
|
|
|
|
|
|
const { selectedImage, visibleItems, downloadAttachment } = useAttachmentCell()! |
|
|
|
|
|
|
|
|
|
const container = ref() |
|
|
|
|
const container = ref<HTMLElement | null>(null) |
|
|
|
|
|
|
|
|
|
const emblaMainApi: CarouselApi = ref() |
|
|
|
|
const emblaThumbnailApi: CarouselApi = ref() |
|
|
|
|
const selectedIndex = ref(0) |
|
|
|
|
const selectedIndex = ref() |
|
|
|
|
|
|
|
|
|
const { getPossibleAttachmentSrc } = useAttachment() |
|
|
|
|
|
|
|
|
|
useEventListener(container, 'click', (e) => { |
|
|
|
|
if (!(e.target as HTMLElement)?.closest('.keep-open') && !(e.target as HTMLElement)?.closest('img')) { |
|
|
|
|
selectedImage.value = false |
|
|
|
|
const target = e.target as HTMLElement |
|
|
|
|
if (!target.closest('.keep-open') && !target.closest('img')) { |
|
|
|
|
selectedFile.value = false |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
function onThumbClick(index: number) { |
|
|
|
|
const onThumbClick = (index: number) => { |
|
|
|
|
if (!emblaMainApi.value || !emblaThumbnailApi.value) return |
|
|
|
|
|
|
|
|
|
emblaMainApi.value.scrollTo(index) |
|
|
|
|
emblaThumbnailApi.value.scrollTo(index) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function onSelect() { |
|
|
|
|
const onSelect = () => { |
|
|
|
|
if (!emblaMainApi.value || !emblaThumbnailApi.value) return |
|
|
|
|
selectedIndex.value = emblaMainApi.value?.selectedScrollSnap() |
|
|
|
|
selectedImage.value = visibleItems.value[emblaMainApi.value?.selectedScrollSnap()] |
|
|
|
|
emblaThumbnailApi.value.scrollTo(emblaMainApi.value.selectedScrollSnap()) |
|
|
|
|
|
|
|
|
|
const newSnap = emblaMainApi.value.selectedScrollSnap() |
|
|
|
|
|
|
|
|
|
selectedIndex.value = newSnap |
|
|
|
|
selectedFile.value = visibleItems.value[newSnap] |
|
|
|
|
emblaThumbnailApi.value.scrollTo(newSnap) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
watchOnce(emblaMainApi, (emblaMainApi) => { |
|
|
|
|
watchOnce(emblaMainApi, async (emblaMainApi) => { |
|
|
|
|
if (!emblaMainApi) return |
|
|
|
|
|
|
|
|
|
onSelect() |
|
|
|
|
emblaMainApi.on('select', onSelect) |
|
|
|
|
emblaThumbnailApi.value?.on('reInit', onSelect) |
|
|
|
|
|
|
|
|
|
emblaMainApi.on('select', onSelect) |
|
|
|
|
|
|
|
|
|
await nextTick(() => { |
|
|
|
|
if (!selectedIndex.value) { |
|
|
|
|
const newIndex = visibleItems.value.findIndex((item) => { |
|
|
|
|
if (selectedFile.value?.path) return item?.path === selectedFile.value.path |
|
|
|
|
if (selectedFile.value?.url) return item?.url === selectedFile.value.url |
|
|
|
|
return selectedFile.value?.title === item?.title |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
selectedIndex.value = newIndex |
|
|
|
|
emblaMainApi.scrollTo(newIndex) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<template> |
|
|
|
|
<GeneralOverlay v-model="selectedImage" transition :z-index="1001" class="bg-black bg-opacity-90"> |
|
|
|
|
<div v-if="selectedImage" class="flex"> |
|
|
|
|
<div ref="container" class="overflow-hidden text-center relative h-screen"> |
|
|
|
|
<GeneralOverlay v-model="selectedFile" transition :z-index="1001" class="bg-black bg-opacity-90"> |
|
|
|
|
<div v-if="selectedFile" class="flex w-full justify-center items-center"> |
|
|
|
|
<div ref="container" class="overflow-hidden w-full flex items-center justify-center text-center relative h-screen"> |
|
|
|
|
<NcButton |
|
|
|
|
class="top-5 !absolute cursor-pointer !hover:bg-transparent left-5" |
|
|
|
|
size="xsmall" |
|
|
|
|
type="text" |
|
|
|
|
@click.stop="selectedImage = false" |
|
|
|
|
@click.stop="selectedFile = false" |
|
|
|
|
> |
|
|
|
|
<component :is="iconMap.close" class="text-white" /> |
|
|
|
|
</NcButton> |
|
|
|
@ -59,7 +78,7 @@ watchOnce(emblaMainApi, (emblaMainApi) => {
|
|
|
|
|
class="hover:underline pointer-events-auto font-semibold cursor-pointer text-white" |
|
|
|
|
@click.stop="downloadAttachment(selectedImage)" |
|
|
|
|
> |
|
|
|
|
{{ selectedImage && selectedImage.title }} |
|
|
|
|
{{ selectedFile && selectedFile.title }} |
|
|
|
|
</h3> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
@ -67,35 +86,50 @@ watchOnce(emblaMainApi, (emblaMainApi) => {
|
|
|
|
|
<NcCarouselContent> |
|
|
|
|
<NcCarouselItem v-for="(item, index) in visibleItems" :key="index"> |
|
|
|
|
<LazyCellAttachmentImage |
|
|
|
|
class="nc-attachment-img-wrapper !h-[80%]" |
|
|
|
|
v-if="isImage(item.title, item.mimeType)" |
|
|
|
|
class="nc-attachment-img-wrapper !h-[60%]" |
|
|
|
|
object-fit="contain" |
|
|
|
|
:alt="item.title" |
|
|
|
|
:srcs="getPossibleAttachmentSrc(item)" |
|
|
|
|
/> |
|
|
|
|
|
|
|
|
|
<LazyCellAttachmentVideo |
|
|
|
|
v-else-if="isVideo(item.title, item.mimeType)" |
|
|
|
|
class="!h-[60%]" |
|
|
|
|
:alt="item.title" |
|
|
|
|
:srcs="getPossibleAttachmentSrc(item)" |
|
|
|
|
/> |
|
|
|
|
</NcCarouselItem> |
|
|
|
|
</NcCarouselContent> |
|
|
|
|
<NcCarouselPrevious size="small" class="!top-5/12 z-20 !left-8 !absolute" /> |
|
|
|
|
<NcCarouselNext size="small" class="!top-5/12 z-20 !right-8 !absolute" /> |
|
|
|
|
</NcCarousel> |
|
|
|
|
|
|
|
|
|
<div class="absolute !w-screen !bottom-5 max-h-18 z-30 flex items-center justify-center inset-x-0"> |
|
|
|
|
<div class="absolute w-full !bottom-5 max-h-18 z-30 flex items-center justify-center"> |
|
|
|
|
<NcCarousel class="absolute max-w-sm" @init-api="(val) => (emblaThumbnailApi = val)"> |
|
|
|
|
<NcCarouselContent class="!flex !gap-3 ml-0"> |
|
|
|
|
<NcCarouselContent class="!flex !gap-2 ml-0"> |
|
|
|
|
<NcCarouselItem |
|
|
|
|
v-for="(item, index) in visibleItems" |
|
|
|
|
:key="index" |
|
|
|
|
:class="{ |
|
|
|
|
'nc-active-attachment': index === selectedIndex, |
|
|
|
|
' opacity-100': index === selectedIndex, |
|
|
|
|
}" |
|
|
|
|
class="pl-0 opacity-50 !basis-1/4 cursor-pointer" |
|
|
|
|
class="px-2 keep-open opacity-50 !basis-1/8 cursor-pointer" |
|
|
|
|
@click="onThumbClick(index)" |
|
|
|
|
> |
|
|
|
|
<LazyCellAttachmentImage |
|
|
|
|
class="nc-attachment-img-wrapper" |
|
|
|
|
object-fit="contain" |
|
|
|
|
:alt="item.title" |
|
|
|
|
:srcs="getPossibleAttachmentSrc(item)" |
|
|
|
|
/> |
|
|
|
|
<div class="flex items-center justify-center"> |
|
|
|
|
<LazyCellAttachmentImage |
|
|
|
|
v-if="isImage(item.title, item.mimeType)" |
|
|
|
|
class="nc-attachment-img-wrapper h-12" |
|
|
|
|
object-fit="contain" |
|
|
|
|
:alt="item.title" |
|
|
|
|
:srcs="getPossibleAttachmentSrc(item)" |
|
|
|
|
/> |
|
|
|
|
<div |
|
|
|
|
v-else-if="isVideo(item.title, item.mimeType)" |
|
|
|
|
class="h-full flex items-center h-6 justify-center rounded-md px-2 py-1 border-1 border-gray-200" |
|
|
|
|
> |
|
|
|
|
<GeneralIcon class="text-white" icon="play" /> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</NcCarouselItem> |
|
|
|
|
</NcCarouselContent> |
|
|
|
|
</NcCarousel> |
|
|
|
@ -109,8 +143,4 @@ watchOnce(emblaMainApi, (emblaMainApi) => {
|
|
|
|
|
.nc-attachment-img-wrapper { |
|
|
|
|
width: fit-content !important; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.nc-active-attachment { |
|
|
|
|
@apply transform opacity-100 scale-110 transition-transform; |
|
|
|
|
} |
|
|
|
|
</style> |
|
|
|
|