Add a modal for controls
This commit is contained in:
47
index.html
47
index.html
@@ -20,9 +20,56 @@
|
|||||||
<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>
|
||||||
|
<div id="controls" class="modal" hidden="hidden">
|
||||||
|
<div class="modal-content">
|
||||||
|
<h3>Controls</h3>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Action</th>
|
||||||
|
<th>Desktop</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Pan</td>
|
||||||
|
<td>Left-click and drag</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Zoom in/out</td>
|
||||||
|
<td>Mouse wheel</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Create state</td>
|
||||||
|
<td>Double-click</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Move state</td>
|
||||||
|
<td>Middle-click and drag</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Edit/Delete state</td>
|
||||||
|
<td>Right-click</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Create transition</td>
|
||||||
|
<td>Left-click and drag</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Edit transition</td>
|
||||||
|
<td>Right-click</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Delete transition</td>
|
||||||
|
<td>Right-click</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<script type="module" src="src/main.js"></script>
|
<script type="module" src="src/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -6,6 +6,7 @@ const IS_INVALID = 'is-invalid';
|
|||||||
|
|
||||||
const wordInput = /** @type {HTMLInputElement} */ (document.getElementById('word-input'));
|
const wordInput = /** @type {HTMLInputElement} */ (document.getElementById('word-input'));
|
||||||
const buttons = /** @type {HTMLDivElement} */ (document.getElementById('input-buttons'));
|
const buttons = /** @type {HTMLDivElement} */ (document.getElementById('input-buttons'));
|
||||||
|
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'));
|
||||||
|
|
||||||
@@ -19,6 +20,11 @@ export function openAutomaton(states, editable = false) {
|
|||||||
|
|
||||||
const viewer = new GraphEditor();
|
const viewer = new GraphEditor();
|
||||||
viewer.readonly = !editable;
|
viewer.readonly = !editable;
|
||||||
|
if (editable) {
|
||||||
|
controlsButton.removeAttribute('hidden');
|
||||||
|
} else {
|
||||||
|
controlsButton.setAttribute('hidden', 'hidden');
|
||||||
|
}
|
||||||
const graph = createGraph(states);
|
const graph = createGraph(states);
|
||||||
viewer.addEventListener('change', () => {
|
viewer.addEventListener('change', () => {
|
||||||
try {
|
try {
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import { AUTOMATONS } from './examples.js';
|
import { AUTOMATONS } from './examples.js';
|
||||||
import { openAutomaton } from './fsm.js';
|
import { openAutomaton } from './fsm.js';
|
||||||
|
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'));
|
||||||
|
34
src/modal.ts
Normal file
34
src/modal.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
let modal: HTMLElement | null = null;
|
||||||
|
|
||||||
|
function openModal(event: Event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const el = document.querySelector((event.target as HTMLElement).getAttribute('href')!)! as HTMLElement;
|
||||||
|
// @ts-expect-error reset
|
||||||
|
el.style.display = null;
|
||||||
|
el.removeAttribute('hidden');
|
||||||
|
el.setAttribute('aria-modal', 'true');
|
||||||
|
modal = el;
|
||||||
|
modal.addEventListener('click', closeModal);
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeModal(event: Event) {
|
||||||
|
event.preventDefault();
|
||||||
|
if (modal === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modal.style.display = 'none';
|
||||||
|
modal.setAttribute('hidden', 'hidden');
|
||||||
|
modal.removeAttribute('aria-modal');
|
||||||
|
modal.removeEventListener('click', closeModal);
|
||||||
|
modal = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('.open-modal').forEach((el) => {
|
||||||
|
el.addEventListener('click', openModal);
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('keydown', (event) => {
|
||||||
|
if (event.key === 'Escape' && modal !== null) {
|
||||||
|
closeModal(event);
|
||||||
|
}
|
||||||
|
});
|
@@ -43,7 +43,7 @@ input {
|
|||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
transition: border-color 0.25s;
|
transition: border-color 0.25s;
|
||||||
}
|
}
|
||||||
button {
|
button, .button {
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
padding: 0.6em 1.2em;
|
padding: 0.6em 1.2em;
|
||||||
@@ -53,8 +53,10 @@ button {
|
|||||||
background-color: #1a1a1a;
|
background-color: #1a1a1a;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: border-color 0.25s;
|
transition: border-color 0.25s;
|
||||||
|
text-decoration: none;
|
||||||
|
color: inherit;
|
||||||
}
|
}
|
||||||
button:hover {
|
button:hover, .button:hover {
|
||||||
border-color: #646cff;
|
border-color: #646cff;
|
||||||
}
|
}
|
||||||
button:focus,
|
button:focus,
|
||||||
@@ -184,12 +186,47 @@ graph-editor {
|
|||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
th, td {
|
||||||
|
border-bottom: thin solid hsla(0, 0%, 100%, .12);
|
||||||
|
height: 48px;
|
||||||
|
padding: 0 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal[hidden] {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal {
|
||||||
|
position: fixed;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: rgba(0, 0, 0, .8);
|
||||||
|
animation: fadeIn .3s both
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-content {
|
||||||
|
overflow: auto;
|
||||||
|
width: 600px;
|
||||||
|
max-width: calc(100vw - 20px);
|
||||||
|
max-height: calc(100vh - 20px);
|
||||||
|
padding: 20px;
|
||||||
|
background-color: #1a1a1a;
|
||||||
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: light) {
|
@media (prefers-color-scheme: light) {
|
||||||
:root {
|
:root {
|
||||||
color: #213547;
|
color: #213547;
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
}
|
}
|
||||||
button {
|
button, .btn {
|
||||||
background-color: #f9f9f9;
|
background-color: #f9f9f9;
|
||||||
}
|
}
|
||||||
.context-menu {
|
.context-menu {
|
||||||
|
Reference in New Issue
Block a user