@innovatorved/code-lab 0.1.13 → 0.3.0
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.
- package/ARCHITECTURE.md +12 -7
- package/CHANGELOG.md +134 -0
- package/README.md +59 -9
- package/dist/code-lab.css +198 -0
- package/dist/code-lab.d.ts +37 -7
- package/dist/code-lab.esm.js +20444 -1278
- package/dist/code-lab.js +20439 -1276
- package/dist/extensions/cpp.d.ts +145 -0
- package/dist/extensions/cpp.esm.js +5932 -0
- package/dist/extensions/cpp.js +5951 -0
- package/dist/extensions/guided-lab.esm.js +86 -6
- package/dist/extensions/guided-lab.js +87 -6
- package/dist/extensions/javascript.d.ts +24 -0
- package/dist/extensions/javascript.esm.js +36 -0
- package/dist/extensions/javascript.js +59 -0
- package/dist/extensions/python.d.ts +92 -0
- package/dist/extensions/python.esm.js +5476 -0
- package/dist/extensions/python.js +5495 -0
- package/dist/extensions/typescript.d.ts +36 -0
- package/dist/extensions/typescript.esm.js +55 -0
- package/dist/extensions/typescript.js +78 -0
- package/dist/index.d.ts +9 -3
- package/dist/preview-sw.js +1 -1
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/module-loader.d.ts +11 -0
- package/dist/runtime/test-harness.d.ts +24 -0
- package/dist/runtime/vfs.d.ts +31 -0
- package/dist/runtime/wasi-host.d.ts +33 -0
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.esm.js +920 -15
- package/dist/runtime.js +914 -15
- package/dist/schemas.d.ts +237 -25
- package/dist/schemas.esm.js +85 -6
- package/dist/schemas.js +85 -6
- package/dist/shell/coreutils/compilers-cli.d.ts +24 -0
- package/dist/shell/index.d.ts +4 -0
- package/dist/shell/lexer-parser.d.ts +26 -0
- package/dist/shell.esm.js +289 -4
- package/dist/shell.js +289 -4
- package/dist/terminal.esm.js +1 -1
- package/dist/terminal.js +1 -1
- package/dist/workbench/command-palette.d.ts +10 -0
- package/dist/workbench/diff-editor.d.ts +26 -0
- package/dist/workbench/drawer.d.ts +18 -0
- package/dist/workbench/editor.d.ts +11 -0
- package/dist/workbench/file-tree.d.ts +11 -0
- package/dist/workbench/guided-pane.d.ts +11 -0
- package/dist/workbench/icons.d.ts +5 -0
- package/dist/workbench/index.d.ts +39 -0
- package/dist/workbench/share.d.ts +21 -0
- package/dist/workbench/styles.d.ts +4 -0
- package/dist/workbench/toolbar.d.ts +17 -0
- package/dist/workbench.d.ts +6 -1
- package/package.json +33 -3
- package/src/code-lab.css +198 -0
- package/src/extensions/cpp.ts +1786 -0
- package/src/extensions/guided-lab.ts +10 -0
- package/src/extensions/javascript.ts +54 -0
- package/src/extensions/python.ts +1293 -0
- package/src/extensions/typescript.ts +85 -0
- package/src/index.ts +66 -3
- package/src/runtime/index.ts +5 -0
- package/src/runtime/test-harness.ts +57 -0
- package/src/runtime.ts +915 -14
- package/src/schemas.ts +94 -7
- package/src/shell/coreutils/compilers-cli.ts +103 -0
- package/src/shell/index.ts +5 -0
- package/src/shell.ts +288 -3
- package/src/workbench/command-palette.ts +140 -0
- package/src/workbench/diff-editor.ts +216 -0
- package/src/workbench/drawer.ts +148 -0
- package/src/workbench/editor.ts +49 -0
- package/src/workbench/file-tree.ts +51 -0
- package/src/workbench/guided-pane.ts +33 -0
- package/src/workbench/icons.ts +48 -0
- package/src/workbench/index.ts +38 -0
- package/src/workbench/share.ts +99 -0
- package/src/workbench/styles.ts +200 -0
- package/src/workbench/toolbar.ts +171 -0
- package/src/workbench.ts +1016 -78
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @innovatorved/code-lab — Fuzzy-Searchable Command Palette (Cmd+Shift+P / Cmd+K)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { CL_ICONS } from './icons';
|
|
6
|
+
|
|
7
|
+
export interface CommandPaletteItem {
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
shortcut?: string;
|
|
11
|
+
action: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getStandardWorkbenchCommands(workbench: any): CommandPaletteItem[] {
|
|
15
|
+
const isGuided = Boolean(workbench.hasGuidedLab && workbench.mode === 'guided');
|
|
16
|
+
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
id: 'run-code',
|
|
20
|
+
label: isGuided ? 'CodeLab: Verify Current Guided Step' : 'CodeLab: Run Active Code / Demo',
|
|
21
|
+
shortcut: '⌘↵',
|
|
22
|
+
action: () => {
|
|
23
|
+
if (isGuided) workbench.verifyCurrentStep();
|
|
24
|
+
else workbench.runCode();
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 'run-demo',
|
|
29
|
+
label: 'CodeLab: Run Demo Script',
|
|
30
|
+
shortcut: '⇧⌘↵',
|
|
31
|
+
action: () => workbench.runDemo()
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'run-tests',
|
|
35
|
+
label: 'CodeLab: Run Unit Tests',
|
|
36
|
+
shortcut: '⌘↵',
|
|
37
|
+
action: () => workbench.runTests()
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: 'format-document',
|
|
41
|
+
label: 'Format: Format Active Document',
|
|
42
|
+
shortcut: '⇧⌥F',
|
|
43
|
+
action: () => workbench.formatActiveDocument()
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 'share-snapshot',
|
|
47
|
+
label: 'Share: Copy URL Snapshot to Clipboard (#codelab=...)',
|
|
48
|
+
action: () => workbench.shareSnapshot()
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 'compare-solution',
|
|
52
|
+
label: 'Diff: Compare Active File with Reference Solution',
|
|
53
|
+
action: () => workbench.showDiffModal(workbench.activeFile || workbench._pickDefaultFile(), 'solution')
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: 'compare-starter',
|
|
57
|
+
label: 'Diff: Compare Active File with Starter Template',
|
|
58
|
+
action: () => workbench.showDiffModal(workbench.activeFile || workbench._pickDefaultFile(), 'starter')
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: 'open-stdin',
|
|
62
|
+
label: 'View: Open Stdin / Custom Input Panel',
|
|
63
|
+
action: () => {
|
|
64
|
+
workbench.drawerTab = 'stdin';
|
|
65
|
+
if (typeof workbench._renderDrawerBody === 'function') workbench._renderDrawerBody();
|
|
66
|
+
const drawer = workbench.container?.querySelector('#cl-drawer');
|
|
67
|
+
if (drawer) drawer.classList.remove('is-minimized');
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 'open-problems',
|
|
72
|
+
label: 'View: Show Problems & Diagnostics',
|
|
73
|
+
action: () => {
|
|
74
|
+
workbench.drawerTab = 'problems';
|
|
75
|
+
if (typeof workbench._renderDrawerBody === 'function') workbench._renderDrawerBody();
|
|
76
|
+
const drawer = workbench.container?.querySelector('#cl-drawer');
|
|
77
|
+
if (drawer) drawer.classList.remove('is-minimized');
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: 'new-file',
|
|
82
|
+
label: 'File: New File...',
|
|
83
|
+
action: () => workbench.startInlineCreate('file', '')
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: 'new-folder',
|
|
87
|
+
label: 'File: New Folder...',
|
|
88
|
+
action: () => workbench.startInlineCreate('folder', '')
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: 'rename-active',
|
|
92
|
+
label: 'File: Rename Active File...',
|
|
93
|
+
shortcut: 'F2',
|
|
94
|
+
action: () => { if (workbench.activeFile) workbench.startInlineRename('file', workbench.activeFile); }
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: 'delete-active',
|
|
98
|
+
label: 'File: Delete Active File',
|
|
99
|
+
action: () => { if (workbench.activeFile) workbench.deleteFile(workbench.activeFile); }
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: 'export-workspace-zip',
|
|
103
|
+
label: 'Workspace: Export Project as ZIP Archive',
|
|
104
|
+
action: () => workbench.exportProjectZip({ download: true })
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: 'export-workspace-json',
|
|
108
|
+
label: 'Workspace: Export Workspace as JSON',
|
|
109
|
+
action: () => workbench.exportWorkspace({ download: true })
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: 'switch-lang',
|
|
113
|
+
label: 'Language: Cycle Active Language (JS / TS / C++ / PY)',
|
|
114
|
+
action: () => {
|
|
115
|
+
const order = ['js'];
|
|
116
|
+
if (workbench.enabledLanguages?.has('ts')) order.push('ts');
|
|
117
|
+
if (workbench.enabledLanguages?.has('cpp')) order.push('cpp');
|
|
118
|
+
if (workbench.enabledLanguages?.has('py')) order.push('py');
|
|
119
|
+
const next = order[(order.indexOf(workbench.lang) + 1) % order.length] || 'js';
|
|
120
|
+
workbench.setLanguage(next);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: 'toggle-fullscreen',
|
|
125
|
+
label: 'View: Toggle Fullscreen Workbench',
|
|
126
|
+
action: () => workbench.toggleFullscreen()
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: 'search-workspace',
|
|
130
|
+
label: 'Search: Find & Replace Across Files...',
|
|
131
|
+
shortcut: '⇧⌘F',
|
|
132
|
+
action: () => workbench.showSearchModal()
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
id: 'open-scm',
|
|
136
|
+
label: 'Git: Source Control (Status, Stage & Commit)...',
|
|
137
|
+
action: () => workbench.showScmModal()
|
|
138
|
+
}
|
|
139
|
+
];
|
|
140
|
+
}
|
|
@@ -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,148 @@
|
|
|
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 & 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 & 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 & 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
|
+
${showTests ? `
|
|
62
|
+
<button type="button" role="tab" aria-selected="${drawerTab === 'tests'}" class="codelab-drawer__tab ${drawerTab === 'tests' ? 'active' : ''}" data-cl-drawertab="tests">
|
|
63
|
+
${CL_ICONS.check}
|
|
64
|
+
<span>Test Suite</span>
|
|
65
|
+
</button>
|
|
66
|
+
` : ''}
|
|
67
|
+
|
|
68
|
+
<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">
|
|
69
|
+
${CL_ICONS.keyboard}
|
|
70
|
+
<span>Stdin</span>
|
|
71
|
+
</button>
|
|
72
|
+
|
|
73
|
+
<button type="button" role="tab" aria-selected="${drawerTab === 'ports'}" class="codelab-drawer__tab ${drawerTab === 'ports' ? 'active' : ''}" data-cl-drawertab="ports">
|
|
74
|
+
${CL_ICONS.radio}
|
|
75
|
+
<span>Ports</span>
|
|
76
|
+
</button>
|
|
77
|
+
|
|
78
|
+
${hasWebContent ? `
|
|
79
|
+
<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">
|
|
80
|
+
${CL_ICONS.externalLink || CL_ICONS.globe}
|
|
81
|
+
<span>Web Preview</span>
|
|
82
|
+
</button>
|
|
83
|
+
` : ''}
|
|
84
|
+
|
|
85
|
+
<button type="button" role="tab" aria-selected="${drawerTab === 'network'}" class="codelab-drawer__tab ${drawerTab === 'network' ? 'active' : ''}" data-cl-drawertab="network">
|
|
86
|
+
${CL_ICONS.activity}
|
|
87
|
+
<span>Network</span>
|
|
88
|
+
</button>
|
|
89
|
+
|
|
90
|
+
<button type="button" role="tab" aria-selected="${drawerTab === 'inspector'}" class="codelab-drawer__tab ${drawerTab === 'inspector' ? 'active' : ''}" data-cl-drawertab="inspector">
|
|
91
|
+
${CL_ICONS.database}
|
|
92
|
+
<span>Virtual Disk & HTTP</span>
|
|
93
|
+
</button>
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
${formatTelemetryHud(lastDurationMs, lastPeakMemoryBytes, workbench.lang || 'js')}
|
|
97
|
+
|
|
98
|
+
<div class="codelab-drawer__actions" style="margin-left:8px;">
|
|
99
|
+
<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;">
|
|
100
|
+
${CL_ICONS.chevronsUpDown}
|
|
101
|
+
</button>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function renderProblemsPanelHtml(workbench: any): string {
|
|
108
|
+
const store = workbench._diagnosticsStore;
|
|
109
|
+
const items = store ? store.getAll() : [];
|
|
110
|
+
|
|
111
|
+
if (items.length === 0) {
|
|
112
|
+
return `
|
|
113
|
+
<div style="display:flex;align-items:center;justify-content:center;height:100%;color:var(--cl-fg-muted, #858585);font-size:12px;gap:8px;">
|
|
114
|
+
${CL_ICONS.check}
|
|
115
|
+
<span>No problems detected in workspace.</span>
|
|
116
|
+
</div>
|
|
117
|
+
`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return `
|
|
121
|
+
<div class="codelab-problems-list">
|
|
122
|
+
${items.map((item: any) => {
|
|
123
|
+
const icon = item.severity === 'error' ? '✗' : (item.severity === 'warning' ? '⚠' : 'ℹ');
|
|
124
|
+
const cls = item.severity === 'error' ? 'codelab-problem-item--error' : (item.severity === 'warning' ? 'codelab-problem-item--warning' : 'codelab-problem-item--info');
|
|
125
|
+
return `
|
|
126
|
+
<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}">
|
|
127
|
+
<span style="font-weight:bold;">${icon}</span>
|
|
128
|
+
<span>${item.message}</span>
|
|
129
|
+
<span class="codelab-problem-item__location">${item.file}:${item.line}:${item.col || 1}</span>
|
|
130
|
+
</div>
|
|
131
|
+
`;
|
|
132
|
+
}).join('')}
|
|
133
|
+
</div>
|
|
134
|
+
`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function renderStdinPanelHtml(workbench: any): string {
|
|
138
|
+
const val = workbench.customStdin || '';
|
|
139
|
+
return `
|
|
140
|
+
<div class="codelab-stdin-panel">
|
|
141
|
+
<div class="codelab-stdin-panel__header">
|
|
142
|
+
<span>Standard Input (std::cin / sys.stdin / process.stdin)</span>
|
|
143
|
+
<button type="button" class="codelab-btn codelab-btn--sm" id="cl-stdin-clear-btn" style="padding:1px 6px;font-size:10px;">Clear</button>
|
|
144
|
+
</div>
|
|
145
|
+
<textarea class="codelab-stdin-panel__textarea" id="cl-stdin-textarea" placeholder="Paste custom input lines here for DSA / competitive programming...">${val}</textarea>
|
|
146
|
+
</div>
|
|
147
|
+
`;
|
|
148
|
+
}
|
|
@@ -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
|
+
}
|