refactor: extract conflict panel dom helper
This commit is contained in:
@@ -23,6 +23,65 @@ function clearSessionConflictSurface(session, deps) {
|
||||
});
|
||||
}
|
||||
|
||||
function createSessionConflictPanel(session, message, deps) {
|
||||
deps = deps || {};
|
||||
var externalConflictMessage = String(deps.externalConflictMessage || '').trim() || '文件已在外部修改';
|
||||
var panel = document.createElement('section');
|
||||
panel.className = 'mnote-editor-conflict-panel';
|
||||
panel.setAttribute('data-testid', 'mnote-editor-conflict-panel');
|
||||
panel.setAttribute('role', 'status');
|
||||
panel.setAttribute('aria-live', 'polite');
|
||||
|
||||
var heading = document.createElement('h2');
|
||||
heading.textContent = '文件冲突';
|
||||
var text = document.createElement('p');
|
||||
text.textContent = message || externalConflictMessage;
|
||||
var meta = document.createElement('div');
|
||||
meta.className = 'mnote-conflict-meta';
|
||||
var fileLabel = session && session.sessionKind === 'resource'
|
||||
? String(session.rootUri || '') + '/' + String(session.resourcePath || session.documentId || '')
|
||||
: String(session && (session.rootUri || session.documentId) || '');
|
||||
var sourceLabel = typeof deps.conflictSourceLabel === 'function'
|
||||
? deps.conflictSourceLabel(session)
|
||||
: '';
|
||||
meta.textContent = '文件:' + fileLabel + ' · 来源:' + (sourceLabel || '本地文件变更');
|
||||
|
||||
var actions = document.createElement('div');
|
||||
actions.className = 'mnote-conflict-actions';
|
||||
var acceptDisk = document.createElement('button');
|
||||
acceptDisk.type = 'button';
|
||||
acceptDisk.textContent = '接受磁盘版本';
|
||||
acceptDisk.setAttribute('data-testid', 'mnote-conflict-accept-disk');
|
||||
var keepCurrent = document.createElement('button');
|
||||
keepCurrent.type = 'button';
|
||||
keepCurrent.textContent = '保留当前编辑器版本';
|
||||
keepCurrent.setAttribute('data-testid', 'mnote-conflict-keep-current');
|
||||
var openDiff = document.createElement('button');
|
||||
openDiff.type = 'button';
|
||||
openDiff.textContent = '打开 diff';
|
||||
openDiff.setAttribute('data-testid', 'mnote-conflict-open-diff');
|
||||
actions.append(acceptDisk, keepCurrent, openDiff);
|
||||
|
||||
var diffPanel = document.createElement('div');
|
||||
diffPanel.className = 'mnote-conflict-diff-panel';
|
||||
diffPanel.setAttribute('data-testid', 'mnote-conflict-diff-panel');
|
||||
diffPanel.hidden = true;
|
||||
panel.append(heading, text, meta, actions, diffPanel);
|
||||
|
||||
acceptDisk.addEventListener('click', function() {
|
||||
if (typeof deps.onAcceptDisk === 'function') deps.onAcceptDisk(session, panel);
|
||||
});
|
||||
keepCurrent.addEventListener('click', function() {
|
||||
if (typeof deps.onKeepCurrent === 'function') deps.onKeepCurrent(session, panel);
|
||||
});
|
||||
openDiff.addEventListener('click', function() {
|
||||
if (typeof deps.onOpenDiff === 'function') deps.onOpenDiff(session, panel);
|
||||
});
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
window.__mnoteDocumentConflictPanelRuntime = {
|
||||
clearSessionConflictSurface: clearSessionConflictSurface
|
||||
clearSessionConflictSurface: clearSessionConflictSurface,
|
||||
createSessionConflictPanel: createSessionConflictPanel
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user