Add playground entry selector
This commit is contained in:
@@ -20,6 +20,7 @@ const activeFile = document.getElementById('active-file');
|
||||
const newFile = document.getElementById('new-file');
|
||||
const deleteFile = document.getElementById('delete-file');
|
||||
const exampleSelect = document.getElementById('example-select');
|
||||
const entrySelect = document.getElementById('entry-select');
|
||||
const loadExample = document.getElementById('load-example');
|
||||
|
||||
const project = loadProject();
|
||||
@@ -178,18 +179,32 @@ function setActiveFile(path) {
|
||||
}
|
||||
project.activePath = normalized;
|
||||
setEditorText(project.files[normalized]);
|
||||
activeFile.textContent = normalized === project.entryPath ? `${normalized} (entry)` : normalized;
|
||||
activeFile.textContent = normalized;
|
||||
deleteFile.disabled = Object.keys(project.files).length <= 1;
|
||||
renderFileTree();
|
||||
updateRunLabel();
|
||||
saveProject();
|
||||
}
|
||||
|
||||
function updateRunLabel() {
|
||||
function updateEntrySelect() {
|
||||
const paths = Object.keys(project.files).sort();
|
||||
const entryPath = project.files[project.entryPath] === undefined ? project.activePath : project.entryPath;
|
||||
project.entryPath = entryPath;
|
||||
run.textContent = `Run ${entryPath}`;
|
||||
run.title = `Materialize ${entryPath}`;
|
||||
entrySelect.replaceChildren(
|
||||
...paths.map((path) => {
|
||||
const option = document.createElement('option');
|
||||
option.value = path;
|
||||
option.textContent = path;
|
||||
return option;
|
||||
}),
|
||||
);
|
||||
entrySelect.value = entryPath;
|
||||
}
|
||||
|
||||
function updateRunLabel() {
|
||||
updateEntrySelect();
|
||||
run.textContent = 'Run';
|
||||
run.title = `Materialize ${project.entryPath}`;
|
||||
}
|
||||
|
||||
function execute() {
|
||||
@@ -247,8 +262,8 @@ function renderTreeList(children) {
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = child.path === project.activePath ? 'file active' : 'file';
|
||||
button.textContent = child.path === project.entryPath ? `${child.name} *` : child.name;
|
||||
button.title = child.path === project.entryPath ? `${child.path} (entry point)` : child.path;
|
||||
button.textContent = child.name;
|
||||
button.title = child.path;
|
||||
button.addEventListener('click', () => setActiveFile(child.path));
|
||||
item.append(button);
|
||||
} else {
|
||||
@@ -277,6 +292,13 @@ try {
|
||||
status.textContent = `Failed to load WASM: ${error?.message ?? error}`;
|
||||
}
|
||||
|
||||
entrySelect.addEventListener('change', () => {
|
||||
const path = normalizePath(entrySelect.value);
|
||||
if (project.files[path] === undefined) return;
|
||||
project.entryPath = path;
|
||||
updateRunLabel();
|
||||
saveProject();
|
||||
});
|
||||
run.addEventListener('click', execute);
|
||||
formatButton.addEventListener('click', formatActiveFile);
|
||||
loadExample.addEventListener('click', () => {
|
||||
|
||||
Reference in New Issue
Block a user