refactor: delegate filetree upload fallback

This commit is contained in:
lix-2026
2026-05-25 02:55:45 +08:00
parent 3b8445ffab
commit fa3dc76d53
3 changed files with 49 additions and 1 deletions
@@ -120,6 +120,35 @@ function fileTreeChildCount(documentId, deps) {
return children.length;
}
function fileTreeUploadTargetFallback(detail, deps) {
detail = detail || {};
deps = deps || {};
var resolveWorkspaceId = typeof deps.resolveWorkspaceId === 'function' ? deps.resolveWorkspaceId : function() { return ''; };
var currentDocumentId = typeof deps.currentDocumentId === 'function' ? deps.currentDocumentId : function() { return ''; };
var workspaceId = String(detail.workspaceId || resolveWorkspaceId(document.body) || '').trim();
var documentId = String(detail.documentId || currentDocumentId() || '').trim();
if (Object.prototype.hasOwnProperty.call(detail, 'targetRelativePath')) {
return {
workspaceId: workspaceId,
targetDocumentId: documentId,
targetMindmapId: null,
targetSubPath: null,
targetRelativePath: String(detail.targetRelativePath || ''),
uploadIntent: String(detail.uploadIntent || 'filetree.folder.drop')
};
}
if (!workspaceId || !documentId) {
throw new Error('请选择一个目标页面后再拖入文件');
}
return {
workspaceId: workspaceId,
targetDocumentId: documentId,
targetMindmapId: null,
targetSubPath: null,
uploadIntent: String(detail.uploadIntent || 'editor.markdown.attach')
};
}
window.__mnoteFileTreeRuntime = {
fileTreeRowKind: fileTreeRowKind,
fileTreeRowDocumentId: fileTreeRowDocumentId,
@@ -131,5 +160,6 @@ window.__mnoteFileTreeRuntime = {
isFileTreeDownloadableRow: isFileTreeDownloadableRow,
fileTreeAssetDownloadDetail: fileTreeAssetDownloadDetail,
fileTreeRowsByRowIds: fileTreeRowsByRowIds,
fileTreeChildCount: fileTreeChildCount
fileTreeChildCount: fileTreeChildCount,
fileTreeUploadTargetFallback: fileTreeUploadTargetFallback
};
@@ -3093,6 +3093,13 @@ const SIDEBAR_TREE_JS: &str = r##"
}
function fallbackFileTreeUploadTarget(detail) {
var runtimeFn = fileTreeRuntimeFunction('fileTreeUploadTargetFallback');
if (runtimeFn) {
return runtimeFn(detail || {}, {
resolveWorkspaceId: resolveWorkspaceId,
currentDocumentId: currentDocumentId
});
}
var workspaceId = String(detail && detail.workspaceId || resolveWorkspaceId(document.body) || '').trim();
var documentId = String(detail && detail.documentId || currentDocumentId() || '').trim();
if (detail && Object.prototype.hasOwnProperty.call(detail, 'targetRelativePath')) {
@@ -11031,6 +11038,7 @@ mod tests {
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('fileTreeAssetDownloadDetail')"));
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('fileTreeRowsByRowIds')"));
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('fileTreeChildCount')"));
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('fileTreeUploadTargetFallback')"));
let document_id_body = js_function_body(SIDEBAR_TREE_JS, "fileTreeRowDocumentId");
assert!(
document_id_body.contains("data-document-id")
@@ -11050,6 +11058,11 @@ mod tests {
assert!(FILETREE_RUNTIME_JS.contains("function fileTreeAssetDownloadDetail"));
assert!(FILETREE_RUNTIME_JS.contains("function fileTreeRowsByRowIds"));
assert!(FILETREE_RUNTIME_JS.contains("function fileTreeChildCount"));
assert!(FILETREE_RUNTIME_JS.contains("function fileTreeUploadTargetFallback"));
assert!(FILETREE_RUNTIME_JS
.contains("uploadIntent: String(detail.uploadIntent || 'filetree.folder.drop')"));
assert!(FILETREE_RUNTIME_JS
.contains("uploadIntent: String(detail.uploadIntent || 'editor.markdown.attach')"));
}
#[test]