Repository navigation
Quick Start
CodeLab can be installed from npm with Bun or Node, imported into any modern bundler, or loaded directly in static HTML from a CDN with zero build configuration.
Install the package in your project:
bun add @innovatorved/code-lab
# or
npm install @innovatorved/code-labTo use CodeLab without a bundler, load either the full IDE workbench or the standalone lightweight SQL editor from jsDelivr:
<!-- Full Browser IDE Workbench -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@innovatorved/code-lab@0.8.0/dist/code-lab.css" />
<script src="https://cdn.jsdelivr.net/npm/@innovatorved/code-lab@0.8.0/dist/code-lab.js"></script>
<!-- Standalone Lightweight SQL Editor (~17 KB gzipped) -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@innovatorved/code-lab@0.8.0/dist/code-lab-sql.css" />
<script src="https://cdn.jsdelivr.net/npm/@innovatorved/code-lab@0.8.0/dist/code-lab-sql.umd.js"></script>Mount a multi-file workbench into any DOM container. JavaScript, Node.js, and Bun run out of the box with no extra setup:
import CodeLab from '@innovatorved/code-lab';
import '@innovatorved/code-lab/code-lab.css';
const lab = CodeLab.mount('#editor', {
id: 'http-rate-limiter',
title: 'HTTP Rate Limiter',
mode: 'sandbox',
language: 'js',
entry: 'server.js',
files: {
'server.js': `const server = Bun.serve({
port: 3000,
fetch() {
return Response.json({ status: 'ok', time: Date.now() });
}
});
console.log('Listening on http://localhost:' + server.port);
`
}
});For interactive articles, documentation pages, or standalone SQL playgrounds, import the dedicated SQL entrypoint so pages stay fast without booting the full multi-file IDE:
import { createSqlEditor } from '@innovatorved/code-lab/sql';
import '@innovatorved/code-lab/sql.css';
const sqlEditor = createSqlEditor(document.getElementById('sql-block')!, {
mode: 'inline',
dialect: 'postgres',
value: 'SELECT id, email FROM customers ORDER BY id LIMIT 10;',
async onRun({ effectiveSql }) {
console.log('Running SQL:', effectiveSql);
}
});Read the SQL Playground & Inline Editor guide for schema-aware autocomplete, formatting, and error diagnostics.
Additional language toolchains and the step-by-step challenge engine are opt-in extensions so your base bundle only loads what your page needs:
import CodeLab from '@innovatorved/code-lab';
import '@innovatorved/code-lab/code-lab.css';
import { typescriptExtension } from '@innovatorved/code-lab/extensions/typescript';
import { cppExtension } from '@innovatorved/code-lab/extensions/cpp';
import { pythonExtension } from '@innovatorved/code-lab/extensions/python';
import { guidedLabExtension } from '@innovatorved/code-lab/extensions/guided-lab';
const lab = CodeLab.mount('#editor', {
id: 'dsa-binary-search',
title: 'Binary Search',
language: 'cpp'
})
.use(typescriptExtension)
.use((wb) => cppExtension(wb, { std: 'c++20', cacheInIndexedDB: true }))
.use((wb) => pythonExtension(wb, { cacheInIndexedDB: true }))
.use((wb) =>
guidedLabExtension(wb, {
starterFiles: { 'src/solution.js': 'module.exports = { search: () => -1 };\n' },
cppStarterFiles: {
'src/solution.hpp': '#pragma once\n#include <bits/stdc++.h>\nint search(const std::vector<int>& nums, int target) { return -1; }\n',
'src/test.cpp': '#include <codelab/test.hpp>\n#include "solution.hpp"\nint main() {\n DESCRIBE("Binary Search", {\n TEST("finds target", { ASSERT_EQ(search({-1, 0, 3, 5, 9, 12}, 9), 4); });\n });\n return CODELAB_TEST_EXIT_CODE();\n}\n'
},
steps: [
{
id: 'step-1',
title: 'Implement O(log N) binary search',
targetFile: 'src/solution.hpp',
instructions: 'Return the index of target in nums, or -1 if absent.',
testNames: ['finds target']
}
]
})
);To teach real Linux instead of the simulated shell, add linuxExtension from @innovatorved/code-lab/extensions/linux and set lang: 'sh'. It boots an Alpine machine in the browser; the Real Linux Terminal guide covers step checks and hosting the image.
CodeLab also registers a custom HTML element for embedding sandboxes directly inside Markdown or static pages:
<code-lab mode="sandbox" language="js" style="height: 600px;">
<script type="application/json">
{
"id": "quick-demo",
"title": "Token Bucket Demo",
"entry": "demo.js",
"files": {
"demo.js": "console.log('Hello from the CodeLab custom element!');"
}
}
</script>
</code-lab>CodeLab v0.8.0 · GitHub Repository · Live Cloud IDE · MIT © Ved Gupta
Getting Started
Workbench & Runtimes
- Workbench Configuration
- Runtime APIs
- POSIX Shell & Coreutils
- Real Linux Terminal
- HTTP Servers & Networking
- Headless Runtime
Extensibility & Architecture