@waveform-playlist/browser 17.0.0-next.8 → 17.0.0-next.9

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.mjs CHANGED
@@ -51,7 +51,7 @@ var __async = (__this, __arguments, generator) => {
51
51
  };
52
52
 
53
53
  // <define:__INSTALL_SPECS__>
54
- var define_INSTALL_SPECS_default = { "@dawcore/wam": "@dawcore/wam@^0.0.5-next.0", "@dnd-kit/abstract": "@dnd-kit/abstract@^0.5.0", "@dnd-kit/dom": "@dnd-kit/dom@^0.5.0", "@dnd-kit/react": "@dnd-kit/react@^0.5.0", "@waveform-playlist/annotations": "@waveform-playlist/annotations@^14.0.0-next.5", "@waveform-playlist/media-element-playout": "@waveform-playlist/media-element-playout@^12.4.0-next.3", "@waveform-playlist/playout": "@waveform-playlist/playout@^13.0.0-next.3", "@waveform-playlist/recording": "@waveform-playlist/recording@^14.0.0-next.5", react: "react@^19.0.0", "react-dom": "react-dom@^19.0.0", "styled-components": "styled-components@^6.0.0", tone: "tone@^15.0.0", "@waveform-playlist/spectrogram": "@waveform-playlist/spectrogram@^15.0.0-next.3" };
54
+ var define_INSTALL_SPECS_default = { "@dawcore/wam": "@dawcore/wam@^0.0.5-next.0", "@dnd-kit/abstract": "@dnd-kit/abstract@^0.5.0", "@dnd-kit/dom": "@dnd-kit/dom@^0.5.0", "@dnd-kit/react": "@dnd-kit/react@^0.5.0", "@waveform-playlist/annotations": "@waveform-playlist/annotations@^14.0.0-next.6", "@waveform-playlist/media-element-playout": "@waveform-playlist/media-element-playout@^12.4.0-next.4", "@waveform-playlist/playout": "@waveform-playlist/playout@^13.0.0-next.4", "@waveform-playlist/recording": "@waveform-playlist/recording@^14.0.0-next.6", react: "react@^19.0.0", "react-dom": "react-dom@^19.0.0", "styled-components": "styled-components@^6.0.0", tone: "tone@^15.0.0", "@waveform-playlist/spectrogram": "@waveform-playlist/spectrogram@^15.0.0-next.4" };
55
55
 
56
56
  // src/WaveformPlaylistContext.tsx
