mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2025-12-21 21:22:25 +00:00
feat: add StorageManager, VisualizationManager, UIManager, EditorManager, and update PanelResizer for improved snippet handling and visualization
This commit is contained in:
44
src/UIManager.js
Normal file
44
src/UIManager.js
Normal file
@@ -0,0 +1,44 @@
|
||||
export class UIManager {
|
||||
constructor(snippetManager) {
|
||||
this.snippetManager = snippetManager;
|
||||
this.setupEventListeners();
|
||||
}
|
||||
|
||||
setupEventListeners() {
|
||||
document.getElementById('new-snippet').onclick = () => this.snippetManager.createNewSnippet();
|
||||
document.getElementById('save-snippet').onclick = () => this.snippetManager.saveCurrentSnippet();
|
||||
document.getElementById('version-switch').onclick = () => {
|
||||
this.snippetManager.loadSnippet(this.snippetManager.currentSnippetId, !this.snippetManager.isDraftVersion);
|
||||
};
|
||||
}
|
||||
|
||||
renderSnippetList(snippets, currentSnippetId) {
|
||||
const container = document.getElementById('snippet-list');
|
||||
container.innerHTML = '';
|
||||
|
||||
snippets.forEach(snippet => {
|
||||
const div = document.createElement('div');
|
||||
div.className = `snippet-item ${snippet.id === currentSnippetId ? 'active' : ''}`;
|
||||
const hasChanges = this.snippetManager.hasDraftChanges(snippet.id);
|
||||
const indicator = hasChanges ? '🟡' : '🟢';
|
||||
div.textContent = `${indicator} ${snippet.name}`;
|
||||
div.onclick = () => this.snippetManager.loadSnippet(snippet.id);
|
||||
container.appendChild(div);
|
||||
});
|
||||
}
|
||||
|
||||
updateSaveButton(hasUnsavedChanges) {
|
||||
const saveButton = document.getElementById('save-snippet');
|
||||
saveButton.disabled = !hasUnsavedChanges;
|
||||
}
|
||||
|
||||
updateVersionSwitch(currentSnippetId, isDraftVersion, hasDraftChanges) {
|
||||
const versionSwitch = document.getElementById('version-switch');
|
||||
if (!versionSwitch) return;
|
||||
|
||||
versionSwitch.style.display = hasDraftChanges ? 'block' : 'none';
|
||||
versionSwitch.textContent = isDraftVersion ?
|
||||
'View Saved Version (Read-only)' :
|
||||
'Switch to Draft Version (Editable)';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user