Add back button
This commit is contained in:
@@ -13,6 +13,10 @@
|
|||||||
<div id="automaton-collection"></div>
|
<div id="automaton-collection"></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="app" hidden="hidden">
|
<div id="app" hidden="hidden">
|
||||||
|
<div class="actions">
|
||||||
|
<button id="back-button">Back</button>
|
||||||
|
<a id="controls-button" class="button open-modal" href="#controls">Controls</a>
|
||||||
|
</div>
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<input type="text" id="word-input" autocapitalize="off" spellcheck="false" />
|
<input type="text" id="word-input" autocapitalize="off" spellcheck="false" />
|
||||||
<div id="light"></div>
|
<div id="light"></div>
|
||||||
@@ -20,7 +24,6 @@
|
|||||||
<div class="input">
|
<div class="input">
|
||||||
<div id="input-buttons"></div>
|
<div id="input-buttons"></div>
|
||||||
<button id="clear-button">Clear</button>
|
<button id="clear-button">Clear</button>
|
||||||
<a id="controls-button" class="button open-modal" href="#controls">Controls</a>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="state-graph"></div>
|
<div id="state-graph"></div>
|
||||||
</div>
|
</div>
|
||||||
|
36
src/fsm.js
36
src/fsm.js
@@ -9,6 +9,7 @@ const buttons = /** @type {HTMLDivElement} */ (document.getElementById('input-bu
|
|||||||
const controlsButton = /** @type {HTMLButtonElement} */ (document.getElementById('controls-button'));
|
const controlsButton = /** @type {HTMLButtonElement} */ (document.getElementById('controls-button'));
|
||||||
const clearButton = /** @type {HTMLButtonElement} */ (document.getElementById('clear-button'));
|
const clearButton = /** @type {HTMLButtonElement} */ (document.getElementById('clear-button'));
|
||||||
const light = /** @type {HTMLDivElement} */ (document.getElementById('light'));
|
const light = /** @type {HTMLDivElement} */ (document.getElementById('light'));
|
||||||
|
const container = /** @type {HTMLDivElement} */ (document.getElementById('state-graph'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import('./examples.js').State[]} states
|
* @param {import('./examples.js').State[]} states
|
||||||
@@ -34,7 +35,9 @@ export function openAutomaton(states, editable = false) {
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const container = /** @type {HTMLDivElement} */ (document.getElementById('state-graph'));
|
while (container.firstChild) {
|
||||||
|
container.removeChild(container.firstChild);
|
||||||
|
}
|
||||||
container.appendChild(viewer);
|
container.appendChild(viewer);
|
||||||
viewer.graph = graph;
|
viewer.graph = graph;
|
||||||
|
|
||||||
@@ -83,21 +86,30 @@ export function openAutomaton(states, editable = false) {
|
|||||||
updateUIState();
|
updateUIState();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dynamically create buttons for each letter in the alphabet
|
|
||||||
/**
|
/**
|
||||||
* @type {string[]}
|
* Dynamically create buttons for each letter in the alphabet.
|
||||||
*/
|
*/
|
||||||
const alphabet = Array.from(states.reduce((acc, current) => {
|
function createLetters() {
|
||||||
Object.keys(current.transitions).forEach(current => acc.add(current));
|
/**
|
||||||
return acc;
|
* @type {string[]}
|
||||||
}, new Set())).sort();
|
*/
|
||||||
for (const letter of alphabet) {
|
const alphabet = Array.from(states.reduce((acc, current) => {
|
||||||
const button = document.createElement('button');
|
Object.keys(current.transitions).forEach(current => acc.add(current));
|
||||||
button.innerText = letter;
|
return acc;
|
||||||
button.addEventListener('click', () => step(letter));
|
}, new Set())).sort();
|
||||||
buttons.appendChild(button);
|
while (buttons.firstChild) {
|
||||||
|
buttons.removeChild(buttons.firstChild);
|
||||||
|
}
|
||||||
|
for (const letter of alphabet) {
|
||||||
|
const button = document.createElement('button');
|
||||||
|
button.innerText = letter;
|
||||||
|
button.addEventListener('click', () => step(letter));
|
||||||
|
buttons.appendChild(button);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createLetters();
|
||||||
|
|
||||||
// Reacts to input in the text box
|
// Reacts to input in the text box
|
||||||
wordInput.addEventListener('input', () => type());
|
wordInput.addEventListener('input', () => type());
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ import './modal.ts';
|
|||||||
|
|
||||||
const automatonSelector = /** @type {HTMLDivElement} */ (document.getElementById('automaton-selector'));
|
const automatonSelector = /** @type {HTMLDivElement} */ (document.getElementById('automaton-selector'));
|
||||||
const automatonCollection = /** @type {HTMLDivElement} */ (document.getElementById('automaton-collection'));
|
const automatonCollection = /** @type {HTMLDivElement} */ (document.getElementById('automaton-collection'));
|
||||||
|
const backButton = /** @type {HTMLButtonElement} */ (document.getElementById('back-button'));
|
||||||
const app = /** @type {HTMLDivElement} */ (document.getElementById('app'));
|
const app = /** @type {HTMLDivElement} */ (document.getElementById('app'));
|
||||||
|
|
||||||
for (const [displayName, automaton] of Object.entries(AUTOMATONS)) {
|
for (const [displayName, automaton] of Object.entries(AUTOMATONS)) {
|
||||||
@@ -44,3 +45,8 @@ create.addEventListener('click', () => {
|
|||||||
app.removeAttribute('hidden');
|
app.removeAttribute('hidden');
|
||||||
openAutomaton([], true);
|
openAutomaton([], true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
backButton.addEventListener('click', () => {
|
||||||
|
app.setAttribute('hidden', 'hidden');
|
||||||
|
automatonSelector.removeAttribute('hidden');
|
||||||
|
});
|
||||||
|
@@ -199,6 +199,12 @@ th, td {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
position: absolute;
|
||||||
|
top: 16px;
|
||||||
|
left: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
.modal {
|
.modal {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -226,7 +232,7 @@ th, td {
|
|||||||
color: #213547;
|
color: #213547;
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
}
|
}
|
||||||
button, .btn {
|
button, .button {
|
||||||
background-color: #f9f9f9;
|
background-color: #f9f9f9;
|
||||||
}
|
}
|
||||||
.context-menu {
|
.context-menu {
|
||||||
|
Reference in New Issue
Block a user