@innovatorved/code-lab 0.5.0 → 0.6.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.
- package/ARCHITECTURE.md +3 -3
- package/CHANGELOG.md +23 -0
- package/README.md +3 -3
- package/dist/code-lab-sql.css +87 -64
- package/dist/code-lab-sql.esm.js +109 -86
- package/dist/code-lab-sql.umd.js +110 -87
- package/dist/code-lab.css +32 -7273
- package/dist/code-lab.d.ts +1 -1
- package/dist/code-lab.esm.js +4966 -74622
- package/dist/code-lab.js +4974 -74631
- package/dist/code-lab.umd.js +4974 -74631
- package/dist/extensions/cpp.d.ts +2 -2
- package/dist/extensions/cpp.esm.js +1788 -14707
- package/dist/extensions/cpp.js +1788 -14707
- package/dist/extensions/guided-lab.esm.js +2938 -16127
- package/dist/extensions/guided-lab.js +2938 -16127
- package/dist/extensions/python.d.ts +2 -2
- package/dist/extensions/python.esm.js +1769 -14701
- package/dist/extensions/python.js +1769 -14701
- package/dist/index.d.ts +1 -1
- package/dist/packages/sql/src/styles.d.ts +1 -1
- package/dist/packages/ui/src/settings-dialog.d.ts +2 -0
- package/dist/preview-sw.js +4 -188
- package/dist/runtime.esm.js +109 -10284
- package/dist/runtime.js +107 -10284
- package/dist/schemas.d.ts +2 -2
- package/dist/schemas.esm.js +2938 -16127
- package/dist/schemas.js +2941 -16130
- package/dist/scm.d.ts +221 -20
- package/dist/shell.esm.js +811 -10002
- package/dist/shell.js +811 -10002
- package/dist/storage.d.ts +9 -0
- package/dist/terminal.esm.js +20 -1347
- package/dist/terminal.js +20 -1347
- package/dist/workbench/command-palette.d.ts +16 -1
- package/dist/workbench/diff-editor.d.ts +27 -1
- package/dist/workbench/icons.d.ts +6 -2
- package/dist/workbench/index.d.ts +33 -1
- package/dist/workbench/intellisense.d.ts +194 -0
- package/dist/workbench/styles.d.ts +1 -1
- package/dist/workbench/xterm-adapter.d.ts +122 -0
- package/package.json +7 -1
- package/packages/commands/package.json +1 -1
- package/packages/core/package.json +1 -1
- package/packages/editor/package.json +1 -1
- package/packages/fs/package.json +1 -1
- package/packages/preview/package.json +1 -1
- package/packages/runtime/package.json +1 -1
- package/packages/settings/package.json +1 -1
- package/packages/sql/package.json +1 -1
- package/packages/sql/src/styles.ts +87 -64
- package/packages/terminal/package.json +1 -1
- package/packages/ui/package.json +1 -1
- package/packages/ui/src/observability.ts +12 -14
- package/packages/ui/src/settings-dialog.ts +383 -47
- package/packages/ui/src/themes.ts +89 -23
- package/src/code-lab.css +1883 -578
- package/src/extensions/cpp.ts +304 -38
- package/src/extensions/python.ts +342 -43
- package/src/index.ts +1 -1
- package/src/runtime.ts +272 -43
- package/src/schemas.ts +2 -2
- package/src/scm.ts +1467 -92
- package/src/shell.ts +1075 -93
- package/src/storage.ts +66 -3
- package/src/terminal.ts +148 -12
- package/src/workbench/command-palette.ts +289 -48
- package/src/workbench/diff-editor.ts +244 -78
- package/src/workbench/drawer.ts +5 -5
- package/src/workbench/icons.ts +250 -53
- package/src/workbench/index.ts +7 -1
- package/src/workbench/intellisense.ts +1871 -0
- package/src/workbench/styles.ts +58 -54
- package/src/workbench/toolbar.ts +1 -1
- package/src/workbench/xterm-adapter.ts +1571 -0
- package/src/workbench.ts +1699 -324
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { CL_ICONS } from './icons';
|
|
6
|
+
import { getMonacoLanguageForFile, getMonacoThemeName } from './intellisense';
|
|
6
7
|
|
|
7
8
|
function escapeHtml(str: unknown): string {
|
|
8
9
|
return String(str ?? '')
|
|
@@ -19,6 +20,16 @@ export interface DiffComputeResult {
|
|
|
19
20
|
removed: number;
|
|
20
21
|
}
|
|
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
|
+
|
|
22
33
|
export function computeSimpleDiff(oldText: string, newText: string): DiffComputeResult {
|
|
23
34
|
const oldLines = String(oldText || '').split('\n');
|
|
24
35
|
const newLines = String(newText || '').split('\n');
|
|
@@ -70,6 +81,26 @@ export function computeSimpleDiff(oldText: string, newText: string): DiffCompute
|
|
|
70
81
|
return { hunks, added, removed };
|
|
71
82
|
}
|
|
72
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
|
+
|
|
73
104
|
export class CodeLabDiffEditorManager {
|
|
74
105
|
private workbench: any;
|
|
75
106
|
private diffEditor: any = null;
|
|
@@ -77,12 +108,200 @@ export class CodeLabDiffEditorManager {
|
|
|
77
108
|
private modifiedModel: any = null;
|
|
78
109
|
public isActive = false;
|
|
79
110
|
public activeFile = '';
|
|
80
|
-
public currentTarget: 'starter' | 'solution' = 'solution';
|
|
111
|
+
public currentTarget: 'starter' | 'solution' | 'git' = 'solution';
|
|
81
112
|
|
|
82
113
|
constructor(workbench: any) {
|
|
83
114
|
this.workbench = workbench;
|
|
84
115
|
}
|
|
85
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
|
+
|
|
86
305
|
public openInlineDiff(file: string, target: 'starter' | 'solution' = 'solution'): boolean {
|
|
87
306
|
const monaco = typeof window !== 'undefined' ? (window as any).monaco : null;
|
|
88
307
|
this.activeFile = file;
|
|
@@ -92,7 +311,6 @@ export class CodeLabDiffEditorManager {
|
|
|
92
311
|
const fallbackTextarea = this.workbench.container?.querySelector('#cl-fallback-editor');
|
|
93
312
|
if (!editorHost) return false;
|
|
94
313
|
|
|
95
|
-
// Get reference code
|
|
96
314
|
const isStarter = target === 'starter';
|
|
97
315
|
const baseFiles = this.workbench._getBaseFilesForModeAndLang
|
|
98
316
|
? this.workbench._getBaseFilesForModeAndLang(isStarter ? 'guided' : 'sandbox', this.workbench.lang)
|
|
@@ -102,53 +320,29 @@ export class CodeLabDiffEditorManager {
|
|
|
102
320
|
const currentCode = this.workbench.files[file] !== undefined ? this.workbench.files[file] : '';
|
|
103
321
|
|
|
104
322
|
if (!monaco || !monaco.editor || typeof monaco.editor.createDiffEditor !== 'function') {
|
|
105
|
-
// Fall back to modal diff if Monaco or createDiffEditor is not available
|
|
106
323
|
if (typeof this.workbench.showDiffModalFallback === 'function') {
|
|
107
324
|
this.workbench.showDiffModalFallback(file, target);
|
|
108
325
|
}
|
|
109
326
|
return false;
|
|
110
327
|
}
|
|
111
328
|
|
|
329
|
+
const hosts = this._ensureDiffContainer();
|
|
330
|
+
if (!hosts) return false;
|
|
331
|
+
const { diffContainer } = hosts;
|
|
112
332
|
this.isActive = true;
|
|
113
333
|
|
|
114
|
-
// Create or reuse diff container
|
|
115
|
-
let diffContainer = this.workbench.container.querySelector('#cl-inline-diff-container');
|
|
116
|
-
if (!diffContainer) {
|
|
117
|
-
diffContainer = document.createElement('div');
|
|
118
|
-
diffContainer.id = 'cl-inline-diff-container';
|
|
119
|
-
diffContainer.className = 'codelab-diff-container';
|
|
120
|
-
editorHost.parentElement.appendChild(diffContainer);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
diffContainer.style.display = 'flex';
|
|
124
|
-
if (editorHost) editorHost.style.display = 'none';
|
|
125
|
-
if (fallbackTextarea) fallbackTextarea.style.display = 'none';
|
|
126
|
-
|
|
127
|
-
if (this.diffEditor) {
|
|
128
|
-
this.diffEditor.dispose();
|
|
129
|
-
this.diffEditor = null;
|
|
130
|
-
}
|
|
131
|
-
if (this.originalModel) {
|
|
132
|
-
this.originalModel.dispose();
|
|
133
|
-
this.originalModel = null;
|
|
134
|
-
}
|
|
135
|
-
if (this.modifiedModel) {
|
|
136
|
-
this.modifiedModel.dispose();
|
|
137
|
-
this.modifiedModel = null;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
334
|
const safeFile = escapeHtml(file);
|
|
141
335
|
diffContainer.innerHTML = `
|
|
142
336
|
<div class="codelab-diff-toolbar">
|
|
143
|
-
<span
|
|
337
|
+
<span class="codelab-diff-toolbar__title">
|
|
144
338
|
${CL_ICONS.diff}
|
|
145
339
|
<span>Diff: <code>${safeFile}</code> (${isStarter ? 'Current vs Starter' : 'Current vs Solution'})</span>
|
|
146
340
|
</span>
|
|
147
|
-
<div class="codelab-segmented" style="margin-left:
|
|
341
|
+
<div class="codelab-segmented" style="margin-left:12px;">
|
|
148
342
|
<button type="button" class="codelab-segmented__btn ${target === 'starter' ? 'active' : ''}" id="cl-diff-toggle-starter">Starter</button>
|
|
149
343
|
<button type="button" class="codelab-segmented__btn ${target === 'solution' ? 'active' : ''}" id="cl-diff-toggle-solution">Solution</button>
|
|
150
344
|
</div>
|
|
151
|
-
<div
|
|
345
|
+
<div class="codelab-diff-toolbar__actions">
|
|
152
346
|
<button type="button" class="codelab-btn codelab-btn--sm" id="cl-diff-revert-btn">${CL_ICONS.refresh} Revert File</button>
|
|
153
347
|
<button type="button" class="codelab-btn codelab-btn--sm codelab-btn--primary" id="cl-diff-apply-btn">${CL_ICONS.check} Apply Solution</button>
|
|
154
348
|
<button type="button" class="codelab-btn codelab-btn--sm" id="cl-diff-close-btn">${CL_ICONS.x} Close Diff</button>
|
|
@@ -161,19 +355,20 @@ export class CodeLabDiffEditorManager {
|
|
|
161
355
|
const resolvedTheme = typeof this.workbench._resolvedTheme === 'function'
|
|
162
356
|
? this.workbench._resolvedTheme()
|
|
163
357
|
: this.workbench.theme;
|
|
164
|
-
const monacoTheme = resolvedTheme
|
|
165
|
-
? 'vs'
|
|
166
|
-
: (resolvedTheme === 'high-contrast' ? 'hc-black' : 'vs-dark');
|
|
358
|
+
const monacoTheme = getMonacoThemeName(resolvedTheme, monaco);
|
|
167
359
|
this.diffEditor = monaco.editor.createDiffEditor(slot, {
|
|
168
360
|
readOnly: false,
|
|
169
361
|
originalEditable: false,
|
|
170
362
|
theme: monacoTheme,
|
|
171
363
|
renderSideBySide: true,
|
|
172
364
|
automaticLayout: true,
|
|
173
|
-
minimap: { enabled: false }
|
|
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
|
|
174
369
|
});
|
|
175
370
|
|
|
176
|
-
const lang =
|
|
371
|
+
const lang = getMonacoLanguageForFile(file, this.workbench.lang);
|
|
177
372
|
this.originalModel = monaco.editor.createModel(refCode, lang);
|
|
178
373
|
this.modifiedModel = monaco.editor.createModel(currentCode, lang);
|
|
179
374
|
|
|
@@ -182,35 +377,10 @@ export class CodeLabDiffEditorManager {
|
|
|
182
377
|
modified: this.modifiedModel
|
|
183
378
|
});
|
|
184
379
|
|
|
185
|
-
const syncFileToWorkbench = (val: string): void => {
|
|
186
|
-
this.workbench.files[file] = val;
|
|
187
|
-
const mainModel = this.workbench.models && typeof this.workbench.models.get === 'function'
|
|
188
|
-
? this.workbench.models.get(file)
|
|
189
|
-
: null;
|
|
190
|
-
if (mainModel && typeof mainModel.getValue === 'function' && mainModel.getValue() !== val) {
|
|
191
|
-
mainModel.setValue(val);
|
|
192
|
-
}
|
|
193
|
-
if (this.workbench.activeFile === file && fallbackTextarea && fallbackTextarea.value !== val) {
|
|
194
|
-
fallbackTextarea.value = val;
|
|
195
|
-
}
|
|
196
|
-
if (this.workbench.shell && this.workbench.shell.vfs && typeof this.workbench.shell.vfs.writeFileSync === 'function') {
|
|
197
|
-
const vfsPath = file.startsWith('/') ? file : `/workspace/${file}`;
|
|
198
|
-
this.workbench.shell.vfs.writeFileSync(vfsPath, val);
|
|
199
|
-
}
|
|
200
|
-
if (typeof this.workbench._saveState === 'function') {
|
|
201
|
-
this.workbench._saveState();
|
|
202
|
-
}
|
|
203
|
-
if (typeof this.workbench._markDirty === 'function') {
|
|
204
|
-
this.workbench._markDirty(file);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
// Wire modified model edits back to workbench, main Monaco model, VFS, and persistence
|
|
209
380
|
this.modifiedModel.onDidChangeContent(() => {
|
|
210
|
-
syncFileToWorkbench(this.modifiedModel.getValue());
|
|
381
|
+
this.syncFileToWorkbench(file, this.modifiedModel.getValue());
|
|
211
382
|
});
|
|
212
383
|
|
|
213
|
-
// Wire buttons
|
|
214
384
|
diffContainer.querySelector('#cl-diff-toggle-starter')?.addEventListener('click', () => {
|
|
215
385
|
this.openInlineDiff(file, 'starter');
|
|
216
386
|
});
|
|
@@ -223,7 +393,7 @@ export class CodeLabDiffEditorManager {
|
|
|
223
393
|
if (typeof this.workbench.setFile === 'function') {
|
|
224
394
|
this.workbench.setFile(file, starterCode);
|
|
225
395
|
} else {
|
|
226
|
-
syncFileToWorkbench(starterCode);
|
|
396
|
+
this.syncFileToWorkbench(file, starterCode);
|
|
227
397
|
}
|
|
228
398
|
this.closeInlineDiff();
|
|
229
399
|
this.workbench.openFile(file);
|
|
@@ -239,7 +409,7 @@ export class CodeLabDiffEditorManager {
|
|
|
239
409
|
if (typeof this.workbench.setFile === 'function') {
|
|
240
410
|
this.workbench.setFile(file, solutionCode);
|
|
241
411
|
} else {
|
|
242
|
-
syncFileToWorkbench(solutionCode);
|
|
412
|
+
this.syncFileToWorkbench(file, solutionCode);
|
|
243
413
|
}
|
|
244
414
|
this.closeInlineDiff();
|
|
245
415
|
this.workbench.openFile(file);
|
|
@@ -276,6 +446,9 @@ export class CodeLabDiffEditorManager {
|
|
|
276
446
|
if (typeof this.workbench._markDirty === 'function') {
|
|
277
447
|
this.workbench._markDirty(file);
|
|
278
448
|
}
|
|
449
|
+
if (typeof this.workbench._refreshGitDecorations === 'function') {
|
|
450
|
+
this.workbench._refreshGitDecorations();
|
|
451
|
+
}
|
|
279
452
|
}
|
|
280
453
|
|
|
281
454
|
public closeInlineDiff(): void {
|
|
@@ -284,21 +457,14 @@ export class CodeLabDiffEditorManager {
|
|
|
284
457
|
if (diffContainer) {
|
|
285
458
|
diffContainer.style.display = 'none';
|
|
286
459
|
}
|
|
460
|
+
const isWelcomeActive = this.workbench.activeFile === '__welcome__';
|
|
461
|
+
const welcomeHost = this.workbench.container?.querySelector('#cl-welcome-host');
|
|
287
462
|
const editorHost = this.workbench.container?.querySelector('#cl-editor-host') || this.workbench.container?.querySelector('#cl-monaco-host');
|
|
288
|
-
if (
|
|
463
|
+
if (isWelcomeActive && welcomeHost) {
|
|
464
|
+
welcomeHost.style.display = 'flex';
|
|
465
|
+
} else if (editorHost) {
|
|
289
466
|
editorHost.style.display = '';
|
|
290
467
|
}
|
|
291
|
-
|
|
292
|
-
this.diffEditor.dispose();
|
|
293
|
-
this.diffEditor = null;
|
|
294
|
-
}
|
|
295
|
-
if (this.originalModel) {
|
|
296
|
-
this.originalModel.dispose();
|
|
297
|
-
this.originalModel = null;
|
|
298
|
-
}
|
|
299
|
-
if (this.modifiedModel) {
|
|
300
|
-
this.modifiedModel.dispose();
|
|
301
|
-
this.modifiedModel = null;
|
|
302
|
-
}
|
|
468
|
+
this._disposeEditorModels();
|
|
303
469
|
}
|
|
304
470
|
}
|
package/src/workbench/drawer.ts
CHANGED
|
@@ -64,7 +64,7 @@ export function renderDrawerTabsHtml(opts: DrawerTabOptions): string {
|
|
|
64
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
65
|
${CL_ICONS.warning}
|
|
66
66
|
<span>Problems</span>
|
|
67
|
-
<span class="codelab-badge ${problemsCount > 0 ? 'codelab-badge--warn' : ''}" id="cl-problems-count"
|
|
67
|
+
<span class="codelab-badge ${problemsCount > 0 ? 'codelab-badge--warn' : ''}" id="cl-problems-count">${problemsCount}</span>
|
|
68
68
|
</button>
|
|
69
69
|
|
|
70
70
|
<button type="button" role="tab" aria-selected="${drawerTab === 'tests'}" class="codelab-drawer__tab ${drawerTab === 'tests' ? 'active' : ''}" data-cl-drawertab="tests">
|
|
@@ -100,8 +100,8 @@ export function renderDrawerTabsHtml(opts: DrawerTabOptions): string {
|
|
|
100
100
|
|
|
101
101
|
${formatTelemetryHud(lastDurationMs, lastPeakMemoryBytes, workbench.lang || 'js')}
|
|
102
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"
|
|
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
105
|
${CL_ICONS.chevronsUpDown}
|
|
106
106
|
</button>
|
|
107
107
|
</div>
|
|
@@ -115,7 +115,7 @@ export function renderProblemsPanelHtml(workbench: any): string {
|
|
|
115
115
|
|
|
116
116
|
if (items.length === 0) {
|
|
117
117
|
return `
|
|
118
|
-
<div
|
|
118
|
+
<div class="cl-ui-empty-center">
|
|
119
119
|
${CL_ICONS.check}
|
|
120
120
|
<span>No problems detected in workspace.</span>
|
|
121
121
|
</div>
|
|
@@ -149,7 +149,7 @@ export function renderStdinPanelHtml(workbench: any): string {
|
|
|
149
149
|
<div class="codelab-stdin-panel">
|
|
150
150
|
<div class="codelab-stdin-panel__header">
|
|
151
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"
|
|
152
|
+
<button type="button" class="codelab-btn codelab-btn--sm" id="cl-stdin-clear-btn">Clear</button>
|
|
153
153
|
</div>
|
|
154
154
|
<textarea class="codelab-stdin-panel__textarea" id="cl-stdin-textarea" placeholder="Paste custom input lines here for DSA / competitive programming...">${val}</textarea>
|
|
155
155
|
</div>
|