@rpg-engine/long-bow 0.5.89 → 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.
@@ -18166,25 +18166,33 @@ var Shortcuts = function Shortcuts(_ref) {
18166
18166
  var _useShortcutCooldown = useShortcutCooldown(onShortcutCast),
18167
18167
  handleShortcutCast = _useShortcutCooldown.handleShortcutCast,
18168
18168
  shortcutCooldown = _useShortcutCooldown.shortcutCooldown;
18169
+ var handleKeyDown = useCallback(function (e) {
18170
+ if (isBlockedCastingByKeyboard) return;
18171
+ var shortcutIndex = Number(e.key) - 1;
18172
+ if (shortcutIndex >= 0 && shortcutIndex <= 11) {
18173
+ var _shortcutsRefs$curren;
18174
+ handleShortcutCast(shortcutIndex);
18175
+ (_shortcutsRefs$curren = shortcutsRefs.current[shortcutIndex]) == null ? void 0 : _shortcutsRefs$curren.classList.add('active');
18176
+ var timeoutId = setTimeout(function () {
18177
+ var _shortcutsRefs$curren2;
18178
+ (_shortcutsRefs$curren2 = shortcutsRefs.current[shortcutIndex]) == null ? void 0 : _shortcutsRefs$curren2.classList.remove('active');
18179
+ }, 150);
18180
+ // Store timeoutId for later cleanup
18181
+ timeoutIds.current.push(timeoutId);
18182
+ }
18183
+ }, [isBlockedCastingByKeyboard, handleShortcutCast]);
18184
+ // Initialize a ref to store the timeout ids
18185
+ var timeoutIds = useRef([]);
18169
18186
  useEffect(function () {
18170
- var handleKeyDown = function handleKeyDown(e) {
18171
- if (isBlockedCastingByKeyboard) return;
18172
- var shortcutIndex = Number(e.key) - 1;
18173
- if (shortcutIndex >= 0 && shortcutIndex <= 11) {
18174
- var _shortcutsRefs$curren;
18175
- handleShortcutCast(shortcutIndex);
18176
- (_shortcutsRefs$curren = shortcutsRefs.current[shortcutIndex]) == null ? void 0 : _shortcutsRefs$curren.classList.add('active');
18177
- setTimeout(function () {
18178
- var _shortcutsRefs$curren2;
18179
- (_shortcutsRefs$curren2 = shortcutsRefs.current[shortcutIndex]) == null ? void 0 : _shortcutsRefs$curren2.classList.remove('active');
18180
- }, 150);
18181
- }
18182
- };
18183
18187
  window.addEventListener('keydown', handleKeyDown);
18184
18188
  return function () {
18185
18189
  window.removeEventListener('keydown', handleKeyDown);
18190
+ // Clear all timeouts when the component unmounts
18191
+ timeoutIds.current.forEach(function (id) {
18192
+ return clearTimeout(id);
18193
+ });
18186
18194
  };
18187
- }, [shortcuts, isBlockedCastingByKeyboard, shortcutCooldown]);
18195
+ }, [handleKeyDown]);
18188
18196
  return React.createElement(List$1, null, Array.from({
18189
18197
  length: 12
18190
18198
  }).map(function (_, i) {