|
| 1 | +<script lang="ts"> |
| 2 | + import {MarkdownRenderer} from 'obsidian'; |
| 3 | + import {EditorInputField} from './EditorInputField'; |
| 4 | + import {onMount} from 'svelte'; |
| 5 | +
|
| 6 | + export let onValueChange: (value: any) => void; |
| 7 | + export let editorInput: EditorInputField; |
| 8 | +
|
| 9 | + let value: string; |
| 10 | + let focus: boolean = false; |
| 11 | + let renderEl: HTMLElement; |
| 12 | + let inputEl: HTMLElement; |
| 13 | +
|
| 14 | + $: onValueChange(value) && render(); |
| 15 | +
|
| 16 | + onMount(() => { |
| 17 | + renderEl.toggleVisibility(true); |
| 18 | + inputEl.toggleVisibility(false); |
| 19 | + }); |
| 20 | +
|
| 21 | + export function updateValue(v: string): void { |
| 22 | + value = v; |
| 23 | + renderEl.innerHTML = ''; |
| 24 | + render(); |
| 25 | + } |
| 26 | +
|
| 27 | + function render() { |
| 28 | + MarkdownRenderer.renderMarkdown(value, renderEl, editorInput.inputFieldMarkdownRenderChild.filePath, editorInput.inputFieldMarkdownRenderChild); |
| 29 | + } |
| 30 | +
|
| 31 | + function focusOut(event: MouseEvent) { |
| 32 | + renderEl.toggleVisibility(true); |
| 33 | + inputEl.toggleVisibility(false); |
| 34 | + renderEl.innerHTML = ''; |
| 35 | + render(); |
| 36 | + } |
| 37 | +
|
| 38 | + function focusIn(event: MouseEvent) { |
| 39 | + console.log('focus in'); |
| 40 | + renderEl.toggleVisibility(false); |
| 41 | + inputEl.toggleVisibility(true); |
| 42 | + inputEl.focus(); |
| 43 | + } |
| 44 | +
|
| 45 | + function log() { |
| 46 | + console.log('focus'); |
| 47 | + } |
| 48 | +</script> |
| 49 | + |
| 50 | +<style> |
| 51 | + .editor-input { |
| 52 | + width: 100%; |
| 53 | + height: 500px; |
| 54 | + padding: 0; |
| 55 | + position: relative; |
| 56 | + } |
| 57 | +
|
| 58 | + .editor-input > textarea { |
| 59 | + background: var(--background-secondary); |
| 60 | + border: none; |
| 61 | + padding: var(--size-4-4) var(--size-4-8); |
| 62 | + margin: 0; |
| 63 | + position: absolute; |
| 64 | + inset: 0; |
| 65 | + resize: none; |
| 66 | + } |
| 67 | +
|
| 68 | + .editor-input > div { |
| 69 | + padding: var(--size-4-4) var(--size-4-8); |
| 70 | + position: absolute; |
| 71 | + inset: 0; |
| 72 | + } |
| 73 | +</style> |
| 74 | + |
| 75 | +<div class="editor-input card" on:click={(event) => focusIn(event)}> |
| 76 | + <textarea bind:this={inputEl} bind:value={value} on:focusout={(event) => focusOut(event)}></textarea> |
| 77 | + <div bind:this={renderEl}></div> |
| 78 | +</div> |
| 79 | + |
0 commit comments