| 
									
										
										
										
											2021-04-28 21:31:39 -08:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <div> | 
					
						
							|  |  |  |     <h2 class="mb-4">{{ $t("recipe.ingredients") }}</h2> | 
					
						
							|  |  |  |     <div v-if="edit"> | 
					
						
							| 
									
										
										
										
											2021-05-01 20:46:02 -08:00
										 |  |  |       <draggable :value="value" @input="updateIndex" @start="drag = true" @end="drag = false" handle=".handle"> | 
					
						
							| 
									
										
										
										
											2021-04-28 21:31:39 -08:00
										 |  |  |         <transition-group type="transition" :name="!drag ? 'flip-list' : null"> | 
					
						
							| 
									
										
										
										
											2021-05-01 20:46:02 -08:00
										 |  |  |           <div v-for="(ingredient, index) in value" :key="generateKey('ingredient', index)"> | 
					
						
							| 
									
										
										
										
											2021-04-28 21:31:39 -08:00
										 |  |  |             <v-row align="center"> | 
					
						
							|  |  |  |               <v-textarea | 
					
						
							|  |  |  |                 class="mr-2" | 
					
						
							|  |  |  |                 :label="$t('recipe.ingredient')" | 
					
						
							|  |  |  |                 v-model="value[index]" | 
					
						
							|  |  |  |                 mdi-move-resize | 
					
						
							|  |  |  |                 auto-grow | 
					
						
							|  |  |  |                 solo | 
					
						
							|  |  |  |                 dense | 
					
						
							|  |  |  |                 rows="1" | 
					
						
							|  |  |  |               > | 
					
						
							|  |  |  |                 <template slot="append-outer"> | 
					
						
							|  |  |  |                   <v-icon class="handle">mdi-arrow-up-down</v-icon> | 
					
						
							|  |  |  |                 </template> | 
					
						
							| 
									
										
										
										
											2021-05-01 20:46:02 -08:00
										 |  |  |                 <v-icon class="mr-n1" slot="prepend" color="error" @click="removeByIndex(value, index)"> | 
					
						
							| 
									
										
										
										
											2021-04-28 21:31:39 -08:00
										 |  |  |                   mdi-delete | 
					
						
							|  |  |  |                 </v-icon> | 
					
						
							|  |  |  |               </v-textarea> | 
					
						
							|  |  |  |             </v-row> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         </transition-group> | 
					
						
							|  |  |  |       </draggable> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       <div class="d-flex row justify-end"> | 
					
						
							|  |  |  |         <BulkAdd @bulk-data="addIngredient" class="mr-2" /> | 
					
						
							|  |  |  |         <v-btn color="secondary" dark @click="addIngredient" class="mr-4"> | 
					
						
							|  |  |  |           <v-icon>mdi-plus</v-icon> | 
					
						
							|  |  |  |         </v-btn> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |     <div v-else> | 
					
						
							|  |  |  |       <v-list-item | 
					
						
							|  |  |  |         dense | 
					
						
							|  |  |  |         v-for="(ingredient, index) in value" | 
					
						
							|  |  |  |         :key="generateKey('ingredient', index)" | 
					
						
							|  |  |  |         @click="toggleChecked(index)" | 
					
						
							|  |  |  |       > | 
					
						
							| 
									
										
										
										
											2021-05-01 20:46:02 -08:00
										 |  |  |         <v-checkbox hide-details :value="checked[index]" class="pt-0 my-auto py-auto" color="secondary"> </v-checkbox> | 
					
						
							| 
									
										
										
										
											2021-04-28 21:31:39 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         <v-list-item-content> | 
					
						
							| 
									
										
										
										
											2021-05-01 20:46:02 -08:00
										 |  |  |           <vue-markdown class="ma-0 pa-0 text-subtitle-1 dense-markdown" :source="ingredient"> </vue-markdown> | 
					
						
							| 
									
										
										
										
											2021-04-28 21:31:39 -08:00
										 |  |  |         </v-list-item-content> | 
					
						
							|  |  |  |       </v-list-item> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script> | 
					
						
							|  |  |  | import BulkAdd from "@/components/Recipe/Parts/Helpers/BulkAdd"; | 
					
						
							|  |  |  | import VueMarkdown from "@adapttive/vue-markdown"; | 
					
						
							|  |  |  | import draggable from "vuedraggable"; | 
					
						
							| 
									
										
										
										
											2021-05-05 14:08:13 -08:00
										 |  |  | import { utils } from "@/utils"; | 
					
						
							| 
									
										
										
										
											2021-04-28 21:31:39 -08:00
										 |  |  | export default { | 
					
						
							|  |  |  |   components: { | 
					
						
							|  |  |  |     BulkAdd, | 
					
						
							|  |  |  |     draggable, | 
					
						
							|  |  |  |     VueMarkdown, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   props: { | 
					
						
							|  |  |  |     value: { | 
					
						
							|  |  |  |       type: Array, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     edit: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: true, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   data() { | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       drag: false, | 
					
						
							|  |  |  |       checked: [], | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   mounted() { | 
					
						
							|  |  |  |     this.checked = this.value.map(() => false); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   methods: { | 
					
						
							|  |  |  |     addIngredient(ingredients = null) { | 
					
						
							|  |  |  |       if (ingredients.length) { | 
					
						
							|  |  |  |         this.value.push(...ingredients); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         this.value.push(""); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     generateKey(item, index) { | 
					
						
							|  |  |  |       return utils.generateUniqueKey(item, index); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     updateIndex(data) { | 
					
						
							|  |  |  |       this.$emit("input", data); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     toggleChecked(index) { | 
					
						
							|  |  |  |       this.$set(this.checked, index, !this.checked[index]); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     removeByIndex(list, index) { | 
					
						
							|  |  |  |       list.splice(index, 1); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-01 20:46:02 -08:00
										 |  |  | <style> | 
					
						
							| 
									
										
										
										
											2021-04-28 21:31:39 -08:00
										 |  |  | .dense-markdown p { | 
					
						
							|  |  |  |   margin: auto !important; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-05-01 20:46:02 -08:00
										 |  |  | </style> |