|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import { nodeViewProps, NodeViewWrapper, NodeViewContent } from '@tiptap/vue-3' |
3 | | -import { ref, computed, watch } from 'vue' |
| 3 | +import { ref, computed } from 'vue' |
4 | 4 | import { useStudio } from '../../../composables/useStudio' |
5 | | -import { useMonaco } from '../../../composables/useMonaco' |
6 | | -import { jsonToYaml, yamlToJson } from '../../../utils/data' |
| 5 | +import type { Draft07 } from '@nuxt/content' |
7 | 6 |
|
8 | 7 | const nodeProps = defineProps(nodeViewProps) |
9 | 8 |
|
10 | | -const { ui } = useStudio() |
| 9 | +const { host, documentTree } = useStudio() |
11 | 10 |
|
12 | | -const editorRef = ref<HTMLElement>() |
13 | 11 | const collapsed = ref(true) |
14 | | -const loadingMonaco = ref(true) |
15 | 12 |
|
16 | 13 | const textColor = computed(() => collapsed.value ? 'text-muted group-hover/header:text-default' : 'text-default') |
17 | 14 |
|
18 | | -const frontmatter = computed({ |
| 15 | +const collection = computed(() => { |
| 16 | + const currentItem = documentTree.currentItem.value |
| 17 | + if (!currentItem?.fsPath) return null |
| 18 | + return host.collection.getByFsPath(currentItem.fsPath) |
| 19 | +}) |
| 20 | +
|
| 21 | +const frontmatterJSON = computed({ |
19 | 22 | get: () => { |
20 | | - return jsonToYaml(nodeProps.node.attrs.frontmatter) |
| 23 | + return nodeProps.node.attrs.frontmatter || {} |
21 | 24 | }, |
22 | 25 | set: (value) => { |
23 | | - return nodeProps.updateAttributes({ frontmatter: yamlToJson(value) }) |
| 26 | + nodeProps.updateAttributes({ frontmatter: value }) |
24 | 27 | }, |
25 | 28 | }) |
26 | | -
|
27 | | -let monaco: ReturnType<typeof useMonaco> | null = null |
28 | | -watch(collapsed, async (isCollapsed) => { |
29 | | - if (isCollapsed) { |
30 | | - return |
31 | | - } |
32 | | -
|
33 | | - if (!monaco) { |
34 | | - monaco = useMonaco(editorRef, { |
35 | | - language: 'yaml', |
36 | | - initialContent: frontmatter.value, |
37 | | - readOnly: false, |
38 | | - colorMode: ui.colorMode, |
39 | | - onChange(value: string) { |
40 | | - frontmatter.value = value |
41 | | - }, |
42 | | - }) |
43 | | -
|
44 | | - loadingMonaco.value = false |
45 | | - } |
46 | | -}) |
47 | | -
|
48 | | -watch(frontmatter, () => { |
49 | | - if (monaco) { |
50 | | - monaco.setContent(frontmatter.value || '') |
51 | | - } |
52 | | -}) |
53 | 29 | </script> |
54 | 30 |
|
55 | 31 | <template> |
@@ -87,13 +63,16 @@ watch(frontmatter, () => { |
87 | 63 | v-show="!collapsed" |
88 | 64 | :min-height="100" |
89 | 65 | :max-height="500" |
90 | | - :initial-height="100" |
| 66 | + :initial-height="270" |
91 | 67 | class="mt-1 border-l-2 shadow-xs border-dashed border-muted bg-muted/30 overflow-hidden" |
92 | 68 | > |
93 | | - <div |
94 | | - ref="editorRef" |
95 | | - class="w-full h-full overflow-hidden" |
96 | | - /> |
| 69 | + <div class="px-4 pt-2 pb-4 overflow-y-auto h-full"> |
| 70 | + <FormSchemaBased |
| 71 | + v-model="frontmatterJSON" |
| 72 | + :collection-name="collection!.name" |
| 73 | + :schema="collection!.schema as Draft07" |
| 74 | + /> |
| 75 | + </div> |
97 | 76 | </ResizableElement> |
98 | 77 | </div> |
99 | 78 | <NodeViewContent /> |
|
0 commit comments