refactor: extract filetree preflight helpers
This commit is contained in:
@@ -371,6 +371,94 @@ function fileTreeUploadTargetFallback(detail, deps) {
|
||||
};
|
||||
}
|
||||
|
||||
function fileTreeRowsForUploadPreflight(deps) {
|
||||
deps = deps || {};
|
||||
var fileTreeRowKind = typeof deps.fileTreeRowKind === 'function' ? deps.fileTreeRowKind : function(row) {
|
||||
return row instanceof HTMLElement ? String(row.getAttribute('data-row-kind') || '').trim() : '';
|
||||
};
|
||||
var fileTreeRowDocumentId = typeof deps.fileTreeRowDocumentId === 'function' ? deps.fileTreeRowDocumentId : function(row) {
|
||||
return row instanceof HTMLElement ? String(row.getAttribute('data-document-id') || row.getAttribute('data-doc-id') || '').trim() : '';
|
||||
};
|
||||
var fileTreeRowAssetId = typeof deps.fileTreeRowAssetId === 'function' ? deps.fileTreeRowAssetId : function(row) {
|
||||
return row instanceof HTMLElement ? String(row.getAttribute('data-asset-id') || '').trim() : '';
|
||||
};
|
||||
return Array.from(document.querySelectorAll('.tree-row[data-shell-mode="filetree"]')).map(function(row) {
|
||||
var documentId = fileTreeRowDocumentId(row);
|
||||
var assetId = fileTreeRowAssetId(row) || null;
|
||||
var badge = row.querySelector('.tree-kind-badge');
|
||||
return {
|
||||
rowId: row.getAttribute('data-row-id') || '',
|
||||
rowKind: fileTreeRowKind(row),
|
||||
documentId: documentId || null,
|
||||
assetId: assetId,
|
||||
assetDocumentId: documentId || null,
|
||||
assetType: badge ? badge.getAttribute('data-kind') : null,
|
||||
storagePath: null
|
||||
};
|
||||
}).filter(function(row) {
|
||||
return row.rowId || row.documentId || row.assetId;
|
||||
});
|
||||
}
|
||||
|
||||
function fileTreeDocumentParentsForPreflight(deps) {
|
||||
deps = deps || {};
|
||||
var fileTreeRowDocumentId = typeof deps.fileTreeRowDocumentId === 'function' ? deps.fileTreeRowDocumentId : function(row) {
|
||||
return row instanceof HTMLElement ? String(row.getAttribute('data-document-id') || row.getAttribute('data-doc-id') || '').trim() : '';
|
||||
};
|
||||
return Array.from(document.querySelectorAll('#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"]')).map(function(row) {
|
||||
var documentId = fileTreeRowDocumentId(row);
|
||||
if (!documentId) return null;
|
||||
var parentRowId = row.getAttribute('data-parent-id') || '';
|
||||
var parentDocumentId = parentRowId.indexOf('doc:') === 0 ? parentRowId.slice(4) : parentRowId || null;
|
||||
return { documentId: documentId, parentId: parentDocumentId };
|
||||
}).filter(Boolean);
|
||||
}
|
||||
|
||||
function fileTreeTargetChildrenForPreflight(targetRow, deps) {
|
||||
deps = deps || {};
|
||||
var fileTreeRowKind = typeof deps.fileTreeRowKind === 'function' ? deps.fileTreeRowKind : function(row) {
|
||||
return row instanceof HTMLElement ? String(row.getAttribute('data-row-kind') || '').trim() : '';
|
||||
};
|
||||
var fileTreeRowDocumentId = typeof deps.fileTreeRowDocumentId === 'function' ? deps.fileTreeRowDocumentId : function(row) {
|
||||
return row instanceof HTMLElement ? String(row.getAttribute('data-document-id') || row.getAttribute('data-doc-id') || '').trim() : '';
|
||||
};
|
||||
var fileTreeRowAssetId = typeof deps.fileTreeRowAssetId === 'function' ? deps.fileTreeRowAssetId : function(row) {
|
||||
return row instanceof HTMLElement ? String(row.getAttribute('data-asset-id') || '').trim() : '';
|
||||
};
|
||||
var rowTitle = typeof deps.rowTitle === 'function' ? deps.rowTitle : function(row) {
|
||||
if (!(row instanceof HTMLElement)) return '';
|
||||
var titleNode = row.querySelector('.tree-link-title');
|
||||
return String(titleNode && titleNode.textContent || row.getAttribute('title') || '').trim();
|
||||
};
|
||||
var node = targetRow instanceof HTMLElement ? targetRow.closest('.tree-node') : null;
|
||||
if (!node) return [];
|
||||
return Array.from(node.querySelectorAll(':scope > .tree-children > .tree-node > .tree-row[data-shell-mode="filetree"]')).map(function(row) {
|
||||
return {
|
||||
rowKind: fileTreeRowKind(row),
|
||||
documentId: fileTreeRowDocumentId(row) || null,
|
||||
assetId: fileTreeRowAssetId(row) || null,
|
||||
title: rowTitle(row)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function fileTreeDropPreflightRows(deps) {
|
||||
deps = deps || {};
|
||||
var cssEscape = typeof deps.cssEscape === 'function' ? deps.cssEscape : function(value) { return String(value).replace(/["\\]/g, '\\$&'); };
|
||||
var rowTitle = typeof deps.rowTitle === 'function' ? deps.rowTitle : function(row) {
|
||||
if (!(row instanceof HTMLElement)) return '';
|
||||
var titleNode = row.querySelector('.tree-link-title');
|
||||
return String(titleNode && titleNode.textContent || row.getAttribute('title') || '').trim();
|
||||
};
|
||||
var rows = typeof deps.fileTreeRowsForUploadPreflight === 'function'
|
||||
? deps.fileTreeRowsForUploadPreflight()
|
||||
: fileTreeRowsForUploadPreflight(deps);
|
||||
return rows.map(function(row) {
|
||||
var domRow = document.querySelector('#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"][data-row-id="' + cssEscape(row.rowId) + '"]');
|
||||
return Object.assign({}, row, { title: rowTitle(domRow) });
|
||||
});
|
||||
}
|
||||
|
||||
window.__mnoteFileTreeRuntime = {
|
||||
readProjection: readProjection,
|
||||
readSidebarDataset: readSidebarDataset,
|
||||
@@ -400,5 +488,9 @@ window.__mnoteFileTreeRuntime = {
|
||||
revealFileTreeRow: revealFileTreeRow,
|
||||
revealFileTreeAssetRow: revealFileTreeAssetRow,
|
||||
appendUploadedAssetRow: appendUploadedAssetRow,
|
||||
fileTreeUploadTargetFallback: fileTreeUploadTargetFallback
|
||||
fileTreeUploadTargetFallback: fileTreeUploadTargetFallback,
|
||||
fileTreeRowsForUploadPreflight: fileTreeRowsForUploadPreflight,
|
||||
fileTreeDocumentParentsForPreflight: fileTreeDocumentParentsForPreflight,
|
||||
fileTreeTargetChildrenForPreflight: fileTreeTargetChildrenForPreflight,
|
||||
fileTreeDropPreflightRows: fileTreeDropPreflightRows
|
||||
};
|
||||
|
||||
@@ -2966,6 +2966,8 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
});
|
||||
|
||||
function fileTreeRowsForUploadPreflight() {
|
||||
var runtimeFn = fileTreeRuntimeFunction('fileTreeRowsForUploadPreflight');
|
||||
if (runtimeFn) return runtimeFn(fileTreeRuntimeDeps());
|
||||
return Array.from(document.querySelectorAll('.tree-row[data-shell-mode="filetree"]')).map(function(row) {
|
||||
return {
|
||||
rowId: row.getAttribute('data-row-id') || '',
|
||||
@@ -3031,6 +3033,8 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
}
|
||||
|
||||
function fileTreeDocumentParentsForPreflight() {
|
||||
var runtimeFn = fileTreeRuntimeFunction('fileTreeDocumentParentsForPreflight');
|
||||
if (runtimeFn) return runtimeFn(fileTreeRuntimeDeps());
|
||||
return Array.from(document.querySelectorAll('#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"]')).map(function(row) {
|
||||
var documentId = row.getAttribute('data-document-id') || row.getAttribute('data-doc-id') || '';
|
||||
if (!documentId) return null;
|
||||
@@ -3041,6 +3045,8 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
}
|
||||
|
||||
function fileTreeTargetChildrenForPreflight(targetRow) {
|
||||
var runtimeFn = fileTreeRuntimeFunction('fileTreeTargetChildrenForPreflight');
|
||||
if (runtimeFn) return runtimeFn(targetRow, fileTreeRuntimeDeps());
|
||||
var node = targetRow instanceof HTMLElement ? targetRow.closest('.tree-node') : null;
|
||||
if (!node) return [];
|
||||
return Array.from(node.querySelectorAll(':scope > .tree-children > .tree-node > .tree-row[data-shell-mode="filetree"]')).map(function(row) {
|
||||
@@ -3054,6 +3060,10 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
}
|
||||
|
||||
function fileTreeDropPreflightRows() {
|
||||
var runtimeFn = fileTreeRuntimeFunction('fileTreeDropPreflightRows');
|
||||
if (runtimeFn) return runtimeFn(Object.assign({}, fileTreeRuntimeDeps(), {
|
||||
fileTreeRowsForUploadPreflight: fileTreeRowsForUploadPreflight
|
||||
}));
|
||||
return fileTreeRowsForUploadPreflight().map(function(row) {
|
||||
var domRow = document.querySelector('#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"][data-row-id="' + cssEscape(row.rowId) + '"]');
|
||||
row.title = rowTitle(domRow);
|
||||
@@ -11099,6 +11109,14 @@ mod tests {
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('revealFileTreeAssetRow')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('appendUploadedAssetRow')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('fileTreeUploadTargetFallback')"));
|
||||
assert!(
|
||||
SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('fileTreeRowsForUploadPreflight')")
|
||||
);
|
||||
assert!(SIDEBAR_TREE_JS
|
||||
.contains("fileTreeRuntimeFunction('fileTreeDocumentParentsForPreflight')"));
|
||||
assert!(SIDEBAR_TREE_JS
|
||||
.contains("fileTreeRuntimeFunction('fileTreeTargetChildrenForPreflight')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('fileTreeDropPreflightRows')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('readProjection')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('readSidebarDataset')"));
|
||||
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('readDatasetProjection')"));
|
||||
@@ -11160,6 +11178,10 @@ mod tests {
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function revealFileTreeAssetRow"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function appendUploadedAssetRow"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function fileTreeUploadTargetFallback"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function fileTreeRowsForUploadPreflight"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function fileTreeDocumentParentsForPreflight"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function fileTreeTargetChildrenForPreflight"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function fileTreeDropPreflightRows"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function readProjection"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function readSidebarDataset"));
|
||||
assert!(FILETREE_RUNTIME_JS.contains("function readDatasetProjection"));
|
||||
@@ -11182,6 +11204,15 @@ mod tests {
|
||||
.contains("applyLocalFolderSidebarSnapshot: applyLocalFolderSidebarSnapshot"));
|
||||
assert!(FILETREE_RUNTIME_JS
|
||||
.contains("markLocalFolderWatchApplied: markLocalFolderWatchApplied"));
|
||||
assert!(FILETREE_RUNTIME_JS
|
||||
.contains("fileTreeRowsForUploadPreflight: fileTreeRowsForUploadPreflight"));
|
||||
assert!(FILETREE_RUNTIME_JS
|
||||
.contains("fileTreeDocumentParentsForPreflight: fileTreeDocumentParentsForPreflight"));
|
||||
assert!(FILETREE_RUNTIME_JS
|
||||
.contains("fileTreeTargetChildrenForPreflight: fileTreeTargetChildrenForPreflight"));
|
||||
assert!(
|
||||
FILETREE_RUNTIME_JS.contains("fileTreeDropPreflightRows: fileTreeDropPreflightRows")
|
||||
);
|
||||
assert!(FILETREE_RUNTIME_JS
|
||||
.contains("uploadIntent: String(detail.uploadIntent || 'filetree.folder.drop')"));
|
||||
assert!(FILETREE_RUNTIME_JS
|
||||
|
||||
Reference in New Issue
Block a user