@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.esm.js
CHANGED
|
@@ -9476,6 +9476,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9476
9476
|
}
|
|
9477
9477
|
|
|
9478
9478
|
async function cloneGitHubRepository(repoInput, vfs, options = {}) {
|
|
9479
|
+
const onProgress = typeof options.onProgress === 'function' ? options.onProgress : null;
|
|
9480
|
+
if (onProgress) {
|
|
9481
|
+
onProgress({ phase: 'connecting', message: `Connecting to repository '${repoInput}'...` });
|
|
9482
|
+
}
|
|
9479
9483
|
const parsed = parseGitHubRepoUrl(repoInput);
|
|
9480
9484
|
if (!parsed) {
|
|
9481
9485
|
throw new Error(`fatal: repository '${repoInput}' does not exist or is not a valid GitHub repository URL`);
|
|
@@ -9499,6 +9503,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9499
9503
|
let rawTreeEntries = null;
|
|
9500
9504
|
let repoNotFound = false;
|
|
9501
9505
|
|
|
9506
|
+
if (onProgress) {
|
|
9507
|
+
onProgress({ phase: 'metadata', message: `Fetching repository metadata for ${owner}/${repo}...` });
|
|
9508
|
+
}
|
|
9509
|
+
|
|
9502
9510
|
// Strategy A: GitHub REST API (with automatic fallback if rate-limited)
|
|
9503
9511
|
try {
|
|
9504
9512
|
if (!resolvedBranch) {
|
|
@@ -9603,6 +9611,11 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9603
9611
|
|
|
9604
9612
|
filtered.sort((a, b) => a.priority - b.priority || a.destPath.localeCompare(b.destPath));
|
|
9605
9613
|
const selectedFiles = filtered.slice(0, maxFiles);
|
|
9614
|
+
const totalToDownload = selectedFiles.length;
|
|
9615
|
+
|
|
9616
|
+
if (onProgress) {
|
|
9617
|
+
onProgress({ phase: 'downloading', message: `Downloading files (0/${totalToDownload})...`, loaded: 0, total: totalToDownload });
|
|
9618
|
+
}
|
|
9606
9619
|
|
|
9607
9620
|
if (!vfs.existsSync(targetDir)) {
|
|
9608
9621
|
vfs.mkdirSync(targetDir, { recursive: true });
|
|
@@ -9648,6 +9661,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9648
9661
|
headSnapshot[entry.destPath] = text;
|
|
9649
9662
|
filesWritten++;
|
|
9650
9663
|
totalBytes += text.length;
|
|
9664
|
+
if (onProgress) {
|
|
9665
|
+
onProgress({ phase: 'downloading', message: `Downloading files (${filesWritten}/${totalToDownload}): ${entry.destPath}`, loaded: filesWritten, total: totalToDownload });
|
|
9666
|
+
}
|
|
9651
9667
|
if (typeof options.onFile === 'function') {
|
|
9652
9668
|
options.onFile(absPath, text, entry.destPath);
|
|
9653
9669
|
}
|
|
@@ -9656,6 +9672,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9656
9672
|
);
|
|
9657
9673
|
}
|
|
9658
9674
|
|
|
9675
|
+
if (onProgress) {
|
|
9676
|
+
onProgress({ phase: 'mounting', message: `Mounting files and writing Git metadata into ${targetDir}...`, loaded: filesWritten, total: totalToDownload });
|
|
9677
|
+
}
|
|
9678
|
+
|
|
9659
9679
|
// Write .git metadata inside targetDir
|
|
9660
9680
|
const gitDir = PosixPath.join(targetDir, '.git');
|
|
9661
9681
|
if (!vfs.existsSync(gitDir)) {
|
|
@@ -9704,6 +9724,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9704
9724
|
];
|
|
9705
9725
|
}
|
|
9706
9726
|
|
|
9727
|
+
if (onProgress) {
|
|
9728
|
+
onProgress({ phase: 'ready', message: `Repository cloned successfully (${filesWritten} files).`, loaded: filesWritten, total: totalToDownload });
|
|
9729
|
+
}
|
|
9730
|
+
|
|
9707
9731
|
return {
|
|
9708
9732
|
owner,
|
|
9709
9733
|
repo,
|
|
@@ -11903,12 +11927,37 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
11903
11927
|
dirDisplayName = parsed.repo;
|
|
11904
11928
|
}
|
|
11905
11929
|
|
|
11930
|
+
// Stream clone progress to the terminal as it happens (no end-of-run buffering).
|
|
11931
|
+
const canStream = typeof ctx.onStdout === 'function';
|
|
11932
|
+
const streamLine = (text) => { if (canStream && text) ctx.onStdout(text); };
|
|
11933
|
+
streamLine(`Cloning into '${dirDisplayName}'...\n`);
|
|
11934
|
+
let enumeratedEmitted = false;
|
|
11935
|
+
let lastProgressPct = -1;
|
|
11936
|
+
|
|
11906
11937
|
try {
|
|
11907
11938
|
const result = await cloneGitHubRepository(repoArg, ctx.vfs, {
|
|
11908
11939
|
targetDir,
|
|
11909
11940
|
branch: branchOpt,
|
|
11910
11941
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
11911
|
-
onFile: (absPath) => ctx.emitMutation('create', absPath)
|
|
11942
|
+
onFile: (absPath) => ctx.emitMutation('create', absPath),
|
|
11943
|
+
onProgress: (ev) => {
|
|
11944
|
+
if (!ev) return;
|
|
11945
|
+
if (ev.phase === 'downloading' && !enumeratedEmitted && typeof ev.total === 'number' && ev.total > 0) {
|
|
11946
|
+
enumeratedEmitted = true;
|
|
11947
|
+
streamLine(`remote: Enumerating objects: ${ev.total}, done.\n`);
|
|
11948
|
+
streamLine(`remote: Counting objects: 100% (${ev.total}/${ev.total}), done.\n`);
|
|
11949
|
+
}
|
|
11950
|
+
if (ev.phase === 'downloading' && typeof ev.total === 'number' && ev.total > 0 && typeof ev.loaded === 'number' && ev.loaded < ev.total) {
|
|
11951
|
+
const pct = Math.min(100, Math.max(0, Math.floor((ev.loaded / ev.total) * 100)));
|
|
11952
|
+
if (pct >= lastProgressPct + 10) {
|
|
11953
|
+
lastProgressPct = pct;
|
|
11954
|
+
streamLine(`Receiving objects: ${pct}% (${ev.loaded}/${ev.total})\n`);
|
|
11955
|
+
}
|
|
11956
|
+
}
|
|
11957
|
+
if (ev.phase === 'mounting') {
|
|
11958
|
+
streamLine(`Resolving deltas: 100% (${ev.total || 0}/${ev.total || 0}), done.\n`);
|
|
11959
|
+
}
|
|
11960
|
+
}
|
|
11912
11961
|
});
|
|
11913
11962
|
|
|
11914
11963
|
gitState.branch = result.branch;
|
|
@@ -11922,6 +11971,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
11922
11971
|
|
|
11923
11972
|
const count = Math.max(1, result.filesWritten);
|
|
11924
11973
|
const kb = Math.max(0.1, result.totalBytes / 1024).toFixed(1);
|
|
11974
|
+
streamLine(`Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`);
|
|
11925
11975
|
const stdout =
|
|
11926
11976
|
`Cloning into '${dirDisplayName}'...\n` +
|
|
11927
11977
|
`remote: Enumerating objects: ${count}, done.\n` +
|
|
@@ -11930,6 +11980,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
11930
11980
|
return { code: 0, stdout, stderr: '' };
|
|
11931
11981
|
} catch (err) {
|
|
11932
11982
|
const msg = err && err.message ? err.message : String(err);
|
|
11983
|
+
if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
|
|
11933
11984
|
return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
11934
11985
|
}
|
|
11935
11986
|
}
|
|
@@ -16074,6 +16125,8 @@ declare module 'bun:sqlite' {
|
|
|
16074
16125
|
this.completedSteps = new Set(this.savedState.completedSteps || []);
|
|
16075
16126
|
this.folders = new Set(this.savedState?.folders || []);
|
|
16076
16127
|
this.collapsedFolders = new Set(this.savedState?.collapsedFolders || []);
|
|
16128
|
+
this.explorerFolder = this.savedState?.explorerFolder || ''; // '' = workspace root, else folder path scope
|
|
16129
|
+
this.folderSwitcherOpen = false;
|
|
16077
16130
|
this.creatingItem = null; // { type: 'file' | 'folder', parentFolder: string } | null
|
|
16078
16131
|
this.renamingItem = null;
|
|
16079
16132
|
this._draggedFile = null;
|
|
@@ -16409,7 +16462,8 @@ declare module 'bun:sqlite' {
|
|
|
16409
16462
|
openTabs: Array.isArray(this.openTabs) ? [...this.openTabs] : undefined,
|
|
16410
16463
|
activeFile: this.activeFile,
|
|
16411
16464
|
folders: Array.from(this.folders || []),
|
|
16412
|
-
collapsedFolders: Array.from(this.collapsedFolders || [])
|
|
16465
|
+
collapsedFolders: Array.from(this.collapsedFolders || []),
|
|
16466
|
+
explorerFolder: this.explorerFolder || ''
|
|
16413
16467
|
};
|
|
16414
16468
|
this.savedState = state;
|
|
16415
16469
|
if (this.options && this.options.persistState === false) {
|
|
@@ -16853,23 +16907,59 @@ declare module 'bun:sqlite' {
|
|
|
16853
16907
|
</button>
|
|
16854
16908
|
` : '';
|
|
16855
16909
|
|
|
16856
|
-
|
|
16910
|
+
const folderOptions = this._listWorkspaceFolders();
|
|
16911
|
+
const scope = this.explorerFolder || '';
|
|
16912
|
+
const scopeLabel = scope ? scope.split('/').pop() : 'workspace';
|
|
16913
|
+
|
|
16914
|
+
const switcherHtml = `
|
|
16915
|
+
<div class="codelab-folder-switcher ${this.folderSwitcherOpen ? 'is-open' : ''}">
|
|
16916
|
+
<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">
|
|
16917
|
+
${CL_ICONS.folder}
|
|
16918
|
+
<span class="codelab-folder-switcher__label">${escapeHtml(scopeLabel)}</span>
|
|
16919
|
+
${CL_ICONS.chevronDown}
|
|
16920
|
+
</button>
|
|
16921
|
+
${this.folderSwitcherOpen ? `
|
|
16922
|
+
<div class="codelab-folder-switcher__menu" role="menu" aria-label="Workspace folders">
|
|
16923
|
+
<div class="codelab-folder-switcher__section">Switch Folder</div>
|
|
16924
|
+
<button type="button" role="menuitem" class="codelab-folder-switcher__option ${!scope ? 'active' : ''}" data-cl-folder-option="">
|
|
16925
|
+
<span class="codelab-folder-switcher__icon">${CL_ICONS.folder}</span>
|
|
16926
|
+
<span class="codelab-folder-switcher__name">workspace</span>
|
|
16927
|
+
<span class="codelab-folder-switcher__path">/</span>
|
|
16928
|
+
</button>
|
|
16929
|
+
${folderOptions.map(f => {
|
|
16930
|
+
const fDepth = f.split('/').length;
|
|
16931
|
+
const fName = f.split('/').pop();
|
|
16932
|
+
return `
|
|
16933
|
+
<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;">
|
|
16934
|
+
<span class="codelab-folder-switcher__icon">${CL_ICONS.folder}</span>
|
|
16935
|
+
<span class="codelab-folder-switcher__name">${escapeHtml(fName)}</span>
|
|
16936
|
+
<span class="codelab-folder-switcher__path">${escapeHtml(f)}</span>
|
|
16937
|
+
</button>
|
|
16938
|
+
`;
|
|
16939
|
+
}).join('')}
|
|
16940
|
+
${folderOptions.length ? '' : '<div class="codelab-folder-switcher__empty">No subfolders yet</div>'}
|
|
16941
|
+
</div>
|
|
16942
|
+
` : ''}
|
|
16943
|
+
</div>
|
|
16944
|
+
`;
|
|
16945
|
+
|
|
16946
|
+
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>`;
|
|
16857
16947
|
|
|
16858
16948
|
if (this.activeFile) {
|
|
16859
16949
|
const segments = this.activeFile.split('/');
|
|
16860
16950
|
for (let i = 0; i < segments.length - 1; i++) {
|
|
16861
16951
|
const folderPath = segments.slice(0, i + 1).join('/');
|
|
16862
|
-
pathHtml += `<span class="codelab-
|
|
16863
|
-
pathHtml += `<button type="button" class="codelab-
|
|
16952
|
+
pathHtml += `<span class="codelab-breadcrumbs__sep" aria-hidden="true">›</span>`;
|
|
16953
|
+
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>`;
|
|
16864
16954
|
}
|
|
16865
16955
|
const fileName = segments[segments.length - 1];
|
|
16866
|
-
pathHtml += `<span class="codelab-
|
|
16867
|
-
pathHtml += `<button type="button" class="codelab-
|
|
16956
|
+
pathHtml += `<span class="codelab-breadcrumbs__sep" aria-hidden="true">›</span>`;
|
|
16957
|
+
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>`;
|
|
16868
16958
|
|
|
16869
16959
|
const symbol = this._detectActiveSymbol(this.activeFile);
|
|
16870
16960
|
if (symbol) {
|
|
16871
|
-
pathHtml += `<span class="codelab-
|
|
16872
|
-
pathHtml += `<span class="codelab-
|
|
16961
|
+
pathHtml += `<span class="codelab-breadcrumbs__sep" aria-hidden="true">›</span>`;
|
|
16962
|
+
pathHtml += `<span class="codelab-breadcrumbs__item codelab-breadcrumbs__item--symbol" data-cl-breadcrumb-symbol="${escapeHtml(symbol)}">ƒ ${escapeHtml(symbol)}</span>`;
|
|
16873
16963
|
}
|
|
16874
16964
|
}
|
|
16875
16965
|
|
|
@@ -16890,7 +16980,10 @@ declare module 'bun:sqlite' {
|
|
|
16890
16980
|
|
|
16891
16981
|
host.innerHTML = `
|
|
16892
16982
|
${expandBtnHtml}
|
|
16893
|
-
<div class="codelab-
|
|
16983
|
+
<div class="codelab-breadcrumbs__left">
|
|
16984
|
+
${switcherHtml}
|
|
16985
|
+
<div class="codelab-breadcrumbs__path">${pathHtml}</div>
|
|
16986
|
+
</div>
|
|
16894
16987
|
<div class="codelab-breadcrumbs__actions">
|
|
16895
16988
|
${diffBtnHtml}
|
|
16896
16989
|
<button type="button" class="codelab-breadcrumb__btn" data-action="command-palette" data-cl-action="command-palette" title="Open Command Palette (⌘⇧P)">
|
|
@@ -17133,6 +17226,36 @@ declare module 'bun:sqlite' {
|
|
|
17133
17226
|
return rootNode;
|
|
17134
17227
|
}
|
|
17135
17228
|
|
|
17229
|
+
_listWorkspaceFolders() {
|
|
17230
|
+
const set = new Set();
|
|
17231
|
+
if (this.folders) {
|
|
17232
|
+
for (const f of this.folders) {
|
|
17233
|
+
if (f) set.add(f);
|
|
17234
|
+
}
|
|
17235
|
+
}
|
|
17236
|
+
for (const filePath of this._orderedFileNames()) {
|
|
17237
|
+
const idx = filePath.lastIndexOf('/');
|
|
17238
|
+
if (idx <= 0) continue;
|
|
17239
|
+
const parts = filePath.slice(0, idx).split('/');
|
|
17240
|
+
let running = '';
|
|
17241
|
+
for (const p of parts) {
|
|
17242
|
+
running = running ? `${running}/${p}` : p;
|
|
17243
|
+
set.add(running);
|
|
17244
|
+
}
|
|
17245
|
+
}
|
|
17246
|
+
return Array.from(set).sort((a, b) => a.localeCompare(b));
|
|
17247
|
+
}
|
|
17248
|
+
|
|
17249
|
+
_resolveFolderNode(rootNode, folderPath) {
|
|
17250
|
+
if (!rootNode || !folderPath) return null;
|
|
17251
|
+
let current = rootNode;
|
|
17252
|
+
for (const seg of folderPath.split('/')) {
|
|
17253
|
+
if (!current || !current.folders || !current.folders.has(seg)) return null;
|
|
17254
|
+
current = current.folders.get(seg);
|
|
17255
|
+
}
|
|
17256
|
+
return current || null;
|
|
17257
|
+
}
|
|
17258
|
+
|
|
17136
17259
|
_renderFileLists() {
|
|
17137
17260
|
const explorerEl = this.container.querySelector('#cl-explorer-list');
|
|
17138
17261
|
const tabsEl = this.container.querySelector('#cl-file-tabs');
|
|
@@ -17141,6 +17264,12 @@ declare module 'bun:sqlite' {
|
|
|
17141
17264
|
if (!explorerEl || !tabsEl) return;
|
|
17142
17265
|
|
|
17143
17266
|
const treeRoot = this._buildFileTree();
|
|
17267
|
+
if (this.explorerFolder && !this._resolveFolderNode(treeRoot, this.explorerFolder)) {
|
|
17268
|
+
this.explorerFolder = '';
|
|
17269
|
+
}
|
|
17270
|
+
const scope = this.explorerFolder || '';
|
|
17271
|
+
const renderRoot = scope ? this._resolveFolderNode(treeRoot, scope) : treeRoot;
|
|
17272
|
+
const rootParent = scope;
|
|
17144
17273
|
let treeHtml = '';
|
|
17145
17274
|
|
|
17146
17275
|
const renderNode = (node, depth) => {
|
|
@@ -17195,7 +17324,7 @@ declare module 'bun:sqlite' {
|
|
|
17195
17324
|
}
|
|
17196
17325
|
};
|
|
17197
17326
|
|
|
17198
|
-
if (this.creatingItem && this.creatingItem.parentFolder ===
|
|
17327
|
+
if (this.creatingItem && this.creatingItem.parentFolder === rootParent) {
|
|
17199
17328
|
treeHtml += `
|
|
17200
17329
|
<div class="codelab-tree-create-row" style="padding-left: 10px;">
|
|
17201
17330
|
<span class="codelab-tree-create-icon">${this.creatingItem.type === 'folder' ? CL_ICONS.folder : CL_ICONS.file}</span>
|
|
@@ -17204,7 +17333,16 @@ declare module 'bun:sqlite' {
|
|
|
17204
17333
|
`;
|
|
17205
17334
|
}
|
|
17206
17335
|
|
|
17207
|
-
|
|
17336
|
+
if (scope) {
|
|
17337
|
+
treeHtml += `
|
|
17338
|
+
<button type="button" class="codelab-scope-up" data-cl-folder-option="" title="Back to workspace root">
|
|
17339
|
+
<span class="codelab-scope-up__arrow">←</span>
|
|
17340
|
+
<span class="codelab-scope-up__label">workspace</span>
|
|
17341
|
+
</button>
|
|
17342
|
+
`;
|
|
17343
|
+
}
|
|
17344
|
+
|
|
17345
|
+
renderNode(renderRoot, 0);
|
|
17208
17346
|
explorerEl.innerHTML = treeHtml;
|
|
17209
17347
|
|
|
17210
17348
|
// Attach file drag events
|
|
@@ -18765,6 +18903,29 @@ declare module 'bun:sqlite' {
|
|
|
18765
18903
|
this._portToasts.delete(p);
|
|
18766
18904
|
}
|
|
18767
18905
|
|
|
18906
|
+
_showToast(message, kind = 'info') {
|
|
18907
|
+
const toastHost = this.container ? this.container.querySelector('#cl-toast-container') : null;
|
|
18908
|
+
if (!toastHost || typeof document === 'undefined') return;
|
|
18909
|
+
const toast = document.createElement('div');
|
|
18910
|
+
toast.className = `codelab-toast codelab-toast--${kind === 'error' ? 'error' : 'info'}`;
|
|
18911
|
+
const icon = kind === 'error' ? (CL_ICONS.x || '⚠') : (CL_ICONS.externalLink || CL_ICONS.radio || '');
|
|
18912
|
+
toast.innerHTML = `
|
|
18913
|
+
<div class="codelab-toast__icon">${icon}</div>
|
|
18914
|
+
<div class="codelab-toast__body">
|
|
18915
|
+
<div class="codelab-toast__meta">${escapeHtml(message)}</div>
|
|
18916
|
+
</div>
|
|
18917
|
+
<button type="button" class="codelab-toast__close" aria-label="Dismiss notification">${CL_ICONS.x || '×'}</button>
|
|
18918
|
+
`;
|
|
18919
|
+
const closeBtn = toast.querySelector('.codelab-toast__close');
|
|
18920
|
+
const remove = () => {
|
|
18921
|
+
if (typeof toast.remove === 'function') toast.remove();
|
|
18922
|
+
else if (toast.parentNode) toast.parentNode.removeChild(toast);
|
|
18923
|
+
};
|
|
18924
|
+
if (closeBtn) closeBtn.addEventListener('click', remove);
|
|
18925
|
+
toastHost.appendChild(toast);
|
|
18926
|
+
setTimeout(remove, 5000);
|
|
18927
|
+
}
|
|
18928
|
+
|
|
18768
18929
|
_registerPreviewServiceWorker() {
|
|
18769
18930
|
if (typeof navigator === 'undefined' || !navigator.serviceWorker || typeof navigator.serviceWorker.register !== 'function') return;
|
|
18770
18931
|
const url = (this.options && this.options.previewSwUrl) || 'preview-sw.js';
|
|
@@ -18855,9 +19016,53 @@ declare module 'bun:sqlite' {
|
|
|
18855
19016
|
_previewGo(urlOrPath) {
|
|
18856
19017
|
let url = String(urlOrPath || '').trim();
|
|
18857
19018
|
if (!url) return Promise.resolve();
|
|
19019
|
+
|
|
19020
|
+
const loopbackPort = this.previewState.port || this._firstListeningPort() || 3000;
|
|
19021
|
+
const localHostRe = /^(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(:\d+)?(\/.*)?$/i;
|
|
19022
|
+
|
|
19023
|
+
// Normalize the input into an absolute URL.
|
|
18858
19024
|
if (!/^https?:\/\//i.test(url)) {
|
|
18859
|
-
|
|
19025
|
+
if (localHostRe.test(url)) {
|
|
19026
|
+
url = `http://${url}`;
|
|
19027
|
+
} else if (/^[a-z0-9-]+(\.[a-z0-9-]+)+(:\d+)?([/?#].*)?$/i.test(url)) {
|
|
19028
|
+
// Bare public domain, e.g. "google.com" or "example.com/path".
|
|
19029
|
+
url = `https://${url}`;
|
|
19030
|
+
} else {
|
|
19031
|
+
url = `http://127.0.0.1:${loopbackPort}${url.startsWith('/') ? '' : '/'}${url}`;
|
|
19032
|
+
}
|
|
19033
|
+
}
|
|
19034
|
+
|
|
19035
|
+
// Public (non-loopback) URLs cannot be served by the virtual loopback Service
|
|
19036
|
+
// Worker, so open them in a real browser tab instead of the in-browser frame.
|
|
19037
|
+
let isExternal = false;
|
|
19038
|
+
try {
|
|
19039
|
+
const u = new URL(url);
|
|
19040
|
+
const host = (u.hostname || '').toLowerCase();
|
|
19041
|
+
isExternal = !(host === 'localhost' || host === '127.0.0.1' || host === '0.0.0.0' || host === '::1' || host === '[::1]');
|
|
19042
|
+
} catch (_) { isExternal = false; }
|
|
19043
|
+
|
|
19044
|
+
if (isExternal) {
|
|
19045
|
+
let opened = false;
|
|
19046
|
+
if (typeof window !== 'undefined' && typeof window.open === 'function') {
|
|
19047
|
+
try {
|
|
19048
|
+
const win = window.open(url, '_blank');
|
|
19049
|
+
if (win) {
|
|
19050
|
+
try { win.opener = null; } catch (_) {}
|
|
19051
|
+
opened = true;
|
|
19052
|
+
}
|
|
19053
|
+
} catch (_) { opened = false; }
|
|
19054
|
+
}
|
|
19055
|
+
if (typeof this._showToast === 'function') {
|
|
19056
|
+
this._showToast(
|
|
19057
|
+
opened ? `Opened ${url} in a new tab` : `Could not open ${url} — allow pop-ups and try again`,
|
|
19058
|
+
opened ? 'info' : 'error'
|
|
19059
|
+
);
|
|
19060
|
+
}
|
|
19061
|
+
const inputEl = this.container.querySelector('#cl-preview-url-input');
|
|
19062
|
+
if (inputEl) inputEl.value = this.previewState.url || inputEl.value;
|
|
19063
|
+
return Promise.resolve();
|
|
18860
19064
|
}
|
|
19065
|
+
|
|
18861
19066
|
let port = this.previewState.port;
|
|
18862
19067
|
let path = '/';
|
|
18863
19068
|
try {
|
|
@@ -18967,7 +19172,7 @@ declare module 'bun:sqlite' {
|
|
|
18967
19172
|
<button type="button" class="codelab-preview-btn" data-cl-action="preview-reload" title="Reload">${CL_ICONS.refresh || '⟳'}</button>
|
|
18968
19173
|
</div>
|
|
18969
19174
|
<select class="codelab-preview-port-select" data-cl-action="preview-port-change" aria-label="Preview port">${portOptions}</select>
|
|
18970
|
-
<input type="text" class="codelab-preview-url-input" id="cl-preview-url-input" value="${escapeHtml(this.previewState.url)}" placeholder="
|
|
19175
|
+
<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" />
|
|
18971
19176
|
<div class="codelab-preview-modes">
|
|
18972
19177
|
<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>
|
|
18973
19178
|
<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>
|
|
@@ -19586,6 +19791,11 @@ declare module 'bun:sqlite' {
|
|
|
19586
19791
|
this._previewGo(previewInput.value);
|
|
19587
19792
|
return;
|
|
19588
19793
|
}
|
|
19794
|
+
if (e.key === 'Escape' && this.folderSwitcherOpen) {
|
|
19795
|
+
this.folderSwitcherOpen = false;
|
|
19796
|
+
this._renderBreadcrumbs();
|
|
19797
|
+
return;
|
|
19798
|
+
}
|
|
19589
19799
|
if (e.key === 'F1' || ((e.metaKey || e.ctrlKey) && e.shiftKey && keyLower === 'p')) {
|
|
19590
19800
|
e.preventDefault();
|
|
19591
19801
|
this.openCommandPalette('commands');
|
|
@@ -19786,12 +19996,39 @@ declare module 'bun:sqlite' {
|
|
|
19786
19996
|
return;
|
|
19787
19997
|
}
|
|
19788
19998
|
|
|
19999
|
+
const fsToggle = e.target.closest('[data-cl-action="toggle-folder-switcher"]');
|
|
20000
|
+
if (fsToggle) {
|
|
20001
|
+
e.stopPropagation();
|
|
20002
|
+
this.folderSwitcherOpen = !this.folderSwitcherOpen;
|
|
20003
|
+
this._renderBreadcrumbs();
|
|
20004
|
+
return;
|
|
20005
|
+
}
|
|
20006
|
+
|
|
20007
|
+
const fsOption = e.target.closest('[data-cl-folder-option]');
|
|
20008
|
+
if (fsOption) {
|
|
20009
|
+
e.stopPropagation();
|
|
20010
|
+
const scopeVal = fsOption.dataset.clFolderOption || '';
|
|
20011
|
+
this.explorerFolder = scopeVal;
|
|
20012
|
+
if (scopeVal) this.collapsedFolders.delete(scopeVal);
|
|
20013
|
+
this.folderSwitcherOpen = false;
|
|
20014
|
+
this._renderFileLists();
|
|
20015
|
+
this._renderBreadcrumbs();
|
|
20016
|
+
return;
|
|
20017
|
+
}
|
|
20018
|
+
|
|
20019
|
+
if (this.folderSwitcherOpen && !e.target.closest('.codelab-folder-switcher')) {
|
|
20020
|
+
this.folderSwitcherOpen = false;
|
|
20021
|
+
this._renderBreadcrumbs();
|
|
20022
|
+
}
|
|
20023
|
+
|
|
19789
20024
|
const bcFolder = e.target.closest('[data-cl-breadcrumb-folder]');
|
|
19790
20025
|
if (bcFolder) {
|
|
19791
20026
|
const folder = bcFolder.dataset.clBreadcrumbFolder;
|
|
19792
20027
|
if (folder) {
|
|
19793
20028
|
this.collapsedFolders.delete(folder);
|
|
20029
|
+
this.explorerFolder = folder;
|
|
19794
20030
|
this._renderFileLists();
|
|
20031
|
+
this._renderBreadcrumbs();
|
|
19795
20032
|
}
|
|
19796
20033
|
return;
|
|
19797
20034
|
}
|
|
@@ -19926,10 +20163,10 @@ declare module 'bun:sqlite' {
|
|
|
19926
20163
|
this.isCreatingFile = true;
|
|
19927
20164
|
this._renderFileLists();
|
|
19928
20165
|
} else if (action === 'new-file-root') {
|
|
19929
|
-
this.creatingItem = { type: 'file', parentFolder: '' };
|
|
20166
|
+
this.creatingItem = { type: 'file', parentFolder: this.explorerFolder || '' };
|
|
19930
20167
|
this._renderFileLists();
|
|
19931
20168
|
} else if (action === 'new-folder-root') {
|
|
19932
|
-
this.creatingItem = { type: 'folder', parentFolder: '' };
|
|
20169
|
+
this.creatingItem = { type: 'folder', parentFolder: this.explorerFolder || '' };
|
|
19933
20170
|
this._renderFileLists();
|
|
19934
20171
|
} else if (action === 'new-file-folder') {
|
|
19935
20172
|
const folder = actionBtn.dataset.clFolder || '';
|