refactor: remove excessive code, move script to app.js

This commit is contained in:
2025-10-13 11:19:13 +03:00
parent 305badf483
commit eafa0dc7d8
5 changed files with 113 additions and 171 deletions

View File

@@ -28,13 +28,13 @@
<div class="app-container">
<!-- Toggle Button Strip -->
<div class="toggle-strip">
<button class="toggle-btn active" id="toggle-snippets" title="Toggle Snippets Panel">
<button class="toggle-btn active" id="toggle-snippet-panel" title="Toggle Snippets Panel">
📄
</button>
<button class="toggle-btn active" id="toggle-editor" title="Toggle Editor Panel">
<button class="toggle-btn active" id="toggle-editor-panel" title="Toggle Editor Panel">
✏️
</button>
<button class="toggle-btn active" id="toggle-preview" title="Toggle Preview Panel">
<button class="toggle-btn active" id="toggle-preview-panel" title="Toggle Preview Panel">
👁️
</button>
</div>
@@ -130,107 +130,6 @@
<script src="src/js/panel-manager.js"></script>
<script src="src/js/editor.js"></script>
<script src="src/js/app.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
// Initialize snippet storage and render list
initializeSnippetsStorage();
// Initialize sort controls
initializeSortControls();
// Initialize search controls
initializeSearchControls();
renderSnippetList();
// Load saved layout
loadLayoutFromStorage();
// Initialize resize functionality
initializeResize();
// Initialize Monaco Editor
require.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.47.0/min/vs' } });
require(['vs/editor/editor.main'], async function () {
// Fetch actual Vega-Lite schema JSON for better validation
let vegaLiteSchema;
try {
const response = await fetch('https://vega.github.io/schema/vega-lite/v5.json');
vegaLiteSchema = await response.json();
} catch (error) {
vegaLiteSchema = null;
}
// Configure JSON language with actual schema
if (vegaLiteSchema) {
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true,
schemas: [{
uri: "https://vega.github.io/schema/vega-lite/v5.json",
fileMatch: ["*"], // Associate with all files
schema: vegaLiteSchema
}]
});
}
// Load Vega libraries before creating editor
await loadVegaLibraries();
// Create the editor with improved configuration
editor = monaco.editor.create(document.getElementById('monaco-editor'), {
value: JSON.stringify(sampleSpec, null, 2),
language: 'json',
theme: 'vs-light',
fontSize: 12,
minimap: { enabled: false },
scrollBeyondLastLine: false,
automaticLayout: true,
wordWrap: 'on',
formatOnPaste: true,
formatOnType: true
});
// Add debounced auto-render on editor change
editor.onDidChangeModelContent(() => {
debouncedRender();
});
// Initial render
renderVisualization();
// Initialize auto-save functionality
initializeAutoSave();
});
// Enhanced toggle functionality with memory and expansion
const toggleButtons = document.querySelectorAll('.toggle-btn');
toggleButtons.forEach(button => {
button.addEventListener('click', function () {
const panelId = this.id.replace('toggle-', ''); // Remove 'toggle-' prefix
togglePanel(panelId);
});
});
// Snippet selection is now handled by snippet-manager.js
// Header link handlers
const headerLinks = document.querySelectorAll('.header-link');
headerLinks.forEach(link => {
link.addEventListener('click', function () {
const linkText = this.textContent.trim();
switch (linkText) {
case 'Import':
case 'Export':
case 'Help':
// TODO: Implement in future phases
break;
}
});
});
});
</script>
</body>
</html>