@innovatorved/code-lab 0.1.0 → 0.1.2

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.
@@ -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
- let pathHtml = `<button type="button" class="codelab-breadcrumb__item codelab-breadcrumb__root" data-action="command-palette-files" data-cl-action="command-palette-files" title="Quick Open File (⌘P)">workspace</button>`;
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-breadcrumb__sep" aria-hidden="true">›</span>`;
16863
- pathHtml += `<button type="button" class="codelab-breadcrumb__item codelab-breadcrumb__folder" data-cl-breadcrumb-folder="${escapeHtml(folderPath)}" data-folder="${escapeHtml(folderPath)}">${escapeHtml(segments[i])}</button>`;
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-breadcrumb__sep" aria-hidden="true">›</span>`;
16867
- pathHtml += `<button type="button" class="codelab-breadcrumb__item codelab-breadcrumb__file active" data-cl-breadcrumb-file="${escapeHtml(this.activeFile)}" data-file="${escapeHtml(this.activeFile)}">${escapeHtml(fileName)}</button>`;
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-breadcrumb__sep" aria-hidden="true">›</span>`;
16872
- pathHtml += `<span class="codelab-breadcrumb__symbol" data-cl-breadcrumb-symbol="${escapeHtml(symbol)}">ƒ ${escapeHtml(symbol)}</span>`;
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-breadcrumbs__path">${pathHtml}</div>
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
- renderNode(treeRoot, 0);
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
@@ -17970,6 +18108,39 @@ declare module 'bun:sqlite' {
17970
18108
  const termSurface = this.container ? this.container.querySelector('#cl-terminal-surface') : null;
17971
18109
  const drawerBody = this.container ? this.container.querySelector('.codelab-drawer__body') : null;
17972
18110
 
18111
+ // The workbench owns live terminal rendering. Only defer when an attached PTY
18112
+ // engine is itself rendering into the DOM (it is created with a null container in
18113
+ // production, so this remains the sole renderer there).
18114
+ const ptyOwnsDom = Boolean(this.ptyEngine && this.ptyEngine.container);
18115
+ const canPatchDom = Boolean(termLogEl && typeof document !== 'undefined' && !ptyOwnsDom);
18116
+
18117
+ // Write a single logical line into the live terminal DOM immediately, so output
18118
+ // streams in as it is produced instead of appearing only when the command ends and
18119
+ // the whole drawer is re-rendered. Reuses the current partial-line element when it
18120
+ // is still attached (carriage-return overwrites / keep-alive updates).
18121
+ const patchLineInDom = (text) => {
18122
+ if (!canPatchDom) return;
18123
+ const html = ansiToHtml ? ansiToHtml(text) : escapeHtml(text);
18124
+ if (this._activeStreamEl && this._activeStreamEl.parentNode === termLogEl) {
18125
+ this._activeStreamEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
18126
+ this._activeStreamEl.innerHTML = html;
18127
+ } else {
18128
+ const newEl = document.createElement('div');
18129
+ newEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
18130
+ newEl.innerHTML = html;
18131
+ termLogEl.appendChild(newEl);
18132
+ this._activeStreamEl = newEl;
18133
+ }
18134
+ };
18135
+
18136
+ // A newline completes the current line: commit it to the log + DOM, then begin a fresh line.
18137
+ const commitActiveLine = () => {
18138
+ this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
18139
+ patchLineInDom(this._activeStreamLine);
18140
+ this._activeStreamLine = '';
18141
+ this._activeStreamEl = null;
18142
+ };
18143
+
17973
18144
  let i = 0;
17974
18145
  while (i < rawText.length) {
17975
18146
  if (rawText.startsWith('\x1b[2K', i)) {
@@ -18004,20 +18175,22 @@ declare module 'bun:sqlite' {
18004
18175
  const ch = rawText[i];
18005
18176
  if (ch === '\r') {
18006
18177
  if (i + 1 < rawText.length && rawText[i + 1] === '\n') {
18007
- this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
18008
- this._activeStreamLine = '';
18009
- this._activeStreamEl = null;
18178
+ commitActiveLine();
18010
18179
  i += 2;
18011
18180
  continue;
18012
18181
  } else {
18182
+ // Bare carriage return: flush the current text into the active line, then
18183
+ // keep overwriting that same DOM node (no extra line is appended).
18184
+ const rendered = this._activeStreamLine;
18185
+ if (rendered || this._activeStreamEl) {
18186
+ patchLineInDom(rendered);
18187
+ }
18013
18188
  this._activeStreamLine = '';
18014
18189
  i++;
18015
18190
  continue;
18016
18191
  }
18017
18192
  } else if (ch === '\n') {
18018
- this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
18019
- this._activeStreamLine = '';
18020
- this._activeStreamEl = null;
18193
+ commitActiveLine();
18021
18194
  i++;
18022
18195
  continue;
18023
18196
  } else {
@@ -18026,20 +18199,9 @@ declare module 'bun:sqlite' {
18026
18199
  }
18027
18200
  }
18028
18201
 
18029
- if (termLogEl && typeof document !== 'undefined') {
18030
- if (this._activeStreamLine) {
18031
- const formattedHtml = ansiToHtml ? ansiToHtml(this._activeStreamLine) : escapeHtml(this._activeStreamLine);
18032
- if (this._activeStreamEl && this._activeStreamEl.parentNode === termLogEl) {
18033
- this._activeStreamEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
18034
- this._activeStreamEl.innerHTML = formattedHtml;
18035
- } else {
18036
- const newEl = document.createElement('div');
18037
- newEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
18038
- newEl.innerHTML = formattedHtml;
18039
- termLogEl.appendChild(newEl);
18040
- this._activeStreamEl = newEl;
18041
- }
18042
- }
18202
+ // Render the still-open partial line so incremental progress stays visible.
18203
+ if (this._activeStreamLine) {
18204
+ patchLineInDom(this._activeStreamLine);
18043
18205
  }
18044
18206
 
18045
18207
  if (termSurface) {
@@ -18765,6 +18927,29 @@ declare module 'bun:sqlite' {
18765
18927
  this._portToasts.delete(p);
18766
18928
  }
18767
18929
 
18930
+ _showToast(message, kind = 'info') {
18931
+ const toastHost = this.container ? this.container.querySelector('#cl-toast-container') : null;
18932
+ if (!toastHost || typeof document === 'undefined') return;
18933
+ const toast = document.createElement('div');
18934
+ toast.className = `codelab-toast codelab-toast--${kind === 'error' ? 'error' : 'info'}`;
18935
+ const icon = kind === 'error' ? (CL_ICONS.x || '⚠') : (CL_ICONS.externalLink || CL_ICONS.radio || '');
18936
+ toast.innerHTML = `
18937
+ <div class="codelab-toast__icon">${icon}</div>
18938
+ <div class="codelab-toast__body">
18939
+ <div class="codelab-toast__meta">${escapeHtml(message)}</div>
18940
+ </div>
18941
+ <button type="button" class="codelab-toast__close" aria-label="Dismiss notification">${CL_ICONS.x || '×'}</button>
18942
+ `;
18943
+ const closeBtn = toast.querySelector('.codelab-toast__close');
18944
+ const remove = () => {
18945
+ if (typeof toast.remove === 'function') toast.remove();
18946
+ else if (toast.parentNode) toast.parentNode.removeChild(toast);
18947
+ };
18948
+ if (closeBtn) closeBtn.addEventListener('click', remove);
18949
+ toastHost.appendChild(toast);
18950
+ setTimeout(remove, 5000);
18951
+ }
18952
+
18768
18953
  _registerPreviewServiceWorker() {
18769
18954
  if (typeof navigator === 'undefined' || !navigator.serviceWorker || typeof navigator.serviceWorker.register !== 'function') return;
18770
18955
  const url = (this.options && this.options.previewSwUrl) || 'preview-sw.js';
@@ -18855,9 +19040,53 @@ declare module 'bun:sqlite' {
18855
19040
  _previewGo(urlOrPath) {
18856
19041
  let url = String(urlOrPath || '').trim();
18857
19042
  if (!url) return Promise.resolve();
19043
+
19044
+ const loopbackPort = this.previewState.port || this._firstListeningPort() || 3000;
19045
+ const localHostRe = /^(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(:\d+)?(\/.*)?$/i;
19046
+
19047
+ // Normalize the input into an absolute URL.
18858
19048
  if (!/^https?:\/\//i.test(url)) {
18859
- url = `http://127.0.0.1:${this.previewState.port || this._firstListeningPort() || 3000}${url.startsWith('/') ? '' : '/'}${url}`;
19049
+ if (localHostRe.test(url)) {
19050
+ url = `http://${url}`;
19051
+ } else if (/^[a-z0-9-]+(\.[a-z0-9-]+)+(:\d+)?([/?#].*)?$/i.test(url)) {
19052
+ // Bare public domain, e.g. "google.com" or "example.com/path".
19053
+ url = `https://${url}`;
19054
+ } else {
19055
+ url = `http://127.0.0.1:${loopbackPort}${url.startsWith('/') ? '' : '/'}${url}`;
19056
+ }
19057
+ }
19058
+
19059
+ // Public (non-loopback) URLs cannot be served by the virtual loopback Service
19060
+ // Worker, so open them in a real browser tab instead of the in-browser frame.
19061
+ let isExternal = false;
19062
+ try {
19063
+ const u = new URL(url);
19064
+ const host = (u.hostname || '').toLowerCase();
19065
+ isExternal = !(host === 'localhost' || host === '127.0.0.1' || host === '0.0.0.0' || host === '::1' || host === '[::1]');
19066
+ } catch (_) { isExternal = false; }
19067
+
19068
+ if (isExternal) {
19069
+ let opened = false;
19070
+ if (typeof window !== 'undefined' && typeof window.open === 'function') {
19071
+ try {
19072
+ const win = window.open(url, '_blank');
19073
+ if (win) {
19074
+ try { win.opener = null; } catch (_) {}
19075
+ opened = true;
19076
+ }
19077
+ } catch (_) { opened = false; }
19078
+ }
19079
+ if (typeof this._showToast === 'function') {
19080
+ this._showToast(
19081
+ opened ? `Opened ${url} in a new tab` : `Could not open ${url} — allow pop-ups and try again`,
19082
+ opened ? 'info' : 'error'
19083
+ );
19084
+ }
19085
+ const inputEl = this.container.querySelector('#cl-preview-url-input');
19086
+ if (inputEl) inputEl.value = this.previewState.url || inputEl.value;
19087
+ return Promise.resolve();
18860
19088
  }
19089
+
18861
19090
  let port = this.previewState.port;
18862
19091
  let path = '/';
18863
19092
  try {
@@ -18967,7 +19196,7 @@ declare module 'bun:sqlite' {
18967
19196
  <button type="button" class="codelab-preview-btn" data-cl-action="preview-reload" title="Reload">${CL_ICONS.refresh || '⟳'}</button>
18968
19197
  </div>
18969
19198
  <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="http://127.0.0.1:3000/" aria-label="Preview URL" />
19199
+ <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
19200
  <div class="codelab-preview-modes">
18972
19201
  <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
19202
  <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 +19815,11 @@ declare module 'bun:sqlite' {
19586
19815
  this._previewGo(previewInput.value);
19587
19816
  return;
19588
19817
  }
19818
+ if (e.key === 'Escape' && this.folderSwitcherOpen) {
19819
+ this.folderSwitcherOpen = false;
19820
+ this._renderBreadcrumbs();
19821
+ return;
19822
+ }
19589
19823
  if (e.key === 'F1' || ((e.metaKey || e.ctrlKey) && e.shiftKey && keyLower === 'p')) {
19590
19824
  e.preventDefault();
19591
19825
  this.openCommandPalette('commands');
@@ -19786,12 +20020,39 @@ declare module 'bun:sqlite' {
19786
20020
  return;
19787
20021
  }
19788
20022
 
20023
+ const fsToggle = e.target.closest('[data-cl-action="toggle-folder-switcher"]');
20024
+ if (fsToggle) {
20025
+ e.stopPropagation();
20026
+ this.folderSwitcherOpen = !this.folderSwitcherOpen;
20027
+ this._renderBreadcrumbs();
20028
+ return;
20029
+ }
20030
+
20031
+ const fsOption = e.target.closest('[data-cl-folder-option]');
20032
+ if (fsOption) {
20033
+ e.stopPropagation();
20034
+ const scopeVal = fsOption.dataset.clFolderOption || '';
20035
+ this.explorerFolder = scopeVal;
20036
+ if (scopeVal) this.collapsedFolders.delete(scopeVal);
20037
+ this.folderSwitcherOpen = false;
20038
+ this._renderFileLists();
20039
+ this._renderBreadcrumbs();
20040
+ return;
20041
+ }
20042
+
20043
+ if (this.folderSwitcherOpen && !e.target.closest('.codelab-folder-switcher')) {
20044
+ this.folderSwitcherOpen = false;
20045
+ this._renderBreadcrumbs();
20046
+ }
20047
+
19789
20048
  const bcFolder = e.target.closest('[data-cl-breadcrumb-folder]');
19790
20049
  if (bcFolder) {
19791
20050
  const folder = bcFolder.dataset.clBreadcrumbFolder;
19792
20051
  if (folder) {
19793
20052
  this.collapsedFolders.delete(folder);
20053
+ this.explorerFolder = folder;
19794
20054
  this._renderFileLists();
20055
+ this._renderBreadcrumbs();
19795
20056
  }
19796
20057
  return;
19797
20058
  }
@@ -19926,10 +20187,10 @@ declare module 'bun:sqlite' {
19926
20187
  this.isCreatingFile = true;
19927
20188
  this._renderFileLists();
19928
20189
  } else if (action === 'new-file-root') {
19929
- this.creatingItem = { type: 'file', parentFolder: '' };
20190
+ this.creatingItem = { type: 'file', parentFolder: this.explorerFolder || '' };
19930
20191
  this._renderFileLists();
19931
20192
  } else if (action === 'new-folder-root') {
19932
- this.creatingItem = { type: 'folder', parentFolder: '' };
20193
+ this.creatingItem = { type: 'folder', parentFolder: this.explorerFolder || '' };
19933
20194
  this._renderFileLists();
19934
20195
  } else if (action === 'new-file-folder') {
19935
20196
  const folder = actionBtn.dataset.clFolder || '';