refactor: normalize filetree upload target plans
This commit is contained in:
@@ -371,6 +371,22 @@ function fileTreeUploadTargetFallback(detail, deps) {
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeFileTreeUploadTargetPlan(detail, plan) {
|
||||
detail = detail || {};
|
||||
plan = plan && typeof plan === 'object' ? Object.assign({}, plan) : {};
|
||||
if (Object.prototype.hasOwnProperty.call(detail, 'targetRelativePath')) {
|
||||
plan.targetRelativePath = String(detail.targetRelativePath || '');
|
||||
}
|
||||
if (detail.uploadIntent) {
|
||||
plan.uploadIntent = String(detail.uploadIntent);
|
||||
} else if (Object.prototype.hasOwnProperty.call(detail, 'targetRelativePath')) {
|
||||
plan.uploadIntent = 'filetree.folder.drop';
|
||||
} else if (!plan.uploadIntent) {
|
||||
plan.uploadIntent = 'editor.markdown.attach';
|
||||
}
|
||||
return plan;
|
||||
}
|
||||
|
||||
function fileTreeRowsForUploadPreflight(deps) {
|
||||
deps = deps || {};
|
||||
var fileTreeRowKind = typeof deps.fileTreeRowKind === 'function' ? deps.fileTreeRowKind : function(row) {
|
||||
@@ -489,6 +505,7 @@ window.__mnoteFileTreeRuntime = {
|
||||
revealFileTreeAssetRow: revealFileTreeAssetRow,
|
||||
appendUploadedAssetRow: appendUploadedAssetRow,
|
||||
fileTreeUploadTargetFallback: fileTreeUploadTargetFallback,
|
||||
normalizeFileTreeUploadTargetPlan: normalizeFileTreeUploadTargetPlan,
|
||||
fileTreeRowsForUploadPreflight: fileTreeRowsForUploadPreflight,
|
||||
fileTreeDocumentParentsForPreflight: fileTreeDocumentParentsForPreflight,
|
||||
fileTreeTargetChildrenForPreflight: fileTreeTargetChildrenForPreflight,
|
||||
|
||||
@@ -3188,6 +3188,10 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
}
|
||||
try {
|
||||
var plan = await preflightFileTreeUploadTarget(detail || {});
|
||||
var normalizePlanRuntime = fileTreeRuntimeFunction('normalizeFileTreeUploadTargetPlan');
|
||||
if (normalizePlanRuntime) {
|
||||
return normalizePlanRuntime(detail || {}, plan);
|
||||
}
|
||||
if (detail && Object.prototype.hasOwnProperty.call(detail, 'targetRelativePath')) {
|
||||
plan.targetRelativePath = String(detail.targetRelativePath || '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user