export function escKey(node, callback) {
    return handleKeyDown(node, callback, 'Escape');
}
export function enterKey(node, callback) {
    return handleKeyDown(node, callback, 'Enter');
}
export function ctrlEnterKey(node, callback) {
    return handleEvent(node, 'keydown', event => (event.ctrlKey || event.metaKey) && event.key === 'Enter', callback);
}
export function delKey(node, callback) {
    return handleKeyDown(node, callback, 'Delete');
}
export function tabKey(node, callback) {
    return handleKeyDown(node, callback, 'Tab');
}
export function backspaceKey(node, callback) {
    return handleKeyDown(node, callback, 'Backspace');
}
export function clickThis(node, callback) {
    return handleEvent(node, 'click', event => event.target === event.currentTarget, callback);
}
function handleKeyDown(node, callback, key) {
    return handleEvent(node, 'keydown', event => event.key === key, callback);
}
function handleEvent(node, event, check, callback) {
    function onEvent(event) {
        if (check(event))
            callback(event);
    }
    node.addEventListener(event, onEvent);
    return {
        destroy() {
            node.removeEventListener(event, onEvent);
        },
    };
}
