Skip to content

Commit f15aa40

Browse files
committed
integrate for frontmatter
1 parent 3be9041 commit f15aa40

File tree

4 files changed

+27
-52
lines changed

4 files changed

+27
-52
lines changed

src/app/src/components/shared/form/FormPanelInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function computeValue(formItem: FormItem): unknown {
8484
:label="label"
8585
:ui="{
8686
root: 'w-full mt-2',
87-
label: 'text-xs font-semibold tracking-tight',
87+
label: 'text-xs font-medium tracking-tight',
8888
}"
8989
>
9090
<UInput

src/app/src/components/shared/form/FormPanelSection.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@ const childrenCount = computed(() => {
2424
class="w-full group/collapsible"
2525
:default-open="true"
2626
>
27-
<div
28-
class="flex items-center gap-2 w-full py-2"
29-
>
27+
<div class="flex items-center gap-2 w-full mt-3">
3028
<div class="flex items-center justify-center size-4 rounded bg-gray-100 dark:bg-gray-800 transition-colors duration-200 group-hover/collapsible:bg-gray-200 dark:group-hover/collapsible:bg-gray-700">
3129
<UIcon
3230
name="i-lucide-chevron-right"
3331
class="size-2.5 text-gray-500 dark:text-gray-400 transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90"
3432
/>
3533
</div>
3634
<div class="flex gap-2 items-center">
37-
<span class="font-semibold text-gray-900 dark:text-gray-100 tracking-tight">
35+
<span class="text-xs font-semibold text-gray-900 dark:text-gray-100 tracking-tight">
3836
{{ formItem.title }}
3937
</span>
4038
<UBadge
@@ -43,13 +41,13 @@ const childrenCount = computed(() => {
4341
size="xs"
4442
class="text-muted"
4543
>
46-
{{ childrenCount }} child{{ childrenCount === 1 ? '' : 'ren' }}
44+
{{ childrenCount }} propert{{ childrenCount === 1 ? 'y' : 'ies' }}
4745
</UBadge>
4846
</div>
4947
</div>
5048

5149
<template #content>
52-
<div class="mt-1 ml-5 pl-4 border-l border-gray-200 dark:border-gray-700/50 space-y-0.5">
50+
<div class="mt-1 ml-3 pl-3 border-l border-gray-200 dark:border-gray-700/50 space-y-0.5">
5351
<FormPanelSection
5452
v-for="childKey in Object.keys(formItem.children)"
5553
:key="formItem.children[childKey].id"

src/app/src/components/shared/item/ItemActionsToolbar.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useStudio } from '../../../composables/useStudio'
44
import { useStudioState } from '../../../composables/useStudioState'
55
import type { StudioAction } from '../../../types'
66
import { StudioItemActionId, TreeStatus } from '../../../types'
7-
import { MEDIA_EXTENSIONS, getFileExtension } from '../../../utils/file'
7+
import { MEDIA_EXTENSIONS } from '../../../utils/file'
88
import type { DropdownMenuItem } from '@nuxt/ui/runtime/components/DropdownMenu.vue.d.ts'
99
import { useI18n } from 'vue-i18n'
1010
@@ -33,12 +33,10 @@ const extraActions = computed<DropdownMenuItem[]>(() => {
3333
const actions: DropdownMenuItem[] = []
3434
3535
if (item.value.type === 'file') {
36-
const fileExtension = getFileExtension(item.value.fsPath)
37-
const isMarkdown = fileExtension === 'md'
3836
const isConflictDetected = context.activeTree.value.draft.current.value?.conflict
3937
4038
// Add editor mode switch for markdown files
41-
if (isMarkdown && !isConflictDetected) {
39+
if (!isConflictDetected) {
4240
actions.push({
4341
label: preferences.value.editorMode === 'code'
4442
? t('studio.actions.labels.switchToTipTap')

src/app/src/components/tiptap/extension/TiptapExtensionFrontmatter.vue

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,31 @@
11
<script setup lang="ts">
22
import { nodeViewProps, NodeViewWrapper, NodeViewContent } from '@tiptap/vue-3'
3-
import { ref, computed, watch } from 'vue'
3+
import { ref, computed } from 'vue'
44
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'
76
87
const nodeProps = defineProps(nodeViewProps)
98
10-
const { ui } = useStudio()
9+
const { host, documentTree } = useStudio()
1110
12-
const editorRef = ref<HTMLElement>()
1311
const collapsed = ref(true)
14-
const loadingMonaco = ref(true)
1512
1613
const textColor = computed(() => collapsed.value ? 'text-muted group-hover/header:text-default' : 'text-default')
1714
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({
1922
get: () => {
20-
return jsonToYaml(nodeProps.node.attrs.frontmatter)
23+
return nodeProps.node.attrs.frontmatter || {}
2124
},
2225
set: (value) => {
23-
return nodeProps.updateAttributes({ frontmatter: yamlToJson(value) })
26+
nodeProps.updateAttributes({ frontmatter: value })
2427
},
2528
})
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-
})
5329
</script>
5430

5531
<template>
@@ -87,13 +63,16 @@ watch(frontmatter, () => {
8763
v-show="!collapsed"
8864
:min-height="100"
8965
:max-height="500"
90-
:initial-height="100"
66+
:initial-height="270"
9167
class="mt-1 border-l-2 shadow-xs border-dashed border-muted bg-muted/30 overflow-hidden"
9268
>
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>
9776
</ResizableElement>
9877
</div>
9978
<NodeViewContent />

0 commit comments

Comments
 (0)