@innovatorved/code-lab 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/ARCHITECTURE.md +11 -6
  2. package/CHANGELOG.md +40 -0
  3. package/README.md +18 -8
  4. package/dist/code-lab.css +198 -0
  5. package/dist/code-lab.d.ts +27 -9
  6. package/dist/code-lab.esm.js +8516 -84
  7. package/dist/code-lab.js +8514 -82
  8. package/dist/extensions/cpp.d.ts +40 -6
  9. package/dist/extensions/cpp.esm.js +1027 -7
  10. package/dist/extensions/cpp.js +1027 -7
  11. package/dist/extensions/guided-lab.esm.js +40 -2
  12. package/dist/extensions/guided-lab.js +40 -2
  13. package/dist/extensions/python.d.ts +92 -0
  14. package/dist/extensions/python.esm.js +5476 -0
  15. package/dist/extensions/python.js +5495 -0
  16. package/dist/index.d.ts +7 -4
  17. package/dist/preview-sw.js +1 -1
  18. package/dist/runtime/index.d.ts +4 -0
  19. package/dist/runtime/test-harness.d.ts +24 -0
  20. package/dist/runtime.esm.js +36 -4
  21. package/dist/runtime.js +36 -4
  22. package/dist/schemas.d.ts +137 -24
  23. package/dist/schemas.esm.js +44 -2
  24. package/dist/schemas.js +44 -2
  25. package/dist/shell/coreutils/compilers-cli.d.ts +24 -0
  26. package/dist/shell/index.d.ts +4 -0
  27. package/dist/shell.esm.js +113 -1
  28. package/dist/shell.js +113 -1
  29. package/dist/terminal.esm.js +1 -1
  30. package/dist/terminal.js +1 -1
  31. package/dist/workbench/command-palette.d.ts +10 -0
  32. package/dist/workbench/diff-editor.d.ts +26 -0
  33. package/dist/workbench/drawer.d.ts +18 -0
  34. package/dist/workbench/editor.d.ts +11 -0
  35. package/dist/workbench/file-tree.d.ts +11 -0
  36. package/dist/workbench/guided-pane.d.ts +11 -0
  37. package/dist/workbench/icons.d.ts +5 -0
  38. package/dist/workbench/index.d.ts +39 -0
  39. package/dist/workbench/share.d.ts +21 -0
  40. package/dist/workbench/styles.d.ts +4 -0
  41. package/dist/workbench/toolbar.d.ts +17 -0
  42. package/dist/workbench.d.ts +6 -1
  43. package/package.json +8 -2
  44. package/src/code-lab.css +198 -0
  45. package/src/extensions/cpp.ts +966 -5
  46. package/src/extensions/python.ts +1293 -0
  47. package/src/index.ts +35 -3
  48. package/src/runtime/index.ts +5 -0
  49. package/src/runtime/test-harness.ts +57 -0
  50. package/src/runtime.ts +35 -3
  51. package/src/schemas.ts +47 -2
  52. package/src/shell/coreutils/compilers-cli.ts +103 -0
  53. package/src/shell/index.ts +5 -0
  54. package/src/shell.ts +112 -0
  55. package/src/workbench/command-palette.ts +140 -0
  56. package/src/workbench/diff-editor.ts +216 -0
  57. package/src/workbench/drawer.ts +144 -0
  58. package/src/workbench/editor.ts +49 -0
  59. package/src/workbench/file-tree.ts +51 -0
  60. package/src/workbench/guided-pane.ts +33 -0
  61. package/src/workbench/icons.ts +48 -0
  62. package/src/workbench/index.ts +38 -0
  63. package/src/workbench/share.ts +99 -0
  64. package/src/workbench/styles.ts +200 -0
  65. package/src/workbench/toolbar.ts +171 -0
  66. package/src/workbench.ts +744 -69
