π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix: simplify ui handling for attachment thumbnails
DarkPhoenix2704a7eb41bd19f1
diff --git a/packages/nc-gui/components/cell/attachment/Card.vue b/packages/nc-gui/components/cell/attachment/Card.vueindex 4761c05e71..c7058a816e 100644--- a/packages/nc-gui/components/cell/attachment/Card.vue+++ b/packages/nc-gui/components/cell/attachment/Card.vue@@ -35,8 +35,7 @@ const emits = defineEmits<{const isSelected = useVModel(props, 'selected', emits)const isDragging = useVModel(props, 'dragging', emits)-const { getPossibleAttachmentSrc } = useAttachment()-const { FileIcon, downloadAttachment, renameFileInline, renameFile, removeFile, isEditAllowed } = useAttachmentCell()!+const { downloadAttachment, renameFileInline, renameFile, removeFile, isEditAllowed } = useAttachmentCell()!const isRenamingFile = ref(false)const renameTitle = ref('')@@ -103,41 +102,12 @@ const handleFileDeleteStart = () => {class="nc-attachment h-full flex justify-center items-center overflow-hidden"@click.stop="emits('clicked')">- <LazyCellAttachmentPreviewImage- v-if="isImage(attachment.title, attachment.mimetype)"- :srcs="getPossibleAttachmentSrc(attachment, 'card_cover')"- object-fit="contain"- class="!w-full !m-0 rounded-t-[5px] justify-center"+ <LazyCellAttachmentPreviewThumbnail+ :attachment="attachment"+ thumbnail="card_cover":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}` : ''"- />- <GeneralIcon- v-else-if="isAudio(attachment.title, attachment.mimetype)"- class="text-white"- icon="ncFileTypeAudio"- :height="45"- :width="45"- />- <GeneralIcon- v-else-if="isVideo(attachment.title, attachment.mimetype)"- class="text-white"- icon="ncFileTypeVideo"- :height="45"- :width="45"- />- <component :is="FileIcon(attachment.icon)" v-else-if="attachment.icon" :height="45" :width="45" class="text-white" />- <GeneralIcon- v-else- :icon="getAttachmentIcon(attachment.title, attachment.mimetype)"- :height="45"- :width="45"- class="text-white"/></div>diff --git a/packages/nc-gui/components/cell/attachment/Carousel.vue b/packages/nc-gui/components/cell/attachment/Carousel.vueindex cfb5aa9794..722e68351b 100644--- a/packages/nc-gui/components/cell/attachment/Carousel.vue+++ b/packages/nc-gui/components/cell/attachment/Carousel.vue@@ -270,40 +270,14 @@ const initEmblaApi = (val: any) => {@click="onThumbClick(index)"><div class="flex items-center justify-center">- <LazyCellAttachmentPreviewImage- v-if="isImage(item.title, item.mimetype)"+ <LazyCellAttachmentPreviewThumbnailclass="nc-attachment-img-wrapper h-12"+ :attachment="item"+ thumbnail="tiny"object-fit="contain":alt="item.title"- :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"- />- <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- v-else-if="isAudio(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="ncVolume2" />- </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></div></NcCarouselItem></NcCarouselContent>diff --git a/packages/nc-gui/components/cell/attachment/Preview/PdfThumbnail.vue b/packages/nc-gui/components/cell/attachment/Preview/PdfThumbnail.vuedeleted file mode 100644index ae85f04b56..0000000000--- a/packages/nc-gui/components/cell/attachment/Preview/PdfThumbnail.vue+++ /dev/null@@ -1,54 +0,0 @@-<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/Preview/Thumbnail.vue b/packages/nc-gui/components/cell/attachment/Preview/Thumbnail.vuenew file mode 100644index 0000000000..7a63d87657--- /dev/null+++ b/packages/nc-gui/components/cell/attachment/Preview/Thumbnail.vue@@ -0,0 +1,147 @@+<script setup lang="ts">+import MdiPdfBox from '~icons/nc-icons-v2/file-type-pdf'+import MdiFileWordOutline from '~icons/nc-icons-v2/file-type-word'+import MdiFilePowerpointBox from '~icons/nc-icons-v2/file-type-presentation'+import MdiFileExcelOutline from '~icons/nc-icons-v2/file-type-csv'+import IcOutlineInsertDriveFile from '~icons/nc-icons-v2/file-type-unknown'++interface Props {+ alt?: string+ objectFit?: string+ isCellPreview?: boolean+ imageClass?: string+ thumbnail?: 'card_cover' | 'tiny' | 'small'+ attachment: Record<string, any>+ iconWidth?: number+ iconHeight?: number+}++const props = withDefaults(defineProps<Props>(), {+ isCellPreview: true,+ imageClass: '',+ iconWidth: 45,+ iconHeight: 45,+})++const emit = defineEmits(['error'])++const { getPossibleAttachmentSrc } = useAttachment()++const FileIcon = (icon: string) => {+ switch (icon) {+ case 'mdi-pdf-box':+ return MdiPdfBox+ case 'mdi-file-word-outline':+ return MdiFileWordOutline+ case 'mdi-file-powerpoint-box':+ return MdiFilePowerpointBox+ case 'mdi-file-excel-outline':+ return MdiFileExcelOutline+ default:+ return IcOutlineInsertDriveFile+ }+}++const srcs = computed(() => {+ return getPossibleAttachmentSrc(props.attachment, props.thumbnail)+})++const index = ref(0)++const onError = async () => {+ index.value+++ if (index.value >= srcs.value.length) {+ const isURLExp = await isURLExpired(srcs.value[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 >= srcs?.length,+ }"+ >+ <img+ v-if="index < srcs?.length"+ ref="imageRef"+ :src="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-if="isImage(attachment.title, attachment.mimetype)"+ class="text-white"+ icon="ncFileTypeImage"+ :height="iconHeight"+ :width="iconWidth"+ />++ <GeneralIcon+ v-else-if="isPdf(attachment.title, attachment.mimetype)"+ class="text-white"+ icon="ncFileTypePdf"+ :height="iconHeight"+ :width="iconWidth"+ />++ <GeneralIcon+ v-else-if="isAudio(attachment.title, attachment.mimetype)"+ class="text-white"+ icon="ncFileTypeAudio"+ :height="iconHeight"+ :width="iconWidth"+ />+ <GeneralIcon+ v-else-if="isVideo(attachment.title, attachment.mimetype)"+ class="text-white"+ icon="ncFileTypeVideo"+ :height="iconHeight"+ :width="iconWidth"+ />++ <GeneralIcon+ v-else-if="isWord(attachment.title, attachment.mimetype)"+ class="text-white"+ icon="ncFileTypeWord"+ :height="iconHeight"+ :width="iconWidth"+ />+ <GeneralIcon+ v-else-if="isExcel(attachment.title, attachment.mimetype)"+ class="text-white"+ icon="ncFileTypeCsv"+ :height="iconHeight"+ :width="iconWidth"+ />++ <GeneralIcon+ v-else-if="isPresentation(attachment.title, attachment.mimetype)"+ class="text-white"+ icon="ncFileTypePresentation"+ :height="iconHeight"+ :width="iconWidth"+ />+ <GeneralIcon+ v-else-if="isZip(attachment.title, attachment.mimetype)"+ class="text-white"+ icon="ncFileTypeZip"+ :height="iconHeight"+ :width="iconWidth"+ />+ <component :is="FileIcon(attachment.icon)" v-else-if="attachment.icon" :height="iconHeight" :width="iconWidth" class="text-white" />++ <GeneralIcon v-else icon="ncFileTypeUnknown" :height="iconHeight" :width="iconWidth" class="text-white" />+ </div>+ </div>+</template>diff --git a/packages/nc-gui/components/cell/attachment/index.vue b/packages/nc-gui/components/cell/attachment/index.vueindex df4fbbce7f..02ae4bf2ad 100644--- a/packages/nc-gui/components/cell/attachment/index.vue+++ b/packages/nc-gui/components/cell/attachment/index.vue@@ -48,8 +48,6 @@ const cellEventHook = inject(CellEventHookInj, null)const { isMobileMode } = useGlobal()-const { getPossibleAttachmentSrc } = useAttachment()-const {isPublic,isForm,@@ -469,25 +467,16 @@ onUnmounted(() => {'h-[64px]': rowHeight === 4 || rowHeight === 6,}">- <LazyCellAttachmentPreviewImage- v-if="isImage(item.title, item.mimetype ?? item.type)"- :alt="item.title || `#${i}`"- object-fit="contain"+ <LazyCellAttachmentPreviewThumbnail+ icon-width="24"+ icon-height="24"class="nc-attachment rounded-lg w-full h-full object-cover overflow-hidden"- :srcs="getPossibleAttachmentSrc(item, attachmentSize)"- @click="() => onFileClick(item)"- />- <LazyCellAttachmentPreviewPdfThumbnail- v-else-if="isPdf(item.title, item.mimetype ?? item.type)":alt="item.title || `#${i}`"+ :attachment="item"+ thumbnail="tiny"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></div></NcTooltip></div>diff --git a/packages/nc-gui/components/smartsheet/Gallery.vue b/packages/nc-gui/components/smartsheet/Gallery.vueindex fa49e55cb2..0e05d1ddd4 100644--- a/packages/nc-gui/components/smartsheet/Gallery.vue+++ b/packages/nc-gui/components/smartsheet/Gallery.vue@@ -17,7 +17,6 @@ const { isViewDataLoading } = storeToRefs(useViewsStore())const { isSqlView, xWhere, isExternalSource, isSyncedTable } = useSmartsheetStoreOrThrow()const { isUIAllowed } = useRoles()const route = useRoute()-const { getPossibleAttachmentSrc } = useAttachment()const router = useRouter()const { showRecordPlanLimitExceededModal, blockExternalSourceRecordVisibility, showAsBluredRecord } = useEeConfig()@@ -484,23 +483,16 @@ const handleOpenNewRecordForm = () => {</NcButton></div></template>- <template v-for="(attachment, index) in attachments(record)">- <LazyCellAttachmentPreviewImage- v-if="isImage(attachment.title, attachment.mimetype ?? attachment.type)"- :key="`carousel-${record.rowMeta.rowIndex}-${index}`"- class="h-52"- image-class="!w-full"- :object-fit="coverImageObjectFitStyle"- :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}`"+ <template+ v-for="(attachment, index) in attachments(record)"+ :key="`carousel-${record.rowMeta.rowIndex}-${index}`"+ >+ <LazyCellAttachmentPreviewThumbnail+ :attachment="attachment"class="h-52"+ thumbnail="card_cover"image-class="!w-full":object-fit="coverImageObjectFitStyle"- :srcs="getPossibleAttachmentSrc(attachment, 'card_cover')"@click="expandFormClick($event, record)"/></template>diff --git a/packages/nc-gui/components/smartsheet/Kanban.vue b/packages/nc-gui/components/smartsheet/Kanban.vueindex 691efe94da..c3bc4d222e 100644--- a/packages/nc-gui/components/smartsheet/Kanban.vue+++ b/packages/nc-gui/components/smartsheet/Kanban.vue@@ -45,8 +45,6 @@ const router = useRouter()const route = router.currentRoute-const { getPossibleAttachmentSrc } = useAttachment()-const { metaColumnById } = useViewColumnsOrThrow(view, meta)const { isSyncedTable } = useSmartsheetStoreOrThrow()@@ -859,22 +857,14 @@ const handleOpenNewRecordForm = (stackTitle?: string) => {</div></template>- <template v-for="attachment in attachments(record)">- <LazyCellAttachmentPreviewImage- v-if="isImage(attachment.title, attachment.mimetype ?? attachment.type)"- :key="attachment.path"- class="h-52"- image-class="!w-full"- :object-fit="coverImageObjectFitStyle"- :srcs="getPossibleAttachmentSrc(attachment, 'card_cover')"- />- <LazyCellAttachmentPreviewPdfThumbnail- v-else-if="isPdf(attachment.title, attachment.mimetype ?? attachment.type)"- :key="`pdf-${attachment.path}`"+ <template v-for="attachment in attachments(record)" :key="attachment.path">+ <LazyCellAttachmentPreviewThumbnail+ :attachment="attachment"class="h-52"image-class="!w-full"+ thumbnail="card_cover":object-fit="coverImageObjectFitStyle"- :srcs="getPossibleAttachmentSrc(attachment, 'card_cover')"+ @click="expandFormClick($event, record)"/></template></a-carousel>