@innovatorved/code-lab 0.1.2 → 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 +182 -73
- package/dist/code-lab.js +182 -73
- 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 +144 -65
- package/src/workbench.ts +144 -65
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();
|
|
@@ -19726,41 +19772,18 @@ declare module 'bun:sqlite' {
|
|
|
19726
19772
|
|
|
19727
19773
|
_renderEmptyEditorContent(emptyEl) {
|
|
19728
19774
|
if (!emptyEl) return;
|
|
19729
|
-
const fileBtns = this._orderedFileNames().map(f => {
|
|
19730
|
-
const ext = f.endsWith('.ts') ? 'ts' : f.endsWith('.js') ? 'js' : f.endsWith('.json') ? 'json' : f.endsWith('.md') ? 'md' : 'txt';
|
|
19731
|
-
return `
|
|
19732
|
-
<button type="button" class="codelab-empty-file-btn" data-cl-file="${escapeHtml(f)}" title="Open ${escapeHtml(f)}">
|
|
19733
|
-
<span class="codelab-tab__ext codelab-tab__ext--${ext}">${ext.toUpperCase()}</span>
|
|
19734
|
-
<span>${escapeHtml(f)}</span>
|
|
19735
|
-
</button>
|
|
19736
|
-
`;
|
|
19737
|
-
}).join('');
|
|
19738
|
-
|
|
19739
19775
|
emptyEl.innerHTML = `
|
|
19740
19776
|
<div class="codelab-empty-editor__inner">
|
|
19741
|
-
<div class="codelab-empty-
|
|
19742
|
-
|
|
19743
|
-
|
|
19744
|
-
<
|
|
19745
|
-
</svg>
|
|
19746
|
-
</div>
|
|
19747
|
-
<h2 class="codelab-empty-editor__title">No Open Editors</h2>
|
|
19748
|
-
<p class="codelab-empty-editor__subtitle">Select a file from the explorer on the left or click a workspace file below to open.</p>
|
|
19749
|
-
<div class="codelab-empty-editor__files" role="group" aria-label="Workspace Files">
|
|
19750
|
-
${fileBtns}
|
|
19751
|
-
</div>
|
|
19752
|
-
<div class="codelab-empty-editor__actions">
|
|
19753
|
-
<button type="button" class="codelab-btn codelab-btn--run" data-cl-action="run-demo" title="Run demo.js (⇧⌘↵)">
|
|
19754
|
-
${CL_ICONS.play}
|
|
19755
|
-
<span>Run Demo</span>
|
|
19756
|
-
<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>
|
|
19757
19781
|
</button>
|
|
19758
|
-
<button type="button" class="codelab-
|
|
19759
|
-
|
|
19760
|
-
<span>Run Tests</span>
|
|
19761
|
-
<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>
|
|
19762
19784
|
</button>
|
|
19763
19785
|
</div>
|
|
19786
|
+
<p class="codelab-empty-editor__subtitle">No editors open. Select a file from the Explorer to start editing.</p>
|
|
19764
19787
|
</div>
|
|
19765
19788
|
`;
|
|
19766
19789
|
}
|
|
@@ -19830,7 +19853,7 @@ declare module 'bun:sqlite' {
|
|
|
19830
19853
|
this.openCommandPalette('files');
|
|
19831
19854
|
return;
|
|
19832
19855
|
}
|
|
19833
|
-
if (
|
|
19856
|
+
if (e.ctrlKey && !e.metaKey && keyLower === 'c') {
|
|
19834
19857
|
const hasSelection = typeof window !== 'undefined' && window.getSelection && window.getSelection().toString().length > 0;
|
|
19835
19858
|
if (!hasSelection && (this.isRunning || this._activeCommandAbortController)) {
|
|
19836
19859
|
e.preventDefault();
|
|
@@ -20132,6 +20155,7 @@ declare module 'bun:sqlite' {
|
|
|
20132
20155
|
if (action === 'run-demo') this.runDemo();
|
|
20133
20156
|
else if (action === 'run-tests') this.runTests();
|
|
20134
20157
|
else if (action === 'stop-run') this.stopExecution();
|
|
20158
|
+
else if (action === 'interrupt') this._handleInterrupt();
|
|
20135
20159
|
else if (action === 'verify-step') this.verifyCurrentStep();
|
|
20136
20160
|
else if (action === 'show-diff') this.showSolutionModal();
|
|
20137
20161
|
else if (action === 'compare-diff') {
|
|
@@ -20725,6 +20749,48 @@ declare module 'bun:sqlite' {
|
|
|
20725
20749
|
hSplitter.addEventListener('pointerup', onUp);
|
|
20726
20750
|
});
|
|
20727
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
|
+
}
|
|
20728
20794
|
}
|
|
20729
20795
|
|
|
20730
20796
|
selectStep(idx, shouldJump = true) {
|
|
@@ -21121,6 +21187,12 @@ declare module 'bun:sqlite' {
|
|
|
21121
21187
|
}
|
|
21122
21188
|
|
|
21123
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
|
+
|
|
21124
21196
|
async _executeRuntime(execOptions) {
|
|
21125
21197
|
const t0 = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
|
21126
21198
|
const payload = {
|
|
@@ -21157,7 +21229,11 @@ declare module 'bun:sqlite' {
|
|
|
21157
21229
|
this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
|
|
21158
21230
|
return res;
|
|
21159
21231
|
} catch (err) {
|
|
21160
|
-
|
|
21232
|
+
if (payload.signal && payload.signal.aborted) {
|
|
21233
|
+
this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
|
|
21234
|
+
} else {
|
|
21235
|
+
this._setRuntimeStatus('error', 'Execution error');
|
|
21236
|
+
}
|
|
21161
21237
|
throw err;
|
|
21162
21238
|
}
|
|
21163
21239
|
}
|
|
@@ -21199,18 +21275,21 @@ declare module 'bun:sqlite' {
|
|
|
21199
21275
|
}
|
|
21200
21276
|
});
|
|
21201
21277
|
this._flushTerminalStream();
|
|
21278
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
21202
21279
|
|
|
21203
|
-
if (!streamedStdout && res.stdout) {
|
|
21280
|
+
if (!aborted && !streamedStdout && res.stdout) {
|
|
21204
21281
|
this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
21205
21282
|
}
|
|
21206
|
-
if (!streamedStderr && res.stderr) {
|
|
21283
|
+
if (!aborted && !streamedStderr && res.stderr) {
|
|
21207
21284
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21208
21285
|
}
|
|
21209
|
-
if (res.error) {
|
|
21286
|
+
if (!aborted && res.error) {
|
|
21210
21287
|
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
21211
21288
|
}
|
|
21212
|
-
|
|
21213
|
-
|
|
21289
|
+
if (!aborted) {
|
|
21290
|
+
this.lastFsSnapshot = res.fsSnapshot || [];
|
|
21291
|
+
this.lastHttpTrace = res.httpTrace || [];
|
|
21292
|
+
}
|
|
21214
21293
|
|
|
21215
21294
|
if (this.onRun) {
|
|
21216
21295
|
try { this.onRun(res); } catch (_) {}
|
|
@@ -21218,7 +21297,9 @@ declare module 'bun:sqlite' {
|
|
|
21218
21297
|
this._emitEvent('codelab:run', { labId: this.labId, mode: 'run', entry, result: res });
|
|
21219
21298
|
} catch (err) {
|
|
21220
21299
|
this._flushTerminalStream();
|
|
21221
|
-
|
|
21300
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21301
|
+
this.terminalLogs.push({ type: 'stderr', text: `Execution error: ${formatErrorText(err)}` });
|
|
21302
|
+
}
|
|
21222
21303
|
} finally {
|
|
21223
21304
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
21224
21305
|
this._activeCommandAbortController = null;
|
|
@@ -21267,18 +21348,21 @@ declare module 'bun:sqlite' {
|
|
|
21267
21348
|
}
|
|
21268
21349
|
});
|
|
21269
21350
|
this._flushTerminalStream();
|
|
21351
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
21270
21352
|
|
|
21271
|
-
|
|
21272
|
-
|
|
21273
|
-
|
|
21353
|
+
if (!aborted) {
|
|
21354
|
+
this.lastTestResults = res.testResults || [];
|
|
21355
|
+
this.lastFsSnapshot = res.fsSnapshot || [];
|
|
21356
|
+
this.lastHttpTrace = res.httpTrace || [];
|
|
21357
|
+
}
|
|
21274
21358
|
|
|
21275
|
-
if (!streamedStdout && res.stdout) {
|
|
21359
|
+
if (!aborted && !streamedStdout && res.stdout) {
|
|
21276
21360
|
this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
21277
21361
|
}
|
|
21278
|
-
if (!streamedStderr && res.stderr) {
|
|
21362
|
+
if (!aborted && !streamedStderr && res.stderr) {
|
|
21279
21363
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21280
21364
|
}
|
|
21281
|
-
if (res.error) {
|
|
21365
|
+
if (!aborted && res.error) {
|
|
21282
21366
|
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
21283
21367
|
}
|
|
21284
21368
|
|
|
@@ -21329,7 +21413,9 @@ declare module 'bun:sqlite' {
|
|
|
21329
21413
|
}
|
|
21330
21414
|
} catch (err) {
|
|
21331
21415
|
this._flushTerminalStream();
|
|
21332
|
-
|
|
21416
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21417
|
+
this.terminalLogs.push({ type: 'stderr', text: `Test runner error: ${formatErrorText(err)}` });
|
|
21418
|
+
}
|
|
21333
21419
|
} finally {
|
|
21334
21420
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
21335
21421
|
this._activeCommandAbortController = null;
|
|
@@ -21420,16 +21506,19 @@ declare module 'bun:sqlite' {
|
|
|
21420
21506
|
onStderr: (c) => { streamedStderr = true; this._appendTerminalStream('stderr', c); }
|
|
21421
21507
|
});
|
|
21422
21508
|
this._flushTerminalStream();
|
|
21509
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
21423
21510
|
const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
|
|
21424
|
-
if (!streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
21425
|
-
if (!streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21426
|
-
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)) {
|
|
21427
21514
|
this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
|
|
21428
21515
|
}
|
|
21429
|
-
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) });
|
|
21430
21517
|
} catch (err) {
|
|
21431
21518
|
this._flushTerminalStream();
|
|
21432
|
-
|
|
21519
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21520
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
21521
|
+
}
|
|
21433
21522
|
} finally {
|
|
21434
21523
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
21435
21524
|
this._activeCommandAbortController = null;
|
|
@@ -21488,6 +21577,7 @@ declare module 'bun:sqlite' {
|
|
|
21488
21577
|
signal: abortCtrl.signal
|
|
21489
21578
|
});
|
|
21490
21579
|
this._flushTerminalStream();
|
|
21580
|
+
const aborted = this._isAbortResult(shellRes, abortCtrl.signal);
|
|
21491
21581
|
this.cwd = this.shell.cwd || this.cwd;
|
|
21492
21582
|
this._syncVfsSnapshot(null, true);
|
|
21493
21583
|
|
|
@@ -21507,10 +21597,10 @@ declare module 'bun:sqlite' {
|
|
|
21507
21597
|
|
|
21508
21598
|
const isCmdNotFound = shellRes && shellRes.exitCode === 127 && typeof shellRes.stderr === 'string' && shellRes.stderr.includes('command not found');
|
|
21509
21599
|
if (!isCmdNotFound) {
|
|
21510
|
-
if (shellRes && shellRes.stdout && !streamedStdout) {
|
|
21600
|
+
if (!aborted && shellRes && shellRes.stdout && !streamedStdout) {
|
|
21511
21601
|
this.terminalLogs.push({ type: 'stdout', text: shellRes.stdout.replace(/\n$/, '') });
|
|
21512
21602
|
}
|
|
21513
|
-
if (shellRes && shellRes.stderr && !streamedStderr) {
|
|
21603
|
+
if (!aborted && shellRes && shellRes.stderr && !streamedStderr) {
|
|
21514
21604
|
this.terminalLogs.push({ type: 'stderr', text: shellRes.stderr.replace(/\n$/, '') });
|
|
21515
21605
|
}
|
|
21516
21606
|
this._renderDrawerBody();
|
|
@@ -21523,7 +21613,9 @@ declare module 'bun:sqlite' {
|
|
|
21523
21613
|
}
|
|
21524
21614
|
} catch (err) {
|
|
21525
21615
|
this._flushTerminalStream();
|
|
21526
|
-
|
|
21616
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21617
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
21618
|
+
}
|
|
21527
21619
|
this._renderDrawerBody();
|
|
21528
21620
|
return;
|
|
21529
21621
|
} finally {
|
|
@@ -21559,17 +21651,18 @@ declare module 'bun:sqlite' {
|
|
|
21559
21651
|
}
|
|
21560
21652
|
});
|
|
21561
21653
|
this._flushTerminalStream();
|
|
21654
|
+
const aborted = this._isAbortResult(res, fallbackAbortCtrl.signal);
|
|
21562
21655
|
const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
|
|
21563
|
-
if (!streamedFallbackStdout && cleanStdout) {
|
|
21656
|
+
if (!aborted && !streamedFallbackStdout && cleanStdout) {
|
|
21564
21657
|
this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
21565
21658
|
}
|
|
21566
|
-
if (!streamedFallbackStderr && res.stderr) {
|
|
21659
|
+
if (!aborted && !streamedFallbackStderr && res.stderr) {
|
|
21567
21660
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21568
21661
|
}
|
|
21569
|
-
if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
21662
|
+
if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
21570
21663
|
this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
|
|
21571
21664
|
}
|
|
21572
|
-
if (res.error) {
|
|
21665
|
+
if (!aborted && res.error) {
|
|
21573
21666
|
const errStr = formatErrorText(res.error);
|
|
21574
21667
|
if (/^[a-zA-Z0-9_-]+$/.test(trimmed) && errStr.includes(`ReferenceError: ${trimmed} is not defined`)) {
|
|
21575
21668
|
this.terminalLogs.push({ type: 'stderr', text: `codelab: ${trimmed}: command not found (type "help" for commands or enter a JS/TS expression)` });
|
|
@@ -21579,7 +21672,9 @@ declare module 'bun:sqlite' {
|
|
|
21579
21672
|
}
|
|
21580
21673
|
} catch (err) {
|
|
21581
21674
|
this._flushTerminalStream();
|
|
21582
|
-
|
|
21675
|
+
if (!(fallbackAbortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21676
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
21677
|
+
}
|
|
21583
21678
|
} finally {
|
|
21584
21679
|
if (this._activeCommandAbortController === fallbackAbortCtrl) {
|
|
21585
21680
|
this._activeCommandAbortController = null;
|
|
@@ -21831,8 +21926,13 @@ declare module 'bun:sqlite' {
|
|
|
21831
21926
|
const intoRoot = options.intoRoot !== false;
|
|
21832
21927
|
const targetDir = intoRoot ? '/workspace' : `/workspace/${parsed.repo}`;
|
|
21833
21928
|
const cmdDisplay = `git clone ${repoInput}${intoRoot ? ' .' : ''}`;
|
|
21929
|
+
this.drawerTab = 'terminal';
|
|
21834
21930
|
this.terminalLogs.push({ type: 'cmd', text: cmdDisplay });
|
|
21931
|
+
this.isRunning = true;
|
|
21932
|
+
const abortCtrl = new AbortController();
|
|
21933
|
+
this._activeCommandAbortController = abortCtrl;
|
|
21835
21934
|
this._renderDrawerBody();
|
|
21935
|
+
this._updateRunStateUI();
|
|
21836
21936
|
|
|
21837
21937
|
try {
|
|
21838
21938
|
if (intoRoot && this.shell && this.shell.vfs) {
|
|
@@ -21855,6 +21955,7 @@ declare module 'bun:sqlite' {
|
|
|
21855
21955
|
maxFiles: options.maxFiles || 250,
|
|
21856
21956
|
maxFileSize: options.maxFileSize || 512 * 1024,
|
|
21857
21957
|
fetchImpl: options.fetchImpl || (this.shell && this.shell.options ? this.shell.options.fetchImpl : undefined),
|
|
21958
|
+
signal: abortCtrl.signal,
|
|
21858
21959
|
onProgress: options.onProgress
|
|
21859
21960
|
});
|
|
21860
21961
|
|
|
@@ -21926,10 +22027,18 @@ declare module 'bun:sqlite' {
|
|
|
21926
22027
|
this._emitEvent('repo:cloned', eventDetail);
|
|
21927
22028
|
return result;
|
|
21928
22029
|
} catch (err) {
|
|
21929
|
-
|
|
21930
|
-
|
|
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
|
+
}
|
|
21931
22034
|
this._renderDrawerBody();
|
|
21932
22035
|
throw err;
|
|
22036
|
+
} finally {
|
|
22037
|
+
if (this._activeCommandAbortController === abortCtrl) {
|
|
22038
|
+
this._activeCommandAbortController = null;
|
|
22039
|
+
}
|
|
22040
|
+
this.isRunning = false;
|
|
22041
|
+
this._updateRunStateUI();
|
|
21933
22042
|
}
|
|
21934
22043
|
}
|
|
21935
22044
|
|