anki/ts/lib/bridgecommand.ts
Henrik Giesel 6e0f7c3d53 Implement register-package and export some packages
Exported packages are:
* anki/packages
* anki/shortcuts
* anki/bridgecommand
2021-08-30 14:41:40 +02:00

24 lines
712 B
TypeScript

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { registerPackage } from "./register-package";
declare global {
interface Window {
bridgeCommand<T>(command: string, callback?: (value: T) => void): void;
}
}
/// HTML <a> tag pointing to a bridge command.
export function bridgeLink(command: string, label: string): string {
return `<a href="javascript:bridgeCommand('${command}')">${label}</a>`;
}
export function bridgeCommand<T>(command: string, callback?: (value: T) => void): void {
window.bridgeCommand<T>(command, callback);
}
registerPackage("anki/bridgecommand", {
bridgeCommand,
});