- Technical Deep Dive
- Frontend Code Reference
Technical Deep Dive
Frontend Code Reference
Component-level documentation for the SvelteKit application, including stores, modals, and editor integration.
Frontend Code Reference
The front-end is a SvelteKit single-page application that lives entirely under frontend/. Vite handles development bundling and production builds. This document examines the most important components and patterns.
1. Editor Integration
1.1 lib/components/MonacoEditor.svelte
<script lang="ts">
import { onMount, onDestroy } from "svelte";
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";
export let value = "";
export let language = "python";
export let theme = "vs-dark";
let editor: monaco.editor.IStandaloneCodeEditor;
onMount(() => {
editor = monaco.editor.create(editorContainer, {
value,
language,
theme,
automaticLayout: true,
minimap: { enabled: false }
});
});
onDestroy(() => editor?.dispose());
</script>
<div bind:this={editorContainer} class="w-full h-full" />
Highlights:
- Uses
automaticLayoutto handle resize events from the split-pane container. - Exposes
valuevia two-way binding to parent components. - Language changes trigger
monaco.editor.setModelLanguagefor syntax highlighting.
1.2 Python Completions
lib/pythonLanguageFeatures.ts registers statically defined snippets. Example:
monaco.languages.registerCompletionItemProvider("python", {
provideCompletionItems() {
return {
suggestions: [
{
label: "pl.scan_parquet",
kind: monaco.languages.CompletionItemKind.Function,
insertText: "pl.scan_parquet(\"${1:path}\")",
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet
}
]
};
}
});
2. Workspace Layout (Route +page.svelte)
The default route / hosts the entire workspace. Key reactive variables:
let tabs: Tab[] = [homeTab]; // each { name, language, value, output, dirty }
let activeTab = 0;
let datasets: DatasetMeta[] = [];
Drag-and-drop reordering is implemented via native HTML5 DnD (handleDragStart, handleDragOver), avoiding external libraries.
Execution flow:
- User presses
⌘↵or clicks Run. executeCode()builds payload{ code, language }and callsapi.fetchApi("/execute", …).- Response
stdoutis appended totabs[activeTab].output. saveCodeVersion()persists snapshot when execution completes.
3. Dataset Management Components
3.1 DataImportModal.svelte
Handles drag-drop as well as file picker. Prior to upload, it checks existence via HEAD /api/check-file.
const checkFileExists = async (fileName: string) => {
const res = await fetchApi(`/check-file?filename=${fileName}`);
return res.status === 200;
};
If a file collision occurs, the user is prompted to overwrite.
3.2 DataframeView.svelte
- Paginated table rendering using native
<table>(no DataTables dependency). - Automatically right-aligns numeric columns via
isNumeric()helper. - Fetches data via
GET /api/dataset/datawith offset/limit props.
4. Version History Component
VersionHistory.svelte consumes GET /api/list-versions/<tab> and lazy-loads file contents only when the accordion row is expanded (loadVersion). It dispatches a loadVersion custom event; the parent RightSidebar listens and replaces the active tab’s code buffer.
5. Global Stores
navigation.ts– ContainshasUnsavedChangesused for ConfirmNavigationModal.editorStore.ts– Ring-buffer of recently closed tabs (createClosedTabsStore). Enables Restore Tab (⌘⇧T) functionality.
6. Styling
Tailwind is configured via tailwind.config.ts with JIT mode. PostCSS plugins (postcss.config.js) ensure vendor prefixing.
7. Hotkeys Cheat-Sheet
Implemented inside +page.svelte::handleKeyboardShortcut:
| Shortcut | Action |
|---|---|
| Cmd/Ctrl + Enter | Execute current file |
| Cmd/Ctrl + Shift + P | New Python tab |
| Cmd/Ctrl + Shift + L | New SQL tab |
| Cmd/Ctrl + Shift + B | New Bokeh tab |
| Cmd/Ctrl + S | Save context file |
| Cmd/Ctrl + E | Export current file |
8. Extending the Front-End
- Theme Switcher – Bind
editor.updateOptions({ theme })to a store and persist user preference. - Multi-cursor Execution – Evaluate only selected text by reading
editor.getSelection(). - Real-time Logs – Hook WebSocket output to an
OutputPane.sveltecomponent.
Conclusion
The SvelteKit front-end is concise (~3 500 LoC including templates) yet feature-rich thanks to strong composition and reactivity patterns. Combined with the Monaco editor, it delivers a desktop-grade coding experience directly in the browser.