Line data Source code
1 13 : <template>
2 71 : <div
3 : ref="container"
4 : class="relative size-full min-h-[200px]"
5 : data-capture-wheel="true"
6 : tabindex="-1"
7 : @pointerdown.stop="focusContainer"
8 : @mousedown.stop
9 : @contextmenu.stop.prevent
10 : @dragover="handleDragOver"
11 : @dragleave.stop="handleDragLeave"
12 : @drop="handleDrop"
13 : >
14 : <LoadingOverlay :loading="loading" :loading-message="loadingMessage" />
15 : <div
16 : v-if="!isPreview && isDragging"
17 : class="pointer-events-none absolute inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm"
18 : >
19 : <div
20 : class="rounded-lg border-2 border-dashed border-blue-400 bg-blue-500/20 px-6 py-4 text-lg font-medium text-blue-100"
21 : >
22 : {{ dragMessage }}
23 : </div>
24 : </div>
25 : </div>
26 : </template>
27 :
28 : <script setup lang="ts">
29 : import { computed, onMounted, onUnmounted, ref } from 'vue'
30 :
31 : import LoadingOverlay from '@comfyorg/design-system/common/LoadingOverlay'
32 : import { useLoad3dDrag } from '@/extensions/core/load3d/composables/useLoad3dDrag'
33 :
34 26 : const props = defineProps<{
35 : initializeLoad3d: (containerRef: HTMLElement) => Promise<void>
36 : cleanup: () => void
37 : loading: boolean
38 : loadingMessage: string
39 : onModelDrop?: (file: File) => void | Promise<void>
40 : isPreview: boolean
41 : }>()
42 :
43 26 : const container = ref<HTMLElement | null>(null)
44 :
45 0 : function focusContainer() {
46 0 : container.value?.focus()
47 : }
48 :
49 26 : const { isDragging, dragMessage, handleDragOver, handleDragLeave, handleDrop } =
50 : useLoad3dDrag({
51 : onModelDrop: async (file) => {
52 1 : if (props.onModelDrop) {
53 1 : await props.onModelDrop(file)
54 : }
55 : },
56 : disabled: computed(() => props.isPreview)
57 : })
58 :
59 26 : onMounted(() => {
60 26 : if (container.value) {
61 26 : void props.initializeLoad3d(container.value)
62 : }
63 : })
64 :
65 26 : onUnmounted(() => {
66 0 : props.cleanup()
67 : })
68 : </script>
|