feat: add snippet deletion functionality and enhance UI for snippet management

This commit is contained in:
2025-01-19 14:23:55 +02:00
parent 86058767a1
commit fe9e554cec
4 changed files with 74 additions and 3 deletions

View File

@@ -149,4 +149,22 @@ export class SnippetManager {
this.readOnlyMode = hasChanges && !this.isDraftVersion;
this.editorManager.updateReadOnlyState(this.readOnlyMode);
}
deleteSnippet(id) {
if (confirm('Are you sure you want to delete this snippet?')) {
this.snippets = this.snippets.filter(s => s.id !== id);
this.storageManager.saveSnippets(this.snippets);
if (this.currentSnippetId === id) {
this.currentSnippetId = null;
if (this.snippets.length > 0) {
this.loadSnippet(this.snippets[0].id);
} else {
this.editorManager.setValue('');
}
}
this.uiManager.renderSnippetList(this.snippets, this.currentSnippetId);
}
}
}

View File

@@ -19,10 +19,25 @@ export class UIManager {
snippets.forEach(snippet => {
const div = document.createElement('div');
div.className = `snippet-item ${snippet.id === currentSnippetId ? 'active' : ''}`;
div.onclick = () => this.snippetManager.loadSnippet(snippet.id);
const hasChanges = this.snippetManager.hasDraftChanges(snippet.id);
const indicator = hasChanges ? '🟡' : '🟢';
div.textContent = `${indicator} ${snippet.name}`;
div.onclick = () => this.snippetManager.loadSnippet(snippet.id);
const contentDiv = document.createElement('div');
contentDiv.className = 'snippet-content';
contentDiv.textContent = `${indicator} ${snippet.name}`;
div.appendChild(contentDiv);
const deleteButton = document.createElement('button');
deleteButton.className = 'delete-snippet';
deleteButton.innerHTML = '❌';
deleteButton.onclick = (e) => {
e.stopPropagation();
this.snippetManager.deleteSnippet(snippet.id);
};
div.appendChild(deleteButton);
container.appendChild(div);
});
}

148
src/styles.css Normal file
View File

@@ -0,0 +1,148 @@
#vis {
width: 100%;
height: 100%;
padding: 1rem;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
display: grid;
grid-template-columns: var(--snippet-width, 1fr) 5px var(--editor-width, 1fr) 5px var(--preview-width, 2fr);
height: 100vh;
background-color: #e0e0e0;
}
.panel {
background: white;
overflow-y: auto;
display: flex;
flex-direction: column;
}
.panel-header {
padding: 1rem;
border-bottom: 1px solid #e0e0e0;
display: flex;
justify-content: space-between;
align-items: center;
background: #f5f5f5;
}
.resize-handle {
background-color: #e0e0e0;
cursor: col-resize;
transition: background-color 0.2s;
}
.resize-handle:hover,
.resize-handle.active {
background-color: #2196F3;
}
.button {
padding: 0.5rem 1rem;
background: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
.button:hover {
background: #45a049;
}
.button:disabled {
background: #cccccc;
cursor: not-allowed;
}
.button.secondary {
background: #607D8B;
}
.button.secondary:hover {
background: #546E7A;
}
.snippet-list {
padding: 1rem;
flex-grow: 1;
}
.snippet-item {
padding: 0.75rem;
margin: 0.5rem 0;
background: #f5f5f5;
border-radius: 4px;
cursor: pointer;
transition: background 0.2s;
}
.snippet-item:hover {
background: #eeeeee;
}
.snippet-item.active {
background: #e3f2fd;
border-left: 4px solid #2196F3;
}
#monaco-editor {
height: 100%;
flex-grow: 1;
}
.preview-panel>*:not(.panel-header) {
padding: 1rem;
}
.editor-controls {
display: flex;
gap: 0.5rem;
align-items: center;
}
.snippet-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px;
cursor: pointer;
gap: 8px;
}
.snippet-item span {
cursor: pointer;
}
.snippet-content {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.delete-snippet {
opacity: 0.4;
font-size: 14px;
padding: 2px 4px;
background: none;
border: none;
cursor: pointer;
min-width: 24px;
}
.delete-snippet:hover {
opacity: 1;
}
.snippet-item:hover .delete-snippet {
opacity: 0.8;
}