Back to Black Site Map Editor
SOURCE / PINNED RELEASE

Made of little things.

Black Site Map Editor

Release
32a57733b7e9…
Author-recorded commit
3f54890f542f…
License
LICENSE
Author’s source reference
nostr://npub1ye5ptcxfyyxl5vjvdjar2ua3f0hynkjzpx552mu5snj3qmx5pzjscpknpr/wss%3A%2F%2Fgit.shakespeare.diy%2F/black-site-map-editor

Archive hash verified: 7a4b1abbac7db5b0…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

src/components/key-hint.ts
import { noChange } from 'lit';
import { Directive, directive, PartType, type ElementPart, type PartInfo } from 'lit/directive.js';
import { editor } from '../editor-controller';
import { ariaCombo, formatCombo } from '../key-combo';

/** Current display label for a shortcut, or '' while unbound or still registering. */
export function bindingLabel(id: string): string {
    const state = editor.shortcuts.get(id);
    return state?.binding && state.source !== 'pending' ? formatCombo(state.binding) : '';
}

class KeyHint extends Directive {
    constructor(part: PartInfo) {
        super(part);
        if (part.type !== PartType.ELEMENT) throw new Error('keyHint belongs on an element.');
    }
    render(_id: string, _label?: string) {
        return noChange;
    }
    update(part: ElementPart, [id, label]: [string, string?]) {
        const state = editor.shortcuts.get(id);
        const text = label ?? state?.action.label ?? '';
        const key = bindingLabel(id);
        part.element.setAttribute('title', key ? `${text} (${key})` : text);
        if (key) part.element.setAttribute('aria-keyshortcuts', ariaCombo(state!.binding!));
        else part.element.removeAttribute('aria-keyshortcuts');
        return noChange;
    }
}

/**
 * Element directive: sets `title` and `aria-keyshortcuts` from the live shortcut binding.
 * Hosts watch `shortcutsRev` so hints refresh when the shell rebinds keys.
 */
export const keyHint = directive(KeyHint);