feat: restore Wolai workspace navigation and assets

This commit is contained in:
Agent Board
2026-07-15 23:12:15 +08:00
parent 31a160fcc5
commit 6f9c7d3b58
48 changed files with 6734 additions and 517 deletions
@@ -41,6 +41,51 @@ export const createSidebarPageTreeRuntime = (dependencies = {}) => {
};
}
function selectSidebarPageTreeDocument(nodeId, options) {
var normalizedNodeId = String(nodeId || '').trim();
if (!normalizedNodeId) return false;
var targetRow = document.querySelector(
'#sidebar-tree-root .tree-row[data-shell-mode="page"][data-node-id="' + cssEscape(normalizedNodeId) + '"]'
);
if (!(targetRow instanceof HTMLElement)) return false;
var parentId = String(targetRow.getAttribute('data-parent-id') || '').trim();
var guard = 0;
while (parentId && guard < 512) {
var parentRow = document.querySelector(
'#sidebar-tree-root .tree-row[data-shell-mode="page"][data-node-id="' + cssEscape(parentId) + '"]'
);
if (!(parentRow instanceof HTMLElement)) break;
if (parentRow.getAttribute('aria-expanded') !== 'true') {
toggleChildren(parentRow, parentRow.querySelector('[data-rust-action="toggle"]'));
}
parentId = String(parentRow.getAttribute('data-parent-id') || '').trim();
guard += 1;
}
document.querySelectorAll('#sidebar-tree-root .tree-row[data-shell-mode="page"][data-active="true"]').forEach(function(row) {
if (!(row instanceof HTMLElement)) return;
row.setAttribute('data-active', 'false');
row.setAttribute('aria-selected', 'false');
row.removeAttribute('aria-current');
});
targetRow.setAttribute('data-active', 'true');
targetRow.setAttribute('aria-selected', 'true');
targetRow.setAttribute('aria-current', 'page');
if (!options || options.scrollIntoView !== false) {
try { targetRow.scrollIntoView({ block: 'nearest' }); } catch (_) {}
}
return true;
}
function selectActiveTreeDocument(nodeId, treeView, options) {
if (treeView === 'filetree') {
selectSidebarFileTreeDocument(nodeId, options);
return;
}
selectSidebarPageTreeDocument(nodeId, options);
}
function navigateToDocument(nodeId, workspaceId, options) {
if (!nodeId) return;
var treeView = normalizeSidebarTreeMode(options && options.treeView ? options.treeView : activeSidebarTreeMode());
@@ -49,22 +94,7 @@ export const createSidebarPageTreeRuntime = (dependencies = {}) => {
if (typeof window.__mnoteDocumentPaneRuntime?.activatePageTab === 'function') {
window.__mnoteDocumentPaneRuntime.activatePageTab();
}
document.querySelectorAll('.tree-row[data-active="true"], .tree-row[data-selected="true"]').forEach(function(row) {
if (row instanceof HTMLElement) {
row.setAttribute('data-active', 'false');
row.setAttribute('data-selected', 'false');
}
});
document.querySelectorAll('.tree-row[data-node-id="' + cssEscape(nodeId) + '"], .tree-row[data-document-id="' + cssEscape(nodeId) + '"], .tree-row[data-doc-id="' + cssEscape(nodeId) + '"]').forEach(function(row) {
if (row instanceof HTMLElement) {
if (row.getAttribute('data-shell-mode') === 'filetree') {
row.setAttribute('data-selected', String(row.getAttribute('data-row-id') === 'doc:' + nodeId));
} else {
row.setAttribute('data-active', 'true');
}
}
});
selectSidebarFileTreeDocument(nodeId, { scrollIntoView: true });
selectActiveTreeDocument(nodeId, treeView, { scrollIntoView: true });
return;
}
var targetUrl = new URL('/documents/' + encodeURIComponent(nodeId), window.location.origin);
@@ -88,7 +118,9 @@ export const createSidebarPageTreeRuntime = (dependencies = {}) => {
}).then(function(){
if (mnoteNavigationInFlight === url) mnoteNavigationInFlight = '';
document.documentElement.removeAttribute('data-mnote-navigation-pending');
selectSidebarFileTreeDocument(nodeId, { scrollIntoView: true });
if (treeView === 'filetree') {
selectSidebarFileTreeDocument(nodeId, { scrollIntoView: true });
}
}).catch(function(error){
console.warn('mnote pane 内导航失败,将回退整页导航', error);
if (window.__mnoteTreeLiveEventSource && typeof window.__mnoteTreeLiveEventSource.close === 'function') {
@@ -110,6 +142,7 @@ export const createSidebarPageTreeRuntime = (dependencies = {}) => {
async function createPage(trigger, parentId) {
var workspaceId = resolveWorkspaceId(trigger);
var effectiveParentId = (parentId || trigger.getAttribute('data-parent-id') || '').trim();
var treeView = activeSidebarTreeMode();
if (!workspaceId) return;
var result = await dispatchTreeCommand(trigger, {
action: 'create',
@@ -126,10 +159,12 @@ export const createSidebarPageTreeRuntime = (dependencies = {}) => {
if (typeof refreshLocalFolderAfterCommand === 'function') {
await refreshLocalFolderAfterCommand('create', result, { parentId: effectiveParentId || null });
}
selectSidebarFileTreeDocument(nextDocumentId, localCreateSelectionOptions(result));
if (treeView === 'filetree') {
selectSidebarFileTreeDocument(nextDocumentId, localCreateSelectionOptions(result));
}
document.documentElement.setAttribute('data-mnote-create-page-selected-document-id', nextDocumentId);
}
navigateToDocument(nextDocumentId, nextWorkspaceId, { treeView: activeSidebarTreeMode() });
navigateToDocument(nextDocumentId, nextWorkspaceId, { treeView: treeView });
}
function startPageDrag(pageRow, event) {
@@ -259,6 +294,7 @@ export const createSidebarPageTreeRuntime = (dependencies = {}) => {
return {
navigateToDocument,
createPage,
selectSidebarPageTreeDocument,
startPageDrag,
readPageDragNodeId,
clearPageDropFeedback,