refactor: extract conflict panel host mount helper
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user