mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
31 lines
823 B
JavaScript
31 lines
823 B
JavaScript
"use client";
|
|
import { useContainer } from "../../player/context.js";
|
|
import { useLatestRef } from "../../utils/use-latest-ref.js";
|
|
import { createHotkey } from "@videojs/core/dom";
|
|
import { useEffect } from "react";
|
|
//#region src/ui/hotkey/use-hotkey.ts
|
|
function useHotkey(options) {
|
|
const { keys, target = "player", repeatable = true, disabled = false } = options;
|
|
const container = useContainer();
|
|
const onActivateRef = useLatestRef(options.onActivate);
|
|
useEffect(() => {
|
|
if (!container || !keys || disabled) return;
|
|
return createHotkey(container, {
|
|
keys,
|
|
target,
|
|
repeatable,
|
|
disabled,
|
|
onActivate: (event, key) => onActivateRef.current(event, key)
|
|
});
|
|
}, [
|
|
container,
|
|
keys,
|
|
target,
|
|
repeatable,
|
|
disabled
|
|
]);
|
|
}
|
|
//#endregion
|
|
export { useHotkey };
|
|
|
|
//# sourceMappingURL=use-hotkey.js.map
|