@innovatorved/code-lab 0.1.8 → 0.1.9
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 +657 -0
- package/dist/code-lab.d.ts +1 -1
- package/dist/code-lab.esm.js +650 -32
- package/dist/code-lab.js +649 -31
- package/dist/index.d.ts +1 -1
- package/dist/preview-sw.js +196 -4
- package/dist/runtime.esm.js +1 -1
- package/dist/runtime.js +1 -1
- package/dist/schemas.d.ts +1 -1
- package/dist/shell.esm.js +119 -14
- package/dist/shell.js +119 -14
- package/dist/terminal.esm.js +1 -1
- package/dist/terminal.js +1 -1
- package/package.json +1 -1
- package/src/code-lab.css +657 -0
- package/src/csp.ts +195 -3
- package/src/index.ts +1 -1
- package/src/schemas.ts +1 -1
- package/src/shell.ts +118 -13
- package/src/workbench.ts +335 -14
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.9';
|
|
61
61
|
|
|
62
62
|
// Ambient TypeScript declarations for Node.js built-ins inside Monaco
|
|
63
63
|
const NODE_AMBIENT_DTS = `
|
|
@@ -1376,6 +1376,10 @@ declare module 'bun:sqlite' {
|
|
|
1376
1376
|
path: '/',
|
|
1377
1377
|
url: '',
|
|
1378
1378
|
frameMode: 'desktop', // 'desktop' | 'tablet' | 'mobile'
|
|
1379
|
+
dockMode: (options && options.previewDock === 'split') ? 'split' : 'bottom', // 'bottom' | 'split'
|
|
1380
|
+
maximized: false,
|
|
1381
|
+
consoleOpen: false,
|
|
1382
|
+
consoleLogs: [],
|
|
1379
1383
|
loading: false,
|
|
1380
1384
|
error: null,
|
|
1381
1385
|
srcdoc: '',
|
|
@@ -1387,6 +1391,7 @@ declare module 'bun:sqlite' {
|
|
|
1387
1391
|
this._previewSwRegistration = null;
|
|
1388
1392
|
this._previewViolationHandler = null;
|
|
1389
1393
|
this._swMessageHandler = null;
|
|
1394
|
+
this._beforeUnloadHandler = null;
|
|
1390
1395
|
this._portToasts = new Map();
|
|
1391
1396
|
this.isFullscreen = false;
|
|
1392
1397
|
this.isRunning = false;
|
|
@@ -1733,6 +1738,11 @@ declare module 'bun:sqlite' {
|
|
|
1733
1738
|
const key = `${this.mode}:${this.lang}`;
|
|
1734
1739
|
const customFiles = (this.savedState && this.savedState.customFiles) || {};
|
|
1735
1740
|
customFiles[key] = { ...this.files };
|
|
1741
|
+
const hasSnapshot = Object.assign(
|
|
1742
|
+
{},
|
|
1743
|
+
(this.savedState && this.savedState.hasSnapshot) || {},
|
|
1744
|
+
{ [key]: true }
|
|
1745
|
+
);
|
|
1736
1746
|
const completedArr = Array.from(this.completedSteps);
|
|
1737
1747
|
const state = {
|
|
1738
1748
|
mode: this.mode,
|
|
@@ -1740,6 +1750,7 @@ declare module 'bun:sqlite' {
|
|
|
1740
1750
|
activeStepIndex: this.activeStepIndex,
|
|
1741
1751
|
completedSteps: completedArr,
|
|
1742
1752
|
customFiles,
|
|
1753
|
+
hasSnapshot,
|
|
1743
1754
|
openTabs: Array.isArray(this.openTabs) ? [...this.openTabs] : undefined,
|
|
1744
1755
|
activeFile: this.activeFile,
|
|
1745
1756
|
folders: Array.from(this.folders || []),
|
|
@@ -1764,6 +1775,20 @@ declare module 'bun:sqlite' {
|
|
|
1764
1775
|
safeStorageSet('codelab_progress_' + this.labId, JSON.stringify(completedArr), this.logger, recordErr),
|
|
1765
1776
|
safeStorageSet('sd_codelab_' + this.labId, serialized, this.logger, recordErr)
|
|
1766
1777
|
];
|
|
1778
|
+
if (root.CodeLabStorage && typeof root.CodeLabStorage.createWorkspaceStorage === 'function') {
|
|
1779
|
+
try {
|
|
1780
|
+
if (!this._idbStorage) {
|
|
1781
|
+
this._idbStorage = root.CodeLabStorage.createWorkspaceStorage({ keyPrefix: STORAGE_PREFIX });
|
|
1782
|
+
}
|
|
1783
|
+
if (this._idbStorage && typeof this._idbStorage.save === 'function') {
|
|
1784
|
+
Promise.resolve(this._idbStorage.save(this.labId, state)).catch((err) => {
|
|
1785
|
+
this.logger.debug('Async WorkspaceStorage save skipped.', err);
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
} catch (err) {
|
|
1789
|
+
this.logger.debug('WorkspaceStorage initialization skipped.', err);
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1767
1792
|
if (persisted.includes(false)) {
|
|
1768
1793
|
this._reportPersistenceFailure(safeStorageSet._lastError);
|
|
1769
1794
|
} else {
|
|
@@ -1916,6 +1941,9 @@ declare module 'bun:sqlite' {
|
|
|
1916
1941
|
const key = `${this.mode}:${this.lang}`;
|
|
1917
1942
|
const saved = this.savedState.customFiles?.[key];
|
|
1918
1943
|
const base = this._getBaseFilesForModeAndLang(this.mode, this.lang);
|
|
1944
|
+
if (this.savedState && this.savedState.hasSnapshot && this.savedState.hasSnapshot[key] && saved && typeof saved === 'object') {
|
|
1945
|
+
return { ...saved };
|
|
1946
|
+
}
|
|
1919
1947
|
if (saved && Object.keys(saved).length > 0) {
|
|
1920
1948
|
return { ...base, ...saved };
|
|
1921
1949
|
}
|
|
@@ -2128,6 +2156,10 @@ declare module 'bun:sqlite' {
|
|
|
2128
2156
|
<div class="codelab-empty-editor" id="cl-empty-editor" style="display:none"></div>
|
|
2129
2157
|
</div>
|
|
2130
2158
|
</div>
|
|
2159
|
+
|
|
2160
|
+
<!-- Right-Hand Split Web Preview Pane -->
|
|
2161
|
+
<div class="codelab-splitter-preview" id="cl-splitter-preview" role="separator" aria-orientation="vertical" title="Drag to resize web preview (double-click to reset)" style="display:none"></div>
|
|
2162
|
+
<div class="codelab-preview-split" id="cl-preview-split" aria-label="In-Browser Web Preview" style="display:none"></div>
|
|
2131
2163
|
</div>
|
|
2132
2164
|
|
|
2133
2165
|
<!-- Interactive Horizontal Splitter -->
|
|
@@ -4509,6 +4541,10 @@ declare module 'bun:sqlite' {
|
|
|
4509
4541
|
type: level === 'error' ? 'stderr' : 'stdout',
|
|
4510
4542
|
text: `[Preview ${level.toUpperCase()}] ${text}`
|
|
4511
4543
|
});
|
|
4544
|
+
if (!Array.isArray(this.previewState.consoleLogs)) this.previewState.consoleLogs = [];
|
|
4545
|
+
this.previewState.consoleLogs.push({ level, text, timestamp: new Date().toLocaleTimeString() });
|
|
4546
|
+
if (this.previewState.consoleLogs.length > 200) this.previewState.consoleLogs.shift();
|
|
4547
|
+
this._updatePreviewConsoleUI();
|
|
4512
4548
|
this._emitEvent('preview-console', { level, text, args });
|
|
4513
4549
|
} else if (data.type === 'codelab:preview-error') {
|
|
4514
4550
|
const msg = String(data.message || 'Uncaught runtime error');
|
|
@@ -4523,9 +4559,66 @@ declare module 'bun:sqlite' {
|
|
|
4523
4559
|
type: 'stderr',
|
|
4524
4560
|
text: `[Preview ERROR] ${msg}${data.stack ? '\n' + String(data.stack) : ''}`
|
|
4525
4561
|
});
|
|
4562
|
+
if (!Array.isArray(this.previewState.consoleLogs)) this.previewState.consoleLogs = [];
|
|
4563
|
+
this.previewState.consoleLogs.push({
|
|
4564
|
+
level: 'error',
|
|
4565
|
+
text: `${msg}${data.stack ? '\n' + String(data.stack) : ''}`,
|
|
4566
|
+
timestamp: new Date().toLocaleTimeString()
|
|
4567
|
+
});
|
|
4568
|
+
this._updatePreviewConsoleUI();
|
|
4526
4569
|
this._emitEvent('preview-error', this.previewState.runtimeError);
|
|
4527
4570
|
} else if (data.type === 'codelab:preview-error-clear') {
|
|
4528
4571
|
this.previewState.runtimeError = null;
|
|
4572
|
+
} else if (data.type === 'codelab:preview-fetch') {
|
|
4573
|
+
const reqId = data.reqId || data.id;
|
|
4574
|
+
const targetPort = Number(data.port) || this.previewState.port || this._firstListeningPort() || 3000;
|
|
4575
|
+
const reqPath = data.path ? (String(data.path).startsWith('/') ? String(data.path) : '/' + String(data.path)) : '/';
|
|
4576
|
+
const targetUrl = String(data.url || `http://127.0.0.1:${targetPort}${reqPath}`);
|
|
4577
|
+
this._dispatchPreviewRequest({
|
|
4578
|
+
port: targetPort,
|
|
4579
|
+
url: targetUrl,
|
|
4580
|
+
method: data.method || 'GET',
|
|
4581
|
+
headers: data.headers || {},
|
|
4582
|
+
body: data.body !== undefined ? data.body : null
|
|
4583
|
+
})
|
|
4584
|
+
.then((res) => {
|
|
4585
|
+
const netPill = this.container ? this.container.querySelector('#cl-network-pill') : null;
|
|
4586
|
+
if (netPill) netPill.textContent = `${(this.lastHttpTrace || []).length} reqs`;
|
|
4587
|
+
if (this.drawerTab === 'network') this._renderDrawerBody();
|
|
4588
|
+
if (iframe && iframe.contentWindow && typeof iframe.contentWindow.postMessage === 'function') {
|
|
4589
|
+
iframe.contentWindow.postMessage({
|
|
4590
|
+
type: 'codelab:preview-fetch-res',
|
|
4591
|
+
reqId,
|
|
4592
|
+
id: reqId,
|
|
4593
|
+
status: res.status || 200,
|
|
4594
|
+
statusText: res.statusText || 'OK',
|
|
4595
|
+
headers: res.headers || {},
|
|
4596
|
+
body: res.body || ''
|
|
4597
|
+
}, '*');
|
|
4598
|
+
}
|
|
4599
|
+
})
|
|
4600
|
+
.catch((err) => {
|
|
4601
|
+
if (iframe && iframe.contentWindow && typeof iframe.contentWindow.postMessage === 'function') {
|
|
4602
|
+
iframe.contentWindow.postMessage({
|
|
4603
|
+
type: 'codelab:preview-fetch-res',
|
|
4604
|
+
reqId,
|
|
4605
|
+
id: reqId,
|
|
4606
|
+
error: String((err && err.message) || err)
|
|
4607
|
+
}, '*');
|
|
4608
|
+
}
|
|
4609
|
+
});
|
|
4610
|
+
} else if (data.type === 'codelab:preview-navigate') {
|
|
4611
|
+
const navHref = data.href || (data.path ? (data.port ? `http://127.0.0.1:${data.port}${data.path}` : String(data.path)) : '');
|
|
4612
|
+
if (navHref) {
|
|
4613
|
+
this._previewGo(String(navHref));
|
|
4614
|
+
}
|
|
4615
|
+
} else if (data.type === 'codelab:preview-url-change') {
|
|
4616
|
+
if (data.path && typeof data.path === 'string') {
|
|
4617
|
+
this.previewState.path = data.path.startsWith('/') ? data.path : '/' + data.path;
|
|
4618
|
+
this.previewState.url = this._previewUrl();
|
|
4619
|
+
const input = this.container ? this.container.querySelector('#cl-preview-url-input') : null;
|
|
4620
|
+
if (input) input.value = this.previewState.url;
|
|
4621
|
+
}
|
|
4529
4622
|
}
|
|
4530
4623
|
};
|
|
4531
4624
|
window.addEventListener('message', this._previewViolationHandler);
|
|
@@ -4589,7 +4682,12 @@ declare module 'bun:sqlite' {
|
|
|
4589
4682
|
this.previewHistory = this.previewHistory.slice(0, this.previewHistoryIdx + 1);
|
|
4590
4683
|
this.previewHistory.push(this.previewState.url);
|
|
4591
4684
|
this.previewHistoryIdx = this.previewHistory.length - 1;
|
|
4592
|
-
this.
|
|
4685
|
+
if (this.previewState.dockMode === 'split') {
|
|
4686
|
+
const splitHost = this.container ? this.container.querySelector('#cl-preview-split') : null;
|
|
4687
|
+
if (splitHost) this._renderWebPreview(splitHost);
|
|
4688
|
+
} else {
|
|
4689
|
+
this.switchDrawerTab('preview');
|
|
4690
|
+
}
|
|
4593
4691
|
return this._previewLoadPromise || Promise.resolve();
|
|
4594
4692
|
}
|
|
4595
4693
|
|
|
@@ -4708,7 +4806,12 @@ declare module 'bun:sqlite' {
|
|
|
4708
4806
|
this.previewHistory = this.previewHistory.slice(0, this.previewHistoryIdx + 1);
|
|
4709
4807
|
this.previewHistory.push(url);
|
|
4710
4808
|
this.previewHistoryIdx = this.previewHistory.length - 1;
|
|
4711
|
-
this.
|
|
4809
|
+
if (this.previewState.dockMode === 'split') {
|
|
4810
|
+
const splitHost = this.container ? this.container.querySelector('#cl-preview-split') : null;
|
|
4811
|
+
if (splitHost) this._renderWebPreview(splitHost);
|
|
4812
|
+
} else {
|
|
4813
|
+
this.switchDrawerTab('preview');
|
|
4814
|
+
}
|
|
4712
4815
|
return this._previewLoadPromise || Promise.resolve();
|
|
4713
4816
|
}
|
|
4714
4817
|
|
|
@@ -4749,6 +4852,94 @@ declare module 'bun:sqlite' {
|
|
|
4749
4852
|
if (!['desktop', 'tablet', 'mobile'].includes(mode)) return;
|
|
4750
4853
|
this.previewState.frameMode = mode;
|
|
4751
4854
|
this._renderDrawerBody();
|
|
4855
|
+
if (this.previewState.dockMode === 'split') {
|
|
4856
|
+
const splitHost = this.container ? this.container.querySelector('#cl-preview-split') : null;
|
|
4857
|
+
if (splitHost) this._renderWebPreview(splitHost);
|
|
4858
|
+
}
|
|
4859
|
+
}
|
|
4860
|
+
|
|
4861
|
+
_togglePreviewDock() {
|
|
4862
|
+
this.previewState.dockMode = this.previewState.dockMode === 'split' ? 'bottom' : 'split';
|
|
4863
|
+
this._previewRenderKey = null;
|
|
4864
|
+
const splitHost = this.container ? this.container.querySelector('#cl-preview-split') : null;
|
|
4865
|
+
const splitBar = this.container ? this.container.querySelector('#cl-splitter-preview') : null;
|
|
4866
|
+
if (this.previewState.dockMode === 'split') {
|
|
4867
|
+
if (splitBar) splitBar.style.display = 'block';
|
|
4868
|
+
if (splitHost) {
|
|
4869
|
+
splitHost.style.display = 'flex';
|
|
4870
|
+
this._renderWebPreview(splitHost);
|
|
4871
|
+
}
|
|
4872
|
+
if (this.drawerTab === 'preview') {
|
|
4873
|
+
this.switchDrawerTab('terminal');
|
|
4874
|
+
} else {
|
|
4875
|
+
this._renderDrawerBody();
|
|
4876
|
+
}
|
|
4877
|
+
} else {
|
|
4878
|
+
if (splitBar) splitBar.style.display = 'none';
|
|
4879
|
+
if (splitHost) {
|
|
4880
|
+
splitHost.style.display = 'none';
|
|
4881
|
+
splitHost.innerHTML = '';
|
|
4882
|
+
}
|
|
4883
|
+
this.switchDrawerTab('preview');
|
|
4884
|
+
}
|
|
4885
|
+
if (this.editor && typeof this.editor.layout === 'function') {
|
|
4886
|
+
setTimeout(() => {
|
|
4887
|
+
if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
|
|
4888
|
+
}, 30);
|
|
4889
|
+
}
|
|
4890
|
+
}
|
|
4891
|
+
|
|
4892
|
+
_togglePreviewMaximize() {
|
|
4893
|
+
this.previewState.maximized = !this.previewState.maximized;
|
|
4894
|
+
const previewEl = this.container ? this.container.querySelector('.codelab-preview') : null;
|
|
4895
|
+
if (previewEl) {
|
|
4896
|
+
previewEl.classList.toggle('is-maximized', Boolean(this.previewState.maximized));
|
|
4897
|
+
}
|
|
4898
|
+
const maxBtn = this.container ? this.container.querySelector('[data-cl-action="preview-maximize"]') : null;
|
|
4899
|
+
if (maxBtn) {
|
|
4900
|
+
maxBtn.classList.toggle('active', Boolean(this.previewState.maximized));
|
|
4901
|
+
}
|
|
4902
|
+
}
|
|
4903
|
+
|
|
4904
|
+
_togglePreviewConsole() {
|
|
4905
|
+
this.previewState.consoleOpen = !this.previewState.consoleOpen;
|
|
4906
|
+
this._updatePreviewConsoleUI();
|
|
4907
|
+
}
|
|
4908
|
+
|
|
4909
|
+
_clearPreviewConsole() {
|
|
4910
|
+
this.previewState.consoleLogs = [];
|
|
4911
|
+
this._updatePreviewConsoleUI();
|
|
4912
|
+
}
|
|
4913
|
+
|
|
4914
|
+
_updatePreviewConsoleUI() {
|
|
4915
|
+
if (!this.container) return;
|
|
4916
|
+
const consoleDrawer = this.container.querySelector('#cl-preview-console');
|
|
4917
|
+
const consoleBody = this.container.querySelector('#cl-preview-console-body');
|
|
4918
|
+
const consolePill = this.container.querySelector('#cl-preview-console-pill');
|
|
4919
|
+
const consoleBtn = this.container.querySelector('[data-cl-action="preview-console-toggle"]');
|
|
4920
|
+
const logs = Array.isArray(this.previewState.consoleLogs) ? this.previewState.consoleLogs : [];
|
|
4921
|
+
if (consolePill) {
|
|
4922
|
+
consolePill.textContent = String(logs.length);
|
|
4923
|
+
}
|
|
4924
|
+
if (consoleBtn) {
|
|
4925
|
+
consoleBtn.classList.toggle('active', Boolean(this.previewState.consoleOpen));
|
|
4926
|
+
}
|
|
4927
|
+
if (consoleDrawer) {
|
|
4928
|
+
consoleDrawer.style.display = this.previewState.consoleOpen ? 'flex' : 'none';
|
|
4929
|
+
}
|
|
4930
|
+
if (consoleBody) {
|
|
4931
|
+
if (logs.length === 0) {
|
|
4932
|
+
consoleBody.innerHTML = `<div class="codelab-preview-console__empty">No console output from preview frame yet.</div>`;
|
|
4933
|
+
} else {
|
|
4934
|
+
consoleBody.innerHTML = logs.map((entry) => `
|
|
4935
|
+
<div class="codelab-preview-console__row codelab-preview-console__row--${escapeHtml(entry.level || 'log')}">
|
|
4936
|
+
<span class="codelab-preview-console__time">${escapeHtml(entry.timestamp || '')}</span>
|
|
4937
|
+
<span class="codelab-preview-console__text">${escapeHtml(entry.text || '')}</span>
|
|
4938
|
+
</div>
|
|
4939
|
+
`).join('');
|
|
4940
|
+
consoleBody.scrollTop = consoleBody.scrollHeight;
|
|
4941
|
+
}
|
|
4942
|
+
}
|
|
4752
4943
|
}
|
|
4753
4944
|
|
|
4754
4945
|
_renderWebPreviewControls() {
|
|
@@ -4760,6 +4951,7 @@ declare module 'bun:sqlite' {
|
|
|
4760
4951
|
if (backBtn) backBtn.disabled = this.previewHistoryIdx <= 0;
|
|
4761
4952
|
const fwdBtn = this.container.querySelector('[data-cl-action="preview-forward"]');
|
|
4762
4953
|
if (fwdBtn) fwdBtn.disabled = this.previewHistoryIdx >= this.previewHistory.length - 1;
|
|
4954
|
+
this._updatePreviewConsoleUI();
|
|
4763
4955
|
}
|
|
4764
4956
|
|
|
4765
4957
|
_popoutPreview() {
|
|
@@ -4780,8 +4972,32 @@ declare module 'bun:sqlite' {
|
|
|
4780
4972
|
_renderWebPreview(bodyEl) {
|
|
4781
4973
|
if (!bodyEl) return;
|
|
4782
4974
|
this._warnPreviewIsolation();
|
|
4783
|
-
const
|
|
4784
|
-
|
|
4975
|
+
const splitHost = this.container ? this.container.querySelector('#cl-preview-split') : null;
|
|
4976
|
+
const splitBar = this.container ? this.container.querySelector('#cl-splitter-preview') : null;
|
|
4977
|
+
|
|
4978
|
+
let targetHost = bodyEl;
|
|
4979
|
+
if (this.previewState.dockMode === 'split' && splitHost) {
|
|
4980
|
+
if (splitBar) splitBar.style.display = 'block';
|
|
4981
|
+
splitHost.style.display = 'flex';
|
|
4982
|
+
if (bodyEl !== splitHost) {
|
|
4983
|
+
bodyEl.innerHTML = `
|
|
4984
|
+
<div class="codelab-preview-split-notice">
|
|
4985
|
+
<span>Web Preview is docked to the right split pane.</span>
|
|
4986
|
+
<button type="button" class="codelab-btn codelab-btn--sm" data-cl-action="preview-dock-toggle">Dock to Bottom Drawer</button>
|
|
4987
|
+
</div>
|
|
4988
|
+
`;
|
|
4989
|
+
}
|
|
4990
|
+
targetHost = splitHost;
|
|
4991
|
+
} else {
|
|
4992
|
+
if (splitBar) splitBar.style.display = 'none';
|
|
4993
|
+
if (splitHost && bodyEl !== splitHost) {
|
|
4994
|
+
splitHost.style.display = 'none';
|
|
4995
|
+
splitHost.innerHTML = '';
|
|
4996
|
+
}
|
|
4997
|
+
}
|
|
4998
|
+
|
|
4999
|
+
const renderKey = `${this.previewState.port}|${this.previewState.path}|${this.previewState.frameMode}|${this.previewState.dockMode}|${this._previewSwReady}`;
|
|
5000
|
+
if (targetHost.querySelector && targetHost.querySelector('.codelab-preview') && this._previewRenderKey === renderKey) {
|
|
4785
5001
|
this._renderWebPreviewControls();
|
|
4786
5002
|
return;
|
|
4787
5003
|
}
|
|
@@ -4812,8 +5028,11 @@ declare module 'bun:sqlite' {
|
|
|
4812
5028
|
? 'Strict Content-Security-Policy: previews cannot reach any remote host.'
|
|
4813
5029
|
: `Previews may load scripts, fonts and data from: ${cspHosts.join(', ') || 'no remote hosts'}. Use previewCsp: 'strict' to block remote hosts.`;
|
|
4814
5030
|
|
|
4815
|
-
|
|
4816
|
-
|
|
5031
|
+
const logsCount = Array.isArray(this.previewState.consoleLogs) ? this.previewState.consoleLogs.length : 0;
|
|
5032
|
+
const isSplit = this.previewState.dockMode === 'split';
|
|
5033
|
+
|
|
5034
|
+
targetHost.innerHTML = `
|
|
5035
|
+
<div class="codelab-preview ${this.previewState.maximized ? 'is-maximized' : ''}">
|
|
4817
5036
|
<div class="codelab-preview-chrome">
|
|
4818
5037
|
<div class="codelab-preview-nav">
|
|
4819
5038
|
<button type="button" class="codelab-preview-btn" data-cl-action="preview-back" title="Back" ${this.previewHistoryIdx <= 0 ? 'disabled' : ''}>${CL_ICONS.arrowLeft || '←'}</button>
|
|
@@ -4829,11 +5048,30 @@ declare module 'bun:sqlite' {
|
|
|
4829
5048
|
</div>
|
|
4830
5049
|
<span class="codelab-preview-csp" id="cl-preview-csp-badge" title="${escapeHtml(cspBadgeTitle)}">${escapeHtml(cspBadge)}</span>
|
|
4831
5050
|
<span class="codelab-preview-csp codelab-preview-csp--blocked" id="cl-preview-csp-status" role="status" hidden></span>
|
|
5051
|
+
<button type="button" class="codelab-preview-btn ${this.previewState.consoleOpen ? 'active' : ''}" data-cl-action="preview-console-toggle" title="Toggle Preview Console">
|
|
5052
|
+
${CL_ICONS.terminal || '>_'} <span class="codelab-preview-console-pill" id="cl-preview-console-pill">${logsCount}</span>
|
|
5053
|
+
</button>
|
|
5054
|
+
<button type="button" class="codelab-preview-btn ${isSplit ? 'active' : ''}" data-cl-action="preview-dock-toggle" title="${isSplit ? 'Dock Preview to Bottom Drawer' : 'Dock Preview to Right Split Pane'}">
|
|
5055
|
+
${CL_ICONS.layout || '◫'}
|
|
5056
|
+
</button>
|
|
5057
|
+
<button type="button" class="codelab-preview-btn ${this.previewState.maximized ? 'active' : ''}" data-cl-action="preview-maximize" title="Maximize / Restore Preview">
|
|
5058
|
+
${CL_ICONS.maximize || '⛶'}
|
|
5059
|
+
</button>
|
|
4832
5060
|
<button type="button" class="codelab-btn codelab-btn--sm" data-cl-action="preview-popout" title="Open in a new browser tab">${CL_ICONS.externalLink || '↗'} <span>Pop Out</span></button>
|
|
4833
5061
|
</div>
|
|
4834
5062
|
<div class="codelab-preview-viewport codelab-preview-viewport--${this.previewState.frameMode}" id="cl-preview-viewport">
|
|
4835
5063
|
<iframe class="codelab-preview-iframe" id="cl-preview-iframe" sandbox="allow-scripts allow-forms allow-modals" allow="camera 'none'; microphone 'none'; geolocation 'none'; payment 'none'; usb 'none'" referrerpolicy="no-referrer-when-downgrade" title="Web Preview"></iframe>
|
|
4836
5064
|
</div>
|
|
5065
|
+
<div class="codelab-preview-console" id="cl-preview-console" style="display:${this.previewState.consoleOpen ? 'flex' : 'none'}">
|
|
5066
|
+
<div class="codelab-preview-console__bar">
|
|
5067
|
+
<span>Preview Console</span>
|
|
5068
|
+
<div style="display:flex;align-items:center;gap:6px;">
|
|
5069
|
+
<button type="button" class="codelab-btn codelab-btn--sm" data-cl-action="preview-console-clear">Clear</button>
|
|
5070
|
+
<button type="button" class="codelab-btn codelab-btn--sm" data-cl-action="preview-console-toggle">Close</button>
|
|
5071
|
+
</div>
|
|
5072
|
+
</div>
|
|
5073
|
+
<div class="codelab-preview-console__body" id="cl-preview-console-body"></div>
|
|
5074
|
+
</div>
|
|
4837
5075
|
${servers.length
|
|
4838
5076
|
? `<div class="codelab-preview-hint">Serving from the in-browser virtual runtime. Use Pop Out for a standalone tab.</div>`
|
|
4839
5077
|
: `<div class="codelab-preview-empty">
|
|
@@ -4846,6 +5084,7 @@ declare module 'bun:sqlite' {
|
|
|
4846
5084
|
</div>
|
|
4847
5085
|
`;
|
|
4848
5086
|
this._updatePreviewCspStatus();
|
|
5087
|
+
this._updatePreviewConsoleUI();
|
|
4849
5088
|
this._loadPreviewFrame();
|
|
4850
5089
|
}
|
|
4851
5090
|
|
|
@@ -4862,11 +5101,12 @@ declare module 'bun:sqlite' {
|
|
|
4862
5101
|
this.previewState.error = 'No port selected';
|
|
4863
5102
|
return Promise.resolve();
|
|
4864
5103
|
}
|
|
5104
|
+
this._syncFilesToShellVfs();
|
|
4865
5105
|
const fullUrl = this._previewUrl();
|
|
4866
5106
|
this.previewState.loading = true;
|
|
4867
5107
|
this.previewState.error = null;
|
|
4868
5108
|
|
|
4869
|
-
if (this._previewSwReady) {
|
|
5109
|
+
if (this.options && this.options.useServiceWorkerForIframe === true && this._previewSwReady) {
|
|
4870
5110
|
try {
|
|
4871
5111
|
const u = new URL(fullUrl);
|
|
4872
5112
|
if (typeof iframe.removeAttribute === 'function') iframe.removeAttribute('srcdoc');
|
|
@@ -4878,8 +5118,8 @@ declare module 'bun:sqlite' {
|
|
|
4878
5118
|
}
|
|
4879
5119
|
}
|
|
4880
5120
|
|
|
4881
|
-
//
|
|
4882
|
-
//
|
|
5121
|
+
// Direct virtual dispatch + srcdoc injection guarantees zero Service Worker
|
|
5122
|
+
// race conditions and 100% deterministic loading inside sandboxed iframes.
|
|
4883
5123
|
return this._dispatchPreviewRequest({ port, url: fullUrl, method: 'GET' })
|
|
4884
5124
|
.then((res) => {
|
|
4885
5125
|
let body = res.body || '';
|
|
@@ -5265,7 +5505,7 @@ declare module 'bun:sqlite' {
|
|
|
5265
5505
|
this.logger.debug(`Could not sync "${filename}" to shell VFS on edit.`, err);
|
|
5266
5506
|
}
|
|
5267
5507
|
}
|
|
5268
|
-
if (this.drawerTab === 'preview' && this.previewState && this.previewState.port) {
|
|
5508
|
+
if ((this.drawerTab === 'preview' || (this.previewState && this.previewState.dockMode === 'split')) && this.previewState && this.previewState.port) {
|
|
5269
5509
|
if (this._previewReloadTimer) {
|
|
5270
5510
|
clearTimeout(this._previewReloadTimer);
|
|
5271
5511
|
}
|
|
@@ -5441,6 +5681,16 @@ declare module 'bun:sqlite' {
|
|
|
5441
5681
|
};
|
|
5442
5682
|
if (typeof document !== 'undefined') {
|
|
5443
5683
|
document.addEventListener('keydown', this._escHandler);
|
|
5684
|
+
this._beforeUnloadHandler = () => {
|
|
5685
|
+
if (document.visibilityState === 'hidden') {
|
|
5686
|
+
try {
|
|
5687
|
+
this._saveState();
|
|
5688
|
+
} catch (err) {
|
|
5689
|
+
void err;
|
|
5690
|
+
}
|
|
5691
|
+
}
|
|
5692
|
+
};
|
|
5693
|
+
document.addEventListener('visibilitychange', this._beforeUnloadHandler);
|
|
5444
5694
|
}
|
|
5445
5695
|
|
|
5446
5696
|
this.container.addEventListener('keydown', e => {
|
|
@@ -5887,15 +6137,29 @@ declare module 'bun:sqlite' {
|
|
|
5887
6137
|
this._previewSetFrameMode(actionBtn.dataset.mode);
|
|
5888
6138
|
} else if (action === 'preview-popout') {
|
|
5889
6139
|
this._popoutPreview();
|
|
6140
|
+
} else if (action === 'preview-dock-toggle') {
|
|
6141
|
+
this._togglePreviewDock();
|
|
6142
|
+
} else if (action === 'preview-maximize') {
|
|
6143
|
+
this._togglePreviewMaximize();
|
|
6144
|
+
} else if (action === 'preview-console-toggle') {
|
|
6145
|
+
this._togglePreviewConsole();
|
|
6146
|
+
} else if (action === 'preview-console-clear') {
|
|
6147
|
+
this._clearPreviewConsole();
|
|
5890
6148
|
} else if (action === 'open-port-client') {
|
|
5891
|
-
const port = actionBtn.dataset.port;
|
|
6149
|
+
const port = actionBtn.dataset.port || actionBtn.dataset.clPort;
|
|
5892
6150
|
if (port) {
|
|
5893
6151
|
this.httpClientUrl = `http://localhost:${port}/`;
|
|
6152
|
+
if (this.httpClientState) {
|
|
6153
|
+
this.httpClientState.url = `http://localhost:${port}/`;
|
|
6154
|
+
}
|
|
5894
6155
|
this._renderDrawerBody();
|
|
5895
6156
|
}
|
|
5896
6157
|
} else if (action === 'stop-port') {
|
|
5897
|
-
const port = Number(actionBtn.dataset.port);
|
|
6158
|
+
const port = Number(actionBtn.dataset.port || actionBtn.dataset.clPort);
|
|
5898
6159
|
if (port) {
|
|
6160
|
+
if (this.portTable && typeof this.portTable.closeServer === 'function') {
|
|
6161
|
+
this.portTable.closeServer(port);
|
|
6162
|
+
}
|
|
5899
6163
|
if (this.shell && this.shell.portTable && typeof this.shell.portTable.unregister === 'function') {
|
|
5900
6164
|
this.shell.portTable.unregister(port);
|
|
5901
6165
|
}
|
|
@@ -5905,18 +6169,32 @@ declare module 'bun:sqlite' {
|
|
|
5905
6169
|
} else if (action === 'http-send') {
|
|
5906
6170
|
this._sendHttpClientRequest();
|
|
5907
6171
|
} else if (action === 'http-tab') {
|
|
5908
|
-
|
|
6172
|
+
const nextTab = actionBtn.dataset.tab || actionBtn.dataset.clHttpTab || actionBtn.dataset.httpTab || 'preview';
|
|
6173
|
+
this.httpActiveTab = nextTab;
|
|
6174
|
+
if (this.httpClientState) {
|
|
6175
|
+
this.httpClientState.activeResponseTab = nextTab;
|
|
6176
|
+
}
|
|
5909
6177
|
this._renderDrawerBody();
|
|
5910
6178
|
} else if (action === 'clear-net-traces') {
|
|
5911
6179
|
this.lastHttpTrace = [];
|
|
5912
6180
|
this.selectedNetTraceIdx = null;
|
|
6181
|
+
if (this.networkFilter) {
|
|
6182
|
+
this.networkFilter.selectedTraceId = null;
|
|
6183
|
+
}
|
|
5913
6184
|
this._renderDrawerBody();
|
|
5914
6185
|
} else if (action === 'select-net-trace') {
|
|
6186
|
+
const traceId = actionBtn.dataset.traceId || actionBtn.dataset.clTraceId || null;
|
|
5915
6187
|
const idx = Number(actionBtn.dataset.traceIdx);
|
|
5916
6188
|
this.selectedNetTraceIdx = Number.isNaN(idx) ? null : idx;
|
|
6189
|
+
if (this.networkFilter) {
|
|
6190
|
+
this.networkFilter.selectedTraceId = traceId;
|
|
6191
|
+
}
|
|
5917
6192
|
this._renderDrawerBody();
|
|
5918
6193
|
} else if (action === 'close-net-detail') {
|
|
5919
6194
|
this.selectedNetTraceIdx = null;
|
|
6195
|
+
if (this.networkFilter) {
|
|
6196
|
+
this.networkFilter.selectedTraceId = null;
|
|
6197
|
+
}
|
|
5920
6198
|
this._renderDrawerBody();
|
|
5921
6199
|
}
|
|
5922
6200
|
return;
|
|
@@ -6416,6 +6694,42 @@ declare module 'bun:sqlite' {
|
|
|
6416
6694
|
fSplitter.addEventListener('pointerup', onUp);
|
|
6417
6695
|
});
|
|
6418
6696
|
}
|
|
6697
|
+
|
|
6698
|
+
const pSplitter = this.container.querySelector('#cl-splitter-preview');
|
|
6699
|
+
if (pSplitter) {
|
|
6700
|
+
pSplitter.addEventListener('dblclick', () => {
|
|
6701
|
+
shell.style.setProperty('--cl-preview-split-width', '44%');
|
|
6702
|
+
if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
|
|
6703
|
+
});
|
|
6704
|
+
|
|
6705
|
+
pSplitter.addEventListener('pointerdown', e => {
|
|
6706
|
+
e.preventDefault();
|
|
6707
|
+
pSplitter.classList.add('is-dragging');
|
|
6708
|
+
shell.classList.add('is-resizing');
|
|
6709
|
+
try { pSplitter.setPointerCapture(e.pointerId); } catch (err) { this.logger.debug('setPointerCapture failed.', err); }
|
|
6710
|
+
|
|
6711
|
+
const onMove = ev => {
|
|
6712
|
+
const ws = this.container.querySelector('.codelab-workspace');
|
|
6713
|
+
const rect = (ws || shell).getBoundingClientRect();
|
|
6714
|
+
const minW = 240;
|
|
6715
|
+
const maxW = Math.max(minW, Math.floor(rect.width * 0.65));
|
|
6716
|
+
const nextW = Math.min(maxW, Math.max(minW, Math.round(rect.right - ev.clientX)));
|
|
6717
|
+
shell.style.setProperty('--cl-preview-split-width', `${nextW}px`);
|
|
6718
|
+
if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
|
|
6719
|
+
};
|
|
6720
|
+
|
|
6721
|
+
const onUp = ev => {
|
|
6722
|
+
pSplitter.classList.remove('is-dragging');
|
|
6723
|
+
shell.classList.remove('is-resizing');
|
|
6724
|
+
try { pSplitter.releasePointerCapture(ev.pointerId); } catch (err) { this.logger.debug('releasePointerCapture failed.', err); }
|
|
6725
|
+
pSplitter.removeEventListener('pointermove', onMove);
|
|
6726
|
+
pSplitter.removeEventListener('pointerup', onUp);
|
|
6727
|
+
};
|
|
6728
|
+
|
|
6729
|
+
pSplitter.addEventListener('pointermove', onMove);
|
|
6730
|
+
pSplitter.addEventListener('pointerup', onUp);
|
|
6731
|
+
});
|
|
6732
|
+
}
|
|
6419
6733
|
}
|
|
6420
6734
|
|
|
6421
6735
|
selectStep(idx, shouldJump = true) {
|
|
@@ -6644,6 +6958,9 @@ declare module 'bun:sqlite' {
|
|
|
6644
6958
|
if (this.savedState.customFiles) {
|
|
6645
6959
|
delete this.savedState.customFiles[key];
|
|
6646
6960
|
}
|
|
6961
|
+
if (this.savedState.hasSnapshot) {
|
|
6962
|
+
delete this.savedState.hasSnapshot[key];
|
|
6963
|
+
}
|
|
6647
6964
|
this._saveState();
|
|
6648
6965
|
this._syncAllModels();
|
|
6649
6966
|
this._syncActiveFileToView();
|
|
@@ -7951,6 +8268,10 @@ declare module 'bun:sqlite' {
|
|
|
7951
8268
|
if (this._escHandler && typeof document !== 'undefined') {
|
|
7952
8269
|
document.removeEventListener('keydown', this._escHandler);
|
|
7953
8270
|
}
|
|
8271
|
+
if (this._beforeUnloadHandler && typeof document !== 'undefined') {
|
|
8272
|
+
document.removeEventListener('visibilitychange', this._beforeUnloadHandler);
|
|
8273
|
+
}
|
|
8274
|
+
this._beforeUnloadHandler = null;
|
|
7954
8275
|
if (this._previewViolationHandler && typeof window !== 'undefined' && typeof window.removeEventListener === 'function') {
|
|
7955
8276
|
window.removeEventListener('message', this._previewViolationHandler);
|
|
7956
8277
|
}
|