mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-29 01:04:18 -04:00 
			
		
		
		
	Refactor recipe page to use break up the component and make it more usable across different pages. I've left the old route in as well in case there is some functional breaks, I plan to remove it before the official release once we've tested the new editor some more in production. For now there will just have to be some duplicate components and pages around.
		
			
				
	
	
		
			86 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
			
		
		
	
	
			86 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
| <template>
 | |
|   <div>
 | |
|     <div v-if="displayPreview" class="d-flex justify-end">
 | |
|       <BaseButtonGroup
 | |
|         :buttons="[
 | |
|           {
 | |
|             icon: previewState ? $globals.icons.edit : $globals.icons.eye,
 | |
|             text: previewState ? $tc('general.edit') : $tc('markdown-editor.preview-markdown-button-label'),
 | |
|             event: 'toggle',
 | |
|           },
 | |
|         ]"
 | |
|         @toggle="previewState = !previewState"
 | |
|       />
 | |
|     </div>
 | |
|     <v-textarea
 | |
|       v-if="!previewState"
 | |
|       v-bind="textarea"
 | |
|       v-model="inputVal"
 | |
|       :class="label == '' ? '' : 'mt-5'"
 | |
|       :label="label"
 | |
|       auto-grow
 | |
|       dense
 | |
|       rows="4"
 | |
|     />
 | |
|     <SafeMarkdown v-else :source="value" />
 | |
|   </div>
 | |
| </template>
 | |
| 
 | |
| <script lang="ts">
 | |
| import { defineComponent, computed, ref } from "@nuxtjs/composition-api";
 | |
| 
 | |
| export default defineComponent({
 | |
|   name: "MarkdownEditor",
 | |
|   props: {
 | |
|     value: {
 | |
|       type: String,
 | |
|       required: true,
 | |
|     },
 | |
|     label: {
 | |
|       type: String,
 | |
|       default: "",
 | |
|     },
 | |
|     preview: {
 | |
|       type: Boolean,
 | |
|       default: undefined,
 | |
|     },
 | |
|     displayPreview: {
 | |
|       type: Boolean,
 | |
|       default: true,
 | |
|     },
 | |
|     textarea: {
 | |
|       type: Object as () => unknown,
 | |
|       default: () => ({}),
 | |
|     },
 | |
|   },
 | |
|   setup(props, context) {
 | |
|     const fallbackPreview = ref(false);
 | |
|     const previewState = computed({
 | |
|       get: () => {
 | |
|         return props.preview ?? fallbackPreview.value;
 | |
|       },
 | |
|       set: (val) => {
 | |
|         if (props.preview) {
 | |
|           context.emit("input:preview", val);
 | |
|         } else {
 | |
|           fallbackPreview.value = val;
 | |
|         }
 | |
|       },
 | |
|     });
 | |
| 
 | |
|     const inputVal = computed({
 | |
|       get: () => {
 | |
|         return props.value;
 | |
|       },
 | |
|       set: (val) => {
 | |
|         context.emit("input", val);
 | |
|       },
 | |
|     });
 | |
|     return {
 | |
|       previewState,
 | |
|       inputVal,
 | |
|     };
 | |
|   },
 | |
| });
 | |
| </script>
 |