mirror of
				https://github.com/ae-utbm/sith.git
				synced 2025-10-31 00:53:08 +00:00 
			
		
		
		
	Fix markdown input initial value and crash when alpine is not loaded
This commit is contained in:
		| @@ -13,16 +13,22 @@ const loadEasyMde = (textarea: HTMLTextAreaElement) => { | ||||
|     element: textarea, | ||||
|     spellChecker: false, | ||||
|     autoDownloadFontAwesome: false, | ||||
|     previewRender: Alpine.debounce((plainText: string, preview: MarkdownInput) => { | ||||
|       const func = async (plainText: string, preview: MarkdownInput): Promise<null> => { | ||||
|         preview.innerHTML = ( | ||||
|           await markdownRenderMarkdown({ body: { text: plainText } }) | ||||
|         ).data as string; | ||||
|     previewRender: (plainText: string, preview: MarkdownInput) => { | ||||
|       /* This is wrapped this way to allow time for Alpine to be loaded on the page */ | ||||
|       return Alpine.debounce((plainText: string, preview: MarkdownInput) => { | ||||
|         const func = async ( | ||||
|           plainText: string, | ||||
|           preview: MarkdownInput, | ||||
|         ): Promise<null> => { | ||||
|           preview.innerHTML = ( | ||||
|             await markdownRenderMarkdown({ body: { text: plainText } }) | ||||
|           ).data as string; | ||||
|           return null; | ||||
|         }; | ||||
|         func(plainText, preview); | ||||
|         return null; | ||||
|       }; | ||||
|       func(plainText, preview); | ||||
|       return null; | ||||
|     }, 300), | ||||
|       }, 300)(plainText, preview); | ||||
|     }, | ||||
|     forceSync: true, // Avoid validation error on generic create view | ||||
|     toolbar: [ | ||||
|       { | ||||
| @@ -187,6 +193,10 @@ const loadEasyMde = (textarea: HTMLTextAreaElement) => { | ||||
| class MarkdownInput extends inheritHtmlElement("textarea") { | ||||
|   connectedCallback() { | ||||
|     super.connectedCallback(); | ||||
|     const initialValue = this.querySelector("slot[name='initial']"); | ||||
|     if (initialValue as HTMLSlotElement) { | ||||
|       this.node.textContent = initialValue.textContent; | ||||
|     } | ||||
|     loadEasyMde(this.node); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user