[web] The web UI: hosts, add/edit with apply progress, undo, history and restore, share links, engine switch, certificates and device installs, signing by hand, settings and tokens; smoke test counts every §4 flow's clicks
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
|
||||
<script lang="ts">
|
||||
import type { Snippet } from "svelte";
|
||||
import { onMount } from "svelte";
|
||||
import Icon from "./Icon.svelte";
|
||||
|
||||
// Handoff §2.9: a native <dialog>, modal (showModal) or not (the engine popover). Focus goes
|
||||
// to the first field (or the element marked data-autofocus), and back to the opener on close.
|
||||
let {
|
||||
title,
|
||||
kind = "dialog",
|
||||
modal = true,
|
||||
role,
|
||||
onclose,
|
||||
escape = true,
|
||||
closable = true,
|
||||
children,
|
||||
footer,
|
||||
}: {
|
||||
title: string;
|
||||
kind?: "dialog" | "panel" | "popover";
|
||||
modal?: boolean;
|
||||
role?: "dialog" | "alertdialog";
|
||||
onclose: () => void;
|
||||
escape?: boolean;
|
||||
closable?: boolean;
|
||||
children?: Snippet;
|
||||
footer?: Snippet;
|
||||
} = $props();
|
||||
|
||||
let el: HTMLDialogElement | undefined = $state();
|
||||
const id = "dlg-" + Math.random().toString(36).slice(2, 9);
|
||||
|
||||
onMount(() => {
|
||||
const opener = document.activeElement;
|
||||
if (el) {
|
||||
if (modal && typeof el.showModal === "function") el.showModal();
|
||||
else if (typeof el.show === "function") el.show();
|
||||
else el.setAttribute("open", "");
|
||||
const first = el.querySelector<HTMLElement>(
|
||||
"[data-autofocus], input:not([type=hidden]):not([readonly]):not([type=radio]), textarea, select",
|
||||
);
|
||||
(first ?? el.querySelector<HTMLElement>(".ia-dialog-title"))?.focus();
|
||||
}
|
||||
return () => {
|
||||
if (opener instanceof HTMLElement && document.contains(opener)) opener.focus();
|
||||
};
|
||||
});
|
||||
|
||||
function cancel(e: Event) {
|
||||
e.preventDefault();
|
||||
if (escape) onclose();
|
||||
}
|
||||
</script>
|
||||
|
||||
<dialog
|
||||
bind:this={el}
|
||||
class="ia-dialog {kind === 'panel' ? 'ia-panel' : kind === 'popover' ? 'ia-popover' : ''}"
|
||||
aria-labelledby={id}
|
||||
{role}
|
||||
oncancel={cancel}
|
||||
>
|
||||
<div class="ia-dialog-head">
|
||||
<h2 class="ia-h3 ia-dialog-title" id={id} tabindex="-1">{title}</h2>
|
||||
{#if closable}
|
||||
<button type="button" class="ia-icon-btn" aria-label="Close" onclick={() => onclose()}><Icon name="close" /></button>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="ia-panel-body">{@render children?.()}</div>
|
||||
{#if footer}<div class="ia-dialog-foot">{@render footer()}</div>{/if}
|
||||
</dialog>
|
||||
Reference in New Issue
Block a user