Diffdown is a real-time collaborative Markdown editor/previewer built on the AT Protocol diffdown.com

Wire paragraph click to comment button; pass ownerDID in comment API calls

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

+27 -2
+27 -2
templates/document_edit.html
··· 788 788 if (!text) return; 789 789 790 790 try { 791 + const body = { paragraphId: activeCommentParagraphId, text }; 792 + if (ownerDID) body.ownerDID = ownerDID; 791 793 const resp = await fetch(`/api/docs/${rkey}/comments`, { 792 794 method: 'POST', 793 795 headers: { 'Content-Type': 'application/json' }, 794 - body: JSON.stringify({ paragraphId: activeCommentParagraphId, text }), 796 + body: JSON.stringify(body), 795 797 }); 796 798 if (!resp.ok) throw new Error(await resp.text()); 797 799 closeCommentForm(); ··· 854 856 async function loadComments() { 855 857 if (!accessToken) return; 856 858 try { 857 - const resp = await fetch(`/api/docs/${rkey}/comments`); 859 + const qs = ownerDID ? '?ownerDID=' + encodeURIComponent(ownerDID) : ''; 860 + const resp = await fetch(`/api/docs/${rkey}/comments${qs}`); 858 861 if (!resp.ok) return; 859 862 const comments = await resp.json(); 860 863 renderCommentThreads(comments); ··· 862 865 console.error('Load comments failed:', e); 863 866 } 864 867 } 868 + 869 + function setupParagraphCommentTrigger() { 870 + const editorEl = document.getElementById('editor-rich'); 871 + if (!editorEl) return; 872 + editorEl.addEventListener('click', e => { 873 + const pmEl = e.target.closest('.ProseMirror'); 874 + if (!pmEl) return; 875 + const paraEl = e.target.closest('p, h1, h2, h3, h4, h5, h6, li'); 876 + if (!paraEl) return; 877 + const siblings = Array.from(paraEl.parentElement.children); 878 + const idx = siblings.indexOf(paraEl); 879 + const pid = 'p-' + idx; 880 + activeCommentParagraphId = pid; 881 + if (commentBtn) { 882 + const rect = paraEl.getBoundingClientRect(); 883 + commentBtn.style.top = (rect.top + window.scrollY + rect.height / 2 - 12) + 'px'; 884 + commentBtn.style.left = (rect.right + window.scrollX + 8) + 'px'; 885 + commentBtn.style.display = 'block'; 886 + } 887 + }); 888 + } 889 + setupParagraphCommentTrigger(); 865 890 866 891 // ── Init ────────────────────────────────────────────────────────────────── 867 892