// Editor View
import { api } from '../api.js';
export async function renderEditor(app) {
const { id, libraryId } = app.state.params;
let doc = null;
let libraries = [];
if (id) {
try {
doc = await api.getDocument(id);
} catch (e) {
app.showToast('Failed to load document', 'error');
app.navigate('dashboard');
return;
}
}
try {
libraries = await api.getLibraries();
} catch (e) {}
const isNew = !id;
const appEl = document.getElementById('app');
let formData = {
title: doc?.title || '',
content: doc?.content || '',
tags: doc?.tags?.join(', ') || '',
type: doc?.type || 'general',
priority: doc?.priority || 'medium',
status: doc?.status || 'draft',
libraryId: doc?.libraryId || libraryId || ''
};
let showPreview = false;
let hasChanges = false;
function render() {
appEl.innerHTML = `
Nothing to preview
'; if (typeof marked !== 'undefined') { return marked.parse(content); } // Fallback return content .replace(/&/g, '&') .replace(//g, '>') .replace(/^### (.+)$/gm, '$1')
.replace(/\n\n/g, ''); }