@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/src/shell.ts
CHANGED
|
@@ -2025,6 +2025,16 @@ function __initShellModule(root: any) {
|
|
|
2025
2025
|
const requestedBranch = options.branch || parsed.branch || null;
|
|
2026
2026
|
const { owner, repo } = parsed;
|
|
2027
2027
|
|
|
2028
|
+
const signal = options.signal || null;
|
|
2029
|
+
const throwIfAborted = () => {
|
|
2030
|
+
if (signal && signal.aborted) {
|
|
2031
|
+
const abortErr = new Error('fatal: clone cancelled (SIGINT)');
|
|
2032
|
+
abortErr.name = 'AbortError';
|
|
2033
|
+
throw abortErr;
|
|
2034
|
+
}
|
|
2035
|
+
};
|
|
2036
|
+
throwIfAborted();
|
|
2037
|
+
|
|
2028
2038
|
if (onProgress) {
|
|
2029
2039
|
onProgress({
|
|
2030
2040
|
phase: 'metadata',
|
|
@@ -2040,7 +2050,8 @@ function __initShellModule(root: any) {
|
|
|
2040
2050
|
try {
|
|
2041
2051
|
if (!resolvedBranch) {
|
|
2042
2052
|
const metaRes = await fetchFn(`https://api.github.com/repos/${owner}/${repo}`, {
|
|
2043
|
-
headers: { Accept: 'application/vnd.github.v3+json' }
|
|
2053
|
+
headers: { Accept: 'application/vnd.github.v3+json' },
|
|
2054
|
+
signal
|
|
2044
2055
|
});
|
|
2045
2056
|
if (metaRes.status === 404) {
|
|
2046
2057
|
repoNotFound = true;
|
|
@@ -2058,9 +2069,10 @@ function __initShellModule(root: any) {
|
|
|
2058
2069
|
: Array.from(new Set([resolvedBranch, 'main', 'master'].filter(Boolean)));
|
|
2059
2070
|
|
|
2060
2071
|
for (const cand of branchCandidates) {
|
|
2072
|
+
throwIfAborted();
|
|
2061
2073
|
const treeRes = await fetchFn(
|
|
2062
2074
|
`https://api.github.com/repos/${owner}/${repo}/git/trees/${encodeURIComponent(cand)}?recursive=1`,
|
|
2063
|
-
{ headers: { Accept: 'application/vnd.github.v3+json' } }
|
|
2075
|
+
{ headers: { Accept: 'application/vnd.github.v3+json' }, signal }
|
|
2064
2076
|
);
|
|
2065
2077
|
if (treeRes.ok) {
|
|
2066
2078
|
const treeJson = await treeRes.json();
|
|
@@ -2086,8 +2098,10 @@ function __initShellModule(root: any) {
|
|
|
2086
2098
|
: Array.from(new Set([resolvedBranch, 'main', 'master'].filter(Boolean)));
|
|
2087
2099
|
|
|
2088
2100
|
for (const cand of branchCandidates) {
|
|
2101
|
+
throwIfAborted();
|
|
2089
2102
|
const flatRes = await fetchFn(
|
|
2090
|
-
`https://data.jsdelivr.com/v1/package/gh/${owner}/${repo}@${encodeURIComponent(cand)}/flat
|
|
2103
|
+
`https://data.jsdelivr.com/v1/package/gh/${owner}/${repo}@${encodeURIComponent(cand)}/flat`,
|
|
2104
|
+
{ signal }
|
|
2091
2105
|
);
|
|
2092
2106
|
if (flatRes && flatRes.ok) {
|
|
2093
2107
|
const flatJson = await flatRes.json();
|
|
@@ -2161,28 +2175,34 @@ function __initShellModule(root: any) {
|
|
|
2161
2175
|
const BATCH_SIZE = 12;
|
|
2162
2176
|
|
|
2163
2177
|
for (let i = 0; i < selectedFiles.length; i += BATCH_SIZE) {
|
|
2178
|
+
throwIfAborted();
|
|
2164
2179
|
const batch = selectedFiles.slice(i, i + BATCH_SIZE);
|
|
2165
2180
|
await Promise.all(
|
|
2166
2181
|
batch.map(async (entry) => {
|
|
2182
|
+
throwIfAborted();
|
|
2167
2183
|
const encodedPath = entry.repoPath.split('/').map(encodeURIComponent).join('/');
|
|
2168
2184
|
const rawUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${encodeURIComponent(resolvedBranch)}/${encodedPath}`;
|
|
2169
2185
|
const cdnUrl = `https://cdn.jsdelivr.net/gh/${owner}/${repo}@${encodeURIComponent(resolvedBranch)}/${encodedPath}`;
|
|
2170
2186
|
|
|
2171
2187
|
let text = null;
|
|
2172
2188
|
try {
|
|
2173
|
-
const r1 = await fetchFn(rawUrl);
|
|
2189
|
+
const r1 = await fetchFn(rawUrl, { signal });
|
|
2174
2190
|
if (r1 && r1.ok) {
|
|
2175
2191
|
text = await r1.text();
|
|
2176
2192
|
}
|
|
2177
|
-
} catch (_) {
|
|
2193
|
+
} catch (_) {
|
|
2194
|
+
if (signal && signal.aborted) throw _;
|
|
2195
|
+
}
|
|
2178
2196
|
|
|
2179
2197
|
if (text === null) {
|
|
2180
2198
|
try {
|
|
2181
|
-
const r2 = await fetchFn(cdnUrl);
|
|
2199
|
+
const r2 = await fetchFn(cdnUrl, { signal });
|
|
2182
2200
|
if (r2 && r2.ok) {
|
|
2183
2201
|
text = await r2.text();
|
|
2184
2202
|
}
|
|
2185
|
-
} catch (_) {
|
|
2203
|
+
} catch (_) {
|
|
2204
|
+
if (signal && signal.aborted) throw _;
|
|
2205
|
+
}
|
|
2186
2206
|
}
|
|
2187
2207
|
|
|
2188
2208
|
if (text !== null && text.length <= maxFileSize) {
|
|
@@ -2213,6 +2233,8 @@ function __initShellModule(root: any) {
|
|
|
2213
2233
|
);
|
|
2214
2234
|
}
|
|
2215
2235
|
|
|
2236
|
+
throwIfAborted();
|
|
2237
|
+
|
|
2216
2238
|
if (onProgress) {
|
|
2217
2239
|
onProgress({
|
|
2218
2240
|
phase: 'mounting',
|
|
@@ -2238,7 +2260,7 @@ function __initShellModule(root: any) {
|
|
|
2238
2260
|
try {
|
|
2239
2261
|
const commitsRes = await fetchFn(
|
|
2240
2262
|
`https://api.github.com/repos/${owner}/${repo}/commits?sha=${encodeURIComponent(resolvedBranch)}&per_page=10`,
|
|
2241
|
-
{ headers: { Accept: 'application/vnd.github.v3+json' } }
|
|
2263
|
+
{ headers: { Accept: 'application/vnd.github.v3+json' }, signal }
|
|
2242
2264
|
);
|
|
2243
2265
|
if (commitsRes && commitsRes.ok) {
|
|
2244
2266
|
const commitsJson = await commitsRes.json();
|
|
@@ -4499,6 +4521,7 @@ function __initShellModule(root: any) {
|
|
|
4499
4521
|
targetDir,
|
|
4500
4522
|
branch: branchOpt,
|
|
4501
4523
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
4524
|
+
signal: ctx.signal,
|
|
4502
4525
|
onFile: (absPath) => ctx.emitMutation('create', absPath),
|
|
4503
4526
|
onProgress: (ev) => {
|
|
4504
4527
|
if (!ev) return;
|
|
@@ -4539,6 +4562,9 @@ function __initShellModule(root: any) {
|
|
|
4539
4562
|
`Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`;
|
|
4540
4563
|
return { code: 0, stdout, stderr: '' };
|
|
4541
4564
|
} catch (err) {
|
|
4565
|
+
if (ctx.signal && ctx.signal.aborted) {
|
|
4566
|
+
return { code: 130, stdout: '', stderr: '', aborted: true };
|
|
4567
|
+
}
|
|
4542
4568
|
const msg = err && err.message ? err.message : String(err);
|
|
4543
4569
|
if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
|
|
4544
4570
|
return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
@@ -4866,6 +4892,7 @@ function __initShellModule(root: any) {
|
|
|
4866
4892
|
targetDir: repoRoot,
|
|
4867
4893
|
branch: gitState.branch,
|
|
4868
4894
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
4895
|
+
signal: ctx.signal,
|
|
4869
4896
|
onFile: (absPath) => ctx.emitMutation('change', absPath)
|
|
4870
4897
|
});
|
|
4871
4898
|
gitState.headSnapshot = Object.assign({}, result.headSnapshot);
|
|
@@ -4875,6 +4902,9 @@ function __initShellModule(root: any) {
|
|
|
4875
4902
|
stderr: ''
|
|
4876
4903
|
};
|
|
4877
4904
|
} catch (err) {
|
|
4905
|
+
if (ctx.signal && ctx.signal.aborted) {
|
|
4906
|
+
return { code: 130, stdout: '', stderr: '', aborted: true };
|
|
4907
|
+
}
|
|
4878
4908
|
const msg = err && err.message ? err.message : String(err);
|
|
4879
4909
|
return { code: 1, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
4880
4910
|
}
|
package/src/workbench.js
CHANGED
|
@@ -1171,6 +1171,9 @@ declare module 'bun:sqlite' {
|
|
|
1171
1171
|
this.folders = new Set(this.savedState?.folders || []);
|
|
1172
1172
|
this.collapsedFolders = new Set(this.savedState?.collapsedFolders || []);
|
|
1173
1173
|
this.explorerFolder = this.savedState?.explorerFolder || ''; // '' = workspace root, else folder path scope
|
|
1174
|
+
this.explorerWidth = (typeof this.savedState?.explorerWidth === 'number' && this.savedState.explorerWidth >= 120)
|
|
1175
|
+
? this.savedState.explorerWidth
|
|
1176
|
+
: 196;
|
|
1174
1177
|
this.folderSwitcherOpen = false;
|
|
1175
1178
|
this.creatingItem = null; // { type: 'file' | 'folder', parentFolder: string } | null
|
|
1176
1179
|
this.renamingItem = null;
|
|
@@ -1508,7 +1511,8 @@ declare module 'bun:sqlite' {
|
|
|
1508
1511
|
activeFile: this.activeFile,
|
|
1509
1512
|
folders: Array.from(this.folders || []),
|
|
1510
1513
|
collapsedFolders: Array.from(this.collapsedFolders || []),
|
|
1511
|
-
explorerFolder: this.explorerFolder || ''
|
|
1514
|
+
explorerFolder: this.explorerFolder || '',
|
|
1515
|
+
explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined
|
|
1512
1516
|
};
|
|
1513
1517
|
this.savedState = state;
|
|
1514
1518
|
if (this.options && this.options.persistState === false) {
|
|
@@ -1689,6 +1693,13 @@ declare module 'bun:sqlite' {
|
|
|
1689
1693
|
if (stopBtn) {
|
|
1690
1694
|
stopBtn.style.display = this.isRunning ? 'inline-flex' : 'none';
|
|
1691
1695
|
}
|
|
1696
|
+
const ctrlCBtn = this.container.querySelector('#cl-ctrl-c-btn');
|
|
1697
|
+
if (ctrlCBtn) {
|
|
1698
|
+
ctrlCBtn.classList.toggle('is-running', Boolean(this.isRunning));
|
|
1699
|
+
ctrlCBtn.title = this.isRunning
|
|
1700
|
+
? 'Send Ctrl+C — interrupt the running command'
|
|
1701
|
+
: 'Send Ctrl+C (clears the current input line)';
|
|
1702
|
+
}
|
|
1692
1703
|
this.container.querySelectorAll('[data-cl-action="run-demo"], [data-cl-action="run-tests"], [data-cl-action="verify-step"]').forEach(btn => {
|
|
1693
1704
|
btn.disabled = this.isRunning;
|
|
1694
1705
|
});
|
|
@@ -1703,8 +1714,9 @@ declare module 'bun:sqlite' {
|
|
|
1703
1714
|
const themeAttr = this.themeOption !== 'auto' ? `data-theme="${escapeHtml(this.themeOption)}"` : '';
|
|
1704
1715
|
const brandLabel = (this.title && this.title !== 'custom-lab' && this.title !== this.labId) ? this.title : 'code-lab';
|
|
1705
1716
|
const isGuideCollapsed = !this.hasGuidedLab || this.mode === 'sandbox' || !this.steps.length;
|
|
1717
|
+
const explorerStyle = `style="--cl-explorer-width:${Math.round(this.explorerWidth || 196)}px"`;
|
|
1706
1718
|
this.container.innerHTML = `
|
|
1707
|
-
<div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr}>
|
|
1719
|
+
<div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr} ${explorerStyle}>
|
|
1708
1720
|
<!-- Top Bar -->
|
|
1709
1721
|
<div class="codelab-topbar codelab-toolbar">
|
|
1710
1722
|
<div class="codelab-topbar__left">
|
|
@@ -1820,6 +1832,9 @@ declare module 'bun:sqlite' {
|
|
|
1820
1832
|
<div class="codelab-explorer__list" id="cl-explorer-list"></div>
|
|
1821
1833
|
</div>
|
|
1822
1834
|
|
|
1835
|
+
<!-- Explorer Resize Splitter -->
|
|
1836
|
+
<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>
|
|
1837
|
+
|
|
1823
1838
|
<!-- Editor Column -->
|
|
1824
1839
|
<div class="codelab-editor-col">
|
|
1825
1840
|
<div class="codelab-tabs codelab-file-tabs" id="cl-file-tabs" role="tablist" aria-label="Open Files"></div>
|
|
@@ -1873,6 +1888,7 @@ declare module 'bun:sqlite' {
|
|
|
1873
1888
|
</button>
|
|
1874
1889
|
</div>
|
|
1875
1890
|
<div style="display:flex;align-items:center;gap:6px;">
|
|
1891
|
+
<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>
|
|
1876
1892
|
<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>
|
|
1877
1893
|
<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>
|
|
1878
1894
|
</div>
|
|
@@ -3014,10 +3030,10 @@ declare module 'bun:sqlite' {
|
|
|
3014
3030
|
this._ptyInputAfterCursor = '';
|
|
3015
3031
|
this._updatePtyActiveLine();
|
|
3016
3032
|
}
|
|
3017
|
-
} else if (
|
|
3033
|
+
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'c') {
|
|
3018
3034
|
e.preventDefault();
|
|
3019
3035
|
this._handleInterrupt();
|
|
3020
|
-
} else if (
|
|
3036
|
+
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'd') {
|
|
3021
3037
|
e.preventDefault();
|
|
3022
3038
|
if (this.inRepl) {
|
|
3023
3039
|
this.inRepl = false;
|
|
@@ -3026,7 +3042,7 @@ declare module 'bun:sqlite' {
|
|
|
3026
3042
|
const nextInput = this.container.querySelector('#cl-repl-input');
|
|
3027
3043
|
if (nextInput && typeof nextInput.focus === 'function') nextInput.focus();
|
|
3028
3044
|
}
|
|
3029
|
-
} else if (
|
|
3045
|
+
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'l') {
|
|
3030
3046
|
e.preventDefault();
|
|
3031
3047
|
this.terminalLogs = [];
|
|
3032
3048
|
this._renderDrawerBody();
|
|
@@ -4771,41 +4787,18 @@ declare module 'bun:sqlite' {
|
|
|
4771
4787
|
|
|
4772
4788
|
_renderEmptyEditorContent(emptyEl) {
|
|
4773
4789
|
if (!emptyEl) return;
|
|
4774
|
-
const fileBtns = this._orderedFileNames().map(f => {
|
|
4775
|
-
const ext = f.endsWith('.ts') ? 'ts' : f.endsWith('.js') ? 'js' : f.endsWith('.json') ? 'json' : f.endsWith('.md') ? 'md' : 'txt';
|
|
4776
|
-
return `
|
|
4777
|
-
<button type="button" class="codelab-empty-file-btn" data-cl-file="${escapeHtml(f)}" title="Open ${escapeHtml(f)}">
|
|
4778
|
-
<span class="codelab-tab__ext codelab-tab__ext--${ext}">${ext.toUpperCase()}</span>
|
|
4779
|
-
<span>${escapeHtml(f)}</span>
|
|
4780
|
-
</button>
|
|
4781
|
-
`;
|
|
4782
|
-
}).join('');
|
|
4783
|
-
|
|
4784
4790
|
emptyEl.innerHTML = `
|
|
4785
4791
|
<div class="codelab-empty-editor__inner">
|
|
4786
|
-
<div class="codelab-empty-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
<
|
|
4790
|
-
</svg>
|
|
4791
|
-
</div>
|
|
4792
|
-
<h2 class="codelab-empty-editor__title">No Open Editors</h2>
|
|
4793
|
-
<p class="codelab-empty-editor__subtitle">Select a file from the explorer on the left or click a workspace file below to open.</p>
|
|
4794
|
-
<div class="codelab-empty-editor__files" role="group" aria-label="Workspace Files">
|
|
4795
|
-
${fileBtns}
|
|
4796
|
-
</div>
|
|
4797
|
-
<div class="codelab-empty-editor__actions">
|
|
4798
|
-
<button type="button" class="codelab-btn codelab-btn--run" data-cl-action="run-demo" title="Run demo.js (⇧⌘↵)">
|
|
4799
|
-
${CL_ICONS.play}
|
|
4800
|
-
<span>Run Demo</span>
|
|
4801
|
-
<span class="codelab-btn__kbd">⇧⌘↵</span>
|
|
4792
|
+
<div class="codelab-empty-editor__watermark" aria-hidden="true">code-lab</div>
|
|
4793
|
+
<div class="codelab-empty-editor__shortcuts" role="group" aria-label="Quick actions">
|
|
4794
|
+
<button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette-files">
|
|
4795
|
+
<span>Go to File</span><kbd>⌘P</kbd>
|
|
4802
4796
|
</button>
|
|
4803
|
-
<button type="button" class="codelab-
|
|
4804
|
-
|
|
4805
|
-
<span>Run Tests</span>
|
|
4806
|
-
<span class="codelab-btn__kbd">⌘↵</span>
|
|
4797
|
+
<button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette">
|
|
4798
|
+
<span>Show All Commands</span><kbd>⌘⇧P</kbd>
|
|
4807
4799
|
</button>
|
|
4808
4800
|
</div>
|
|
4801
|
+
<p class="codelab-empty-editor__subtitle">No editors open. Select a file from the Explorer to start editing.</p>
|
|
4809
4802
|
</div>
|
|
4810
4803
|
`;
|
|
4811
4804
|
}
|
|
@@ -4875,7 +4868,7 @@ declare module 'bun:sqlite' {
|
|
|
4875
4868
|
this.openCommandPalette('files');
|
|
4876
4869
|
return;
|
|
4877
4870
|
}
|
|
4878
|
-
if (
|
|
4871
|
+
if (e.ctrlKey && !e.metaKey && keyLower === 'c') {
|
|
4879
4872
|
const hasSelection = typeof window !== 'undefined' && window.getSelection && window.getSelection().toString().length > 0;
|
|
4880
4873
|
if (!hasSelection && (this.isRunning || this._activeCommandAbortController)) {
|
|
4881
4874
|
e.preventDefault();
|
|
@@ -5177,6 +5170,7 @@ declare module 'bun:sqlite' {
|
|
|
5177
5170
|
if (action === 'run-demo') this.runDemo();
|
|
5178
5171
|
else if (action === 'run-tests') this.runTests();
|
|
5179
5172
|
else if (action === 'stop-run') this.stopExecution();
|
|
5173
|
+
else if (action === 'interrupt') this._handleInterrupt();
|
|
5180
5174
|
else if (action === 'verify-step') this.verifyCurrentStep();
|
|
5181
5175
|
else if (action === 'show-diff') this.showSolutionModal();
|
|
5182
5176
|
else if (action === 'compare-diff') {
|
|
@@ -5770,6 +5764,48 @@ declare module 'bun:sqlite' {
|
|
|
5770
5764
|
hSplitter.addEventListener('pointerup', onUp);
|
|
5771
5765
|
});
|
|
5772
5766
|
}
|
|
5767
|
+
|
|
5768
|
+
const fSplitter = this.container.querySelector('#cl-splitter-files');
|
|
5769
|
+
if (fSplitter) {
|
|
5770
|
+
const applyWidth = (w) => {
|
|
5771
|
+
this.explorerWidth = Math.round(w);
|
|
5772
|
+
shell.style.setProperty('--cl-explorer-width', `${this.explorerWidth}px`);
|
|
5773
|
+
if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
|
|
5774
|
+
};
|
|
5775
|
+
|
|
5776
|
+
fSplitter.addEventListener('dblclick', () => {
|
|
5777
|
+
applyWidth(196);
|
|
5778
|
+
this._saveState();
|
|
5779
|
+
});
|
|
5780
|
+
|
|
5781
|
+
fSplitter.addEventListener('pointerdown', e => {
|
|
5782
|
+
e.preventDefault();
|
|
5783
|
+
fSplitter.classList.add('is-dragging');
|
|
5784
|
+
shell.classList.add('is-resizing');
|
|
5785
|
+
try { fSplitter.setPointerCapture(e.pointerId); } catch (_) {}
|
|
5786
|
+
|
|
5787
|
+
const onMove = ev => {
|
|
5788
|
+
const ws = this.container.querySelector('.codelab-workspace');
|
|
5789
|
+
const rect = (ws || shell).getBoundingClientRect();
|
|
5790
|
+
const minW = 140;
|
|
5791
|
+
const maxW = Math.max(minW, Math.floor(rect.width * 0.5));
|
|
5792
|
+
const nextW = Math.min(maxW, Math.max(minW, Math.round(ev.clientX - rect.left)));
|
|
5793
|
+
applyWidth(nextW);
|
|
5794
|
+
};
|
|
5795
|
+
|
|
5796
|
+
const onUp = ev => {
|
|
5797
|
+
fSplitter.classList.remove('is-dragging');
|
|
5798
|
+
shell.classList.remove('is-resizing');
|
|
5799
|
+
try { fSplitter.releasePointerCapture(ev.pointerId); } catch (_) {}
|
|
5800
|
+
fSplitter.removeEventListener('pointermove', onMove);
|
|
5801
|
+
fSplitter.removeEventListener('pointerup', onUp);
|
|
5802
|
+
this._saveState();
|
|
5803
|
+
};
|
|
5804
|
+
|
|
5805
|
+
fSplitter.addEventListener('pointermove', onMove);
|
|
5806
|
+
fSplitter.addEventListener('pointerup', onUp);
|
|
5807
|
+
});
|
|
5808
|
+
}
|
|
5773
5809
|
}
|
|
5774
5810
|
|
|
5775
5811
|
selectStep(idx, shouldJump = true) {
|
|
@@ -6166,6 +6202,12 @@ declare module 'bun:sqlite' {
|
|
|
6166
6202
|
}
|
|
6167
6203
|
|
|
6168
6204
|
// ── Execution Engine (Web Worker + Virtual Node Runtime) ───────────────
|
|
6205
|
+
_isAbortResult(res, signal) {
|
|
6206
|
+
if (signal && signal.aborted) return true;
|
|
6207
|
+
if (!res || typeof res !== 'object') return false;
|
|
6208
|
+
return Boolean(res.cancelled || res.aborted || res.exitCode === 130);
|
|
6209
|
+
}
|
|
6210
|
+
|
|
6169
6211
|
async _executeRuntime(execOptions) {
|
|
6170
6212
|
const t0 = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
|
6171
6213
|
const payload = {
|
|
@@ -6202,7 +6244,11 @@ declare module 'bun:sqlite' {
|
|
|
6202
6244
|
this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
|
|
6203
6245
|
return res;
|
|
6204
6246
|
} catch (err) {
|
|
6205
|
-
|
|
6247
|
+
if (payload.signal && payload.signal.aborted) {
|
|
6248
|
+
this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
|
|
6249
|
+
} else {
|
|
6250
|
+
this._setRuntimeStatus('error', 'Execution error');
|
|
6251
|
+
}
|
|
6206
6252
|
throw err;
|
|
6207
6253
|
}
|
|
6208
6254
|
}
|
|
@@ -6244,18 +6290,21 @@ declare module 'bun:sqlite' {
|
|
|
6244
6290
|
}
|
|
6245
6291
|
});
|
|
6246
6292
|
this._flushTerminalStream();
|
|
6293
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
6247
6294
|
|
|
6248
|
-
if (!streamedStdout && res.stdout) {
|
|
6295
|
+
if (!aborted && !streamedStdout && res.stdout) {
|
|
6249
6296
|
this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
6250
6297
|
}
|
|
6251
|
-
if (!streamedStderr && res.stderr) {
|
|
6298
|
+
if (!aborted && !streamedStderr && res.stderr) {
|
|
6252
6299
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
6253
6300
|
}
|
|
6254
|
-
if (res.error) {
|
|
6301
|
+
if (!aborted && res.error) {
|
|
6255
6302
|
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
6256
6303
|
}
|
|
6257
|
-
|
|
6258
|
-
|
|
6304
|
+
if (!aborted) {
|
|
6305
|
+
this.lastFsSnapshot = res.fsSnapshot || [];
|
|
6306
|
+
this.lastHttpTrace = res.httpTrace || [];
|
|
6307
|
+
}
|
|
6259
6308
|
|
|
6260
6309
|
if (this.onRun) {
|
|
6261
6310
|
try { this.onRun(res); } catch (_) {}
|
|
@@ -6263,7 +6312,9 @@ declare module 'bun:sqlite' {
|
|
|
6263
6312
|
this._emitEvent('codelab:run', { labId: this.labId, mode: 'run', entry, result: res });
|
|
6264
6313
|
} catch (err) {
|
|
6265
6314
|
this._flushTerminalStream();
|
|
6266
|
-
|
|
6315
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
6316
|
+
this.terminalLogs.push({ type: 'stderr', text: `Execution error: ${formatErrorText(err)}` });
|
|
6317
|
+
}
|
|
6267
6318
|
} finally {
|
|
6268
6319
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
6269
6320
|
this._activeCommandAbortController = null;
|
|
@@ -6312,18 +6363,21 @@ declare module 'bun:sqlite' {
|
|
|
6312
6363
|
}
|
|
6313
6364
|
});
|
|
6314
6365
|
this._flushTerminalStream();
|
|
6366
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
6315
6367
|
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6368
|
+
if (!aborted) {
|
|
6369
|
+
this.lastTestResults = res.testResults || [];
|
|
6370
|
+
this.lastFsSnapshot = res.fsSnapshot || [];
|
|
6371
|
+
this.lastHttpTrace = res.httpTrace || [];
|
|
6372
|
+
}
|
|
6319
6373
|
|
|
6320
|
-
if (!streamedStdout && res.stdout) {
|
|
6374
|
+
if (!aborted && !streamedStdout && res.stdout) {
|
|
6321
6375
|
this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
6322
6376
|
}
|
|
6323
|
-
if (!streamedStderr && res.stderr) {
|
|
6377
|
+
if (!aborted && !streamedStderr && res.stderr) {
|
|
6324
6378
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
6325
6379
|
}
|
|
6326
|
-
if (res.error) {
|
|
6380
|
+
if (!aborted && res.error) {
|
|
6327
6381
|
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
6328
6382
|
}
|
|
6329
6383
|
|
|
@@ -6374,7 +6428,9 @@ declare module 'bun:sqlite' {
|
|
|
6374
6428
|
}
|
|
6375
6429
|
} catch (err) {
|
|
6376
6430
|
this._flushTerminalStream();
|
|
6377
|
-
|
|
6431
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
6432
|
+
this.terminalLogs.push({ type: 'stderr', text: `Test runner error: ${formatErrorText(err)}` });
|
|
6433
|
+
}
|
|
6378
6434
|
} finally {
|
|
6379
6435
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
6380
6436
|
this._activeCommandAbortController = null;
|
|
@@ -6465,16 +6521,19 @@ declare module 'bun:sqlite' {
|
|
|
6465
6521
|
onStderr: (c) => { streamedStderr = true; this._appendTerminalStream('stderr', c); }
|
|
6466
6522
|
});
|
|
6467
6523
|
this._flushTerminalStream();
|
|
6524
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
6468
6525
|
const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
|
|
6469
|
-
if (!streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
6470
|
-
if (!streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
6471
|
-
if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
6526
|
+
if (!aborted && !streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
6527
|
+
if (!aborted && !streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
6528
|
+
if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
6472
6529
|
this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
|
|
6473
6530
|
}
|
|
6474
|
-
if (res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
6531
|
+
if (!aborted && res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
6475
6532
|
} catch (err) {
|
|
6476
6533
|
this._flushTerminalStream();
|
|
6477
|
-
|
|
6534
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
6535
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
6536
|
+
}
|
|
6478
6537
|
} finally {
|
|
6479
6538
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
6480
6539
|
this._activeCommandAbortController = null;
|
|
@@ -6533,6 +6592,7 @@ declare module 'bun:sqlite' {
|
|
|
6533
6592
|
signal: abortCtrl.signal
|
|
6534
6593
|
});
|
|
6535
6594
|
this._flushTerminalStream();
|
|
6595
|
+
const aborted = this._isAbortResult(shellRes, abortCtrl.signal);
|
|
6536
6596
|
this.cwd = this.shell.cwd || this.cwd;
|
|
6537
6597
|
this._syncVfsSnapshot(null, true);
|
|
6538
6598
|
|
|
@@ -6552,10 +6612,10 @@ declare module 'bun:sqlite' {
|
|
|
6552
6612
|
|
|
6553
6613
|
const isCmdNotFound = shellRes && shellRes.exitCode === 127 && typeof shellRes.stderr === 'string' && shellRes.stderr.includes('command not found');
|
|
6554
6614
|
if (!isCmdNotFound) {
|
|
6555
|
-
if (shellRes && shellRes.stdout && !streamedStdout) {
|
|
6615
|
+
if (!aborted && shellRes && shellRes.stdout && !streamedStdout) {
|
|
6556
6616
|
this.terminalLogs.push({ type: 'stdout', text: shellRes.stdout.replace(/\n$/, '') });
|
|
6557
6617
|
}
|
|
6558
|
-
if (shellRes && shellRes.stderr && !streamedStderr) {
|
|
6618
|
+
if (!aborted && shellRes && shellRes.stderr && !streamedStderr) {
|
|
6559
6619
|
this.terminalLogs.push({ type: 'stderr', text: shellRes.stderr.replace(/\n$/, '') });
|
|
6560
6620
|
}
|
|
6561
6621
|
this._renderDrawerBody();
|
|
@@ -6568,7 +6628,9 @@ declare module 'bun:sqlite' {
|
|
|
6568
6628
|
}
|
|
6569
6629
|
} catch (err) {
|
|
6570
6630
|
this._flushTerminalStream();
|
|
6571
|
-
|
|
6631
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
6632
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
6633
|
+
}
|
|
6572
6634
|
this._renderDrawerBody();
|
|
6573
6635
|
return;
|
|
6574
6636
|
} finally {
|
|
@@ -6604,17 +6666,18 @@ declare module 'bun:sqlite' {
|
|
|
6604
6666
|
}
|
|
6605
6667
|
});
|
|
6606
6668
|
this._flushTerminalStream();
|
|
6669
|
+
const aborted = this._isAbortResult(res, fallbackAbortCtrl.signal);
|
|
6607
6670
|
const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
|
|
6608
|
-
if (!streamedFallbackStdout && cleanStdout) {
|
|
6671
|
+
if (!aborted && !streamedFallbackStdout && cleanStdout) {
|
|
6609
6672
|
this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
6610
6673
|
}
|
|
6611
|
-
if (!streamedFallbackStderr && res.stderr) {
|
|
6674
|
+
if (!aborted && !streamedFallbackStderr && res.stderr) {
|
|
6612
6675
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
6613
6676
|
}
|
|
6614
|
-
if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
6677
|
+
if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
6615
6678
|
this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
|
|
6616
6679
|
}
|
|
6617
|
-
if (res.error) {
|
|
6680
|
+
if (!aborted && res.error) {
|
|
6618
6681
|
const errStr = formatErrorText(res.error);
|
|
6619
6682
|
if (/^[a-zA-Z0-9_-]+$/.test(trimmed) && errStr.includes(`ReferenceError: ${trimmed} is not defined`)) {
|
|
6620
6683
|
this.terminalLogs.push({ type: 'stderr', text: `codelab: ${trimmed}: command not found (type "help" for commands or enter a JS/TS expression)` });
|
|
@@ -6624,7 +6687,9 @@ declare module 'bun:sqlite' {
|
|
|
6624
6687
|
}
|
|
6625
6688
|
} catch (err) {
|
|
6626
6689
|
this._flushTerminalStream();
|
|
6627
|
-
|
|
6690
|
+
if (!(fallbackAbortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
6691
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
6692
|
+
}
|
|
6628
6693
|
} finally {
|
|
6629
6694
|
if (this._activeCommandAbortController === fallbackAbortCtrl) {
|
|
6630
6695
|
this._activeCommandAbortController = null;
|
|
@@ -6876,8 +6941,13 @@ declare module 'bun:sqlite' {
|
|
|
6876
6941
|
const intoRoot = options.intoRoot !== false;
|
|
6877
6942
|
const targetDir = intoRoot ? '/workspace' : `/workspace/${parsed.repo}`;
|
|
6878
6943
|
const cmdDisplay = `git clone ${repoInput}${intoRoot ? ' .' : ''}`;
|
|
6944
|
+
this.drawerTab = 'terminal';
|
|
6879
6945
|
this.terminalLogs.push({ type: 'cmd', text: cmdDisplay });
|
|
6946
|
+
this.isRunning = true;
|
|
6947
|
+
const abortCtrl = new AbortController();
|
|
6948
|
+
this._activeCommandAbortController = abortCtrl;
|
|
6880
6949
|
this._renderDrawerBody();
|
|
6950
|
+
this._updateRunStateUI();
|
|
6881
6951
|
|
|
6882
6952
|
try {
|
|
6883
6953
|
if (intoRoot && this.shell && this.shell.vfs) {
|
|
@@ -6900,6 +6970,7 @@ declare module 'bun:sqlite' {
|
|
|
6900
6970
|
maxFiles: options.maxFiles || 250,
|
|
6901
6971
|
maxFileSize: options.maxFileSize || 512 * 1024,
|
|
6902
6972
|
fetchImpl: options.fetchImpl || (this.shell && this.shell.options ? this.shell.options.fetchImpl : undefined),
|
|
6973
|
+
signal: abortCtrl.signal,
|
|
6903
6974
|
onProgress: options.onProgress
|
|
6904
6975
|
});
|
|
6905
6976
|
|
|
@@ -6971,10 +7042,18 @@ declare module 'bun:sqlite' {
|
|
|
6971
7042
|
this._emitEvent('repo:cloned', eventDetail);
|
|
6972
7043
|
return result;
|
|
6973
7044
|
} catch (err) {
|
|
6974
|
-
|
|
6975
|
-
|
|
7045
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
7046
|
+
const msg = err && err.message ? err.message : String(err);
|
|
7047
|
+
this.terminalLogs.push({ type: 'stderr', text: msg });
|
|
7048
|
+
}
|
|
6976
7049
|
this._renderDrawerBody();
|
|
6977
7050
|
throw err;
|
|
7051
|
+
} finally {
|
|
7052
|
+
if (this._activeCommandAbortController === abortCtrl) {
|
|
7053
|
+
this._activeCommandAbortController = null;
|
|
7054
|
+
}
|
|
7055
|
+
this.isRunning = false;
|
|
7056
|
+
this._updateRunStateUI();
|
|
6978
7057
|
}
|
|
6979
7058
|
}
|
|
6980
7059
|
|