@@ -0,0 +1,216 @@
1
+ /**
2
+ * @innovatorved/code-lab — Inline Monaco Side-by-Side Diff Editor & Fallback Unified Diff
3
+ */
4
+
5
+ import { CL_ICONS } from './icons';
6
+
7
+ export interface DiffComputeResult {
8
+ hunks: Array<{ type: 'context' | 'add' | 'del'; text: string; oldLine: number | null; newLine: number | null }>;
9
+ added: number;
10
+ removed: number;
11
+ }
12
+
13
+ export function computeSimpleDiff(oldText: string, newText: string): DiffComputeResult {
14
+ const oldLines = String(oldText || '').split('\n');
15
+ const newLines = String(newText || '').split('\n');
16
+ const hunks: Array<{ type: 'context' | 'add' | 'del'; text: string; oldLine: number | null; newLine: number | null }> = [];
17
+ let added = 0;
18
+ let removed = 0;
19
+
20
+ const m = oldLines.length;
21
+ const n = newLines.length;
22
+ let i = 0;
23
+ let j = 0;
24
+ let oldLineNum = 1;
25
+ let newLineNum = 1;
26
+
27
+ while (i < m && j < n) {
28
+ if (oldLines[i] === newLines[j]) {
29
+ hunks.push({ type: 'context', text: oldLines[i], oldLine: oldLineNum++, newLine: newLineNum++ });
30
+ i++;
31
+ j++;
32
+ } else {
33
+ let matchIdx = -1;
34
+ for (let k = j + 1; k < Math.min(n, j + 5); k++) {
35
+ if (newLines[k] === oldLines[i]) {
36
+ matchIdx = k;
37
+ break;
38
+ }
39
+ }
40
+ if (matchIdx !== -1) {
41
+ while (j < matchIdx) {
42
+ hunks.push({ type: 'add', text: newLines[j++], oldLine: null, newLine: newLineNum++ });
43
+ added++;
44
+ }
45
+ } else {
46
+ hunks.push({ type: 'del', text: oldLines[i++], oldLine: oldLineNum++, newLine: null });
47
+ removed++;
48
+ }
49
+ }
50
+ }
51
+
52
+ while (i < m) {
53
+ hunks.push({ type: 'del', text: oldLines[i++], oldLine: oldLineNum++, newLine: null });
54
+ removed++;
55
+ }
56
+ while (j < n) {
57
+ hunks.push({ type: 'add', text: newLines[j++], oldLine: null, newLine: newLineNum++ });
58
+ added++;
59
+ }
60
+
61
+ return { hunks, added, removed };
62
+ }
63
+
64
+ export class CodeLabDiffEditorManager {
65
+ private workbench: any;
66
+ private diffEditor: any = null;
67
+ private originalModel: any = null;
68
+ private modifiedModel: any = null;
69
+ public isActive = false;
70
+ public activeFile = '';
71
+ public currentTarget: 'starter' | 'solution' = 'solution';
72
+
73
+ constructor(workbench: any) {
74
+ this.workbench = workbench;
75
+ }
76
+
77
+ public openInlineDiff(file: string, target: 'starter' | 'solution' = 'solution'): boolean {
78
+ const monaco = typeof window !== 'undefined' ? (window as any).monaco : null;
79
+ this.activeFile = file;
80
+ this.currentTarget = target;
81
+
82
+ const editorHost = this.workbench.container?.querySelector('#cl-editor-host') || this.workbench.container?.querySelector('#cl-monaco-host');
83
+ const fallbackTextarea = this.workbench.container?.querySelector('#cl-fallback-editor');
84
+ if (!editorHost) return false;
85
+
86
+ // Get reference code
87
+ const isStarter = target === 'starter';
88
+ const baseFiles = this.workbench._getBaseFilesForModeAndLang
89
+ ? this.workbench._getBaseFilesForModeAndLang(isStarter ? 'guided' : 'sandbox', this.workbench.lang)
90
+ : (isStarter ? (this.workbench.starterFiles || {}) : (this.workbench.solutionFiles || {}));
91
+
92
+ const refCode = baseFiles[file] !== undefined ? baseFiles[file] : '';
93
+ const currentCode = this.workbench.files[file] !== undefined ? this.workbench.files[file] : '';
94
+
95
+ if (!monaco || !monaco.editor || typeof monaco.editor.createDiffEditor !== 'function') {
96
+ // Fall back to modal diff if Monaco or createDiffEditor is not available
97
+ if (typeof this.workbench.showDiffModalFallback === 'function') {
98
+ this.workbench.showDiffModalFallback(file, target);
99
+ }
100
+ return false;
101
+ }
102
+
103
+ this.isActive = true;
104
+
105
+ // Create or reuse diff container
106
+ let diffContainer = this.workbench.container.querySelector('#cl-inline-diff-container');
107
+ if (!diffContainer) {
108
+ diffContainer = document.createElement('div');
109
+ diffContainer.id = 'cl-inline-diff-container';
110
+ diffContainer.className = 'codelab-diff-container';
111
+ editorHost.parentElement.appendChild(diffContainer);
112
+ }
113
+
114
+ diffContainer.style.display = 'flex';
115
+ if (editorHost) editorHost.style.display = 'none';
116
+ if (fallbackTextarea) fallbackTextarea.style.display = 'none';
117
+
118
+ diffContainer.innerHTML = `
119
+ <div class="codelab-diff-toolbar">
120
+ <span style="font-weight:600;display:inline-flex;align-items:center;gap:6px;">
121
+ ${CL_ICONS.diff}
122
+ <span>Diff: <code>${file}</code> (${isStarter ? 'Current vs Starter' : 'Current vs Solution'})</span>
123
+ </span>
124
+ <div class="codelab-segmented" style="margin-left:16px;">
125
+ <button type="button" class="codelab-segmented__btn ${target === 'starter' ? 'active' : ''}" id="cl-diff-toggle-starter">Starter</button>
126
+ <button type="button" class="codelab-segmented__btn ${target === 'solution' ? 'active' : ''}" id="cl-diff-toggle-solution">Solution</button>
127
+ </div>
128
+ <div style="margin-left:auto;display:inline-flex;align-items:center;gap:6px;">
129
+ <button type="button" class="codelab-btn codelab-btn--sm" id="cl-diff-revert-btn">${CL_ICONS.refresh} Revert File</button>
130
+ <button type="button" class="codelab-btn codelab-btn--sm codelab-btn--primary" id="cl-diff-apply-btn">${CL_ICONS.check} Apply Solution</button>
131
+ <button type="button" class="codelab-btn codelab-btn--sm" id="cl-diff-close-btn">${CL_ICONS.x} Close Diff</button>
132
+ </div>
133
+ </div>
134
+ <div class="codelab-diff-host" id="cl-diff-editor-slot"></div>
135
+ `;
136
+
137
+ const slot = diffContainer.querySelector('#cl-diff-editor-slot');
138
+ if (!this.diffEditor) {
139
+ this.diffEditor = monaco.editor.createDiffEditor(slot, {
140
+ readOnly: false,
141
+ originalEditable: false,
142
+ theme: this.workbench.theme === 'light' ? 'vs' : 'vs-dark',
143
+ renderSideBySide: true,
144
+ automaticLayout: true,
145
+ minimap: { enabled: false }
146
+ });
147
+ }
148
+
149
+ const lang = file.endsWith('.ts') ? 'typescript' : file.endsWith('.cpp') ? 'cpp' : file.endsWith('.py') ? 'python' : 'javascript';
150
+ this.originalModel = monaco.editor.createModel(refCode, lang);
151
+ this.modifiedModel = monaco.editor.createModel(currentCode, lang);
152
+
153
+ this.diffEditor.setModel({
154
+ original: this.originalModel,
155
+ modified: this.modifiedModel
156
+ });
157
+
158
+ // Wire modified model edits back to workbench
159
+ this.modifiedModel.onDidChangeContent(() => {
160
+ const val = this.modifiedModel.getValue();
161
+ this.workbench.files[file] = val;
162
+ if (typeof this.workbench._markDirty === 'function') {
163
+ this.workbench._markDirty(file);
164
+ }
165
+ });
166
+
167
+ // Wire buttons
168
+ diffContainer.querySelector('#cl-diff-toggle-starter')?.addEventListener('click', () => {
169
+ this.openInlineDiff(file, 'starter');
170
+ });
171
+ diffContainer.querySelector('#cl-diff-toggle-solution')?.addEventListener('click', () => {
172
+ this.openInlineDiff(file, 'solution');
173
+ });
174
+ diffContainer.querySelector('#cl-diff-revert-btn')?.addEventListener('click', () => {
175
+ const starterCode = (this.workbench.starterFiles && this.workbench.starterFiles[file]) || '';
176
+ this.workbench.files[file] = starterCode;
177
+ this.closeInlineDiff();
178
+ this.workbench.openFile(file);
179
+ });
180
+ diffContainer.querySelector('#cl-diff-apply-btn')?.addEventListener('click', () => {
181
+ const solutionCode = (this.workbench.solutionFiles && this.workbench.solutionFiles[file]) || '';
182
+ this.workbench.files[file] = solutionCode;
183
+ this.closeInlineDiff();
184
+ this.workbench.openFile(file);
185
+ });
186
+ diffContainer.querySelector('#cl-diff-close-btn')?.addEventListener('click', () => {
187
+ this.closeInlineDiff();
188
+ });
189
+
190
+ return true;
191
+ }
192
+
193
+ public closeInlineDiff(): void {
194
+ this.isActive = false;
195
+ const diffContainer = this.workbench.container?.querySelector('#cl-inline-diff-container');
196
+ if (diffContainer) {
197
+ diffContainer.style.display = 'none';
198
+ }
199
+ const editorHost = this.workbench.container?.querySelector('#cl-editor-host') || this.workbench.container?.querySelector('#cl-monaco-host');
200
+ if (editorHost) {
201
+ editorHost.style.display = '';
202
+ }
203
+ if (this.diffEditor) {
204
+ this.diffEditor.dispose();
205
+ this.diffEditor = null;
206
+ }
207
+ if (this.originalModel) {
208
+ this.originalModel.dispose();
209
+ this.originalModel = null;
210
+ }
211
+ if (this.modifiedModel) {
212
+ this.modifiedModel.dispose();
213
+ this.modifiedModel = null;
214
+ }
215
+ }
216
+ }
@@ -0,0 +1,144 @@
1
+ /**
2
+ * @innovatorved/code-lab — Resizable Bottom Drawer, Contextual Tabs & Telemetry HUD
3
+ */
4
+
5
+ import { CL_ICONS } from './icons';
6
+
7
+ export interface DrawerTabOptions {
8
+ workbench: any;
9
+ drawerTab: string;
10
+ hasGuidedLab: boolean;
11
+ mode: string;
12
+ hasWebContent: boolean;
13
+ problemsCount: number;
14
+ testSuiteVisible: boolean;
15
+ lastDurationMs: number | null;
16
+ lastPeakMemoryBytes: number | null;
17
+ }
18
+
19
+ export function formatTelemetryHud(durationMs: number | null, memoryBytes: number | null, lang: string): string {
20
+ if (durationMs === null && memoryBytes === null) return '';
21
+
22
+ const timeStr = durationMs !== null
23
+ ? (durationMs < 1000 ? `${durationMs.toFixed(1)} ms` : `${(durationMs / 1000).toFixed(2)} s`)
24
+ : '';
25
+
26
+ let memStr = '';
27
+ if (memoryBytes !== null && memoryBytes > 0) {
28
+ const mb = memoryBytes / (1024 * 1024);
29
+ const suffix = lang === 'cpp' ? 'Wasm' : lang === 'py' ? 'Heap' : 'Mem';
30
+ memStr = `${mb < 0.1 ? (memoryBytes / 1024).toFixed(1) + ' KB' : mb.toFixed(1) + ' MB'} ${suffix}`;
31
+ }
32
+
33
+ return `
34
+ <div class="codelab-hud-pill" id="cl-telemetry-hud" title="Last Execution Telemetry">
35
+ ${timeStr ? `<span class="codelab-hud-pill__metric">${CL_ICONS.clock} <span>${timeStr}</span></span>` : ''}
36
+ ${timeStr && memStr ? `<span style="opacity:0.4;">·</span>` : ''}
37
+ ${memStr ? `<span class="codelab-hud-pill__metric">${CL_ICONS.memory} <span>${memStr}</span></span>` : ''}
38
+ </div>
39
+ `;
40
+ }
41
+
42
+ export function renderDrawerTabsHtml(opts: DrawerTabOptions): string {
43
+ const { workbench, drawerTab, hasGuidedLab, mode, hasWebContent, problemsCount, testSuiteVisible, lastDurationMs, lastPeakMemoryBytes } = opts;
44
+ const isGuided = Boolean(hasGuidedLab && mode === 'guided');
45
+ const showTests = isGuided || testSuiteVisible || drawerTab === 'tests';
46
+
47
+ return `
48
+ <div class="codelab-drawer__header">
49
+ <div class="codelab-drawer__tabs" role="tablist" aria-label="Terminal &amp; Diagnostics Panels">
50
+ <button type="button" role="tab" aria-selected="${drawerTab === 'terminal'}" class="codelab-drawer__tab ${drawerTab === 'terminal' ? 'active' : ''}" data-cl-drawertab="terminal">
51
+ ${CL_ICONS.terminal}
52
+ <span>Terminal &amp; REPL</span>
53
+ </button>
54
+
55
+ <button type="button" role="tab" aria-selected="${drawerTab === 'problems'}" class="codelab-drawer__tab ${drawerTab === 'problems' ? 'active' : ''}" data-cl-drawertab="problems" title="Compiler &amp; Runtime Problems">
56
+ ${CL_ICONS.warning}
57
+ <span>Problems</span>
58
+ <span class="codelab-badge ${problemsCount > 0 ? 'codelab-badge--warn' : ''}" id="cl-problems-count" style="margin-left:4px;font-size:10px;padding:1px 5px;border-radius:10px;background:${problemsCount > 0 ? '#cca700' : 'rgba(255,255,255,0.1)'};color:#fff;">${problemsCount}</span>
59
+ </button>
60
+
61
+ <button type="button" role="tab" aria-selected="${drawerTab === 'tests'}" class="codelab-drawer__tab ${drawerTab === 'tests' ? 'active' : ''}" data-cl-drawertab="tests">
62
+ ${CL_ICONS.check}
63
+ <span>Test Suite</span>
64
+ </button>
65
+
66
+ <button type="button" role="tab" aria-selected="${drawerTab === 'stdin'}" class="codelab-drawer__tab ${drawerTab === 'stdin' ? 'active' : ''}" data-cl-drawertab="stdin" title="Standard Input / Competitive Programming Custom Input">
67
+ ${CL_ICONS.keyboard}
68
+ <span>Stdin</span>
69
+ </button>
70
+
71
+ <button type="button" role="tab" aria-selected="${drawerTab === 'ports'}" class="codelab-drawer__tab ${drawerTab === 'ports' ? 'active' : ''}" data-cl-drawertab="ports">
72
+ ${CL_ICONS.radio}
73
+ <span>Ports</span>
74
+ </button>
75
+
76
+ <button type="button" role="tab" aria-selected="${drawerTab === 'preview'}" class="codelab-drawer__tab ${drawerTab === 'preview' ? 'active' : ''}" data-cl-drawertab="preview" title="In-browser Web Preview">
77
+ ${CL_ICONS.externalLink || CL_ICONS.globe}
78
+ <span>Web Preview</span>
79
+ </button>
80
+
81
+ <button type="button" role="tab" aria-selected="${drawerTab === 'network'}" class="codelab-drawer__tab ${drawerTab === 'network' ? 'active' : ''}" data-cl-drawertab="network">
82
+ ${CL_ICONS.activity}
83
+ <span>Network</span>
84
+ </button>
85
+
86
+ <button type="button" role="tab" aria-selected="${drawerTab === 'inspector'}" class="codelab-drawer__tab ${drawerTab === 'inspector' ? 'active' : ''}" data-cl-drawertab="inspector">
87
+ ${CL_ICONS.database}
88
+ <span>Virtual Disk &amp; HTTP</span>
89
+ </button>
90
+ </div>
91
+
92
+ ${formatTelemetryHud(lastDurationMs, lastPeakMemoryBytes, workbench.lang || 'js')}
93
+
94
+ <div class="codelab-drawer__actions" style="margin-left:8px;">
95
+ <button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="toggle-drawer" title="Minimize/Expand Drawer" aria-label="Minimize or Expand Drawer" style="padding:2px 6px;font-size:11px;">
96
+ ${CL_ICONS.chevronsUpDown}
97
+ </button>
98
+ </div>
99
+ </div>
100
+ `;
101
+ }
102
+
103
+ export function renderProblemsPanelHtml(workbench: any): string {
104
+ const store = workbench._diagnosticsStore;
105
+ const items = store ? store.getAll() : [];
106
+
107
+ if (items.length === 0) {
108
+ return `
109
+ <div style="display:flex;align-items:center;justify-content:center;height:100%;color:var(--cl-fg-muted, #858585);font-size:12px;gap:8px;">
110
+ ${CL_ICONS.check}
111
+ <span>No problems detected in workspace.</span>
112
+ </div>
113
+ `;
114
+ }
115
+
116
+ return `
117
+ <div class="codelab-problems-list">
118
+ ${items.map((item: any) => {
119
+ const icon = item.severity === 'error' ? '✗' : (item.severity === 'warning' ? '⚠' : 'ℹ');
120
+ const cls = item.severity === 'error' ? 'codelab-problem-item--error' : (item.severity === 'warning' ? 'codelab-problem-item--warning' : 'codelab-problem-item--info');
121
+ return `
122
+ <div class="codelab-problem-item ${cls}" data-cl-problem-file="${item.file}" data-cl-problem-line="${item.line}" data-cl-problem-col="${item.col || 1}">
123
+ <span style="font-weight:bold;">${icon}</span>
124
+ <span>${item.message}</span>
125
+ <span class="codelab-problem-item__location">${item.file}:${item.line}:${item.col || 1}</span>
126
+ </div>
127
+ `;
128
+ }).join('')}
129
+ </div>
130
+ `;
131
+ }
132
+
133
+ export function renderStdinPanelHtml(workbench: any): string {
134
+ const val = workbench.customStdin || '';
135
+ return `
136
+ <div class="codelab-stdin-panel">
137
+ <div class="codelab-stdin-panel__header">
138
+ <span>Standard Input (std::cin / sys.stdin / process.stdin)</span>
139
+ <button type="button" class="codelab-btn codelab-btn--sm" id="cl-stdin-clear-btn" style="padding:1px 6px;font-size:10px;">Clear</button>
140
+ </div>
141
+ <textarea class="codelab-stdin-panel__textarea" id="cl-stdin-textarea" placeholder="Paste custom input lines here for DSA / competitive programming...">${val}</textarea>
142
+ </div>
143
+ `;
144
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @innovatorved/code-lab — Monaco Editor Host, Model Lifecycle & Formatting
3
+ */
4
+
5
+ export interface EditorPosition {
6
+ lineNumber: number;
7
+ column: number;
8
+ }
9
+
10
+ /**
11
+ * Normalizes C++ source indentation and braces.
12
+ */
13
+ export function formatCppSource(code: string): string {
14
+ if (!code || typeof code !== 'string') return code;
15
+ const lines = code.split('\n');
16
+ const formatted: string[] = [];
17
+ let indentLevel = 0;
18
+
19
+ for (let i = 0; i < lines.length; i++) {
20
+ const rawLine = lines[i];
21
+ const trimmed = rawLine.trim();
22
+
23
+ if (!trimmed) {
24
+ formatted.push('');
25
+ continue;
26
+ }
27
+
28
+ if (trimmed.startsWith('#')) {
29
+ formatted.push(trimmed);
30
+ continue;
31
+ }
32
+
33
+ // Dedent for closing brace
34
+ let currentIndent = indentLevel;
35
+ if (trimmed.startsWith('}') || trimmed.startsWith(');') || trimmed.startsWith('public:') || trimmed.startsWith('private:') || trimmed.startsWith('protected:')) {
36
+ currentIndent = Math.max(0, indentLevel - 1);
37
+ }
38
+
39
+ formatted.push(' '.repeat(currentIndent) + trimmed);
40
+
41
+ // Update indentLevel
42
+ for (let c = 0; c < trimmed.length; c++) {
43
+ if (trimmed[c] === '{') indentLevel++;
44
+ else if (trimmed[c] === '}') indentLevel = Math.max(0, indentLevel - 1);
45
+ }
46
+ }
47
+
48
+ return formatted.join('\n');
49
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @innovatorved/code-lab — Explorer File Tree & CRUD Utilities
3
+ */
4
+
5
+ import { CL_ICONS } from './icons';
6
+
7
+ export interface FileNode {
8
+ name: string;
9
+ fullPath: string;
10
+ isFolder: boolean;
11
+ children: FileNode[];
12
+ }
13
+
14
+ export function buildFileHierarchy(files: Record<string, string>, creatingItem?: any): FileNode {
15
+ const root: FileNode = { name: '', fullPath: '', isFolder: true, children: [] };
16
+
17
+ const paths = Object.keys(files).sort();
18
+ for (const p of paths) {
19
+ const parts = p.split('/').filter(Boolean);
20
+ let curr = root;
21
+ let accPath = '';
22
+
23
+ for (let i = 0; i < parts.length; i++) {
24
+ const part = parts[i];
25
+ accPath = accPath ? `${accPath}/${part}` : part;
26
+ const isLast = i === parts.length - 1;
27
+
28
+ let child = curr.children.find((c) => c.name === part);
29
+ if (!child) {
30
+ child = {
31
+ name: part,
32
+ fullPath: accPath,
33
+ isFolder: !isLast,
34
+ children: []
35
+ };
36
+ curr.children.push(child);
37
+ }
38
+ curr = child;
39
+ }
40
+ }
41
+
42
+ return root;
43
+ }
44
+
45
+ export function getFileIcon(filename: string): string {
46
+ if (filename.endsWith('.json')) return CL_ICONS.database;
47
+ if (filename.endsWith('.md')) return CL_ICONS.book;
48
+ if (filename.endsWith('.cpp') || filename.endsWith('.hpp') || filename.endsWith('.h')) return CL_ICONS.code;
49
+ if (filename.endsWith('.py')) return CL_ICONS.code;
50
+ return CL_ICONS.file;
51
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @innovatorved/code-lab — Guided Pane: Walkthrough Stepper, Hints & Verification
3
+ */
4
+
5
+ import { CL_ICONS } from './icons';
6
+
7
+ export interface GuidedStepData {
8
+ id: string;
9
+ title: string;
10
+ instructions: string | string[];
11
+ hint?: string;
12
+ testNames?: string[];
13
+ }
14
+
15
+ export function renderStepPillsHtml(steps: GuidedStepData[], activeIndex: number, completedStepIds: Set<string>): string {
16
+ if (!steps || steps.length === 0) return '';
17
+
18
+ return `
19
+ <div class="codelab-stepper" role="tablist" aria-label="Step progress">
20
+ ${steps.map((step, idx) => {
21
+ const isPassed = completedStepIds.has(step.id);
22
+ const isActive = idx === activeIndex;
23
+ const cls = `codelab-step-pill ${isActive ? 'active' : ''} ${isPassed ? 'passed' : ''}`;
24
+ return `
25
+ <button type="button" role="tab" aria-selected="${isActive}" class="${cls}" data-cl-step="${idx}" title="Step ${idx + 1}: ${step.title}">
26
+ <span class="codelab-step-pill__num">${isPassed ? CL_ICONS.check : idx + 1}</span>
27
+ <span class="codelab-step-pill__label">${step.title}</span>
28
+ </button>
29
+ `;
30
+ }).join('')}
31
+ </div>
32
+ `;
33
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @innovatorved/code-lab — Workbench SVG Icon Registry
3
+ * Complete set of lightweight, crisp SVG icons for toolbar, file tree, drawer, and modals.
4
+ */
5
+
6
+ export const CL_ICONS: Record<string, string> = {
7
+ arrowLeft: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>',
8
+ arrowRight: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg>',
9
+ target: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="6"/><circle cx="12" cy="12" r="2"/></svg>',
10
+ code: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>',
11
+ play: '<svg width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><polygon points="6 4 20 12 6 20 6 4"/></svg>',
12
+ stop: '<svg width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><rect x="5" y="5" width="14" height="14" rx="2"/></svg>',
13
+ check: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>',
14
+ lightbulb: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5"/><path d="M9 18h6"/><path d="M10 22h4"/></svg>',
15
+ list: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><line x1="3" y1="6" x2="3.01" y2="6"/><line x1="3" y1="12" x2="3.01" y2="12"/><line x1="3" y1="18" x2="3.01" y2="18"/></svg>',
16
+ book: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/></svg>',
17
+ file: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>',
18
+ terminal: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>',
19
+ database: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/></svg>',
20
+ globe: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>',
21
+ package: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16.5 9.4-9-5.19"/><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.29 7 12 12 20.71 7"/><line x1="12" y1="22" x2="12" y2="12"/></svg>',
22
+ chevronsUpDown: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/></svg>',
23
+ chevronDown: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>',
24
+ chevronRight: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>',
25
+ folder: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/></svg>',
26
+ plus: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>',
27
+ edit: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>',
28
+ trash: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>',
29
+ box: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.29 7 12 12 20.71 7"/><line x1="12" y1="22" x2="12" y2="12"/></svg>',
30
+ search: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>',
31
+ diff: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="3" x2="12" y2="21"/><path d="M8 8H4v8h4"/><path d="M16 8h4v8h-4"/></svg>',
32
+ command: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 3a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3H6a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3V6a3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3h12a3 3 0 0 0 3-3 3 3 0 0 0-3-3z"/></svg>',
33
+ download: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>',
34
+ refresh: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M23 4v6h-6"/><path d="M1 20v-6h6"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/></svg>',
35
+ send: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>',
36
+ activity: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg>',
37
+ radio: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="2"/><path d="M16.24 7.76a6 6 0 0 1 0 8.49m-8.48-.01a6 6 0 0 1 0-8.49m11.31-2.82a10 10 0 0 1 0 14.14m-14.14 0a10 10 0 0 1 0-14.14"/></svg>',
38
+ monitor: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>',
39
+ tablet: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="2" width="16" height="20" rx="2"/><line x1="12" y1="18" x2="12.01" y2="18"/></svg>',
40
+ smartphone: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="7" y="2" width="10" height="20" rx="2"/><line x1="12" y1="18" x2="12.01" y2="18"/></svg>',
41
+ externalLink: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>',
42
+ x: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',
43
+ warning: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>',
44
+ clock: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>',
45
+ memory: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 19v2"/><path d="M10 19v2"/><path d="M14 19v2"/><path d="M18 19v2"/><path d="M6 3v2"/><path d="M10 3v2"/><path d="M14 3v2"/><path d="M18 3v2"/><rect x="2" y="5" width="20" height="14" rx="2"/></svg>',
46
+ keyboard: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="M6 8h.01"/><path d="M10 8h.01"/><path d="M14 8h.01"/><path d="M18 8h.01"/><path d="M6 12h.01"/><path d="M10 12h.01"/><path d="M14 12h.01"/><path d="M18 12h.01"/><path d="M7 16h10"/></svg>',
47
+ share: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.59" y1="13.51" x2="15.42" y2="17.49"/><line x1="15.41" y1="6.51" x2="8.59" y2="10.49"/></svg>'
48
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @innovatorved/code-lab — Workbench Subsystem Entrypoint
3
+ */
4
+
5
+ export * from './icons';
6
+ export * from './styles';
7
+ export * from './toolbar';
8
+ export * from './drawer';
9
+ export * from './diff-editor';
10
+ export * from './command-palette';
11
+ export * from './share';
12
+ export * from './file-tree';
13
+ export * from './editor';
14
+ export * from './guided-pane';
15
+
16
+ import * as icons from './icons';
17
+ import * as styles from './styles';
18
+ import * as toolbar from './toolbar';
19
+ import * as drawer from './drawer';
20
+ import * as diffEditor from './diff-editor';
21
+ import * as commandPalette from './command-palette';
22
+ import * as share from './share';
23
+ import * as fileTree from './file-tree';
24
+ import * as editor from './editor';
25
+ import * as guidedPane from './guided-pane';
26
+
27
+ export const CodeLabWorkbenchComponents = {
28
+ ...icons,
29
+ ...styles,
30
+ ...toolbar,
31
+ ...drawer,
32
+ ...diffEditor,
33
+ ...commandPalette,
34
+ ...share,
35
+ ...fileTree,
36
+ ...editor,
37
+ ...guidedPane
38
+ };