@innovatorved/code-lab 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/code-lab.css +209 -1
- package/dist/code-lab.esm.js +253 -16
- package/dist/code-lab.js +253 -16
- package/dist/shell.esm.js +52 -1
- package/dist/shell.js +52 -1
- package/package.json +2 -2
- package/src/code-lab.css +209 -1
- package/src/shell.js +52 -1
- package/src/shell.ts +28 -1
- package/src/workbench.js +201 -15
- package/src/workbench.ts +201 -15
package/dist/code-lab.js
CHANGED
|
@@ -9479,6 +9479,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9479
9479
|
}
|
|
9480
9480
|
|
|
9481
9481
|
async function cloneGitHubRepository(repoInput, vfs, options = {}) {
|
|
9482
|
+
const onProgress = typeof options.onProgress === 'function' ? options.onProgress : null;
|
|
9483
|
+
if (onProgress) {
|
|
9484
|
+
onProgress({ phase: 'connecting', message: `Connecting to repository '${repoInput}'...` });
|
|
9485
|
+
}
|
|
9482
9486
|
const parsed = parseGitHubRepoUrl(repoInput);
|
|
9483
9487
|
if (!parsed) {
|
|
9484
9488
|
throw new Error(`fatal: repository '${repoInput}' does not exist or is not a valid GitHub repository URL`);
|
|
@@ -9502,6 +9506,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9502
9506
|
let rawTreeEntries = null;
|
|
9503
9507
|
let repoNotFound = false;
|
|
9504
9508
|
|
|
9509
|
+
if (onProgress) {
|
|
9510
|
+
onProgress({ phase: 'metadata', message: `Fetching repository metadata for ${owner}/${repo}...` });
|
|
9511
|
+
}
|
|
9512
|
+
|
|
9505
9513
|
// Strategy A: GitHub REST API (with automatic fallback if rate-limited)
|
|
9506
9514
|
try {
|
|
9507
9515
|
if (!resolvedBranch) {
|
|
@@ -9606,6 +9614,11 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9606
9614
|
|
|
9607
9615
|
filtered.sort((a, b) => a.priority - b.priority || a.destPath.localeCompare(b.destPath));
|
|
9608
9616
|
const selectedFiles = filtered.slice(0, maxFiles);
|
|
9617
|
+
const totalToDownload = selectedFiles.length;
|
|
9618
|
+
|
|
9619
|
+
if (onProgress) {
|
|
9620
|
+
onProgress({ phase: 'downloading', message: `Downloading files (0/${totalToDownload})...`, loaded: 0, total: totalToDownload });
|
|
9621
|
+
}
|
|
9609
9622
|
|
|
9610
9623
|
if (!vfs.existsSync(targetDir)) {
|
|
9611
9624
|
vfs.mkdirSync(targetDir, { recursive: true });
|
|
@@ -9651,6 +9664,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9651
9664
|
headSnapshot[entry.destPath] = text;
|
|
9652
9665
|
filesWritten++;
|
|
9653
9666
|
totalBytes += text.length;
|
|
9667
|
+
if (onProgress) {
|
|
9668
|
+
onProgress({ phase: 'downloading', message: `Downloading files (${filesWritten}/${totalToDownload}): ${entry.destPath}`, loaded: filesWritten, total: totalToDownload });
|
|
9669
|
+
}
|
|
9654
9670
|
if (typeof options.onFile === 'function') {
|
|
9655
9671
|
options.onFile(absPath, text, entry.destPath);
|
|
9656
9672
|
}
|
|
@@ -9659,6 +9675,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9659
9675
|
);
|
|
9660
9676
|
}
|
|
9661
9677
|
|
|
9678
|
+
if (onProgress) {
|
|
9679
|
+
onProgress({ phase: 'mounting', message: `Mounting files and writing Git metadata into ${targetDir}...`, loaded: filesWritten, total: totalToDownload });
|
|
9680
|
+
}
|
|
9681
|
+
|
|
9662
9682
|
// Write .git metadata inside targetDir
|
|
9663
9683
|
const gitDir = PosixPath.join(targetDir, '.git');
|
|
9664
9684
|
if (!vfs.existsSync(gitDir)) {
|
|
@@ -9707,6 +9727,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9707
9727
|
];
|
|
9708
9728
|
}
|
|
9709
9729
|
|
|
9730
|
+
if (onProgress) {
|
|
9731
|
+
onProgress({ phase: 'ready', message: `Repository cloned successfully (${filesWritten} files).`, loaded: filesWritten, total: totalToDownload });
|
|
9732
|
+
}
|
|
9733
|
+
|
|
9710
9734
|
return {
|
|
9711
9735
|
owner,
|
|
9712
9736
|
repo,
|
|
@@ -11906,12 +11930,37 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
11906
11930
|
dirDisplayName = parsed.repo;
|
|
11907
11931
|
}
|
|
11908
11932
|
|
|
11933
|
+
// Stream clone progress to the terminal as it happens (no end-of-run buffering).
|
|
11934
|
+
const canStream = typeof ctx.onStdout === 'function';
|
|
11935
|
+
const streamLine = (text) => { if (canStream && text) ctx.onStdout(text); };
|
|
11936
|
+
streamLine(`Cloning into '${dirDisplayName}'...\n`);
|
|
11937
|
+
let enumeratedEmitted = false;
|
|
11938
|
+
let lastProgressPct = -1;
|
|
11939
|
+
|
|
11909
11940
|
try {
|
|
11910
11941
|
const result = await cloneGitHubRepository(repoArg, ctx.vfs, {
|
|
11911
11942
|
targetDir,
|
|
11912
11943
|
branch: branchOpt,
|
|
11913
11944
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
11914
|
-
onFile: (absPath) => ctx.emitMutation('create', absPath)
|
|
11945
|
+
onFile: (absPath) => ctx.emitMutation('create', absPath),
|
|
11946
|
+
onProgress: (ev) => {
|
|
11947
|
+
if (!ev) return;
|
|
11948
|
+
if (ev.phase === 'downloading' && !enumeratedEmitted && typeof ev.total === 'number' && ev.total > 0) {
|
|
11949
|
+
enumeratedEmitted = true;
|
|
11950
|
+
streamLine(`remote: Enumerating objects: ${ev.total}, done.\n`);
|
|
11951
|
+
streamLine(`remote: Counting objects: 100% (${ev.total}/${ev.total}), done.\n`);
|
|
11952
|
+
}
|
|
11953
|
+
if (ev.phase === 'downloading' && typeof ev.total === 'number' && ev.total > 0 && typeof ev.loaded === 'number' && ev.loaded < ev.total) {
|
|
11954
|
+
const pct = Math.min(100, Math.max(0, Math.floor((ev.loaded / ev.total) * 100)));
|
|
11955
|
+
if (pct >= lastProgressPct + 10) {
|
|
11956
|
+
lastProgressPct = pct;
|
|
11957
|
+
streamLine(`Receiving objects: ${pct}% (${ev.loaded}/${ev.total})\n`);
|
|
11958
|
+
}
|
|
11959
|
+
}
|
|
11960
|
+
if (ev.phase === 'mounting') {
|
|
11961
|
+
streamLine(`Resolving deltas: 100% (${ev.total || 0}/${ev.total || 0}), done.\n`);
|
|
11962
|
+
}
|
|
11963
|
+
}
|
|
11915
11964
|
});
|
|
11916
11965
|
|
|
11917
11966
|
gitState.branch = result.branch;
|
|
@@ -11925,6 +11974,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
11925
11974
|
|
|
11926
11975
|
const count = Math.max(1, result.filesWritten);
|
|
11927
11976
|
const kb = Math.max(0.1, result.totalBytes / 1024).toFixed(1);
|
|
11977
|
+
streamLine(`Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`);
|
|
11928
11978
|
const stdout =
|
|
11929
11979
|
`Cloning into '${dirDisplayName}'...\n` +
|
|
11930
11980
|
`remote: Enumerating objects: ${count}, done.\n` +
|
|
@@ -11933,6 +11983,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
11933
11983
|
return { code: 0, stdout, stderr: '' };
|
|
11934
11984
|
} catch (err) {
|
|
11935
11985
|
const msg = err && err.message ? err.message : String(err);
|
|
11986
|
+
if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
|
|
11936
11987
|
return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
11937
11988
|
}
|
|
11938
11989
|
}
|
|
@@ -16081,6 +16132,8 @@ declare module 'bun:sqlite' {
|
|
|
16081
16132
|
this.completedSteps = new Set(this.savedState.completedSteps || []);
|
|
16082
16133
|
this.folders = new Set(this.savedState?.folders || []);
|
|
16083
16134
|
this.collapsedFolders = new Set(this.savedState?.collapsedFolders || []);
|
|
16135
|
+
this.explorerFolder = this.savedState?.explorerFolder || ''; // '' = workspace root, else folder path scope
|
|
16136
|
+
this.folderSwitcherOpen = false;
|
|
16084
16137
|
this.creatingItem = null; // { type: 'file' | 'folder', parentFolder: string } | null
|
|
16085
16138
|
this.renamingItem = null;
|
|
16086
16139
|
this._draggedFile = null;
|
|
@@ -16416,7 +16469,8 @@ declare module 'bun:sqlite' {
|
|
|
16416
16469
|
openTabs: Array.isArray(this.openTabs) ? [...this.openTabs] : undefined,
|
|
16417
16470
|
activeFile: this.activeFile,
|
|
16418
16471
|
folders: Array.from(this.folders || []),
|
|
16419
|
-
collapsedFolders: Array.from(this.collapsedFolders || [])
|
|
16472
|
+
collapsedFolders: Array.from(this.collapsedFolders || []),
|
|
16473
|
+
explorerFolder: this.explorerFolder || ''
|
|
16420
16474
|
};
|
|
16421
16475
|
this.savedState = state;
|
|
16422
16476
|
if (this.options && this.options.persistState === false) {
|
|
@@ -16860,23 +16914,59 @@ declare module 'bun:sqlite' {
|
|
|
16860
16914
|
</button>
|
|
16861
16915
|
` : '';
|
|
16862
16916
|
|
|
16863
|
-
|
|
16917
|
+
const folderOptions = this._listWorkspaceFolders();
|
|
16918
|
+
const scope = this.explorerFolder || '';
|
|
16919
|
+
const scopeLabel = scope ? scope.split('/').pop() : 'workspace';
|
|
16920
|
+
|
|
16921
|
+
const switcherHtml = `
|
|
16922
|
+
<div class="codelab-folder-switcher ${this.folderSwitcherOpen ? 'is-open' : ''}">
|
|
16923
|
+
<button type="button" class="codelab-folder-switcher__toggle ${scope ? 'is-scoped' : ''}" data-cl-action="toggle-folder-switcher" aria-haspopup="true" aria-expanded="${this.folderSwitcherOpen ? 'true' : 'false'}" title="Switch workspace folder">
|
|
16924
|
+
${CL_ICONS.folder}
|
|
16925
|
+
<span class="codelab-folder-switcher__label">${escapeHtml(scopeLabel)}</span>
|
|
16926
|
+
${CL_ICONS.chevronDown}
|
|
16927
|
+
</button>
|
|
16928
|
+
${this.folderSwitcherOpen ? `
|
|
16929
|
+
<div class="codelab-folder-switcher__menu" role="menu" aria-label="Workspace folders">
|
|
16930
|
+
<div class="codelab-folder-switcher__section">Switch Folder</div>
|
|
16931
|
+
<button type="button" role="menuitem" class="codelab-folder-switcher__option ${!scope ? 'active' : ''}" data-cl-folder-option="">
|
|
16932
|
+
<span class="codelab-folder-switcher__icon">${CL_ICONS.folder}</span>
|
|
16933
|
+
<span class="codelab-folder-switcher__name">workspace</span>
|
|
16934
|
+
<span class="codelab-folder-switcher__path">/</span>
|
|
16935
|
+
</button>
|
|
16936
|
+
${folderOptions.map(f => {
|
|
16937
|
+
const fDepth = f.split('/').length;
|
|
16938
|
+
const fName = f.split('/').pop();
|
|
16939
|
+
return `
|
|
16940
|
+
<button type="button" role="menuitem" class="codelab-folder-switcher__option ${scope === f ? 'active' : ''}" data-cl-folder-option="${escapeHtml(f)}" style="padding-left:${10 + (fDepth - 1) * 12}px;">
|
|
16941
|
+
<span class="codelab-folder-switcher__icon">${CL_ICONS.folder}</span>
|
|
16942
|
+
<span class="codelab-folder-switcher__name">${escapeHtml(fName)}</span>
|
|
16943
|
+
<span class="codelab-folder-switcher__path">${escapeHtml(f)}</span>
|
|
16944
|
+
</button>
|
|
16945
|
+
`;
|
|
16946
|
+
}).join('')}
|
|
16947
|
+
${folderOptions.length ? '' : '<div class="codelab-folder-switcher__empty">No subfolders yet</div>'}
|
|
16948
|
+
</div>
|
|
16949
|
+
` : ''}
|
|
16950
|
+
</div>
|
|
16951
|
+
`;
|
|
16952
|
+
|
|
16953
|
+
let pathHtml = `<button type="button" class="codelab-breadcrumbs__item codelab-breadcrumbs__item--root" data-action="command-palette-files" data-cl-action="command-palette-files" title="Quick Open File (⌘P)">workspace</button>`;
|
|
16864
16954
|
|
|
16865
16955
|
if (this.activeFile) {
|
|
16866
16956
|
const segments = this.activeFile.split('/');
|
|
16867
16957
|
for (let i = 0; i < segments.length - 1; i++) {
|
|
16868
16958
|
const folderPath = segments.slice(0, i + 1).join('/');
|
|
16869
|
-
pathHtml += `<span class="codelab-
|
|
16870
|
-
pathHtml += `<button type="button" class="codelab-
|
|
16959
|
+
pathHtml += `<span class="codelab-breadcrumbs__sep" aria-hidden="true">›</span>`;
|
|
16960
|
+
pathHtml += `<button type="button" class="codelab-breadcrumbs__item codelab-breadcrumbs__item--folder" data-cl-breadcrumb-folder="${escapeHtml(folderPath)}" data-folder="${escapeHtml(folderPath)}" title="Scope explorer to ${escapeHtml(folderPath)}">${escapeHtml(segments[i])}</button>`;
|
|
16871
16961
|
}
|
|
16872
16962
|
const fileName = segments[segments.length - 1];
|
|
16873
|
-
pathHtml += `<span class="codelab-
|
|
16874
|
-
pathHtml += `<button type="button" class="codelab-
|
|
16963
|
+
pathHtml += `<span class="codelab-breadcrumbs__sep" aria-hidden="true">›</span>`;
|
|
16964
|
+
pathHtml += `<button type="button" class="codelab-breadcrumbs__item codelab-breadcrumbs__item--file active" data-cl-breadcrumb-file="${escapeHtml(this.activeFile)}" data-file="${escapeHtml(this.activeFile)}">${escapeHtml(fileName)}</button>`;
|
|
16875
16965
|
|
|
16876
16966
|
const symbol = this._detectActiveSymbol(this.activeFile);
|
|
16877
16967
|
if (symbol) {
|
|
16878
|
-
pathHtml += `<span class="codelab-
|
|
16879
|
-
pathHtml += `<span class="codelab-
|
|
16968
|
+
pathHtml += `<span class="codelab-breadcrumbs__sep" aria-hidden="true">›</span>`;
|
|
16969
|
+
pathHtml += `<span class="codelab-breadcrumbs__item codelab-breadcrumbs__item--symbol" data-cl-breadcrumb-symbol="${escapeHtml(symbol)}">ƒ ${escapeHtml(symbol)}</span>`;
|
|
16880
16970
|
}
|
|
16881
16971
|
}
|
|
16882
16972
|
|
|
@@ -16897,7 +16987,10 @@ declare module 'bun:sqlite' {
|
|
|
16897
16987
|
|
|
16898
16988
|
host.innerHTML = `
|
|
16899
16989
|
${expandBtnHtml}
|
|
16900
|
-
<div class="codelab-
|
|
16990
|
+
<div class="codelab-breadcrumbs__left">
|
|
16991
|
+
${switcherHtml}
|
|
16992
|
+
<div class="codelab-breadcrumbs__path">${pathHtml}</div>
|
|
16993
|
+
</div>
|
|
16901
16994
|
<div class="codelab-breadcrumbs__actions">
|
|
16902
16995
|
${diffBtnHtml}
|
|
16903
16996
|
<button type="button" class="codelab-breadcrumb__btn" data-action="command-palette" data-cl-action="command-palette" title="Open Command Palette (⌘⇧P)">
|
|
@@ -17140,6 +17233,36 @@ declare module 'bun:sqlite' {
|
|
|
17140
17233
|
return rootNode;
|
|
17141
17234
|
}
|
|
17142
17235
|
|
|
17236
|
+
_listWorkspaceFolders() {
|
|
17237
|
+
const set = new Set();
|
|
17238
|
+
if (this.folders) {
|
|
17239
|
+
for (const f of this.folders) {
|
|
17240
|
+
if (f) set.add(f);
|
|
17241
|
+
}
|
|
17242
|
+
}
|
|
17243
|
+
for (const filePath of this._orderedFileNames()) {
|
|
17244
|
+
const idx = filePath.lastIndexOf('/');
|
|
17245
|
+
if (idx <= 0) continue;
|
|
17246
|
+
const parts = filePath.slice(0, idx).split('/');
|
|
17247
|
+
let running = '';
|
|
17248
|
+
for (const p of parts) {
|
|
17249
|
+
running = running ? `${running}/${p}` : p;
|
|
17250
|
+
set.add(running);
|
|
17251
|
+
}
|
|
17252
|
+
}
|
|
17253
|
+
return Array.from(set).sort((a, b) => a.localeCompare(b));
|
|
17254
|
+
}
|
|
17255
|
+
|
|
17256
|
+
_resolveFolderNode(rootNode, folderPath) {
|
|
17257
|
+
if (!rootNode || !folderPath) return null;
|
|
17258
|
+
let current = rootNode;
|
|
17259
|
+
for (const seg of folderPath.split('/')) {
|
|
17260
|
+
if (!current || !current.folders || !current.folders.has(seg)) return null;
|
|
17261
|
+
current = current.folders.get(seg);
|
|
17262
|
+
}
|
|
17263
|
+
return current || null;
|
|
17264
|
+
}
|
|
17265
|
+
|
|
17143
17266
|
_renderFileLists() {
|
|
17144
17267
|
const explorerEl = this.container.querySelector('#cl-explorer-list');
|
|
17145
17268
|
const tabsEl = this.container.querySelector('#cl-file-tabs');
|
|
@@ -17148,6 +17271,12 @@ declare module 'bun:sqlite' {
|
|
|
17148
17271
|
if (!explorerEl || !tabsEl) return;
|
|
17149
17272
|
|
|
17150
17273
|
const treeRoot = this._buildFileTree();
|
|
17274
|
+
if (this.explorerFolder && !this._resolveFolderNode(treeRoot, this.explorerFolder)) {
|
|
17275
|
+
this.explorerFolder = '';
|
|
17276
|
+
}
|
|
17277
|
+
const scope = this.explorerFolder || '';
|
|
17278
|
+
const renderRoot = scope ? this._resolveFolderNode(treeRoot, scope) : treeRoot;
|
|
17279
|
+
const rootParent = scope;
|
|
17151
17280
|
let treeHtml = '';
|
|
17152
17281
|
|
|
17153
17282
|
const renderNode = (node, depth) => {
|
|
@@ -17202,7 +17331,7 @@ declare module 'bun:sqlite' {
|
|
|
17202
17331
|
}
|
|
17203
17332
|
};
|
|
17204
17333
|
|
|
17205
|
-
if (this.creatingItem && this.creatingItem.parentFolder ===
|
|
17334
|
+
if (this.creatingItem && this.creatingItem.parentFolder === rootParent) {
|
|
17206
17335
|
treeHtml += `
|
|
17207
17336
|
<div class="codelab-tree-create-row" style="padding-left: 10px;">
|
|
17208
17337
|
<span class="codelab-tree-create-icon">${this.creatingItem.type === 'folder' ? CL_ICONS.folder : CL_ICONS.file}</span>
|
|
@@ -17211,7 +17340,16 @@ declare module 'bun:sqlite' {
|
|
|
17211
17340
|
`;
|
|
17212
17341
|
}
|
|
17213
17342
|
|
|
17214
|
-
|
|
17343
|
+
if (scope) {
|
|
17344
|
+
treeHtml += `
|
|
17345
|
+
<button type="button" class="codelab-scope-up" data-cl-folder-option="" title="Back to workspace root">
|
|
17346
|
+
<span class="codelab-scope-up__arrow">←</span>
|
|
17347
|
+
<span class="codelab-scope-up__label">workspace</span>
|
|
17348
|
+
</button>
|
|
17349
|
+
`;
|
|
17350
|
+
}
|
|
17351
|
+
|
|
17352
|
+
renderNode(renderRoot, 0);
|
|
17215
17353
|
explorerEl.innerHTML = treeHtml;
|
|
17216
17354
|
|
|
17217
17355
|
// Attach file drag events
|
|
@@ -18772,6 +18910,29 @@ declare module 'bun:sqlite' {
|
|
|
18772
18910
|
this._portToasts.delete(p);
|
|
18773
18911
|
}
|
|
18774
18912
|
|
|
18913
|
+
_showToast(message, kind = 'info') {
|
|
18914
|
+
const toastHost = this.container ? this.container.querySelector('#cl-toast-container') : null;
|
|
18915
|
+
if (!toastHost || typeof document === 'undefined') return;
|
|
18916
|
+
const toast = document.createElement('div');
|
|
18917
|
+
toast.className = `codelab-toast codelab-toast--${kind === 'error' ? 'error' : 'info'}`;
|
|
18918
|
+
const icon = kind === 'error' ? (CL_ICONS.x || '⚠') : (CL_ICONS.externalLink || CL_ICONS.radio || '');
|
|
18919
|
+
toast.innerHTML = `
|
|
18920
|
+
<div class="codelab-toast__icon">${icon}</div>
|
|
18921
|
+
<div class="codelab-toast__body">
|
|
18922
|
+
<div class="codelab-toast__meta">${escapeHtml(message)}</div>
|
|
18923
|
+
</div>
|
|
18924
|
+
<button type="button" class="codelab-toast__close" aria-label="Dismiss notification">${CL_ICONS.x || '×'}</button>
|
|
18925
|
+
`;
|
|
18926
|
+
const closeBtn = toast.querySelector('.codelab-toast__close');
|
|
18927
|
+
const remove = () => {
|
|
18928
|
+
if (typeof toast.remove === 'function') toast.remove();
|
|
18929
|
+
else if (toast.parentNode) toast.parentNode.removeChild(toast);
|
|
18930
|
+
};
|
|
18931
|
+
if (closeBtn) closeBtn.addEventListener('click', remove);
|
|
18932
|
+
toastHost.appendChild(toast);
|
|
18933
|
+
setTimeout(remove, 5000);
|
|
18934
|
+
}
|
|
18935
|
+
|
|
18775
18936
|
_registerPreviewServiceWorker() {
|
|
18776
18937
|
if (typeof navigator === 'undefined' || !navigator.serviceWorker || typeof navigator.serviceWorker.register !== 'function') return;
|
|
18777
18938
|
const url = (this.options && this.options.previewSwUrl) || 'preview-sw.js';
|
|
@@ -18862,9 +19023,53 @@ declare module 'bun:sqlite' {
|
|
|
18862
19023
|
_previewGo(urlOrPath) {
|
|
18863
19024
|
let url = String(urlOrPath || '').trim();
|
|
18864
19025
|
if (!url) return Promise.resolve();
|
|
19026
|
+
|
|
19027
|
+
const loopbackPort = this.previewState.port || this._firstListeningPort() || 3000;
|
|
19028
|
+
const localHostRe = /^(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(:\d+)?(\/.*)?$/i;
|
|
19029
|
+
|
|
19030
|
+
// Normalize the input into an absolute URL.
|
|
18865
19031
|
if (!/^https?:\/\//i.test(url)) {
|
|
18866
|
-
|
|
19032
|
+
if (localHostRe.test(url)) {
|
|
19033
|
+
url = `http://${url}`;
|
|
19034
|
+
} else if (/^[a-z0-9-]+(\.[a-z0-9-]+)+(:\d+)?([/?#].*)?$/i.test(url)) {
|
|
19035
|
+
// Bare public domain, e.g. "google.com" or "example.com/path".
|
|
19036
|
+
url = `https://${url}`;
|
|
19037
|
+
} else {
|
|
19038
|
+
url = `http://127.0.0.1:${loopbackPort}${url.startsWith('/') ? '' : '/'}${url}`;
|
|
19039
|
+
}
|
|
19040
|
+
}
|
|
19041
|
+
|
|
19042
|
+
// Public (non-loopback) URLs cannot be served by the virtual loopback Service
|
|
19043
|
+
// Worker, so open them in a real browser tab instead of the in-browser frame.
|
|
19044
|
+
let isExternal = false;
|
|
19045
|
+
try {
|
|
19046
|
+
const u = new URL(url);
|
|
19047
|
+
const host = (u.hostname || '').toLowerCase();
|
|
19048
|
+
isExternal = !(host === 'localhost' || host === '127.0.0.1' || host === '0.0.0.0' || host === '::1' || host === '[::1]');
|
|
19049
|
+
} catch (_) { isExternal = false; }
|
|
19050
|
+
|
|
19051
|
+
if (isExternal) {
|
|
19052
|
+
let opened = false;
|
|
19053
|
+
if (typeof window !== 'undefined' && typeof window.open === 'function') {
|
|
19054
|
+
try {
|
|
19055
|
+
const win = window.open(url, '_blank');
|
|
19056
|
+
if (win) {
|
|
19057
|
+
try { win.opener = null; } catch (_) {}
|
|
19058
|
+
opened = true;
|
|
19059
|
+
}
|
|
19060
|
+
} catch (_) { opened = false; }
|
|
19061
|
+
}
|
|
19062
|
+
if (typeof this._showToast === 'function') {
|
|
19063
|
+
this._showToast(
|
|
19064
|
+
opened ? `Opened ${url} in a new tab` : `Could not open ${url} — allow pop-ups and try again`,
|
|
19065
|
+
opened ? 'info' : 'error'
|
|
19066
|
+
);
|
|
19067
|
+
}
|
|
19068
|
+
const inputEl = this.container.querySelector('#cl-preview-url-input');
|
|
19069
|
+
if (inputEl) inputEl.value = this.previewState.url || inputEl.value;
|
|
19070
|
+
return Promise.resolve();
|
|
18867
19071
|
}
|
|
19072
|
+
|
|
18868
19073
|
let port = this.previewState.port;
|
|
18869
19074
|
let path = '/';
|
|
18870
19075
|
try {
|
|
@@ -18974,7 +19179,7 @@ declare module 'bun:sqlite' {
|
|
|
18974
19179
|
<button type="button" class="codelab-preview-btn" data-cl-action="preview-reload" title="Reload">${CL_ICONS.refresh || '⟳'}</button>
|
|
18975
19180
|
</div>
|
|
18976
19181
|
<select class="codelab-preview-port-select" data-cl-action="preview-port-change" aria-label="Preview port">${portOptions}</select>
|
|
18977
|
-
<input type="text" class="codelab-preview-url-input" id="cl-preview-url-input" value="${escapeHtml(this.previewState.url)}" placeholder="
|
|
19182
|
+
<input type="text" class="codelab-preview-url-input" id="cl-preview-url-input" value="${escapeHtml(this.previewState.url)}" placeholder="127.0.0.1:3000/ or https://example.com" aria-label="Preview URL" title="Localhost/virtual ports load in-frame; public URLs open in a new tab" />
|
|
18978
19183
|
<div class="codelab-preview-modes">
|
|
18979
19184
|
<button type="button" class="codelab-preview-btn ${this.previewState.frameMode === 'desktop' ? 'active' : ''}" data-cl-action="preview-mode" data-mode="desktop" title="Desktop">${CL_ICONS.monitor || '▭'}</button>
|
|
18980
19185
|
<button type="button" class="codelab-preview-btn ${this.previewState.frameMode === 'tablet' ? 'active' : ''}" data-cl-action="preview-mode" data-mode="tablet" title="Tablet">${CL_ICONS.tablet || '▢'}</button>
|
|
@@ -19593,6 +19798,11 @@ declare module 'bun:sqlite' {
|
|
|
19593
19798
|
this._previewGo(previewInput.value);
|
|
19594
19799
|
return;
|
|
19595
19800
|
}
|
|
19801
|
+
if (e.key === 'Escape' && this.folderSwitcherOpen) {
|
|
19802
|
+
this.folderSwitcherOpen = false;
|
|
19803
|
+
this._renderBreadcrumbs();
|
|
19804
|
+
return;
|
|
19805
|
+
}
|
|
19596
19806
|
if (e.key === 'F1' || ((e.metaKey || e.ctrlKey) && e.shiftKey && keyLower === 'p')) {
|
|
19597
19807
|
e.preventDefault();
|
|
19598
19808
|
this.openCommandPalette('commands');
|
|
@@ -19793,12 +20003,39 @@ declare module 'bun:sqlite' {
|
|
|
19793
20003
|
return;
|
|
19794
20004
|
}
|
|
19795
20005
|
|
|
20006
|
+
const fsToggle = e.target.closest('[data-cl-action="toggle-folder-switcher"]');
|
|
20007
|
+
if (fsToggle) {
|
|
20008
|
+
e.stopPropagation();
|
|
20009
|
+
this.folderSwitcherOpen = !this.folderSwitcherOpen;
|
|
20010
|
+
this._renderBreadcrumbs();
|
|
20011
|
+
return;
|
|
20012
|
+
}
|
|
20013
|
+
|
|
20014
|
+
const fsOption = e.target.closest('[data-cl-folder-option]');
|
|
20015
|
+
if (fsOption) {
|
|
20016
|
+
e.stopPropagation();
|
|
20017
|
+
const scopeVal = fsOption.dataset.clFolderOption || '';
|
|
20018
|
+
this.explorerFolder = scopeVal;
|
|
20019
|
+
if (scopeVal) this.collapsedFolders.delete(scopeVal);
|
|
20020
|
+
this.folderSwitcherOpen = false;
|
|
20021
|
+
this._renderFileLists();
|
|
20022
|
+
this._renderBreadcrumbs();
|
|
20023
|
+
return;
|
|
20024
|
+
}
|
|
20025
|
+
|
|
20026
|
+
if (this.folderSwitcherOpen && !e.target.closest('.codelab-folder-switcher')) {
|
|
20027
|
+
this.folderSwitcherOpen = false;
|
|
20028
|
+
this._renderBreadcrumbs();
|
|
20029
|
+
}
|
|
20030
|
+
|
|
19796
20031
|
const bcFolder = e.target.closest('[data-cl-breadcrumb-folder]');
|
|
19797
20032
|
if (bcFolder) {
|
|
19798
20033
|
const folder = bcFolder.dataset.clBreadcrumbFolder;
|
|
19799
20034
|
if (folder) {
|
|
19800
20035
|
this.collapsedFolders.delete(folder);
|
|
20036
|
+
this.explorerFolder = folder;
|
|
19801
20037
|
this._renderFileLists();
|
|
20038
|
+
this._renderBreadcrumbs();
|
|
19802
20039
|
}
|
|
19803
20040
|
return;
|
|
19804
20041
|
}
|
|
@@ -19933,10 +20170,10 @@ declare module 'bun:sqlite' {
|
|
|
19933
20170
|
this.isCreatingFile = true;
|
|
19934
20171
|
this._renderFileLists();
|
|
19935
20172
|
} else if (action === 'new-file-root') {
|
|
19936
|
-
this.creatingItem = { type: 'file', parentFolder: '' };
|
|
20173
|
+
this.creatingItem = { type: 'file', parentFolder: this.explorerFolder || '' };
|
|
19937
20174
|
this._renderFileLists();
|
|
19938
20175
|
} else if (action === 'new-folder-root') {
|
|
19939
|
-
this.creatingItem = { type: 'folder', parentFolder: '' };
|
|
20176
|
+
this.creatingItem = { type: 'folder', parentFolder: this.explorerFolder || '' };
|
|
19940
20177
|
this._renderFileLists();
|
|
19941
20178
|
} else if (action === 'new-file-folder') {
|
|
19942
20179
|
const folder = actionBtn.dataset.clFolder || '';
|
package/dist/shell.esm.js
CHANGED
|
@@ -2004,6 +2004,10 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2004
2004
|
}
|
|
2005
2005
|
|
|
2006
2006
|
async function cloneGitHubRepository(repoInput, vfs, options = {}) {
|
|
2007
|
+
const onProgress = typeof options.onProgress === 'function' ? options.onProgress : null;
|
|
2008
|
+
if (onProgress) {
|
|
2009
|
+
onProgress({ phase: 'connecting', message: `Connecting to repository '${repoInput}'...` });
|
|
2010
|
+
}
|
|
2007
2011
|
const parsed = parseGitHubRepoUrl(repoInput);
|
|
2008
2012
|
if (!parsed) {
|
|
2009
2013
|
throw new Error(`fatal: repository '${repoInput}' does not exist or is not a valid GitHub repository URL`);
|
|
@@ -2027,6 +2031,10 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2027
2031
|
let rawTreeEntries = null;
|
|
2028
2032
|
let repoNotFound = false;
|
|
2029
2033
|
|
|
2034
|
+
if (onProgress) {
|
|
2035
|
+
onProgress({ phase: 'metadata', message: `Fetching repository metadata for ${owner}/${repo}...` });
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2030
2038
|
// Strategy A: GitHub REST API (with automatic fallback if rate-limited)
|
|
2031
2039
|
try {
|
|
2032
2040
|
if (!resolvedBranch) {
|
|
@@ -2131,6 +2139,11 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2131
2139
|
|
|
2132
2140
|
filtered.sort((a, b) => a.priority - b.priority || a.destPath.localeCompare(b.destPath));
|
|
2133
2141
|
const selectedFiles = filtered.slice(0, maxFiles);
|
|
2142
|
+
const totalToDownload = selectedFiles.length;
|
|
2143
|
+
|
|
2144
|
+
if (onProgress) {
|
|
2145
|
+
onProgress({ phase: 'downloading', message: `Downloading files (0/${totalToDownload})...`, loaded: 0, total: totalToDownload });
|
|
2146
|
+
}
|
|
2134
2147
|
|
|
2135
2148
|
if (!vfs.existsSync(targetDir)) {
|
|
2136
2149
|
vfs.mkdirSync(targetDir, { recursive: true });
|
|
@@ -2176,6 +2189,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2176
2189
|
headSnapshot[entry.destPath] = text;
|
|
2177
2190
|
filesWritten++;
|
|
2178
2191
|
totalBytes += text.length;
|
|
2192
|
+
if (onProgress) {
|
|
2193
|
+
onProgress({ phase: 'downloading', message: `Downloading files (${filesWritten}/${totalToDownload}): ${entry.destPath}`, loaded: filesWritten, total: totalToDownload });
|
|
2194
|
+
}
|
|
2179
2195
|
if (typeof options.onFile === 'function') {
|
|
2180
2196
|
options.onFile(absPath, text, entry.destPath);
|
|
2181
2197
|
}
|
|
@@ -2184,6 +2200,10 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2184
2200
|
);
|
|
2185
2201
|
}
|
|
2186
2202
|
|
|
2203
|
+
if (onProgress) {
|
|
2204
|
+
onProgress({ phase: 'mounting', message: `Mounting files and writing Git metadata into ${targetDir}...`, loaded: filesWritten, total: totalToDownload });
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2187
2207
|
// Write .git metadata inside targetDir
|
|
2188
2208
|
const gitDir = PosixPath.join(targetDir, '.git');
|
|
2189
2209
|
if (!vfs.existsSync(gitDir)) {
|
|
@@ -2232,6 +2252,10 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2232
2252
|
];
|
|
2233
2253
|
}
|
|
2234
2254
|
|
|
2255
|
+
if (onProgress) {
|
|
2256
|
+
onProgress({ phase: 'ready', message: `Repository cloned successfully (${filesWritten} files).`, loaded: filesWritten, total: totalToDownload });
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2235
2259
|
return {
|
|
2236
2260
|
owner,
|
|
2237
2261
|
repo,
|
|
@@ -4431,12 +4455,37 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
4431
4455
|
dirDisplayName = parsed.repo;
|
|
4432
4456
|
}
|
|
4433
4457
|
|
|
4458
|
+
// Stream clone progress to the terminal as it happens (no end-of-run buffering).
|
|
4459
|
+
const canStream = typeof ctx.onStdout === 'function';
|
|
4460
|
+
const streamLine = (text) => { if (canStream && text) ctx.onStdout(text); };
|
|
4461
|
+
streamLine(`Cloning into '${dirDisplayName}'...\n`);
|
|
4462
|
+
let enumeratedEmitted = false;
|
|
4463
|
+
let lastProgressPct = -1;
|
|
4464
|
+
|
|
4434
4465
|
try {
|
|
4435
4466
|
const result = await cloneGitHubRepository(repoArg, ctx.vfs, {
|
|
4436
4467
|
targetDir,
|
|
4437
4468
|
branch: branchOpt,
|
|
4438
4469
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
4439
|
-
onFile: (absPath) => ctx.emitMutation('create', absPath)
|
|
4470
|
+
onFile: (absPath) => ctx.emitMutation('create', absPath),
|
|
4471
|
+
onProgress: (ev) => {
|
|
4472
|
+
if (!ev) return;
|
|
4473
|
+
if (ev.phase === 'downloading' && !enumeratedEmitted && typeof ev.total === 'number' && ev.total > 0) {
|
|
4474
|
+
enumeratedEmitted = true;
|
|
4475
|
+
streamLine(`remote: Enumerating objects: ${ev.total}, done.\n`);
|
|
4476
|
+
streamLine(`remote: Counting objects: 100% (${ev.total}/${ev.total}), done.\n`);
|
|
4477
|
+
}
|
|
4478
|
+
if (ev.phase === 'downloading' && typeof ev.total === 'number' && ev.total > 0 && typeof ev.loaded === 'number' && ev.loaded < ev.total) {
|
|
4479
|
+
const pct = Math.min(100, Math.max(0, Math.floor((ev.loaded / ev.total) * 100)));
|
|
4480
|
+
if (pct >= lastProgressPct + 10) {
|
|
4481
|
+
lastProgressPct = pct;
|
|
4482
|
+
streamLine(`Receiving objects: ${pct}% (${ev.loaded}/${ev.total})\n`);
|
|
4483
|
+
}
|
|
4484
|
+
}
|
|
4485
|
+
if (ev.phase === 'mounting') {
|
|
4486
|
+
streamLine(`Resolving deltas: 100% (${ev.total || 0}/${ev.total || 0}), done.\n`);
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
4440
4489
|
});
|
|
4441
4490
|
|
|
4442
4491
|
gitState.branch = result.branch;
|
|
@@ -4450,6 +4499,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
4450
4499
|
|
|
4451
4500
|
const count = Math.max(1, result.filesWritten);
|
|
4452
4501
|
const kb = Math.max(0.1, result.totalBytes / 1024).toFixed(1);
|
|
4502
|
+
streamLine(`Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`);
|
|
4453
4503
|
const stdout =
|
|
4454
4504
|
`Cloning into '${dirDisplayName}'...\n` +
|
|
4455
4505
|
`remote: Enumerating objects: ${count}, done.\n` +
|
|
@@ -4458,6 +4508,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
4458
4508
|
return { code: 0, stdout, stderr: '' };
|
|
4459
4509
|
} catch (err) {
|
|
4460
4510
|
const msg = err && err.message ? err.message : String(err);
|
|
4511
|
+
if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
|
|
4461
4512
|
return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
4462
4513
|
}
|
|
4463
4514
|
}
|