@superinterface/react 5.3.0-beta.16 → 5.3.0-beta.18

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
@@ -47419,6 +47419,18 @@ var useMessageAudio = function(_ref) {
47419
47419
  var superinterfaceContext = useSuperinterfaceContext();
47420
47420
  var _useState91 = _sliced_to_array(useState9(false), 2), isPlaying = _useState91[0], setIsPlaying = _useState91[1];
47421
47421
  var _useState92 = _sliced_to_array(useState9([]), 2), audioQueue = _useState92[0], setAudioQueue = _useState92[1];
47422
+ var commitAudioQueue = useCallback7(function(next) {
47423
+ if (typeof next === "function") {
47424
+ setAudioQueue(function(prev) {
47425
+ var computed = next(prev);
47426
+ audioQueueRef.current = computed;
47427
+ return computed;
47428
+ });
47429
+ } else {
47430
+ audioQueueRef.current = next;
47431
+ setAudioQueue(next);
47432
+ }
47433
+ }, []);
47422
47434
  var audioQueueRef = useRef8([]);
47423
47435
  useEffect10(function() {
47424
47436
  audioQueueRef.current = audioQueue;
@@ -47443,7 +47455,7 @@ var useMessageAudio = function(_ref) {
47443
47455
  var checkForCompletion = useCallback7(function() {
47444
47456
  if (activeSegmentsRef.current > 0) return;
47445
47457
  var hasPending = audioQueueRef.current.some(function(m) {
47446
- return !m.stopped && (m.nextIndex < m.segments.length || m.status === "in_progress");
47458
+ return !m.stopped && m.nextIndex < m.segments.length;
47447
47459
  });
47448
47460
  if (hasPending) {
47449
47461
  onEndPendingRef.current = true;
@@ -47595,16 +47607,16 @@ var useMessageAudio = function(_ref) {
47595
47607
  ];
47596
47608
  case 6:
47597
47609
  unfinished = nextQueue.filter(function(m_7) {
47598
- return !m_7.stopped && (m_7.status === "in_progress" || m_7.nextIndex < m_7.segments.length);
47610
+ return !m_7.stopped && m_7.nextIndex < m_7.segments.length;
47599
47611
  });
47600
47612
  finished = nextQueue.filter(function(m_8) {
47601
- return !(!m_8.stopped && (m_8.status === "in_progress" || m_8.nextIndex < m_8.segments.length));
47613
+ return !(!m_8.stopped && m_8.nextIndex < m_8.segments.length);
47602
47614
  });
47603
47615
  prunedFinished = finished.length > KEEP_FINISHED_MESSAGES ? finished.slice(finished.length - KEEP_FINISHED_MESSAGES) : finished;
47604
47616
  combined = _to_consumable_array(unfinished).concat(_to_consumable_array(prunedFinished));
47605
47617
  if (combined.some(function(m_9) {
47606
- return !m_9.stopped && (m_9.nextIndex < m_9.segments.length || m_9.status === "in_progress");
47607
- })) {
47618
+ return !m_9.stopped && m_9.nextIndex < m_9.segments.length;
47619
+ }) || activeSegmentsRef.current > 0) {
47608
47620
  onEndPendingRef.current = true;
47609
47621
  }
47610
47622
  if (!changed) {
@@ -47662,7 +47674,7 @@ var useMessageAudio = function(_ref) {
47662
47674
  }
47663
47675
  }
47664
47676
  }
47665
- if (changed) setAudioQueue(combined);
47677
+ if (changed) commitAudioQueue(combined);
47666
47678
  if (segCache.size > MAX_SEG_CACHE) {
47667
47679
  entries = Array.from(segCache.entries());
47668
47680
  entries.sort(function(a, b) {
@@ -47941,8 +47953,8 @@ var useMessageAudio = function(_ref) {
47941
47953
  defaultPlaySegments
47942
47954
  ]);
47943
47955
  var handleStop = useCallback7(function(messageId) {
47944
- setAudioQueue(function(prev) {
47945
- return prev.map(function(m_13) {
47956
+ commitAudioQueue(function(prev_0) {
47957
+ return prev_0.map(function(m_13) {
47946
47958
  return m_13.id === messageId ? _objectSpread47(_objectSpread47({}, m_13), {}, {
47947
47959
  stopped: true
47948
47960
  }) : m_13;
@@ -47961,7 +47973,6 @@ var useMessageAudio = function(_ref) {
47961
47973
  if (activeSegmentsRef.current === 0) {
47962
47974
  setIsPlaying(false);
47963
47975
  currentSegmentRef.current = null;
47964
- pickLockRef.current = false;
47965
47976
  checkForCompletion();
47966
47977
  }
47967
47978
  }, [
@@ -47991,75 +48002,107 @@ var useMessageAudio = function(_ref) {
47991
48002
  if (!candidate || candidate.segments.length === 0) return;
47992
48003
  pickLockRef.current = true;
47993
48004
  if (!allowParallel) setIsPlaying(true);
47994
- setAudioQueue(function(prev_0) {
47995
- return prev_0.map(function(m_14) {
47996
- return m_14.id === candidate.messageId ? _objectSpread47(_objectSpread47({}, m_14), {}, {
47997
- nextIndex: candidate.startIndex + candidate.segments.length
48005
+ var selected = candidate;
48006
+ commitAudioQueue(function(prev_1) {
48007
+ return prev_1.map(function(m_14) {
48008
+ return m_14.id === selected.messageId ? _objectSpread47(_objectSpread47({}, m_14), {}, {
48009
+ nextIndex: selected.startIndex
47998
48010
  }) : m_14;
47999
48011
  });
48000
48012
  });
48001
- var runPlayback = function() {
48002
- var nextIndex_0 = candidate.startIndex;
48003
- var launch = function() {
48004
- return playSegmentsImpl({
48005
- segments: candidate.segments,
48006
- startIndex: candidate.startIndex,
48007
- message: candidate.message,
48008
- play: function() {
48009
- var _play = _asyncToGenerator11(function(segment_0) {
48010
- return _ts_generator(this, function(_state) {
48011
- switch(_state.label){
48012
- case 0:
48013
- activeSegmentsRef.current += 1;
48014
- nextIndex_0 += 1;
48015
- currentSegmentRef.current = {
48016
- messageId: candidate.messageId,
48017
- nextIndex: nextIndex_0
48018
- };
48019
- return [
48020
- 4,
48021
- playInternal(segment_0, {
48022
- onPlay: function() {},
48023
- onStop: function() {
48024
- return handleStop(candidate.messageId);
48025
- },
48026
- onEnd: function() {
48027
- return handleSegmentEnd();
48013
+ var runPlayback = /* @__PURE__ */ function() {
48014
+ var _ref0 = _asyncToGenerator11(function() {
48015
+ var launchedCount;
48016
+ return _ts_generator(this, function(_state) {
48017
+ switch(_state.label){
48018
+ case 0:
48019
+ launchedCount = 0;
48020
+ return [
48021
+ 4,
48022
+ playSegmentsImpl({
48023
+ segments: selected.segments,
48024
+ startIndex: selected.startIndex,
48025
+ message: selected.message,
48026
+ play: function() {
48027
+ var _play = _asyncToGenerator11(function(segment_0) {
48028
+ var advanceTo;
48029
+ return _ts_generator(this, function(_state) {
48030
+ switch(_state.label){
48031
+ case 0:
48032
+ activeSegmentsRef.current += 1;
48033
+ launchedCount += 1;
48034
+ advanceTo = selected.startIndex + launchedCount;
48035
+ onEndPendingRef.current = true;
48036
+ commitAudioQueue(function(prev_2) {
48037
+ return prev_2.map(function(m_15) {
48038
+ return m_15.id === selected.messageId ? _objectSpread47(_objectSpread47({}, m_15), {}, {
48039
+ nextIndex: m_15.nextIndex >= advanceTo ? m_15.nextIndex : advanceTo
48040
+ }) : m_15;
48041
+ });
48042
+ });
48043
+ currentSegmentRef.current = {
48044
+ messageId: selected.messageId,
48045
+ nextIndex: advanceTo
48046
+ };
48047
+ return [
48048
+ 4,
48049
+ playInternal(segment_0, {
48050
+ onPlay: function() {},
48051
+ onStop: function() {
48052
+ return handleStop(selected.messageId);
48053
+ },
48054
+ onEnd: function() {
48055
+ commitAudioQueue(function(prev_3) {
48056
+ return prev_3.map(function(m_16) {
48057
+ return m_16.id === selected.messageId ? _objectSpread47(_objectSpread47({}, m_16), {}, {
48058
+ nextIndex: m_16.nextIndex >= advanceTo ? m_16.nextIndex : advanceTo
48059
+ }) : m_16;
48060
+ });
48061
+ });
48062
+ handleSegmentEnd();
48063
+ }
48064
+ })
48065
+ ];
48066
+ case 1:
48067
+ _state.sent();
48068
+ return [
48069
+ 2
48070
+ ];
48028
48071
  }
48029
- })
48030
- ];
48031
- case 1:
48032
- _state.sent();
48033
- return [
48034
- 2
48035
- ];
48036
- }
48037
- });
48038
- });
48039
- function play(_x6) {
48040
- return _play.apply(this, arguments);
48041
- }
48042
- return play;
48043
- }()
48072
+ });
48073
+ });
48074
+ function play(_x6) {
48075
+ return _play.apply(this, arguments);
48076
+ }
48077
+ return play;
48078
+ }()
48079
+ })
48080
+ ];
48081
+ case 1:
48082
+ _state.sent();
48083
+ return [
48084
+ 2
48085
+ ];
48086
+ }
48044
48087
  });
48088
+ });
48089
+ return function runPlayback2() {
48090
+ return _ref0.apply(this, arguments);
48045
48091
  };
48046
- try {
48047
- Promise.resolve(launch()).catch(function(error_0) {
48048
- handleStop(candidate.messageId);
48049
- console.error(error_0);
48050
- }).finally(function() {
48051
- checkForCompletion();
48052
- });
48053
- } catch (error) {
48054
- handleStop(candidate.messageId);
48055
- console.error(error);
48056
- checkForCompletion();
48057
- }
48058
- };
48059
- runPlayback();
48060
- if (allowParallel) {
48092
+ }();
48093
+ Promise.resolve(runPlayback()).catch(function(error) {
48094
+ handleStop(selected.messageId);
48095
+ console.error(error);
48096
+ }).finally(function() {
48097
+ var finalNextIndex = selected.startIndex + selected.segments.length;
48098
+ commitAudioQueue(audioQueueRef.current.map(function(m_17) {
48099
+ return m_17.id === selected.messageId ? _objectSpread47(_objectSpread47({}, m_17), {}, {
48100
+ nextIndex: m_17.nextIndex >= finalNextIndex ? m_17.nextIndex : finalNextIndex
48101
+ }) : m_17;
48102
+ }));
48061
48103
  pickLockRef.current = false;
48062
- }
48104
+ checkForCompletion();
48105
+ });
48063
48106
  }, [
48064
48107
  audioQueue,
48065
48108
  isPlaying,
@@ -48117,8 +48160,8 @@ var useMessageAudio = function(_ref) {
48117
48160
  audioEngine
48118
48161
  ]);
48119
48162
  var isPending = useMemo17(function() {
48120
- return isPlaying || audioQueue.some(function(m_15) {
48121
- return !m_15.stopped && (m_15.nextIndex < m_15.segments.length || m_15.status === "in_progress");
48163
+ return isPlaying || audioQueue.some(function(m_18) {
48164
+ return !m_18.stopped && (m_18.nextIndex < m_18.segments.length || m_18.status === "in_progress");
48122
48165
  });
48123
48166
  }, [
48124
48167
  isPlaying,