Skip to content

Commit 93fe90c

Browse files
authored
fix(editor): data type edition (#117)
1 parent 7c50d49 commit 93fe90c

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/app/src/components/content/ContentEditorCode.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,21 @@ watch(showAutomaticFormattingDiff, async (show) => {
123123
124124
// Trigger on document changes
125125
watch(() => document.value?.id + '-' + props.draftItem.version, async () => {
126-
if (document.value?.body) {
126+
if (document.value) {
127127
setContent(document.value)
128128
}
129129
}, { immediate: true })
130130
131131
async function setContent(document: DatabasePageItem) {
132-
const contentFromDocument = host.document.generate.contentFromDocument
133-
const md = await contentFromDocument(document) || ''
134-
content.value = md
135-
setEditorContent(md, true)
132+
const generateContentFromDocument = host.document.generate.contentFromDocument
133+
const generatedContent = await generateContentFromDocument(document) || ''
134+
content.value = generatedContent
135+
setEditorContent(generatedContent, true)
136136
currentDocumentId.value = document.id
137137
138138
isAutomaticFormattingDetected.value = false
139139
if (props.draftItem.original && props.draftItem.remoteFile?.content) {
140-
const localOriginal = await contentFromDocument(props.draftItem.original as DatabaseItem) as string
140+
const localOriginal = await generateContentFromDocument(props.draftItem.original as DatabaseItem) as string
141141
const remoteOriginal = props.draftItem.remoteFile.encoding === 'base64' ? fromBase64ToUTF8(props.draftItem.remoteFile.content!) : props.draftItem.remoteFile.content!
142142
143143
isAutomaticFormattingDetected.value = !areContentEqual(localOriginal, remoteOriginal)

src/module/src/runtime/utils/document.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,19 @@ export async function generateDocumentFromYAMLContent(id: string, content: strin
249249
parsed = { body: data }
250250
}
251251

252-
return {
252+
const document = {
253253
id,
254254
extension: getFileExtension(id),
255255
stem: generateStemFromId(id),
256256
meta: {},
257257
...parsed,
258-
body: parsed.body || parsed,
259258
} as DatabaseItem
259+
260+
if (parsed.body) {
261+
document.body = parsed.body
262+
}
263+
264+
return document
260265
}
261266

262267
export async function generateDocumentFromJSONContent(id: string, content: string): Promise<DatabaseItem> {

0 commit comments

Comments
 (0)