Update editor, themes, menus, backgrounds, and release tooling
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { actionIcon, type ActionIcon } from "../ui/actionIcons";
|
||||
import { attachTooltip } from "../ui/tooltip";
|
||||
const tooltipCleanups = new WeakMap<HTMLElement, () => void>();
|
||||
import { actionMenu, type ActionMenuItem } from "../ui/actionMenu";
|
||||
|
||||
export type ImageActions = {
|
||||
@@ -32,7 +34,7 @@ function button(label: string, icon: ActionIcon, action: () => void) {
|
||||
control.type = "button";
|
||||
control.className = "image-action";
|
||||
control.setAttribute("aria-label", label);
|
||||
control.dataset.tooltip = label;
|
||||
tooltipCleanups.set(control, attachTooltip(control, () => label));
|
||||
control.append(actionIcon(icon));
|
||||
control.addEventListener("click", event => { event.preventDefault(); event.stopPropagation(); action(); });
|
||||
return control;
|
||||
@@ -73,7 +75,7 @@ function zoomImage(original: HTMLImageElement, trigger: HTMLButtonElement) {
|
||||
dialog.append(header, viewport);
|
||||
dialog.addEventListener("click", event => { if (event.target === dialog || event.target === viewport) dialog.close(); });
|
||||
// Escape and focus trapping are provided by the native modal dialog.
|
||||
dialog.addEventListener("close", () => { dialog.remove(); if (trigger.isConnected) trigger.focus(); }, { once: true });
|
||||
dialog.addEventListener("close", () => { [zoomOut, zoomIn, fit, close].forEach(button => tooltipCleanups.get(button)?.()); dialog.remove(); if (trigger.isConnected) trigger.focus(); }, { once: true });
|
||||
image.addEventListener("load", () => resize(scale));
|
||||
document.body.append(dialog);
|
||||
dialog.showModal();
|
||||
@@ -103,6 +105,7 @@ export function imageControls(root: HTMLElement, actions: ImageActions = {}, mea
|
||||
toolbar.append(zoom);
|
||||
if (actions.edit) toolbar.append(button(actions.editing ? "Hide image source" : "Edit image source", "code", actions.editing && actions.done ? actions.done : actions.edit));
|
||||
frame.append(toolbar);
|
||||
cleanup.push(() => toolbar.querySelectorAll<HTMLButtonElement>("button").forEach(button => tooltipCleanups.get(button)?.()));
|
||||
let menu: HTMLElement | undefined;
|
||||
let openingMenu = false;
|
||||
function closeMenu(focus = true) { menu?.remove(); menu = undefined; if (focus && frame.isConnected) frame.focus({ preventScroll: true }); }
|
||||
|
||||
Reference in New Issue
Block a user