π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat: add PDF thumbnail preview support across gallery, kanban and attachment views
DarkPhoenix27048640b845fd3c
diff --git a/packages/nc-gui/components/cell/attachment/Card.vue b/packages/nc-gui/components/cell/attachment/Card.vueindex 36eb8e4a01..4761c05e71 100644--- a/packages/nc-gui/components/cell/attachment/Card.vue+++ b/packages/nc-gui/components/cell/attachment/Card.vue@@ -110,6 +110,13 @@ const handleFileDeleteStart = () => {class="!w-full !m-0 rounded-t-[5px] justify-center":class="previewClassOverride ? `${previewClassOverride}` : ''"/>+ <LazyCellAttachmentPreviewPdfThumbnail+ v-else-if="isPdf(attachment.title, attachment.mimetype)"+ :srcs="getPossibleAttachmentSrc(attachment, 'card_cover')"+ object-fit="contain"+ class="!w-full !m-0 rounded-t-[5px] justify-center"+ :class="previewClassOverride ? `${previewClassOverride}` : ''"+ /><GeneralIconv-else-if="isAudio(attachment.title, attachment.mimetype)"class="text-white"diff --git a/packages/nc-gui/components/cell/attachment/Carousel.vue b/packages/nc-gui/components/cell/attachment/Carousel.vueindex c51308d251..cfb5aa9794 100644--- a/packages/nc-gui/components/cell/attachment/Carousel.vue+++ b/packages/nc-gui/components/cell/attachment/Carousel.vue@@ -278,6 +278,15 @@ const initEmblaApi = (val: any) => {:srcs="getPossibleAttachmentSrc(item, 'tiny')"@error="triggerReload"/>+ <LazyCellAttachmentPreviewPdfThumbnail+ v-else-if="isPdf(item.title, item.mimetype)"+ class="nc-attachment-img-wrapper h-12"+ object-fit="contain"+ controls+ :alt="item.title"+ :srcs="getPossibleAttachmentSrc(item, 'tiny')"+ @error="triggerReload"+ /><divv-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"@@ -292,13 +301,6 @@ const initEmblaApi = (val: any) => {<GeneralIcon class="text-white" icon="ncVolume2" /></div>- <div- v-else-if="isPdf(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="pdfFile" />- </div>-<div v-else 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="file" /></div>diff --git a/packages/nc-gui/components/cell/attachment/Preview/PdfThumbnail.vue b/packages/nc-gui/components/cell/attachment/Preview/PdfThumbnail.vuenew file mode 100644index 0000000000..ae85f04b56--- /dev/null+++ b/packages/nc-gui/components/cell/attachment/Preview/PdfThumbnail.vue@@ -0,0 +1,54 @@+<script setup lang="ts">+import { useEventListener } from '@vueuse/core'++interface Props {+ srcs: string[]+ alt?: string+ objectFit?: string+ isCellPreview?: boolean+ imageClass?: string+}++const props = withDefaults(defineProps<Props>(), {+ isCellPreview: true,+ imageClass: '',+})+const emit = defineEmits(['error'])++const index = ref(0)++const onError = async () => {+ index.value+++ if (index.value >= props.srcs.length) {+ const isURLExp = await isURLExpired(props.srcs[0])+ if (isURLExp.isExpired) {+ emit('error')+ }+ }+}++</script>++<template>+ <div class="relative h-full w-full">+ <div+ ref="containerRef"+ class="h-full w-full overflow-hidden"+ :class="{+ 'flex items-center justify-center': index >= props.srcs?.length,+ }"+ >+ <img+ v-if="index < props.srcs?.length"+ ref="imageRef"+ :src="props.srcs[index]"+ :alt="props?.alt || ''"+ :class="[imageClass, { '!object-contain': props.objectFit === 'contain' }]"+ class="m-auto h-full max-h-full w-auto nc-attachment-image object-cover origin-center"+ loading="lazy"+ @error="onError"+ />+ <GeneralIcon v-else icon="ncFileTypePdf" class="flex-none w-6" />+ </div>+ </div>+</template>diff --git a/packages/nc-gui/components/cell/attachment/index.vue b/packages/nc-gui/components/cell/attachment/index.vueindex afd3451e64..df4fbbce7f 100644--- a/packages/nc-gui/components/cell/attachment/index.vue+++ b/packages/nc-gui/components/cell/attachment/index.vue@@ -477,6 +477,14 @@ onUnmounted(() => {:srcs="getPossibleAttachmentSrc(item, attachmentSize)"@click="() => onFileClick(item)"/>+ <LazyCellAttachmentPreviewPdfThumbnail+ v-else-if="isPdf(item.title, item.mimetype ?? item.type)"+ :alt="item.title || `#${i}`"+ object-fit="contain"+ class="nc-attachment rounded-lg w-full h-full object-cover overflow-hidden"+ :srcs="getPossibleAttachmentSrc(item, attachmentSize)"+ @click="() => onFileClick(item)"+ /><div v-else class="nc-attachment h-full w-full flex items-center justify-center" @click="onFileClick(item)"><CellAttachmentIconView :item="item" class="max-h-full max-w-full" /></div>diff --git a/packages/nc-gui/components/smartsheet/Gallery.vue b/packages/nc-gui/components/smartsheet/Gallery.vueindex 741ccaca77..fa49e55cb2 100644--- a/packages/nc-gui/components/smartsheet/Gallery.vue+++ b/packages/nc-gui/components/smartsheet/Gallery.vue@@ -494,6 +494,15 @@ const handleOpenNewRecordForm = () => {:srcs="getPossibleAttachmentSrc(attachment, 'card_cover')"@click="expandFormClick($event, record)"/>+ <LazyCellAttachmentPreviewPdfThumbnail+ v-else-if="isPdf(attachment.title, attachment.mimetype ?? attachment.type)"+ :key="`carousel-pdf-${record.rowMeta.rowIndex}-${index}`"+ class="h-52"+ image-class="!w-full"+ :object-fit="coverImageObjectFitStyle"+ :srcs="getPossibleAttachmentSrc(attachment, 'card_cover')"+ @click="expandFormClick($event, record)"+ /></template></a-carousel><divdiff --git a/packages/nc-gui/components/smartsheet/Kanban.vue b/packages/nc-gui/components/smartsheet/Kanban.vueindex 00182066ac..691efe94da 100644--- a/packages/nc-gui/components/smartsheet/Kanban.vue+++ b/packages/nc-gui/components/smartsheet/Kanban.vue@@ -868,6 +868,14 @@ const handleOpenNewRecordForm = (stackTitle?: string) => {:object-fit="coverImageObjectFitStyle":srcs="getPossibleAttachmentSrc(attachment, 'card_cover')"/>+ <LazyCellAttachmentPreviewPdfThumbnail+ v-else-if="isPdf(attachment.title, attachment.mimetype ?? attachment.type)"+ :key="`pdf-${attachment.path}`"+ class="h-52"+ image-class="!w-full"+ :object-fit="coverImageObjectFitStyle"+ :srcs="getPossibleAttachmentSrc(attachment, 'card_cover')"+ /></template></a-carousel></template>