@innovatorved/code-lab 0.7.0 → 0.7.2
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 +2 -2
- package/CHANGELOG.md +30 -0
- package/README.md +6 -6
- package/dist/code-lab-sql.esm.js +19 -19
- package/dist/code-lab-sql.umd.js +20 -20
- package/dist/code-lab.css +1 -1
- package/dist/code-lab.d.ts +47 -38
- package/dist/code-lab.esm.js +1183 -1909
- package/dist/code-lab.js +1182 -1906
- package/dist/extensions/cpp.esm.js +132 -8760
- package/dist/extensions/cpp.js +124 -8770
- package/dist/extensions/guided-lab.esm.js +33 -6836
- package/dist/extensions/guided-lab.js +33 -6854
- package/dist/extensions/javascript.esm.js +1 -36
- package/dist/extensions/javascript.js +1 -58
- package/dist/extensions/python.esm.js +113 -8122
- package/dist/extensions/python.js +113 -8140
- package/dist/extensions/typescript.esm.js +1 -55
- package/dist/extensions/typescript.js +1 -77
- package/dist/index.d.ts +1 -1
- package/dist/logger.d.ts +4 -20
- package/dist/modular-kernel.d.ts +0 -5
- package/dist/packages/core/src/errors.d.ts +5 -1
- package/dist/packages/fs/src/backends.d.ts +0 -27
- package/dist/packages/fs/src/index.d.ts +1 -1
- package/dist/packages/ui/src/html.d.ts +1 -0
- package/dist/packages/ui/src/index.d.ts +1 -0
- package/dist/{apps/web/src/index.d.ts → packages/ui/src/kernel.d.ts} +3 -11
- package/dist/packages/ui/src/observability.d.ts +1 -1
- package/dist/packages/ui/src/settings-dialog.d.ts +0 -1
- package/dist/preview-sw.js +1 -1
- package/dist/runtime.d.ts +3 -0
- package/dist/runtime.esm.js +78 -78
- package/dist/runtime.js +78 -78
- package/dist/schemas.d.ts +10 -1
- package/dist/schemas.esm.js +33 -6815
- package/dist/schemas.js +33 -6831
- package/dist/shell.esm.js +277 -285
- package/dist/shell.js +277 -285
- package/dist/terminal.esm.js +9 -7
- package/dist/terminal.js +7 -7
- package/dist/workbench/command-palette.d.ts +0 -4
- package/dist/workbench/editor.d.ts +0 -4
- package/dist/workbench/index.d.ts +0 -22
- package/dist/workbench/intellisense.d.ts +1 -8
- package/dist/workbench/xterm-adapter.d.ts +0 -1
- package/package.json +4 -13
- package/dist/code-lab.umd.js +0 -6117
- package/dist/packages/editor/src/index.d.ts +0 -118
- package/dist/packages/preview/src/index.d.ts +0 -34
- package/dist/packages/runtime/src/index.d.ts +0 -47
- package/dist/packages/terminal/src/index.d.ts +0 -54
- package/dist/workbench/drawer.d.ts +0 -18
- package/dist/workbench/file-tree.d.ts +0 -11
- package/dist/workbench/guided-pane.d.ts +0 -11
- package/dist/workbench/styles.d.ts +0 -4
- package/dist/workbench/toolbar.d.ts +0 -17
- package/packages/commands/README.md +0 -7
- package/packages/commands/package.json +0 -16
- package/packages/commands/src/index.ts +0 -467
- package/packages/commands/tsconfig.json +0 -22
- package/packages/core/README.md +0 -12
- package/packages/core/package.json +0 -13
- package/packages/core/src/di.ts +0 -147
- package/packages/core/src/disposable.ts +0 -112
- package/packages/core/src/errors.ts +0 -205
- package/packages/core/src/events.ts +0 -157
- package/packages/core/src/index.ts +0 -49
- package/packages/core/src/path.ts +0 -118
- package/packages/core/src/registry.ts +0 -61
- package/packages/core/tsconfig.json +0 -19
- package/packages/editor/README.md +0 -9
- package/packages/editor/package.json +0 -18
- package/packages/editor/src/index.ts +0 -344
- package/packages/editor/tsconfig.json +0 -24
- package/packages/fs/README.md +0 -7
- package/packages/fs/package.json +0 -16
- package/packages/fs/src/backends.ts +0 -301
- package/packages/fs/src/index.ts +0 -18
- package/packages/fs/src/types.ts +0 -44
- package/packages/fs/src/vfs-service.ts +0 -257
- package/packages/fs/tsconfig.json +0 -22
- package/packages/preview/README.md +0 -3
- package/packages/preview/package.json +0 -16
- package/packages/preview/src/index.ts +0 -125
- package/packages/preview/tsconfig.json +0 -22
- package/packages/runtime/README.md +0 -3
- package/packages/runtime/package.json +0 -17
- package/packages/runtime/src/index.ts +0 -134
- package/packages/runtime/tsconfig.json +0 -23
- package/packages/settings/README.md +0 -7
- package/packages/settings/package.json +0 -16
- package/packages/settings/src/builtin-schemas.ts +0 -262
- package/packages/settings/src/configuration-service.ts +0 -609
- package/packages/settings/src/index.ts +0 -38
- package/packages/settings/src/jsonc.ts +0 -189
- package/packages/settings/src/schema.ts +0 -164
- package/packages/settings/tsconfig.json +0 -22
- package/packages/sql/README.md +0 -12
- package/packages/sql/package.json +0 -13
- package/packages/sql/src/completions.ts +0 -359
- package/packages/sql/src/diagnostics.ts +0 -200
- package/packages/sql/src/formatter.ts +0 -271
- package/packages/sql/src/index.ts +0 -54
- package/packages/sql/src/sql-editor.ts +0 -802
- package/packages/sql/src/styles.ts +0 -524
- package/packages/sql/src/tokenizer.ts +0 -457
- package/packages/sql/src/types.ts +0 -148
- package/packages/sql/tsconfig.json +0 -19
- package/packages/terminal/README.md +0 -3
- package/packages/terminal/package.json +0 -16
- package/packages/terminal/src/index.ts +0 -183
- package/packages/terminal/tsconfig.json +0 -22
- package/packages/ui/README.md +0 -8
- package/packages/ui/package.json +0 -18
- package/packages/ui/src/index.ts +0 -40
- package/packages/ui/src/observability.ts +0 -173
- package/packages/ui/src/plugin-registry.ts +0 -289
- package/packages/ui/src/settings-dialog.ts +0 -939
- package/packages/ui/src/themes.ts +0 -333
- package/packages/ui/tsconfig.json +0 -24
- package/src/code-lab.css +0 -8584
- package/src/csp.ts +0 -590
- package/src/diagnostics.ts +0 -287
- package/src/extensions/cpp.ts +0 -2389
- package/src/extensions/guided-lab.ts +0 -64
- package/src/extensions/javascript.ts +0 -54
- package/src/extensions/python.ts +0 -1737
- package/src/extensions/typescript.ts +0 -85
- package/src/extensions/umbrella.ts +0 -5
- package/src/html.ts +0 -88
- package/src/index.ts +0 -129
- package/src/logger.ts +0 -139
- package/src/modular-kernel.ts +0 -11
- package/src/preview-sw.js +0 -296
- package/src/runtime/test-harness.ts +0 -57
- package/src/runtime.ts +0 -10480
- package/src/sample.html +0 -304
- package/src/schemas.ts +0 -366
- package/src/scm.ts +0 -2453
- package/src/search.ts +0 -433
- package/src/shell.ts +0 -10987
- package/src/storage.ts +0 -773
- package/src/terminal.ts +0 -1400
- package/src/workbench/command-palette.ts +0 -381
- package/src/workbench/diff-editor.ts +0 -470
- package/src/workbench/drawer.ts +0 -157
- package/src/workbench/editor.ts +0 -49
- package/src/workbench/file-tree.ts +0 -51
- package/src/workbench/guided-pane.ts +0 -43
- package/src/workbench/icons.ts +0 -255
- package/src/workbench/index.ts +0 -44
- package/src/workbench/intellisense.ts +0 -1871
- package/src/workbench/share.ts +0 -128
- package/src/workbench/styles.ts +0 -211
- package/src/workbench/toolbar.ts +0 -182
- package/src/workbench/xterm-adapter.ts +0 -1571
- package/src/workbench.ts +0 -22132
- package/src/zip.ts +0 -348
|
@@ -1,470 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @innovatorved/code-lab — Inline Monaco Side-by-Side Diff Editor & Fallback Unified Diff
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { CL_ICONS } from './icons';
|
|
6
|
-
import { getMonacoLanguageForFile, getMonacoThemeName } from './intellisense';
|
|
7
|
-
|
|
8
|
-
function escapeHtml(str: unknown): string {
|
|
9
|
-
return String(str ?? '')
|
|
10
|
-
.replace(/&/g, '&')
|
|
11
|
-
.replace(/</g, '<')
|
|
12
|
-
.replace(/>/g, '>')
|
|
13
|
-
.replace(/"/g, '"')
|
|
14
|
-
.replace(/'/g, ''');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface DiffComputeResult {
|
|
18
|
-
hunks: Array<{ type: 'context' | 'add' | 'del'; text: string; oldLine: number | null; newLine: number | null }>;
|
|
19
|
-
added: number;
|
|
20
|
-
removed: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface GitDiffOpenOptions {
|
|
24
|
-
staged?: boolean;
|
|
25
|
-
originalText: string;
|
|
26
|
-
modifiedText: string;
|
|
27
|
-
label?: string;
|
|
28
|
-
onStage?: () => void | Promise<void>;
|
|
29
|
-
onUnstage?: () => void | Promise<void>;
|
|
30
|
-
onDiscard?: () => void | Promise<void>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function computeSimpleDiff(oldText: string, newText: string): DiffComputeResult {
|
|
34
|
-
const oldLines = String(oldText || '').split('\n');
|
|
35
|
-
const newLines = String(newText || '').split('\n');
|
|
36
|
-
const hunks: Array<{ type: 'context' | 'add' | 'del'; text: string; oldLine: number | null; newLine: number | null }> = [];
|
|
37
|
-
let added = 0;
|
|
38
|
-
let removed = 0;
|
|
39
|
-
|
|
40
|
-
const m = oldLines.length;
|
|
41
|
-
const n = newLines.length;
|
|
42
|
-
let i = 0;
|
|
43
|
-
let j = 0;
|
|
44
|
-
let oldLineNum = 1;
|
|
45
|
-
let newLineNum = 1;
|
|
46
|
-
|
|
47
|
-
while (i < m && j < n) {
|
|
48
|
-
if (oldLines[i] === newLines[j]) {
|
|
49
|
-
hunks.push({ type: 'context', text: oldLines[i], oldLine: oldLineNum++, newLine: newLineNum++ });
|
|
50
|
-
i++;
|
|
51
|
-
j++;
|
|
52
|
-
} else {
|
|
53
|
-
let matchIdx = -1;
|
|
54
|
-
for (let k = j + 1; k < Math.min(n, j + 5); k++) {
|
|
55
|
-
if (newLines[k] === oldLines[i]) {
|
|
56
|
-
matchIdx = k;
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (matchIdx !== -1) {
|
|
61
|
-
while (j < matchIdx) {
|
|
62
|
-
hunks.push({ type: 'add', text: newLines[j++], oldLine: null, newLine: newLineNum++ });
|
|
63
|
-
added++;
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
hunks.push({ type: 'del', text: oldLines[i++], oldLine: oldLineNum++, newLine: null });
|
|
67
|
-
removed++;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
while (i < m) {
|
|
73
|
-
hunks.push({ type: 'del', text: oldLines[i++], oldLine: oldLineNum++, newLine: null });
|
|
74
|
-
removed++;
|
|
75
|
-
}
|
|
76
|
-
while (j < n) {
|
|
77
|
-
hunks.push({ type: 'add', text: newLines[j++], oldLine: null, newLine: newLineNum++ });
|
|
78
|
-
added++;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return { hunks, added, removed };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function renderFallbackUnifiedDiffHtml(oldText: string, newText: string): string {
|
|
85
|
-
const diff = computeSimpleDiff(oldText, newText);
|
|
86
|
-
if (diff.added === 0 && diff.removed === 0) {
|
|
87
|
-
return `<div class="codelab-diff-empty">No textual changes between versions.</div>`;
|
|
88
|
-
}
|
|
89
|
-
const rows = diff.hunks.map((h) => {
|
|
90
|
-
const cls = h.type === 'add' ? 'is-add' : h.type === 'del' ? 'is-del' : 'is-ctx';
|
|
91
|
-
const prefix = h.type === 'add' ? '+' : h.type === 'del' ? '-' : ' ';
|
|
92
|
-
const oldNum = h.oldLine !== null ? String(h.oldLine) : '';
|
|
93
|
-
const newNum = h.newLine !== null ? String(h.newLine) : '';
|
|
94
|
-
return `<div class="codelab-diff-fallback-row ${cls}">` +
|
|
95
|
-
`<span class="codelab-diff-ln">${oldNum}</span>` +
|
|
96
|
-
`<span class="codelab-diff-ln">${newNum}</span>` +
|
|
97
|
-
`<span class="codelab-diff-sign">${prefix}</span>` +
|
|
98
|
-
`<span class="codelab-diff-code">${escapeHtml(h.text)}</span>` +
|
|
99
|
-
`</div>`;
|
|
100
|
-
}).join('');
|
|
101
|
-
return `<div class="codelab-diff-fallback" role="region" aria-label="Unified diff view">${rows}</div>`;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export class CodeLabDiffEditorManager {
|
|
105
|
-
private workbench: any;
|
|
106
|
-
private diffEditor: any = null;
|
|
107
|
-
private originalModel: any = null;
|
|
108
|
-
private modifiedModel: any = null;
|
|
109
|
-
public isActive = false;
|
|
110
|
-
public activeFile = '';
|
|
111
|
-
public currentTarget: 'starter' | 'solution' | 'git' = 'solution';
|
|
112
|
-
|
|
113
|
-
constructor(workbench: any) {
|
|
114
|
-
this.workbench = workbench;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
private _ensureDiffContainer(): { diffContainer: any; editorHost: any; fallbackTextarea: any } | null {
|
|
118
|
-
const editorHost = this.workbench.container?.querySelector('#cl-editor-host')
|
|
119
|
-
|| this.workbench.container?.querySelector('#cl-monaco-host');
|
|
120
|
-
const fallbackTextarea = this.workbench.container?.querySelector('#cl-fallback-editor');
|
|
121
|
-
if (!editorHost) return null;
|
|
122
|
-
|
|
123
|
-
let diffContainer = this.workbench.container.querySelector('#cl-inline-diff-container');
|
|
124
|
-
if (!diffContainer) {
|
|
125
|
-
diffContainer = document.createElement('div');
|
|
126
|
-
diffContainer.id = 'cl-inline-diff-container';
|
|
127
|
-
diffContainer.className = 'codelab-diff-container';
|
|
128
|
-
editorHost.parentElement.appendChild(diffContainer);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const welcomeHost = this.workbench.container?.querySelector('#cl-welcome-host');
|
|
132
|
-
if (welcomeHost) welcomeHost.style.display = 'none';
|
|
133
|
-
|
|
134
|
-
diffContainer.style.display = 'flex';
|
|
135
|
-
editorHost.style.display = 'none';
|
|
136
|
-
if (fallbackTextarea) fallbackTextarea.style.display = 'none';
|
|
137
|
-
|
|
138
|
-
this._disposeEditorModels();
|
|
139
|
-
return { diffContainer, editorHost, fallbackTextarea };
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
private _disposeEditorModels(): void {
|
|
143
|
-
if (this.diffEditor) {
|
|
144
|
-
try { this.diffEditor.dispose(); } catch (_err) { void _err; }
|
|
145
|
-
this.diffEditor = null;
|
|
146
|
-
}
|
|
147
|
-
if (this.originalModel) {
|
|
148
|
-
try { this.originalModel.dispose(); } catch (_err) { void _err; }
|
|
149
|
-
this.originalModel = null;
|
|
150
|
-
}
|
|
151
|
-
if (this.modifiedModel) {
|
|
152
|
-
try { this.modifiedModel.dispose(); } catch (_err) { void _err; }
|
|
153
|
-
this.modifiedModel = null;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Opens a VS Code Source Control side-by-side diff (`Working Tree` or `Index` vs `HEAD`).
|
|
159
|
-
*/
|
|
160
|
-
public openGitDiff(file: string, opts: GitDiffOpenOptions): boolean {
|
|
161
|
-
const monaco = typeof window !== 'undefined' ? (window as any).monaco : null;
|
|
162
|
-
const hosts = this._ensureDiffContainer();
|
|
163
|
-
if (!hosts) return false;
|
|
164
|
-
|
|
165
|
-
const { diffContainer } = hosts;
|
|
166
|
-
this.isActive = true;
|
|
167
|
-
this.activeFile = file;
|
|
168
|
-
this.currentTarget = 'git';
|
|
169
|
-
|
|
170
|
-
const staged = Boolean(opts.staged);
|
|
171
|
-
const titleLabel = opts.label || (staged ? `${file} (Index ↔ HEAD)` : `${file} (Working Tree)`);
|
|
172
|
-
const safeTitle = escapeHtml(titleLabel);
|
|
173
|
-
|
|
174
|
-
diffContainer.innerHTML = `
|
|
175
|
-
<div class="codelab-diff-toolbar">
|
|
176
|
-
<span class="codelab-diff-toolbar__title">
|
|
177
|
-
${CL_ICONS.diff}
|
|
178
|
-
<span>${safeTitle}</span>
|
|
179
|
-
</span>
|
|
180
|
-
<div class="codelab-diff-toolbar__actions">
|
|
181
|
-
${staged
|
|
182
|
-
? (opts.onUnstage ? `<button type="button" class="codelab-btn codelab-btn--sm" id="cl-git-diff-unstage-btn" title="Unstage Changes">${CL_ICONS.minus || '−'} Unstage</button>` : '')
|
|
183
|
-
: `${opts.onDiscard ? `<button type="button" class="codelab-btn codelab-btn--sm" id="cl-git-diff-discard-btn" title="Discard Changes">${CL_ICONS.discard || CL_ICONS.refresh} Discard</button>` : ''}
|
|
184
|
-
${opts.onStage ? `<button type="button" class="codelab-btn codelab-btn--sm codelab-btn--primary" id="cl-git-diff-stage-btn" title="Stage Changes">${CL_ICONS.plus || '+'} Stage</button>` : ''}`
|
|
185
|
-
}
|
|
186
|
-
<button type="button" class="codelab-btn codelab-btn--sm" id="cl-git-diff-open-file-btn" title="Open File">Open File</button>
|
|
187
|
-
<button type="button" class="codelab-btn codelab-btn--sm" id="cl-diff-close-btn" title="Close Diff (Esc)">${CL_ICONS.x}</button>
|
|
188
|
-
</div>
|
|
189
|
-
</div>
|
|
190
|
-
<div class="codelab-diff-host" id="cl-diff-editor-slot"></div>
|
|
191
|
-
`;
|
|
192
|
-
|
|
193
|
-
const slot = diffContainer.querySelector('#cl-diff-editor-slot');
|
|
194
|
-
if (monaco?.editor && typeof monaco.editor.createDiffEditor === 'function' && slot) {
|
|
195
|
-
const resolvedTheme = typeof this.workbench._resolvedTheme === 'function'
|
|
196
|
-
? this.workbench._resolvedTheme()
|
|
197
|
-
: this.workbench.theme;
|
|
198
|
-
const monacoTheme = getMonacoThemeName(resolvedTheme, monaco);
|
|
199
|
-
const lang = getMonacoLanguageForFile(file, this.workbench.lang);
|
|
200
|
-
|
|
201
|
-
this.diffEditor = monaco.editor.createDiffEditor(slot, {
|
|
202
|
-
readOnly: staged,
|
|
203
|
-
originalEditable: false,
|
|
204
|
-
theme: monacoTheme,
|
|
205
|
-
renderSideBySide: true,
|
|
206
|
-
automaticLayout: true,
|
|
207
|
-
minimap: { enabled: false },
|
|
208
|
-
scrollBeyondLastLine: false,
|
|
209
|
-
fontFamily: '"Geist Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, monospace',
|
|
210
|
-
fontSize: Number(this.workbench._editorFontSize) || 13
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
this.originalModel = monaco.editor.createModel(String(opts.originalText ?? ''), lang);
|
|
214
|
-
this.modifiedModel = monaco.editor.createModel(String(opts.modifiedText ?? ''), lang);
|
|
215
|
-
this.diffEditor.setModel({
|
|
216
|
-
original: this.originalModel,
|
|
217
|
-
modified: this.modifiedModel
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
if (!staged) {
|
|
221
|
-
this.modifiedModel.onDidChangeContent(() => {
|
|
222
|
-
this.syncFileToWorkbench(file, this.modifiedModel.getValue());
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
} else if (slot) {
|
|
226
|
-
slot.innerHTML = renderFallbackUnifiedDiffHtml(opts.originalText, opts.modifiedText);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
diffContainer.querySelector('#cl-git-diff-stage-btn')?.addEventListener('click', async () => {
|
|
230
|
-
await opts.onStage?.();
|
|
231
|
-
this.closeInlineDiff();
|
|
232
|
-
});
|
|
233
|
-
diffContainer.querySelector('#cl-git-diff-unstage-btn')?.addEventListener('click', async () => {
|
|
234
|
-
await opts.onUnstage?.();
|
|
235
|
-
this.closeInlineDiff();
|
|
236
|
-
});
|
|
237
|
-
diffContainer.querySelector('#cl-git-diff-discard-btn')?.addEventListener('click', async () => {
|
|
238
|
-
await opts.onDiscard?.();
|
|
239
|
-
this.closeInlineDiff();
|
|
240
|
-
});
|
|
241
|
-
diffContainer.querySelector('#cl-git-diff-open-file-btn')?.addEventListener('click', () => {
|
|
242
|
-
this.closeInlineDiff();
|
|
243
|
-
if (typeof this.workbench.openFile === 'function') {
|
|
244
|
-
this.workbench.openFile(file);
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
diffContainer.querySelector('#cl-diff-close-btn')?.addEventListener('click', () => {
|
|
248
|
-
this.closeInlineDiff();
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
return true;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Mounts a side-by-side (or inline) Monaco DiffEditor directly into an existing slot element
|
|
256
|
-
* without overwriting the surrounding `.codelab-scm-diff-header` toolbar.
|
|
257
|
-
*/
|
|
258
|
-
public mountMonacoDiffIntoSlot(
|
|
259
|
-
slotEl: HTMLElement,
|
|
260
|
-
opts: {
|
|
261
|
-
relPath: string;
|
|
262
|
-
originalContent: string;
|
|
263
|
-
modifiedContent: string;
|
|
264
|
-
sideBySide?: boolean;
|
|
265
|
-
readOnly?: boolean;
|
|
266
|
-
}
|
|
267
|
-
): boolean {
|
|
268
|
-
const monaco = this.workbench?.monaco || (typeof window !== 'undefined' ? (window as any).monaco : null);
|
|
269
|
-
if (!slotEl || !monaco?.editor || typeof monaco.editor.createDiffEditor !== 'function') {
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
272
|
-
this._disposeEditorModels();
|
|
273
|
-
this.isActive = true;
|
|
274
|
-
this.activeFile = opts.relPath;
|
|
275
|
-
this.currentTarget = 'git';
|
|
276
|
-
|
|
277
|
-
const resolvedTheme = typeof this.workbench?._resolvedTheme === 'function'
|
|
278
|
-
? this.workbench._resolvedTheme()
|
|
279
|
-
: (this.workbench?.theme || 'dark');
|
|
280
|
-
const monacoTheme = getMonacoThemeName(resolvedTheme, monaco);
|
|
281
|
-
const lang = getMonacoLanguageForFile(opts.relPath, this.workbench?.lang);
|
|
282
|
-
|
|
283
|
-
slotEl.innerHTML = '';
|
|
284
|
-
this.diffEditor = monaco.editor.createDiffEditor(slotEl, {
|
|
285
|
-
readOnly: opts.readOnly !== false,
|
|
286
|
-
originalEditable: false,
|
|
287
|
-
theme: monacoTheme,
|
|
288
|
-
renderSideBySide: opts.sideBySide !== false,
|
|
289
|
-
automaticLayout: true,
|
|
290
|
-
minimap: { enabled: false },
|
|
291
|
-
scrollBeyondLastLine: false,
|
|
292
|
-
fontFamily: '"Geist Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, monospace',
|
|
293
|
-
fontSize: Number(this.workbench?._editorFontSize) || 13
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
this.originalModel = monaco.editor.createModel(String(opts.originalContent ?? ''), lang);
|
|
297
|
-
this.modifiedModel = monaco.editor.createModel(String(opts.modifiedContent ?? ''), lang);
|
|
298
|
-
this.diffEditor.setModel({
|
|
299
|
-
original: this.originalModel,
|
|
300
|
-
modified: this.modifiedModel
|
|
301
|
-
});
|
|
302
|
-
return true;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
public openInlineDiff(file: string, target: 'starter' | 'solution' = 'solution'): boolean {
|
|
306
|
-
const monaco = typeof window !== 'undefined' ? (window as any).monaco : null;
|
|
307
|
-
this.activeFile = file;
|
|
308
|
-
this.currentTarget = target;
|
|
309
|
-
|
|
310
|
-
const editorHost = this.workbench.container?.querySelector('#cl-editor-host') || this.workbench.container?.querySelector('#cl-monaco-host');
|
|
311
|
-
const fallbackTextarea = this.workbench.container?.querySelector('#cl-fallback-editor');
|
|
312
|
-
if (!editorHost) return false;
|
|
313
|
-
|
|
314
|
-
const isStarter = target === 'starter';
|
|
315
|
-
const baseFiles = this.workbench._getBaseFilesForModeAndLang
|
|
316
|
-
? this.workbench._getBaseFilesForModeAndLang(isStarter ? 'guided' : 'sandbox', this.workbench.lang)
|
|
317
|
-
: (isStarter ? (this.workbench.starterFiles || {}) : (this.workbench.solutionFiles || {}));
|
|
318
|
-
|
|
319
|
-
const refCode = baseFiles[file] !== undefined ? baseFiles[file] : '';
|
|
320
|
-
const currentCode = this.workbench.files[file] !== undefined ? this.workbench.files[file] : '';
|
|
321
|
-
|
|
322
|
-
if (!monaco || !monaco.editor || typeof monaco.editor.createDiffEditor !== 'function') {
|
|
323
|
-
if (typeof this.workbench.showDiffModalFallback === 'function') {
|
|
324
|
-
this.workbench.showDiffModalFallback(file, target);
|
|
325
|
-
}
|
|
326
|
-
return false;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const hosts = this._ensureDiffContainer();
|
|
330
|
-
if (!hosts) return false;
|
|
331
|
-
const { diffContainer } = hosts;
|
|
332
|
-
this.isActive = true;
|
|
333
|
-
|
|
334
|
-
const safeFile = escapeHtml(file);
|
|
335
|
-
diffContainer.innerHTML = `
|
|
336
|
-
<div class="codelab-diff-toolbar">
|
|
337
|
-
<span class="codelab-diff-toolbar__title">
|
|
338
|
-
${CL_ICONS.diff}
|
|
339
|
-
<span>Diff: <code>${safeFile}</code> (${isStarter ? 'Current vs Starter' : 'Current vs Solution'})</span>
|
|
340
|
-
</span>
|
|
341
|
-
<div class="codelab-segmented" style="margin-left:12px;">
|
|
342
|
-
<button type="button" class="codelab-segmented__btn ${target === 'starter' ? 'active' : ''}" id="cl-diff-toggle-starter">Starter</button>
|
|
343
|
-
<button type="button" class="codelab-segmented__btn ${target === 'solution' ? 'active' : ''}" id="cl-diff-toggle-solution">Solution</button>
|
|
344
|
-
</div>
|
|
345
|
-
<div class="codelab-diff-toolbar__actions">
|
|
346
|
-
<button type="button" class="codelab-btn codelab-btn--sm" id="cl-diff-revert-btn">${CL_ICONS.refresh} Revert File</button>
|
|
347
|
-
<button type="button" class="codelab-btn codelab-btn--sm codelab-btn--primary" id="cl-diff-apply-btn">${CL_ICONS.check} Apply Solution</button>
|
|
348
|
-
<button type="button" class="codelab-btn codelab-btn--sm" id="cl-diff-close-btn">${CL_ICONS.x} Close Diff</button>
|
|
349
|
-
</div>
|
|
350
|
-
</div>
|
|
351
|
-
<div class="codelab-diff-host" id="cl-diff-editor-slot"></div>
|
|
352
|
-
`;
|
|
353
|
-
|
|
354
|
-
const slot = diffContainer.querySelector('#cl-diff-editor-slot');
|
|
355
|
-
const resolvedTheme = typeof this.workbench._resolvedTheme === 'function'
|
|
356
|
-
? this.workbench._resolvedTheme()
|
|
357
|
-
: this.workbench.theme;
|
|
358
|
-
const monacoTheme = getMonacoThemeName(resolvedTheme, monaco);
|
|
359
|
-
this.diffEditor = monaco.editor.createDiffEditor(slot, {
|
|
360
|
-
readOnly: false,
|
|
361
|
-
originalEditable: false,
|
|
362
|
-
theme: monacoTheme,
|
|
363
|
-
renderSideBySide: true,
|
|
364
|
-
automaticLayout: true,
|
|
365
|
-
minimap: { enabled: false },
|
|
366
|
-
scrollBeyondLastLine: false,
|
|
367
|
-
fontFamily: '"Geist Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, monospace',
|
|
368
|
-
fontSize: Number(this.workbench._editorFontSize) || 13
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
const lang = getMonacoLanguageForFile(file, this.workbench.lang);
|
|
372
|
-
this.originalModel = monaco.editor.createModel(refCode, lang);
|
|
373
|
-
this.modifiedModel = monaco.editor.createModel(currentCode, lang);
|
|
374
|
-
|
|
375
|
-
this.diffEditor.setModel({
|
|
376
|
-
original: this.originalModel,
|
|
377
|
-
modified: this.modifiedModel
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
this.modifiedModel.onDidChangeContent(() => {
|
|
381
|
-
this.syncFileToWorkbench(file, this.modifiedModel.getValue());
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
diffContainer.querySelector('#cl-diff-toggle-starter')?.addEventListener('click', () => {
|
|
385
|
-
this.openInlineDiff(file, 'starter');
|
|
386
|
-
});
|
|
387
|
-
diffContainer.querySelector('#cl-diff-toggle-solution')?.addEventListener('click', () => {
|
|
388
|
-
this.openInlineDiff(file, 'solution');
|
|
389
|
-
});
|
|
390
|
-
diffContainer.querySelector('#cl-diff-revert-btn')?.addEventListener('click', () => {
|
|
391
|
-
const starterMap = this.workbench.starterFiles || (typeof this.workbench._getBaseFilesForModeAndLang === 'function' ? this.workbench._getBaseFilesForModeAndLang('guided', this.workbench.lang) : {});
|
|
392
|
-
const starterCode = (starterMap && starterMap[file]) || '';
|
|
393
|
-
if (typeof this.workbench.setFile === 'function') {
|
|
394
|
-
this.workbench.setFile(file, starterCode);
|
|
395
|
-
} else {
|
|
396
|
-
this.syncFileToWorkbench(file, starterCode);
|
|
397
|
-
}
|
|
398
|
-
this.closeInlineDiff();
|
|
399
|
-
this.workbench.openFile(file);
|
|
400
|
-
});
|
|
401
|
-
diffContainer.querySelector('#cl-diff-apply-btn')?.addEventListener('click', () => {
|
|
402
|
-
if (typeof this.workbench.applyReferenceSolution === 'function') {
|
|
403
|
-
this.closeInlineDiff();
|
|
404
|
-
this.workbench.applyReferenceSolution();
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
const solutionMap = this.workbench.solutionFiles || (typeof this.workbench._getBaseFilesForModeAndLang === 'function' ? this.workbench._getBaseFilesForModeAndLang('sandbox', this.workbench.lang) : {});
|
|
408
|
-
const solutionCode = (solutionMap && solutionMap[file]) || '';
|
|
409
|
-
if (typeof this.workbench.setFile === 'function') {
|
|
410
|
-
this.workbench.setFile(file, solutionCode);
|
|
411
|
-
} else {
|
|
412
|
-
this.syncFileToWorkbench(file, solutionCode);
|
|
413
|
-
}
|
|
414
|
-
this.closeInlineDiff();
|
|
415
|
-
this.workbench.openFile(file);
|
|
416
|
-
});
|
|
417
|
-
diffContainer.querySelector('#cl-diff-close-btn')?.addEventListener('click', () => {
|
|
418
|
-
this.closeInlineDiff();
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
return true;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
public syncFileToWorkbench(file: string, nextVal: string): void {
|
|
425
|
-
this.workbench.files[file] = nextVal;
|
|
426
|
-
const mainModel = this.workbench.models instanceof Map ? this.workbench.models.get(file) : null;
|
|
427
|
-
if (mainModel && typeof mainModel.getValue === 'function' && mainModel.getValue() !== nextVal) {
|
|
428
|
-
mainModel.setValue(nextVal);
|
|
429
|
-
}
|
|
430
|
-
const fallbackEl = this.workbench.container?.querySelector('#cl-fallback-editor');
|
|
431
|
-
if (fallbackEl && this.workbench.activeFile === file) {
|
|
432
|
-
fallbackEl.value = nextVal;
|
|
433
|
-
}
|
|
434
|
-
if (this.workbench.shell?.vfs && typeof this.workbench.shell.vfs.writeFileSync === 'function') {
|
|
435
|
-
try {
|
|
436
|
-
this.workbench.shell.vfs.writeFileSync('/workspace/' + String(file).replace(/^\/+/, ''), nextVal);
|
|
437
|
-
} catch (err) {
|
|
438
|
-
if (this.workbench.logger && typeof this.workbench.logger.debug === 'function') {
|
|
439
|
-
this.workbench.logger.debug('Diff VFS sync skipped.', err);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
if (typeof this.workbench._saveState === 'function') {
|
|
444
|
-
this.workbench._saveState();
|
|
445
|
-
}
|
|
446
|
-
if (typeof this.workbench._markDirty === 'function') {
|
|
447
|
-
this.workbench._markDirty(file);
|
|
448
|
-
}
|
|
449
|
-
if (typeof this.workbench._refreshGitDecorations === 'function') {
|
|
450
|
-
this.workbench._refreshGitDecorations();
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
public closeInlineDiff(): void {
|
|
455
|
-
this.isActive = false;
|
|
456
|
-
const diffContainer = this.workbench.container?.querySelector('#cl-inline-diff-container');
|
|
457
|
-
if (diffContainer) {
|
|
458
|
-
diffContainer.style.display = 'none';
|
|
459
|
-
}
|
|
460
|
-
const isWelcomeActive = this.workbench.activeFile === '__welcome__';
|
|
461
|
-
const welcomeHost = this.workbench.container?.querySelector('#cl-welcome-host');
|
|
462
|
-
const editorHost = this.workbench.container?.querySelector('#cl-editor-host') || this.workbench.container?.querySelector('#cl-monaco-host');
|
|
463
|
-
if (isWelcomeActive && welcomeHost) {
|
|
464
|
-
welcomeHost.style.display = 'flex';
|
|
465
|
-
} else if (editorHost) {
|
|
466
|
-
editorHost.style.display = '';
|
|
467
|
-
}
|
|
468
|
-
this._disposeEditorModels();
|
|
469
|
-
}
|
|
470
|
-
}
|
package/src/workbench/drawer.ts
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @innovatorved/code-lab — Resizable Bottom Drawer, Contextual Tabs & Telemetry HUD
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { CL_ICONS } from './icons';
|
|
6
|
-
|
|
7
|
-
function escapeHtml(str: unknown): string {
|
|
8
|
-
return String(str ?? '')
|
|
9
|
-
.replace(/&/g, '&')
|
|
10
|
-
.replace(/</g, '<')
|
|
11
|
-
.replace(/>/g, '>')
|
|
12
|
-
.replace(/"/g, '"')
|
|
13
|
-
.replace(/'/g, ''');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface DrawerTabOptions {
|
|
17
|
-
workbench: any;
|
|
18
|
-
drawerTab: string;
|
|
19
|
-
hasGuidedLab: boolean;
|
|
20
|
-
mode: string;
|
|
21
|
-
hasWebContent: boolean;
|
|
22
|
-
problemsCount: number;
|
|
23
|
-
testSuiteVisible: boolean;
|
|
24
|
-
lastDurationMs: number | null;
|
|
25
|
-
lastPeakMemoryBytes: number | null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function formatTelemetryHud(durationMs: number | null, memoryBytes: number | null, lang: string): string {
|
|
29
|
-
if (durationMs === null && memoryBytes === null) return '';
|
|
30
|
-
|
|
31
|
-
const timeStr = durationMs !== null
|
|
32
|
-
? (durationMs < 1000 ? `${durationMs.toFixed(1)} ms` : `${(durationMs / 1000).toFixed(2)} s`)
|
|
33
|
-
: '';
|
|
34
|
-
|
|
35
|
-
let memStr = '';
|
|
36
|
-
if (memoryBytes !== null && memoryBytes > 0) {
|
|
37
|
-
const mb = memoryBytes / (1024 * 1024);
|
|
38
|
-
const suffix = lang === 'cpp' ? 'Wasm' : lang === 'py' ? 'Heap' : 'Mem';
|
|
39
|
-
memStr = `${mb < 0.1 ? (memoryBytes / 1024).toFixed(1) + ' KB' : mb.toFixed(1) + ' MB'} ${suffix}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return `
|
|
43
|
-
<div class="codelab-hud-pill" id="cl-telemetry-hud" title="Last Execution Telemetry">
|
|
44
|
-
${timeStr ? `<span class="codelab-hud-pill__metric">${CL_ICONS.clock} <span>${timeStr}</span></span>` : ''}
|
|
45
|
-
${timeStr && memStr ? `<span style="opacity:0.4;">·</span>` : ''}
|
|
46
|
-
${memStr ? `<span class="codelab-hud-pill__metric">${CL_ICONS.memory} <span>${memStr}</span></span>` : ''}
|
|
47
|
-
</div>
|
|
48
|
-
`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function renderDrawerTabsHtml(opts: DrawerTabOptions): string {
|
|
52
|
-
const { workbench, drawerTab, hasGuidedLab, mode, hasWebContent, problemsCount, testSuiteVisible, lastDurationMs, lastPeakMemoryBytes } = opts;
|
|
53
|
-
const isGuided = Boolean(hasGuidedLab && mode === 'guided');
|
|
54
|
-
const showTests = isGuided || testSuiteVisible || drawerTab === 'tests';
|
|
55
|
-
|
|
56
|
-
return `
|
|
57
|
-
<div class="codelab-drawer__header">
|
|
58
|
-
<div class="codelab-drawer__tabs" role="tablist" aria-label="Terminal & Diagnostics Panels">
|
|
59
|
-
<button type="button" role="tab" aria-selected="${drawerTab === 'terminal'}" class="codelab-drawer__tab ${drawerTab === 'terminal' ? 'active' : ''}" data-cl-drawertab="terminal">
|
|
60
|
-
${CL_ICONS.terminal}
|
|
61
|
-
<span>Terminal & REPL</span>
|
|
62
|
-
</button>
|
|
63
|
-
|
|
64
|
-
<button type="button" role="tab" aria-selected="${drawerTab === 'problems'}" class="codelab-drawer__tab ${drawerTab === 'problems' ? 'active' : ''}" data-cl-drawertab="problems" title="Compiler & Runtime Problems">
|
|
65
|
-
${CL_ICONS.warning}
|
|
66
|
-
<span>Problems</span>
|
|
67
|
-
<span class="codelab-badge ${problemsCount > 0 ? 'codelab-badge--warn' : ''}" id="cl-problems-count">${problemsCount}</span>
|
|
68
|
-
</button>
|
|
69
|
-
|
|
70
|
-
<button type="button" role="tab" aria-selected="${drawerTab === 'tests'}" class="codelab-drawer__tab ${drawerTab === 'tests' ? 'active' : ''}" data-cl-drawertab="tests">
|
|
71
|
-
${CL_ICONS.check}
|
|
72
|
-
<span>Test Suite</span>
|
|
73
|
-
</button>
|
|
74
|
-
|
|
75
|
-
<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">
|
|
76
|
-
${CL_ICONS.keyboard}
|
|
77
|
-
<span>Stdin</span>
|
|
78
|
-
</button>
|
|
79
|
-
|
|
80
|
-
<button type="button" role="tab" aria-selected="${drawerTab === 'ports'}" class="codelab-drawer__tab ${drawerTab === 'ports' ? 'active' : ''}" data-cl-drawertab="ports">
|
|
81
|
-
${CL_ICONS.radio}
|
|
82
|
-
<span>Ports</span>
|
|
83
|
-
</button>
|
|
84
|
-
|
|
85
|
-
<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">
|
|
86
|
-
${CL_ICONS.externalLink || CL_ICONS.globe}
|
|
87
|
-
<span>Web Preview</span>
|
|
88
|
-
</button>
|
|
89
|
-
|
|
90
|
-
<button type="button" role="tab" aria-selected="${drawerTab === 'network'}" class="codelab-drawer__tab ${drawerTab === 'network' ? 'active' : ''}" data-cl-drawertab="network">
|
|
91
|
-
${CL_ICONS.activity}
|
|
92
|
-
<span>Network</span>
|
|
93
|
-
</button>
|
|
94
|
-
|
|
95
|
-
<button type="button" role="tab" aria-selected="${drawerTab === 'inspector'}" class="codelab-drawer__tab ${drawerTab === 'inspector' ? 'active' : ''}" data-cl-drawertab="inspector">
|
|
96
|
-
${CL_ICONS.database}
|
|
97
|
-
<span>Virtual Disk & HTTP</span>
|
|
98
|
-
</button>
|
|
99
|
-
</div>
|
|
100
|
-
|
|
101
|
-
${formatTelemetryHud(lastDurationMs, lastPeakMemoryBytes, workbench.lang || 'js')}
|
|
102
|
-
|
|
103
|
-
<div class="codelab-drawer__actions">
|
|
104
|
-
<button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="toggle-drawer" title="Minimize/Expand Drawer" aria-label="Minimize or Expand Drawer">
|
|
105
|
-
${CL_ICONS.chevronsUpDown}
|
|
106
|
-
</button>
|
|
107
|
-
</div>
|
|
108
|
-
</div>
|
|
109
|
-
`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function renderProblemsPanelHtml(workbench: any): string {
|
|
113
|
-
const store = workbench._diagnosticsStore;
|
|
114
|
-
const items = store ? store.getAll() : [];
|
|
115
|
-
|
|
116
|
-
if (items.length === 0) {
|
|
117
|
-
return `
|
|
118
|
-
<div class="cl-ui-empty-center">
|
|
119
|
-
${CL_ICONS.check}
|
|
120
|
-
<span>No problems detected in workspace.</span>
|
|
121
|
-
</div>
|
|
122
|
-
`;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return `
|
|
126
|
-
<div class="codelab-problems-list">
|
|
127
|
-
${items.map((item: any) => {
|
|
128
|
-
const icon = item.severity === 'error' ? '✗' : (item.severity === 'warning' ? '⚠' : 'ℹ');
|
|
129
|
-
const cls = item.severity === 'error' ? 'codelab-problem-item--error' : (item.severity === 'warning' ? 'codelab-problem-item--warning' : 'codelab-problem-item--info');
|
|
130
|
-
const safeFile = escapeHtml(item.file);
|
|
131
|
-
const safeMsg = escapeHtml(item.message);
|
|
132
|
-
const safeLine = Number(item.line) || 1;
|
|
133
|
-
const safeCol = Number(item.col) || 1;
|
|
134
|
-
return `
|
|
135
|
-
<div class="codelab-problem-item ${cls}" data-cl-problem-file="${safeFile}" data-cl-problem-line="${safeLine}" data-cl-problem-col="${safeCol}">
|
|
136
|
-
<span style="font-weight:bold;">${icon}</span>
|
|
137
|
-
<span>${safeMsg}</span>
|
|
138
|
-
<span class="codelab-problem-item__location">${safeFile}:${safeLine}:${safeCol}</span>
|
|
139
|
-
</div>
|
|
140
|
-
`;
|
|
141
|
-
}).join('')}
|
|
142
|
-
</div>
|
|
143
|
-
`;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function renderStdinPanelHtml(workbench: any): string {
|
|
147
|
-
const val = escapeHtml(workbench.customStdin || '');
|
|
148
|
-
return `
|
|
149
|
-
<div class="codelab-stdin-panel">
|
|
150
|
-
<div class="codelab-stdin-panel__header">
|
|
151
|
-
<span>Standard Input (std::cin / sys.stdin / process.stdin)</span>
|
|
152
|
-
<button type="button" class="codelab-btn codelab-btn--sm" id="cl-stdin-clear-btn">Clear</button>
|
|
153
|
-
</div>
|
|
154
|
-
<textarea class="codelab-stdin-panel__textarea" id="cl-stdin-textarea" placeholder="Paste custom input lines here for DSA / competitive programming...">${val}</textarea>
|
|
155
|
-
</div>
|
|
156
|
-
`;
|
|
157
|
-
}
|
package/src/workbench/editor.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
}
|