mirror of https://github.com/docusealco/docuseal
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							162 lines
						
					
					
						
							4.6 KiB
						
					
					
				
			
		
		
	
	
							162 lines
						
					
					
						
							4.6 KiB
						
					
					
				| <template>
 | |
|   <div>
 | |
|     <div v-for="(previewImage, index) in document.preview_images" :key="previewImage.id" class="relative">
 | |
|       <img
 | |
|         :src="previewImage.url"
 | |
|         :width="previewImage.metadata.width"
 | |
|         :height="previewImage.metadata.height"
 | |
|         class="rounded border"
 | |
|         loading="lazy"
 | |
|       >
 | |
|       <div class="absolute bottom-0 left-0 bg-white text-gray-700 p-1">
 | |
|         {{ index + 1 }}
 | |
|       </div>
 | |
|       <div
 | |
|         class="group flex justify-end cursor-pointer top-0 bottom-0 left-0 right-0 absolute p-1"
 | |
|         @click="$emit('scroll-to', item, previewImage)"
 | |
|       >
 | |
|         <div
 | |
|           v-if="editable && index==0"
 | |
|           class="flex justify-between w-full"
 | |
|         >
 | |
|           <div style="width: 26px" />
 | |
|           <div class="">
 | |
|             <ReplaceButton
 | |
|               :is-direct-upload="isDirectUpload"
 | |
|               :template-id="template.id"
 | |
|               :accept-file-types="acceptFileTypes"
 | |
|               class="opacity-0 group-hover:opacity-100"
 | |
|               @click.stop
 | |
|               @success="$emit('replace', { replaceSchemaItem: item, ...$event })"
 | |
|             />
 | |
|           </div>
 | |
|           <div
 | |
|             class="flex flex-col justify-between opacity-0 group-hover:opacity-100"
 | |
|           >
 | |
|             <div>
 | |
|               <button
 | |
|                 class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-red-500 hover:border-base-content w-full transition-colors"
 | |
|                 style="width: 24px; height: 24px"
 | |
|                 @click.stop="$emit('remove', item)"
 | |
|               >
 | |
|                 ×
 | |
|               </button>
 | |
|             </div>
 | |
|             <div
 | |
|               v-if="withArrows"
 | |
|               class="flex flex-col space-y-1"
 | |
|             >
 | |
|               <button
 | |
|                 class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-red-500 hover:border-base-content w-full transition-colors"
 | |
|                 style="width: 24px; height: 24px"
 | |
|                 @click.stop="$emit('up', item)"
 | |
|               >
 | |
|                 ↑
 | |
|               </button>
 | |
|               <button
 | |
|                 class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-red-500 hover:border-base-content w-full transition-colors"
 | |
|                 style="width: 24px; height: 24px"
 | |
|                 @click.stop="$emit('down', item)"
 | |
|               >
 | |
|                 ↓
 | |
|               </button>
 | |
|             </div>
 | |
|           </div>
 | |
|         </div>
 | |
|         <div
 | |
|           v-else
 | |
|           class="flex justify-between w-full"
 | |
|         >
 | |
|           <div
 | |
|             class="flex flex-col justify-between opacity-0 group-hover:opacity-100"
 | |
|           >
 | |
|             <button
 | |
|               class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-base-content hover:border-base-content w-full transition-colors"
 | |
|               style="width: 24px; height: 24px"
 | |
|               @click.stop="$emit('remove-image', { item, previewImageId: previewImage.id })"
 | |
|             >
 | |
|               ×
 | |
|             </button>
 | |
|           </div>
 | |
|         </div>
 | |
|       </div>
 | |
|     </div>
 | |
|     <div class="flex pb-2 pt-1.5">
 | |
|       <Contenteditable
 | |
|         :model-value="item.name"
 | |
|         :icon-width="16"
 | |
|         style="max-width: 95%"
 | |
|         class="mx-auto"
 | |
|         @update:model-value="onUpdateName"
 | |
|       />
 | |
|     </div>
 | |
|   </div>
 | |
| </template>
 | |
| 
 | |
| <script>
 | |
| import Contenteditable from './contenteditable'
 | |
| import Upload from './upload'
 | |
| import ReplaceButton from './replace'
 | |
| 
 | |
| export default {
 | |
|   name: 'DocumentPreview',
 | |
|   components: {
 | |
|     Contenteditable,
 | |
|     ReplaceButton
 | |
|   },
 | |
|   props: {
 | |
|     item: {
 | |
|       type: Object,
 | |
|       required: true
 | |
|     },
 | |
|     template: {
 | |
|       type: Object,
 | |
|       required: true
 | |
|     },
 | |
|     document: {
 | |
|       type: Object,
 | |
|       required: true
 | |
|     },
 | |
|     editable: {
 | |
|       type: Boolean,
 | |
|       required: false,
 | |
|       default: true
 | |
|     },
 | |
|     acceptFileTypes: {
 | |
|       type: String,
 | |
|       required: false,
 | |
|       default: 'image/*, application/pdf'
 | |
|     },
 | |
|     isDirectUpload: {
 | |
|       type: Boolean,
 | |
|       required: true,
 | |
|       default: false
 | |
|     },
 | |
|     withArrows: {
 | |
|       type: Boolean,
 | |
|       required: false,
 | |
|       default: true
 | |
|     }
 | |
|   },
 | |
|   emits: ['scroll-to', 'change', 'remove', 'up', 'down', 'replace', 'remove-image'],
 | |
|   computed: {
 | |
|     previewImage () {
 | |
|       return [...this.document.preview_images].sort((a, b) => parseInt(a.filename) - parseInt(b.filename))[0]
 | |
|     }
 | |
|   },
 | |
|   mounted () {
 | |
|     if (this.isDirectUpload) {
 | |
|       import('@rails/activestorage')
 | |
|     }
 | |
|   },
 | |
|   methods: {
 | |
|     upload: Upload.methods.upload,
 | |
|     onUpdateName (value) {
 | |
|       this.item.name = value
 | |
| 
 | |
|       this.$emit('change')
 | |
|     }
 | |
|   }
 | |
| }
 | |
| </script>
 |