fix local markdown attachment regressions

This commit is contained in:
lix-2026
2026-05-29 11:13:05 +08:00
parent 1109e3c0d8
commit cbe789e034
63 changed files with 3249 additions and 1502 deletions
@@ -423,17 +423,17 @@ export const createSidebarTreeLiveApplyRuntime = (dependencies = {}) => {
void refreshLocalFolderSidebarSnapshot();
return true;
}
var changedPaths = Array.isArray(batch && batch.changedPaths)
? batch.changedPaths
: Array.isArray(batch && batch.changed_paths)
? batch.changed_paths
: [];
var affectedParents = Array.isArray(batch && batch.affectedParents)
? batch.affectedParents
: Array.isArray(batch && batch.affected_parents)
? batch.affected_parents
: [];
if (!affectedParents.length) {
var changedPaths = Array.isArray(batch && batch.changedPaths)
? batch.changedPaths
: Array.isArray(batch && batch.changed_paths)
? batch.changed_paths
: [];
affectedParents = changedPaths.map(function(item) {
var relativePath = String(item && (item.relativePath || item.relative_path) || '').trim();
return { relativePath: parentRelativePathForPath(relativePath), reason: 'derived-from-changed-path' };
@@ -452,6 +452,10 @@ export const createSidebarTreeLiveApplyRuntime = (dependencies = {}) => {
affectedParents.forEach(function(parent) {
addCommandRefreshParent(parents, parent && (parent.relativePath || parent.relative_path));
});
var needsSidebarRefresh = changedPaths.some(function(item) {
var relativePath = String(item && (item.relativePath || item.relative_path) || '').trim().toLowerCase();
return relativePath.endsWith('.md') || relativePath.endsWith('.markdown');
});
document.documentElement.setAttribute('data-mnote-local-folder-watch-batch-applied', String(batch.revision || 'true'));
void Promise.all(Array.from(parents).map(function(parentRelativePath) {
return refreshFileTreeParent(parentRelativePath).catch(function(error) {
@@ -459,6 +463,9 @@ export const createSidebarTreeLiveApplyRuntime = (dependencies = {}) => {
return false;
});
})).then(function() {
if (needsSidebarRefresh) {
void refreshLocalFolderSidebarSnapshot();
}
markLocalFolderWatchApplied('watch_batch');
});
return true;
@@ -1391,6 +1398,7 @@ export const createSidebarTreeLiveApplyRuntime = (dependencies = {}) => {
if (runtimeFn) return runtimeFn(value);
var appliedValue = String(value || 'projection');
document.documentElement.setAttribute('data-mnote-local-folder-watch-applied', appliedValue);
document.documentElement.removeAttribute('data-mnote-local-folder-watch-disabled');
return true;
}
@@ -1492,55 +1500,11 @@ export const createSidebarTreeLiveApplyRuntime = (dependencies = {}) => {
if (!rootUri) return;
ensureFileTreeLazyCacheScope();
scheduleRestorePersistedFileTreeExpansionState();
var revision = '';
var refreshTimer = 0;
var treeLiveEventsActive = function() {
var treeTransport = document.documentElement.getAttribute('data-mnote-tree-live-transport') || '';
return treeTransport === 'local-folder-events';
};
var scheduleRefresh = function() {
if (treeLiveEventsActive()) return;
if (refreshTimer) return;
refreshTimer = window.setTimeout(function() {
refreshTimer = 0;
if (treeLiveEventsActive()) return;
var fileTreeScope = currentFileTreeScope();
if (fileTreeScope) {
markFileTreeParentStale(currentFileTreeParentKey(fileTreeScope));
markLocalFolderWatchApplied('scope_stale');
document.documentElement.setAttribute('data-mnote-filetree-scope-watch-stale', fileTreeScope);
return;
}
void refreshLocalFolderSidebarSnapshot();
}, 180);
};
var poll = async function() {
if (document.hidden) return;
// If tree live SSE transport is active for local_folder, skip polling (fallback)
if (treeLiveEventsActive()) return;
var url = new URL('/api/tree/local-folder-watch', window.location.origin);
url.searchParams.set('rootUri', rootUri);
var response = await fetch(url.toString(), { headers: { accept: 'application/json' } });
if (!response.ok) return;
if (treeLiveEventsActive()) return;
var payload = await response.json();
var nextRevision = payload && payload.result && typeof payload.result.revision === 'string'
? payload.result.revision
: '';
if (!nextRevision) return;
if (!revision) {
revision = nextRevision;
return;
}
if (nextRevision !== revision) {
revision = nextRevision;
scheduleRefresh();
}
};
window.setInterval(function() {
void poll();
}, 1200);
void poll();
var treeTransport = document.documentElement.getAttribute('data-mnote-tree-live-transport') || '';
if (treeTransport !== 'local-folder-events') {
document.documentElement.setAttribute('data-mnote-local-folder-watch-applied', 'static');
document.documentElement.setAttribute('data-mnote-local-folder-watch-disabled', 'events-required');
}
}
function isTitleOnlyDocumentPatch(candidate) {