@innovatorved/code-lab 0.1.9 → 0.1.11
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 +87 -15
- package/dist/code-lab.d.ts +1 -1
- package/dist/code-lab.esm.js +218 -22
- package/dist/code-lab.js +217 -21
- package/dist/index.d.ts +1 -1
- package/dist/preview-sw.js +2 -2
- package/dist/runtime.esm.js +29 -4
- package/dist/runtime.js +29 -4
- package/dist/schemas.d.ts +1 -1
- package/dist/shell.esm.js +151 -9
- package/dist/shell.js +151 -9
- package/dist/terminal.esm.js +1 -1
- package/dist/terminal.js +1 -1
- package/package.json +1 -1
- package/src/code-lab.css +87 -15
- package/src/csp.ts +6 -1
- package/src/index.ts +1 -1
- package/src/runtime.ts +28 -3
- package/src/schemas.ts +1 -1
- package/src/shell.ts +150 -8
- package/src/workbench.ts +37 -8
package/src/workbench.ts
CHANGED
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
|
|
58
58
|
// The bundler rewrites this literal from package.json at build time. Keeping
|
|
59
59
|
// the fallback in sync lets tests require src/workbench.js directly.
|
|
60
|
-
const CODELAB_VERSION = '0.1.
|
|
60
|
+
const CODELAB_VERSION = '0.1.10';
|
|
61
61
|
|
|
62
62
|
// Ambient TypeScript declarations for Node.js built-ins inside Monaco
|
|
63
63
|
const NODE_AMBIENT_DTS = `
|
|
@@ -1364,6 +1364,11 @@ declare module 'bun:sqlite' {
|
|
|
1364
1364
|
this.explorerWidth = (typeof this.savedState?.explorerWidth === 'number' && this.savedState.explorerWidth >= 120)
|
|
1365
1365
|
? this.savedState.explorerWidth
|
|
1366
1366
|
: 196;
|
|
1367
|
+
// 0 = use the default 44% track; otherwise a pixel width chosen by dragging
|
|
1368
|
+
// the preview splitter.
|
|
1369
|
+
this.previewSplitWidth = (typeof this.savedState?.previewSplitWidth === 'number' && this.savedState.previewSplitWidth >= 200)
|
|
1370
|
+
? this.savedState.previewSplitWidth
|
|
1371
|
+
: 0;
|
|
1367
1372
|
this.folderSwitcherOpen = false;
|
|
1368
1373
|
this.creatingItem = null; // { type: 'file' | 'folder', parentFolder: string } | null
|
|
1369
1374
|
this.renamingItem = null;
|
|
@@ -1756,7 +1761,8 @@ declare module 'bun:sqlite' {
|
|
|
1756
1761
|
folders: Array.from(this.folders || []),
|
|
1757
1762
|
collapsedFolders: Array.from(this.collapsedFolders || []),
|
|
1758
1763
|
explorerFolder: this.explorerFolder || '',
|
|
1759
|
-
explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined
|
|
1764
|
+
explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined,
|
|
1765
|
+
previewSplitWidth: this.previewSplitWidth || undefined
|
|
1760
1766
|
};
|
|
1761
1767
|
this.savedState = state;
|
|
1762
1768
|
if (this.options && this.options.persistState === false) {
|
|
@@ -1982,7 +1988,12 @@ declare module 'bun:sqlite' {
|
|
|
1982
1988
|
const found = names.find(f => pattern.test(f));
|
|
1983
1989
|
if (found) return found;
|
|
1984
1990
|
if (kind === 'demo') {
|
|
1985
|
-
|
|
1991
|
+
const isConfigOrTest = f => /(^|\/)(test|.*\.(?:test|spec|config|d))\.(js|ts|mjs|cjs)$/i.test(f) || /(^|\/)\.[^/]+$/i.test(f);
|
|
1992
|
+
const hasHtmlEntry = Boolean(this.files['index.html'] || this.files['public/index.html']);
|
|
1993
|
+
if (hasHtmlEntry) {
|
|
1994
|
+
return names.find(f => /(^|\/)(server|app|demo)\.(js|ts)$/i.test(f) && !/^src\//i.test(f)) || null;
|
|
1995
|
+
}
|
|
1996
|
+
return names.find(f => /\.(js|ts)$/i.test(f) && !isConfigOrTest(f)) || null;
|
|
1986
1997
|
}
|
|
1987
1998
|
return null;
|
|
1988
1999
|
}
|
|
@@ -2018,7 +2029,9 @@ declare module 'bun:sqlite' {
|
|
|
2018
2029
|
const themeAttr = this.themeOption !== 'auto' ? `data-theme="${escapeHtml(this.themeOption)}"` : '';
|
|
2019
2030
|
const brandLabel = (this.title && this.title !== 'custom-lab' && this.title !== this.labId) ? this.title : 'code-lab';
|
|
2020
2031
|
const isGuideCollapsed = !this.hasGuidedLab || this.mode === 'sandbox' || !this.steps.length;
|
|
2021
|
-
const
|
|
2032
|
+
const shellVars = [`--cl-explorer-width:${Math.round(this.explorerWidth || 196)}px`];
|
|
2033
|
+
if (this.previewSplitWidth) shellVars.push(`--cl-preview-split-width:${Math.round(this.previewSplitWidth)}px`);
|
|
2034
|
+
const explorerStyle = `style="${shellVars.join(';')}"`;
|
|
2022
2035
|
this.container.innerHTML = `
|
|
2023
2036
|
<div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr} ${explorerStyle}>
|
|
2024
2037
|
<!-- Top Bar -->
|
|
@@ -3413,6 +3426,7 @@ declare module 'bun:sqlite' {
|
|
|
3413
3426
|
}
|
|
3414
3427
|
|
|
3415
3428
|
if (this.drawerTab === 'preview') {
|
|
3429
|
+
bodyEl.scrollTop = 0;
|
|
3416
3430
|
this._renderWebPreview(bodyEl);
|
|
3417
3431
|
return;
|
|
3418
3432
|
}
|
|
@@ -4712,8 +4726,10 @@ declare module 'bun:sqlite' {
|
|
|
4712
4726
|
return null;
|
|
4713
4727
|
}
|
|
4714
4728
|
|
|
4715
|
-
const
|
|
4716
|
-
|
|
4729
|
+
const hasSrcScripts = Boolean(this.files && Object.keys(this.files).some((f) => /^src\/.+\.(?:[cm]?jsx?|tsx?)$/i.test(f)));
|
|
4730
|
+
const rootDir = this.files['index.html'] ? '/workspace'
|
|
4731
|
+
: (this.files['public/index.html'] && !hasSrcScripts) ? '/workspace/public'
|
|
4732
|
+
: this.files['site/index.html'] ? '/workspace/site'
|
|
4717
4733
|
: '/workspace';
|
|
4718
4734
|
|
|
4719
4735
|
if (!this.shell || typeof this.shell.execute !== 'function') return null;
|
|
@@ -4861,9 +4877,11 @@ declare module 'bun:sqlite' {
|
|
|
4861
4877
|
_togglePreviewDock() {
|
|
4862
4878
|
this.previewState.dockMode = this.previewState.dockMode === 'split' ? 'bottom' : 'split';
|
|
4863
4879
|
this._previewRenderKey = null;
|
|
4880
|
+
const ws = this.container ? this.container.querySelector('.codelab-workspace') : null;
|
|
4864
4881
|
const splitHost = this.container ? this.container.querySelector('#cl-preview-split') : null;
|
|
4865
4882
|
const splitBar = this.container ? this.container.querySelector('#cl-splitter-preview') : null;
|
|
4866
4883
|
if (this.previewState.dockMode === 'split') {
|
|
4884
|
+
if (ws) ws.classList.add('has-preview-split');
|
|
4867
4885
|
if (splitBar) splitBar.style.display = 'block';
|
|
4868
4886
|
if (splitHost) {
|
|
4869
4887
|
splitHost.style.display = 'flex';
|
|
@@ -4875,6 +4893,7 @@ declare module 'bun:sqlite' {
|
|
|
4875
4893
|
this._renderDrawerBody();
|
|
4876
4894
|
}
|
|
4877
4895
|
} else {
|
|
4896
|
+
if (ws) ws.classList.remove('has-preview-split');
|
|
4878
4897
|
if (splitBar) splitBar.style.display = 'none';
|
|
4879
4898
|
if (splitHost) {
|
|
4880
4899
|
splitHost.style.display = 'none';
|
|
@@ -4974,9 +4993,11 @@ declare module 'bun:sqlite' {
|
|
|
4974
4993
|
this._warnPreviewIsolation();
|
|
4975
4994
|
const splitHost = this.container ? this.container.querySelector('#cl-preview-split') : null;
|
|
4976
4995
|
const splitBar = this.container ? this.container.querySelector('#cl-splitter-preview') : null;
|
|
4996
|
+
const ws = this.container ? this.container.querySelector('.codelab-workspace') : null;
|
|
4977
4997
|
|
|
4978
4998
|
let targetHost = bodyEl;
|
|
4979
4999
|
if (this.previewState.dockMode === 'split' && splitHost) {
|
|
5000
|
+
if (ws) ws.classList.add('has-preview-split');
|
|
4980
5001
|
if (splitBar) splitBar.style.display = 'block';
|
|
4981
5002
|
splitHost.style.display = 'flex';
|
|
4982
5003
|
if (bodyEl !== splitHost) {
|
|
@@ -4989,6 +5010,7 @@ declare module 'bun:sqlite' {
|
|
|
4989
5010
|
}
|
|
4990
5011
|
targetHost = splitHost;
|
|
4991
5012
|
} else {
|
|
5013
|
+
if (ws) ws.classList.remove('has-preview-split');
|
|
4992
5014
|
if (splitBar) splitBar.style.display = 'none';
|
|
4993
5015
|
if (splitHost && bodyEl !== splitHost) {
|
|
4994
5016
|
splitHost.style.display = 'none';
|
|
@@ -6698,8 +6720,10 @@ declare module 'bun:sqlite' {
|
|
|
6698
6720
|
const pSplitter = this.container.querySelector('#cl-splitter-preview');
|
|
6699
6721
|
if (pSplitter) {
|
|
6700
6722
|
pSplitter.addEventListener('dblclick', () => {
|
|
6701
|
-
|
|
6723
|
+
this.previewSplitWidth = 0;
|
|
6724
|
+
shell.style.removeProperty('--cl-preview-split-width');
|
|
6702
6725
|
if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
|
|
6726
|
+
this._saveState();
|
|
6703
6727
|
});
|
|
6704
6728
|
|
|
6705
6729
|
pSplitter.addEventListener('pointerdown', e => {
|
|
@@ -6714,6 +6738,7 @@ declare module 'bun:sqlite' {
|
|
|
6714
6738
|
const minW = 240;
|
|
6715
6739
|
const maxW = Math.max(minW, Math.floor(rect.width * 0.65));
|
|
6716
6740
|
const nextW = Math.min(maxW, Math.max(minW, Math.round(rect.right - ev.clientX)));
|
|
6741
|
+
this.previewSplitWidth = nextW;
|
|
6717
6742
|
shell.style.setProperty('--cl-preview-split-width', `${nextW}px`);
|
|
6718
6743
|
if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
|
|
6719
6744
|
};
|
|
@@ -6724,6 +6749,7 @@ declare module 'bun:sqlite' {
|
|
|
6724
6749
|
try { pSplitter.releasePointerCapture(ev.pointerId); } catch (err) { this.logger.debug('releasePointerCapture failed.', err); }
|
|
6725
6750
|
pSplitter.removeEventListener('pointermove', onMove);
|
|
6726
6751
|
pSplitter.removeEventListener('pointerup', onUp);
|
|
6752
|
+
this._saveState();
|
|
6727
6753
|
};
|
|
6728
6754
|
|
|
6729
6755
|
pSplitter.addEventListener('pointermove', onMove);
|
|
@@ -7191,6 +7217,9 @@ declare module 'bun:sqlite' {
|
|
|
7191
7217
|
if (this.isRunning) return;
|
|
7192
7218
|
const entry = this._findEntryFile('demo');
|
|
7193
7219
|
if (!entry) {
|
|
7220
|
+
if ((this.files['index.html'] || this.files['public/index.html']) && typeof this.previewApp === 'function') {
|
|
7221
|
+
return this.previewApp();
|
|
7222
|
+
}
|
|
7194
7223
|
this.terminalLogs.push({ type: 'stderr', text: 'No demo.js / demo.ts file found in this workspace.' });
|
|
7195
7224
|
this.drawerTab = 'terminal';
|
|
7196
7225
|
this._renderDrawerBody();
|
|
@@ -8066,7 +8095,7 @@ declare module 'bun:sqlite' {
|
|
|
8066
8095
|
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.
|
|
8067
8096
|
</p>
|
|
8068
8097
|
<div style="display:flex;gap:8px;">
|
|
8069
|
-
<input id="cl-clone-repo-input" type="text" placeholder="e.g.
|
|
8098
|
+
<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;" />
|
|
8070
8099
|
<button type="button" class="codelab-btn codelab-btn--primary" data-cl-action="confirm-clone-repo">Clone Repo</button>
|
|
8071
8100
|
</div>
|
|
8072
8101
|
</div>
|