main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | var tslib_1 = require("tslib");
|
---|
| 4 | var react_1 = require("react");
|
---|
| 5 | var useMount_1 = tslib_1.__importDefault(require("./useMount"));
|
---|
| 6 | var useKeyboardJs = function (combination) {
|
---|
| 7 | var _a = react_1.useState([false, null]), state = _a[0], set = _a[1];
|
---|
| 8 | var _b = react_1.useState(null), keyboardJs = _b[0], setKeyboardJs = _b[1];
|
---|
| 9 | useMount_1.default(function () {
|
---|
| 10 | Promise.resolve().then(function () { return tslib_1.__importStar(require('keyboardjs')); }).then(function (k) { return setKeyboardJs(k.default || k); });
|
---|
| 11 | });
|
---|
| 12 | react_1.useEffect(function () {
|
---|
| 13 | if (!keyboardJs) {
|
---|
| 14 | return;
|
---|
| 15 | }
|
---|
| 16 | var down = function (event) { return set([true, event]); };
|
---|
| 17 | var up = function (event) { return set([false, event]); };
|
---|
| 18 | keyboardJs.bind(combination, down, up, true);
|
---|
| 19 | return function () {
|
---|
| 20 | keyboardJs.unbind(combination, down, up);
|
---|
| 21 | };
|
---|
| 22 | }, [combination, keyboardJs]);
|
---|
| 23 | return state;
|
---|
| 24 | };
|
---|
| 25 | exports.default = useKeyboardJs;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.