@innovatorved/code-lab 0.1.4 → 0.1.6
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 +2 -1
- package/README.md +4 -2
- package/dist/code-lab.css +49 -0
- package/dist/code-lab.d.ts +3 -1
- package/dist/code-lab.esm.js +1472 -87
- package/dist/code-lab.js +1462 -86
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.esm.js +783 -32
- package/dist/runtime.js +740 -21
- package/dist/schemas.esm.js +4191 -0
- package/dist/schemas.js +4207 -0
- package/dist/shell.esm.js +657 -64
- package/dist/shell.js +657 -64
- package/dist/terminal.esm.js +7 -1
- package/package.json +9 -4
- package/src/code-lab.css +49 -0
- package/src/runtime.js +740 -21
- package/src/runtime.ts +741 -21
- package/src/shell.js +657 -64
- package/src/shell.ts +657 -64
- package/src/workbench.js +64 -1
- package/src/workbench.ts +64 -1
package/src/workbench.js
CHANGED
|
@@ -1766,6 +1766,9 @@ declare module 'bun:sqlite' {
|
|
|
1766
1766
|
<span>${(this.hasGuidedLab && this.mode === 'guided') ? 'Verify Step' : 'Run Tests'}</span>
|
|
1767
1767
|
<span class="codelab-btn__kbd">⌘↵</span>
|
|
1768
1768
|
</button>
|
|
1769
|
+
<button type="button" class="codelab-btn codelab-btn--icon" id="cl-preview-app-btn" data-cl-action="preview-app" title="Run & Preview in Browser (built-in dev server)" aria-label="Run and Preview in Browser">
|
|
1770
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>
|
|
1771
|
+
</button>
|
|
1769
1772
|
<span class="codelab-toolbar__sep" aria-hidden="true"></span>
|
|
1770
1773
|
${this.hasGuidedLab ? `
|
|
1771
1774
|
<button type="button" class="codelab-btn codelab-btn--icon ${isGuideCollapsed ? '' : 'active'}" id="cl-toggle-guide-btn" data-cl-action="toggle-guide" title="Toggle Guide Panel" aria-label="Toggle Guide Panel" aria-pressed="${isGuideCollapsed ? 'false' : 'true'}">
|
|
@@ -4098,6 +4101,55 @@ declare module 'bun:sqlite' {
|
|
|
4098
4101
|
return this._previewLoadPromise || Promise.resolve();
|
|
4099
4102
|
}
|
|
4100
4103
|
|
|
4104
|
+
// One-click "run the app in a browser": if nothing is listening yet, start the
|
|
4105
|
+
// built-in preview server (which transpiles TS/JSX to browser-native ESM and
|
|
4106
|
+
// resolves bare imports via jsDelivr) and then open the Web Preview.
|
|
4107
|
+
async previewApp() {
|
|
4108
|
+
const existing = this._firstListeningPort();
|
|
4109
|
+
if (existing) {
|
|
4110
|
+
this._openWebPreview(existing);
|
|
4111
|
+
return existing;
|
|
4112
|
+
}
|
|
4113
|
+
|
|
4114
|
+
const htmlCandidates = ['public/index.html', 'index.html', 'site/index.html', 'src/index.html'];
|
|
4115
|
+
if (!htmlCandidates.some((f) => this.files && this.files[f])) {
|
|
4116
|
+
this.drawerTab = 'terminal';
|
|
4117
|
+
this.terminalLogs.push({
|
|
4118
|
+
type: 'system',
|
|
4119
|
+
text: '\nNo index.html found. Add an `index.html` (or run `serve <dir>` in the terminal) to preview your app.'
|
|
4120
|
+
});
|
|
4121
|
+
this._renderDrawerBody();
|
|
4122
|
+
return null;
|
|
4123
|
+
}
|
|
4124
|
+
|
|
4125
|
+
const rootDir = (this.files['public/index.html']) ? '/workspace/public'
|
|
4126
|
+
: (this.files['site/index.html']) ? '/workspace/site'
|
|
4127
|
+
: '/workspace';
|
|
4128
|
+
|
|
4129
|
+
if (!this.shell || typeof this.shell.execute !== 'function') return null;
|
|
4130
|
+
this._syncFilesToShellVfs();
|
|
4131
|
+
this.shell.cwd = this.cwd || '/workspace';
|
|
4132
|
+
this.drawerTab = 'terminal';
|
|
4133
|
+
this.terminalLogs.push({ type: 'system', text: `\n$ serve ${rootDir}` });
|
|
4134
|
+
this._renderDrawerBody();
|
|
4135
|
+
|
|
4136
|
+
try {
|
|
4137
|
+
const res = await this.shell.execute(`serve ${rootDir}`, {});
|
|
4138
|
+
if (res && res.stdout) this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
4139
|
+
if (res && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
4140
|
+
} catch (err) {
|
|
4141
|
+
this.terminalLogs.push({ type: 'stderr', text: String((err && err.message) || err) });
|
|
4142
|
+
}
|
|
4143
|
+
this._renderDrawerBody();
|
|
4144
|
+
|
|
4145
|
+
const port = this._firstListeningPort();
|
|
4146
|
+
if (port) {
|
|
4147
|
+
this._openWebPreview(port);
|
|
4148
|
+
return port;
|
|
4149
|
+
}
|
|
4150
|
+
return null;
|
|
4151
|
+
}
|
|
4152
|
+
|
|
4101
4153
|
_previewGo(urlOrPath) {
|
|
4102
4154
|
let url = String(urlOrPath || '').trim();
|
|
4103
4155
|
if (!url) return Promise.resolve();
|
|
@@ -4268,7 +4320,15 @@ declare module 'bun:sqlite' {
|
|
|
4268
4320
|
<div class="codelab-preview-viewport codelab-preview-viewport--${this.previewState.frameMode}" id="cl-preview-viewport">
|
|
4269
4321
|
<iframe class="codelab-preview-iframe" id="cl-preview-iframe" sandbox="allow-scripts allow-forms allow-same-origin allow-modals" title="Web Preview"></iframe>
|
|
4270
4322
|
</div>
|
|
4271
|
-
|
|
4323
|
+
${servers.length
|
|
4324
|
+
? `<div class="codelab-preview-hint">Serving from the in-browser virtual runtime. Use Pop Out for a standalone tab.</div>`
|
|
4325
|
+
: `<div class="codelab-preview-empty">
|
|
4326
|
+
<div class="codelab-preview-empty__icon">${CL_ICONS.globe || '🌐'}</div>
|
|
4327
|
+
<div class="codelab-preview-empty__title">No server running</div>
|
|
4328
|
+
<div class="codelab-preview-empty__text">Start the built-in preview server to render your <code>index.html</code>. TypeScript, TSX and JSX are transpiled for the browser automatically — no bundler required.</div>
|
|
4329
|
+
<button type="button" class="codelab-btn codelab-btn--primary codelab-btn--sm" data-cl-action="preview-app">${CL_ICONS.play || '▶'} <span>Run & Preview</span></button>
|
|
4330
|
+
<div class="codelab-preview-empty__hint">or run <code>serve</code> in the terminal</div>
|
|
4331
|
+
</div>`}
|
|
4272
4332
|
</div>
|
|
4273
4333
|
`;
|
|
4274
4334
|
this._loadPreviewFrame();
|
|
@@ -5271,6 +5331,8 @@ declare module 'bun:sqlite' {
|
|
|
5271
5331
|
} else if (action === 'open-web-preview') {
|
|
5272
5332
|
const port = Number(actionBtn.dataset.port || actionBtn.dataset.clPort);
|
|
5273
5333
|
if (port) this._openWebPreview(port);
|
|
5334
|
+
} else if (action === 'preview-app') {
|
|
5335
|
+
this.previewApp();
|
|
5274
5336
|
} else if (action === 'dismiss-toast') {
|
|
5275
5337
|
this._dismissPortToast(actionBtn.dataset.port);
|
|
5276
5338
|
} else if (action === 'preview-back') {
|
|
@@ -7217,6 +7279,7 @@ declare module 'bun:sqlite' {
|
|
|
7217
7279
|
cloneRepo(repoInput, opts) { return this._instance ? this._instance.cloneRepo(repoInput, opts) : Promise.reject(new Error('Workbench not mounted')); }
|
|
7218
7280
|
runDemo() { return this._instance ? this._instance.runDemo() : Promise.resolve(); }
|
|
7219
7281
|
runTests(filter) { return this._instance ? this._instance.runTests(filter) : Promise.resolve(); }
|
|
7282
|
+
previewApp() { return this._instance ? this._instance.previewApp() : Promise.resolve(null); }
|
|
7220
7283
|
stopExecution() { if (this._instance) this._instance.stopExecution(); }
|
|
7221
7284
|
reset() { if (this._instance) this._instance.reset(); }
|
|
7222
7285
|
exportWorkspace(opts) { return this._instance ? this._instance.exportWorkspace(opts) : null; }
|
package/src/workbench.ts
CHANGED
|
@@ -1767,6 +1767,9 @@ declare module 'bun:sqlite' {
|
|
|
1767
1767
|
<span>${(this.hasGuidedLab && this.mode === 'guided') ? 'Verify Step' : 'Run Tests'}</span>
|
|
1768
1768
|
<span class="codelab-btn__kbd">⌘↵</span>
|
|
1769
1769
|
</button>
|
|
1770
|
+
<button type="button" class="codelab-btn codelab-btn--icon" id="cl-preview-app-btn" data-cl-action="preview-app" title="Run & Preview in Browser (built-in dev server)" aria-label="Run and Preview in Browser">
|
|
1771
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>
|
|
1772
|
+
</button>
|
|
1770
1773
|
<span class="codelab-toolbar__sep" aria-hidden="true"></span>
|
|
1771
1774
|
${this.hasGuidedLab ? `
|
|
1772
1775
|
<button type="button" class="codelab-btn codelab-btn--icon ${isGuideCollapsed ? '' : 'active'}" id="cl-toggle-guide-btn" data-cl-action="toggle-guide" title="Toggle Guide Panel" aria-label="Toggle Guide Panel" aria-pressed="${isGuideCollapsed ? 'false' : 'true'}">
|
|
@@ -4099,6 +4102,55 @@ declare module 'bun:sqlite' {
|
|
|
4099
4102
|
return this._previewLoadPromise || Promise.resolve();
|
|
4100
4103
|
}
|
|
4101
4104
|
|
|
4105
|
+
// One-click "run the app in a browser": if nothing is listening yet, start the
|
|
4106
|
+
// built-in preview server (which transpiles TS/JSX to browser-native ESM and
|
|
4107
|
+
// resolves bare imports via jsDelivr) and then open the Web Preview.
|
|
4108
|
+
async previewApp() {
|
|
4109
|
+
const existing = this._firstListeningPort();
|
|
4110
|
+
if (existing) {
|
|
4111
|
+
this._openWebPreview(existing);
|
|
4112
|
+
return existing;
|
|
4113
|
+
}
|
|
4114
|
+
|
|
4115
|
+
const htmlCandidates = ['public/index.html', 'index.html', 'site/index.html', 'src/index.html'];
|
|
4116
|
+
if (!htmlCandidates.some((f) => this.files && this.files[f])) {
|
|
4117
|
+
this.drawerTab = 'terminal';
|
|
4118
|
+
this.terminalLogs.push({
|
|
4119
|
+
type: 'system',
|
|
4120
|
+
text: '\nNo index.html found. Add an `index.html` (or run `serve <dir>` in the terminal) to preview your app.'
|
|
4121
|
+
});
|
|
4122
|
+
this._renderDrawerBody();
|
|
4123
|
+
return null;
|
|
4124
|
+
}
|
|
4125
|
+
|
|
4126
|
+
const rootDir = (this.files['public/index.html']) ? '/workspace/public'
|
|
4127
|
+
: (this.files['site/index.html']) ? '/workspace/site'
|
|
4128
|
+
: '/workspace';
|
|
4129
|
+
|
|
4130
|
+
if (!this.shell || typeof this.shell.execute !== 'function') return null;
|
|
4131
|
+
this._syncFilesToShellVfs();
|
|
4132
|
+
this.shell.cwd = this.cwd || '/workspace';
|
|
4133
|
+
this.drawerTab = 'terminal';
|
|
4134
|
+
this.terminalLogs.push({ type: 'system', text: `\n$ serve ${rootDir}` });
|
|
4135
|
+
this._renderDrawerBody();
|
|
4136
|
+
|
|
4137
|
+
try {
|
|
4138
|
+
const res = await this.shell.execute(`serve ${rootDir}`, {});
|
|
4139
|
+
if (res && res.stdout) this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
4140
|
+
if (res && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
4141
|
+
} catch (err) {
|
|
4142
|
+
this.terminalLogs.push({ type: 'stderr', text: String((err && err.message) || err) });
|
|
4143
|
+
}
|
|
4144
|
+
this._renderDrawerBody();
|
|
4145
|
+
|
|
4146
|
+
const port = this._firstListeningPort();
|
|
4147
|
+
if (port) {
|
|
4148
|
+
this._openWebPreview(port);
|
|
4149
|
+
return port;
|
|
4150
|
+
}
|
|
4151
|
+
return null;
|
|
4152
|
+
}
|
|
4153
|
+
|
|
4102
4154
|
_previewGo(urlOrPath) {
|
|
4103
4155
|
let url = String(urlOrPath || '').trim();
|
|
4104
4156
|
if (!url) return Promise.resolve();
|
|
@@ -4269,7 +4321,15 @@ declare module 'bun:sqlite' {
|
|
|
4269
4321
|
<div class="codelab-preview-viewport codelab-preview-viewport--${this.previewState.frameMode}" id="cl-preview-viewport">
|
|
4270
4322
|
<iframe class="codelab-preview-iframe" id="cl-preview-iframe" sandbox="allow-scripts allow-forms allow-same-origin allow-modals" title="Web Preview"></iframe>
|
|
4271
4323
|
</div>
|
|
4272
|
-
|
|
4324
|
+
${servers.length
|
|
4325
|
+
? `<div class="codelab-preview-hint">Serving from the in-browser virtual runtime. Use Pop Out for a standalone tab.</div>`
|
|
4326
|
+
: `<div class="codelab-preview-empty">
|
|
4327
|
+
<div class="codelab-preview-empty__icon">${CL_ICONS.globe || '🌐'}</div>
|
|
4328
|
+
<div class="codelab-preview-empty__title">No server running</div>
|
|
4329
|
+
<div class="codelab-preview-empty__text">Start the built-in preview server to render your <code>index.html</code>. TypeScript, TSX and JSX are transpiled for the browser automatically — no bundler required.</div>
|
|
4330
|
+
<button type="button" class="codelab-btn codelab-btn--primary codelab-btn--sm" data-cl-action="preview-app">${CL_ICONS.play || '▶'} <span>Run & Preview</span></button>
|
|
4331
|
+
<div class="codelab-preview-empty__hint">or run <code>serve</code> in the terminal</div>
|
|
4332
|
+
</div>`}
|
|
4273
4333
|
</div>
|
|
4274
4334
|
`;
|
|
4275
4335
|
this._loadPreviewFrame();
|
|
@@ -5272,6 +5332,8 @@ declare module 'bun:sqlite' {
|
|
|
5272
5332
|
} else if (action === 'open-web-preview') {
|
|
5273
5333
|
const port = Number(actionBtn.dataset.port || actionBtn.dataset.clPort);
|
|
5274
5334
|
if (port) this._openWebPreview(port);
|
|
5335
|
+
} else if (action === 'preview-app') {
|
|
5336
|
+
this.previewApp();
|
|
5275
5337
|
} else if (action === 'dismiss-toast') {
|
|
5276
5338
|
this._dismissPortToast(actionBtn.dataset.port);
|
|
5277
5339
|
} else if (action === 'preview-back') {
|
|
@@ -7218,6 +7280,7 @@ declare module 'bun:sqlite' {
|
|
|
7218
7280
|
cloneRepo(repoInput, opts) { return this._instance ? this._instance.cloneRepo(repoInput, opts) : Promise.reject(new Error('Workbench not mounted')); }
|
|
7219
7281
|
runDemo() { return this._instance ? this._instance.runDemo() : Promise.resolve(); }
|
|
7220
7282
|
runTests(filter) { return this._instance ? this._instance.runTests(filter) : Promise.resolve(); }
|
|
7283
|
+
previewApp() { return this._instance ? this._instance.previewApp() : Promise.resolve(null); }
|
|
7221
7284
|
stopExecution() { if (this._instance) this._instance.stopExecution(); }
|
|
7222
7285
|
reset() { if (this._instance) this._instance.reset(); }
|
|
7223
7286
|
exportWorkspace(opts) { return this._instance ? this._instance.exportWorkspace(opts) : null; }
|