refactor: extract dnd target and sidebar helpers

This commit is contained in:
lix-2026
2026-05-25 04:16:35 +08:00
parent 32adfb38a1
commit 1e097a9597
9 changed files with 201 additions and 57 deletions
@@ -214,6 +214,17 @@ function groupRowsByParent(rows) {
return grouped;
}
function replaceSidebarTreeFromDocument(nextDocument, rootId) {
var current = document.getElementById(rootId);
var next = nextDocument ? nextDocument.getElementById(rootId) : null;
if (!(current instanceof HTMLElement) || !(next instanceof HTMLElement)) return false;
current.innerHTML = next.innerHTML;
Array.from(next.attributes || []).forEach(function(attr) {
current.setAttribute(attr.name, attr.value);
});
return true;
}
function revealFileTreeRow(row) {
if (!(row instanceof HTMLElement)) return;
var node = row.closest('.tree-node');
@@ -351,6 +362,7 @@ window.__mnoteFileTreeRuntime = {
titleOf: titleOf,
fileWorkspaceRelativePath: fileWorkspaceRelativePath,
groupRowsByParent: groupRowsByParent,
replaceSidebarTreeFromDocument: replaceSidebarTreeFromDocument,
fileTreeRowKind: fileTreeRowKind,
fileTreeRowDocumentId: fileTreeRowDocumentId,
fileTreeRowAssetId: fileTreeRowAssetId,