@waveform-playlist/browser 17.0.0-next.5 → 17.0.0-next.6

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/index.js CHANGED
@@ -1058,18 +1058,17 @@ var import_react13 = require("react");
1058
1058
  var import_core3 = require("@waveform-playlist/core");
1059
1059
  var useKeyboardShortcuts = (options) => {
1060
1060
  const { shortcuts, enabled = true } = options;
1061
- const shortcutsRef = (0, import_react13.useRef)(shortcuts);
1062
- (0, import_react13.useEffect)(() => {
1063
- shortcutsRef.current = shortcuts;
1061
+ const latest = (0, import_react13.useRef)({ shortcuts, enabled });
1062
+ (0, import_react13.useLayoutEffect)(() => {
1063
+ latest.current = { shortcuts, enabled };
1064
1064
  });
1065
- (0, import_react13.useEffect)(() => {
1066
- if (!enabled) return;
1067
- const handleKeyDown = (event) => (0, import_core3.handleKeyboardEvent)(event, shortcutsRef.current, true);
1065
+ (0, import_react13.useLayoutEffect)(() => {
1066
+ const handleKeyDown = (event) => (0, import_core3.handleKeyboardEvent)(event, latest.current.shortcuts, latest.current.enabled);
1068
1067
  window.addEventListener("keydown", handleKeyDown);
1069
1068
  return () => {
1070
1069
  window.removeEventListener("keydown", handleKeyDown);
1071
1070
  };
1072
- }, [enabled]);
1071
+ }, []);
1073
1072
  };
1074
1073
 
1075
1074
  // src/hooks/usePlaybackShortcuts.ts
@@ -1084,7 +1083,7 @@ function usePlayFromSelectionOrCursor() {
1084
1083
  const isLoopEnabled = (_b = (_a = useLoopOptional()) == null ? void 0 : _a.isLoopEnabled) != null ? _b : false;
1085
1084
  const { play } = usePlaybackControls();
1086
1085
  const latest = (0, import_react14.useRef)({ selectionStart, selectionEnd, isLoopEnabled });
1087
- (0, import_react14.useEffect)(() => {
1086
+ (0, import_react14.useLayoutEffect)(() => {
1088
1087
  latest.current = { selectionStart, selectionEnd, isLoopEnabled };
1089
1088
  });
1090
1089
  return (0, import_react14.useCallback)(() => __async(null, null, function* () {