@rpg-engine/long-bow 0.5.90 → 0.5.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/long-bow.cjs.development.js +22 -14
- package/dist/long-bow.cjs.development.js.map +1 -1
- package/dist/long-bow.cjs.production.min.js +1 -1
- package/dist/long-bow.cjs.production.min.js.map +1 -1
- package/dist/long-bow.esm.js +22 -14
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Shortcuts/Shortcuts.tsx +16 -6
|
@@ -18169,25 +18169,33 @@ var Shortcuts = function Shortcuts(_ref) {
|
|
|
18169
18169
|
var _useShortcutCooldown = useShortcutCooldown(onShortcutCast),
|
|
18170
18170
|
handleShortcutCast = _useShortcutCooldown.handleShortcutCast,
|
|
18171
18171
|
shortcutCooldown = _useShortcutCooldown.shortcutCooldown;
|
|
18172
|
+
var handleKeyDown = React.useCallback(function (e) {
|
|
18173
|
+
if (isBlockedCastingByKeyboard) return;
|
|
18174
|
+
var shortcutIndex = Number(e.key) - 1;
|
|
18175
|
+
if (shortcutIndex >= 0 && shortcutIndex <= 11) {
|
|
18176
|
+
var _shortcutsRefs$curren;
|
|
18177
|
+
handleShortcutCast(shortcutIndex);
|
|
18178
|
+
(_shortcutsRefs$curren = shortcutsRefs.current[shortcutIndex]) == null ? void 0 : _shortcutsRefs$curren.classList.add('active');
|
|
18179
|
+
var timeoutId = setTimeout(function () {
|
|
18180
|
+
var _shortcutsRefs$curren2;
|
|
18181
|
+
(_shortcutsRefs$curren2 = shortcutsRefs.current[shortcutIndex]) == null ? void 0 : _shortcutsRefs$curren2.classList.remove('active');
|
|
18182
|
+
}, 150);
|
|
18183
|
+
// Store timeoutId for later cleanup
|
|
18184
|
+
timeoutIds.current.push(timeoutId);
|
|
18185
|
+
}
|
|
18186
|
+
}, [isBlockedCastingByKeyboard, handleShortcutCast]);
|
|
18187
|
+
// Initialize a ref to store the timeout ids
|
|
18188
|
+
var timeoutIds = React.useRef([]);
|
|
18172
18189
|
React.useEffect(function () {
|
|
18173
|
-
var handleKeyDown = function handleKeyDown(e) {
|
|
18174
|
-
if (isBlockedCastingByKeyboard) return;
|
|
18175
|
-
var shortcutIndex = Number(e.key) - 1;
|
|
18176
|
-
if (shortcutIndex >= 0 && shortcutIndex <= 11) {
|
|
18177
|
-
var _shortcutsRefs$curren;
|
|
18178
|
-
handleShortcutCast(shortcutIndex);
|
|
18179
|
-
(_shortcutsRefs$curren = shortcutsRefs.current[shortcutIndex]) == null ? void 0 : _shortcutsRefs$curren.classList.add('active');
|
|
18180
|
-
setTimeout(function () {
|
|
18181
|
-
var _shortcutsRefs$curren2;
|
|
18182
|
-
(_shortcutsRefs$curren2 = shortcutsRefs.current[shortcutIndex]) == null ? void 0 : _shortcutsRefs$curren2.classList.remove('active');
|
|
18183
|
-
}, 150);
|
|
18184
|
-
}
|
|
18185
|
-
};
|
|
18186
18190
|
window.addEventListener('keydown', handleKeyDown);
|
|
18187
18191
|
return function () {
|
|
18188
18192
|
window.removeEventListener('keydown', handleKeyDown);
|
|
18193
|
+
// Clear all timeouts when the component unmounts
|
|
18194
|
+
timeoutIds.current.forEach(function (id) {
|
|
18195
|
+
return clearTimeout(id);
|
|
18196
|
+
});
|
|
18189
18197
|
};
|
|
18190
|
-
}, [
|
|
18198
|
+
}, [handleKeyDown]);
|
|
18191
18199
|
return React__default.createElement(List$1, null, Array.from({
|
|
18192
18200
|
length: 12
|
|
18193
18201
|
}).map(function (_, i) {
|