π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
fix(editor): validate document titles (#711)
QinXifc685174e760
diff --git a/frontend/app/components/MarkdownEditor/MarkdownEditor.vue b/frontend/app/components/MarkdownEditor/MarkdownEditor.vueindex 8c277337..18251753 100644--- a/frontend/app/components/MarkdownEditor/MarkdownEditor.vue+++ b/frontend/app/components/MarkdownEditor/MarkdownEditor.vue@@ -11,7 +11,15 @@<!-- Compact Document Metadata --><div class="document-meta"><div class="line">- <input v-model="document.name" :placeholder="t('components.editor.placeholder.title')" class="meta-title" @input="autoSaveConditional" />+ <input+ ref="titleInput"+ v-model="document.name"+ :autofocus="autofocusTitle"+ :placeholder="t('components.editor.placeholder.title')"+ class="meta-title"+ required+ @input="autoSaveConditional"+ /><inputv-model="document.description":placeholder="t('components.editor.placeholder.description')"@@ -62,13 +70,14 @@ const resourcesStore = useResourcesStore();const nodesStore = useNodesStore();const preferences = usePreferencesStore();-defineProps<{ public?: boolean }>();+const props = defineProps<{ public?: boolean; autofocusTitle?: boolean }>();const emit = defineEmits<{(e: 'save' | 'autoSave', doc: Partial<Node>): void;(e: 'exit'): void;}>();const editorContainer = ref<HTMLDivElement>();+const titleInput = ref<HTMLInputElement>();const markdownPreviewComponent = ref<InstanceType<typeof NodeDocumentContentCompiled>>();const markdownPreview = computed(() => markdownPreviewComponent.value?.rootElement as HTMLElement | undefined);const editorView = ref<EditorView | null>(null);@@ -127,6 +136,7 @@ const state = createEditorState({});onMounted(() => {+ if (props.autofocusTitle) titleInput.value?.focus();if (!editorContainer.value) return;editorView.value = new EditorView({state,@@ -185,11 +195,19 @@ const updateDocumentContent = debounce(() => {}, 100);const save = debounce(() => {+ if (!document.value.name?.trim()) {+ titleInput.value?.focus();+ titleInput.value?.reportValidity();+ return;+ }updateDocumentContent();emit('save', document.value);}, 1000);const autoSave = debounceDelayed(() => {+ // New documents persist locally before they have a title; existing documents+ // must never overwrite their saved title with an empty value.+ if (document.value.id && !document.value.name?.trim()) return;updateDocumentContent();emit('autoSave', document.value);}, 2000);diff --git a/frontend/app/pages/dashboard/docs/new.vue b/frontend/app/pages/dashboard/docs/new.vueindex f13dcd30..55850884 100644--- a/frontend/app/pages/dashboard/docs/new.vue+++ b/frontend/app/pages/dashboard/docs/new.vue@@ -1,5 +1,5 @@<template>- <LazyMarkdownEditor v-model="document" @save="data => save(data)" @exit="exit" @auto-save="savePending" />+ <LazyMarkdownEditor v-model="document" autofocus-title @save="data => save(data)" @exit="exit" @auto-save="savePending" /></template><script lang="ts" setup>import localForage from 'localforage';