mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
222 lines
6.3 KiB
222 lines
6.3 KiB
2 years ago
|
<script lang="ts" setup>
|
||
|
import { onKeyDown } from '@vueuse/core'
|
||
|
import { useAttachmentCell } from './utils'
|
||
2 years ago
|
import { useSortable } from './sort'
|
||
2 years ago
|
import { isImage, openLink, ref, useDropZone, useUIPermission, watch } from '#imports'
|
||
2 years ago
|
|
||
|
const { isUIAllowed } = useUIPermission()
|
||
|
|
||
2 years ago
|
const {
|
||
|
open,
|
||
|
isLoading,
|
||
|
isPublicGrid,
|
||
2 years ago
|
isReadonly,
|
||
2 years ago
|
visibleItems,
|
||
|
modalVisible,
|
||
|
column,
|
||
|
FileIcon,
|
||
|
removeFile,
|
||
|
onDrop,
|
||
|
downloadFile,
|
||
|
updateModelValue,
|
||
2 years ago
|
selectedImage,
|
||
2 years ago
|
} = useAttachmentCell()!
|
||
2 years ago
|
|
||
|
// todo: replace placeholder var
|
||
|
const isLocked = ref(false)
|
||
|
|
||
2 years ago
|
const dropZoneRef = ref<HTMLDivElement>()
|
||
2 years ago
|
|
||
2 years ago
|
const sortableRef = ref<HTMLDivElement>()
|
||
|
|
||
2 years ago
|
const { dragging } = useSortable(sortableRef, visibleItems, updateModelValue, isReadonly)
|
||
2 years ago
|
|
||
2 years ago
|
const { isOverDropZone } = useDropZone(dropZoneRef, onDrop)
|
||
|
|
||
2 years ago
|
const { isSharedForm } = useSmartsheetStoreOrThrow()
|
||
|
|
||
2 years ago
|
onKeyDown('Escape', () => {
|
||
|
modalVisible.value = false
|
||
|
isOverDropZone.value = false
|
||
|
})
|
||
2 years ago
|
|
||
|
function onClick(item: Record<string, any>) {
|
||
|
selectedImage.value = item
|
||
|
modalVisible.value = false
|
||
|
|
||
|
const stopHandle = watch(selectedImage, (nextImage, _, onCleanup) => {
|
||
|
if (!nextImage) {
|
||
|
setTimeout(() => {
|
||
|
modalVisible.value = true
|
||
|
}, 50)
|
||
|
stopHandle?.()
|
||
|
}
|
||
|
|
||
|
onCleanup(() => stopHandle?.())
|
||
|
})
|
||
|
}
|
||
2 years ago
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<a-modal v-model:visible="modalVisible" class="nc-attachment-modal" width="80%" :footer="null">
|
||
2 years ago
|
<template #title>
|
||
|
<div class="flex gap-4">
|
||
|
<div
|
||
2 years ago
|
v-if="isSharedForm || (!isReadonly && isUIAllowed('tableAttachment') && !isPublicGrid && !isLocked)"
|
||
2 years ago
|
class="nc-attach-file group"
|
||
|
@click="open"
|
||
|
>
|
||
2 years ago
|
<MaterialSymbolsAttachFile class="transform group-hover:(text-accent scale-120)" />
|
||
2 years ago
|
Attach File
|
||
|
</div>
|
||
|
|
||
|
<div class="flex items-center gap-2">
|
||
2 years ago
|
<div v-if="isReadonly" class="text-gray-400">[Readonly]</div>
|
||
2 years ago
|
Viewing Attachments of
|
||
|
<div class="font-semibold underline">{{ column.title }}</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
2 years ago
|
<div ref="dropZoneRef">
|
||
2 years ago
|
<template v-if="isSharedForm || (!isReadonly && !dragging)">
|
||
2 years ago
|
<general-overlay
|
||
|
v-model="isOverDropZone"
|
||
|
inline
|
||
2 years ago
|
class="text-white ring ring-accent bg-gray-700/75 flex items-center justify-center gap-2 backdrop-blur-xl"
|
||
2 years ago
|
>
|
||
2 years ago
|
<MaterialSymbolsFileCopyOutline class="text-accent" height="35" width="35" />
|
||
2 years ago
|
<div class="text-white text-3xl">Drop here</div>
|
||
|
</general-overlay>
|
||
|
</template>
|
||
2 years ago
|
|
||
2 years ago
|
<div ref="sortableRef" :class="{ dragging }" class="grid grid-cols-2 md:grid-cols-3 xl:grid-cols-4 gap-6 relative p-6">
|
||
2 years ago
|
<div v-for="(item, i) of visibleItems" :key="`${item.title}-${i}`" class="flex flex-col gap-1">
|
||
|
<a-card class="nc-attachment-item group">
|
||
2 years ago
|
<a-tooltip v-if="!isReadonly">
|
||
2 years ago
|
<template #title> Remove File </template>
|
||
|
<MdiCloseCircle
|
||
2 years ago
|
v-if="isSharedForm || (isUIAllowed('tableAttachment') && !isPublicGrid && !isLocked)"
|
||
2 years ago
|
class="nc-attachment-remove"
|
||
|
@click.stop="removeFile(i)"
|
||
|
/>
|
||
|
</a-tooltip>
|
||
|
|
||
|
<a-tooltip placement="bottom">
|
||
|
<template #title> Download file </template>
|
||
|
|
||
|
<div class="nc-attachment-download group-hover:(opacity-100)">
|
||
|
<MdiDownload @click.stop="downloadFile(item)" />
|
||
|
</div>
|
||
|
</a-tooltip>
|
||
|
|
||
2 years ago
|
<div
|
||
|
:class="[dragging ? 'cursor-move' : 'cursor-pointer']"
|
||
|
class="nc-attachment h-full w-full flex items-center justify-center"
|
||
|
>
|
||
2 years ago
|
<div
|
||
|
v-if="isImage(item.title, item.mimetype)"
|
||
2 years ago
|
:style="{ backgroundImage: `url('${item.url || item.data}')` }"
|
||
2 years ago
|
class="w-full h-full bg-contain bg-center bg-no-repeat"
|
||
2 years ago
|
@click.stop="onClick(item)"
|
||
2 years ago
|
/>
|
||
2 years ago
|
|
||
|
<component
|
||
|
:is="FileIcon(item.icon)"
|
||
|
v-else-if="item.icon"
|
||
|
height="150"
|
||
|
width="150"
|
||
|
@click.stop="openLink(item.url || item.data)"
|
||
|
/>
|
||
|
|
||
|
<IcOutlineInsertDriveFile v-else height="150" width="150" @click.stop="openLink(item.url || item.data)" />
|
||
2 years ago
|
</div>
|
||
2 years ago
|
</a-card>
|
||
2 years ago
|
|
||
2 years ago
|
<div class="truncate" :title="item.title">
|
||
|
{{ item.title }}
|
||
2 years ago
|
</div>
|
||
|
</div>
|
||
2 years ago
|
|
||
|
<div v-if="isLoading" class="flex flex-col gap-1">
|
||
|
<a-card class="nc-attachment-item group">
|
||
|
<div class="nc-attachment h-full w-full flex items-center justify-center">
|
||
|
<a-skeleton-image class />
|
||
|
</div>
|
||
|
</a-card>
|
||
|
</div>
|
||
2 years ago
|
</div>
|
||
|
</div>
|
||
|
</a-modal>
|
||
|
</template>
|
||
|
|
||
2 years ago
|
<style lang="scss">
|
||
|
.nc-attachment-modal {
|
||
|
.nc-attach-file {
|
||
|
@apply select-none cursor-pointer color-transition flex items-center gap-1 border-1 p-2 rounded
|
||
2 years ago
|
@apply hover:(bg-primary bg-opacity-10 text-primary ring);
|
||
2 years ago
|
@apply active:(ring-accent bg-primary bg-opacity-20);
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
.nc-attachment-item {
|
||
2 years ago
|
@apply !h-2/3 !min-h-[200px] flex items-center justify-center relative;
|
||
|
|
||
|
@supports (-moz-appearance: none) {
|
||
|
@apply hover:border-0;
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
&::after {
|
||
|
@apply pointer-events-none rounded absolute top-0 left-0 right-0 bottom-0 transition-all duration-150 ease-in-out;
|
||
|
content: '';
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
@supports (-moz-appearance: none) {
|
||
|
&:hover::after {
|
||
|
@apply ring shadow transform scale-103;
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
&:active::after {
|
||
2 years ago
|
@apply ring ring-accent shadow transform scale-103;
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
.nc-attachment-download {
|
||
2 years ago
|
@apply bg-white absolute bottom-2 right-2;
|
||
2 years ago
|
@apply transition-opacity duration-150 ease-in opacity-0 hover:ring;
|
||
|
@apply cursor-pointer rounded shadow flex items-center p-1 border-1;
|
||
2 years ago
|
@apply active:(ring border-0 ring-accent);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
.nc-attachment-remove {
|
||
2 years ago
|
@apply absolute top-2 right-2 bg-white;
|
||
2 years ago
|
@apply hover:(ring ring-red-500);
|
||
2 years ago
|
@apply cursor-pointer rounded-full border-2;
|
||
2 years ago
|
@apply active:(ring border-0 ring-red-500);
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
.ant-card-body {
|
||
2 years ago
|
@apply !p-2 w-full h-full;
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
.ant-modal-body {
|
||
|
@apply !p-0;
|
||
|
}
|
||
2 years ago
|
|
||
|
.ghost,
|
||
|
.ghost > * {
|
||
|
@apply !pointer-events-none;
|
||
|
}
|
||
|
|
||
2 years ago
|
.dragging {
|
||
|
.nc-attachment-item {
|
||
|
@apply !pointer-events-none;
|
||
|
}
|
||
|
|
||
2 years ago
|
.ant-tooltip {
|
||
|
@apply !hidden;
|
||
|
}
|
||
|
}
|
||
2 years ago
|
}
|
||
|
</style>
|