@innovatorved/code-lab 0.1.1 → 0.1.3
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/dist/code-lab.css +78 -31
- package/dist/code-lab.d.ts +1 -0
- package/dist/code-lab.esm.js +226 -93
- package/dist/code-lab.js +226 -93
- package/dist/shell.esm.js +38 -8
- package/dist/shell.js +38 -8
- package/package.json +1 -1
- package/src/code-lab.css +78 -31
- package/src/shell.js +38 -8
- package/src/shell.ts +38 -8
- package/src/workbench.js +188 -85
- package/src/workbench.ts +188 -85
package/dist/code-lab.esm.js
CHANGED
|
@@ -9499,6 +9499,16 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9499
9499
|
const requestedBranch = options.branch || parsed.branch || null;
|
|
9500
9500
|
const { owner, repo } = parsed;
|
|
9501
9501
|
|
|
9502
|
+
const signal = options.signal || null;
|
|
9503
|
+
const throwIfAborted = () => {
|
|
9504
|
+
if (signal && signal.aborted) {
|
|
9505
|
+
const abortErr = new Error('fatal: clone cancelled (SIGINT)');
|
|
9506
|
+
abortErr.name = 'AbortError';
|
|
9507
|
+
throw abortErr;
|
|
9508
|
+
}
|
|
9509
|
+
};
|
|
9510
|
+
throwIfAborted();
|
|
9511
|
+
|
|
9502
9512
|
let resolvedBranch = requestedBranch;
|
|
9503
9513
|
let rawTreeEntries = null;
|
|
9504
9514
|
let repoNotFound = false;
|
|
@@ -9511,7 +9521,8 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9511
9521
|
try {
|
|
9512
9522
|
if (!resolvedBranch) {
|
|
9513
9523
|
const metaRes = await fetchFn(`https://api.github.com/repos/${owner}/${repo}`, {
|
|
9514
|
-
headers: { Accept: 'application/vnd.github.v3+json' }
|
|
9524
|
+
headers: { Accept: 'application/vnd.github.v3+json' },
|
|
9525
|
+
signal
|
|
9515
9526
|
});
|
|
9516
9527
|
if (metaRes.status === 404) {
|
|
9517
9528
|
repoNotFound = true;
|
|
@@ -9529,9 +9540,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9529
9540
|
: Array.from(new Set([resolvedBranch, 'main', 'master'].filter(Boolean)));
|
|
9530
9541
|
|
|
9531
9542
|
for (const cand of branchCandidates) {
|
|
9543
|
+
throwIfAborted();
|
|
9532
9544
|
const treeRes = await fetchFn(
|
|
9533
9545
|
`https://api.github.com/repos/${owner}/${repo}/git/trees/${encodeURIComponent(cand)}?recursive=1`,
|
|
9534
|
-
{ headers: { Accept: 'application/vnd.github.v3+json' } }
|
|
9546
|
+
{ headers: { Accept: 'application/vnd.github.v3+json' }, signal }
|
|
9535
9547
|
);
|
|
9536
9548
|
if (treeRes.ok) {
|
|
9537
9549
|
const treeJson = await treeRes.json();
|
|
@@ -9557,8 +9569,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9557
9569
|
: Array.from(new Set([resolvedBranch, 'main', 'master'].filter(Boolean)));
|
|
9558
9570
|
|
|
9559
9571
|
for (const cand of branchCandidates) {
|
|
9572
|
+
throwIfAborted();
|
|
9560
9573
|
const flatRes = await fetchFn(
|
|
9561
|
-
`https://data.jsdelivr.com/v1/package/gh/${owner}/${repo}@${encodeURIComponent(cand)}/flat
|
|
9574
|
+
`https://data.jsdelivr.com/v1/package/gh/${owner}/${repo}@${encodeURIComponent(cand)}/flat`,
|
|
9575
|
+
{ signal }
|
|
9562
9576
|
);
|
|
9563
9577
|
if (flatRes && flatRes.ok) {
|
|
9564
9578
|
const flatJson = await flatRes.json();
|
|
@@ -9627,28 +9641,34 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9627
9641
|
const BATCH_SIZE = 12;
|
|
9628
9642
|
|
|
9629
9643
|
for (let i = 0; i < selectedFiles.length; i += BATCH_SIZE) {
|
|
9644
|
+
throwIfAborted();
|
|
9630
9645
|
const batch = selectedFiles.slice(i, i + BATCH_SIZE);
|
|
9631
9646
|
await Promise.all(
|
|
9632
9647
|
batch.map(async (entry) => {
|
|
9648
|
+
throwIfAborted();
|
|
9633
9649
|
const encodedPath = entry.repoPath.split('/').map(encodeURIComponent).join('/');
|
|
9634
9650
|
const rawUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${encodeURIComponent(resolvedBranch)}/${encodedPath}`;
|
|
9635
9651
|
const cdnUrl = `https://cdn.jsdelivr.net/gh/${owner}/${repo}@${encodeURIComponent(resolvedBranch)}/${encodedPath}`;
|
|
9636
9652
|
|
|
9637
9653
|
let text = null;
|
|
9638
9654
|
try {
|
|
9639
|
-
const r1 = await fetchFn(rawUrl);
|
|
9655
|
+
const r1 = await fetchFn(rawUrl, { signal });
|
|
9640
9656
|
if (r1 && r1.ok) {
|
|
9641
9657
|
text = await r1.text();
|
|
9642
9658
|
}
|
|
9643
|
-
} catch (_) {
|
|
9659
|
+
} catch (_) {
|
|
9660
|
+
if (signal && signal.aborted) throw _;
|
|
9661
|
+
}
|
|
9644
9662
|
|
|
9645
9663
|
if (text === null) {
|
|
9646
9664
|
try {
|
|
9647
|
-
const r2 = await fetchFn(cdnUrl);
|
|
9665
|
+
const r2 = await fetchFn(cdnUrl, { signal });
|
|
9648
9666
|
if (r2 && r2.ok) {
|
|
9649
9667
|
text = await r2.text();
|
|
9650
9668
|
}
|
|
9651
|
-
} catch (_) {
|
|
9669
|
+
} catch (_) {
|
|
9670
|
+
if (signal && signal.aborted) throw _;
|
|
9671
|
+
}
|
|
9652
9672
|
}
|
|
9653
9673
|
|
|
9654
9674
|
if (text !== null && text.length <= maxFileSize) {
|
|
@@ -9672,6 +9692,8 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9672
9692
|
);
|
|
9673
9693
|
}
|
|
9674
9694
|
|
|
9695
|
+
throwIfAborted();
|
|
9696
|
+
|
|
9675
9697
|
if (onProgress) {
|
|
9676
9698
|
onProgress({ phase: 'mounting', message: `Mounting files and writing Git metadata into ${targetDir}...`, loaded: filesWritten, total: totalToDownload });
|
|
9677
9699
|
}
|
|
@@ -9692,7 +9714,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9692
9714
|
try {
|
|
9693
9715
|
const commitsRes = await fetchFn(
|
|
9694
9716
|
`https://api.github.com/repos/${owner}/${repo}/commits?sha=${encodeURIComponent(resolvedBranch)}&per_page=10`,
|
|
9695
|
-
{ headers: { Accept: 'application/vnd.github.v3+json' } }
|
|
9717
|
+
{ headers: { Accept: 'application/vnd.github.v3+json' }, signal }
|
|
9696
9718
|
);
|
|
9697
9719
|
if (commitsRes && commitsRes.ok) {
|
|
9698
9720
|
const commitsJson = await commitsRes.json();
|
|
@@ -11939,6 +11961,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
11939
11961
|
targetDir,
|
|
11940
11962
|
branch: branchOpt,
|
|
11941
11963
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
11964
|
+
signal: ctx.signal,
|
|
11942
11965
|
onFile: (absPath) => ctx.emitMutation('create', absPath),
|
|
11943
11966
|
onProgress: (ev) => {
|
|
11944
11967
|
if (!ev) return;
|
|
@@ -11979,6 +12002,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
11979
12002
|
`Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`;
|
|
11980
12003
|
return { code: 0, stdout, stderr: '' };
|
|
11981
12004
|
} catch (err) {
|
|
12005
|
+
if (ctx.signal && ctx.signal.aborted) {
|
|
12006
|
+
return { code: 130, stdout: '', stderr: '', aborted: true };
|
|
12007
|
+
}
|
|
11982
12008
|
const msg = err && err.message ? err.message : String(err);
|
|
11983
12009
|
if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
|
|
11984
12010
|
return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
@@ -12306,6 +12332,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
12306
12332
|
targetDir: repoRoot,
|
|
12307
12333
|
branch: gitState.branch,
|
|
12308
12334
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
12335
|
+
signal: ctx.signal,
|
|
12309
12336
|
onFile: (absPath) => ctx.emitMutation('change', absPath)
|
|
12310
12337
|
});
|
|
12311
12338
|
gitState.headSnapshot = Object.assign({}, result.headSnapshot);
|
|
@@ -12315,6 +12342,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
12315
12342
|
stderr: ''
|
|
12316
12343
|
};
|
|
12317
12344
|
} catch (err) {
|
|
12345
|
+
if (ctx.signal && ctx.signal.aborted) {
|
|
12346
|
+
return { code: 130, stdout: '', stderr: '', aborted: true };
|
|
12347
|
+
}
|
|
12318
12348
|
const msg = err && err.message ? err.message : String(err);
|
|
12319
12349
|
return { code: 1, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
12320
12350
|
}
|
|
@@ -16126,6 +16156,9 @@ declare module 'bun:sqlite' {
|
|
|
16126
16156
|
this.folders = new Set(this.savedState?.folders || []);
|
|
16127
16157
|
this.collapsedFolders = new Set(this.savedState?.collapsedFolders || []);
|
|
16128
16158
|
this.explorerFolder = this.savedState?.explorerFolder || ''; // '' = workspace root, else folder path scope
|
|
16159
|
+
this.explorerWidth = (typeof this.savedState?.explorerWidth === 'number' && this.savedState.explorerWidth >= 120)
|
|
16160
|
+
? this.savedState.explorerWidth
|
|
16161
|
+
: 196;
|
|
16129
16162
|
this.folderSwitcherOpen = false;
|
|
16130
16163
|
this.creatingItem = null; // { type: 'file' | 'folder', parentFolder: string } | null
|
|
16131
16164
|
this.renamingItem = null;
|
|
@@ -16463,7 +16496,8 @@ declare module 'bun:sqlite' {
|
|
|
16463
16496
|
activeFile: this.activeFile,
|
|
16464
16497
|
folders: Array.from(this.folders || []),
|
|
16465
16498
|
collapsedFolders: Array.from(this.collapsedFolders || []),
|
|
16466
|
-
explorerFolder: this.explorerFolder || ''
|
|
16499
|
+
explorerFolder: this.explorerFolder || '',
|
|
16500
|
+
explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined
|
|
16467
16501
|
};
|
|
16468
16502
|
this.savedState = state;
|
|
16469
16503
|
if (this.options && this.options.persistState === false) {
|
|
@@ -16644,6 +16678,13 @@ declare module 'bun:sqlite' {
|
|
|
16644
16678
|
if (stopBtn) {
|
|
16645
16679
|
stopBtn.style.display = this.isRunning ? 'inline-flex' : 'none';
|
|
16646
16680
|
}
|
|
16681
|
+
const ctrlCBtn = this.container.querySelector('#cl-ctrl-c-btn');
|
|
16682
|
+
if (ctrlCBtn) {
|
|
16683
|
+
ctrlCBtn.classList.toggle('is-running', Boolean(this.isRunning));
|
|
16684
|
+
ctrlCBtn.title = this.isRunning
|
|
16685
|
+
? 'Send Ctrl+C — interrupt the running command'
|
|
16686
|
+
: 'Send Ctrl+C (clears the current input line)';
|
|
16687
|
+
}
|
|
16647
16688
|
this.container.querySelectorAll('[data-cl-action="run-demo"], [data-cl-action="run-tests"], [data-cl-action="verify-step"]').forEach(btn => {
|
|
16648
16689
|
btn.disabled = this.isRunning;
|
|
16649
16690
|
});
|
|
@@ -16658,8 +16699,9 @@ declare module 'bun:sqlite' {
|
|
|
16658
16699
|
const themeAttr = this.themeOption !== 'auto' ? `data-theme="${escapeHtml(this.themeOption)}"` : '';
|
|
16659
16700
|
const brandLabel = (this.title && this.title !== 'custom-lab' && this.title !== this.labId) ? this.title : 'code-lab';
|
|
16660
16701
|
const isGuideCollapsed = !this.hasGuidedLab || this.mode === 'sandbox' || !this.steps.length;
|
|
16702
|
+
const explorerStyle = `style="--cl-explorer-width:${Math.round(this.explorerWidth || 196)}px"`;
|
|
16661
16703
|
this.container.innerHTML = `
|
|
16662
|
-
<div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr}>
|
|
16704
|
+
<div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr} ${explorerStyle}>
|
|
16663
16705
|
<!-- Top Bar -->
|
|
16664
16706
|
<div class="codelab-topbar codelab-toolbar">
|
|
16665
16707
|
<div class="codelab-topbar__left">
|
|
@@ -16775,6 +16817,9 @@ declare module 'bun:sqlite' {
|
|
|
16775
16817
|
<div class="codelab-explorer__list" id="cl-explorer-list"></div>
|
|
16776
16818
|
</div>
|
|
16777
16819
|
|
|
16820
|
+
<!-- Explorer Resize Splitter -->
|
|
16821
|
+
<div class="codelab-splitter-files" id="cl-splitter-files" role="separator" aria-orientation="vertical" title="Drag to resize file explorer (double-click to reset)"></div>
|
|
16822
|
+
|
|
16778
16823
|
<!-- Editor Column -->
|
|
16779
16824
|
<div class="codelab-editor-col">
|
|
16780
16825
|
<div class="codelab-tabs codelab-file-tabs" id="cl-file-tabs" role="tablist" aria-label="Open Files"></div>
|
|
@@ -16828,6 +16873,7 @@ declare module 'bun:sqlite' {
|
|
|
16828
16873
|
</button>
|
|
16829
16874
|
</div>
|
|
16830
16875
|
<div style="display:flex;align-items:center;gap:6px;">
|
|
16876
|
+
<button type="button" class="codelab-btn codelab-btn--icon codelab-btn--ctrl-c" id="cl-ctrl-c-btn" data-cl-action="interrupt" title="Send Ctrl+C — interrupt a running command" aria-label="Send Ctrl+C interrupt" style="padding:2px 8px;font-size:11px;font-family:var(--cl-font-mono);">Ctrl+C</button>
|
|
16831
16877
|
<button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="clear-terminal" title="Clear Output" style="padding:2px 6px;font-size:11px;">Clear</button>
|
|
16832
16878
|
<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;">${CL_ICONS.chevronsUpDown}</button>
|
|
16833
16879
|
</div>
|
|
@@ -17969,10 +18015,10 @@ declare module 'bun:sqlite' {
|
|
|
17969
18015
|
this._ptyInputAfterCursor = '';
|
|
17970
18016
|
this._updatePtyActiveLine();
|
|
17971
18017
|
}
|
|
17972
|
-
} else if (
|
|
18018
|
+
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'c') {
|
|
17973
18019
|
e.preventDefault();
|
|
17974
18020
|
this._handleInterrupt();
|
|
17975
|
-
} else if (
|
|
18021
|
+
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'd') {
|
|
17976
18022
|
e.preventDefault();
|
|
17977
18023
|
if (this.inRepl) {
|
|
17978
18024
|
this.inRepl = false;
|
|
@@ -17981,7 +18027,7 @@ declare module 'bun:sqlite' {
|
|
|
17981
18027
|
const nextInput = this.container.querySelector('#cl-repl-input');
|
|
17982
18028
|
if (nextInput && typeof nextInput.focus === 'function') nextInput.focus();
|
|
17983
18029
|
}
|
|
17984
|
-
} else if (
|
|
18030
|
+
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'l') {
|
|
17985
18031
|
e.preventDefault();
|
|
17986
18032
|
this.terminalLogs = [];
|
|
17987
18033
|
this._renderDrawerBody();
|
|
@@ -18108,6 +18154,39 @@ declare module 'bun:sqlite' {
|
|
|
18108
18154
|
const termSurface = this.container ? this.container.querySelector('#cl-terminal-surface') : null;
|
|
18109
18155
|
const drawerBody = this.container ? this.container.querySelector('.codelab-drawer__body') : null;
|
|
18110
18156
|
|
|
18157
|
+
// The workbench owns live terminal rendering. Only defer when an attached PTY
|
|
18158
|
+
// engine is itself rendering into the DOM (it is created with a null container in
|
|
18159
|
+
// production, so this remains the sole renderer there).
|
|
18160
|
+
const ptyOwnsDom = Boolean(this.ptyEngine && this.ptyEngine.container);
|
|
18161
|
+
const canPatchDom = Boolean(termLogEl && typeof document !== 'undefined' && !ptyOwnsDom);
|
|
18162
|
+
|
|
18163
|
+
// Write a single logical line into the live terminal DOM immediately, so output
|
|
18164
|
+
// streams in as it is produced instead of appearing only when the command ends and
|
|
18165
|
+
// the whole drawer is re-rendered. Reuses the current partial-line element when it
|
|
18166
|
+
// is still attached (carriage-return overwrites / keep-alive updates).
|
|
18167
|
+
const patchLineInDom = (text) => {
|
|
18168
|
+
if (!canPatchDom) return;
|
|
18169
|
+
const html = ansiToHtml ? ansiToHtml(text) : escapeHtml(text);
|
|
18170
|
+
if (this._activeStreamEl && this._activeStreamEl.parentNode === termLogEl) {
|
|
18171
|
+
this._activeStreamEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
|
|
18172
|
+
this._activeStreamEl.innerHTML = html;
|
|
18173
|
+
} else {
|
|
18174
|
+
const newEl = document.createElement('div');
|
|
18175
|
+
newEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
|
|
18176
|
+
newEl.innerHTML = html;
|
|
18177
|
+
termLogEl.appendChild(newEl);
|
|
18178
|
+
this._activeStreamEl = newEl;
|
|
18179
|
+
}
|
|
18180
|
+
};
|
|
18181
|
+
|
|
18182
|
+
// A newline completes the current line: commit it to the log + DOM, then begin a fresh line.
|
|
18183
|
+
const commitActiveLine = () => {
|
|
18184
|
+
this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
|
|
18185
|
+
patchLineInDom(this._activeStreamLine);
|
|
18186
|
+
this._activeStreamLine = '';
|
|
18187
|
+
this._activeStreamEl = null;
|
|
18188
|
+
};
|
|
18189
|
+
|
|
18111
18190
|
let i = 0;
|
|
18112
18191
|
while (i < rawText.length) {
|
|
18113
18192
|
if (rawText.startsWith('\x1b[2K', i)) {
|
|
@@ -18142,20 +18221,22 @@ declare module 'bun:sqlite' {
|
|
|
18142
18221
|
const ch = rawText[i];
|
|
18143
18222
|
if (ch === '\r') {
|
|
18144
18223
|
if (i + 1 < rawText.length && rawText[i + 1] === '\n') {
|
|
18145
|
-
|
|
18146
|
-
this._activeStreamLine = '';
|
|
18147
|
-
this._activeStreamEl = null;
|
|
18224
|
+
commitActiveLine();
|
|
18148
18225
|
i += 2;
|
|
18149
18226
|
continue;
|
|
18150
18227
|
} else {
|
|
18228
|
+
// Bare carriage return: flush the current text into the active line, then
|
|
18229
|
+
// keep overwriting that same DOM node (no extra line is appended).
|
|
18230
|
+
const rendered = this._activeStreamLine;
|
|
18231
|
+
if (rendered || this._activeStreamEl) {
|
|
18232
|
+
patchLineInDom(rendered);
|
|
18233
|
+
}
|
|
18151
18234
|
this._activeStreamLine = '';
|
|
18152
18235
|
i++;
|
|
18153
18236
|
continue;
|
|
18154
18237
|
}
|
|
18155
18238
|
} else if (ch === '\n') {
|
|
18156
|
-
|
|
18157
|
-
this._activeStreamLine = '';
|
|
18158
|
-
this._activeStreamEl = null;
|
|
18239
|
+
commitActiveLine();
|
|
18159
18240
|
i++;
|
|
18160
18241
|
continue;
|
|
18161
18242
|
} else {
|
|
@@ -18164,20 +18245,9 @@ declare module 'bun:sqlite' {
|
|
|
18164
18245
|
}
|
|
18165
18246
|
}
|
|
18166
18247
|
|
|
18167
|
-
|
|
18168
|
-
|
|
18169
|
-
|
|
18170
|
-
if (this._activeStreamEl && this._activeStreamEl.parentNode === termLogEl) {
|
|
18171
|
-
this._activeStreamEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
|
|
18172
|
-
this._activeStreamEl.innerHTML = formattedHtml;
|
|
18173
|
-
} else {
|
|
18174
|
-
const newEl = document.createElement('div');
|
|
18175
|
-
newEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
|
|
18176
|
-
newEl.innerHTML = formattedHtml;
|
|
18177
|
-
termLogEl.appendChild(newEl);
|
|
18178
|
-
this._activeStreamEl = newEl;
|
|
18179
|
-
}
|
|
18180
|
-
}
|
|
18248
|
+
// Render the still-open partial line so incremental progress stays visible.
|
|
18249
|
+
if (this._activeStreamLine) {
|
|
18250
|
+
patchLineInDom(this._activeStreamLine);
|
|
18181
18251
|
}
|
|
18182
18252
|
|
|
18183
18253
|
if (termSurface) {
|
|
@@ -19702,41 +19772,18 @@ declare module 'bun:sqlite' {
|
|
|
19702
19772
|
|
|
19703
19773
|
_renderEmptyEditorContent(emptyEl) {
|
|
19704
19774
|
if (!emptyEl) return;
|
|
19705
|
-
const fileBtns = this._orderedFileNames().map(f => {
|
|
19706
|
-
const ext = f.endsWith('.ts') ? 'ts' : f.endsWith('.js') ? 'js' : f.endsWith('.json') ? 'json' : f.endsWith('.md') ? 'md' : 'txt';
|
|
19707
|
-
return `
|
|
19708
|
-
<button type="button" class="codelab-empty-file-btn" data-cl-file="${escapeHtml(f)}" title="Open ${escapeHtml(f)}">
|
|
19709
|
-
<span class="codelab-tab__ext codelab-tab__ext--${ext}">${ext.toUpperCase()}</span>
|
|
19710
|
-
<span>${escapeHtml(f)}</span>
|
|
19711
|
-
</button>
|
|
19712
|
-
`;
|
|
19713
|
-
}).join('');
|
|
19714
|
-
|
|
19715
19775
|
emptyEl.innerHTML = `
|
|
19716
19776
|
<div class="codelab-empty-editor__inner">
|
|
19717
|
-
<div class="codelab-empty-
|
|
19718
|
-
|
|
19719
|
-
|
|
19720
|
-
<
|
|
19721
|
-
</svg>
|
|
19722
|
-
</div>
|
|
19723
|
-
<h2 class="codelab-empty-editor__title">No Open Editors</h2>
|
|
19724
|
-
<p class="codelab-empty-editor__subtitle">Select a file from the explorer on the left or click a workspace file below to open.</p>
|
|
19725
|
-
<div class="codelab-empty-editor__files" role="group" aria-label="Workspace Files">
|
|
19726
|
-
${fileBtns}
|
|
19727
|
-
</div>
|
|
19728
|
-
<div class="codelab-empty-editor__actions">
|
|
19729
|
-
<button type="button" class="codelab-btn codelab-btn--run" data-cl-action="run-demo" title="Run demo.js (⇧⌘↵)">
|
|
19730
|
-
${CL_ICONS.play}
|
|
19731
|
-
<span>Run Demo</span>
|
|
19732
|
-
<span class="codelab-btn__kbd">⇧⌘↵</span>
|
|
19777
|
+
<div class="codelab-empty-editor__watermark" aria-hidden="true">code-lab</div>
|
|
19778
|
+
<div class="codelab-empty-editor__shortcuts" role="group" aria-label="Quick actions">
|
|
19779
|
+
<button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette-files">
|
|
19780
|
+
<span>Go to File</span><kbd>⌘P</kbd>
|
|
19733
19781
|
</button>
|
|
19734
|
-
<button type="button" class="codelab-
|
|
19735
|
-
|
|
19736
|
-
<span>Run Tests</span>
|
|
19737
|
-
<span class="codelab-btn__kbd">⌘↵</span>
|
|
19782
|
+
<button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette">
|
|
19783
|
+
<span>Show All Commands</span><kbd>⌘⇧P</kbd>
|
|
19738
19784
|
</button>
|
|
19739
19785
|
</div>
|
|
19786
|
+
<p class="codelab-empty-editor__subtitle">No editors open. Select a file from the Explorer to start editing.</p>
|
|
19740
19787
|
</div>
|
|
19741
19788
|
`;
|
|
19742
19789
|
}
|
|
@@ -19806,7 +19853,7 @@ declare module 'bun:sqlite' {
|
|
|
19806
19853
|
this.openCommandPalette('files');
|
|
19807
19854
|
return;
|
|
19808
19855
|
}
|
|
19809
|
-
if (
|
|
19856
|
+
if (e.ctrlKey && !e.metaKey && keyLower === 'c') {
|
|
19810
19857
|
const hasSelection = typeof window !== 'undefined' && window.getSelection && window.getSelection().toString().length > 0;
|
|
19811
19858
|
if (!hasSelection && (this.isRunning || this._activeCommandAbortController)) {
|
|
19812
19859
|
e.preventDefault();
|
|
@@ -20108,6 +20155,7 @@ declare module 'bun:sqlite' {
|
|
|
20108
20155
|
if (action === 'run-demo') this.runDemo();
|
|
20109
20156
|
else if (action === 'run-tests') this.runTests();
|
|
20110
20157
|
else if (action === 'stop-run') this.stopExecution();
|
|
20158
|
+
else if (action === 'interrupt') this._handleInterrupt();
|
|
20111
20159
|
else if (action === 'verify-step') this.verifyCurrentStep();
|
|
20112
20160
|
else if (action === 'show-diff') this.showSolutionModal();
|
|
20113
20161
|
else if (action === 'compare-diff') {
|
|
@@ -20701,6 +20749,48 @@ declare module 'bun:sqlite' {
|
|
|
20701
20749
|
hSplitter.addEventListener('pointerup', onUp);
|
|
20702
20750
|
});
|
|
20703
20751
|
}
|
|
20752
|
+
|
|
20753
|
+
const fSplitter = this.container.querySelector('#cl-splitter-files');
|
|
20754
|
+
if (fSplitter) {
|
|
20755
|
+
const applyWidth = (w) => {
|
|
20756
|
+
this.explorerWidth = Math.round(w);
|
|
20757
|
+
shell.style.setProperty('--cl-explorer-width', `${this.explorerWidth}px`);
|
|
20758
|
+
if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
|
|
20759
|
+
};
|
|
20760
|
+
|
|
20761
|
+
fSplitter.addEventListener('dblclick', () => {
|
|
20762
|
+
applyWidth(196);
|
|
20763
|
+
this._saveState();
|
|
20764
|
+
});
|
|
20765
|
+
|
|
20766
|
+
fSplitter.addEventListener('pointerdown', e => {
|
|
20767
|
+
e.preventDefault();
|
|
20768
|
+
fSplitter.classList.add('is-dragging');
|
|
20769
|
+
shell.classList.add('is-resizing');
|
|
20770
|
+
try { fSplitter.setPointerCapture(e.pointerId); } catch (_) {}
|
|
20771
|
+
|
|
20772
|
+
const onMove = ev => {
|
|
20773
|
+
const ws = this.container.querySelector('.codelab-workspace');
|
|
20774
|
+
const rect = (ws || shell).getBoundingClientRect();
|
|
20775
|
+
const minW = 140;
|
|
20776
|
+
const maxW = Math.max(minW, Math.floor(rect.width * 0.5));
|
|
20777
|
+
const nextW = Math.min(maxW, Math.max(minW, Math.round(ev.clientX - rect.left)));
|
|
20778
|
+
applyWidth(nextW);
|
|
20779
|
+
};
|
|
20780
|
+
|
|
20781
|
+
const onUp = ev => {
|
|
20782
|
+
fSplitter.classList.remove('is-dragging');
|
|
20783
|
+
shell.classList.remove('is-resizing');
|
|
20784
|
+
try { fSplitter.releasePointerCapture(ev.pointerId); } catch (_) {}
|
|
20785
|
+
fSplitter.removeEventListener('pointermove', onMove);
|
|
20786
|
+
fSplitter.removeEventListener('pointerup', onUp);
|
|
20787
|
+
this._saveState();
|
|
20788
|
+
};
|
|
20789
|
+
|
|
20790
|
+
fSplitter.addEventListener('pointermove', onMove);
|
|
20791
|
+
fSplitter.addEventListener('pointerup', onUp);
|
|
20792
|
+
});
|
|
20793
|
+
}
|
|
20704
20794
|
}
|
|
20705
20795
|
|
|
20706
20796
|
selectStep(idx, shouldJump = true) {
|
|
@@ -21097,6 +21187,12 @@ declare module 'bun:sqlite' {
|
|
|
21097
21187
|
}
|
|
21098
21188
|
|
|
21099
21189
|
// ── Execution Engine (Web Worker + Virtual Node Runtime) ───────────────
|
|
21190
|
+
_isAbortResult(res, signal) {
|
|
21191
|
+
if (signal && signal.aborted) return true;
|
|
21192
|
+
if (!res || typeof res !== 'object') return false;
|
|
21193
|
+
return Boolean(res.cancelled || res.aborted || res.exitCode === 130);
|
|
21194
|
+
}
|
|
21195
|
+
|
|
21100
21196
|
async _executeRuntime(execOptions) {
|
|
21101
21197
|
const t0 = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
|
21102
21198
|
const payload = {
|
|
@@ -21133,7 +21229,11 @@ declare module 'bun:sqlite' {
|
|
|
21133
21229
|
this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
|
|
21134
21230
|
return res;
|
|
21135
21231
|
} catch (err) {
|
|
21136
|
-
|
|
21232
|
+
if (payload.signal && payload.signal.aborted) {
|
|
21233
|
+
this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
|
|
21234
|
+
} else {
|
|
21235
|
+
this._setRuntimeStatus('error', 'Execution error');
|
|
21236
|
+
}
|
|
21137
21237
|
throw err;
|
|
21138
21238
|
}
|
|
21139
21239
|
}
|
|
@@ -21175,18 +21275,21 @@ declare module 'bun:sqlite' {
|
|
|
21175
21275
|
}
|
|
21176
21276
|
});
|
|
21177
21277
|
this._flushTerminalStream();
|
|
21278
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
21178
21279
|
|
|
21179
|
-
if (!streamedStdout && res.stdout) {
|
|
21280
|
+
if (!aborted && !streamedStdout && res.stdout) {
|
|
21180
21281
|
this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
21181
21282
|
}
|
|
21182
|
-
if (!streamedStderr && res.stderr) {
|
|
21283
|
+
if (!aborted && !streamedStderr && res.stderr) {
|
|
21183
21284
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21184
21285
|
}
|
|
21185
|
-
if (res.error) {
|
|
21286
|
+
if (!aborted && res.error) {
|
|
21186
21287
|
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
21187
21288
|
}
|
|
21188
|
-
|
|
21189
|
-
|
|
21289
|
+
if (!aborted) {
|
|
21290
|
+
this.lastFsSnapshot = res.fsSnapshot || [];
|
|
21291
|
+
this.lastHttpTrace = res.httpTrace || [];
|
|
21292
|
+
}
|
|
21190
21293
|
|
|
21191
21294
|
if (this.onRun) {
|
|
21192
21295
|
try { this.onRun(res); } catch (_) {}
|
|
@@ -21194,7 +21297,9 @@ declare module 'bun:sqlite' {
|
|
|
21194
21297
|
this._emitEvent('codelab:run', { labId: this.labId, mode: 'run', entry, result: res });
|
|
21195
21298
|
} catch (err) {
|
|
21196
21299
|
this._flushTerminalStream();
|
|
21197
|
-
|
|
21300
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21301
|
+
this.terminalLogs.push({ type: 'stderr', text: `Execution error: ${formatErrorText(err)}` });
|
|
21302
|
+
}
|
|
21198
21303
|
} finally {
|
|
21199
21304
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
21200
21305
|
this._activeCommandAbortController = null;
|
|
@@ -21243,18 +21348,21 @@ declare module 'bun:sqlite' {
|
|
|
21243
21348
|
}
|
|
21244
21349
|
});
|
|
21245
21350
|
this._flushTerminalStream();
|
|
21351
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
21246
21352
|
|
|
21247
|
-
|
|
21248
|
-
|
|
21249
|
-
|
|
21353
|
+
if (!aborted) {
|
|
21354
|
+
this.lastTestResults = res.testResults || [];
|
|
21355
|
+
this.lastFsSnapshot = res.fsSnapshot || [];
|
|
21356
|
+
this.lastHttpTrace = res.httpTrace || [];
|
|
21357
|
+
}
|
|
21250
21358
|
|
|
21251
|
-
if (!streamedStdout && res.stdout) {
|
|
21359
|
+
if (!aborted && !streamedStdout && res.stdout) {
|
|
21252
21360
|
this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
21253
21361
|
}
|
|
21254
|
-
if (!streamedStderr && res.stderr) {
|
|
21362
|
+
if (!aborted && !streamedStderr && res.stderr) {
|
|
21255
21363
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21256
21364
|
}
|
|
21257
|
-
if (res.error) {
|
|
21365
|
+
if (!aborted && res.error) {
|
|
21258
21366
|
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
21259
21367
|
}
|
|
21260
21368
|
|
|
@@ -21305,7 +21413,9 @@ declare module 'bun:sqlite' {
|
|
|
21305
21413
|
}
|
|
21306
21414
|
} catch (err) {
|
|
21307
21415
|
this._flushTerminalStream();
|
|
21308
|
-
|
|
21416
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21417
|
+
this.terminalLogs.push({ type: 'stderr', text: `Test runner error: ${formatErrorText(err)}` });
|
|
21418
|
+
}
|
|
21309
21419
|
} finally {
|
|
21310
21420
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
21311
21421
|
this._activeCommandAbortController = null;
|
|
@@ -21396,16 +21506,19 @@ declare module 'bun:sqlite' {
|
|
|
21396
21506
|
onStderr: (c) => { streamedStderr = true; this._appendTerminalStream('stderr', c); }
|
|
21397
21507
|
});
|
|
21398
21508
|
this._flushTerminalStream();
|
|
21509
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
21399
21510
|
const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
|
|
21400
|
-
if (!streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
21401
|
-
if (!streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21402
|
-
if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
21511
|
+
if (!aborted && !streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
21512
|
+
if (!aborted && !streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21513
|
+
if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
21403
21514
|
this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
|
|
21404
21515
|
}
|
|
21405
|
-
if (res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
21516
|
+
if (!aborted && res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
21406
21517
|
} catch (err) {
|
|
21407
21518
|
this._flushTerminalStream();
|
|
21408
|
-
|
|
21519
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21520
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
21521
|
+
}
|
|
21409
21522
|
} finally {
|
|
21410
21523
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
21411
21524
|
this._activeCommandAbortController = null;
|
|
@@ -21464,6 +21577,7 @@ declare module 'bun:sqlite' {
|
|
|
21464
21577
|
signal: abortCtrl.signal
|
|
21465
21578
|
});
|
|
21466
21579
|
this._flushTerminalStream();
|
|
21580
|
+
const aborted = this._isAbortResult(shellRes, abortCtrl.signal);
|
|
21467
21581
|
this.cwd = this.shell.cwd || this.cwd;
|
|
21468
21582
|
this._syncVfsSnapshot(null, true);
|
|
21469
21583
|
|
|
@@ -21483,10 +21597,10 @@ declare module 'bun:sqlite' {
|
|
|
21483
21597
|
|
|
21484
21598
|
const isCmdNotFound = shellRes && shellRes.exitCode === 127 && typeof shellRes.stderr === 'string' && shellRes.stderr.includes('command not found');
|
|
21485
21599
|
if (!isCmdNotFound) {
|
|
21486
|
-
if (shellRes && shellRes.stdout && !streamedStdout) {
|
|
21600
|
+
if (!aborted && shellRes && shellRes.stdout && !streamedStdout) {
|
|
21487
21601
|
this.terminalLogs.push({ type: 'stdout', text: shellRes.stdout.replace(/\n$/, '') });
|
|
21488
21602
|
}
|
|
21489
|
-
if (shellRes && shellRes.stderr && !streamedStderr) {
|
|
21603
|
+
if (!aborted && shellRes && shellRes.stderr && !streamedStderr) {
|
|
21490
21604
|
this.terminalLogs.push({ type: 'stderr', text: shellRes.stderr.replace(/\n$/, '') });
|
|
21491
21605
|
}
|
|
21492
21606
|
this._renderDrawerBody();
|
|
@@ -21499,7 +21613,9 @@ declare module 'bun:sqlite' {
|
|
|
21499
21613
|
}
|
|
21500
21614
|
} catch (err) {
|
|
21501
21615
|
this._flushTerminalStream();
|
|
21502
|
-
|
|
21616
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21617
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
21618
|
+
}
|
|
21503
21619
|
this._renderDrawerBody();
|
|
21504
21620
|
return;
|
|
21505
21621
|
} finally {
|
|
@@ -21535,17 +21651,18 @@ declare module 'bun:sqlite' {
|
|
|
21535
21651
|
}
|
|
21536
21652
|
});
|
|
21537
21653
|
this._flushTerminalStream();
|
|
21654
|
+
const aborted = this._isAbortResult(res, fallbackAbortCtrl.signal);
|
|
21538
21655
|
const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
|
|
21539
|
-
if (!streamedFallbackStdout && cleanStdout) {
|
|
21656
|
+
if (!aborted && !streamedFallbackStdout && cleanStdout) {
|
|
21540
21657
|
this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
21541
21658
|
}
|
|
21542
|
-
if (!streamedFallbackStderr && res.stderr) {
|
|
21659
|
+
if (!aborted && !streamedFallbackStderr && res.stderr) {
|
|
21543
21660
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21544
21661
|
}
|
|
21545
|
-
if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
21662
|
+
if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
21546
21663
|
this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
|
|
21547
21664
|
}
|
|
21548
|
-
if (res.error) {
|
|
21665
|
+
if (!aborted && res.error) {
|
|
21549
21666
|
const errStr = formatErrorText(res.error);
|
|
21550
21667
|
if (/^[a-zA-Z0-9_-]+$/.test(trimmed) && errStr.includes(`ReferenceError: ${trimmed} is not defined`)) {
|
|
21551
21668
|
this.terminalLogs.push({ type: 'stderr', text: `codelab: ${trimmed}: command not found (type "help" for commands or enter a JS/TS expression)` });
|
|
@@ -21555,7 +21672,9 @@ declare module 'bun:sqlite' {
|
|
|
21555
21672
|
}
|
|
21556
21673
|
} catch (err) {
|
|
21557
21674
|
this._flushTerminalStream();
|
|
21558
|
-
|
|
21675
|
+
if (!(fallbackAbortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21676
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
21677
|
+
}
|
|
21559
21678
|
} finally {
|
|
21560
21679
|
if (this._activeCommandAbortController === fallbackAbortCtrl) {
|
|
21561
21680
|
this._activeCommandAbortController = null;
|
|
@@ -21807,8 +21926,13 @@ declare module 'bun:sqlite' {
|
|
|
21807
21926
|
const intoRoot = options.intoRoot !== false;
|
|
21808
21927
|
const targetDir = intoRoot ? '/workspace' : `/workspace/${parsed.repo}`;
|
|
21809
21928
|
const cmdDisplay = `git clone ${repoInput}${intoRoot ? ' .' : ''}`;
|
|
21929
|
+
this.drawerTab = 'terminal';
|
|
21810
21930
|
this.terminalLogs.push({ type: 'cmd', text: cmdDisplay });
|
|
21931
|
+
this.isRunning = true;
|
|
21932
|
+
const abortCtrl = new AbortController();
|
|
21933
|
+
this._activeCommandAbortController = abortCtrl;
|
|
21811
21934
|
this._renderDrawerBody();
|
|
21935
|
+
this._updateRunStateUI();
|
|
21812
21936
|
|
|
21813
21937
|
try {
|
|
21814
21938
|
if (intoRoot && this.shell && this.shell.vfs) {
|
|
@@ -21831,6 +21955,7 @@ declare module 'bun:sqlite' {
|
|
|
21831
21955
|
maxFiles: options.maxFiles || 250,
|
|
21832
21956
|
maxFileSize: options.maxFileSize || 512 * 1024,
|
|
21833
21957
|
fetchImpl: options.fetchImpl || (this.shell && this.shell.options ? this.shell.options.fetchImpl : undefined),
|
|
21958
|
+
signal: abortCtrl.signal,
|
|
21834
21959
|
onProgress: options.onProgress
|
|
21835
21960
|
});
|
|
21836
21961
|
|
|
@@ -21902,10 +22027,18 @@ declare module 'bun:sqlite' {
|
|
|
21902
22027
|
this._emitEvent('repo:cloned', eventDetail);
|
|
21903
22028
|
return result;
|
|
21904
22029
|
} catch (err) {
|
|
21905
|
-
|
|
21906
|
-
|
|
22030
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
22031
|
+
const msg = err && err.message ? err.message : String(err);
|
|
22032
|
+
this.terminalLogs.push({ type: 'stderr', text: msg });
|
|
22033
|
+
}
|
|
21907
22034
|
this._renderDrawerBody();
|
|
21908
22035
|
throw err;
|
|
22036
|
+
} finally {
|
|
22037
|
+
if (this._activeCommandAbortController === abortCtrl) {
|
|
22038
|
+
this._activeCommandAbortController = null;
|
|
22039
|
+
}
|
|
22040
|
+
this.isRunning = false;
|
|
22041
|
+
this._updateRunStateUI();
|
|
21909
22042
|
}
|
|
21910
22043
|
}
|
|
21911
22044
|
|