Compare commits

..

2 Commits

Author SHA1 Message Date
schmeeve
0a13fed4a2 autosave for existing notes 2026-09-23 17:27:37 -07:00
schmeeve
c2436f39ea attaching images renders 2026-09-23 16:54:20 -07:00

View File

@@ -470,7 +470,6 @@ function renderEditor(body, owner) {
const isNew = !state.noteId;
const back = el("button", { class: "btn ghost", text: "← Back", onclick: exitEditor });
const save = isNew ? null : el("button", { class: "btn primary", text: "Save", onclick: saveNote });
const del = state.noteId ? el("button", { class: "btn danger", text: "Delete", onclick: deleteNote }) : null;
const hist = state.noteId ? el("button", { class: "btn ghost", text: "History", onclick: showHistory }) : null;
@@ -513,7 +512,7 @@ function renderEditor(body, owner) {
const attach = el("button", { class: "btn", text: "Attach", onclick: () => fileInput.click() });
const wrap = el("div", { class: "editor-wrap" }, [
el("div", { class: "editor-topbar" }, [back, ...(isNew ? [] : [spaceSel]), el("div", { class: "spacer" }), attach, hist, del, commonLabel, previewBtn, ...(isNew ? [] : [save])]),
el("div", { class: "editor-topbar" }, [back, ...(isNew ? [] : [spaceSel]), el("div", { class: "spacer" }), attach, hist, del, commonLabel, previewBtn]),
toolbar,
split,
hint,
@@ -583,18 +582,12 @@ async function persistNote() {
} catch (e) { status.textContent = "Error: " + e.message; }
}
async function saveNote() {
const isNew = !state.noteId;
await persistNote();
if (isNew) showHome();
}
function editorIsEmpty() {
return !state.editor || state.editor.getText().trim() === "";
}
async function exitEditor() {
if (!state.noteId && !editorIsEmpty()) {
if (state.noteId || !editorIsEmpty()) {
await persistNote();
}
showHome();
@@ -625,11 +618,18 @@ async function uploadAttachment(input) {
throw new Error(err.detail || resp.statusText);
}
const data = await resp.json();
if (file.type.startsWith("image/")) {
state.editor.chain().focus().insertContent({
type: "image",
attrs: { src: data.url, alt: data.name, title: data.name },
}).run();
} else {
state.editor.chain().focus().insertContent({
type: "text",
text: data.name,
marks: [{ type: "link", attrs: { href: data.url } }],
}).run();
}
if (status) status.textContent = "Attached " + data.name;
} catch (e) {
if (status) status.textContent = "Error: " + e.message;