@innovatorved/code-lab 0.1.10 → 0.1.12
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/ARCHITECTURE.md +1 -1
- package/README.md +1 -1
- package/dist/code-lab.css +28 -0
- package/dist/code-lab.d.ts +1 -1
- package/dist/code-lab.esm.js +165 -18
- package/dist/code-lab.js +164 -17
- package/dist/preview-sw.js +1 -1
- package/dist/runtime.esm.js +29 -4
- package/dist/runtime.js +29 -4
- package/dist/shell.esm.js +121 -9
- package/dist/shell.js +121 -9
- package/dist/terminal.esm.js +1 -1
- package/dist/terminal.js +1 -1
- package/package.json +1 -1
- package/src/code-lab.css +28 -0
- package/src/runtime.ts +28 -3
- package/src/shell.ts +120 -8
- package/src/workbench.ts +15 -5
package/ARCHITECTURE.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# `@innovatorved/code-lab` Architecture (v0.1.
|
|
1
|
+
# `@innovatorved/code-lab` Architecture (v0.1.12)
|
|
2
2
|
|
|
3
3
|
`@innovatorved/code-lab` is an embeddable, browser-native Node.js v22 + Bun v1.1 IDE, POSIX shell, PTY terminal, and virtual execution sandbox with self-contained browser bundles (zero runtime dependencies in `dist/*`; Zod schemas available under `@innovatorved/code-lab/schemas`).
|
|
4
4
|
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Browser-native code IDE workbench, modular guided challenge engine (`@innovatorv
|
|
|
11
11
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
14
|
-
- **Modular Architecture (`v0.1.
|
|
14
|
+
- **Modular Architecture (`v0.1.12`)**: Pure, general-purpose browser IDE (`code-lab`) by default with File Explorer, Monaco Editor, and PTY Terminal. Curriculum features (Guided Steps, Mode Switcher, and JS/TS switcher) are encapsulated in an opt-in modular extension (`@innovatorved/code-lab/extensions/guided-lab`).
|
|
15
15
|
- **End-to-End TypeScript & Zod Type Safety**: Written in TypeScript with strict runtime schemas and inferred types (`z.infer<typeof ...>`) for workbench options, guided labs, runtime execution, and git cloning.
|
|
16
16
|
- **Public GitHub Repository Cloning (`git clone`)**: Clone any public GitHub repository (`git clone https://github.com/owner/repo` or `git clone owner/repo --branch main` in the terminal, or `await lab.cloneRepo('owner/repo')` via the SDK) directly into `/workspace` with zero authentication required (automatic GitHub Trees API + jsDelivr unlimited fallback). Clone progress (`remote: Enumerating objects…`, `Receiving objects: n%…`) streams into the terminal in real time as it downloads.
|
|
17
17
|
- **Interactive IDE Workbench**: Multi-file Monaco editor, collapsible hierarchical file tree with drag-and-drop, a workspace **folder switcher** (breadcrumb dropdown that scopes the explorer to any subfolder), decoupled editor tabs, Command Palette (`Cmd+Shift+P`), Quick Open (`Cmd+P`), breadcrumbs, and line-by-line solution diff viewer.
|
package/dist/code-lab.css
CHANGED
|
@@ -4347,6 +4347,27 @@ code-lab,
|
|
|
4347
4347
|
max-width: 110px;
|
|
4348
4348
|
}
|
|
4349
4349
|
|
|
4350
|
+
/* The split pane is narrower than the drawer, so the single-row chrome would
|
|
4351
|
+
clip its right-hand controls. Wrap instead, and give the URL its own row. */
|
|
4352
|
+
.codelab-preview-split .codelab-preview-chrome {
|
|
4353
|
+
flex-wrap: wrap;
|
|
4354
|
+
row-gap: 4px;
|
|
4355
|
+
}
|
|
4356
|
+
|
|
4357
|
+
.codelab-preview-split .codelab-preview-url-input {
|
|
4358
|
+
order: 10;
|
|
4359
|
+
flex: 1 1 100%;
|
|
4360
|
+
}
|
|
4361
|
+
|
|
4362
|
+
/* Icon-only pop-out keeps the split chrome to two rows. */
|
|
4363
|
+
.codelab-preview-split [data-cl-action="preview-popout"] {
|
|
4364
|
+
padding: 0 6px;
|
|
4365
|
+
}
|
|
4366
|
+
|
|
4367
|
+
.codelab-preview-split [data-cl-action="preview-popout"] > span {
|
|
4368
|
+
display: none;
|
|
4369
|
+
}
|
|
4370
|
+
|
|
4350
4371
|
.codelab-preview-csp--blocked {
|
|
4351
4372
|
color: var(--cl-red);
|
|
4352
4373
|
border-color: var(--cl-red);
|
|
@@ -5107,6 +5128,13 @@ code-lab,
|
|
|
5107
5128
|
These must come after the base `.codelab-workspace.has-preview-split` rule
|
|
5108
5129
|
above: equal specificity, later wins. */
|
|
5109
5130
|
@media (max-width: 900px) {
|
|
5131
|
+
/* Device emulation and the allowlist badge are not useful in a narrow pane.
|
|
5132
|
+
The violation chip stays visible so blocked requests are still surfaced. */
|
|
5133
|
+
.codelab-preview-split .codelab-preview-modes,
|
|
5134
|
+
.codelab-preview-split #cl-preview-csp-badge {
|
|
5135
|
+
display: none;
|
|
5136
|
+
}
|
|
5137
|
+
|
|
5110
5138
|
/* Keep the split, but give the editor a floor and cap the preview share. */
|
|
5111
5139
|
.codelab-workspace.has-preview-split {
|
|
5112
5140
|
grid-template-columns: 155px 4px minmax(180px, 1fr) 5px minmax(200px, min(42%, var(--cl-preview-split-width, 44%)));
|
package/dist/code-lab.d.ts
CHANGED
package/dist/code-lab.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ============================================================
|
|
3
|
-
* @innovatorved/code-lab v0.1.
|
|
3
|
+
* @innovatorved/code-lab v0.1.12 — Standalone Browser Code IDE & Virtual Runtime
|
|
4
4
|
* ============================================================
|
|
5
5
|
* Features:
|
|
6
6
|
* - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
|
|
@@ -5932,6 +5932,7 @@ function __initVirtualRuntime(rootScope) {
|
|
|
5932
5932
|
if (/@jsx\b/.test(source)) return true;
|
|
5933
5933
|
if (source.indexOf('<>') !== -1) return true;
|
|
5934
5934
|
if (/<\/[A-Za-z]/.test(source)) return true;
|
|
5935
|
+
if (/<[A-Za-z_$][A-Za-z0-9_$:.\-]*\b[^>\n]*\/>/.test(source)) return true;
|
|
5935
5936
|
return false;
|
|
5936
5937
|
}
|
|
5937
5938
|
|
|
@@ -6009,6 +6010,23 @@ function __initVirtualRuntime(rootScope) {
|
|
|
6009
6010
|
return i;
|
|
6010
6011
|
}
|
|
6011
6012
|
|
|
6013
|
+
function isJsxCommentOnly(str) {
|
|
6014
|
+
if (!str) return true;
|
|
6015
|
+
let k = 0;
|
|
6016
|
+
while (k < str.length) {
|
|
6017
|
+
k = jsxSkipWs(str, k);
|
|
6018
|
+
if (k >= str.length) break;
|
|
6019
|
+
if (str[k] === '/' && (str[k + 1] === '/' || str[k + 1] === '*')) {
|
|
6020
|
+
const next = jsxSkipJsLiteral(str, k);
|
|
6021
|
+
if (next === -1) return false;
|
|
6022
|
+
k = next;
|
|
6023
|
+
} else {
|
|
6024
|
+
return false;
|
|
6025
|
+
}
|
|
6026
|
+
}
|
|
6027
|
+
return true;
|
|
6028
|
+
}
|
|
6029
|
+
|
|
6012
6030
|
function normalizeJsxText(raw) {
|
|
6013
6031
|
if (!raw) return '';
|
|
6014
6032
|
let t = raw.replace(/\r/g, '');
|
|
@@ -6152,8 +6170,12 @@ function __initVirtualRuntime(rootScope) {
|
|
|
6152
6170
|
}
|
|
6153
6171
|
if (c === '{') {
|
|
6154
6172
|
const br = jsxReadBraced(source, j, o);
|
|
6155
|
-
|
|
6156
|
-
|
|
6173
|
+
if (!isJsxCommentOnly(br.inner)) {
|
|
6174
|
+
const inner = jsxTransform(br.inner, o);
|
|
6175
|
+
if (inner && inner.trim()) {
|
|
6176
|
+
children.push(inner.indexOf('//') !== -1 && !inner.endsWith('\n') ? inner + '\n' : inner);
|
|
6177
|
+
}
|
|
6178
|
+
}
|
|
6157
6179
|
j = br.next;
|
|
6158
6180
|
continue;
|
|
6159
6181
|
}
|
|
@@ -6218,7 +6240,8 @@ function __initVirtualRuntime(rootScope) {
|
|
|
6218
6240
|
// JSX/TSX must be rewritten before masking so JSX text is kept verbatim.
|
|
6219
6241
|
if (hasJsx) {
|
|
6220
6242
|
const { pragma, frag } = readJsxPragma(source);
|
|
6221
|
-
const
|
|
6243
|
+
const hasReactBinding = /\bimport\s+(?!type\b)(?:\*\s+as\s+React\b|React\b)|(?:\bconst|\blet|\bvar|\bfunction|\bclass)\s+React\b|\bReact\s*=/.test(source);
|
|
6244
|
+
const needsReact = pragma === 'React.createElement' && (keepEsm ? !hasReactBinding : !/\bReact\b/.test(source));
|
|
6222
6245
|
const transformed = jsxTransform(source, { pragma, frag });
|
|
6223
6246
|
if (transformed !== source) {
|
|
6224
6247
|
source = transformed;
|
|
@@ -6226,6 +6249,8 @@ function __initVirtualRuntime(rootScope) {
|
|
|
6226
6249
|
if (needsReact) {
|
|
6227
6250
|
source = (keepEsm ? 'import React from "react";\n' : 'const React = require("react");\n') + source;
|
|
6228
6251
|
}
|
|
6252
|
+
} else if (!isTS && !hasESM) {
|
|
6253
|
+
return source;
|
|
6229
6254
|
}
|
|
6230
6255
|
}
|
|
6231
6256
|
|
|
@@ -13176,6 +13201,12 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13176
13201
|
if (!pkgName) continue;
|
|
13177
13202
|
const subpath = spec.slice(pkgName.length).replace(/^\/+/, '');
|
|
13178
13203
|
const version = resolveBareVersion(vfs, rootDir, pkgName);
|
|
13204
|
+
if (subpath && /\.css$/i.test(subpath)) {
|
|
13205
|
+
const cssHref = `${CDN_ESM_BASE}/${pkgName}@${version}/${subpath.replace(/^\/+/, '')}`;
|
|
13206
|
+
const loader = `if(typeof document!=='undefined'){const l=document.createElement('link');l.rel='stylesheet';l.href=${JSON.stringify(cssHref)};document.head.appendChild(l);}export default ${JSON.stringify(cssHref)};`;
|
|
13207
|
+
imports[spec] = `data:text/javascript;charset=utf-8,${encodeURIComponent(loader)}`;
|
|
13208
|
+
continue;
|
|
13209
|
+
}
|
|
13179
13210
|
imports[spec] = cdnEsmUrl(pkgName, version, subpath || undefined);
|
|
13180
13211
|
}
|
|
13181
13212
|
return imports;
|
|
@@ -13196,6 +13227,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13196
13227
|
let match;
|
|
13197
13228
|
while ((match = re.exec(text)) !== null) {
|
|
13198
13229
|
const url = match[0];
|
|
13230
|
+
if (url.includes('${')) continue;
|
|
13199
13231
|
const pkgName = decodeURIComponent(match[1]);
|
|
13200
13232
|
const rest = match[2];
|
|
13201
13233
|
const pinnedVersion = rest.split(/[\/?]/)[0];
|
|
@@ -13240,6 +13272,35 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13240
13272
|
return files;
|
|
13241
13273
|
}
|
|
13242
13274
|
|
|
13275
|
+
function collectPreviewAssetFiles(vfs, rootDir, maxFiles = 200) {
|
|
13276
|
+
const files = [];
|
|
13277
|
+
const walk = (dir, depth) => {
|
|
13278
|
+
if (depth > 8 || files.length >= maxFiles) return;
|
|
13279
|
+
let entries = [];
|
|
13280
|
+
try { entries = vfs.readdirSync(dir); } catch (_) { return; }
|
|
13281
|
+
for (const name of entries) {
|
|
13282
|
+
if (name === 'node_modules' || name.startsWith('.')) continue;
|
|
13283
|
+
const full = PosixPath.join(dir, name);
|
|
13284
|
+
let st;
|
|
13285
|
+
try { st = vfs.statSync(full); } catch (_) { continue; }
|
|
13286
|
+
const dirFlag = st && (typeof st.isDirectory === 'function' ? st.isDirectory() : st.isDirectory);
|
|
13287
|
+
if (dirFlag) {
|
|
13288
|
+
walk(full, depth + 1);
|
|
13289
|
+
} else if (/\.(?:css|json|svg)$/i.test(name) && files.length < maxFiles) {
|
|
13290
|
+
try {
|
|
13291
|
+
const content = vfs.readFileSync(full, 'utf8');
|
|
13292
|
+
const rel = full.startsWith(rootDir + '/') ? full.slice(rootDir.length + 1) : name;
|
|
13293
|
+
files.push({ full, rel, content });
|
|
13294
|
+
} catch (err) {
|
|
13295
|
+
_shellLogger.debug('Preview asset read skipped.', full, err);
|
|
13296
|
+
}
|
|
13297
|
+
}
|
|
13298
|
+
}
|
|
13299
|
+
};
|
|
13300
|
+
walk(rootDir, 0);
|
|
13301
|
+
return files;
|
|
13302
|
+
}
|
|
13303
|
+
|
|
13243
13304
|
function collectPreviewScripts(vfs, rootDir, maxFiles = 200) {
|
|
13244
13305
|
return collectPreviewScriptFiles(vfs, rootDir, maxFiles).map((f) => f.content);
|
|
13245
13306
|
}
|
|
@@ -13322,11 +13383,31 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13322
13383
|
return out;
|
|
13323
13384
|
};
|
|
13324
13385
|
|
|
13386
|
+
const inlineLocalCssImports = (cssText, cssDir) => {
|
|
13387
|
+
if (!cssText) return '';
|
|
13388
|
+
return cssText.replace(/@import\s+(?:url\(\s*['"]?([^'")]+)['"]?\s*\)|['"]([^'"]+)['"])\s*;?/gi, (full, u1, u2) => {
|
|
13389
|
+
const spec = (u1 || u2 || '').trim();
|
|
13390
|
+
if (!spec || /^(?:https?:|data:|\/\/)/i.test(spec)) return full;
|
|
13391
|
+
if (spec === 'tailwindcss') return '';
|
|
13392
|
+
const subTarget = resolveLocalTarget(cssDir, spec);
|
|
13393
|
+
if (subTarget && /\.css$/i.test(subTarget)) {
|
|
13394
|
+
const subCss = readText(subTarget);
|
|
13395
|
+
if (subCss !== null) return subCss;
|
|
13396
|
+
}
|
|
13397
|
+
return '';
|
|
13398
|
+
});
|
|
13399
|
+
};
|
|
13400
|
+
|
|
13325
13401
|
const buildHtmlPreviewResponse = (htmlBody, htmlTargetPath) => {
|
|
13326
13402
|
const scriptFiles = collectPreviewScriptFiles(ctx.vfs, rootDir);
|
|
13403
|
+
const assetFiles = collectPreviewAssetFiles(ctx.vfs, rootDir);
|
|
13327
13404
|
const specifiers = new Set();
|
|
13405
|
+
const compiledScripts = [];
|
|
13328
13406
|
for (const f of scriptFiles) {
|
|
13329
13407
|
for (const s of extractBareSpecifiers(f.content)) specifiers.add(s);
|
|
13408
|
+
const compiled = transpileAndRewriteLocalImports(f.content, f.full);
|
|
13409
|
+
for (const s of extractBareSpecifiers(compiled)) specifiers.add(s);
|
|
13410
|
+
compiledScripts.push({ file: f, compiled });
|
|
13330
13411
|
}
|
|
13331
13412
|
// Also scan inline module scripts in HTML for bare specifiers
|
|
13332
13413
|
const inlineScriptRe = /<script\b[^>]*>([\s\S]*?)<\/script>/gi;
|
|
@@ -13340,14 +13421,53 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13340
13421
|
const importMap = buildPreviewImportMap(ctx.vfs, rootDir, specifiers);
|
|
13341
13422
|
for (const f of scriptFiles) aliasPinnedCdnUrls(ctx.vfs, rootDir, f.content, importMap);
|
|
13342
13423
|
aliasPinnedCdnUrls(ctx.vfs, rootDir, htmlBody, importMap);
|
|
13343
|
-
for (const
|
|
13344
|
-
const
|
|
13345
|
-
const key = toLocalImportKey(f.full);
|
|
13424
|
+
for (const { file, compiled } of compiledScripts) {
|
|
13425
|
+
const key = toLocalImportKey(file.full);
|
|
13346
13426
|
importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(compiled)}`;
|
|
13347
13427
|
}
|
|
13348
13428
|
|
|
13429
|
+
let needsTailwindBrowser = false;
|
|
13430
|
+
for (const af of assetFiles) {
|
|
13431
|
+
const key = toLocalImportKey(af.full);
|
|
13432
|
+
if (/\.css$/i.test(af.full)) {
|
|
13433
|
+
if (/@import\s+['"]tailwindcss['"]/i.test(af.content)) {
|
|
13434
|
+
needsTailwindBrowser = true;
|
|
13435
|
+
}
|
|
13436
|
+
const resolvedCss = inlineLocalCssImports(af.content, PosixPath.dirname(af.full));
|
|
13437
|
+
const cssModuleJs = `const __css=${JSON.stringify(resolvedCss)};if(typeof document!=='undefined'){const __s=document.createElement('style');__s.setAttribute('data-codelab-css',${JSON.stringify(af.rel)});__s.textContent=__css;document.head.appendChild(__s);}export default __css;`;
|
|
13438
|
+
importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(cssModuleJs)}`;
|
|
13439
|
+
} else if (/\.json$/i.test(af.full)) {
|
|
13440
|
+
const jsonModuleJs = `export default ${af.content.trim() || 'null'};`;
|
|
13441
|
+
importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(jsonModuleJs)}`;
|
|
13442
|
+
} else if (/\.svg$/i.test(af.full)) {
|
|
13443
|
+
const svgDataUrl = `data:image/svg+xml;utf8,${encodeURIComponent(af.content)}`;
|
|
13444
|
+
const svgModuleJs = `export default ${JSON.stringify(svgDataUrl)};`;
|
|
13445
|
+
importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(svgModuleJs)}`;
|
|
13446
|
+
}
|
|
13447
|
+
}
|
|
13448
|
+
|
|
13349
13449
|
const htmlDir = PosixPath.dirname(htmlTargetPath);
|
|
13350
|
-
let transformedHtml = htmlBody;
|
|
13450
|
+
let transformedHtml = htmlBody.replace(/%PUBLIC_URL%\//g, '/').replace(/%PUBLIC_URL%/g, '');
|
|
13451
|
+
|
|
13452
|
+
// Auto-inject entry script for Create React App / bundler templates where index.html omits <script src="...">
|
|
13453
|
+
const hasLocalScriptTag = /<script\b[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*>/i.test(transformedHtml);
|
|
13454
|
+
if (!hasLocalScriptTag) {
|
|
13455
|
+
const defaultEntries = [
|
|
13456
|
+
'/src/main.tsx', '/src/main.jsx', '/src/main.ts', '/src/main.js',
|
|
13457
|
+
'/src/index.tsx', '/src/index.jsx', '/src/index.ts', '/src/index.js'
|
|
13458
|
+
];
|
|
13459
|
+
for (const cand of defaultEntries) {
|
|
13460
|
+
if (isFile(PosixPath.join(rootDir, cand.slice(1)))) {
|
|
13461
|
+
const entryTag = `<script type="module" src="${cand}"></script>`;
|
|
13462
|
+
if (/<\/body>/i.test(transformedHtml)) {
|
|
13463
|
+
transformedHtml = transformedHtml.replace(/<\/body>/i, ` ${entryTag}\n</body>`);
|
|
13464
|
+
} else {
|
|
13465
|
+
transformedHtml += `\n${entryTag}`;
|
|
13466
|
+
}
|
|
13467
|
+
break;
|
|
13468
|
+
}
|
|
13469
|
+
}
|
|
13470
|
+
}
|
|
13351
13471
|
|
|
13352
13472
|
// Inline local <link rel="stylesheet" href="..."> so styles work in opaque-origin / srcdoc frames
|
|
13353
13473
|
transformedHtml = transformedHtml.replace(/<link\b([^>]*?)>/gi, (fullTag, attrs) => {
|
|
@@ -13358,7 +13478,11 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13358
13478
|
if (!cssTarget || !/\.css$/i.test(cssTarget)) return fullTag;
|
|
13359
13479
|
const cssContent = readText(cssTarget);
|
|
13360
13480
|
if (cssContent === null) return fullTag;
|
|
13361
|
-
|
|
13481
|
+
if (/@import\s+['"]tailwindcss['"]/i.test(cssContent)) {
|
|
13482
|
+
needsTailwindBrowser = true;
|
|
13483
|
+
}
|
|
13484
|
+
const resolvedCss = inlineLocalCssImports(cssContent, PosixPath.dirname(cssTarget));
|
|
13485
|
+
return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '"')}">\n${resolvedCss}\n</style>`;
|
|
13362
13486
|
});
|
|
13363
13487
|
|
|
13364
13488
|
// Inline local <script ... src="..."></script> so entry modules & scripts execute reliably in opaque-origin / srcdoc frames
|
|
@@ -13370,11 +13494,20 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13370
13494
|
const rawScript = readText(scriptTarget);
|
|
13371
13495
|
if (rawScript === null) return fullTag;
|
|
13372
13496
|
const compiled = transpileAndRewriteLocalImports(rawScript, scriptTarget);
|
|
13373
|
-
const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget);
|
|
13497
|
+
const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget) || /^\s*(?:import|export)\b/m.test(rawScript);
|
|
13374
13498
|
const typeAttr = isMod ? ' type="module"' : '';
|
|
13375
13499
|
return `<script${typeAttr} data-codelab-src="${srcMatch[1].replace(/"/g, '"')}">\n${compiled}\n</script>`;
|
|
13376
13500
|
});
|
|
13377
13501
|
|
|
13502
|
+
if (needsTailwindBrowser && !transformedHtml.includes('@tailwindcss/browser')) {
|
|
13503
|
+
const twTag = '<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>';
|
|
13504
|
+
if (/<head[^>]*>/i.test(transformedHtml)) {
|
|
13505
|
+
transformedHtml = transformedHtml.replace(/<head[^>]*>/i, (m) => `${m}\n ${twTag}`);
|
|
13506
|
+
} else {
|
|
13507
|
+
transformedHtml = twTag + '\n' + transformedHtml;
|
|
13508
|
+
}
|
|
13509
|
+
}
|
|
13510
|
+
|
|
13378
13511
|
return injectPreviewExtras(transformedHtml, importMap);
|
|
13379
13512
|
};
|
|
13380
13513
|
|
|
@@ -13386,7 +13519,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13386
13519
|
const hasExt = /\.[A-Za-z0-9]+$/.test(rel);
|
|
13387
13520
|
|
|
13388
13521
|
if (!rel || pathname.endsWith('/') || isDir(target)) {
|
|
13389
|
-
|
|
13522
|
+
const rootIdx = PosixPath.join(target, 'index.html');
|
|
13523
|
+
const pubIdx = PosixPath.join(target, 'public', 'index.html');
|
|
13524
|
+
target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx;
|
|
13390
13525
|
}
|
|
13391
13526
|
if (!exists(target) && !hasExt) {
|
|
13392
13527
|
// Resolve extensionless module specifiers (e.g. `./components/Counter`)
|
|
@@ -13400,7 +13535,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
13400
13535
|
for (const c of cands) { if (exists(c)) { target = c; break; } }
|
|
13401
13536
|
}
|
|
13402
13537
|
if (!exists(target) && !hasExt) {
|
|
13403
|
-
|
|
13538
|
+
const rootIdx = PosixPath.join(rootDir, 'index.html');
|
|
13539
|
+
const pubIdx = PosixPath.join(rootDir, 'public', 'index.html');
|
|
13540
|
+
target = (!exists(rootIdx) && exists(pubIdx)) ? pubIdx : rootIdx; // SPA fallback
|
|
13404
13541
|
}
|
|
13405
13542
|
if (!exists(target)) {
|
|
13406
13543
|
return new Response(
|
|
@@ -18778,7 +18915,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
18778
18915
|
|
|
18779
18916
|
// The bundler rewrites this literal from package.json at build time. Keeping
|
|
18780
18917
|
// the fallback in sync lets tests require src/workbench.js directly.
|
|
18781
|
-
const CODELAB_VERSION = '0.1.
|
|
18918
|
+
const CODELAB_VERSION = '0.1.12';
|
|
18782
18919
|
|
|
18783
18920
|
// Ambient TypeScript declarations for Node.js built-ins inside Monaco
|
|
18784
18921
|
const NODE_AMBIENT_DTS = `
|
|
@@ -20709,7 +20846,12 @@ declare module 'bun:sqlite' {
|
|
|
20709
20846
|
const found = names.find(f => pattern.test(f));
|
|
20710
20847
|
if (found) return found;
|
|
20711
20848
|
if (kind === 'demo') {
|
|
20712
|
-
|
|
20849
|
+
const isConfigOrTest = f => /(^|\/)(test|.*\.(?:test|spec|config|d))\.(js|ts|mjs|cjs)$/i.test(f) || /(^|\/)\.[^/]+$/i.test(f);
|
|
20850
|
+
const hasHtmlEntry = Boolean(this.files['index.html'] || this.files['public/index.html']);
|
|
20851
|
+
if (hasHtmlEntry) {
|
|
20852
|
+
return names.find(f => /(^|\/)(server|app|demo)\.(js|ts)$/i.test(f) && !/^src\//i.test(f)) || null;
|
|
20853
|
+
}
|
|
20854
|
+
return names.find(f => /\.(js|ts)$/i.test(f) && !isConfigOrTest(f)) || null;
|
|
20713
20855
|
}
|
|
20714
20856
|
return null;
|
|
20715
20857
|
}
|
|
@@ -23442,8 +23584,10 @@ declare module 'bun:sqlite' {
|
|
|
23442
23584
|
return null;
|
|
23443
23585
|
}
|
|
23444
23586
|
|
|
23445
|
-
const
|
|
23446
|
-
|
|
23587
|
+
const hasSrcScripts = Boolean(this.files && Object.keys(this.files).some((f) => /^src\/.+\.(?:[cm]?jsx?|tsx?)$/i.test(f)));
|
|
23588
|
+
const rootDir = this.files['index.html'] ? '/workspace'
|
|
23589
|
+
: (this.files['public/index.html'] && !hasSrcScripts) ? '/workspace/public'
|
|
23590
|
+
: this.files['site/index.html'] ? '/workspace/site'
|
|
23447
23591
|
: '/workspace';
|
|
23448
23592
|
|
|
23449
23593
|
if (!this.shell || typeof this.shell.execute !== 'function') return null;
|
|
@@ -25931,6 +26075,9 @@ declare module 'bun:sqlite' {
|
|
|
25931
26075
|
if (this.isRunning) return;
|
|
25932
26076
|
const entry = this._findEntryFile('demo');
|
|
25933
26077
|
if (!entry) {
|
|
26078
|
+
if ((this.files['index.html'] || this.files['public/index.html']) && typeof this.previewApp === 'function') {
|
|
26079
|
+
return this.previewApp();
|
|
26080
|
+
}
|
|
25934
26081
|
this.terminalLogs.push({ type: 'stderr', text: 'No demo.js / demo.ts file found in this workspace.' });
|
|
25935
26082
|
this.drawerTab = 'terminal';
|
|
25936
26083
|
this._renderDrawerBody();
|
|
@@ -26806,7 +26953,7 @@ declare module 'bun:sqlite' {
|
|
|
26806
26953
|
Enter any public GitHub repository URL or <code>owner/repo</code> slug. Files will be cloned directly into the in-memory Virtual Filesystem (VFS) with zero authentication required.
|
|
26807
26954
|
</p>
|
|
26808
26955
|
<div style="display:flex;gap:8px;">
|
|
26809
|
-
<input id="cl-clone-repo-input" type="text" placeholder="e.g.
|
|
26956
|
+
<input id="cl-clone-repo-input" type="text" placeholder="e.g. mdn/todo-react or https://github.com/owner/repo" style="flex:1;height:34px;padding:0 10px;background:var(--cl-bg);border:1px solid var(--cl-border-strong);border-radius:var(--cl-radius-sm);color:var(--cl-fg);font-family:var(--cl-font-mono);font-size:12px;outline:none;" />
|
|
26810
26957
|
<button type="button" class="codelab-btn codelab-btn--primary" data-cl-action="confirm-clone-repo">Clone Repo</button>
|
|
26811
26958
|
</div>
|
|
26812
26959
|
</div>
|
|
@@ -27281,7 +27428,7 @@ const PTYTerminalEngine = CodeLabTerminal ? CodeLabTerminal.PTYTerminalEngine :
|
|
|
27281
27428
|
const mount = CodeLab ? CodeLab.mount : null;
|
|
27282
27429
|
const create = CodeLab ? CodeLab.create : null;
|
|
27283
27430
|
const unmount = CodeLab ? CodeLab.unmount : null;
|
|
27284
|
-
const version = CodeLab ? CodeLab.version : '0.1.
|
|
27431
|
+
const version = CodeLab ? CodeLab.version : '0.1.12';
|
|
27285
27432
|
const renderMarkdown = CodeLab ? CodeLab.renderMarkdown : null;
|
|
27286
27433
|
const renderSimpleMarkdown = CodeLab ? CodeLab.renderSimpleMarkdown : null;
|
|
27287
27434
|
const cloneRepo = CodeLab ? CodeLab.cloneRepo : null;
|