refactor: extract conflict panel host mount helper

This commit is contained in:
lix-2026
2026-05-25 08:38:05 +08:00
parent f33807eacc
commit 0245b09301
3 changed files with 45 additions and 4 deletions
@@ -17,12 +17,29 @@ function clearSessionConflictSurface(session, deps) {
? deps.sessionViews(session)
: [];
views.forEach(function(view) {
var host = view.runtimeDescriptor.root.closest('.document-pane') || view.runtimeDescriptor.root;
var host = conflictPanelHost(view && view.runtimeDescriptor && view.runtimeDescriptor.root);
if (!(host instanceof HTMLElement)) return;
host.querySelectorAll('[data-testid="mnote-editor-conflict-panel"]').forEach(function(node) { node.remove(); });
});
}
function conflictPanelHost(root) {
if (!(root instanceof Element)) return null;
return root.closest('.document-pane') || root;
}
function mountSessionConflictPanel(root, panel) {
var host = conflictPanelHost(root);
if (!(host instanceof HTMLElement) || !(panel instanceof HTMLElement)) return false;
var header = host.querySelector('.document-shell-header');
if (header && header.parentNode) {
header.parentNode.insertBefore(panel, header.nextSibling);
} else {
host.prepend(panel);
}
return true;
}
function createSessionConflictPanel(session, message, deps) {
deps = deps || {};
var externalConflictMessage = String(deps.externalConflictMessage || '').trim() || '文件已在外部修改';
@@ -185,6 +202,7 @@ function runSessionConflictAction(action, deps) {
window.__mnoteDocumentConflictPanelRuntime = {
clearSessionConflictSurface: clearSessionConflictSurface,
createSessionConflictPanel: createSessionConflictPanel,
mountSessionConflictPanel: mountSessionConflictPanel,
populateSessionConflictDiffPanel: populateSessionConflictDiffPanel,
runSessionConflictAction: runSessionConflictAction
};