@rpg-engine/long-bow 0.8.87 → 0.8.89

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.
@@ -27184,19 +27184,36 @@ var useShortcutCooldown = function useShortcutCooldown(onShortcutCast) {
27184
27184
  var _useState = useState(0),
27185
27185
  shortcutCooldown = _useState[0],
27186
27186
  setShortcutCooldown = _useState[1];
27187
- var cooldownTimeout = useRef(null);
27188
- var handleShortcutCast = function handleShortcutCast(index) {
27189
- if (shortcutCooldown <= 0) setShortcutCooldown(1.5);
27187
+ var intervalRef = useRef(null);
27188
+ var clearCooldownInterval = useCallback(function () {
27189
+ if (intervalRef.current) {
27190
+ clearInterval(intervalRef.current);
27191
+ intervalRef.current = null;
27192
+ }
27193
+ }, []);
27194
+ var handleShortcutCast = useCallback(function (index) {
27195
+ if (shortcutCooldown <= 0) {
27196
+ setShortcutCooldown(1.5);
27197
+ }
27190
27198
  onShortcutCast(index);
27191
- };
27199
+ }, [shortcutCooldown, onShortcutCast]);
27192
27200
  useEffect(function () {
27193
- if (cooldownTimeout.current) clearTimeout(cooldownTimeout.current);
27194
- if (shortcutCooldown > 0) {
27195
- cooldownTimeout.current = setTimeout(function () {
27196
- setShortcutCooldown(shortcutCooldown - 0.1);
27201
+ if (shortcutCooldown > 0 && !intervalRef.current) {
27202
+ intervalRef.current = setInterval(function () {
27203
+ setShortcutCooldown(function (prev) {
27204
+ var next = prev - 0.1;
27205
+ if (next <= 0) {
27206
+ clearCooldownInterval();
27207
+ return 0;
27208
+ }
27209
+ return next;
27210
+ });
27197
27211
  }, 100);
27198
27212
  }
27199
- }, [shortcutCooldown]);
27213
+ return function () {
27214
+ clearCooldownInterval();
27215
+ };
27216
+ }, [shortcutCooldown > 0, clearCooldownInterval]);
27200
27217
  return {
27201
27218
  shortcutCooldown: shortcutCooldown,
27202
27219
  handleShortcutCast: handleShortcutCast
@@ -27451,19 +27468,18 @@ var DraggableContainer = function DraggableContainer(_ref) {
27451
27468
  height = '100%';
27452
27469
  }
27453
27470
  useOutsideClick(draggableRef, 'item-container');
27471
+ var handleClickOutside = useCallback(function (event) {
27472
+ var e = event;
27473
+ if (e.detail.id === 'item-container') {
27474
+ onOutsideClick == null ? void 0 : onOutsideClick();
27475
+ }
27476
+ }, [onOutsideClick]);
27454
27477
  useEffect(function () {
27455
- document.addEventListener('clickOutside', function (event) {
27456
- var e = event;
27457
- if (e.detail.id === 'item-container') {
27458
- if (onOutsideClick) {
27459
- onOutsideClick();
27460
- }
27461
- }
27462
- });
27478
+ document.addEventListener('clickOutside', handleClickOutside);
27463
27479
  return function () {
27464
- document.removeEventListener('clickOutside', function (_e) {});
27480
+ document.removeEventListener('clickOutside', handleClickOutside);
27465
27481
  };
27466
- }, []);
27482
+ }, [handleClickOutside]);
27467
27483
  return React.createElement(Draggable, {
27468
27484
  cancel: ".container-close,input,button," + cancelDrag,
27469
27485
  disabled: dragDisabled,
@@ -30565,19 +30581,18 @@ var RelativeListMenu = function RelativeListMenu(_ref) {
30565
30581
  pos = _ref.pos;
30566
30582
  var ref = useRef(null);
30567
30583
  useOutsideClick(ref, 'relative-context-menu');
30584
+ var handleClickOutside = useCallback(function (event) {
30585
+ var e = event;
30586
+ if (e.detail.id === 'relative-context-menu') {
30587
+ onOutsideClick == null ? void 0 : onOutsideClick();
30588
+ }
30589
+ }, [onOutsideClick]);
30568
30590
  useEffect(function () {
30569
- document.addEventListener('clickOutside', function (event) {
30570
- var e = event;
30571
- if (e.detail.id === 'relative-context-menu') {
30572
- if (onOutsideClick) {
30573
- onOutsideClick();
30574
- }
30575
- }
30576
- });
30591
+ document.addEventListener('clickOutside', handleClickOutside);
30577
30592
  return function () {
30578
- document.removeEventListener('clickOutside', function (_e) {});
30593
+ document.removeEventListener('clickOutside', handleClickOutside);
30579
30594
  };
30580
- }, []);
30595
+ }, [handleClickOutside]);
30581
30596
  return React.createElement(ModalPortal, null, React.createElement(Container$k, Object.assign({
30582
30597
  fontSize: fontSize,
30583
30598
  ref: ref
@@ -36032,8 +36047,6 @@ var ProgressBar$1 = function ProgressBar(_ref) {
36032
36047
  minWidth = _ref$minWidth === void 0 ? 100 : _ref$minWidth,
36033
36048
  style = _ref.style,
36034
36049
  mobileScale = _ref.mobileScale;
36035
- value = Math.round(value);
36036
- max = Math.round(max);
36037
36050
  var calculatePercentageValue = function calculatePercentageValue(max, value) {
36038
36051
  if (value > max) {
36039
36052
  value = max;
@@ -36041,6 +36054,9 @@ var ProgressBar$1 = function ProgressBar(_ref) {
36041
36054
  var percentage = value * 100 / max;
36042
36055
  return Math.min(99.99, percentage);
36043
36056
  };
36057
+ // Round only for display, not for calculation
36058
+ var displayValue = Math.round(value);
36059
+ var displayMax = Math.round(max);
36044
36060
  return React.createElement(Container$B, {
36045
36061
  className: "rpgui-progress",
36046
36062
  "data-value": calculatePercentageValue(max, value) / 100,
@@ -36049,7 +36065,7 @@ var ProgressBar$1 = function ProgressBar(_ref) {
36049
36065
  minWidth: minWidth,
36050
36066
  style: style,
36051
36067
  mobileScale: mobileScale
36052
- }, displayText && React.createElement(TextOverlay$1, null, React.createElement(ProgressBarText, null, value, "/", max)), React.createElement("div", {
36068
+ }, displayText && React.createElement(TextOverlay$1, null, React.createElement(ProgressBarText, null, displayValue, "/", displayMax)), React.createElement("div", {
36053
36069
  className: " rpgui-progress-track"
36054
36070
  }, React.createElement("div", {
36055
36071
  className: "rpgui-progress-fill " + color + " ",
@@ -36347,6 +36363,8 @@ var Shortcuts = function Shortcuts(_ref) {
36347
36363
  var _useShortcutCooldown = useShortcutCooldown(onShortcutCast),
36348
36364
  handleShortcutCast = _useShortcutCooldown.handleShortcutCast,
36349
36365
  shortcutCooldown = _useShortcutCooldown.shortcutCooldown;
36366
+ // Use a Set to track active timeouts - automatically cleaned when they complete
36367
+ var activeTimeouts = useRef(new Set());
36350
36368
  var handleKeyDown = useCallback(function (e) {
36351
36369
  if (isBlockedCastingByKeyboard) return;
36352
36370
  var shortcutIndex = Number(e.key) - 1;
@@ -36357,21 +36375,20 @@ var Shortcuts = function Shortcuts(_ref) {
36357
36375
  var timeoutId = setTimeout(function () {
36358
36376
  var _shortcutsRefs$curren2;
36359
36377
  (_shortcutsRefs$curren2 = shortcutsRefs.current[shortcutIndex]) == null ? void 0 : _shortcutsRefs$curren2.classList.remove('active');
36378
+ activeTimeouts.current["delete"](timeoutId);
36360
36379
  }, 150);
36361
- // Store timeoutId for later cleanup
36362
- timeoutIds.current.push(timeoutId);
36380
+ activeTimeouts.current.add(timeoutId);
36363
36381
  }
36364
36382
  }, [isBlockedCastingByKeyboard, handleShortcutCast]);
36365
- // Initialize a ref to store the timeout ids
36366
- var timeoutIds = useRef([]);
36367
36383
  useEffect(function () {
36368
36384
  window.addEventListener('keydown', handleKeyDown);
36369
36385
  return function () {
36370
36386
  window.removeEventListener('keydown', handleKeyDown);
36371
- // Clear all timeouts when the component unmounts
36372
- timeoutIds.current.forEach(function (id) {
36387
+ // Clear all active timeouts when the component unmounts
36388
+ activeTimeouts.current.forEach(function (id) {
36373
36389
  return clearTimeout(id);
36374
36390
  });
36391
+ activeTimeouts.current.clear();
36375
36392
  };
36376
36393
  }, [handleKeyDown]);
36377
36394
  return React.createElement(List$1, null, Array.from({