@innovatorved/code-lab 0.1.13 → 0.3.0
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 +12 -7
- package/CHANGELOG.md +134 -0
- package/README.md +59 -9
- package/dist/code-lab.css +198 -0
- package/dist/code-lab.d.ts +37 -7
- package/dist/code-lab.esm.js +20444 -1278
- package/dist/code-lab.js +20439 -1276
- package/dist/extensions/cpp.d.ts +145 -0
- package/dist/extensions/cpp.esm.js +5932 -0
- package/dist/extensions/cpp.js +5951 -0
- package/dist/extensions/guided-lab.esm.js +86 -6
- package/dist/extensions/guided-lab.js +87 -6
- package/dist/extensions/javascript.d.ts +24 -0
- package/dist/extensions/javascript.esm.js +36 -0
- package/dist/extensions/javascript.js +59 -0
- package/dist/extensions/python.d.ts +92 -0
- package/dist/extensions/python.esm.js +5476 -0
- package/dist/extensions/python.js +5495 -0
- package/dist/extensions/typescript.d.ts +36 -0
- package/dist/extensions/typescript.esm.js +55 -0
- package/dist/extensions/typescript.js +78 -0
- package/dist/index.d.ts +9 -3
- package/dist/preview-sw.js +1 -1
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/module-loader.d.ts +11 -0
- package/dist/runtime/test-harness.d.ts +24 -0
- package/dist/runtime/vfs.d.ts +31 -0
- package/dist/runtime/wasi-host.d.ts +33 -0
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.esm.js +920 -15
- package/dist/runtime.js +914 -15
- package/dist/schemas.d.ts +237 -25
- package/dist/schemas.esm.js +85 -6
- package/dist/schemas.js +85 -6
- package/dist/shell/coreutils/compilers-cli.d.ts +24 -0
- package/dist/shell/index.d.ts +4 -0
- package/dist/shell/lexer-parser.d.ts +26 -0
- package/dist/shell.esm.js +289 -4
- package/dist/shell.js +289 -4
- package/dist/terminal.esm.js +1 -1
- package/dist/terminal.js +1 -1
- package/dist/workbench/command-palette.d.ts +10 -0
- package/dist/workbench/diff-editor.d.ts +26 -0
- package/dist/workbench/drawer.d.ts +18 -0
- package/dist/workbench/editor.d.ts +11 -0
- package/dist/workbench/file-tree.d.ts +11 -0
- package/dist/workbench/guided-pane.d.ts +11 -0
- package/dist/workbench/icons.d.ts +5 -0
- package/dist/workbench/index.d.ts +39 -0
- package/dist/workbench/share.d.ts +21 -0
- package/dist/workbench/styles.d.ts +4 -0
- package/dist/workbench/toolbar.d.ts +17 -0
- package/dist/workbench.d.ts +6 -1
- package/package.json +33 -3
- package/src/code-lab.css +198 -0
- package/src/extensions/cpp.ts +1786 -0
- package/src/extensions/guided-lab.ts +10 -0
- package/src/extensions/javascript.ts +54 -0
- package/src/extensions/python.ts +1293 -0
- package/src/extensions/typescript.ts +85 -0
- package/src/index.ts +66 -3
- package/src/runtime/index.ts +5 -0
- package/src/runtime/test-harness.ts +57 -0
- package/src/runtime.ts +915 -14
- package/src/schemas.ts +94 -7
- package/src/shell/coreutils/compilers-cli.ts +103 -0
- package/src/shell/index.ts +5 -0
- package/src/shell.ts +288 -3
- package/src/workbench/command-palette.ts +140 -0
- package/src/workbench/diff-editor.ts +216 -0
- package/src/workbench/drawer.ts +148 -0
- package/src/workbench/editor.ts +49 -0
- package/src/workbench/file-tree.ts +51 -0
- package/src/workbench/guided-pane.ts +33 -0
- package/src/workbench/icons.ts +48 -0
- package/src/workbench/index.ts +38 -0
- package/src/workbench/share.ts +99 -0
- package/src/workbench/styles.ts +200 -0
- package/src/workbench/toolbar.ts +171 -0
- package/src/workbench.ts +1016 -78
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.
|
|
60
|
+
const CODELAB_VERSION = '0.3.0';
|
|
61
61
|
|
|
62
62
|
// Ambient TypeScript declarations for Node.js built-ins inside Monaco
|
|
63
63
|
const NODE_AMBIENT_DTS = `
|
|
@@ -1096,11 +1096,88 @@ declare module 'bun:sqlite' {
|
|
|
1096
1096
|
return monacoPromise;
|
|
1097
1097
|
}
|
|
1098
1098
|
|
|
1099
|
-
|
|
1100
|
-
|
|
1099
|
+
const DEFAULT_STANDALONE_CPP_FILES = {
|
|
1100
|
+
'solution.hpp': `#pragma once
|
|
1101
|
+
#include <bits/stdc++.h>
|
|
1102
|
+
#include <codelab/dsa.hpp>
|
|
1103
|
+
using namespace std;
|
|
1104
|
+
|
|
1105
|
+
vector<int> twoSum(const vector<int>& nums, int target) {
|
|
1106
|
+
unordered_map<int, int> seen;
|
|
1107
|
+
for (int i = 0; i < (int)nums.size(); ++i) {
|
|
1108
|
+
int complement = target - nums[i];
|
|
1109
|
+
if (seen.count(complement)) return {seen[complement], i};
|
|
1110
|
+
seen[nums[i]] = i;
|
|
1111
|
+
}
|
|
1112
|
+
return {};
|
|
1113
|
+
}
|
|
1114
|
+
`,
|
|
1115
|
+
'main.cpp': `#include "solution.hpp"
|
|
1116
|
+
|
|
1117
|
+
int main() {
|
|
1118
|
+
vector<int> nums = {2, 7, 11, 15};
|
|
1119
|
+
codelab::dbg(twoSum(nums, 9));
|
|
1120
|
+
return 0;
|
|
1121
|
+
}
|
|
1122
|
+
`,
|
|
1123
|
+
'test.cpp': `#include <codelab/test.hpp>
|
|
1124
|
+
#include "solution.hpp"
|
|
1125
|
+
|
|
1126
|
+
int main() {
|
|
1127
|
+
DESCRIBE("Standalone C++ Sandbox", [] {
|
|
1128
|
+
TEST("twoSum finds target pair indices", [] {
|
|
1129
|
+
ASSERT_EQ(twoSum({2, 7, 11, 15}, 9), (vector<int>{0, 1}));
|
|
1130
|
+
ASSERT_EQ(twoSum({3, 2, 4}, 6), (vector<int>{1, 2}));
|
|
1131
|
+
});
|
|
1132
|
+
});
|
|
1133
|
+
return codelab::test::exit_code();
|
|
1134
|
+
}
|
|
1135
|
+
`
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
// Helper to convert JS file set to TS, C++, or Python file set if explicit language files aren't provided
|
|
1139
|
+
function mapFilesToLanguage(filesObj, lang, explicitTsFiles, explicitCppFiles, explicitPyFiles) {
|
|
1101
1140
|
if (lang === 'ts' && explicitTsFiles && Object.keys(explicitTsFiles).length > 0) {
|
|
1102
1141
|
return { ...explicitTsFiles };
|
|
1103
1142
|
}
|
|
1143
|
+
if (lang === 'cpp') {
|
|
1144
|
+
if (explicitCppFiles && Object.keys(explicitCppFiles).length > 0) {
|
|
1145
|
+
return { ...explicitCppFiles };
|
|
1146
|
+
}
|
|
1147
|
+
const existingCpp = {};
|
|
1148
|
+
for (const [name, content] of Object.entries(filesObj || {})) {
|
|
1149
|
+
if (/\.(cpp|cc|cxx|h|hpp|md)$/i.test(name)) {
|
|
1150
|
+
existingCpp[name] = content;
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
if (Object.keys(existingCpp).some(f => /\.(cpp|cc|cxx)$/i.test(f))) {
|
|
1154
|
+
return existingCpp;
|
|
1155
|
+
}
|
|
1156
|
+
const outCpp = { ...DEFAULT_STANDALONE_CPP_FILES };
|
|
1157
|
+
if (filesObj && filesObj['README.md']) {
|
|
1158
|
+
outCpp['README.md'] = filesObj['README.md'];
|
|
1159
|
+
}
|
|
1160
|
+
return outCpp;
|
|
1161
|
+
}
|
|
1162
|
+
if (lang === 'py') {
|
|
1163
|
+
if (explicitPyFiles && Object.keys(explicitPyFiles).length > 0) {
|
|
1164
|
+
return { ...explicitPyFiles };
|
|
1165
|
+
}
|
|
1166
|
+
const existingPy = {};
|
|
1167
|
+
for (const [name, content] of Object.entries(filesObj || {})) {
|
|
1168
|
+
if (/\.(py|md)$/i.test(name)) {
|
|
1169
|
+
existingPy[name] = content;
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
if (Object.keys(existingPy).some(f => /\.py$/i.test(f))) {
|
|
1173
|
+
return existingPy;
|
|
1174
|
+
}
|
|
1175
|
+
const outPy = { ...DEFAULT_STANDALONE_PYTHON_FILES };
|
|
1176
|
+
if (filesObj && filesObj['README.md']) {
|
|
1177
|
+
outPy['README.md'] = filesObj['README.md'];
|
|
1178
|
+
}
|
|
1179
|
+
return outPy;
|
|
1180
|
+
}
|
|
1104
1181
|
const out = {};
|
|
1105
1182
|
for (const [name, content] of Object.entries(filesObj || {})) {
|
|
1106
1183
|
if (lang === 'ts' && name.endsWith('.js')) {
|
|
@@ -1115,6 +1192,11 @@ declare module 'bun:sqlite' {
|
|
|
1115
1192
|
return out;
|
|
1116
1193
|
}
|
|
1117
1194
|
|
|
1195
|
+
const DEFAULT_STANDALONE_PYTHON_FILES = {
|
|
1196
|
+
'main.py': `"""\\nStandalone Python 3.12 Sandbox with CPython WebAssembly.\\n"""\\nfrom codelab_test import describe, it, assert_equal\\n\\ndef solve(x):\\n return x\\n\\nif __name__ == '__main__':\\n print("Hello from Python 3.12 in CodeLab!")\\n print("Output:", solve({"status": "ok"}))\\n`,
|
|
1197
|
+
'test.py': `from codelab_test import describe, it, assert_equal\\nfrom main import solve\\n\\nwith describe("Python Sandbox Test Suite"):\\n with it("returns input value"):\\n assert_equal(solve(42), 42)\\n`
|
|
1198
|
+
};
|
|
1199
|
+
|
|
1118
1200
|
const DEFAULT_STANDALONE_FILES = {
|
|
1119
1201
|
'index.js': `'use strict';\n\nfunction solve(input) {\n return input;\n}\n\nmodule.exports = { solve };\n`,
|
|
1120
1202
|
'demo.js': `'use strict';\nconst { solve } = require('./index.js');\n\nconsole.log('Demo output:', solve({ status: 'ok', timestamp: Date.now() }));\n`,
|
|
@@ -1157,7 +1239,12 @@ declare module 'bun:sqlite' {
|
|
|
1157
1239
|
tablet: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="2" width="16" height="20" rx="2"/><line x1="12" y1="18" x2="12.01" y2="18"/></svg>',
|
|
1158
1240
|
smartphone: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="7" y="2" width="10" height="20" rx="2"/><line x1="12" y1="18" x2="12.01" y2="18"/></svg>',
|
|
1159
1241
|
externalLink: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>',
|
|
1160
|
-
x: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>'
|
|
1242
|
+
x: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',
|
|
1243
|
+
warning: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>',
|
|
1244
|
+
clock: '<svg width="12" height="12" 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"/><polyline points="12 6 12 12 16 14"/></svg>',
|
|
1245
|
+
memory: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 19v2"/><path d="M10 19v2"/><path d="M14 19v2"/><path d="M18 19v2"/><path d="M6 3v2"/><path d="M10 3v2"/><path d="M14 3v2"/><path d="M18 3v2"/><rect x="2" y="5" width="20" height="14" rx="2"/></svg>',
|
|
1246
|
+
keyboard: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="M6 8h.01"/><path d="M10 8h.01"/><path d="M14 8h.01"/><path d="M18 8h.01"/><path d="M6 12h.01"/><path d="M10 12h.01"/><path d="M14 12h.01"/><path d="M18 12h.01"/><path d="M7 16h10"/></svg>',
|
|
1247
|
+
share: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.59" y1="13.51" x2="15.42" y2="17.49"/><line x1="15.41" y1="6.51" x2="8.59" y2="10.49"/></svg>'
|
|
1161
1248
|
};
|
|
1162
1249
|
|
|
1163
1250
|
let _workbenchInstanceCounter = 0;
|
|
@@ -1332,7 +1419,11 @@ declare module 'bun:sqlite' {
|
|
|
1332
1419
|
...(options.guided || {}),
|
|
1333
1420
|
...(options.starterFiles ? { starterFiles: options.starterFiles } : {}),
|
|
1334
1421
|
...(options.tsStarterFiles ? { tsStarterFiles: options.tsStarterFiles } : {}),
|
|
1335
|
-
...((options.tsSolutionFiles || options.tsFiles) ? { tsSolutionFiles: options.tsSolutionFiles || options.tsFiles } : {})
|
|
1422
|
+
...((options.tsSolutionFiles || options.tsFiles) ? { tsSolutionFiles: options.tsSolutionFiles || options.tsFiles } : {}),
|
|
1423
|
+
...(options.cppStarterFiles ? { cppStarterFiles: options.cppStarterFiles } : {}),
|
|
1424
|
+
...((options.cppSolutionFiles || options.cppFiles) ? { cppSolutionFiles: options.cppSolutionFiles || options.cppFiles } : {}),
|
|
1425
|
+
...(options.pyStarterFiles ? { pyStarterFiles: options.pyStarterFiles } : {}),
|
|
1426
|
+
...((options.pySolutionFiles || options.pyFiles) ? { pySolutionFiles: options.pySolutionFiles || options.pyFiles } : {})
|
|
1336
1427
|
};
|
|
1337
1428
|
this.steps = options.steps || this.guidedConfig?.steps || [];
|
|
1338
1429
|
this.hasGuidedLab = Boolean(
|
|
@@ -1340,14 +1431,57 @@ declare module 'bun:sqlite' {
|
|
|
1340
1431
|
options.guidedLab ||
|
|
1341
1432
|
(this.steps && this.steps.length > 0)
|
|
1342
1433
|
);
|
|
1434
|
+
this.enabledLanguages = new Set(['js']);
|
|
1435
|
+
if (Array.isArray(options.languages)) {
|
|
1436
|
+
for (const l of options.languages) {
|
|
1437
|
+
if (l === 'js' || l === 'ts' || l === 'cpp' || l === 'py') this.enabledLanguages.add(l);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
if (
|
|
1441
|
+
options.hasMultipleLanguages ||
|
|
1442
|
+
this.guidedConfig.tsStarterFiles ||
|
|
1443
|
+
this.guidedConfig.tsSolutionFiles ||
|
|
1444
|
+
this.guidedConfig.tsFiles ||
|
|
1445
|
+
options.lang === 'ts' ||
|
|
1446
|
+
options.language === 'ts'
|
|
1447
|
+
) {
|
|
1448
|
+
this.enabledLanguages.add('ts');
|
|
1449
|
+
}
|
|
1450
|
+
if (
|
|
1451
|
+
this.guidedConfig.cppStarterFiles ||
|
|
1452
|
+
this.guidedConfig.cppSolutionFiles ||
|
|
1453
|
+
this.guidedConfig.cppFiles ||
|
|
1454
|
+
options.lang === 'cpp' ||
|
|
1455
|
+
options.language === 'cpp'
|
|
1456
|
+
) {
|
|
1457
|
+
this.enabledLanguages.add('cpp');
|
|
1458
|
+
}
|
|
1459
|
+
if (
|
|
1460
|
+
this.guidedConfig.pyStarterFiles ||
|
|
1461
|
+
this.guidedConfig.pySolutionFiles ||
|
|
1462
|
+
this.guidedConfig.pyFiles ||
|
|
1463
|
+
options.lang === 'py' ||
|
|
1464
|
+
options.language === 'py'
|
|
1465
|
+
) {
|
|
1466
|
+
this.enabledLanguages.add('py');
|
|
1467
|
+
}
|
|
1343
1468
|
this.hasMultipleLanguages = Boolean(
|
|
1344
1469
|
options.hasMultipleLanguages ||
|
|
1345
1470
|
options.languages ||
|
|
1471
|
+
this.enabledLanguages.size > 1 ||
|
|
1346
1472
|
this.guidedConfig.tsStarterFiles ||
|
|
1347
1473
|
this.guidedConfig.tsSolutionFiles ||
|
|
1348
1474
|
this.guidedConfig.tsFiles ||
|
|
1475
|
+
this.guidedConfig.cppStarterFiles ||
|
|
1476
|
+
this.guidedConfig.cppSolutionFiles ||
|
|
1477
|
+
this.guidedConfig.cppFiles ||
|
|
1478
|
+
this.guidedConfig.pyStarterFiles ||
|
|
1479
|
+
this.guidedConfig.pySolutionFiles ||
|
|
1480
|
+
this.guidedConfig.pyFiles ||
|
|
1349
1481
|
(this.hasGuidedLab && (options.lang || options.language))
|
|
1350
1482
|
);
|
|
1483
|
+
this.showWebPreviewOption = Boolean(options.showWebPreview);
|
|
1484
|
+
this._diffManager = null;
|
|
1351
1485
|
|
|
1352
1486
|
// Load saved user state from localStorage (with in-memory fallback)
|
|
1353
1487
|
this.savedState = this._loadState();
|
|
@@ -1374,7 +1508,12 @@ declare module 'bun:sqlite' {
|
|
|
1374
1508
|
this.renamingItem = null;
|
|
1375
1509
|
this._draggedFile = null;
|
|
1376
1510
|
this.guideTab = 'steps'; // 'steps' | 'readme'
|
|
1377
|
-
this.drawerTab =
|
|
1511
|
+
this.drawerTab = (this.hasGuidedLab && this.mode === 'guided') ? 'tests' : 'terminal';
|
|
1512
|
+
this.testSuiteVisible = Boolean(this.hasGuidedLab && this.mode === 'guided');
|
|
1513
|
+
this.lastDurationMs = null;
|
|
1514
|
+
this.lastPeakMemoryBytes = null;
|
|
1515
|
+
this.customStdin = (options && options.stdin) || '';
|
|
1516
|
+
this._eventsBound = false;
|
|
1378
1517
|
// ── Web Preview (M3) state ──
|
|
1379
1518
|
this.previewState = {
|
|
1380
1519
|
port: null,
|
|
@@ -1512,11 +1651,14 @@ declare module 'bun:sqlite' {
|
|
|
1512
1651
|
this._renderShell();
|
|
1513
1652
|
this._bindEvents();
|
|
1514
1653
|
this._initEditor();
|
|
1654
|
+
this._checkUrlSnapshot();
|
|
1515
1655
|
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1656
|
+
const initialPlugins = [
|
|
1657
|
+
...(Array.isArray(options.extensions) ? options.extensions : []),
|
|
1658
|
+
...(Array.isArray(options.plugins) ? options.plugins : [])
|
|
1659
|
+
];
|
|
1660
|
+
for (const plugin of initialPlugins) {
|
|
1661
|
+
this.use(plugin);
|
|
1520
1662
|
}
|
|
1521
1663
|
|
|
1522
1664
|
if (options.repo && typeof options.repo === 'string') {
|
|
@@ -1941,9 +2083,12 @@ declare module 'bun:sqlite' {
|
|
|
1941
2083
|
}
|
|
1942
2084
|
}
|
|
1943
2085
|
if (durEl) {
|
|
1944
|
-
|
|
2086
|
+
const ms = (typeof this.lastDurationMs === 'number' && !Number.isNaN(this.lastDurationMs))
|
|
2087
|
+
? this.lastDurationMs
|
|
2088
|
+
: this.lastRunDurationMs;
|
|
2089
|
+
if (typeof ms === 'number' && !Number.isNaN(ms)) {
|
|
1945
2090
|
durEl.style.display = 'inline-flex';
|
|
1946
|
-
durEl.textContent = `⚡ ${
|
|
2091
|
+
durEl.textContent = `⚡ ${ms.toFixed(1)}ms`;
|
|
1947
2092
|
} else {
|
|
1948
2093
|
durEl.style.display = 'none';
|
|
1949
2094
|
}
|
|
@@ -1952,8 +2097,15 @@ declare module 'bun:sqlite' {
|
|
|
1952
2097
|
curEl.textContent = `Ln ${this.cursorPos.lineNumber || 1}, Col ${this.cursorPos.column || 1}`;
|
|
1953
2098
|
}
|
|
1954
2099
|
if (langEl) {
|
|
1955
|
-
langEl.textContent = this.lang === '
|
|
2100
|
+
langEl.textContent = this.lang === 'cpp'
|
|
2101
|
+
? 'C++20 (Clang/WASI)'
|
|
2102
|
+
: this.lang === 'py'
|
|
2103
|
+
? 'Python 3.12 (CPython WASI)'
|
|
2104
|
+
: this.lang === 'ts'
|
|
2105
|
+
? 'TypeScript 5.x'
|
|
2106
|
+
: 'JavaScript (CJS/ESM)';
|
|
1956
2107
|
}
|
|
2108
|
+
this._updateTelemetryHud();
|
|
1957
2109
|
}
|
|
1958
2110
|
|
|
1959
2111
|
_getBaseFilesForModeAndLang(mode, lang) {
|
|
@@ -1962,10 +2114,22 @@ declare module 'bun:sqlite' {
|
|
|
1962
2114
|
...this.referenceFiles,
|
|
1963
2115
|
...(this.guidedConfig?.starterFiles || {})
|
|
1964
2116
|
};
|
|
1965
|
-
if (mode === 'guided' && this.guidedConfig?.starterFiles) {
|
|
1966
|
-
return mapFilesToLanguage(
|
|
2117
|
+
if (mode === 'guided' && (this.guidedConfig?.starterFiles || this.guidedConfig?.tsStarterFiles || this.guidedConfig?.cppStarterFiles || this.guidedConfig?.pyStarterFiles)) {
|
|
2118
|
+
return mapFilesToLanguage(
|
|
2119
|
+
baseJsStarter,
|
|
2120
|
+
lang,
|
|
2121
|
+
this.guidedConfig?.tsStarterFiles,
|
|
2122
|
+
this.guidedConfig?.cppStarterFiles,
|
|
2123
|
+
this.guidedConfig?.pyStarterFiles
|
|
2124
|
+
);
|
|
1967
2125
|
}
|
|
1968
|
-
return mapFilesToLanguage(
|
|
2126
|
+
return mapFilesToLanguage(
|
|
2127
|
+
baseJsSolution,
|
|
2128
|
+
lang,
|
|
2129
|
+
this.guidedConfig?.tsSolutionFiles,
|
|
2130
|
+
this.guidedConfig?.cppSolutionFiles,
|
|
2131
|
+
this.guidedConfig?.pySolutionFiles
|
|
2132
|
+
);
|
|
1969
2133
|
}
|
|
1970
2134
|
|
|
1971
2135
|
_isUserCreatedFile(filename) {
|
|
@@ -1988,6 +2152,35 @@ declare module 'bun:sqlite' {
|
|
|
1988
2152
|
|
|
1989
2153
|
_pickDefaultFile() {
|
|
1990
2154
|
const names = Object.keys(this.files);
|
|
2155
|
+
if (this.lang === 'py') {
|
|
2156
|
+
if (this.guidedConfig?.mainFile) {
|
|
2157
|
+
const pyMain = this.guidedConfig.mainFile.replace(/\.(js|ts|cpp)$/, '.py');
|
|
2158
|
+
if (this.files[pyMain]) return pyMain;
|
|
2159
|
+
}
|
|
2160
|
+
if (this.files['main.py']) return 'main.py';
|
|
2161
|
+
if (this.files['solution.py']) return 'solution.py';
|
|
2162
|
+
if (this.files['app.py']) return 'app.py';
|
|
2163
|
+
const pyImpl = names.find(f =>
|
|
2164
|
+
/\.py$/i.test(f) &&
|
|
2165
|
+
!/(^|\/)(demo|test.*|.*_test)\.py$/i.test(f)
|
|
2166
|
+
);
|
|
2167
|
+
return pyImpl || names.find(f => !f.endsWith('.md')) || names[0] || '';
|
|
2168
|
+
}
|
|
2169
|
+
if (this.lang === 'cpp') {
|
|
2170
|
+
if (this.guidedConfig?.mainFile) {
|
|
2171
|
+
const cppMain = this.guidedConfig.mainFile.replace(/\.(js|ts)$/, '.hpp');
|
|
2172
|
+
if (this.files[cppMain]) return cppMain;
|
|
2173
|
+
const cppMainSrc = this.guidedConfig.mainFile.replace(/\.(js|ts)$/, '.cpp');
|
|
2174
|
+
if (this.files[cppMainSrc]) return cppMainSrc;
|
|
2175
|
+
}
|
|
2176
|
+
if (this.files['solution.hpp']) return 'solution.hpp';
|
|
2177
|
+
if (this.files['main.cpp']) return 'main.cpp';
|
|
2178
|
+
const cppImpl = names.find(f =>
|
|
2179
|
+
/\.(cpp|cc|cxx|hpp|h)$/i.test(f) &&
|
|
2180
|
+
!/(^|\/)(demo|test)\.(cpp|cc|cxx)$/i.test(f)
|
|
2181
|
+
);
|
|
2182
|
+
return cppImpl || names.find(f => !f.endsWith('.md')) || names[0] || '';
|
|
2183
|
+
}
|
|
1991
2184
|
const ext = this.lang === 'ts' ? '.ts' : '.js';
|
|
1992
2185
|
if (this.guidedConfig?.mainFile) {
|
|
1993
2186
|
const mainCandidate = this.lang === 'ts'
|
|
@@ -2004,6 +2197,50 @@ declare module 'bun:sqlite' {
|
|
|
2004
2197
|
|
|
2005
2198
|
_findEntryFile(kind) {
|
|
2006
2199
|
const names = Object.keys(this.files);
|
|
2200
|
+
if (this.lang === 'py') {
|
|
2201
|
+
if (kind === 'test') {
|
|
2202
|
+
if (this.explicitTestEntry) {
|
|
2203
|
+
const pyTest = this.explicitTestEntry.replace(/\.(js|ts|cpp)$/, '.py');
|
|
2204
|
+
if (this.files[pyTest]) return pyTest;
|
|
2205
|
+
if (this.files[this.explicitTestEntry]) return this.explicitTestEntry;
|
|
2206
|
+
}
|
|
2207
|
+
if (this.files['test.py']) return 'test.py';
|
|
2208
|
+
if (this.files['test_main.py']) return 'test_main.py';
|
|
2209
|
+
return names.find(f => /(^|\/)(test.*|.*_test)\.py$/i.test(f)) || null;
|
|
2210
|
+
}
|
|
2211
|
+
if (this.explicitEntry) {
|
|
2212
|
+
const pyEntry = this.explicitEntry.replace(/\.(js|ts|cpp)$/, '.py');
|
|
2213
|
+
if (this.files[pyEntry]) return pyEntry;
|
|
2214
|
+
if (this.files[this.explicitEntry]) return this.explicitEntry;
|
|
2215
|
+
}
|
|
2216
|
+
if (this.files['main.py']) return 'main.py';
|
|
2217
|
+
if (this.files['demo.py']) return 'demo.py';
|
|
2218
|
+
if (this.files['app.py']) return 'app.py';
|
|
2219
|
+
return names.find(f => /(^|\/)(main|demo|app)\.py$/i.test(f)) ||
|
|
2220
|
+
names.find(f => /\.py$/i.test(f) && !/(^|\/)(test.*|.*_test)\.py$/i.test(f)) ||
|
|
2221
|
+
null;
|
|
2222
|
+
}
|
|
2223
|
+
if (this.lang === 'cpp') {
|
|
2224
|
+
if (kind === 'test') {
|
|
2225
|
+
if (this.explicitTestEntry) {
|
|
2226
|
+
const cppTest = this.explicitTestEntry.replace(/\.(js|ts)$/, '.cpp');
|
|
2227
|
+
if (this.files[cppTest]) return cppTest;
|
|
2228
|
+
if (this.files[this.explicitTestEntry]) return this.explicitTestEntry;
|
|
2229
|
+
}
|
|
2230
|
+
if (this.files['test.cpp']) return 'test.cpp';
|
|
2231
|
+
return names.find(f => /(^|\/)test\.(cpp|cc|cxx)$/i.test(f)) || null;
|
|
2232
|
+
}
|
|
2233
|
+
if (this.explicitEntry) {
|
|
2234
|
+
const cppEntry = this.explicitEntry.replace(/\.(js|ts)$/, '.cpp');
|
|
2235
|
+
if (this.files[cppEntry]) return cppEntry;
|
|
2236
|
+
if (this.files[this.explicitEntry]) return this.explicitEntry;
|
|
2237
|
+
}
|
|
2238
|
+
if (this.files['main.cpp']) return 'main.cpp';
|
|
2239
|
+
if (this.files['demo.cpp']) return 'demo.cpp';
|
|
2240
|
+
return names.find(f => /(^|\/)(main|demo)\.(cpp|cc|cxx)$/i.test(f)) ||
|
|
2241
|
+
names.find(f => /\.(cpp|cc|cxx)$/i.test(f) && !/(^|\/)test\.(cpp|cc|cxx)$/i.test(f)) ||
|
|
2242
|
+
null;
|
|
2243
|
+
}
|
|
2007
2244
|
if (kind === 'test' && this.explicitTestEntry) {
|
|
2008
2245
|
const candidate = this.lang === 'ts' ? this.explicitTestEntry.replace(/\.js$/, '.ts') : this.explicitTestEntry;
|
|
2009
2246
|
if (this.files[candidate]) return candidate;
|
|
@@ -2014,16 +2251,16 @@ declare module 'bun:sqlite' {
|
|
|
2014
2251
|
if (this.files[candidate]) return candidate;
|
|
2015
2252
|
if (this.files[this.explicitEntry]) return this.explicitEntry;
|
|
2016
2253
|
}
|
|
2017
|
-
const pattern = kind === 'test' ? /(^|\/)test\.(js|ts)$/i : /(^|\/)demo\.(js|ts)$/i;
|
|
2254
|
+
const pattern = kind === 'test' ? /(^|\/)test\.(js|ts|cpp|cc|cxx|py)$/i : /(^|\/)(demo|main)\.(js|ts|cpp|cc|cxx|py)$/i;
|
|
2018
2255
|
const found = names.find(f => pattern.test(f));
|
|
2019
2256
|
if (found) return found;
|
|
2020
2257
|
if (kind === 'demo') {
|
|
2021
|
-
const isConfigOrTest = f => /(^|\/)(test|.*\.(?:test|spec|config|d))\.(js|ts|mjs|cjs)$/i.test(f) || /(^|\/)\.[^/]+$/i.test(f);
|
|
2258
|
+
const isConfigOrTest = f => /(^|\/)(test|.*\.(?:test|spec|config|d))\.(js|ts|mjs|cjs|cpp|cc|cxx|py)$/i.test(f) || /(^|\/)\.[^/]+$/i.test(f);
|
|
2022
2259
|
const hasHtmlEntry = Boolean(this.files['index.html'] || this.files['public/index.html']);
|
|
2023
2260
|
if (hasHtmlEntry) {
|
|
2024
2261
|
return names.find(f => /(^|\/)(server|app|demo)\.(js|ts)$/i.test(f) && !/^src\//i.test(f)) || null;
|
|
2025
2262
|
}
|
|
2026
|
-
return names.find(f => /\.(js|ts)$/i.test(f) && !isConfigOrTest(f)) || null;
|
|
2263
|
+
return names.find(f => /\.(js|ts|cpp|cc|cxx|py)$/i.test(f) && !isConfigOrTest(f)) || null;
|
|
2027
2264
|
}
|
|
2028
2265
|
return null;
|
|
2029
2266
|
}
|
|
@@ -2045,11 +2282,136 @@ declare module 'bun:sqlite' {
|
|
|
2045
2282
|
? 'Send Ctrl+C — interrupt the running command'
|
|
2046
2283
|
: 'Send Ctrl+C (clears the current input line)';
|
|
2047
2284
|
}
|
|
2048
|
-
this.container.querySelectorAll('[data-cl-action="run-demo"], [data-cl-action="run-tests"], [data-cl-action="verify-step"]').forEach(btn => {
|
|
2285
|
+
this.container.querySelectorAll('[data-cl-action="run-code"], [data-cl-action="run-entry"], [data-cl-action="run-active-file"], [data-cl-action="run-demo"], [data-cl-action="run-tests"], [data-cl-action="verify-step"]').forEach(btn => {
|
|
2049
2286
|
btn.disabled = this.isRunning;
|
|
2050
2287
|
});
|
|
2051
2288
|
}
|
|
2052
2289
|
|
|
2290
|
+
_hasWebContent() {
|
|
2291
|
+
if (this.showWebPreviewOption === true) return true;
|
|
2292
|
+
if (!this.files) return false;
|
|
2293
|
+
if (this.files['index.html'] || this.files['src/index.html'] || this.files['public/index.html']) return true;
|
|
2294
|
+
if (this.portTable && typeof this.portTable.listServers === 'function' && this.portTable.listServers().length > 0) return true;
|
|
2295
|
+
return false;
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
_renderLanguageSwitcherHtml() {
|
|
2299
|
+
const hasMulti = Boolean(
|
|
2300
|
+
this.hasMultipleLanguages ||
|
|
2301
|
+
(this.enabledLanguages && this.enabledLanguages.size > 1)
|
|
2302
|
+
);
|
|
2303
|
+
if (!hasMulti) return '';
|
|
2304
|
+
const showTs = Boolean(
|
|
2305
|
+
!this.enabledLanguages ||
|
|
2306
|
+
this.enabledLanguages.has('ts') ||
|
|
2307
|
+
!this.enabledLanguages.has('cpp')
|
|
2308
|
+
);
|
|
2309
|
+
const showCpp = Boolean(this.enabledLanguages && this.enabledLanguages.has('cpp'));
|
|
2310
|
+
const showPy = Boolean(this.enabledLanguages && this.enabledLanguages.has('py'));
|
|
2311
|
+
return `
|
|
2312
|
+
<div class="codelab-lang-switch" role="group" aria-label="Language Selector">
|
|
2313
|
+
<button type="button" class="codelab-lang-btn ${this.lang === 'js' ? 'active' : ''}" data-cl-lang="js" data-lang="js" aria-pressed="${this.lang === 'js'}">JS</button>
|
|
2314
|
+
${showTs ? `<button type="button" class="codelab-lang-btn ${this.lang === 'ts' ? 'active' : ''}" data-cl-lang="ts" data-lang="ts" aria-pressed="${this.lang === 'ts'}">TS</button>` : ''}
|
|
2315
|
+
${showCpp ? `<button type="button" class="codelab-lang-btn ${this.lang === 'cpp' ? 'active' : ''}" data-cl-lang="cpp" data-lang="cpp" aria-pressed="${this.lang === 'cpp'}">C++</button>` : ''}
|
|
2316
|
+
${showPy ? `<button type="button" class="codelab-lang-btn ${this.lang === 'py' ? 'active' : ''}" data-cl-lang="py" data-lang="py" aria-pressed="${this.lang === 'py'}">PY</button>` : ''}
|
|
2317
|
+
</div>
|
|
2318
|
+
`;
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
_refreshLanguageSwitcher() {
|
|
2322
|
+
if (!this.container) return;
|
|
2323
|
+
const topLeft = this.container.querySelector('.codelab-topbar__left');
|
|
2324
|
+
if (!topLeft) return;
|
|
2325
|
+
const existing = topLeft.querySelector('.codelab-lang-switch');
|
|
2326
|
+
const htmlStr = this._renderLanguageSwitcherHtml().trim();
|
|
2327
|
+
if (existing) {
|
|
2328
|
+
if (htmlStr) {
|
|
2329
|
+
existing.outerHTML = htmlStr;
|
|
2330
|
+
} else {
|
|
2331
|
+
existing.remove();
|
|
2332
|
+
}
|
|
2333
|
+
} else if (htmlStr) {
|
|
2334
|
+
topLeft.insertAdjacentHTML('beforeend', htmlStr);
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
_refreshToolbarAndTabs() {
|
|
2339
|
+
if (!this.container) return;
|
|
2340
|
+
this._refreshLanguageSwitcher();
|
|
2341
|
+
const topbar = this.container.querySelector('.codelab-topbar');
|
|
2342
|
+
if (topbar) {
|
|
2343
|
+
const previewBtn = topbar.querySelector('#cl-preview-app-btn');
|
|
2344
|
+
const hasWeb = this._hasWebContent();
|
|
2345
|
+
if (hasWeb) {
|
|
2346
|
+
if (!previewBtn) {
|
|
2347
|
+
const stopBtn = topbar.querySelector('#cl-stop-btn');
|
|
2348
|
+
if (stopBtn && stopBtn.parentElement) {
|
|
2349
|
+
const globeHtml = `<button type="button" class="codelab-btn codelab-btn--icon" id="cl-preview-app-btn" data-cl-action="preview-app" title="Run & Preview in Browser" aria-label="Run and Preview in Browser">${CL_ICONS.globe}</button>`;
|
|
2350
|
+
stopBtn.insertAdjacentHTML('afterend', globeHtml);
|
|
2351
|
+
}
|
|
2352
|
+
} else {
|
|
2353
|
+
previewBtn.style.display = 'inline-flex';
|
|
2354
|
+
}
|
|
2355
|
+
} else if (previewBtn) {
|
|
2356
|
+
previewBtn.style.display = 'none';
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
this._refreshDrawerTabs();
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
_refreshDrawerTabs() {
|
|
2363
|
+
if (!this.container) return;
|
|
2364
|
+
const drawerTabs = this.container.querySelector('.codelab-drawer__tabs');
|
|
2365
|
+
if (!drawerTabs) return;
|
|
2366
|
+
|
|
2367
|
+
const isGuided = Boolean(this.hasGuidedLab && this.mode === 'guided');
|
|
2368
|
+
const showTests = isGuided || this.testSuiteVisible || this.drawerTab === 'tests';
|
|
2369
|
+
const hasWeb = this._hasWebContent();
|
|
2370
|
+
const problemsCount = this._diagnosticsStore && typeof this._diagnosticsStore.getAll === 'function'
|
|
2371
|
+
? this._diagnosticsStore.getAll().length
|
|
2372
|
+
: 0;
|
|
2373
|
+
|
|
2374
|
+
let probTab = drawerTabs.querySelector('[data-cl-drawertab="problems"]');
|
|
2375
|
+
if (!probTab) {
|
|
2376
|
+
const termTab = drawerTabs.querySelector('[data-cl-drawertab="terminal"]');
|
|
2377
|
+
if (termTab) {
|
|
2378
|
+
termTab.insertAdjacentHTML('afterend', `
|
|
2379
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'problems'}" class="codelab-drawer__tab ${this.drawerTab === 'problems' ? 'active' : ''}" data-cl-drawertab="problems" title="Compiler & Runtime Problems">
|
|
2380
|
+
${CL_ICONS.warning}
|
|
2381
|
+
<span>Problems</span>
|
|
2382
|
+
<span class="codelab-badge ${problemsCount > 0 ? 'codelab-badge--warn' : ''}" id="cl-problems-count" style="margin-left:4px;font-size:10px;padding:1px 5px;border-radius:10px;background:${problemsCount > 0 ? '#cca700' : 'rgba(255,255,255,0.1)'};color:#fff;">${problemsCount}</span>
|
|
2383
|
+
</button>
|
|
2384
|
+
`);
|
|
2385
|
+
}
|
|
2386
|
+
} else {
|
|
2387
|
+
const countSpan = probTab.querySelector('#cl-problems-count');
|
|
2388
|
+
if (countSpan) countSpan.textContent = String(problemsCount);
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
let testTab = drawerTabs.querySelector('[data-cl-drawertab="tests"]');
|
|
2392
|
+
if (testTab) {
|
|
2393
|
+
testTab.style.display = showTests ? 'inline-flex' : 'none';
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
let stdinTab = drawerTabs.querySelector('[data-cl-drawertab="stdin"]');
|
|
2397
|
+
if (!stdinTab) {
|
|
2398
|
+
const afterTab = testTab || drawerTabs.querySelector('[data-cl-drawertab="problems"]') || drawerTabs.querySelector('[data-cl-drawertab="terminal"]');
|
|
2399
|
+
if (afterTab) {
|
|
2400
|
+
afterTab.insertAdjacentHTML('afterend', `
|
|
2401
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'stdin'}" class="codelab-drawer__tab ${this.drawerTab === 'stdin' ? 'active' : ''}" data-cl-drawertab="stdin" title="Standard Input">
|
|
2402
|
+
${CL_ICONS.keyboard}
|
|
2403
|
+
<span>Stdin</span>
|
|
2404
|
+
</button>
|
|
2405
|
+
`);
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
let previewTab = drawerTabs.querySelector('[data-cl-drawertab="preview"]');
|
|
2410
|
+
if (previewTab) {
|
|
2411
|
+
previewTab.style.display = hasWeb ? 'inline-flex' : 'none';
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2053
2415
|
// ── Render Workbench DOM ───────────────────────────────────────────────
|
|
2054
2416
|
_renderShell() {
|
|
2055
2417
|
if (this.themeOption !== 'auto') {
|
|
@@ -2090,12 +2452,13 @@ declare module 'bun:sqlite' {
|
|
|
2090
2452
|
</button>
|
|
2091
2453
|
</div>
|
|
2092
2454
|
` : ''}
|
|
2093
|
-
${this.
|
|
2094
|
-
<
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2455
|
+
${this._renderLanguageSwitcherHtml()}
|
|
2456
|
+
<span class="codelab-toolbar__sep" aria-hidden="true"></span>
|
|
2457
|
+
<button type="button" class="codelab-cmd-trigger" data-cl-action="command-palette" title="Open Command Palette (⌘K / ⇧⌘P)">
|
|
2458
|
+
${CL_ICONS.search}
|
|
2459
|
+
<span>Command Palette</span>
|
|
2460
|
+
<kbd style="opacity:0.7">⇧⌘P</kbd>
|
|
2461
|
+
</button>
|
|
2099
2462
|
</div>
|
|
2100
2463
|
|
|
2101
2464
|
<div class="codelab-topbar__right">
|
|
@@ -2103,18 +2466,50 @@ declare module 'bun:sqlite' {
|
|
|
2103
2466
|
${CL_ICONS.stop}
|
|
2104
2467
|
<span>Stop</span>
|
|
2105
2468
|
</button>
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2469
|
+
${(this.hasGuidedLab && this.mode === 'guided') ? `
|
|
2470
|
+
<button type="button" class="codelab-btn codelab-btn--run" data-cl-action="run-demo" title="Run demo.js (⌘+Shift+Enter)">
|
|
2471
|
+
${CL_ICONS.play}
|
|
2472
|
+
<span>Run Demo</span>
|
|
2473
|
+
<span class="codelab-btn__kbd">⇧⌘↵</span>
|
|
2474
|
+
</button>
|
|
2475
|
+
<button type="button" class="codelab-btn codelab-btn--test" id="cl-primary-exec-btn" data-cl-action="verify-step" title="Verify Current Step (⌘+Enter)">
|
|
2476
|
+
${CL_ICONS.check}
|
|
2477
|
+
<span>Verify Step</span>
|
|
2478
|
+
<span class="codelab-btn__kbd">⌘↵</span>
|
|
2479
|
+
</button>
|
|
2480
|
+
` : `
|
|
2481
|
+
<div class="codelab-btn-split">
|
|
2482
|
+
<button type="button" class="codelab-btn codelab-btn--run codelab-btn-split__main" id="cl-primary-exec-btn" data-cl-action="run-code" title="Run Code (⌘↵)">
|
|
2483
|
+
${CL_ICONS.play}
|
|
2484
|
+
<span>Run Code</span>
|
|
2485
|
+
<span class="codelab-btn__kbd">⌘↵</span>
|
|
2486
|
+
</button>
|
|
2487
|
+
<button type="button" class="codelab-btn codelab-btn--run codelab-btn-split__trigger" id="cl-split-run-trigger" title="More Execution Options" aria-haspopup="true">
|
|
2488
|
+
${CL_ICONS.chevronDown}
|
|
2489
|
+
</button>
|
|
2490
|
+
<div class="codelab-split-menu" id="cl-split-run-menu">
|
|
2491
|
+
<button type="button" class="codelab-split-menu__item" data-cl-action="run-demo">
|
|
2492
|
+
<span>▶ Run Entry / Demo</span> <kbd style="opacity:0.6">⌘↵</kbd>
|
|
2493
|
+
</button>
|
|
2494
|
+
<button type="button" class="codelab-split-menu__item" data-cl-action="run-active-file">
|
|
2495
|
+
<span>▶ Run Active File (${escapeHtml(this.activeFile || 'active')})</span> <kbd style="opacity:0.6">⇧⌘↵</kbd>
|
|
2496
|
+
</button>
|
|
2497
|
+
${this._findEntryFile('test') ? `
|
|
2498
|
+
<button type="button" class="codelab-split-menu__item" data-cl-action="run-tests">
|
|
2499
|
+
<span>✓ Run Test Suite</span>
|
|
2500
|
+
</button>
|
|
2501
|
+
` : ''}
|
|
2502
|
+
<button type="button" class="codelab-split-menu__item" data-cl-action="open-stdin">
|
|
2503
|
+
<span>⌨ Configure Stdin / Input...</span>
|
|
2504
|
+
</button>
|
|
2505
|
+
</div>
|
|
2506
|
+
</div>
|
|
2507
|
+
`}
|
|
2508
|
+
<button type="button" class="codelab-btn codelab-btn--icon" id="cl-preview-app-btn" data-cl-action="preview-app" title="Run & Preview in Browser" aria-label="Run and Preview in Browser" style="display: ${this._hasWebContent() ? 'inline-flex' : 'none'}">
|
|
2509
|
+
${CL_ICONS.globe}
|
|
2115
2510
|
</button>
|
|
2116
|
-
<button type="button" class="codelab-btn codelab-btn--icon"
|
|
2117
|
-
|
|
2511
|
+
<button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="share-snapshot" title="Share Snapshot Link (#codelab=...)" aria-label="Share Snapshot Link">
|
|
2512
|
+
${CL_ICONS.share}
|
|
2118
2513
|
</button>
|
|
2119
2514
|
<span class="codelab-toolbar__sep" aria-hidden="true"></span>
|
|
2120
2515
|
${this.hasGuidedLab ? `
|
|
@@ -2212,22 +2607,33 @@ declare module 'bun:sqlite' {
|
|
|
2212
2607
|
<div class="codelab-drawer codelab-bottom" id="cl-drawer">
|
|
2213
2608
|
<div class="codelab-drawer__bar">
|
|
2214
2609
|
<div class="codelab-drawer__tabs" role="tablist" aria-label="Execution Output Panels">
|
|
2610
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'terminal'}" class="codelab-drawer__tab ${this.drawerTab === 'terminal' ? 'active' : ''}" data-cl-drawertab="terminal">
|
|
2611
|
+
${CL_ICONS.terminal}
|
|
2612
|
+
<span>Terminal & REPL</span>
|
|
2613
|
+
</button>
|
|
2614
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'problems'}" class="codelab-drawer__tab ${this.drawerTab === 'problems' ? 'active' : ''}" data-cl-drawertab="problems" title="Compiler & Runtime Problems">
|
|
2615
|
+
${CL_ICONS.warning}
|
|
2616
|
+
<span>Problems</span>
|
|
2617
|
+
<span class="codelab-badge" id="cl-problems-count" style="margin-left:4px;font-size:10px;padding:1px 5px;border-radius:10px;background:rgba(255,255,255,0.1);color:#fff;">${this._diagnosticsStore ? this._diagnosticsStore.getAll().length : 0}</span>
|
|
2618
|
+
</button>
|
|
2619
|
+
${((this.hasGuidedLab && this.mode === 'guided') || this.testSuiteVisible || this.drawerTab === 'tests') ? `
|
|
2215
2620
|
<button type="button" role="tab" aria-selected="${this.drawerTab === 'tests'}" class="codelab-drawer__tab ${this.drawerTab === 'tests' ? 'active' : ''}" data-cl-drawertab="tests">
|
|
2216
2621
|
${CL_ICONS.check}
|
|
2217
2622
|
<span>Test Suite</span>
|
|
2218
2623
|
<span class="codelab-drawer__pill" id="cl-test-pill">Ready</span>
|
|
2219
2624
|
</button>
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2625
|
+
` : ''}
|
|
2626
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'stdin'}" class="codelab-drawer__tab ${this.drawerTab === 'stdin' ? 'active' : ''}" data-cl-drawertab="stdin" title="Standard Input">
|
|
2627
|
+
${CL_ICONS.keyboard}
|
|
2628
|
+
<span>Stdin</span>
|
|
2223
2629
|
</button>
|
|
2224
2630
|
<button type="button" role="tab" aria-selected="${this.drawerTab === 'ports'}" class="codelab-drawer__tab ${this.drawerTab === 'ports' ? 'active' : ''}" data-cl-drawertab="ports">
|
|
2225
2631
|
${CL_ICONS.radio}
|
|
2226
2632
|
<span>Ports</span>
|
|
2227
2633
|
<span class="codelab-drawer__pill" id="cl-ports-pill">${this.portTable && typeof this.portTable.listServers === 'function' ? this.portTable.listServers().length : 0} open</span>
|
|
2228
2634
|
</button>
|
|
2229
|
-
<button type="button" role="tab" aria-selected="${this.drawerTab === 'preview'}" class="codelab-drawer__tab ${this.drawerTab === 'preview' ? 'active' : ''}" data-cl-drawertab="preview" title="In-browser Web Preview">
|
|
2230
|
-
${CL_ICONS.
|
|
2635
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'preview'}" class="codelab-drawer__tab ${this.drawerTab === 'preview' ? 'active' : ''}" data-cl-drawertab="preview" title="In-browser Web Preview" style="display: ${this._hasWebContent() ? 'inline-flex' : 'none'}">
|
|
2636
|
+
${CL_ICONS.globe}
|
|
2231
2637
|
<span>Web Preview</span>
|
|
2232
2638
|
</button>
|
|
2233
2639
|
<button type="button" role="tab" aria-selected="${this.drawerTab === 'network'}" class="codelab-drawer__tab ${this.drawerTab === 'network' ? 'active' : ''}" data-cl-drawertab="network">
|
|
@@ -2241,6 +2647,7 @@ declare module 'bun:sqlite' {
|
|
|
2241
2647
|
<span class="codelab-drawer__pill" id="cl-vfs-pill">0 files</span>
|
|
2242
2648
|
</button>
|
|
2243
2649
|
</div>
|
|
2650
|
+
<div class="codelab-hud-pill" id="cl-telemetry-hud" style="display:none;" title="Last Execution Telemetry"></div>
|
|
2244
2651
|
<div style="display:flex;align-items:center;gap:6px;">
|
|
2245
2652
|
<button type="button" class="codelab-btn codelab-btn--icon codelab-btn--ctrl-c" id="cl-ctrl-c-btn" data-cl-action="interrupt" title="Send Ctrl+C — interrupt a running command" aria-label="Send Ctrl+C interrupt" style="padding:2px 8px;font-size:11px;font-family:var(--cl-font-mono);">Ctrl+C</button>
|
|
2246
2653
|
<button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="clear-terminal" title="Clear Output" style="padding:2px 6px;font-size:11px;">Clear</button>
|
|
@@ -2269,7 +2676,7 @@ declare module 'bun:sqlite' {
|
|
|
2269
2676
|
<span class="codelab-statusbar__sep">·</span>
|
|
2270
2677
|
<span class="codelab-statusbar__item">UTF-8</span>
|
|
2271
2678
|
<span class="codelab-statusbar__sep">·</span>
|
|
2272
|
-
<span class="codelab-statusbar__item" id="cl-status-lang">${this.lang === 'ts' ? 'TypeScript 5.x' : 'JavaScript (CJS/ESM)'}</span>
|
|
2679
|
+
<span class="codelab-statusbar__item" id="cl-status-lang">${this.lang === 'cpp' ? 'C++20 (Clang/WASI)' : this.lang === 'py' ? 'Python 3.12 (CPython WASI)' : this.lang === 'ts' ? 'TypeScript 5.x' : 'JavaScript (CJS/ESM)'}</span>
|
|
2273
2680
|
</div>
|
|
2274
2681
|
</footer>
|
|
2275
2682
|
|
|
@@ -2290,13 +2697,30 @@ declare module 'bun:sqlite' {
|
|
|
2290
2697
|
this._updateRunStateUI();
|
|
2291
2698
|
}
|
|
2292
2699
|
|
|
2700
|
+
_resolveStepTargetFile(rawTarget) {
|
|
2701
|
+
if (!rawTarget) return '';
|
|
2702
|
+
if (this.lang === 'cpp') {
|
|
2703
|
+
const asHpp = rawTarget.replace(/\.(js|ts)$/, '.hpp');
|
|
2704
|
+
if (this.files && this.files[asHpp] !== undefined) return asHpp;
|
|
2705
|
+
const asCpp = rawTarget.replace(/\.(js|ts)$/, '.cpp');
|
|
2706
|
+
if (this.files && this.files[asCpp] !== undefined) return asCpp;
|
|
2707
|
+
if (this.files && this.files['solution.hpp'] !== undefined) return 'solution.hpp';
|
|
2708
|
+
if (this.files && this.files['main.cpp'] !== undefined) return 'main.cpp';
|
|
2709
|
+
return asCpp;
|
|
2710
|
+
}
|
|
2711
|
+
if (this.lang === 'ts') {
|
|
2712
|
+
return rawTarget.replace(/\.js$/, '.ts');
|
|
2713
|
+
}
|
|
2714
|
+
return rawTarget;
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2293
2717
|
_detectActiveSymbol(filePath) {
|
|
2294
2718
|
if (!filePath || !this.files || typeof this.files[filePath] !== 'string') return '';
|
|
2295
2719
|
if (this.mode === 'guided' && this.steps && this.steps.length > 0) {
|
|
2296
2720
|
const step = this.steps[this.activeStepIndex];
|
|
2297
2721
|
if (step) {
|
|
2298
2722
|
const rawTarget = step.targetFile || '';
|
|
2299
|
-
const stepTarget =
|
|
2723
|
+
const stepTarget = rawTarget ? this._resolveStepTargetFile(rawTarget) : '';
|
|
2300
2724
|
if ((!stepTarget || stepTarget === filePath) && (step.targetSymbol || step.symbol)) {
|
|
2301
2725
|
return String(step.targetSymbol || step.symbol);
|
|
2302
2726
|
}
|
|
@@ -2499,7 +2923,7 @@ declare module 'bun:sqlite' {
|
|
|
2499
2923
|
|
|
2500
2924
|
const step = this.steps[this.activeStepIndex] || this.steps[0];
|
|
2501
2925
|
const isStepPassed = this.completedSteps.has(step.id);
|
|
2502
|
-
const targetFile =
|
|
2926
|
+
const targetFile = step.targetFile ? this._resolveStepTargetFile(step.targetFile) : this._pickDefaultFile();
|
|
2503
2927
|
const progressPct = Math.round((this.completedSteps.size / Math.max(1, this.steps.length)) * 100);
|
|
2504
2928
|
|
|
2505
2929
|
// Match step test results
|
|
@@ -2726,8 +3150,8 @@ declare module 'bun:sqlite' {
|
|
|
2726
3150
|
const sortedFiles = Array.from(node.files.entries()).sort((a, b) => a[0].localeCompare(b[0]));
|
|
2727
3151
|
for (const [baseName, fullPath] of sortedFiles) {
|
|
2728
3152
|
const isActive = fullPath === this.activeFile;
|
|
2729
|
-
const badge = fullPath.endsWith('.md') ? 'DOC' : fullPath.endsWith('.json') ? 'PKG' : /(^|\/)test\./i.test(fullPath) ? 'TEST' : /(^|\/)demo\./i.test(fullPath) ? 'DEMO' : 'SRC';
|
|
2730
|
-
const ext = fullPath.endsWith('.ts') ? 'ts' : fullPath.endsWith('.js') ? 'js' : fullPath.endsWith('.json') ? 'json' : fullPath.endsWith('.md') ? 'md' : 'txt';
|
|
3153
|
+
const badge = fullPath.endsWith('.md') ? 'DOC' : fullPath.endsWith('.json') ? 'PKG' : /(^|\/)test\./i.test(fullPath) ? 'TEST' : /(^|\/)(demo|main)\./i.test(fullPath) ? 'DEMO' : /\.(hpp|h)$/i.test(fullPath) ? 'HDR' : 'SRC';
|
|
3154
|
+
const ext = /\.(cpp|cc|cxx|hpp|h)$/i.test(fullPath) ? 'cpp' : fullPath.endsWith('.ts') ? 'ts' : fullPath.endsWith('.js') ? 'js' : fullPath.endsWith('.json') ? 'json' : fullPath.endsWith('.md') ? 'md' : 'txt';
|
|
2731
3155
|
const fileIcon = ext === 'json' ? CL_ICONS.database : ext === 'md' ? CL_ICONS.book : CL_ICONS.file;
|
|
2732
3156
|
const indent = depth * 14 + 10;
|
|
2733
3157
|
treeHtml += `
|
|
@@ -2851,10 +3275,10 @@ declare module 'bun:sqlite' {
|
|
|
2851
3275
|
const openTabs = Array.isArray(this.openTabs) ? this.openTabs : [];
|
|
2852
3276
|
const tabsHtml = openTabs.map(f => {
|
|
2853
3277
|
const isActive = f === this.activeFile;
|
|
2854
|
-
const ext = f.endsWith('.ts') ? 'ts' : f.endsWith('.js') ? 'js' : f.endsWith('.json') ? 'json' : f.endsWith('.md') ? 'md' : 'txt';
|
|
3278
|
+
const ext = /\.(cpp|cc|cxx|hpp|h)$/i.test(f) ? 'cpp' : f.endsWith('.ts') ? 'ts' : f.endsWith('.js') ? 'js' : f.endsWith('.json') ? 'json' : f.endsWith('.md') ? 'md' : 'txt';
|
|
2855
3279
|
return `
|
|
2856
3280
|
<div role="tab" tabindex="0" aria-selected="${isActive}" class="codelab-tab ${isActive ? 'active' : ''}" data-cl-file="${escapeHtml(f)}" data-tab-file="${escapeHtml(f)}">
|
|
2857
|
-
<span class="codelab-tab__ext codelab-tab__ext--${ext}">${ext.toUpperCase()}</span>
|
|
3281
|
+
<span class="codelab-tab__ext codelab-tab__ext--${ext}">${ext === 'cpp' ? 'C++' : ext.toUpperCase()}</span>
|
|
2858
3282
|
<span class="codelab-tab__label">${escapeHtml(f)}</span>
|
|
2859
3283
|
<button type="button" class="codelab-tab__close" data-action="close-tab" data-cl-file="${escapeHtml(f)}" title="Close ${escapeHtml(f)}" aria-label="Close ${escapeHtml(f)}">×</button>
|
|
2860
3284
|
</div>
|
|
@@ -3109,7 +3533,7 @@ declare module 'bun:sqlite' {
|
|
|
3109
3533
|
createFile(rawName, initialContent = null) {
|
|
3110
3534
|
let clean = String(rawName).trim().replace(/^\/+/, '');
|
|
3111
3535
|
if (!clean) return;
|
|
3112
|
-
if (!/\.(js|ts|json|md|txt)$/i.test(clean) && !clean.includes('.')) {
|
|
3536
|
+
if (!/\.(js|ts|cpp|cc|cxx|hpp|h|json|md|txt)$/i.test(clean) && !clean.includes('.')) {
|
|
3113
3537
|
clean += `.${this.lang}`;
|
|
3114
3538
|
}
|
|
3115
3539
|
if (this.files[clean] !== undefined) {
|
|
@@ -3127,7 +3551,11 @@ declare module 'bun:sqlite' {
|
|
|
3127
3551
|
} else {
|
|
3128
3552
|
this.files[clean] = clean.endsWith('.json')
|
|
3129
3553
|
? '{\n "name": "' + this.labId + '",\n "dependencies": {}\n}\n'
|
|
3130
|
-
:
|
|
3554
|
+
: /\.(hpp|h)$/i.test(clean)
|
|
3555
|
+
? `#pragma once\n#include <bits/stdc++.h>\n\n// ${clean}\n`
|
|
3556
|
+
: /\.(cpp|cc|cxx)$/i.test(clean)
|
|
3557
|
+
? `#include <bits/stdc++.h>\nusing namespace std;\n\n// ${clean}\nint main() {\n return 0;\n}\n`
|
|
3558
|
+
: `'use strict';\n\n// ${clean}\n`;
|
|
3131
3559
|
}
|
|
3132
3560
|
this._saveState();
|
|
3133
3561
|
this._getOrCreateModel(clean);
|
|
@@ -3257,6 +3685,15 @@ declare module 'bun:sqlite' {
|
|
|
3257
3685
|
});
|
|
3258
3686
|
|
|
3259
3687
|
// Update pills
|
|
3688
|
+
const problemsCountEl = this.container.querySelector('#cl-problems-count');
|
|
3689
|
+
if (problemsCountEl) {
|
|
3690
|
+
const count = this._diagnosticsStore && typeof this._diagnosticsStore.getAll === 'function'
|
|
3691
|
+
? this._diagnosticsStore.getAll().length
|
|
3692
|
+
: 0;
|
|
3693
|
+
problemsCountEl.textContent = String(count);
|
|
3694
|
+
}
|
|
3695
|
+
this._updateTelemetryHud();
|
|
3696
|
+
|
|
3260
3697
|
if (testPill) {
|
|
3261
3698
|
if (!this.lastTestResults.length) {
|
|
3262
3699
|
testPill.textContent = 'Ready';
|
|
@@ -3284,6 +3721,61 @@ declare module 'bun:sqlite' {
|
|
|
3284
3721
|
vfsPill.textContent = httpCount > 0 ? `${diskCount} files · ${httpCount} reqs` : `${diskCount} files`;
|
|
3285
3722
|
}
|
|
3286
3723
|
|
|
3724
|
+
if (this.drawerTab === 'problems') {
|
|
3725
|
+
const store = this._diagnosticsStore;
|
|
3726
|
+
const problems = store && typeof store.getAll === 'function' ? store.getAll() : [];
|
|
3727
|
+
if (!problems.length) {
|
|
3728
|
+
bodyEl.innerHTML = `
|
|
3729
|
+
<div style="color:var(--cl-fg-muted);padding:16px;text-align:center;">
|
|
3730
|
+
${CL_ICONS.check} No problems detected in workspace.
|
|
3731
|
+
</div>
|
|
3732
|
+
`;
|
|
3733
|
+
return;
|
|
3734
|
+
}
|
|
3735
|
+
bodyEl.innerHTML = `
|
|
3736
|
+
<div class="codelab-problems-list">
|
|
3737
|
+
${problems.map(p => {
|
|
3738
|
+
const icon = p.severity === 'error' ? '✖' : (p.severity === 'warning' ? '⚠' : 'ℹ');
|
|
3739
|
+
const cls = p.severity === 'error' ? 'codelab-problem-item--error' : (p.severity === 'warning' ? 'codelab-problem-item--warning' : 'codelab-problem-item--info');
|
|
3740
|
+
return `
|
|
3741
|
+
<div class="codelab-problem-item ${cls}" data-cl-problem-file="${escapeHtml(p.file || '')}" data-cl-problem-line="${p.line || 1}" data-cl-problem-col="${p.col || 1}" role="button" tabindex="0">
|
|
3742
|
+
<span class="codelab-problem-item__icon">${icon}</span>
|
|
3743
|
+
<span class="codelab-problem-item__msg">${escapeHtml(p.message || '')}</span>
|
|
3744
|
+
<span class="codelab-problem-item__loc">${escapeHtml(p.file || '')}:${p.line || 1}:${p.col || 1}</span>
|
|
3745
|
+
</div>
|
|
3746
|
+
`;
|
|
3747
|
+
}).join('')}
|
|
3748
|
+
</div>
|
|
3749
|
+
`;
|
|
3750
|
+
return;
|
|
3751
|
+
}
|
|
3752
|
+
|
|
3753
|
+
if (this.drawerTab === 'stdin') {
|
|
3754
|
+
bodyEl.innerHTML = `
|
|
3755
|
+
<div class="codelab-stdin-panel" style="padding:10px;height:100%;display:flex;flex-direction:column;box-sizing:border-box;">
|
|
3756
|
+
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:6px;font-size:12px;color:var(--cl-fg-muted);">
|
|
3757
|
+
<span>Standard Input (std::cin / sys.stdin / process.stdin)</span>
|
|
3758
|
+
<button type="button" class="codelab-btn codelab-btn--sm" id="cl-stdin-clear-btn" style="padding:2px 8px;font-size:11px;">Clear</button>
|
|
3759
|
+
</div>
|
|
3760
|
+
<textarea id="cl-stdin-textarea" class="codelab-stdin-textarea" style="flex:1;width:100%;background:var(--cl-bg-input, #1e1e1e);color:var(--cl-fg, #d4d4d4);border:1px solid var(--cl-border, #333);border-radius:4px;padding:8px;font-family:var(--cl-font-mono, monospace);font-size:12px;resize:none;outline:none;box-sizing:border-box;" placeholder="Enter or paste custom stdin here (used by std::cin, sys.stdin, fs.readFileSync(0))...">${escapeHtml(this.customStdin || '')}</textarea>
|
|
3761
|
+
</div>
|
|
3762
|
+
`;
|
|
3763
|
+
const ta = bodyEl.querySelector('#cl-stdin-textarea');
|
|
3764
|
+
if (ta) {
|
|
3765
|
+
ta.addEventListener('input', () => {
|
|
3766
|
+
this.customStdin = ta.value;
|
|
3767
|
+
});
|
|
3768
|
+
}
|
|
3769
|
+
const clearBtn = bodyEl.querySelector('#cl-stdin-clear-btn');
|
|
3770
|
+
if (clearBtn && ta) {
|
|
3771
|
+
clearBtn.addEventListener('click', () => {
|
|
3772
|
+
this.customStdin = '';
|
|
3773
|
+
ta.value = '';
|
|
3774
|
+
});
|
|
3775
|
+
}
|
|
3776
|
+
return;
|
|
3777
|
+
}
|
|
3778
|
+
|
|
3287
3779
|
if (this.drawerTab === 'tests') {
|
|
3288
3780
|
if (!this.lastTestResults.length) {
|
|
3289
3781
|
bodyEl.innerHTML = `
|
|
@@ -3642,6 +4134,33 @@ declare module 'bun:sqlite' {
|
|
|
3642
4134
|
}
|
|
3643
4135
|
}
|
|
3644
4136
|
|
|
4137
|
+
_updateTelemetryHud() {
|
|
4138
|
+
const hud = this.container ? this.container.querySelector('#cl-telemetry-hud') : null;
|
|
4139
|
+
if (!hud) return;
|
|
4140
|
+
if (this.lastDurationMs === null && this.lastPeakMemoryBytes === null) {
|
|
4141
|
+
hud.style.display = 'none';
|
|
4142
|
+
return;
|
|
4143
|
+
}
|
|
4144
|
+
hud.style.display = 'inline-flex';
|
|
4145
|
+
let timeStr = '';
|
|
4146
|
+
if (this.lastDurationMs !== null) {
|
|
4147
|
+
timeStr = this.lastDurationMs < 1000
|
|
4148
|
+
? `${this.lastDurationMs.toFixed(1)} ms`
|
|
4149
|
+
: `${(this.lastDurationMs / 1000).toFixed(2)} s`;
|
|
4150
|
+
}
|
|
4151
|
+
let memStr = '';
|
|
4152
|
+
if (this.lastPeakMemoryBytes !== null && this.lastPeakMemoryBytes > 0) {
|
|
4153
|
+
const mb = this.lastPeakMemoryBytes / (1024 * 1024);
|
|
4154
|
+
const suffix = this.lang === 'cpp' ? 'Wasm' : this.lang === 'py' ? 'Heap' : 'Mem';
|
|
4155
|
+
memStr = `${mb < 0.1 ? (this.lastPeakMemoryBytes / 1024).toFixed(1) + ' KB' : mb.toFixed(1) + ' MB'} ${suffix}`;
|
|
4156
|
+
}
|
|
4157
|
+
hud.innerHTML = `
|
|
4158
|
+
${timeStr ? `<span class="codelab-hud-pill__metric">${CL_ICONS.clock} <span>${timeStr}</span></span>` : ''}
|
|
4159
|
+
${timeStr && memStr ? `<span style="opacity:0.4;">·</span>` : ''}
|
|
4160
|
+
${memStr ? `<span class="codelab-hud-pill__metric">${CL_ICONS.memory} <span>${memStr}</span></span>` : ''}
|
|
4161
|
+
`;
|
|
4162
|
+
}
|
|
4163
|
+
|
|
3645
4164
|
_handleInterrupt() {
|
|
3646
4165
|
const isCommandRunning = Boolean(this.isRunning || this._activeCommandAbortController);
|
|
3647
4166
|
const cwdShort = (this.cwd || '/workspace').replace(/^\/workspace\/?/, '') || '~';
|
|
@@ -5735,7 +6254,21 @@ declare module 'bun:sqlite' {
|
|
|
5735
6254
|
const rawUri = `file:///${this.labId}/${filename}`;
|
|
5736
6255
|
const uri = uriParser ? uriParser.parse(rawUri) : { toString: () => rawUri };
|
|
5737
6256
|
let model = typeof this.monaco.editor.getModel === 'function' ? this.monaco.editor.getModel(uri) : null;
|
|
5738
|
-
const lang =
|
|
6257
|
+
const lang = /\.(cpp|cc|cxx|hpp|h)$/i.test(filename)
|
|
6258
|
+
? 'cpp'
|
|
6259
|
+
: /\.py$/i.test(filename)
|
|
6260
|
+
? 'python'
|
|
6261
|
+
: filename.endsWith('.ts')
|
|
6262
|
+
? 'typescript'
|
|
6263
|
+
: filename.endsWith('.json')
|
|
6264
|
+
? 'json'
|
|
6265
|
+
: filename.endsWith('.html')
|
|
6266
|
+
? 'html'
|
|
6267
|
+
: filename.endsWith('.css')
|
|
6268
|
+
? 'css'
|
|
6269
|
+
: filename.endsWith('.md')
|
|
6270
|
+
? 'markdown'
|
|
6271
|
+
: 'javascript';
|
|
5739
6272
|
if (!model) {
|
|
5740
6273
|
model = this.monaco.editor.createModel(this.files[filename] || '', lang, uri);
|
|
5741
6274
|
if (model && typeof model.onDidChangeContent === 'function') {
|
|
@@ -5744,6 +6277,12 @@ declare module 'bun:sqlite' {
|
|
|
5744
6277
|
this.files[filename] = val;
|
|
5745
6278
|
this._saveState();
|
|
5746
6279
|
this._notifyCodeChange(filename, val);
|
|
6280
|
+
if (this.lang === 'py' && typeof this._pyLintHandler === 'function') {
|
|
6281
|
+
this._pyLintHandler(filename, val);
|
|
6282
|
+
}
|
|
6283
|
+
if (this.lang === 'cpp' && typeof this._cppLintHandler === 'function') {
|
|
6284
|
+
this._cppLintHandler(filename, val);
|
|
6285
|
+
}
|
|
5747
6286
|
});
|
|
5748
6287
|
}
|
|
5749
6288
|
} else if (model.getValue() !== (this.files[filename] || '')) {
|
|
@@ -5846,6 +6385,9 @@ declare module 'bun:sqlite' {
|
|
|
5846
6385
|
|
|
5847
6386
|
// ── Event Delegation & Interactive Splitters ───────────────────────────
|
|
5848
6387
|
_bindEvents() {
|
|
6388
|
+
if (this._eventsBound) return;
|
|
6389
|
+
this._eventsBound = true;
|
|
6390
|
+
|
|
5849
6391
|
this._bindSplitters();
|
|
5850
6392
|
|
|
5851
6393
|
this._escHandler = e => {
|
|
@@ -5914,6 +6456,16 @@ declare module 'bun:sqlite' {
|
|
|
5914
6456
|
this.openCommandPalette('commands');
|
|
5915
6457
|
return;
|
|
5916
6458
|
}
|
|
6459
|
+
if ((e.metaKey || e.ctrlKey) && keyLower === 'k') {
|
|
6460
|
+
e.preventDefault();
|
|
6461
|
+
this.openCommandPalette('commands');
|
|
6462
|
+
return;
|
|
6463
|
+
}
|
|
6464
|
+
if (e.altKey && e.shiftKey && keyLower === 'f') {
|
|
6465
|
+
e.preventDefault();
|
|
6466
|
+
this.formatActiveDocument();
|
|
6467
|
+
return;
|
|
6468
|
+
}
|
|
5917
6469
|
if ((e.metaKey || e.ctrlKey) && !e.shiftKey && keyLower === 'p') {
|
|
5918
6470
|
e.preventDefault();
|
|
5919
6471
|
this.openCommandPalette('files');
|
|
@@ -5930,11 +6482,15 @@ declare module 'bun:sqlite' {
|
|
|
5930
6482
|
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
|
|
5931
6483
|
e.preventDefault();
|
|
5932
6484
|
if (e.shiftKey) {
|
|
5933
|
-
this.
|
|
6485
|
+
if (this.mode === 'guided') {
|
|
6486
|
+
this.runDemo();
|
|
6487
|
+
} else {
|
|
6488
|
+
this.runActiveFile();
|
|
6489
|
+
}
|
|
5934
6490
|
} else if (this.mode === 'guided') {
|
|
5935
6491
|
this.verifyCurrentStep();
|
|
5936
6492
|
} else {
|
|
5937
|
-
this.
|
|
6493
|
+
this.runCode();
|
|
5938
6494
|
}
|
|
5939
6495
|
}
|
|
5940
6496
|
});
|
|
@@ -6211,6 +6767,36 @@ declare module 'bun:sqlite' {
|
|
|
6211
6767
|
return;
|
|
6212
6768
|
}
|
|
6213
6769
|
|
|
6770
|
+
const splitTrigger = e.target.closest('#cl-split-run-trigger');
|
|
6771
|
+
if (splitTrigger) {
|
|
6772
|
+
e.stopPropagation();
|
|
6773
|
+
const menu = this.container.querySelector('#cl-split-run-menu');
|
|
6774
|
+
if (menu) menu.classList.toggle('active');
|
|
6775
|
+
return;
|
|
6776
|
+
}
|
|
6777
|
+
|
|
6778
|
+
const splitMenu = this.container.querySelector('#cl-split-run-menu');
|
|
6779
|
+
if (splitMenu && splitMenu.classList.contains('active') && !e.target.closest('.codelab-btn-split')) {
|
|
6780
|
+
splitMenu.classList.remove('active');
|
|
6781
|
+
}
|
|
6782
|
+
|
|
6783
|
+
const problemItem = e.target.closest('[data-cl-problem-file]');
|
|
6784
|
+
if (problemItem) {
|
|
6785
|
+
e.stopPropagation();
|
|
6786
|
+
const pFile = problemItem.dataset.clProblemFile;
|
|
6787
|
+
const pLine = Number(problemItem.dataset.clProblemLine || 1);
|
|
6788
|
+
const pCol = Number(problemItem.dataset.clProblemCol || 1);
|
|
6789
|
+
if (pFile) {
|
|
6790
|
+
this.openFile(pFile);
|
|
6791
|
+
if (this.editor && typeof this.editor.revealLineInCenter === 'function') {
|
|
6792
|
+
this.editor.revealLineInCenter(pLine);
|
|
6793
|
+
this.editor.setPosition({ lineNumber: pLine, column: pCol });
|
|
6794
|
+
this.editor.focus();
|
|
6795
|
+
}
|
|
6796
|
+
}
|
|
6797
|
+
return;
|
|
6798
|
+
}
|
|
6799
|
+
|
|
6214
6800
|
const drawerTabBtn = e.target.closest('[data-cl-drawertab]');
|
|
6215
6801
|
if (drawerTabBtn) {
|
|
6216
6802
|
this.switchDrawerTab(drawerTabBtn.dataset.clDrawertab);
|
|
@@ -6219,8 +6805,16 @@ declare module 'bun:sqlite' {
|
|
|
6219
6805
|
|
|
6220
6806
|
const actionBtn = e.target.closest('[data-cl-action], [data-action]');
|
|
6221
6807
|
if (actionBtn) {
|
|
6808
|
+
if (splitMenu && splitMenu.classList.contains('active')) {
|
|
6809
|
+
splitMenu.classList.remove('active');
|
|
6810
|
+
}
|
|
6222
6811
|
const action = actionBtn.dataset.clAction || actionBtn.dataset.action;
|
|
6223
|
-
if (action === 'run-
|
|
6812
|
+
if (action === 'run-code') this.runCode();
|
|
6813
|
+
else if (action === 'run-entry') this.runEntry();
|
|
6814
|
+
else if (action === 'run-active-file') this.runActiveFile();
|
|
6815
|
+
else if (action === 'open-stdin') this.switchDrawerTab('stdin');
|
|
6816
|
+
else if (action === 'share-snapshot') this.shareSnapshot();
|
|
6817
|
+
else if (action === 'run-demo') this.runDemo();
|
|
6224
6818
|
else if (action === 'run-tests') this.runTests();
|
|
6225
6819
|
else if (action === 'stop-run') this.stopExecution();
|
|
6226
6820
|
else if (action === 'interrupt') this._handleInterrupt();
|
|
@@ -6508,9 +7102,15 @@ declare module 'bun:sqlite' {
|
|
|
6508
7102
|
// ── VS Code Command Palette & Quick Open ────────────────────────────────
|
|
6509
7103
|
_getPaletteCommands() {
|
|
6510
7104
|
return [
|
|
7105
|
+
{ id: 'run-code', label: 'CodeLab: Run Code (Entry or Active File)', shortcut: '⌘↵', action: () => this.runCode() },
|
|
7106
|
+
{ id: 'run-active', label: 'CodeLab: Run Active File', shortcut: '⇧⌘↵', action: () => this.runActiveFile() },
|
|
6511
7107
|
{ id: 'run-demo', label: 'CodeLab: Run Demo Script', shortcut: '⇧⌘↵', action: () => this.runDemo() },
|
|
6512
7108
|
{ id: 'run-tests', label: 'CodeLab: Run Unit Tests', shortcut: '⌘↵', action: () => this.runTests() },
|
|
6513
7109
|
{ id: 'verify-step', label: 'CodeLab: Verify Current Guided Step', shortcut: '⌘↵', action: () => this.verifyCurrentStep() },
|
|
7110
|
+
{ id: 'format-document', label: 'Editor: Format Document', shortcut: '⇧⌥F', action: () => this.formatActiveDocument() },
|
|
7111
|
+
{ id: 'share-snapshot', label: 'CodeLab: Share Snapshot Link (#codelab=...)', action: () => this.shareSnapshot() },
|
|
7112
|
+
{ id: 'open-stdin', label: 'View: Open Stdin / Custom Input Panel', action: () => this.switchDrawerTab('stdin') },
|
|
7113
|
+
{ id: 'view-problems-tab', label: 'View: Focus Problems Drawer Tab', action: () => this.switchDrawerTab('problems') },
|
|
6514
7114
|
{ id: 'compare-solution', label: 'CodeLab: Compare Active File with Reference Solution (Diff)', action: () => this.showDiffModal(this.activeFile || this._pickDefaultFile(), 'solution') },
|
|
6515
7115
|
{ id: 'compare-starter', label: 'CodeLab: Compare Active File with Starter Template (Diff)', action: () => this.showDiffModal(this.activeFile || this._pickDefaultFile(), 'starter') },
|
|
6516
7116
|
{ id: 'apply-solution', label: 'CodeLab: Apply Reference Solution to Active File', action: () => this.applyReferenceSolution() },
|
|
@@ -6521,7 +7121,13 @@ declare module 'bun:sqlite' {
|
|
|
6521
7121
|
{ id: 'export-workspace', label: 'Workspace: Export Workspace as JSON', action: () => this.exportWorkspace({ download: true }) },
|
|
6522
7122
|
{ id: 'export-workspace-zip', label: 'Workspace: Export Project as ZIP Archive', action: () => this.exportProjectZip({ download: true }) },
|
|
6523
7123
|
{ id: 'reset-workspace', label: 'Workspace: Reset Workspace to Clean State', action: () => this.resetLab() },
|
|
6524
|
-
{ id: 'switch-lang', label: 'Language: Switch JavaScript / TypeScript', action: () =>
|
|
7124
|
+
{ id: 'switch-lang', label: 'Language: Switch JavaScript / TypeScript / C++ / Python', action: () => {
|
|
7125
|
+
const order = ['js', 'ts'];
|
|
7126
|
+
if (this.enabledLanguages && this.enabledLanguages.has('cpp')) order.push('cpp');
|
|
7127
|
+
if (this.enabledLanguages && this.enabledLanguages.has('py')) order.push('py');
|
|
7128
|
+
const next = order[(order.indexOf(this.lang) + 1) % order.length] || 'js';
|
|
7129
|
+
this.setLanguage(next);
|
|
7130
|
+
} },
|
|
6525
7131
|
{ id: 'switch-mode', label: 'Mode: Switch Guided / Sandbox Mode', action: () => this.setMode(this.mode === 'guided' ? 'sandbox' : 'guided') },
|
|
6526
7132
|
{ id: 'toggle-guide', label: 'View: Toggle Guide Sidebar', action: () => this.toggleGuide() },
|
|
6527
7133
|
{ id: 'toggle-drawer', label: 'View: Toggle Bottom Drawer (Tests / Terminal / VFS)', action: () => {
|
|
@@ -6714,6 +7320,31 @@ declare module 'bun:sqlite' {
|
|
|
6714
7320
|
}
|
|
6715
7321
|
|
|
6716
7322
|
showDiffModal(targetFile = null, compareTarget = 'solution') {
|
|
7323
|
+
const file = targetFile || this.activeFile || this._pickDefaultFile();
|
|
7324
|
+
if (!this._diffManager) {
|
|
7325
|
+
let DiffManagerCls = (root && root.CodeLabWorkbenchComponents && root.CodeLabWorkbenchComponents.CodeLabDiffEditorManager) ||
|
|
7326
|
+
(typeof globalThis !== 'undefined' && globalThis.CodeLabWorkbenchComponents && globalThis.CodeLabWorkbenchComponents.CodeLabDiffEditorManager) ||
|
|
7327
|
+
null;
|
|
7328
|
+
if (!DiffManagerCls && typeof require === 'function') {
|
|
7329
|
+
try {
|
|
7330
|
+
const mod = require('./workbench/diff-editor');
|
|
7331
|
+
DiffManagerCls = mod.CodeLabDiffEditorManager;
|
|
7332
|
+
} catch (err) {
|
|
7333
|
+
void err;
|
|
7334
|
+
}
|
|
7335
|
+
}
|
|
7336
|
+
if (DiffManagerCls) {
|
|
7337
|
+
this._diffManager = new DiffManagerCls(this);
|
|
7338
|
+
}
|
|
7339
|
+
}
|
|
7340
|
+
if (this._diffManager && typeof window !== 'undefined' && window.monaco && window.monaco.editor && typeof window.monaco.editor.createDiffEditor === 'function') {
|
|
7341
|
+
const ok = this._diffManager.openInlineDiff(file, compareTarget);
|
|
7342
|
+
if (ok) return;
|
|
7343
|
+
}
|
|
7344
|
+
this.showDiffModalFallback(file, compareTarget);
|
|
7345
|
+
}
|
|
7346
|
+
|
|
7347
|
+
showDiffModalFallback(targetFile = null, compareTarget = 'solution') {
|
|
6717
7348
|
const slot = this.container.querySelector('#cl-modal-slot');
|
|
6718
7349
|
if (!slot) return;
|
|
6719
7350
|
|
|
@@ -6986,7 +7617,7 @@ declare module 'bun:sqlite' {
|
|
|
6986
7617
|
const step = this.steps[idx];
|
|
6987
7618
|
if (step) {
|
|
6988
7619
|
const rawTarget = step.targetFile || this._pickDefaultFile();
|
|
6989
|
-
const targetFile =
|
|
7620
|
+
const targetFile = rawTarget ? this._resolveStepTargetFile(rawTarget) : this._pickDefaultFile();
|
|
6990
7621
|
this.openFile(targetFile, step.targetSymbol || `TODO (Step ${idx + 1})`);
|
|
6991
7622
|
}
|
|
6992
7623
|
}
|
|
@@ -7090,15 +7721,31 @@ declare module 'bun:sqlite' {
|
|
|
7090
7721
|
}
|
|
7091
7722
|
}
|
|
7092
7723
|
|
|
7724
|
+
get language() {
|
|
7725
|
+
return this.lang;
|
|
7726
|
+
}
|
|
7727
|
+
|
|
7728
|
+
set language(newLang) {
|
|
7729
|
+
this.setLanguage(newLang);
|
|
7730
|
+
}
|
|
7731
|
+
|
|
7093
7732
|
setLanguage(newLang) {
|
|
7094
|
-
if (newLang !== 'js' && newLang !== 'ts') return;
|
|
7733
|
+
if (newLang !== 'js' && newLang !== 'ts' && newLang !== 'cpp' && newLang !== 'py') return;
|
|
7095
7734
|
if (this.lang === newLang) return;
|
|
7096
7735
|
this.lang = newLang;
|
|
7736
|
+
if (this.enabledLanguages instanceof Set) {
|
|
7737
|
+
this.enabledLanguages.add(newLang);
|
|
7738
|
+
}
|
|
7097
7739
|
this.files = this._computeInitialFiles();
|
|
7098
7740
|
this.openTabs = this._orderedFileNames();
|
|
7099
7741
|
this.activeFile = this._pickDefaultFile();
|
|
7100
7742
|
this._saveState();
|
|
7101
7743
|
|
|
7744
|
+
if (typeof this._refreshToolbarAndTabs === 'function') {
|
|
7745
|
+
this._refreshToolbarAndTabs();
|
|
7746
|
+
} else {
|
|
7747
|
+
this._refreshLanguageSwitcher();
|
|
7748
|
+
}
|
|
7102
7749
|
this.container.querySelectorAll('[data-cl-lang]').forEach(btn => {
|
|
7103
7750
|
const isActive = btn.dataset.clLang === this.lang;
|
|
7104
7751
|
btn.classList.toggle('active', isActive);
|
|
@@ -7108,6 +7755,15 @@ declare module 'bun:sqlite' {
|
|
|
7108
7755
|
this._syncAllModels();
|
|
7109
7756
|
this._syncActiveFileToView();
|
|
7110
7757
|
this._renderGuidePane();
|
|
7758
|
+
this._updateStatusBar();
|
|
7759
|
+
}
|
|
7760
|
+
|
|
7761
|
+
switchLang(newLang) {
|
|
7762
|
+
return this.setLanguage(newLang);
|
|
7763
|
+
}
|
|
7764
|
+
|
|
7765
|
+
switchMode(newMode) {
|
|
7766
|
+
return this.setMode(newMode);
|
|
7111
7767
|
}
|
|
7112
7768
|
|
|
7113
7769
|
configure({ mode, lang, stepIndex, onClose } = {}) {
|
|
@@ -7129,7 +7785,7 @@ declare module 'bun:sqlite' {
|
|
|
7129
7785
|
if (mode === 'guided' || mode === 'sandbox') {
|
|
7130
7786
|
this.setMode(mode);
|
|
7131
7787
|
}
|
|
7132
|
-
if (lang === 'js' || lang === 'ts') {
|
|
7788
|
+
if (lang === 'js' || lang === 'ts' || lang === 'cpp' || lang === 'py') {
|
|
7133
7789
|
this.setLanguage(lang);
|
|
7134
7790
|
}
|
|
7135
7791
|
if (typeof stepIndex === 'number' && !Number.isNaN(stepIndex)) {
|
|
@@ -7384,12 +8040,16 @@ declare module 'bun:sqlite' {
|
|
|
7384
8040
|
const payload = {
|
|
7385
8041
|
...execOptions,
|
|
7386
8042
|
instanceId: this.instanceId,
|
|
8043
|
+
stdin: execOptions.stdin !== undefined ? execOptions.stdin : (this.customStdin || ''),
|
|
8044
|
+
cppCompiler: execOptions.cppCompiler || this.cppCompiler,
|
|
7387
8045
|
onStdout: execOptions.onStdout || ((chunk) => this._appendTerminalStream('stdout', chunk)),
|
|
7388
8046
|
onStderr: execOptions.onStderr || ((chunk) => this._appendTerminalStream('stderr', chunk)),
|
|
7389
8047
|
signal: execOptions.signal || this._activeCommandAbortController?.signal
|
|
7390
8048
|
};
|
|
7391
8049
|
try {
|
|
7392
|
-
|
|
8050
|
+
const isCppEntry = Boolean(payload && typeof payload.entry === 'string' && /\.(cpp|cc|cxx|wasm)$/i.test(payload.entry));
|
|
8051
|
+
const isPyEntry = Boolean(payload && typeof payload.entry === 'string' && /\.py$/i.test(payload.entry));
|
|
8052
|
+
if (!isCppEntry && !isPyEntry && typeof root.CodeLabRuntime?.preloadNpmPackages === 'function' && payload && payload.files) {
|
|
7393
8053
|
const rawDetected = this._detectPackages();
|
|
7394
8054
|
const detectedList = Array.isArray(rawDetected)
|
|
7395
8055
|
? rawDetected
|
|
@@ -7406,9 +8066,24 @@ declare module 'bun:sqlite' {
|
|
|
7406
8066
|
payload.packages = Object.assign({}, preloaded, payload.packages || {});
|
|
7407
8067
|
}
|
|
7408
8068
|
}
|
|
7409
|
-
this._setRuntimeStatus('running', `Running ${payload.entry || payload.mode || 'script'}...`);
|
|
8069
|
+
this._setRuntimeStatus('running', isCppEntry ? `Compiling & Running ${payload.entry}...` : isPyEntry ? `Running Python 3.12: ${payload.entry}...` : `Running ${payload.entry || payload.mode || 'script'}...`);
|
|
7410
8070
|
let res;
|
|
7411
|
-
|
|
8071
|
+
const pyRunner = this.pythonCompiler || (typeof globalThis !== 'undefined' && globalThis.__codelabPythonCompiler) || (typeof root !== 'undefined' && root.__codelabPythonCompiler);
|
|
8072
|
+
if ((isPyEntry || this.lang === 'py') && pyRunner) {
|
|
8073
|
+
res = await pyRunner(payload);
|
|
8074
|
+
} else if (isPyEntry || this.lang === 'py') {
|
|
8075
|
+
this._setRuntimeStatus('error', 'Python 3.12 extension not loaded');
|
|
8076
|
+
return {
|
|
8077
|
+
ok: false,
|
|
8078
|
+
exitCode: 1,
|
|
8079
|
+
stdout: '',
|
|
8080
|
+
stderr: 'Python WebAssembly toolchain is not registered. Enable pythonExtension from "@innovatorved/code-lab/extensions/python" to run Python files.\n',
|
|
8081
|
+
durationMs: 0,
|
|
8082
|
+
peakMemoryBytes: 0
|
|
8083
|
+
};
|
|
8084
|
+
} else if (isCppEntry && typeof root.CodeLabRuntime?.executeInVirtualRuntime === 'function') {
|
|
8085
|
+
res = await root.CodeLabRuntime.executeInVirtualRuntime(payload);
|
|
8086
|
+
} else if (typeof root.CodeLabRuntime?.executeInWorker === 'function') {
|
|
7412
8087
|
res = await root.CodeLabRuntime.executeInWorker(payload);
|
|
7413
8088
|
} else if (typeof root.CodeLabRuntime?.executeInVirtualRuntime === 'function') {
|
|
7414
8089
|
res = await root.CodeLabRuntime.executeInVirtualRuntime(payload);
|
|
@@ -7417,6 +8092,9 @@ declare module 'bun:sqlite' {
|
|
|
7417
8092
|
}
|
|
7418
8093
|
const elapsed = Math.round((typeof performance !== 'undefined' ? performance.now() : Date.now()) - t0);
|
|
7419
8094
|
this.lastRunDurationMs = res && typeof res.durationMs === 'number' ? res.durationMs : elapsed;
|
|
8095
|
+
this.lastDurationMs = this.lastRunDurationMs;
|
|
8096
|
+
this.lastPeakMemoryBytes = res && typeof res.peakMemoryBytes === 'number' ? res.peakMemoryBytes : null;
|
|
8097
|
+
this._updateTelemetryHud();
|
|
7420
8098
|
this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
|
|
7421
8099
|
return res;
|
|
7422
8100
|
} catch (err) {
|
|
@@ -7429,14 +8107,36 @@ declare module 'bun:sqlite' {
|
|
|
7429
8107
|
}
|
|
7430
8108
|
}
|
|
7431
8109
|
|
|
7432
|
-
async
|
|
7433
|
-
|
|
7434
|
-
const entry = this._findEntryFile('demo');
|
|
8110
|
+
async runCode() {
|
|
8111
|
+
const entry = this._findEntryFile('demo') || this.activeFile || this._pickDefaultFile();
|
|
7435
8112
|
if (!entry) {
|
|
7436
|
-
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
8113
|
+
this.terminalLogs.push({ type: 'stderr', text: 'No entry file or active file to run.' });
|
|
8114
|
+
this.drawerTab = 'terminal';
|
|
8115
|
+
this._renderDrawerBody();
|
|
8116
|
+
return;
|
|
8117
|
+
}
|
|
8118
|
+
return this._executeEntryFile(entry);
|
|
8119
|
+
}
|
|
8120
|
+
|
|
8121
|
+
async runEntry() {
|
|
8122
|
+
return this.runCode();
|
|
8123
|
+
}
|
|
8124
|
+
|
|
8125
|
+
async runActiveFile() {
|
|
8126
|
+
const file = this.activeFile || this._pickDefaultFile();
|
|
8127
|
+
if (!file) {
|
|
8128
|
+
this.terminalLogs.push({ type: 'stderr', text: 'No active file to run.' });
|
|
8129
|
+
this.drawerTab = 'terminal';
|
|
8130
|
+
this._renderDrawerBody();
|
|
8131
|
+
return;
|
|
8132
|
+
}
|
|
8133
|
+
return this._executeEntryFile(file);
|
|
8134
|
+
}
|
|
8135
|
+
|
|
8136
|
+
async _executeEntryFile(entry) {
|
|
8137
|
+
if (this.isRunning) return;
|
|
8138
|
+
if (!entry || this.files[entry] === undefined) {
|
|
8139
|
+
this.terminalLogs.push({ type: 'stderr', text: `File not found: ${entry || 'entry'}` });
|
|
7440
8140
|
this.drawerTab = 'terminal';
|
|
7441
8141
|
this._renderDrawerBody();
|
|
7442
8142
|
return;
|
|
@@ -7445,19 +8145,28 @@ declare module 'bun:sqlite' {
|
|
|
7445
8145
|
this.isRunning = true;
|
|
7446
8146
|
this._updateRunStateUI();
|
|
7447
8147
|
this.drawerTab = 'terminal';
|
|
7448
|
-
|
|
8148
|
+
const isCpp = /\.(cpp|cc|cxx)$/i.test(entry);
|
|
8149
|
+
const isPy = /\.py$/i.test(entry);
|
|
8150
|
+
const cmdText = isCpp
|
|
8151
|
+
? `\n$ g++ -std=c++20 ${entry} -o a.out && ./a.out`
|
|
8152
|
+
: isPy
|
|
8153
|
+
? `\n$ python3 ${entry}`
|
|
8154
|
+
: `\n$ node ${entry}`;
|
|
8155
|
+
this.terminalLogs.push({ type: 'system', text: cmdText });
|
|
7449
8156
|
this._renderDrawerBody();
|
|
7450
8157
|
|
|
7451
|
-
|
|
8158
|
+
let abortCtrl = new AbortController();
|
|
7452
8159
|
this._activeCommandAbortController = abortCtrl;
|
|
7453
8160
|
let streamedStdout = false;
|
|
7454
8161
|
let streamedStderr = false;
|
|
8162
|
+
let lastRes = null;
|
|
7455
8163
|
|
|
7456
8164
|
try {
|
|
7457
8165
|
const res = await this._executeRuntime({
|
|
7458
8166
|
files: { ...this.files },
|
|
7459
8167
|
entry,
|
|
7460
8168
|
mode: 'run',
|
|
8169
|
+
stdin: this.customStdin || '',
|
|
7461
8170
|
signal: abortCtrl.signal,
|
|
7462
8171
|
onStdout: (c) => {
|
|
7463
8172
|
streamedStdout = true;
|
|
@@ -7468,6 +8177,7 @@ declare module 'bun:sqlite' {
|
|
|
7468
8177
|
this._appendTerminalStream('stderr', c);
|
|
7469
8178
|
}
|
|
7470
8179
|
});
|
|
8180
|
+
lastRes = res;
|
|
7471
8181
|
this._flushTerminalStream();
|
|
7472
8182
|
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
7473
8183
|
|
|
@@ -7483,6 +8193,9 @@ declare module 'bun:sqlite' {
|
|
|
7483
8193
|
if (!aborted) {
|
|
7484
8194
|
this.lastFsSnapshot = res.fsSnapshot || [];
|
|
7485
8195
|
this.lastHttpTrace = res.httpTrace || [];
|
|
8196
|
+
if (res.durationMs !== undefined) this.lastDurationMs = res.durationMs;
|
|
8197
|
+
if (res.peakMemoryBytes !== undefined) this.lastPeakMemoryBytes = res.peakMemoryBytes;
|
|
8198
|
+
this._updateTelemetryHud();
|
|
7486
8199
|
}
|
|
7487
8200
|
|
|
7488
8201
|
if (this.onRun) {
|
|
@@ -7503,33 +8216,216 @@ declare module 'bun:sqlite' {
|
|
|
7503
8216
|
}
|
|
7504
8217
|
|
|
7505
8218
|
this._renderDrawerBody();
|
|
8219
|
+
return lastRes;
|
|
8220
|
+
}
|
|
8221
|
+
|
|
8222
|
+
async runDemo() {
|
|
8223
|
+
if (this.isRunning) return;
|
|
8224
|
+
const entry = this._findEntryFile('demo') || this._findEntryFile('entry') || this.activeFile;
|
|
8225
|
+
if (!entry) {
|
|
8226
|
+
if ((this.files['index.html'] || this.files['public/index.html']) && typeof this.previewApp === 'function') {
|
|
8227
|
+
return this.previewApp();
|
|
8228
|
+
}
|
|
8229
|
+
this.terminalLogs.push({ type: 'stderr', text: 'No entry or demo file found in this workspace.' });
|
|
8230
|
+
this.drawerTab = 'terminal';
|
|
8231
|
+
this._renderDrawerBody();
|
|
8232
|
+
return;
|
|
8233
|
+
}
|
|
8234
|
+
return this._executeEntryFile(entry);
|
|
8235
|
+
}
|
|
8236
|
+
|
|
8237
|
+
async formatActiveDocument() {
|
|
8238
|
+
if (!this.activeFile) return;
|
|
8239
|
+
const file = this.activeFile;
|
|
8240
|
+
const code = this.files[file] || '';
|
|
8241
|
+
if (!code) return;
|
|
8242
|
+
|
|
8243
|
+
if (file.endsWith('.js') || file.endsWith('.ts') || file.endsWith('.jsx') || file.endsWith('.tsx')) {
|
|
8244
|
+
if (this.editor && typeof this.editor.getAction === 'function') {
|
|
8245
|
+
const action = this.editor.getAction('editor.action.formatDocument');
|
|
8246
|
+
if (action && typeof action.run === 'function') {
|
|
8247
|
+
await action.run();
|
|
8248
|
+
const newCode = this.editor.getValue();
|
|
8249
|
+
this.files[file] = newCode;
|
|
8250
|
+
this._saveState();
|
|
8251
|
+
this._notifyCodeChange(file, newCode);
|
|
8252
|
+
return;
|
|
8253
|
+
}
|
|
8254
|
+
}
|
|
8255
|
+
} else if (file.endsWith('.cpp') || file.endsWith('.hpp') || file.endsWith('.cc') || file.endsWith('.h')) {
|
|
8256
|
+
let formatter = (root && root.CodeLabWorkbenchComponents && root.CodeLabWorkbenchComponents.formatCppSource) ||
|
|
8257
|
+
(typeof globalThis !== 'undefined' && globalThis.CodeLabWorkbenchComponents && globalThis.CodeLabWorkbenchComponents.formatCppSource) ||
|
|
8258
|
+
null;
|
|
8259
|
+
if (!formatter && typeof require === 'function') {
|
|
8260
|
+
try {
|
|
8261
|
+
const mod = require('./workbench/editor');
|
|
8262
|
+
formatter = mod.formatCppSource;
|
|
8263
|
+
} catch (err) {
|
|
8264
|
+
void err;
|
|
8265
|
+
}
|
|
8266
|
+
}
|
|
8267
|
+
if (formatter) {
|
|
8268
|
+
const formatted = formatter(code);
|
|
8269
|
+
if (formatted !== code) {
|
|
8270
|
+
this.files[file] = formatted;
|
|
8271
|
+
if (this.editor && this.editor.getModel()) {
|
|
8272
|
+
this.editor.setValue(formatted);
|
|
8273
|
+
}
|
|
8274
|
+
this._saveState();
|
|
8275
|
+
this._notifyCodeChange(file, formatted);
|
|
8276
|
+
}
|
|
8277
|
+
}
|
|
8278
|
+
} else if (file.endsWith('.py')) {
|
|
8279
|
+
let formatter = (root && root.CodeLabPython && root.CodeLabPython.formatPythonSource) ||
|
|
8280
|
+
(typeof globalThis !== 'undefined' && globalThis.CodeLabPython && globalThis.CodeLabPython.formatPythonSource) ||
|
|
8281
|
+
null;
|
|
8282
|
+
if (!formatter && typeof require === 'function') {
|
|
8283
|
+
try {
|
|
8284
|
+
const mod = require('./extensions/python');
|
|
8285
|
+
formatter = mod.formatPythonSource;
|
|
8286
|
+
} catch (err) {
|
|
8287
|
+
void err;
|
|
8288
|
+
}
|
|
8289
|
+
}
|
|
8290
|
+
if (formatter) {
|
|
8291
|
+
const formatted = formatter(code);
|
|
8292
|
+
if (formatted !== code) {
|
|
8293
|
+
this.files[file] = formatted;
|
|
8294
|
+
if (this.editor && this.editor.getModel()) {
|
|
8295
|
+
this.editor.setValue(formatted);
|
|
8296
|
+
}
|
|
8297
|
+
this._saveState();
|
|
8298
|
+
this._notifyCodeChange(file, formatted);
|
|
8299
|
+
}
|
|
8300
|
+
}
|
|
8301
|
+
}
|
|
8302
|
+
}
|
|
8303
|
+
|
|
8304
|
+
async shareSnapshot() {
|
|
8305
|
+
let compressor = (root && root.CodeLabWorkbenchComponents && root.CodeLabWorkbenchComponents.compressWorkspaceSnapshot) ||
|
|
8306
|
+
(typeof globalThis !== 'undefined' && globalThis.CodeLabWorkbenchComponents && globalThis.CodeLabWorkbenchComponents.compressWorkspaceSnapshot) ||
|
|
8307
|
+
null;
|
|
8308
|
+
if (!compressor && typeof require === 'function') {
|
|
8309
|
+
try {
|
|
8310
|
+
const mod = require('./workbench/share');
|
|
8311
|
+
compressor = mod.compressWorkspaceSnapshot;
|
|
8312
|
+
} catch (err) {
|
|
8313
|
+
void err;
|
|
8314
|
+
}
|
|
8315
|
+
}
|
|
8316
|
+
if (!compressor) {
|
|
8317
|
+
this._showToast('Snapshot compression not available', 'error');
|
|
8318
|
+
return;
|
|
8319
|
+
}
|
|
8320
|
+
try {
|
|
8321
|
+
const payload = {
|
|
8322
|
+
lang: this.lang,
|
|
8323
|
+
activeFile: this.activeFile,
|
|
8324
|
+
files: { ...this.files },
|
|
8325
|
+
stdin: this.customStdin || ''
|
|
8326
|
+
};
|
|
8327
|
+
const token = await compressor(payload);
|
|
8328
|
+
if (typeof window !== 'undefined' && window.location) {
|
|
8329
|
+
const newUrl = `${window.location.origin}${window.location.pathname}#codelab=${token}`;
|
|
8330
|
+
if (window.history && typeof window.history.replaceState === 'function') {
|
|
8331
|
+
window.history.replaceState(null, '', newUrl);
|
|
8332
|
+
} else {
|
|
8333
|
+
window.location.hash = `codelab=${token}`;
|
|
8334
|
+
}
|
|
8335
|
+
if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
|
|
8336
|
+
await navigator.clipboard.writeText(newUrl);
|
|
8337
|
+
this._showToast('Snapshot link copied to clipboard! (#codelab=...)', 'success');
|
|
8338
|
+
} else {
|
|
8339
|
+
this._showToast('Snapshot link generated in URL hash (#codelab=...)', 'success');
|
|
8340
|
+
}
|
|
8341
|
+
}
|
|
8342
|
+
} catch (err) {
|
|
8343
|
+
this.logger.error('Failed to create snapshot.', err);
|
|
8344
|
+
this._showToast('Failed to create snapshot', 'error');
|
|
8345
|
+
}
|
|
8346
|
+
}
|
|
8347
|
+
|
|
8348
|
+
async _checkUrlSnapshot() {
|
|
8349
|
+
if (typeof window === 'undefined' || !window.location || !window.location.hash) return;
|
|
8350
|
+
const hash = window.location.hash;
|
|
8351
|
+
const match = hash.match(/#(?:codelab|snapshot)=([A-Za-z0-9_-]+)/);
|
|
8352
|
+
if (!match) return;
|
|
8353
|
+
const token = match[1];
|
|
8354
|
+
let decompressor = (root && root.CodeLabWorkbenchComponents && root.CodeLabWorkbenchComponents.decompressWorkspaceSnapshot) ||
|
|
8355
|
+
(typeof globalThis !== 'undefined' && globalThis.CodeLabWorkbenchComponents && globalThis.CodeLabWorkbenchComponents.decompressWorkspaceSnapshot) ||
|
|
8356
|
+
null;
|
|
8357
|
+
if (!decompressor && typeof require === 'function') {
|
|
8358
|
+
try {
|
|
8359
|
+
const mod = require('./workbench/share');
|
|
8360
|
+
decompressor = mod.decompressWorkspaceSnapshot;
|
|
8361
|
+
} catch (err) {
|
|
8362
|
+
void err;
|
|
8363
|
+
}
|
|
8364
|
+
}
|
|
8365
|
+
if (!decompressor) return;
|
|
8366
|
+
try {
|
|
8367
|
+
const snapshot = await decompressor(token);
|
|
8368
|
+
if (snapshot && snapshot.files && typeof snapshot.files === 'object') {
|
|
8369
|
+
this.files = { ...snapshot.files };
|
|
8370
|
+
if (snapshot.lang && (snapshot.lang === 'js' || snapshot.lang === 'ts' || snapshot.lang === 'cpp' || snapshot.lang === 'py')) {
|
|
8371
|
+
this.lang = snapshot.lang;
|
|
8372
|
+
}
|
|
8373
|
+
if (snapshot.stdin) {
|
|
8374
|
+
this.customStdin = snapshot.stdin;
|
|
8375
|
+
}
|
|
8376
|
+
if (snapshot.activeFile && this.files[snapshot.activeFile]) {
|
|
8377
|
+
this.activeFile = snapshot.activeFile;
|
|
8378
|
+
}
|
|
8379
|
+
this.openTabs = Object.keys(this.files);
|
|
8380
|
+
this._renderFileLists();
|
|
8381
|
+
this._renderBreadcrumbs();
|
|
8382
|
+
this._syncAllModels();
|
|
8383
|
+
if (this.activeFile) this.openFile(this.activeFile);
|
|
8384
|
+
this._showToast('Restored workspace from snapshot URL', 'success');
|
|
8385
|
+
}
|
|
8386
|
+
} catch (err) {
|
|
8387
|
+
this.logger.warn('Failed to decompress URL snapshot.', err);
|
|
8388
|
+
}
|
|
7506
8389
|
}
|
|
7507
8390
|
|
|
7508
8391
|
async runTests(filterTestNames = null) {
|
|
7509
8392
|
if (this.isRunning) return;
|
|
7510
8393
|
const entry = this._findEntryFile('test');
|
|
7511
8394
|
if (!entry) {
|
|
7512
|
-
this.terminalLogs.push({ type: 'stderr', text: 'No test.js
|
|
8395
|
+
this.terminalLogs.push({ type: 'stderr', text: 'No test file (test.js, test.ts, test.cpp, test.py) found in this workspace.' });
|
|
7513
8396
|
this.drawerTab = 'terminal';
|
|
7514
8397
|
this._renderDrawerBody();
|
|
7515
8398
|
return;
|
|
7516
8399
|
}
|
|
7517
8400
|
|
|
7518
8401
|
this.isRunning = true;
|
|
7519
|
-
this.
|
|
8402
|
+
this.testSuiteVisible = true;
|
|
7520
8403
|
this.drawerTab = 'tests';
|
|
7521
|
-
this.
|
|
8404
|
+
this._refreshDrawerTabs();
|
|
8405
|
+
this._updateRunStateUI();
|
|
8406
|
+
const isCppTest = /\.(cpp|cc|cxx)$/i.test(entry);
|
|
8407
|
+
const isPyTest = /\.py$/i.test(entry);
|
|
8408
|
+
this.terminalLogs.push({
|
|
8409
|
+
type: 'system',
|
|
8410
|
+
text: isCppTest
|
|
8411
|
+
? `\n$ g++ -std=c++20 ${entry} -o a.out && ./a.out`
|
|
8412
|
+
: isPyTest
|
|
8413
|
+
? `\n$ pytest ${entry}`
|
|
8414
|
+
: `\n$ node ${entry}`
|
|
8415
|
+
});
|
|
7522
8416
|
|
|
7523
|
-
|
|
8417
|
+
let abortCtrl = new AbortController();
|
|
7524
8418
|
this._activeCommandAbortController = abortCtrl;
|
|
7525
8419
|
let streamedStdout = false;
|
|
7526
8420
|
let streamedStderr = false;
|
|
8421
|
+
let lastRes = null;
|
|
7527
8422
|
|
|
7528
8423
|
try {
|
|
7529
8424
|
const res = await this._executeRuntime({
|
|
7530
8425
|
files: { ...this.files },
|
|
7531
8426
|
entry,
|
|
7532
8427
|
mode: 'test',
|
|
8428
|
+
stdin: this.customStdin || '',
|
|
7533
8429
|
testFilter: filterTestNames,
|
|
7534
8430
|
signal: abortCtrl.signal,
|
|
7535
8431
|
onStdout: (c) => {
|
|
@@ -7541,6 +8437,7 @@ declare module 'bun:sqlite' {
|
|
|
7541
8437
|
this._appendTerminalStream('stderr', c);
|
|
7542
8438
|
}
|
|
7543
8439
|
});
|
|
8440
|
+
lastRes = res;
|
|
7544
8441
|
this._flushTerminalStream();
|
|
7545
8442
|
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
7546
8443
|
|
|
@@ -7548,6 +8445,9 @@ declare module 'bun:sqlite' {
|
|
|
7548
8445
|
this.lastTestResults = res.testResults || [];
|
|
7549
8446
|
this.lastFsSnapshot = res.fsSnapshot || [];
|
|
7550
8447
|
this.lastHttpTrace = res.httpTrace || [];
|
|
8448
|
+
if (res.durationMs !== undefined) this.lastDurationMs = res.durationMs;
|
|
8449
|
+
if (res.peakMemoryBytes !== undefined) this.lastPeakMemoryBytes = res.peakMemoryBytes;
|
|
8450
|
+
this._updateTelemetryHud();
|
|
7551
8451
|
}
|
|
7552
8452
|
|
|
7553
8453
|
if (!aborted && !streamedStdout && res.stdout) {
|
|
@@ -7621,6 +8521,7 @@ declare module 'bun:sqlite' {
|
|
|
7621
8521
|
this._renderStepPills();
|
|
7622
8522
|
this._renderGuidePane();
|
|
7623
8523
|
this._renderDrawerBody();
|
|
8524
|
+
return lastRes;
|
|
7624
8525
|
}
|
|
7625
8526
|
|
|
7626
8527
|
async verifyCurrentStep() {
|
|
@@ -7951,7 +8852,7 @@ declare module 'bun:sqlite' {
|
|
|
7951
8852
|
if (data.mode === 'guided' || data.mode === 'sandbox') {
|
|
7952
8853
|
this.mode = data.mode;
|
|
7953
8854
|
}
|
|
7954
|
-
if (data.language === 'js' || data.language === 'ts') {
|
|
8855
|
+
if (data.language === 'js' || data.language === 'ts' || data.language === 'cpp') {
|
|
7955
8856
|
this.lang = data.language;
|
|
7956
8857
|
}
|
|
7957
8858
|
if (data.files && typeof data.files === 'object') {
|
|
@@ -8106,6 +9007,7 @@ declare module 'bun:sqlite' {
|
|
|
8106
9007
|
}
|
|
8107
9008
|
|
|
8108
9009
|
showProblemsModal() {
|
|
9010
|
+
this.switchDrawerTab('problems');
|
|
8109
9011
|
const slot = this.container ? this.container.querySelector('#cl-modal-slot') : null;
|
|
8110
9012
|
if (!slot) return;
|
|
8111
9013
|
const items = this.getDiagnostics();
|
|
@@ -8501,6 +9403,14 @@ declare module 'bun:sqlite' {
|
|
|
8501
9403
|
} else if (typeof plugin === 'object' && typeof plugin.install === 'function') {
|
|
8502
9404
|
plugin.install(this, pluginOptions);
|
|
8503
9405
|
}
|
|
9406
|
+
if (this.enabledLanguages instanceof Set && this.enabledLanguages.size > 1) {
|
|
9407
|
+
this.hasMultipleLanguages = true;
|
|
9408
|
+
}
|
|
9409
|
+
if (typeof this._refreshToolbarAndTabs === 'function') {
|
|
9410
|
+
this._refreshToolbarAndTabs();
|
|
9411
|
+
} else {
|
|
9412
|
+
this._refreshLanguageSwitcher();
|
|
9413
|
+
}
|
|
8504
9414
|
return this;
|
|
8505
9415
|
}
|
|
8506
9416
|
|
|
@@ -8563,7 +9473,7 @@ declare module 'bun:sqlite' {
|
|
|
8563
9473
|
if (rootEl) rootEl.setAttribute('data-cl-theme', this._instance._resolvedTheme());
|
|
8564
9474
|
} else if (name === 'mode' && (newVal === 'guided' || newVal === 'sandbox')) {
|
|
8565
9475
|
this._instance.switchMode(newVal);
|
|
8566
|
-
} else if ((name === 'language' || name === 'lang') && (newVal === 'js' || newVal === 'ts')) {
|
|
9476
|
+
} else if ((name === 'language' || name === 'lang') && (newVal === 'js' || newVal === 'ts' || newVal === 'cpp')) {
|
|
8567
9477
|
this._instance.switchLang(newVal);
|
|
8568
9478
|
} else if (name === 'title' && newVal) {
|
|
8569
9479
|
this._instance.title = newVal;
|
|
@@ -8635,8 +9545,13 @@ declare module 'bun:sqlite' {
|
|
|
8635
9545
|
openCommandPalette(mode) { if (this._instance) this._instance.openCommandPalette(mode); }
|
|
8636
9546
|
showDiffModal(file, target) { if (this._instance) this._instance.showDiffModal(file, target); }
|
|
8637
9547
|
cloneRepo(repoInput, opts) { return this._instance ? this._instance.cloneRepo(repoInput, opts) : Promise.reject(new Error('Workbench not mounted')); }
|
|
9548
|
+
runCode() { return this._instance ? this._instance.runCode() : Promise.resolve(); }
|
|
9549
|
+
runEntry() { return this._instance ? this._instance.runEntry() : Promise.resolve(); }
|
|
9550
|
+
runActiveFile() { return this._instance ? this._instance.runActiveFile() : Promise.resolve(); }
|
|
8638
9551
|
runDemo() { return this._instance ? this._instance.runDemo() : Promise.resolve(); }
|
|
8639
9552
|
runTests(filter) { return this._instance ? this._instance.runTests(filter) : Promise.resolve(); }
|
|
9553
|
+
formatActiveDocument() { return this._instance ? this._instance.formatActiveDocument() : Promise.resolve(); }
|
|
9554
|
+
shareSnapshot() { return this._instance ? this._instance.shareSnapshot() : Promise.resolve(); }
|
|
8640
9555
|
previewApp() { return this._instance ? this._instance.previewApp() : Promise.resolve(null); }
|
|
8641
9556
|
stopExecution() { if (this._instance) this._instance.stopExecution(); }
|
|
8642
9557
|
reset() { if (this._instance) this._instance.reset(); }
|
|
@@ -8728,7 +9643,11 @@ declare module 'bun:sqlite' {
|
|
|
8728
9643
|
renderMarkdown: renderSimpleMarkdown,
|
|
8729
9644
|
renderSimpleMarkdown: renderSimpleMarkdown,
|
|
8730
9645
|
extensions: {
|
|
8731
|
-
guidedLab: null
|
|
9646
|
+
guidedLab: null,
|
|
9647
|
+
javascript: null,
|
|
9648
|
+
typescript: null,
|
|
9649
|
+
cpp: null,
|
|
9650
|
+
python: null
|
|
8732
9651
|
},
|
|
8733
9652
|
parseGitHubRepoUrl,
|
|
8734
9653
|
cloneRepo: cloneGitHubRepository,
|
|
@@ -8755,3 +9674,22 @@ declare module 'bun:sqlite' {
|
|
|
8755
9674
|
module.exports = CodeLabSDK;
|
|
8756
9675
|
}
|
|
8757
9676
|
})(typeof window !== 'undefined' ? window : globalThis);
|
|
9677
|
+
|
|
9678
|
+
// ── TypeScript module surface (stripped from browser bundles) ──────────────
|
|
9679
|
+
const _hostWorkbench: any = (typeof globalThis !== 'undefined' ? (globalThis as any).CodeLabWorkbench : undefined)
|
|
9680
|
+
|| (typeof window !== 'undefined' ? (window as any).CodeLabWorkbench : undefined)
|
|
9681
|
+
|| (typeof module !== 'undefined' && module.exports && (module.exports.CodeLabWorkbench || module.exports) ? (module.exports.CodeLabWorkbench || module.exports) : undefined);
|
|
9682
|
+
|
|
9683
|
+
const _hostElement: any = (typeof globalThis !== 'undefined' ? (globalThis as any).CodeLabElement : undefined)
|
|
9684
|
+
|| (typeof window !== 'undefined' ? (window as any).CodeLabElement : undefined)
|
|
9685
|
+
|| (typeof module !== 'undefined' && module.exports ? module.exports.CodeLabElement : undefined);
|
|
9686
|
+
|
|
9687
|
+
const _hostSDK: any = (typeof globalThis !== 'undefined' ? (globalThis as any).CodeLab : undefined)
|
|
9688
|
+
|| (typeof window !== 'undefined' ? (window as any).CodeLab : undefined)
|
|
9689
|
+
|| (typeof module !== 'undefined' && module.exports ? module.exports : {});
|
|
9690
|
+
|
|
9691
|
+
export const CodeLabWorkbench: any = _hostWorkbench;
|
|
9692
|
+
export const Workbench: any = _hostWorkbench;
|
|
9693
|
+
export const CodeLabElement: any = _hostElement;
|
|
9694
|
+
export const CodeLab: any = _hostSDK;
|
|
9695
|
+
export default _hostSDK;
|