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

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.cjs CHANGED
@@ -47568,6 +47568,18 @@ var useMessageAudio = function(_ref) {
47568
47568
  var superinterfaceContext = useSuperinterfaceContext();
47569
47569
  var _$_ref1 = _sliced_to_array((0, import_react67.useState)(false), 2), isPlaying = _$_ref1[0], setIsPlaying = _$_ref1[1];
47570
47570
  var _$_ref2 = _sliced_to_array((0, import_react67.useState)([]), 2), audioQueue = _$_ref2[0], setAudioQueue = _$_ref2[1];
47571
+ var commitAudioQueue = (0, import_react67.useCallback)(function(next) {
47572
+ if (typeof next === "function") {
47573
+ setAudioQueue(function(prev) {
47574
+ var computed = next(prev);
47575
+ audioQueueRef.current = computed;
47576
+ return computed;
47577
+ });
47578
+ } else {
47579
+ audioQueueRef.current = next;
47580
+ setAudioQueue(next);
47581
+ }
47582
+ }, []);
47571
47583
  var audioQueueRef = (0, import_react67.useRef)([]);
47572
47584
  (0, import_react67.useEffect)(function() {
47573
47585
  audioQueueRef.current = audioQueue;
@@ -47592,7 +47604,7 @@ var useMessageAudio = function(_ref) {
47592
47604
  var checkForCompletion = (0, import_react67.useCallback)(function() {
47593
47605
  if (activeSegmentsRef.current > 0) return;
47594
47606
  var hasPending = audioQueueRef.current.some(function(m) {
47595
- return !m.stopped && (m.nextIndex < m.segments.length || m.status === "in_progress");
47607
+ return !m.stopped && m.nextIndex < m.segments.length;
47596
47608
  });
47597
47609
  if (hasPending) {
47598
47610
  onEndPendingRef.current = true;
@@ -47744,16 +47756,16 @@ var useMessageAudio = function(_ref) {
47744
47756
  ];
47745
47757
  case 6:
47746
47758
  unfinished = nextQueue.filter(function(m_7) {
47747
- return !m_7.stopped && (m_7.status === "in_progress" || m_7.nextIndex < m_7.segments.length);
47759
+ return !m_7.stopped && m_7.nextIndex < m_7.segments.length;
47748
47760
  });
47749
47761
  finished = nextQueue.filter(function(m_8) {
47750
- return !(!m_8.stopped && (m_8.status === "in_progress" || m_8.nextIndex < m_8.segments.length));
47762
+ return !(!m_8.stopped && m_8.nextIndex < m_8.segments.length);
47751
47763
  });
47752
47764
  prunedFinished = finished.length > KEEP_FINISHED_MESSAGES ? finished.slice(finished.length - KEEP_FINISHED_MESSAGES) : finished;
47753
47765
  combined = _to_consumable_array(unfinished).concat(_to_consumable_array(prunedFinished));
47754
47766
  if (combined.some(function(m_9) {
47755
- return !m_9.stopped && (m_9.nextIndex < m_9.segments.length || m_9.status === "in_progress");
47756
- })) {
47767
+ return !m_9.stopped && m_9.nextIndex < m_9.segments.length;
47768
+ }) || activeSegmentsRef.current > 0) {
47757
47769
  onEndPendingRef.current = true;
47758
47770
  }
47759
47771
  if (!changed) {
@@ -47811,7 +47823,7 @@ var useMessageAudio = function(_ref) {
47811
47823
  }
47812
47824
  }
47813
47825
  }
47814
- if (changed) setAudioQueue(combined);
47826
+ if (changed) commitAudioQueue(combined);
47815
47827
  if (segCache.size > MAX_SEG_CACHE) {
47816
47828
  entries = Array.from(segCache.entries());
47817
47829
  entries.sort(function(a, b) {
@@ -48090,8 +48102,8 @@ var useMessageAudio = function(_ref) {
48090
48102
  defaultPlaySegments
48091
48103
  ]);
48092
48104
  var handleStop = (0, import_react67.useCallback)(function(messageId) {
48093
- setAudioQueue(function(prev) {
48094
- return prev.map(function(m_13) {
48105
+ commitAudioQueue(function(prev_0) {
48106
+ return prev_0.map(function(m_13) {
48095
48107
  return m_13.id === messageId ? _objectSpread47(_objectSpread47({}, m_13), {}, {
48096
48108
  stopped: true
48097
48109
  }) : m_13;
@@ -48110,7 +48122,6 @@ var useMessageAudio = function(_ref) {
48110
48122
  if (activeSegmentsRef.current === 0) {
48111
48123
  setIsPlaying(false);
48112
48124
  currentSegmentRef.current = null;
48113
- pickLockRef.current = false;
48114
48125
  checkForCompletion();
48115
48126
  }
48116
48127
  }, [
@@ -48140,72 +48151,107 @@ var useMessageAudio = function(_ref) {
48140
48151
  if (!candidate || candidate.segments.length === 0) return;
48141
48152
  pickLockRef.current = true;
48142
48153
  if (!allowParallel) setIsPlaying(true);
48143
- setAudioQueue(function(prev_0) {
48144
- return prev_0.map(function(m_14) {
48145
- return m_14.id === candidate.messageId ? _objectSpread47(_objectSpread47({}, m_14), {}, {
48146
- nextIndex: candidate.startIndex + candidate.segments.length
48154
+ var selected = candidate;
48155
+ commitAudioQueue(function(prev_1) {
48156
+ return prev_1.map(function(m_14) {
48157
+ return m_14.id === selected.messageId ? _objectSpread47(_objectSpread47({}, m_14), {}, {
48158
+ nextIndex: selected.startIndex
48147
48159
  }) : m_14;
48148
48160
  });
48149
48161
  });
48150
- var runPlayback = function() {
48151
- var nextIndex_0 = candidate.startIndex;
48152
- var launch = function() {
48153
- return playSegmentsImpl({
48154
- segments: candidate.segments,
48155
- startIndex: candidate.startIndex,
48156
- message: candidate.message,
48157
- play: function() {
48158
- var _play = _asyncToGenerator11(function(segment_0) {
48159
- return _ts_generator(this, function(_state) {
48160
- switch(_state.label){
48161
- case 0:
48162
- activeSegmentsRef.current += 1;
48163
- nextIndex_0 += 1;
48164
- currentSegmentRef.current = {
48165
- messageId: candidate.messageId,
48166
- nextIndex: nextIndex_0
48167
- };
48168
- return [
48169
- 4,
48170
- playInternal(segment_0, {
48171
- onPlay: function() {},
48172
- onStop: function() {
48173
- return handleStop(candidate.messageId);
48174
- },
48175
- onEnd: function() {
48176
- return handleSegmentEnd();
48162
+ var runPlayback = /* @__PURE__ */ function() {
48163
+ var _ref0 = _asyncToGenerator11(function() {
48164
+ var launchedCount;
48165
+ return _ts_generator(this, function(_state) {
48166
+ switch(_state.label){
48167
+ case 0:
48168
+ launchedCount = 0;
48169
+ return [
48170
+ 4,
48171
+ playSegmentsImpl({
48172
+ segments: selected.segments,
48173
+ startIndex: selected.startIndex,
48174
+ message: selected.message,
48175
+ play: function() {
48176
+ var _play = _asyncToGenerator11(function(segment_0) {
48177
+ var advanceTo;
48178
+ return _ts_generator(this, function(_state) {
48179
+ switch(_state.label){
48180
+ case 0:
48181
+ activeSegmentsRef.current += 1;
48182
+ launchedCount += 1;
48183
+ advanceTo = selected.startIndex + launchedCount;
48184
+ onEndPendingRef.current = true;
48185
+ commitAudioQueue(function(prev_2) {
48186
+ return prev_2.map(function(m_15) {
48187
+ return m_15.id === selected.messageId ? _objectSpread47(_objectSpread47({}, m_15), {}, {
48188
+ nextIndex: m_15.nextIndex >= advanceTo ? m_15.nextIndex : advanceTo
48189
+ }) : m_15;
48190
+ });
48191
+ });
48192
+ currentSegmentRef.current = {
48193
+ messageId: selected.messageId,
48194
+ nextIndex: advanceTo
48195
+ };
48196
+ return [
48197
+ 4,
48198
+ playInternal(segment_0, {
48199
+ onPlay: function() {},
48200
+ onStop: function() {
48201
+ return handleStop(selected.messageId);
48202
+ },
48203
+ onEnd: function() {
48204
+ commitAudioQueue(function(prev_3) {
48205
+ return prev_3.map(function(m_16) {
48206
+ return m_16.id === selected.messageId ? _objectSpread47(_objectSpread47({}, m_16), {}, {
48207
+ nextIndex: m_16.nextIndex >= advanceTo ? m_16.nextIndex : advanceTo
48208
+ }) : m_16;
48209
+ });
48210
+ });
48211
+ handleSegmentEnd();
48212
+ }
48213
+ })
48214
+ ];
48215
+ case 1:
48216
+ _state.sent();
48217
+ return [
48218
+ 2
48219
+ ];
48177
48220
  }
48178
- })
48179
- ];
48180
- case 1:
48181
- _state.sent();
48182
- return [
48183
- 2
48184
- ];
48185
- }
48186
- });
48187
- });
48188
- function play(_x6) {
48189
- return _play.apply(this, arguments);
48190
- }
48191
- return play;
48192
- }()
48221
+ });
48222
+ });
48223
+ function play(_x6) {
48224
+ return _play.apply(this, arguments);
48225
+ }
48226
+ return play;
48227
+ }()
48228
+ })
48229
+ ];
48230
+ case 1:
48231
+ _state.sent();
48232
+ return [
48233
+ 2
48234
+ ];
48235
+ }
48193
48236
  });
48237
+ });
48238
+ return function runPlayback2() {
48239
+ return _ref0.apply(this, arguments);
48194
48240
  };
48195
- try {
48196
- Promise.resolve(launch()).catch(function(error_0) {
48197
- handleStop(candidate.messageId);
48198
- console.error(error_0);
48199
- }).finally(function() {
48200
- checkForCompletion();
48201
- });
48202
- } catch (error) {
48203
- handleStop(candidate.messageId);
48204
- console.error(error);
48205
- checkForCompletion();
48206
- }
48207
- };
48208
- runPlayback();
48241
+ }();
48242
+ Promise.resolve(runPlayback()).catch(function(error) {
48243
+ handleStop(selected.messageId);
48244
+ console.error(error);
48245
+ }).finally(function() {
48246
+ var finalNextIndex = selected.startIndex + selected.segments.length;
48247
+ commitAudioQueue(audioQueueRef.current.map(function(m_17) {
48248
+ return m_17.id === selected.messageId ? _objectSpread47(_objectSpread47({}, m_17), {}, {
48249
+ nextIndex: m_17.nextIndex >= finalNextIndex ? m_17.nextIndex : finalNextIndex
48250
+ }) : m_17;
48251
+ }));
48252
+ pickLockRef.current = false;
48253
+ checkForCompletion();
48254
+ });
48209
48255
  if (allowParallel) {
48210
48256
  pickLockRef.current = false;
48211
48257
  }
@@ -48266,8 +48312,8 @@ var useMessageAudio = function(_ref) {
48266
48312
  audioEngine
48267
48313
  ]);
48268
48314
  var isPending = (0, import_react67.useMemo)(function() {
48269
- return isPlaying || audioQueue.some(function(m_15) {
48270
- return !m_15.stopped && (m_15.nextIndex < m_15.segments.length || m_15.status === "in_progress");
48315
+ return isPlaying || audioQueue.some(function(m_18) {
48316
+ return !m_18.stopped && (m_18.nextIndex < m_18.segments.length || m_18.status === "in_progress");
48271
48317
  });
48272
48318
  }, [
48273
48319
  isPlaying,