useFilePreviewViewer.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { ref } from 'vue'
  3. import { useImageViewer } from '#shared/composables/useImageViewer.ts'
  4. import type { FilePreview } from '#shared/utils/files.ts'
  5. import { useFlyout } from '#desktop/components/CommonFlyout/useFlyout.ts'
  6. import type { MaybeRef } from '@vueuse/shared'
  7. interface ImagePreview {
  8. src?: string
  9. title?: string
  10. }
  11. export interface ViewerFile {
  12. id?: string
  13. name?: string
  14. content?: string
  15. preview?: string
  16. inline?: string
  17. type?: Maybe<string>
  18. }
  19. export interface ViewerOptions {
  20. images: ImagePreview[]
  21. index: number
  22. visible: boolean
  23. }
  24. export const imageViewerOptions = ref<ViewerOptions>({
  25. visible: false,
  26. index: 0,
  27. images: [],
  28. })
  29. export const useFilePreviewViewer = (viewFiles: MaybeRef<ViewerFile[]>) => {
  30. const { showImage } = useImageViewer(viewFiles)
  31. const calendarPreviewFlyout = useFlyout({
  32. name: 'common-calendar-preview',
  33. component: () =>
  34. import(
  35. '#desktop/components/CommonCalendarPreviewFlyout/CommonCalendarPreviewFlyout.vue'
  36. ),
  37. })
  38. const showPreview = (type: FilePreview, filePreviewfile: ViewerFile) => {
  39. if (type === 'image') {
  40. showImage(filePreviewfile)
  41. }
  42. if (type === 'calendar') {
  43. calendarPreviewFlyout.open({
  44. fileId: filePreviewfile.id,
  45. fileType: filePreviewfile.type,
  46. fileName: filePreviewfile.name,
  47. })
  48. }
  49. }
  50. return {
  51. showPreview,
  52. }
  53. }