diff --git a/packages/nc-gui-v2/components.d.ts b/packages/nc-gui-v2/components.d.ts index d0e6800cef..9d7df38fcc 100644 --- a/packages/nc-gui-v2/components.d.ts +++ b/packages/nc-gui-v2/components.d.ts @@ -11,6 +11,7 @@ declare module '@vue/runtime-core' { AAutoComplete: typeof import('ant-design-vue/es')['AutoComplete'] AButton: typeof import('ant-design-vue/es')['Button'] ACard: typeof import('ant-design-vue/es')['Card'] + ACarousel: typeof import('ant-design-vue/es')['Carousel'] ACheckbox: typeof import('ant-design-vue/es')['Checkbox'] ACol: typeof import('ant-design-vue/es')['Col'] ACollapse: typeof import('ant-design-vue/es')['Collapse'] diff --git a/packages/nc-gui-v2/components/cell/attachment/Carousel.vue b/packages/nc-gui-v2/components/cell/attachment/Carousel.vue new file mode 100644 index 0000000000..2274b1e9e3 --- /dev/null +++ b/packages/nc-gui-v2/components/cell/attachment/Carousel.vue @@ -0,0 +1,128 @@ + + + + + + + + + + + + {{ selectedImage && selectedImage.title }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/nc-gui-v2/components/cell/attachment/Modal.vue b/packages/nc-gui-v2/components/cell/attachment/Modal.vue index ae02af9b77..da5295b52f 100644 --- a/packages/nc-gui-v2/components/cell/attachment/Modal.vue +++ b/packages/nc-gui-v2/components/cell/attachment/Modal.vue @@ -25,7 +25,7 @@ const { onDrop, downloadFile, updateModelValue, -} = useAttachmentCell() +} = useAttachmentCell()! // todo: replace placeholder var const isLocked = ref(false) diff --git a/packages/nc-gui-v2/components/cell/attachment/index.vue b/packages/nc-gui-v2/components/cell/attachment/index.vue index 8aa198833f..3249a552a0 100644 --- a/packages/nc-gui-v2/components/cell/attachment/index.vue +++ b/packages/nc-gui-v2/components/cell/attachment/index.vue @@ -2,6 +2,7 @@ import { useProvideAttachmentCell } from './utils' import Modal from './Modal.vue' import { useSortable } from './sort' +import Carousel from './Carousel.vue' import { ref, useDropZone, watch } from '#imports' import { isImage, openLink } from '~/utils' import MaterialSymbolsAttachFile from '~icons/material-symbols/attach-file' @@ -26,7 +27,8 @@ const dropZoneRef = ref() const sortableRef = ref() -const { modalVisible, attachments, visibleItems, onDrop, isLoading, open, FileIcon } = useProvideAttachmentCell(updateModelValue) +const { modalVisible, attachments, visibleItems, onDrop, isLoading, open, FileIcon, selectedImage } = + useProvideAttachmentCell(updateModelValue) const { dragging } = useSortable(sortableRef, visibleItems, updateModelValue) @@ -43,17 +45,18 @@ watch( ) function updateModelValue(data: string | Record) { - console.log(data) emits('update:modelValue', typeof data !== 'string' ? JSON.stringify(data) : data) } -const selectImage = (file: any, i: unknown) => { - // todo: implement +const selectImage = (file: any) => { + selectedImage.value = file } + + { v-if="isImage(item.title, item.mimetype)" :alt="item.title || `#${i}`" :src="item.url || item.data" - @click="selectImage(item.url || item.data, i)" + @click="selectImage(item)" /> diff --git a/packages/nc-gui-v2/components/cell/attachment/sort.ts b/packages/nc-gui-v2/components/cell/attachment/sort.ts index c7985cc2bc..80cf19fb46 100644 --- a/packages/nc-gui-v2/components/cell/attachment/sort.ts +++ b/packages/nc-gui-v2/components/cell/attachment/sort.ts @@ -39,8 +39,6 @@ export function useSortable( // todo: replace with vuedraggable const initSortable = (el: HTMLElement) => { - if (sortable) sortable.destroy() - sortable = new Sortable(el, { handle: '.nc-attachment', ghostClass: 'ghost', @@ -50,11 +48,12 @@ export function useSortable( } watchPostEffect((onCleanup) => { + const _element = unref(element) + onCleanup(() => { - if (sortable) sortable.destroy() + if (_element && sortable) sortable.destroy() }) - const _element = unref(element) if (_element) initSortable(_element) }) diff --git a/packages/nc-gui-v2/components/cell/attachment/utils.ts b/packages/nc-gui-v2/components/cell/attachment/utils.ts index 1716d85969..c874b6e6d4 100644 --- a/packages/nc-gui-v2/components/cell/attachment/utils.ts +++ b/packages/nc-gui-v2/components/cell/attachment/utils.ts @@ -31,6 +31,8 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( const modalVisible = ref(false) + const selectedImage = ref() + const { project } = useProject() const { api, isLoading } = useApi() @@ -140,6 +142,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( removeFile, downloadFile, updateModelValue, + selectedImage, } }, 'attachmentCell',