Skip to content

Commit 83f3459

Browse files
committed
Add editor preview
1 parent 9027fa4 commit 83f3459

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/pages/edit.vue

+28-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { onBeforeUnmount, onMounted, reactive, ref, shallowRef, watch } from 'vue';
2+
import { computed, onBeforeUnmount, onMounted, reactive, ref, shallowRef, watch } from 'vue';
33
import type { editor } from 'monaco-editor';
44
import { themeNames, themes } from '@/lib/monaco/themes';
55
import type * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api';
@@ -18,6 +18,7 @@ import type { AtUri } from '@atproto/syntax';
1818
import { useLocalStorage, watchImmediate } from '@vueuse/core';
1919
import { lookupMime } from '@/lib/mime';
2020
import MonacoEditor from '@/components/MonacoEditor.vue';
21+
import MarkdownRenderer from '@/components/MarkdownRenderer.vue';
2122
2223
const MONACO_EDITOR_OPTIONS: editor.IStandaloneEditorConstructionOptions = {
2324
automaticLayout: true,
@@ -28,6 +29,7 @@ const MONACO_EDITOR_OPTIONS: editor.IStandaloneEditorConstructionOptions = {
2829
};
2930
3031
const editorRef = shallowRef<editor.IStandaloneCodeEditor>();
32+
const editorValue = ref('');
3133
const submitted = ref(false);
3234
3335
function onBeforeMonacoMount() {
@@ -43,6 +45,13 @@ function onBeforeMonacoMount() {
4345
4446
function onMonacoMount(editor: editor.IStandaloneCodeEditor) {
4547
editorRef.value = editor;
48+
49+
editorRef.value.onDidChangeModelContent(event => {
50+
const value = editorRef.value!.getValue();
51+
if (value !== editorValue.value) {
52+
editorValue.value = value;
53+
}
54+
});
4655
}
4756
4857
// your action
@@ -108,6 +117,8 @@ watch(activeFile, activeFile => {
108117
);
109118
});
110119
120+
const isMarkdownFile = computed(() => !activeFile.value || ((lookupMime(activeFile.value) ?? 'text/mdx') === 'text/mdx'));
121+
111122
</script>
112123

113124
<template>
@@ -123,15 +134,6 @@ watch(activeFile, activeFile => {
123134
</template>
124135
<template #content>
125136
<div class="flex">
126-
<div class="errors" v-if="submitErrors.length">
127-
Errors:
128-
<ul>
129-
<li v-for="error, idx in submitErrors" :key="idx">
130-
{{ String(error) }}
131-
</li>
132-
</ul>
133-
</div>
134-
135137
<div class="inputs">
136138
<VaInput
137139
v-model="activeFile"
@@ -169,6 +171,22 @@ watch(activeFile, activeFile => {
169171
/> -->
170172
</div>
171173
</template>
174+
<template #right v-if="isMarkdownFile">
175+
<div style="min-width: 25vw;">
176+
<div style="padding: var(--va-grid-gutter-base); max-height: calc(100vh - 69.6px); overflow: auto;">
177+
<div class="errors" v-if="submitErrors.length">
178+
Errors:
179+
<ul>
180+
<li v-for="error, idx in submitErrors" :key="idx">
181+
{{ String(error) }}
182+
</li>
183+
</ul>
184+
</div>
185+
186+
<MarkdownRenderer :markdown="editorValue"></MarkdownRenderer>
187+
</div>
188+
</div>
189+
</template>
172190
</VaLayout>
173191
</template>
174192

0 commit comments

Comments
 (0)