Add playground entry selector
This commit is contained in:
@@ -9,15 +9,23 @@ import ManualLayout from '../layouts/ManualLayout.astro';
|
|||||||
<p>Virtual files are evaluated in the browser through WebAssembly. Use import paths such as <code>./schemas/service.dcdl</code>.</p>
|
<p>Virtual files are evaluated in the browser through WebAssembly. Use import paths such as <code>./schemas/service.dcdl</code>.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="playground-actions">
|
<div class="playground-actions">
|
||||||
|
<div class="action-group example-actions">
|
||||||
<label class="example-picker">
|
<label class="example-picker">
|
||||||
<span>Example</span>
|
<span>Example</span>
|
||||||
<select id="example-select" aria-label="Playground example"></select>
|
<select id="example-select" aria-label="Playground example"></select>
|
||||||
</label>
|
</label>
|
||||||
<button id="load-example" type="button">Load</button>
|
<button id="load-example" type="button">Load</button>
|
||||||
<p id="status" class="status">Loading WASM...</p>
|
</div>
|
||||||
|
<div class="action-group run-actions">
|
||||||
<button id="format" disabled>Format</button>
|
<button id="format" disabled>Format</button>
|
||||||
|
<label class="entry-picker">
|
||||||
|
<span>Entry</span>
|
||||||
|
<select id="entry-select" aria-label="Entry point file"></select>
|
||||||
|
</label>
|
||||||
<button id="run" disabled>Run</button>
|
<button id="run" disabled>Run</button>
|
||||||
</div>
|
</div>
|
||||||
|
<p id="status" class="status">Loading WASM...</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="playground-shell">
|
<div class="playground-shell">
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ const activeFile = document.getElementById('active-file');
|
|||||||
const newFile = document.getElementById('new-file');
|
const newFile = document.getElementById('new-file');
|
||||||
const deleteFile = document.getElementById('delete-file');
|
const deleteFile = document.getElementById('delete-file');
|
||||||
const exampleSelect = document.getElementById('example-select');
|
const exampleSelect = document.getElementById('example-select');
|
||||||
|
const entrySelect = document.getElementById('entry-select');
|
||||||
const loadExample = document.getElementById('load-example');
|
const loadExample = document.getElementById('load-example');
|
||||||
|
|
||||||
const project = loadProject();
|
const project = loadProject();
|
||||||
@@ -178,18 +179,32 @@ function setActiveFile(path) {
|
|||||||
}
|
}
|
||||||
project.activePath = normalized;
|
project.activePath = normalized;
|
||||||
setEditorText(project.files[normalized]);
|
setEditorText(project.files[normalized]);
|
||||||
activeFile.textContent = normalized === project.entryPath ? `${normalized} (entry)` : normalized;
|
activeFile.textContent = normalized;
|
||||||
deleteFile.disabled = Object.keys(project.files).length <= 1;
|
deleteFile.disabled = Object.keys(project.files).length <= 1;
|
||||||
renderFileTree();
|
renderFileTree();
|
||||||
updateRunLabel();
|
updateRunLabel();
|
||||||
saveProject();
|
saveProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateRunLabel() {
|
function updateEntrySelect() {
|
||||||
|
const paths = Object.keys(project.files).sort();
|
||||||
const entryPath = project.files[project.entryPath] === undefined ? project.activePath : project.entryPath;
|
const entryPath = project.files[project.entryPath] === undefined ? project.activePath : project.entryPath;
|
||||||
project.entryPath = entryPath;
|
project.entryPath = entryPath;
|
||||||
run.textContent = `Run ${entryPath}`;
|
entrySelect.replaceChildren(
|
||||||
run.title = `Materialize ${entryPath}`;
|
...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() {
|
function execute() {
|
||||||
@@ -247,8 +262,8 @@ function renderTreeList(children) {
|
|||||||
const button = document.createElement('button');
|
const button = document.createElement('button');
|
||||||
button.type = 'button';
|
button.type = 'button';
|
||||||
button.className = child.path === project.activePath ? 'file active' : 'file';
|
button.className = child.path === project.activePath ? 'file active' : 'file';
|
||||||
button.textContent = child.path === project.entryPath ? `${child.name} *` : child.name;
|
button.textContent = child.name;
|
||||||
button.title = child.path === project.entryPath ? `${child.path} (entry point)` : child.path;
|
button.title = child.path;
|
||||||
button.addEventListener('click', () => setActiveFile(child.path));
|
button.addEventListener('click', () => setActiveFile(child.path));
|
||||||
item.append(button);
|
item.append(button);
|
||||||
} else {
|
} else {
|
||||||
@@ -277,6 +292,13 @@ try {
|
|||||||
status.textContent = `Failed to load WASM: ${error?.message ?? error}`;
|
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);
|
run.addEventListener('click', execute);
|
||||||
formatButton.addEventListener('click', formatActiveFile);
|
formatButton.addEventListener('click', formatActiveFile);
|
||||||
loadExample.addEventListener('click', () => {
|
loadExample.addEventListener('click', () => {
|
||||||
|
|||||||
@@ -293,11 +293,26 @@ main.playground {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
gap: 8px;
|
gap: 10px;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
|
|
||||||
.example-picker {
|
.action-group {
|
||||||
|
align-items: center;
|
||||||
|
background: rgba(15, 23, 42, 0.55);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 12px;
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.run-actions {
|
||||||
|
border-color: rgba(96, 165, 250, 0.35);
|
||||||
|
}
|
||||||
|
|
||||||
|
.example-picker,
|
||||||
|
.entry-picker {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -307,7 +322,8 @@ main.playground {
|
|||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
}
|
}
|
||||||
|
|
||||||
.example-picker select {
|
.example-picker select,
|
||||||
|
.entry-picker select {
|
||||||
background: var(--surface);
|
background: var(--surface);
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
@@ -318,6 +334,10 @@ main.playground {
|
|||||||
text-transform: none;
|
text-transform: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.entry-picker select {
|
||||||
|
max-width: 220px;
|
||||||
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
background: var(--link);
|
background: var(--link);
|
||||||
border: 0;
|
border: 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user