|
34 | 34 | DropdownMenuTrigger |
35 | 35 | } from "@/components/ui/dropdown-menu"; |
36 | 36 | import { MoreHorizontal } from "lucide-vue-next"; |
| 37 | + import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; |
37 | 38 |
|
38 | 39 | const props = defineProps<FormFieldProps<FormUploadFieldData> & { asEditorEmbed?: boolean }>(); |
39 | 40 |
|
|
60 | 61 | && (!props.field.imageTransformableFileTypes || props.field.imageTransformableFileTypes?.includes(extension.value)) |
61 | 62 | && props.value?.mime_type?.startsWith('image/'); |
62 | 63 | }); |
| 64 | +
|
63 | 65 | const transformedImg = ref<string>(); |
64 | 66 | const uppyFile = ref<UppyFile>(); |
| 67 | + const isEditable = computed(() => { |
| 68 | + return props.value |
| 69 | + && (!uppyFile.value || !uppyFile.value.progress.uploadStarted || uppyFile.value.progress.uploadComplete) |
| 70 | + && isTransformable.value |
| 71 | + && !props.hasError; |
| 72 | + }); |
65 | 73 | const uppy = new Uppy({ |
66 | 74 | id: props.fieldErrorKey, |
67 | 75 | restrictions: { |
|
257 | 265 | uppy.emit('cancel-all', { reason: 'user' }); |
258 | 266 | emit('uploading', false); |
259 | 267 | }); |
260 | | -
|
261 | | - const menuOpened = ref(false); |
262 | 268 | </script> |
263 | 269 |
|
264 | 270 | <template> |
|
267 | 273 | <template v-if="value?.path || value?.uploaded || uppyFile"> |
268 | 274 | <div :class="{ 'bg-background border border-input rounded-md p-4': !asEditorEmbed }"> |
269 | 275 | <div class="flex"> |
270 | | - <template v-if="transformedImg ?? value?.thumbnail ?? uppyFile?.preview"> |
271 | | - <img class="mr-4 object-contain" |
272 | | - width="150" |
273 | | - :src="transformedImg ?? value?.thumbnail ?? uppyFile.preview" |
274 | | - alt="" |
275 | | - > |
| 276 | + <template v-if="transformedImg ?? value?.thumbnail ?? uppyFile?.preview"> |
| 277 | + <div class="mr-4 group/img relative rounded-md overflow-hidden"> |
| 278 | + <img class="object-contain" |
| 279 | + width="150" |
| 280 | + :src="transformedImg ?? value?.thumbnail ?? uppyFile.preview" |
| 281 | + alt="" |
| 282 | + > |
| 283 | + <template v-if="isEditable"> |
| 284 | + <button class="absolute grid place-content-center inset-0 bg-black/50 transition text-white text-xs font-medium opacity-0 group-hover/img:opacity-100" tabindex="-1" @click="onEdit"> |
| 285 | + {{ __('sharp::form.upload.edit_button') }} |
| 286 | + </button> |
| 287 | + </template> |
| 288 | + </div> |
276 | 289 | </template> |
277 | 290 | <div class="flex-1 min-w-0"> |
278 | 291 | <div class="text-sm font-medium truncate"> |
279 | 292 | <template v-if="value?.path"> |
280 | | - <a class="hover:underline underline-offset-4" |
281 | | - :href="route('code16.sharp.download.show', { |
282 | | - entityKey: form.entityKey, |
283 | | - instanceId: form.instanceId, |
284 | | - disk: value.disk, |
285 | | - path: value.path, |
286 | | - })" |
287 | | - :download="value?.name?.split('/').at(-1)"> |
288 | | - {{ value?.name?.split('/').at(-1) }} |
289 | | - </a> |
| 293 | + <TooltipProvider> |
| 294 | + <Tooltip :delay-duration="0" disable-hoverable-content> |
| 295 | + <TooltipTrigger as-child> |
| 296 | + <a class="hover:underline underline-offset-4" |
| 297 | + :href="route('code16.sharp.download.show', { |
| 298 | + entityKey: form.entityKey, |
| 299 | + instanceId: form.instanceId, |
| 300 | + disk: value.disk, |
| 301 | + path: value.path, |
| 302 | + })" |
| 303 | + :download="value?.name?.split('/').at(-1)" |
| 304 | + > |
| 305 | + {{ value?.name?.split('/').at(-1) }} |
| 306 | + </a> |
| 307 | + </TooltipTrigger> |
| 308 | + |
| 309 | + <TooltipContent class="pointer-events-none" :side-offset="10"> |
| 310 | + {{ __('sharp::form.upload.download_tooltip') }} |
| 311 | + </TooltipContent> |
| 312 | + </Tooltip> |
| 313 | + </TooltipProvider> |
290 | 314 | </template> |
291 | 315 | <template v-else> |
292 | 316 | {{ value?.name?.split('/').at(-1) ?? uppyFile?.name }} |
|
358 | 382 | {{ __('sharp::form.upload.download_link') }} |
359 | 383 | </DropdownMenuItem> |
360 | 384 | </template> |
361 | | - <template v-if="value && (!uppyFile || !uppyFile.progress.uploadStarted || uppyFile.progress.uploadComplete) && isTransformable && !hasError"> |
| 385 | + <template v-if="isEditable"> |
362 | 386 | <DropdownMenuItem @click="onEdit"> |
363 | 387 | {{ __('sharp::form.upload.edit_button') }} |
364 | 388 | </DropdownMenuItem> |
|
0 commit comments