@chief-editor/ui
Version:
UI Component for chief editor
1 lines • 1.57 kB
JavaScript
;var __importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(exports,"__esModule",{value:!0});var hotkey_1=require("@rc-hooks/hotkey"),use_1=require("@rc-hooks/use"),react_1=__importStar(require("react"));function SelectHotKey(e){var t=e.handlers,r=void 0===t?{}:t,o=e.focusableElementRef,l=use_1.useRefGetter(r),n=react_1.useCallback((function(){var e,t,r,n;return document.activeElement&&document.activeElement===o.current&&(null===(t=(e=o.current).scrollIntoView)||void 0===t||t.call(e,{behavior:"smooth",block:"nearest"}),null===(n=(r=l()).stepUp)||void 0===n||n.call(r)),!1}),[]),c=react_1.useCallback((function(){var e,t,r,n;return document.activeElement&&document.activeElement===o.current&&(null===(t=(e=o.current).scrollIntoView)||void 0===t||t.call(e,{behavior:"smooth",block:"nearest"}),null===(n=(r=l()).stepDown)||void 0===n||n.call(r)),!1}),[]),u=react_1.useCallback((function(){var e,t,r,n;document.activeElement&&document.activeElement===o.current&&(null===(t=(e=o.current).scrollIntoView)||void 0===t||t.call(e,{behavior:"smooth",block:"nearest"}),null===(n=(r=l()).selectBackFill)||void 0===n||n.call(r))}),[]);return hotkey_1.useHotKey("up",n,"keydown"),hotkey_1.useHotKey("up",n,"keypress"),hotkey_1.useHotKey("down",c,"keydown"),hotkey_1.useHotKey("down",c,"keypress"),hotkey_1.useHotKey("enter",u,"keydown"),react_1.default.createElement(react_1.Fragment,null)}exports.SelectHotKey=SelectHotKey;