57
57
  import {
@@ -418,6 +418,7 @@ var PlaylistMixerContext = slot();
418
418
  var TrackReorderPreviewContext = slot();
419
419
  var TrimPreviewContext = slot();
420
420
  var TrimPreviewPeaksContext = slot();
421
+ var DragGuardContext = slot();
421
422
  var RecordingTrackContext = slot();
422
423
  var PlaybackRateContext = slot();
423
424
  var MediaElementTrackContext = slot();
@@ -471,6 +472,7 @@ var usePlaylistViewOptional = () => orNull(use(PlaylistViewContext));
471
472
  var usePlaylistZoomOptional = () => orNull(use(PlaylistZoomContext));
472
473
  var useTrimPreviewOptional = () => orNull(use(TrimPreviewContext));
473
474
  var useTrimPreviewPeaksOptional = () => orNull(use(TrimPreviewPeaksContext));
475
+ var useDragGuardOptional = () => orNull(use(DragGuardContext));
474
476
 
475
477
  // src/hooks/useClipDragHandlers.ts
476
478
  function trimOrderFor(clips, clip) {
@@ -533,6 +535,14 @@ function useClipDragHandlers({
533
535
  const trimDragRef = React.useRef(null);
534
536
  const lastBoundaryDeltaRef = React.useRef(0);
535
537
  const moveDragRef = React.useRef(null);
538
+ const dragGuard = useDragGuardOptional();
539
+ const endGuardRef = React.useRef(null);
540
+ const endGuard = React.useCallback(() => {
541
+ var _a;
542
+ (_a = endGuardRef.current) == null ? void 0 : _a.call(endGuardRef);
543
+ endGuardRef.current = null;
544
+ }, []);
545
+ React.useEffect(() => endGuard, [endGuard]);
536
546
  React.useEffect(() => {
537
547
  if (!preview) return;
538
548
  return () => {
@@ -544,9 +554,11 @@ function useClipDragHandlers({
544
554
  }, [preview]);
545
555
  const onDragStart = React.useCallback(
546
556
  (event) => {
547
- var _a;
557
+ var _a, _b;
548
558
  const data = (_a = event.operation.source) == null ? void 0 : _a.data;
549
559
  if (!data || data.kind === "track-reorder") return;
560
+ endGuard();
561
+ endGuardRef.current = (_b = dragGuard == null ? void 0 : dragGuard.begin()) != null ? _b : null;
550
562
  trimDragRef.current = null;
551
563
  trimOrderRef.current = null;
552
564
  moveDragRef.current = null;
@@ -572,7 +584,7 @@ function useClipDragHandlers({
572
584
  };
573
585
  trimOrderRef.current = trimOrderFor(clips, clip);
574
586
  },
575
- [arrangement]
587
+ [arrangement, dragGuard, endGuard]
576
588
  );
577
589
  const onDragMove = React.useCallback(
578
590
  (event) => {
@@ -624,6 +636,7 @@ function useClipDragHandlers({
624
636
  var _a, _b;
625
637
  const data = (_a = event.operation.source) == null ? void 0 : _a.data;
626
638
  if ((data == null ? void 0 : data.kind) === "track-reorder") return;
639
+ endGuard();
627
640
  const drag = trimDragRef.current;
628
641
  const move = moveDragRef.current;
629
642
  const delta = lastBoundaryDeltaRef.current;
@@ -656,7 +669,7 @@ function useClipDragHandlers({
656
669
  arrangement.moveClip(track.id, clipId, Math.floor(sampleDelta));
657
670
  }
658
671
  },
659
- [samplesPerPixel, arrangement, preview, commitTrim]
672
+ [samplesPerPixel, arrangement, preview, commitTrim, endGuard]
660
673
  );
661
674
  return {
662
675
  onDragStart,
@@ -2922,7 +2935,7 @@ function useRecordingActive(arrangement) {
2922
2935
  const recordingTrack = useMemo10(() => ({ recordingTrackId }), [recordingTrackId]);
2923
2936
  return { setRecordingActive, recordingActiveRef, recordingTrack };
2924
2937
  }
2925
- function useArrangementEditing(arrangement) {
2938
+ function useArrangementEditing(arrangement, dragGuard) {
2926
2939
  const setTrackMute = useCallback18(
2927
2940
  (trackId, muted, options) => {
2928
2941
  if (isTrackId("setTrackMute", trackId)) arrangement.setTrackMute(trackId, muted, options);
@@ -2952,8 +2965,12 @@ function useArrangementEditing(arrangement) {
2952
2965
  (trackId, toIndex) => arrangement.reorderTrack(trackId, toIndex),
2953
2966
  [arrangement]
2954
2967
  );
2955
- const undo = useCallback18(() => arrangement.undo(), [arrangement]);
2956
- const redo = useCallback18(() => arrangement.redo(), [arrangement]);
2968
+ const undo = useCallback18(() => {
2969
+ if (!dragGuard.active) arrangement.undo();
2970
+ }, [arrangement, dragGuard]);
2971
+ const redo = useCallback18(() => {
2972
+ if (!dragGuard.active) arrangement.redo();
2973
+ }, [arrangement, dragGuard]);
2957
2974
  const { setRecordingActive, recordingActiveRef, recordingTrack } = useRecordingActive(arrangement);
2958
2975
  return {
2959
2976
  setTrackMute,
@@ -2969,6 +2986,25 @@ function useArrangementEditing(arrangement) {
2969
2986
  };
2970
2987
  }
2971
2988
 
2989
+ // src/providerInternals/dragGuard.ts
2990
+ function createDragGuard() {
2991
+ let count = 0;
2992
+ return {
2993
+ begin() {
2994
+ count++;
2995
+ let ended = false;
2996
+ return () => {
2997
+ if (ended) return;
2998
+ ended = true;
2999
+ count--;
3000
+ };
3001
+ },
3002
+ get active() {
3003
+ return count > 0;
3004
+ }
3005
+ };
3006
+ }
3007
+
2972
3008
  // src/providerInternals/arrangementIdentity.ts
2973
3009
  import { useEffect as useEffect7, useRef as useRef20 } from "react";
2974
3010
  var arrangementKeys = /* @__PURE__ */ new WeakMap();
@@ -3215,7 +3251,8 @@ var ProviderOnArrangement = ({
3215
3251
  peaksOptions: view.peaksOptions,
3216
3252
  peaksCacheRef: view.peaksCacheRef
3217
3253
  });
3218
- const editing = useArrangementEditing(arrangement);
3254
+ const [dragGuard] = useState15(createDragGuard);
3255
+ const editing = useArrangementEditing(arrangement, dragGuard);
3219
3256
  const { recordingActiveRef } = editing;
3220
3257
  const setLoopRegionFromSelection = useCallback19(() => {
3221
3258
  var _a, _b;
@@ -3833,25 +3870,31 @@ var ProviderOnArrangement = ({
3833
3870
  () => ({ trackDragPreview }),
3834
3871
  [trackDragPreview]
3835
3872
  );
3836
- return /* @__PURE__ */ jsx(ThemeProvider, { theme: mergedTheme, children: /* @__PURE__ */ jsx(PlaybackRateContext, { value: BLOCKED, children: /* @__PURE__ */ jsx(MediaElementTrackContext, { value: BLOCKED, children: /* @__PURE__ */ jsx(ArrangementContext, { value: arrangement, children: /* @__PURE__ */ jsx(PlaybackRefsContext, { value: refsValue, children: /* @__PURE__ */ jsx(EngineRefsContext, { value: engineRefsValue, children: /* @__PURE__ */ jsx(TrimPreviewContext, { value: trimPreview, children: /* @__PURE__ */ jsx(TrimPreviewPeaksContext, { value: trimPreviewPeaks, children: /* @__PURE__ */ jsx(PlaybackControlsContext, { value: controlsValue, children: /* @__PURE__ */ jsx(EditorControlsContext, { value: editorControlsValue, children: /* @__PURE__ */ jsx(PlaylistViewContext, { value: viewValue, children: /* @__PURE__ */ jsx(PlaylistSettingsContext, { value: settingsValue, children: /* @__PURE__ */ jsx(PlaylistZoomContext, { value: zoomValue, children: /* @__PURE__ */ jsx(UndoRedoContext, { value: undoRedoValue, children: /* @__PURE__ */ jsx(SelectedTrackIdContext, { value: selectedTrackIdValue, children: /* @__PURE__ */ jsx(SelectedRowContext, { value: selectedTrackIdValue, children: /* @__PURE__ */ jsx(LoopContext, { value: loopValue, children: /* @__PURE__ */ jsx(AnnotationOptionsContext, { value: annotationOptionsValue, children: /* @__PURE__ */ jsx(AnnotationsContext, { value: annotationsValue, children: /* @__PURE__ */ jsx(IsPlayingContext, { value: isPlayingValue, children: /* @__PURE__ */ jsx(ActiveAnnotationContext, { value: activeAnnotationValue, children: /* @__PURE__ */ jsx(CurrentTimeContext, { value: currentTimeValue, children: /* @__PURE__ */ jsx(SelectionContext, { value: selectionValue, children: /* @__PURE__ */ jsx(
3837
- TrackReorderPreviewContext,
3873
+ return /* @__PURE__ */ jsx(ThemeProvider, { theme: mergedTheme, children: /* @__PURE__ */ jsx(PlaybackRateContext, { value: BLOCKED, children: /* @__PURE__ */ jsx(MediaElementTrackContext, { value: BLOCKED, children: /* @__PURE__ */ jsx(ArrangementContext, { value: arrangement, children: /* @__PURE__ */ jsx(PlaybackRefsContext, { value: refsValue, children: /* @__PURE__ */ jsx(EngineRefsContext, { value: engineRefsValue, children: /* @__PURE__ */ jsx(DragGuardContext, { value: dragGuard, children: /* @__PURE__ */ jsx(TrimPreviewContext, { value: trimPreview, children: /* @__PURE__ */ jsx(TrimPreviewPeaksContext, { value: trimPreviewPeaks, children: /* @__PURE__ */ jsx(PlaybackControlsContext, { value: controlsValue, children: /* @__PURE__ */ jsx(EditorControlsContext, { value: editorControlsValue, children: /* @__PURE__ */ jsx(PlaylistViewContext, { value: viewValue, children: /* @__PURE__ */ jsx(PlaylistSettingsContext, { value: settingsValue, children: /* @__PURE__ */ jsx(PlaylistZoomContext, { value: zoomValue, children: /* @__PURE__ */ jsx(UndoRedoContext, { value: undoRedoValue, children: /* @__PURE__ */ jsx(SelectedTrackIdContext, { value: selectedTrackIdValue, children: /* @__PURE__ */ jsx(SelectedRowContext, { value: selectedTrackIdValue, children: /* @__PURE__ */ jsx(LoopContext, { value: loopValue, children: /* @__PURE__ */ jsx(AnnotationOptionsContext, { value: annotationOptionsValue, children: /* @__PURE__ */ jsx(AnnotationsContext, { value: annotationsValue, children: /* @__PURE__ */ jsx(IsPlayingContext, { value: isPlayingValue, children: /* @__PURE__ */ jsx(
3874
+ ActiveAnnotationContext,
3838
3875
  {
3839
- value: reorderPreviewValue,
3840
- children: /* @__PURE__ */ jsx(PlaylistMixerContext, { value: mixerValue, children: /* @__PURE__ */ jsx(
3841
- PlaylistTimelineContext,
3876
+ value: activeAnnotationValue,
3877
+ children: /* @__PURE__ */ jsx(CurrentTimeContext, { value: currentTimeValue, children: /* @__PURE__ */ jsx(SelectionContext, { value: selectionValue, children: /* @__PURE__ */ jsx(
3878
+ TrackReorderPreviewContext,
3842
3879
  {
3843
- value: timelineValue,
3844
- children: /* @__PURE__ */ jsx(
3845
- RecordingTrackContext,
3880
+ value: reorderPreviewValue,
3881
+ children: /* @__PURE__ */ jsx(PlaylistMixerContext, { value: mixerValue, children: /* @__PURE__ */ jsx(
3882
+ PlaylistTimelineContext,
3846
3883
  {
3847
- value: editing.recordingTrack,
3848
- children
3884
+ value: timelineValue,
3885
+ children: /* @__PURE__ */ jsx(
3886
+ RecordingTrackContext,
3887
+ {
3888
+ value: editing.recordingTrack,
3889
+ children
3890
+ }
3891
+ )
3849
3892
  }
3850
- )
3893
+ ) })
3851
3894
  }
3852
- ) })
3895
+ ) }) })
3853
3896
  }
3854
- ) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) });
3897
+ ) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) });
3855
3898
  };
3856
3899
 
3857
3900
  // src/MediaElementPlaylistContext.tsx
@@ -7370,11 +7413,21 @@ var ClipInteractionProvider = ({
7370
7413
  onDragMove,
7371
7414
  onDragEnd
7372
7415
  } = useClipDragHandlers({ samplesPerPixel, snapSamplePosition });
7416
+ const dragGuard = useDragGuardOptional();
7417
+ const endReorderGuardRef = useRef32(null);
7418
+ const endReorderGuard = useCallback28(() => {
7419
+ var _a;
7420
+ (_a = endReorderGuardRef.current) == null ? void 0 : _a.call(endReorderGuardRef);
7421
+ endReorderGuardRef.current = null;
7422
+ }, []);
7423
+ React23.useEffect(() => endReorderGuard, [endReorderGuard]);
7373
7424
  const onDragStart = React23.useCallback(
7374
7425
  (event) => {
7375
- var _a, _b;
7426
+ var _a, _b, _c;
7376
7427
  const data = (_b = (_a = event.operation) == null ? void 0 : _a.source) == null ? void 0 : _b.data;
7377
7428
  if ((data == null ? void 0 : data.kind) === "track-reorder") {
7429
+ endReorderGuard();
7430
+ endReorderGuardRef.current = (_c = dragGuard == null ? void 0 : dragGuard.begin()) != null ? _c : null;
7378
7431
  if (data.trackId) setSelectedTrackId(data.trackId);
7379
7432
  return;
7380
7433
  }
@@ -7385,7 +7438,7 @@ var ClipInteractionProvider = ({
7385
7438
  }
7386
7439
  handleDragStart(event);
7387
7440
  },
7388
- [handleDragStart, setSelectedTrackId]
7441
+ [handleDragStart, setSelectedTrackId, dragGuard, endReorderGuard]
7389
7442
  );
7390
7443
  const handleDragOver = React23.useCallback(
7391
7444
  (event) => {
@@ -7407,6 +7460,7 @@ var ClipInteractionProvider = ({
7407
7460
  var _a;
7408
7461
  const data = (_a = event.operation.source) == null ? void 0 : _a.data;
7409
7462
  if ((data == null ? void 0 : data.kind) === "track-reorder") {
7463
+ endReorderGuard();
7410
7464
  const sortable = event.operation.source.sortable;
7411
7465
  const trackId = data.trackId;
7412
7466
  const moves = !event.canceled && trackId && sortable && sortable.index !== sortable.initialIndex;
@@ -7418,7 +7472,7 @@ var ClipInteractionProvider = ({
7418
7472
  }
7419
7473
  onDragEnd(event);
7420
7474
  },
7421
- [onDragEnd, reorderTrack, setTrackDragPreview]
7475
+ [onDragEnd, reorderTrack, setTrackDragPreview, endReorderGuard]
7422
7476
  );
7423
7477
  const modifiers = useMemo23(() => {
7424
7478
  const mods = [RestrictToHorizontalAxis2];