@waveform-playlist/browser 15.3.4 → 16.0.0

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
@@ -588,7 +588,7 @@ function useClipDragHandlers({
588
588
  (event) => {
589
589
  var _a;
590
590
  const data = (_a = event.operation.source) == null ? void 0 : _a.data;
591
- if (!data) return;
591
+ if (!data || data.kind === "track-reorder") return;
592
592
  if (!data.boundary) {
593
593
  originalClipStateRef.current = null;
594
594
  if (engineRef.current) {
@@ -624,7 +624,7 @@ function useClipDragHandlers({
624
624
  (event) => {
625
625
  var _a, _b, _c;
626
626
  const data = (_a = event.operation.source) == null ? void 0 : _a.data;
627
- if (!data) return;
627
+ if (!data || data.kind === "track-reorder") return;
628
628
  if (!data.boundary) return;
629
629
  if (!originalClipStateRef.current) return;
630
630
  const { boundary, trackIndex, clipIndex } = data;
@@ -684,10 +684,12 @@ function useClipDragHandlers({
684
684
  );
685
685
  const onDragEnd = React.useCallback(
686
686
  (event) => {
687
- var _a, _b, _c, _d, _e, _f, _g;
687
+ var _a, _b, _c, _d, _e, _f, _g, _h;
688
+ const kindData = (_a = event.operation.source) == null ? void 0 : _a.data;
689
+ if ((kindData == null ? void 0 : kindData.kind) === "track-reorder") return;
688
690
  if (event.canceled) {
689
691
  if (originalClipStateRef.current) {
690
- const cancelData = (_a = event.operation.source) == null ? void 0 : _a.data;
692
+ const cancelData = (_b = event.operation.source) == null ? void 0 : _b.data;
691
693
  if (cancelData) {
692
694
  const { trackIndex: trackIndex2, clipIndex } = cancelData;
693
695
  const original = originalClipStateRef.current;
@@ -709,25 +711,25 @@ function useClipDragHandlers({
709
711
  isDraggingRef.current = false;
710
712
  originalClipStateRef.current = null;
711
713
  lastBoundaryDeltaRef.current = 0;
712
- (_b = engineRef.current) == null ? void 0 : _b.abortTransaction();
714
+ (_c = engineRef.current) == null ? void 0 : _c.abortTransaction();
713
715
  return;
714
716
  }
715
- const data = (_c = event.operation.source) == null ? void 0 : _c.data;
717
+ const data = (_d = event.operation.source) == null ? void 0 : _d.data;
716
718
  if (!data) {
717
719
  isDraggingRef.current = false;
718
- (_d = engineRef.current) == null ? void 0 : _d.abortTransaction();
720
+ (_e = engineRef.current) == null ? void 0 : _e.abortTransaction();
719
721
  return;
720
722
  }
721
723
  const { trackIndex, clipId, boundary } = data;
722
724
  const sampleDelta = boundary ? lastBoundaryDeltaRef.current : event.operation.transform.x * samplesPerPixel;
723
- const trackId = (_e = tracks[trackIndex]) == null ? void 0 : _e.id;
725
+ const trackId = (_f = tracks[trackIndex]) == null ? void 0 : _f.id;
724
726
  if (boundary) {
725
727
  isDraggingRef.current = false;
726
728
  if (!trackId) {
727
729
  console.warn(
728
730
  `[waveform-playlist] onDragEnd: track at index ${trackIndex} not found \u2014 trim not synced to adapter`
729
731
  );
730
- (_f = engineRef.current) == null ? void 0 : _f.abortTransaction();
732
+ (_g = engineRef.current) == null ? void 0 : _g.abortTransaction();
731
733
  } else if (!engineRef.current) {
732
734
  console.warn("[waveform-playlist] engineRef is null \u2014 trim not synced to adapter");
733
735
  } else {
@@ -742,7 +744,7 @@ function useClipDragHandlers({
742
744
  console.warn(
743
745
  `[waveform-playlist] onDragEnd: track at index ${trackIndex} not found \u2014 move not synced to adapter`
744
746
  );
745
- (_g = engineRef.current) == null ? void 0 : _g.abortTransaction();
747
+ (_h = engineRef.current) == null ? void 0 : _h.abortTransaction();
746
748
  } else if (!engineRef.current) {
747
749
  console.warn("[waveform-playlist] engineRef is null \u2014 move not synced to adapter");
748
750
  } else {
@@ -1849,6 +1851,8 @@ var WaveformPlaylistProvider = ({
1849
1851
  const [linkEndpoints, setLinkEndpoints] = useState9((_b = annotationList == null ? void 0 : annotationList.linkEndpoints) != null ? _b : false);
1850
1852
  const [annotationsEditable, setAnnotationsEditable] = useState9((_c = annotationList == null ? void 0 : annotationList.editable) != null ? _c : false);
1851
1853
  const [isReady, setIsReady] = useState9(false);
1854
+ const [trackReorderEpoch, setTrackReorderEpoch] = useState9(0);
1855
+ const [trackDragPreview, setTrackDragPreview] = useState9(null);
1852
1856
  const engineRef = useRef9(null);
1853
1857
  const adapterRef = useRef9(null);
1854
1858
  const audioInitializedRef = useRef9(false);
@@ -2188,6 +2192,19 @@ var WaveformPlaylistProvider = ({
2188
2192
  if (!suppressTracksMirroring && state.tracksVersion !== lastTracksVersionRef.current) {
2189
2193
  lastTracksVersionRef.current = state.tracksVersion;
2190
2194
  engineTracksRef.current = state.tracks;
2195
+ const oldTracks = tracksRef.current;
2196
+ const oldStates = trackStatesRef.current;
2197
+ if (oldTracks.length === oldStates.length && oldTracks.length === state.tracks.length) {
2198
+ const idToState = new Map(oldTracks.map((t, i) => [t.id, oldStates[i]]));
2199
+ const reordered = state.tracks.map((t, i) => {
2200
+ var _a4;
2201
+ return (_a4 = idToState.get(t.id)) != null ? _a4 : oldStates[i];
2202
+ });
2203
+ const orderChanged = reordered.some((s, i) => s !== oldStates[i]);
2204
+ if (orderChanged) {
2205
+ setTrackStates(reordered);
2206
+ }
2207
+ }
2191
2208
  if (onTracksChange) {
2192
2209
  onTracksChange(state.tracks);
2193
2210
  } else {
@@ -2670,6 +2687,19 @@ var WaveformPlaylistProvider = ({
2670
2687
  },
2671
2688
  [trackStates]
2672
2689
  );
2690
+ const reorderTrack = useCallback13(
2691
+ (trackId, toIndex) => {
2692
+ if (!engineRef.current) {
2693
+ console.warn("[waveform-playlist] reorderTrack: engine not ready, call ignored");
2694
+ return;
2695
+ }
2696
+ engineRef.current.reorderTrack(trackId, toIndex);
2697
+ },
2698
+ [engineRef]
2699
+ );
2700
+ const bumpTrackReorderEpoch = useCallback13(() => {
2701
+ setTrackReorderEpoch((epoch) => epoch + 1);
2702
+ }, []);
2673
2703
  const setSelection = useCallback13(
2674
2704
  (start, end) => {
2675
2705
  setSelectionEngine(start, end);
@@ -2799,6 +2829,9 @@ var WaveformPlaylistProvider = ({
2799
2829
  setTrackSolo,
2800
2830
  setTrackVolume,
2801
2831
  setTrackPan,
2832
+ reorderTrack,
2833
+ bumpTrackReorderEpoch,
2834
+ setTrackDragPreview,
2802
2835
  // Selection
2803
2836
  setSelection,
2804
2837
  setSelectedTrackId: setSelectedTrackIdControl,
@@ -2841,6 +2874,9 @@ var WaveformPlaylistProvider = ({
2841
2874
  setTrackSolo,
2842
2875
  setTrackVolume,
2843
2876
  setTrackPan,
2877
+ reorderTrack,
2878
+ bumpTrackReorderEpoch,
2879
+ setTrackDragPreview,
2844
2880
  setSelection,
2845
2881
  setSelectedTrackIdControl,
2846
2882
  setTimeFormat,
@@ -2888,6 +2924,8 @@ var WaveformPlaylistProvider = ({
2888
2924
  roundedBars,
2889
2925
  progressBarWidth,
2890
2926
  isReady,
2927
+ trackReorderEpoch,
2928
+ trackDragPreview,
2891
2929
  mono,
2892
2930
  isDraggingRef,
2893
2931
  onTracksChange
@@ -2914,6 +2952,8 @@ var WaveformPlaylistProvider = ({
2914
2952
  roundedBars,
2915
2953
  progressBarWidth,
2916
2954
  isReady,
2955
+ trackReorderEpoch,
2956
+ trackDragPreview,
2917
2957
  mono,
2918
2958
  isDraggingRef,
2919
2959
  onTracksChange
@@ -3689,11 +3729,11 @@ function useClipInteractionEnabled() {
3689
3729
  // src/components/PlaylistVisualization.tsx
3690
3730
  import {
3691
3731
  useContext as useContext6,
3692
- useEffect as useEffect10,
3693
- useRef as useRef14,
3694
- useState as useState11,
3732
+ useEffect as useEffect12,
3733
+ useRef as useRef15,
3734
+ useState as useState12,
3695
3735
  useMemo as useMemo5,
3696
- useCallback as useCallback16
3736
+ useCallback as useCallback17
3697
3737
  } from "react";
3698
3738
  import { createPortal } from "react-dom";
3699
3739
  import styled4 from "styled-components";
@@ -3719,14 +3759,155 @@ import {
3719
3759
  useTheme as useTheme2,
3720
3760
  waveformColorToCss as waveformColorToCss2,
3721
3761
  SpectrogramLabels,
3722
- CLIP_HEADER_HEIGHT
3762
+ CLIP_HEADER_HEIGHT,
3763
+ ReorderRail
3723
3764
  } from "@waveform-playlist/ui-components";
3765
+
3766
+ // src/components/SortableTrackControls.tsx
3767
+ import { useCallback as useCallback16, useEffect as useEffect8, useRef as useRef12 } from "react";
3768
+ import { useSortable } from "@dnd-kit/react/sortable";
3769
+ import { RestrictToVerticalAxis } from "@dnd-kit/abstract/modifiers";
3770
+ import { Feedback } from "@dnd-kit/dom";
3771
+
3772
+ // src/utils/dragPopoverHealer.ts
3773
+ function createDragPopoverHealer(element) {
3774
+ if (typeof element.showPopover !== "function") {
3775
+ return () => {
3776
+ };
3777
+ }
3778
+ const heal = () => {
3779
+ if (!element.isConnected || !element.hasAttribute("popover")) return;
3780
+ let open = false;
3781
+ try {
3782
+ open = element.matches(":popover-open");
3783
+ } catch (e) {
3784
+ }
3785
+ if (open) return;
3786
+ try {
3787
+ element.showPopover();
3788
+ } catch (e) {
3789
+ }
3790
+ };
3791
+ const observer = new MutationObserver(heal);
3792
+ observer.observe(element.ownerDocument.body, {
3793
+ childList: true,
3794
+ subtree: true
3795
+ });
3796
+ return () => observer.disconnect();
3797
+ }
3798
+
3799
+ // src/components/SortableTrackControls.tsx
3800
+ import { Fragment, jsx as jsx7 } from "react/jsx-runtime";
3801
+ var MOVE_FEEDBACK = Feedback.configure({ feedback: "move" });
3802
+ var withMoveFeedback = (defaults) => [...defaults, MOVE_FEEDBACK];
3803
+ var SortableTrackControls = ({
3804
+ trackId,
3805
+ index,
3806
+ disabled = false,
3807
+ children
3808
+ }) => {
3809
+ const { ref, handleRef, isDragSource } = useSortable({
3810
+ id: `track-reorder-${trackId}`,
3811
+ index,
3812
+ group: "playlist-tracks",
3813
+ type: "track",
3814
+ accept: ["track"],
3815
+ data: { kind: "track-reorder", trackId },
3816
+ modifiers: [RestrictToVerticalAxis],
3817
+ disabled,
3818
+ // Per-entity Feedback config (@dnd-kit 0.5+ moved `feedback` out of the
3819
+ // hook options into `plugins`). The FUNCTION form extends the sortable's
3820
+ // default plugins — a bare array would silently drop
3821
+ // OptimisticSortingPlugin, which drives the live `sortable.index` that
3822
+ // drag-commit reads (covered by sortableTrackControlsFeedbackPlugins.test).
3823
+ //
3824
+ // feedback: 'move' (NOT 'none' — see below) disables the Feedback
3825
+ // plugin's placeholder/clone splicing for this sortable while KEEPING its
3826
+ // dragOperation.shape computation alive. That plugin does raw,
3827
+ // React-bypassing DOM surgery on ANY pointer movement during an activated
3828
+ // drag (insertAdjacentElement to splice in a placeholder, then
3829
+ // `placeholder.replaceWith(element)` on drop) — confirmed via
3830
+ // MutationObserver instrumentation to relocate the React-owned row 6
3831
+ // times during a single one-slot drag, leaving its final parent/sibling
3832
+ // different from what React's fiber tree still believes. That desync is
3833
+ // permanent for the session: every later React-driven reorder (button OR
3834
+ // drag) computes the correct data but silently fails to update the DOM
3835
+ // for these rows. The placeholder splice is created only when
3836
+ // `feedback !== 'move'` (@dnd-kit/dom Feedback.ts) — 'move' keeps the
3837
+ // dragged element in the live DOM (no clone/placeholder) while still
3838
+ // running the *unconditional* `dragOperation.shape = ...` assignment.
3839
+ // `feedback: 'none'` looked like the boundary-trim precedent (Clip.tsx /
3840
+ // AnnotationBox.tsx) but is wrong here: 'none' bails out of Feedback's
3841
+ // render function BEFORE dragOperation.shape is ever set, and shape is
3842
+ // the ONLY input CollisionObserver.computeCollisions() checks — with
3843
+ // 'none', collision (and therefore sortable.index) never updates, so
3844
+ // drag-based reordering silently never commits. Boundary trims don't hit
3845
+ // this because they're plain useDraggable (no collision-based commit) —
3846
+ // sortables need shape. `isDragSource` (box-shadow lift feedback below)
3847
+ // is a reactive signal, unaffected either way. See browser/CLAUDE.md
3848
+ // "Track Reordering".
3849
+ plugins: withMoveFeedback
3850
+ });
3851
+ const elementRef = useRef12(null);
3852
+ const composedRef = useCallback16(
3853
+ (element) => {
3854
+ elementRef.current = element instanceof HTMLElement ? element : null;
3855
+ ref(element);
3856
+ },
3857
+ [ref]
3858
+ );
3859
+ useEffect8(() => {
3860
+ if (!isDragSource || !elementRef.current) return void 0;
3861
+ return createDragPopoverHealer(elementRef.current);
3862
+ }, [isDragSource]);
3863
+ return /* @__PURE__ */ jsx7(Fragment, { children: children({ ref: composedRef, handleRef, isDragSource }) });
3864
+ };
3865
+
3866
+ // src/utils/trackOrderPreview.ts
3867
+ function applyTrackOrderPreview(tracks, preview) {
3868
+ if (!preview) return tracks;
3869
+ const fromIndex = tracks.findIndex((t) => t.id === preview.trackId);
3870
+ if (fromIndex === -1) return tracks;
3871
+ const toIndex = Math.max(0, Math.min(tracks.length - 1, preview.toIndex));
3872
+ if (toIndex === fromIndex) return tracks;
3873
+ const next = tracks.slice();
3874
+ const [moved] = next.splice(fromIndex, 1);
3875
+ next.splice(toIndex, 0, moved);
3876
+ return next;
3877
+ }
3878
+ function computeTrackLayout(orderedIds, heightById) {
3879
+ var _a;
3880
+ const topById = /* @__PURE__ */ new Map();
3881
+ let top = 0;
3882
+ for (const id of orderedIds) {
3883
+ topById.set(id, top);
3884
+ top += (_a = heightById.get(id)) != null ? _a : 0;
3885
+ }
3886
+ return { topById, totalHeight: top };
3887
+ }
3888
+
3889
+ // src/hooks/useTrailingActive.ts
3890
+ import { useEffect as useEffect9, useState as useState11 } from "react";
3891
+ function useTrailingActive(active, trailingMs) {
3892
+ const [trailing, setTrailing] = useState11(active);
3893
+ useEffect9(() => {
3894
+ if (active) {
3895
+ setTrailing(true);
3896
+ return void 0;
3897
+ }
3898
+ const timer = setTimeout(() => setTrailing(false), trailingMs);
3899
+ return () => clearTimeout(timer);
3900
+ }, [active, trailingMs]);
3901
+ return trailing || active;
3902
+ }
3903
+
3904
+ // src/components/PlaylistVisualization.tsx
3724
3905
  import { resolveRecordingOffsetSamples } from "@waveform-playlist/core";
3725
3906
 
3726
3907
  // src/components/AnimatedPlayhead.tsx
3727
- import { useRef as useRef12, useEffect as useEffect8 } from "react";
3908
+ import { useRef as useRef13, useEffect as useEffect10 } from "react";
3728
3909
  import styled2 from "styled-components";
3729
- import { jsx as jsx7 } from "react/jsx-runtime";
3910
+ import { jsx as jsx8 } from "react/jsx-runtime";
3730
3911
  var PlayheadLine = styled2.div.attrs((props) => ({
3731
3912
  style: {
3732
3913
  width: `${props.$width}px`,
@@ -3742,7 +3923,7 @@ var PlayheadLine = styled2.div.attrs((props) => ({
3742
3923
  will-change: transform;
3743
3924
  `;
3744
3925
  var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3745
- const playheadRef = useRef12(null);
3926
+ const playheadRef = useRef13(null);
3746
3927
  const {
3747
3928
  isPlaying,
3748
3929
  currentTimeRef,
@@ -3751,7 +3932,7 @@ var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3751
3932
  unregisterFrameCallback
3752
3933
  } = usePlaybackAnimation();
3753
3934
  const { samplesPerPixel, sampleRate, progressBarWidth } = usePlaylistData();
3754
- useEffect8(() => {
3935
+ useEffect10(() => {
3755
3936
  const id = "playhead";
3756
3937
  if (isPlaying) {
3757
3938
  registerFrameCallback(id, ({ visualTime, sampleRate: sr, samplesPerPixel: spp }) => {
@@ -3763,7 +3944,7 @@ var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3763
3944
  }
3764
3945
  return () => unregisterFrameCallback(id);
3765
3946
  }, [isPlaying, registerFrameCallback, unregisterFrameCallback]);
3766
- useEffect8(() => {
3947
+ useEffect10(() => {
3767
3948
  var _a, _b;
3768
3949
  if (!isPlaying && playheadRef.current) {
3769
3950
  const time = (_b = (_a = visualTimeRef.current) != null ? _a : currentTimeRef.current) != null ? _b : 0;
@@ -3771,11 +3952,11 @@ var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3771
3952
  playheadRef.current.style.transform = `translate3d(${position}px, 0, 0)`;
3772
3953
  }
3773
3954
  });
3774
- return /* @__PURE__ */ jsx7(PlayheadLine, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
3955
+ return /* @__PURE__ */ jsx8(PlayheadLine, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
3775
3956
  };
3776
3957
 
3777
3958
  // src/components/ChannelWithProgress.tsx
3778
- import { useId, useRef as useRef13, useEffect as useEffect9 } from "react";
3959
+ import { useId, useRef as useRef14, useEffect as useEffect11 } from "react";
3779
3960
  import styled3 from "styled-components";
3780
3961
  import {
3781
3962
  clipPixelWidth as computeClipPixelWidth
@@ -3786,7 +3967,7 @@ import {
3786
3967
  usePlaylistInfo,
3787
3968
  waveformColorToCss
3788
3969
  } from "@waveform-playlist/ui-components";
3789
- import { Fragment, jsx as jsx8, jsxs } from "react/jsx-runtime";
3970
+ import { Fragment as Fragment2, jsx as jsx9, jsxs } from "react/jsx-runtime";
3790
3971
  var ChannelWrapper = styled3.div`
3791
3972
  position: relative;
3792
3973
  `;
@@ -3840,7 +4021,7 @@ var ChannelWithProgress = (_a) => {
3840
4021
  "clipSampleRate",
3841
4022
  "clipOffsetSeconds"
3842
4023
  ]);
3843
- const progressRef = useRef13(null);
4024
+ const progressRef = useRef14(null);
3844
4025
  const callbackId = useId();
3845
4026
  const theme = useTheme();
3846
4027
  const { waveHeight } = usePlaylistInfo();
@@ -3858,7 +4039,7 @@ var ChannelWithProgress = (_a) => {
3858
4039
  clipDurationSamples,
3859
4040
  samplesPerPixel
3860
4041
  );
3861
- useEffect9(() => {
4042
+ useEffect11(() => {
3862
4043
  if (isPlaying) {
3863
4044
  registerFrameCallback(callbackId, ({ visualTime, sampleRate: sr }) => {
3864
4045
  if (progressRef.current) {
@@ -3886,7 +4067,7 @@ var ChannelWithProgress = (_a) => {
3886
4067
  registerFrameCallback,
3887
4068
  unregisterFrameCallback
3888
4069
  ]);
3889
- useEffect9(() => {
4070
+ useEffect11(() => {
3890
4071
  var _a2, _b2;
3891
4072
  if (!isPlaying && progressRef.current) {
3892
4073
  const currentTime = (_b2 = (_a2 = visualTimeRef.current) != null ? _a2 : currentTimeRef.current) != null ? _b2 : 0;
@@ -3920,8 +4101,8 @@ var ChannelWithProgress = (_a) => {
3920
4101
  const effectiveTop = isBothMode ? smartChannelProps.index * waveHeight : smartChannelProps.index * waveHeight;
3921
4102
  const waveformBackgroundCss = waveformColorToCss(backgroundColor);
3922
4103
  return /* @__PURE__ */ jsxs(ChannelWrapper, { children: [
3923
- isBothMode ? /* @__PURE__ */ jsxs(Fragment, { children: [
3924
- /* @__PURE__ */ jsx8(
4104
+ isBothMode ? /* @__PURE__ */ jsxs(Fragment2, { children: [
4105
+ /* @__PURE__ */ jsx9(
3925
4106
  Background,
3926
4107
  {
3927
4108
  $color: "#000",
@@ -3930,7 +4111,7 @@ var ChannelWithProgress = (_a) => {
3930
4111
  $width: smartChannelProps.length
3931
4112
  }
3932
4113
  ),
3933
- /* @__PURE__ */ jsx8(
4114
+ /* @__PURE__ */ jsx9(
3934
4115
  Background,
3935
4116
  {
3936
4117
  $color: waveformBackgroundCss,
@@ -3939,7 +4120,7 @@ var ChannelWithProgress = (_a) => {
3939
4120
  $width: smartChannelProps.length
3940
4121
  }
3941
4122
  )
3942
- ] }) : /* @__PURE__ */ jsx8(
4123
+ ] }) : /* @__PURE__ */ jsx9(
3943
4124
  Background,
3944
4125
  {
3945
4126
  $color: backgroundCss,
@@ -3948,7 +4129,7 @@ var ChannelWithProgress = (_a) => {
3948
4129
  $width: smartChannelProps.length
3949
4130
  }
3950
4131
  ),
3951
- !isPianoRollMode && /* @__PURE__ */ jsx8(
4132
+ !isPianoRollMode && /* @__PURE__ */ jsx9(
3952
4133
  ProgressOverlay,
3953
4134
  {
3954
4135
  ref: progressRef,
@@ -3958,7 +4139,7 @@ var ChannelWithProgress = (_a) => {
3958
4139
  $width: clipPixelWidth
3959
4140
  }
3960
4141
  ),
3961
- /* @__PURE__ */ jsx8(ChannelContainer, { children: /* @__PURE__ */ jsx8(
4142
+ /* @__PURE__ */ jsx9(ChannelContainer, { children: /* @__PURE__ */ jsx9(
3962
4143
  SmartChannel,
3963
4144
  __spreadProps(__spreadValues({}, smartChannelProps), {
3964
4145
  transparentBackground: true,
@@ -3985,15 +4166,42 @@ function useSpectrogramIntegration() {
3985
4166
  }
3986
4167
 
3987
4168
  // src/components/PlaylistVisualization.tsx
3988
- import { Fragment as Fragment2, jsx as jsx9, jsxs as jsxs2 } from "react/jsx-runtime";
4169
+ import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs2 } from "react/jsx-runtime";
3989
4170
  var DEFAULT_EMPTY_TRACK_DURATION = 60;
3990
- var ControlSlot = styled4.div.attrs((props) => ({
4171
+ var DRAG_SOURCE_SHADOW = "0 4px 12px rgba(0, 0, 0, 0.35)";
4172
+ var TracksLayout = styled4.div.attrs((props) => ({
3991
4173
  style: { height: `${props.$height}px` }
3992
4174
  }))`
4175
+ position: relative;
4176
+ `;
4177
+ var TrackRowPositioner = styled4.div.attrs((props) => ({
4178
+ style: { top: `${props.$top}px` }
4179
+ }))`
4180
+ position: absolute;
4181
+ left: 0;
4182
+ right: 0;
4183
+ ${(props) => props.$animate && "transition: top 150ms ease;"}
4184
+ @media (prefers-reduced-motion: reduce) {
4185
+ transition: none;
4186
+ }
4187
+ `;
4188
+ var ControlSlot = styled4.div.attrs((props) => ({
4189
+ style: {
4190
+ height: `${props.$height}px`,
4191
+ top: `${props.$top}px`
4192
+ }
4193
+ }))`
4194
+ position: absolute;
4195
+ left: 0;
4196
+ right: 0;
3993
4197
  overflow: hidden;
3994
4198
  pointer-events: auto;
3995
4199
  background: ${(props) => props.theme.surfaceColor};
3996
4200
  transition: background 0.15s ease-in-out;
4201
+ ${(props) => props.$animate && "transition: top 150ms ease, background 0.15s ease-in-out;"}
4202
+ @media (prefers-reduced-motion: reduce) {
4203
+ transition: background 0.15s ease-in-out;
4204
+ }
3997
4205
  ${(props) => props.$isSelected && `background: ${props.theme.selectedTrackControlsBackground};`}
3998
4206
  `;
3999
4207
  var CustomPlayhead = ({ renderPlayhead, color, samplesPerPixel, sampleRate }) => {
@@ -4028,6 +4236,133 @@ function getTrackChannelCount(trackClipPeaks, recordingState, trackId, mono) {
4028
4236
  const recordingChannels = (recordingState == null ? void 0 : recordingState.isRecording) && recordingState.trackId === trackId ? mono ? 1 : recordingState.peaks.length : 0;
4029
4237
  return Math.max(clipChannels, recordingChannels);
4030
4238
  }
4239
+ function DefaultTrackControls({
4240
+ trackIndex,
4241
+ track,
4242
+ trackState,
4243
+ effectiveRenderMode,
4244
+ selectTrack,
4245
+ onRemoveTrack,
4246
+ setTrackMute,
4247
+ setTrackSolo,
4248
+ setTrackVolume,
4249
+ setTrackPan,
4250
+ spectrogram,
4251
+ setSettingsModalTrackId,
4252
+ trackReordering,
4253
+ reorderTrack,
4254
+ trackCount,
4255
+ gripRef
4256
+ }) {
4257
+ return /* @__PURE__ */ jsxs2(
4258
+ Controls,
4259
+ {
4260
+ onClick: () => selectTrack(trackIndex),
4261
+ style: trackReordering ? { position: "relative", paddingLeft: 18, paddingRight: 18 } : void 0,
4262
+ children: [
4263
+ /* @__PURE__ */ jsxs2(Header, { style: { justifyContent: "center", position: "relative" }, children: [
4264
+ onRemoveTrack && /* @__PURE__ */ jsx10(
4265
+ CloseButton,
4266
+ {
4267
+ onClick: (e) => {
4268
+ e.stopPropagation();
4269
+ onRemoveTrack(trackIndex);
4270
+ }
4271
+ }
4272
+ ),
4273
+ /* @__PURE__ */ jsx10(
4274
+ "span",
4275
+ {
4276
+ style: {
4277
+ overflow: "hidden",
4278
+ textOverflow: "ellipsis",
4279
+ whiteSpace: "nowrap",
4280
+ padding: "0 24px",
4281
+ display: "block"
4282
+ },
4283
+ children: trackState.name || `Track ${trackIndex + 1}`
4284
+ }
4285
+ ),
4286
+ (spectrogram == null ? void 0 : spectrogram.renderMenuItems) && /* @__PURE__ */ jsx10("span", { style: { position: "absolute", right: 0, top: 0 }, children: /* @__PURE__ */ jsx10(
4287
+ TrackMenu,
4288
+ {
4289
+ items: (onClose) => spectrogram.renderMenuItems({
4290
+ renderMode: effectiveRenderMode,
4291
+ onRenderModeChange: (mode) => spectrogram.setTrackRenderMode(track.id, mode),
4292
+ onOpenSettings: () => setSettingsModalTrackId(track.id),
4293
+ onClose
4294
+ })
4295
+ }
4296
+ ) })
4297
+ ] }),
4298
+ /* @__PURE__ */ jsxs2(ButtonGroup, { children: [
4299
+ /* @__PURE__ */ jsx10(
4300
+ Button,
4301
+ {
4302
+ $variant: trackState.muted ? "danger" : "outline",
4303
+ onClick: () => setTrackMute(trackIndex, !trackState.muted),
4304
+ children: "Mute"
4305
+ }
4306
+ ),
4307
+ /* @__PURE__ */ jsx10(
4308
+ Button,
4309
+ {
4310
+ $variant: trackState.soloed ? "info" : "outline",
4311
+ onClick: () => setTrackSolo(trackIndex, !trackState.soloed),
4312
+ children: "Solo"
4313
+ }
4314
+ )
4315
+ ] }),
4316
+ /* @__PURE__ */ jsxs2(SliderWrapper, { children: [
4317
+ /* @__PURE__ */ jsx10(VolumeDownIcon, {}),
4318
+ /* @__PURE__ */ jsx10(
4319
+ Slider,
4320
+ {
4321
+ min: "0",
4322
+ max: "1",
4323
+ step: "0.01",
4324
+ value: trackState.volume,
4325
+ onChange: (e) => setTrackVolume(trackIndex, parseFloat(e.target.value))
4326
+ }
4327
+ ),
4328
+ /* @__PURE__ */ jsx10(VolumeUpIcon, {})
4329
+ ] }),
4330
+ /* @__PURE__ */ jsxs2(SliderWrapper, { children: [
4331
+ /* @__PURE__ */ jsx10("span", { children: "L" }),
4332
+ /* @__PURE__ */ jsx10(
4333
+ Slider,
4334
+ {
4335
+ min: "-1",
4336
+ max: "1",
4337
+ step: "0.01",
4338
+ value: trackState.pan,
4339
+ onChange: (e) => setTrackPan(trackIndex, parseFloat(e.target.value))
4340
+ }
4341
+ ),
4342
+ /* @__PURE__ */ jsx10("span", { children: "R" })
4343
+ ] }),
4344
+ trackReordering && /* @__PURE__ */ jsx10(
4345
+ ReorderRail,
4346
+ {
4347
+ style: { position: "absolute", right: 2, top: "50%", transform: "translateY(-50%)" },
4348
+ gripRef,
4349
+ onGripClick: (e) => e.stopPropagation(),
4350
+ upDisabled: trackIndex === 0,
4351
+ downDisabled: trackIndex === trackCount - 1,
4352
+ onMoveUp: (e) => {
4353
+ e.stopPropagation();
4354
+ reorderTrack(track.id, trackIndex - 1);
4355
+ },
4356
+ onMoveDown: (e) => {
4357
+ e.stopPropagation();
4358
+ reorderTrack(track.id, trackIndex + 1);
4359
+ }
4360
+ }
4361
+ )
4362
+ ]
4363
+ }
4364
+ );
4365
+ }
4031
4366
  var PlaylistVisualization = ({
4032
4367
  renderTrackControls,
4033
4368
  renderTick,
@@ -4040,7 +4375,8 @@ var PlaylistVisualization = ({
4040
4375
  showFades = false,
4041
4376
  touchOptimized = false,
4042
4377
  onRemoveTrack,
4043
- recordingState
4378
+ recordingState,
4379
+ trackReordering = false
4044
4380
  }) => {
4045
4381
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
4046
4382
  const theme = useTheme2();
@@ -4074,7 +4410,8 @@ var PlaylistVisualization = ({
4074
4410
  setSelectedTrackId,
4075
4411
  setCurrentTime,
4076
4412
  setLoopRegion,
4077
- setRecordingActive
4413
+ setRecordingActive,
4414
+ reorderTrack
4078
4415
  } = usePlaylistControls();
4079
4416
  const {
4080
4417
  peaksDataArray,
@@ -4090,12 +4427,14 @@ var PlaylistVisualization = ({
4090
4427
  barGap,
4091
4428
  roundedBars,
4092
4429
  isReady,
4093
- mono
4430
+ trackReorderEpoch,
4431
+ mono,
4432
+ trackDragPreview
4094
4433
  } = usePlaylistData();
4095
4434
  const spectrogram = useContext6(SpectrogramIntegrationContext);
4096
4435
  const recordingActive = !!(recordingState == null ? void 0 : recordingState.isRecording);
4097
4436
  const armedTrackId = (_a = recordingState == null ? void 0 : recordingState.trackId) != null ? _a : null;
4098
- useEffect10(() => {
4437
+ useEffect12(() => {
4099
4438
  if (!recordingActive) return void 0;
4100
4439
  setRecordingActive(true, armedTrackId);
4101
4440
  return () => setRecordingActive(false);
@@ -4119,11 +4458,11 @@ var PlaylistVisualization = ({
4119
4458
  });
4120
4459
  return helpers;
4121
4460
  }, [tracks, spectrogram]);
4122
- const [settingsModalTrackId, setSettingsModalTrackId] = useState11(null);
4123
- const [isSelecting, setIsSelecting] = useState11(false);
4124
- const mouseDownTimeRef = useRef14(0);
4125
- const scrollContainerRef = useRef14(null);
4126
- const handleScrollContainerRef = useCallback16(
4461
+ const [settingsModalTrackId, setSettingsModalTrackId] = useState12(null);
4462
+ const [isSelecting, setIsSelecting] = useState12(false);
4463
+ const mouseDownTimeRef = useRef15(0);
4464
+ const scrollContainerRef = useRef15(null);
4465
+ const handleScrollContainerRef = useCallback17(
4127
4466
  (element) => {
4128
4467
  scrollContainerRef.current = element;
4129
4468
  setScrollContainer(element);
@@ -4161,7 +4500,7 @@ var PlaylistVisualization = ({
4161
4500
  );
4162
4501
  }
4163
4502
  });
4164
- const selectTrack = useCallback16(
4503
+ const selectTrack = useCallback17(
4165
4504
  (trackIndex) => {
4166
4505
  if (trackIndex >= 0 && trackIndex < tracks.length) {
4167
4506
  const track = tracks[trackIndex];
@@ -4229,120 +4568,99 @@ var PlaylistVisualization = ({
4229
4568
  setSelection(start, end);
4230
4569
  }
4231
4570
  };
4571
+ const trackHeightById = useMemo5(() => {
4572
+ const m = /* @__PURE__ */ new Map();
4573
+ peaksDataArray.forEach((trackClipPeaks, trackIndex) => {
4574
+ const track = tracks[trackIndex];
4575
+ if (!track) return;
4576
+ const maxChannels = getTrackChannelCount(trackClipPeaks, recordingState, track.id, mono);
4577
+ m.set(track.id, waveHeight * maxChannels + (showClipHeaders ? CLIP_HEADER_HEIGHT : 0));
4578
+ });
4579
+ return m;
4580
+ }, [peaksDataArray, tracks, recordingState, mono, waveHeight, showClipHeaders]);
4581
+ const displayOrderIds = useMemo5(
4582
+ () => applyTrackOrderPreview(tracks, trackDragPreview).map((t) => t.id),
4583
+ [tracks, trackDragPreview]
4584
+ );
4585
+ const trackLayout = useMemo5(
4586
+ () => computeTrackLayout(displayOrderIds, trackHeightById),
4587
+ [displayOrderIds, trackHeightById]
4588
+ );
4589
+ const animateTrackLayout = useTrailingActive(trackDragPreview !== null, 200);
4232
4590
  const hasClips = tracks.some((track) => track.clips.length > 0);
4233
4591
  if (hasClips && peaksDataArray.length === 0) {
4234
- return /* @__PURE__ */ jsx9("div", { className, children: "Loading waveform..." });
4592
+ return /* @__PURE__ */ jsx10("div", { className, children: "Loading waveform..." });
4235
4593
  }
4236
- const trackControlsSlots = controls.show ? peaksDataArray.map((trackClipPeaks, trackIndex) => {
4237
- var _a2, _b2, _c2;
4238
- const track = tracks[trackIndex];
4239
- if (!track) return null;
4240
- const trackState = trackStates[trackIndex] || {
4241
- name: `Track ${trackIndex + 1}`,
4242
- muted: false,
4243
- soloed: false,
4244
- volume: 1,
4245
- pan: 0
4246
- };
4247
- const hasMidiNotes = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
4248
- const effectiveRenderMode = (_c2 = (_b2 = (_a2 = spectrogram == null ? void 0 : spectrogram.trackSpectrogramOverrides.get(track.id)) == null ? void 0 : _a2.renderMode) != null ? _b2 : track.renderMode) != null ? _c2 : hasMidiNotes ? "piano-roll" : "waveform";
4249
- const maxChannels = getTrackChannelCount(trackClipPeaks, recordingState, track.id, mono);
4250
- const slotHeight = waveHeight * maxChannels + (showClipHeaders ? CLIP_HEADER_HEIGHT : 0);
4251
- const trackControlContent = renderTrackControls ? renderTrackControls(trackIndex) : /* @__PURE__ */ jsxs2(Controls, { onClick: () => selectTrack(trackIndex), children: [
4252
- /* @__PURE__ */ jsxs2(Header, { style: { justifyContent: "center", position: "relative" }, children: [
4253
- onRemoveTrack && /* @__PURE__ */ jsx9(
4254
- CloseButton,
4255
- {
4256
- onClick: (e) => {
4257
- e.stopPropagation();
4258
- onRemoveTrack(trackIndex);
4259
- }
4260
- }
4261
- ),
4262
- /* @__PURE__ */ jsx9(
4263
- "span",
4264
- {
4265
- style: {
4266
- overflow: "hidden",
4267
- textOverflow: "ellipsis",
4268
- whiteSpace: "nowrap",
4269
- padding: "0 24px",
4270
- display: "block"
4271
- },
4272
- children: trackState.name || `Track ${trackIndex + 1}`
4273
- }
4274
- ),
4275
- (spectrogram == null ? void 0 : spectrogram.renderMenuItems) && /* @__PURE__ */ jsx9("span", { style: { position: "absolute", right: 0, top: 0 }, children: /* @__PURE__ */ jsx9(
4276
- TrackMenu,
4277
- {
4278
- items: (onClose) => spectrogram.renderMenuItems({
4279
- renderMode: effectiveRenderMode,
4280
- onRenderModeChange: (mode) => spectrogram.setTrackRenderMode(track.id, mode),
4281
- onOpenSettings: () => setSettingsModalTrackId(track.id),
4282
- onClose
4283
- })
4284
- }
4285
- ) })
4286
- ] }),
4287
- /* @__PURE__ */ jsxs2(ButtonGroup, { children: [
4288
- /* @__PURE__ */ jsx9(
4289
- Button,
4290
- {
4291
- $variant: trackState.muted ? "danger" : "outline",
4292
- onClick: () => setTrackMute(trackIndex, !trackState.muted),
4293
- children: "Mute"
4294
- }
4295
- ),
4296
- /* @__PURE__ */ jsx9(
4297
- Button,
4594
+ const trackControlsSlots = controls.show ? [
4595
+ /* @__PURE__ */ jsx10(TracksLayout, { $height: trackLayout.totalHeight, children: peaksDataArray.map((trackClipPeaks, trackIndex) => {
4596
+ var _a2, _b2, _c2, _d2, _e2;
4597
+ const track = tracks[trackIndex];
4598
+ if (!track) return null;
4599
+ const trackState = trackStates[trackIndex] || {
4600
+ name: `Track ${trackIndex + 1}`,
4601
+ muted: false,
4602
+ soloed: false,
4603
+ volume: 1,
4604
+ pan: 0
4605
+ };
4606
+ const hasMidiNotes = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
4607
+ const effectiveRenderMode = (_c2 = (_b2 = (_a2 = spectrogram == null ? void 0 : spectrogram.trackSpectrogramOverrides.get(track.id)) == null ? void 0 : _a2.renderMode) != null ? _b2 : track.renderMode) != null ? _c2 : hasMidiNotes ? "piano-roll" : "waveform";
4608
+ const slotHeight = (_d2 = trackHeightById.get(track.id)) != null ? _d2 : 0;
4609
+ const defaultControlProps = {
4610
+ trackIndex,
4611
+ track,
4612
+ trackState,
4613
+ effectiveRenderMode,
4614
+ selectTrack,
4615
+ onRemoveTrack,
4616
+ setTrackMute,
4617
+ setTrackSolo,
4618
+ setTrackVolume,
4619
+ setTrackPan,
4620
+ spectrogram,
4621
+ setSettingsModalTrackId,
4622
+ trackReordering,
4623
+ reorderTrack,
4624
+ trackCount: peaksDataArray.length
4625
+ };
4626
+ const trackControlContent = renderTrackControls ? renderTrackControls(trackIndex) : trackReordering ? /* @__PURE__ */ jsx10(SortableTrackControls, { trackId: track.id, index: trackIndex, children: ({ ref, handleRef, isDragSource }) => /* @__PURE__ */ jsx10(
4627
+ "div",
4628
+ {
4629
+ ref,
4630
+ style: {
4631
+ height: "100%",
4632
+ boxShadow: isDragSource ? DRAG_SOURCE_SHADOW : void 0,
4633
+ // Opaque background for the floating (top-layer, popover-based)
4634
+ // drag-source row — without it the row underneath shows through.
4635
+ // onDragStart selects the dragged track, so its slot always shows
4636
+ // the selected-track background while lifted.
4637
+ background: isDragSource ? theme.selectedTrackControlsBackground : void 0
4638
+ },
4639
+ children: /* @__PURE__ */ jsx10(DefaultTrackControls, __spreadProps(__spreadValues({}, defaultControlProps), { gripRef: handleRef }))
4640
+ }
4641
+ ) }) : /* @__PURE__ */ jsx10(DefaultTrackControls, __spreadValues({}, defaultControlProps));
4642
+ return (
4643
+ // key includes trackReorderEpoch: forces a remount after every
4644
+ // track-reorder drag, discarding @dnd-kit sortable-plugin DOM
4645
+ // corruption (see bumpTrackReorderEpoch's doc comment in
4646
+ // WaveformPlaylistContext). Stays at `-0` — a no-op suffix — for
4647
+ // consumers that never enable trackReordering.
4648
+ /* @__PURE__ */ jsx10(
4649
+ ControlSlot,
4298
4650
  {
4299
- $variant: trackState.soloed ? "info" : "outline",
4300
- onClick: () => setTrackSolo(trackIndex, !trackState.soloed),
4301
- children: "Solo"
4302
- }
4651
+ $height: slotHeight,
4652
+ $top: (_e2 = trackLayout.topById.get(track.id)) != null ? _e2 : 0,
4653
+ $animate: animateTrackLayout,
4654
+ $isSelected: track.id === selectedTrackId,
4655
+ children: trackControlContent
4656
+ },
4657
+ `${track.id}-${trackReorderEpoch}`
4303
4658
  )
4304
- ] }),
4305
- /* @__PURE__ */ jsxs2(SliderWrapper, { children: [
4306
- /* @__PURE__ */ jsx9(VolumeDownIcon, {}),
4307
- /* @__PURE__ */ jsx9(
4308
- Slider,
4309
- {
4310
- min: "0",
4311
- max: "1",
4312
- step: "0.01",
4313
- value: trackState.volume,
4314
- onChange: (e) => setTrackVolume(trackIndex, parseFloat(e.target.value))
4315
- }
4316
- ),
4317
- /* @__PURE__ */ jsx9(VolumeUpIcon, {})
4318
- ] }),
4319
- /* @__PURE__ */ jsxs2(SliderWrapper, { children: [
4320
- /* @__PURE__ */ jsx9("span", { children: "L" }),
4321
- /* @__PURE__ */ jsx9(
4322
- Slider,
4323
- {
4324
- min: "-1",
4325
- max: "1",
4326
- step: "0.01",
4327
- value: trackState.pan,
4328
- onChange: (e) => setTrackPan(trackIndex, parseFloat(e.target.value))
4329
- }
4330
- ),
4331
- /* @__PURE__ */ jsx9("span", { children: "R" })
4332
- ] })
4333
- ] });
4334
- return /* @__PURE__ */ jsx9(
4335
- ControlSlot,
4336
- {
4337
- $height: slotHeight,
4338
- $isSelected: track.id === selectedTrackId,
4339
- children: trackControlContent
4340
- },
4341
- track.id
4342
- );
4343
- }) : void 0;
4659
+ );
4660
+ }) }, "control-slots-layout")
4661
+ ] : void 0;
4344
4662
  return /* @__PURE__ */ jsxs2(DevicePixelRatioProvider, { children: [
4345
- /* @__PURE__ */ jsx9(
4663
+ /* @__PURE__ */ jsx10(
4346
4664
  PlaylistInfoContext.Provider,
4347
4665
  {
4348
4666
  value: {
@@ -4357,7 +4675,7 @@ var PlaylistVisualization = ({
4357
4675
  barGap,
4358
4676
  roundedBars
4359
4677
  },
4360
- children: /* @__PURE__ */ jsx9(
4678
+ children: /* @__PURE__ */ jsx10(
4361
4679
  Playlist,
4362
4680
  {
4363
4681
  theme,
@@ -4374,9 +4692,9 @@ var PlaylistVisualization = ({
4374
4692
  "data-playlist-state": isReady ? "ready" : "loading",
4375
4693
  trackControlsSlots,
4376
4694
  timescaleGapHeight: timeScaleHeight > 0 ? timeScaleHeight + 1 : 0,
4377
- timescale: timeScaleHeight > 0 ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
4378
- /* @__PURE__ */ jsx9(SmartScale, { renderTick }),
4379
- isLoopEnabled && /* @__PURE__ */ jsx9(
4695
+ timescale: timeScaleHeight > 0 ? /* @__PURE__ */ jsxs2(Fragment3, { children: [
4696
+ /* @__PURE__ */ jsx10(SmartScale, { renderTick }),
4697
+ isLoopEnabled && /* @__PURE__ */ jsx10(
4380
4698
  TimescaleLoopRegion,
4381
4699
  {
4382
4700
  startPosition: Math.min(loopStart, loopEnd) * sampleRate / samplesPerPixel,
@@ -4393,9 +4711,9 @@ var PlaylistVisualization = ({
4393
4711
  }
4394
4712
  )
4395
4713
  ] }) : void 0,
4396
- children: /* @__PURE__ */ jsxs2(Fragment2, { children: [
4397
- peaksDataArray.map((trackClipPeaks, trackIndex) => {
4398
- var _a2, _b2, _c2, _d2;
4714
+ children: /* @__PURE__ */ jsxs2(Fragment3, { children: [
4715
+ /* @__PURE__ */ jsx10(TracksLayout, { $height: trackLayout.totalHeight, children: peaksDataArray.map((trackClipPeaks, trackIndex) => {
4716
+ var _a2, _b2, _c2, _d2, _e2;
4399
4717
  const track = tracks[trackIndex];
4400
4718
  if (!track) return null;
4401
4719
  const hasMidiNotes = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
@@ -4406,153 +4724,163 @@ var PlaylistVisualization = ({
4406
4724
  track.id,
4407
4725
  mono
4408
4726
  );
4409
- return /* @__PURE__ */ jsxs2(
4410
- TrackComponent,
4727
+ return /* @__PURE__ */ jsx10(
4728
+ TrackRowPositioner,
4411
4729
  {
4412
- numChannels: maxChannels,
4413
- backgroundColor: effectiveRenderMode === "piano-roll" ? theme.pianoRollBackgroundColor || "#1a1a2e" : waveformColorToCss2(theme.waveOutlineColor),
4414
- offset: 0,
4415
- width: tracksFullWidth,
4416
- hasClipHeaders: showClipHeaders,
4417
- trackId: track.id,
4418
- isSelected: track.id === selectedTrackId,
4419
- children: [
4420
- effectiveRenderMode !== "waveform" && (() => {
4421
- var _a3, _b3;
4422
- const helpers = perTrackSpectrogramHelpers.get(track.id);
4423
- const trackCfg = helpers == null ? void 0 : helpers.config;
4424
- if (!(trackCfg == null ? void 0 : trackCfg.labels) || !helpers) return null;
4425
- return /* @__PURE__ */ jsx9(
4426
- SpectrogramLabels,
4427
- {
4428
- waveHeight,
4429
- numChannels: maxChannels,
4430
- frequencyScaleFn: helpers.frequencyScaleFn,
4431
- minFrequency: (_a3 = trackCfg.minFrequency) != null ? _a3 : 0,
4432
- maxFrequency: (_b3 = trackCfg.maxFrequency) != null ? _b3 : sampleRate / 2,
4433
- labelsColor: trackCfg.labelsColor,
4434
- labelsBackground: trackCfg.labelsBackground,
4435
- renderMode: effectiveRenderMode,
4436
- hasClipHeaders: showClipHeaders
4437
- }
4438
- );
4439
- })(),
4440
- trackClipPeaks.map((clip, clipIndex) => {
4441
- const peaksData = clip.peaks;
4442
- const width = peaksData.length;
4443
- return /* @__PURE__ */ jsx9(
4444
- Clip,
4445
- {
4446
- clipId: clip.clipId,
4447
- trackIndex,
4448
- clipIndex,
4449
- trackName: clip.trackName,
4450
- startSample: clip.startSample,
4451
- durationSamples: clip.durationSamples,
4452
- samplesPerPixel,
4453
- showHeader: showClipHeaders,
4454
- disableHeaderDrag: !interactiveClips,
4455
- isSelected: track.id === selectedTrackId,
4456
- trackId: track.id,
4457
- fadeIn: clip.fadeIn,
4458
- fadeOut: clip.fadeOut,
4459
- sampleRate,
4460
- showFades,
4461
- touchOptimized,
4462
- onMouseDown: (e) => {
4463
- const target = e.target;
4464
- const isDraggable = target.closest(
4465
- '[role="button"][aria-roledescription="draggable"]'
4466
- );
4467
- if (isDraggable) {
4468
- return;
4730
+ $top: (_d2 = trackLayout.topById.get(track.id)) != null ? _d2 : 0,
4731
+ $animate: animateTrackLayout,
4732
+ "data-track-row": "",
4733
+ "data-track-id": track.id,
4734
+ "data-track-drag-source": (trackDragPreview == null ? void 0 : trackDragPreview.trackId) === track.id ? "true" : void 0,
4735
+ children: /* @__PURE__ */ jsxs2(
4736
+ TrackComponent,
4737
+ {
4738
+ numChannels: maxChannels,
4739
+ backgroundColor: effectiveRenderMode === "piano-roll" ? theme.pianoRollBackgroundColor || "#1a1a2e" : waveformColorToCss2(theme.waveOutlineColor),
4740
+ offset: 0,
4741
+ width: tracksFullWidth,
4742
+ hasClipHeaders: showClipHeaders,
4743
+ trackId: track.id,
4744
+ isSelected: track.id === selectedTrackId,
4745
+ children: [
4746
+ effectiveRenderMode !== "waveform" && (() => {
4747
+ var _a3, _b3;
4748
+ const helpers = perTrackSpectrogramHelpers.get(track.id);
4749
+ const trackCfg = helpers == null ? void 0 : helpers.config;
4750
+ if (!(trackCfg == null ? void 0 : trackCfg.labels) || !helpers) return null;
4751
+ return /* @__PURE__ */ jsx10(
4752
+ SpectrogramLabels,
4753
+ {
4754
+ waveHeight,
4755
+ numChannels: maxChannels,
4756
+ frequencyScaleFn: helpers.frequencyScaleFn,
4757
+ minFrequency: (_a3 = trackCfg.minFrequency) != null ? _a3 : 0,
4758
+ maxFrequency: (_b3 = trackCfg.maxFrequency) != null ? _b3 : sampleRate / 2,
4759
+ labelsColor: trackCfg.labelsColor,
4760
+ labelsBackground: trackCfg.labelsBackground,
4761
+ renderMode: effectiveRenderMode,
4762
+ hasClipHeaders: showClipHeaders
4469
4763
  }
4470
- selectTrack(trackIndex);
4471
- },
4472
- children: peaksData.data.map((channelPeaks, channelIndex) => {
4473
- return /* @__PURE__ */ jsx9(
4474
- ChannelWithProgress,
4475
- {
4476
- index: channelIndex,
4477
- data: channelPeaks,
4478
- bits: peaksData.bits,
4479
- length: width,
4480
- isSelected: track.id === selectedTrackId,
4481
- clipStartSample: clip.startSample,
4482
- clipDurationSamples: clip.durationSamples,
4483
- renderMode: clip.midiNotes ? "piano-roll" : effectiveRenderMode,
4484
- midiNotes: clip.midiNotes,
4485
- clipSampleRate: clip.sampleRate,
4486
- clipOffsetSeconds: clip.offsetSamples != null ? clip.offsetSamples / (clip.sampleRate || sampleRate) : 0,
4487
- samplesPerPixel,
4488
- spectrogramClipId: clip.clipId,
4489
- spectrogramOnCanvasRegister: spectrogram ? spectrogram.registerSpectrogramCanvas : void 0,
4490
- spectrogramOnCanvasUnregister: spectrogram ? spectrogram.unregisterSpectrogramCanvas : void 0
4764
+ );
4765
+ })(),
4766
+ trackClipPeaks.map((clip, clipIndex) => {
4767
+ const peaksData = clip.peaks;
4768
+ const width = peaksData.length;
4769
+ return /* @__PURE__ */ jsx10(
4770
+ Clip,
4771
+ {
4772
+ clipId: clip.clipId,
4773
+ trackIndex,
4774
+ clipIndex,
4775
+ trackName: clip.trackName,
4776
+ startSample: clip.startSample,
4777
+ durationSamples: clip.durationSamples,
4778
+ samplesPerPixel,
4779
+ showHeader: showClipHeaders,
4780
+ disableHeaderDrag: !interactiveClips,
4781
+ isSelected: track.id === selectedTrackId,
4782
+ trackId: track.id,
4783
+ fadeIn: clip.fadeIn,
4784
+ fadeOut: clip.fadeOut,
4785
+ sampleRate,
4786
+ showFades,
4787
+ touchOptimized,
4788
+ onMouseDown: (e) => {
4789
+ const target = e.target;
4790
+ const isDraggable = target.closest(
4791
+ '[role="button"][aria-roledescription="draggable"]'
4792
+ );
4793
+ if (isDraggable) {
4794
+ return;
4795
+ }
4796
+ selectTrack(trackIndex);
4491
4797
  },
4492
- `${clip.clipId}-${channelIndex}`
4493
- );
4494
- })
4495
- },
4496
- clip.clipId
4497
- );
4498
- }),
4499
- (recordingState == null ? void 0 : recordingState.isRecording) && recordingState.trackId === track.id && ((_d2 = recordingState.peaks[0]) == null ? void 0 : _d2.length) > 0 && (() => {
4500
- const latencyOffsetSamples = resolveRecordingOffsetSamples({
4501
- overrideSeconds: recordingState.latencyOffset,
4502
- outputLatency: getOutputLatency(),
4503
- lookAhead: getLookAhead(),
4504
- sampleRate
4505
- });
4506
- const latencyPixels = Math.floor(latencyOffsetSamples / samplesPerPixel);
4507
- const skipPeakElements = latencyPixels * 2;
4508
- const previewDuration = Math.max(
4509
- 0,
4510
- recordingState.durationSamples - latencyOffsetSamples
4511
- );
4512
- const previewChannels = (mono ? recordingState.peaks.slice(0, 1) : recordingState.peaks).map(
4513
- (channelPeaks) => skipPeakElements > 0 && skipPeakElements < channelPeaks.length ? channelPeaks.subarray(skipPeakElements) : channelPeaks
4514
- );
4515
- return /* @__PURE__ */ jsx9(
4516
- Clip,
4517
- {
4518
- clipId: "recording-preview",
4519
- trackIndex,
4520
- clipIndex: trackClipPeaks.length,
4521
- trackName: "Recording...",
4522
- startSample: recordingState.startSample,
4523
- durationSamples: previewDuration,
4524
- samplesPerPixel,
4525
- showHeader: showClipHeaders,
4526
- disableHeaderDrag: true,
4527
- isSelected: track.id === selectedTrackId,
4528
- trackId: track.id,
4529
- children: previewChannels.map((channelPeaks, chIdx) => /* @__PURE__ */ jsx9(
4530
- ChannelWithProgress,
4798
+ children: peaksData.data.map((channelPeaks, channelIndex) => {
4799
+ return /* @__PURE__ */ jsx10(
4800
+ ChannelWithProgress,
4801
+ {
4802
+ index: channelIndex,
4803
+ data: channelPeaks,
4804
+ bits: peaksData.bits,
4805
+ length: width,
4806
+ isSelected: track.id === selectedTrackId,
4807
+ clipStartSample: clip.startSample,
4808
+ clipDurationSamples: clip.durationSamples,
4809
+ renderMode: clip.midiNotes ? "piano-roll" : effectiveRenderMode,
4810
+ midiNotes: clip.midiNotes,
4811
+ clipSampleRate: clip.sampleRate,
4812
+ clipOffsetSeconds: clip.offsetSamples != null ? clip.offsetSamples / (clip.sampleRate || sampleRate) : 0,
4813
+ samplesPerPixel,
4814
+ spectrogramClipId: clip.clipId,
4815
+ spectrogramOnCanvasRegister: spectrogram ? spectrogram.registerSpectrogramCanvas : void 0,
4816
+ spectrogramOnCanvasUnregister: spectrogram ? spectrogram.unregisterSpectrogramCanvas : void 0
4817
+ },
4818
+ `${clip.clipId}-${channelIndex}`
4819
+ );
4820
+ })
4821
+ },
4822
+ clip.clipId
4823
+ );
4824
+ }),
4825
+ (recordingState == null ? void 0 : recordingState.isRecording) && recordingState.trackId === track.id && ((_e2 = recordingState.peaks[0]) == null ? void 0 : _e2.length) > 0 && (() => {
4826
+ const latencyOffsetSamples = resolveRecordingOffsetSamples({
4827
+ overrideSeconds: recordingState.latencyOffset,
4828
+ outputLatency: getOutputLatency(),
4829
+ lookAhead: getLookAhead(),
4830
+ sampleRate
4831
+ });
4832
+ const latencyPixels = Math.floor(latencyOffsetSamples / samplesPerPixel);
4833
+ const skipPeakElements = latencyPixels * 2;
4834
+ const previewDuration = Math.max(
4835
+ 0,
4836
+ recordingState.durationSamples - latencyOffsetSamples
4837
+ );
4838
+ const previewChannels = (mono ? recordingState.peaks.slice(0, 1) : recordingState.peaks).map(
4839
+ (channelPeaks) => skipPeakElements > 0 && skipPeakElements < channelPeaks.length ? channelPeaks.subarray(skipPeakElements) : channelPeaks
4840
+ );
4841
+ return /* @__PURE__ */ jsx10(
4842
+ Clip,
4531
4843
  {
4532
- index: chIdx,
4533
- data: channelPeaks,
4534
- bits: recordingState.bits,
4535
- length: Math.floor(channelPeaks.length / 2),
4844
+ clipId: "recording-preview",
4845
+ trackIndex,
4846
+ clipIndex: trackClipPeaks.length,
4847
+ trackName: "Recording...",
4848
+ startSample: recordingState.startSample,
4849
+ durationSamples: previewDuration,
4850
+ samplesPerPixel,
4851
+ showHeader: showClipHeaders,
4852
+ disableHeaderDrag: true,
4536
4853
  isSelected: track.id === selectedTrackId,
4537
- clipStartSample: recordingState.startSample,
4538
- clipDurationSamples: previewDuration
4854
+ trackId: track.id,
4855
+ children: previewChannels.map((channelPeaks, chIdx) => /* @__PURE__ */ jsx10(
4856
+ ChannelWithProgress,
4857
+ {
4858
+ index: chIdx,
4859
+ data: channelPeaks,
4860
+ bits: recordingState.bits,
4861
+ length: Math.floor(channelPeaks.length / 2),
4862
+ isSelected: track.id === selectedTrackId,
4863
+ clipStartSample: recordingState.startSample,
4864
+ clipDurationSamples: previewDuration
4865
+ },
4866
+ `${track.id}-recording-${chIdx}`
4867
+ ))
4539
4868
  },
4540
- `${track.id}-recording-${chIdx}`
4541
- ))
4542
- },
4543
- `${track.id}-recording`
4544
- );
4545
- })()
4546
- ]
4869
+ `${track.id}-recording`
4870
+ );
4871
+ })()
4872
+ ]
4873
+ }
4874
+ )
4547
4875
  },
4548
4876
  track.id
4549
4877
  );
4550
- }),
4551
- annotations.length > 0 && annotationIntegration && /* @__PURE__ */ jsx9(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
4878
+ }) }),
4879
+ annotations.length > 0 && annotationIntegration && /* @__PURE__ */ jsx10(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
4552
4880
  const startPosition = annotation.start * sampleRate / samplesPerPixel;
4553
4881
  const endPosition = annotation.end * sampleRate / samplesPerPixel;
4554
4882
  const label = getAnnotationBoxLabel ? getAnnotationBoxLabel(annotation, index) : annotation.id;
4555
- return /* @__PURE__ */ jsx9(
4883
+ return /* @__PURE__ */ jsx10(
4556
4884
  annotationIntegration.AnnotationBox,
4557
4885
  {
4558
4886
  annotationId: annotation.id,
@@ -4568,7 +4896,7 @@ var PlaylistVisualization = ({
4568
4896
  annotation.id
4569
4897
  );
4570
4898
  }) }),
4571
- selectionStart !== selectionEnd && /* @__PURE__ */ jsx9(
4899
+ selectionStart !== selectionEnd && /* @__PURE__ */ jsx10(
4572
4900
  Selection,
4573
4901
  {
4574
4902
  startPosition: Math.min(selectionStart, selectionEnd) * sampleRate / samplesPerPixel,
@@ -4576,7 +4904,7 @@ var PlaylistVisualization = ({
4576
4904
  color: theme.selectionColor
4577
4905
  }
4578
4906
  ),
4579
- (isPlaying || selectionStart === selectionEnd) && (renderPlayhead ? /* @__PURE__ */ jsx9(
4907
+ (isPlaying || selectionStart === selectionEnd) && (renderPlayhead ? /* @__PURE__ */ jsx10(
4580
4908
  CustomPlayhead,
4581
4909
  {
4582
4910
  renderPlayhead,
@@ -4584,14 +4912,14 @@ var PlaylistVisualization = ({
4584
4912
  samplesPerPixel,
4585
4913
  sampleRate
4586
4914
  }
4587
- ) : /* @__PURE__ */ jsx9(AnimatedPlayhead, { color: theme.playheadColor }))
4915
+ ) : /* @__PURE__ */ jsx10(AnimatedPlayhead, { color: theme.playheadColor }))
4588
4916
  ] })
4589
4917
  }
4590
4918
  )
4591
4919
  }
4592
4920
  ),
4593
4921
  (spectrogram == null ? void 0 : spectrogram.SettingsModal) && typeof document !== "undefined" && createPortal(
4594
- /* @__PURE__ */ jsx9(
4922
+ /* @__PURE__ */ jsx10(
4595
4923
  spectrogram.SettingsModal,
4596
4924
  {
4597
4925
  open: settingsModalTrackId !== null,
@@ -4611,8 +4939,8 @@ var PlaylistVisualization = ({
4611
4939
  };
4612
4940
 
4613
4941
  // src/components/PlaylistAnnotationList.tsx
4614
- import { useCallback as useCallback17 } from "react";
4615
- import { jsx as jsx10 } from "react/jsx-runtime";
4942
+ import { useCallback as useCallback18 } from "react";
4943
+ import { jsx as jsx11 } from "react/jsx-runtime";
4616
4944
  var PlaylistAnnotationList = ({
4617
4945
  height,
4618
4946
  renderAnnotationItem,
@@ -4626,7 +4954,7 @@ var PlaylistAnnotationList = ({
4626
4954
  const integration = useAnnotationIntegration();
4627
4955
  const { setAnnotations } = usePlaylistControls();
4628
4956
  const resolvedConfig = annotationListConfig != null ? annotationListConfig : { linkEndpoints, continuousPlay };
4629
- const handleAnnotationUpdate = useCallback17(
4957
+ const handleAnnotationUpdate = useCallback18(
4630
4958
  (updatedAnnotations) => {
4631
4959
  setAnnotations(updatedAnnotations);
4632
4960
  onAnnotationUpdate == null ? void 0 : onAnnotationUpdate(updatedAnnotations);
@@ -4634,7 +4962,7 @@ var PlaylistAnnotationList = ({
4634
4962
  [setAnnotations, onAnnotationUpdate]
4635
4963
  );
4636
4964
  const { AnnotationText } = integration;
4637
- return /* @__PURE__ */ jsx10(
4965
+ return /* @__PURE__ */ jsx11(
4638
4966
  AnnotationText,
4639
4967
  {
4640
4968
  annotations,
@@ -4653,7 +4981,7 @@ var PlaylistAnnotationList = ({
4653
4981
  };
4654
4982
 
4655
4983
  // src/components/Waveform.tsx
4656
- import { Fragment as Fragment3, jsx as jsx11, jsxs as jsxs3 } from "react/jsx-runtime";
4984
+ import { Fragment as Fragment4, jsx as jsx12, jsxs as jsxs3 } from "react/jsx-runtime";
4657
4985
  var Waveform = ({
4658
4986
  renderTrackControls,
4659
4987
  renderTick,
@@ -4672,13 +5000,14 @@ var Waveform = ({
4672
5000
  showFades = false,
4673
5001
  touchOptimized = false,
4674
5002
  onRemoveTrack,
5003
+ trackReordering = false,
4675
5004
  recordingState
4676
5005
  }) => {
4677
5006
  const { annotations } = usePlaylistState();
4678
5007
  const clipInteractionEnabled = useClipInteractionEnabled();
4679
5008
  const effectiveInteractiveClips = interactiveClips || clipInteractionEnabled;
4680
- return /* @__PURE__ */ jsxs3(Fragment3, { children: [
4681
- /* @__PURE__ */ jsx11(
5009
+ return /* @__PURE__ */ jsxs3(Fragment4, { children: [
5010
+ /* @__PURE__ */ jsx12(
4682
5011
  PlaylistVisualization,
4683
5012
  {
4684
5013
  renderTrackControls,
@@ -4692,10 +5021,11 @@ var Waveform = ({
4692
5021
  showFades,
4693
5022
  touchOptimized,
4694
5023
  onRemoveTrack,
5024
+ trackReordering,
4695
5025
  recordingState
4696
5026
  }
4697
5027
  ),
4698
- annotations.length > 0 && /* @__PURE__ */ jsx11(
5028
+ annotations.length > 0 && /* @__PURE__ */ jsx12(
4699
5029
  PlaylistAnnotationList,
4700
5030
  {
4701
5031
  height: annotationTextHeight,
@@ -4710,7 +5040,7 @@ var Waveform = ({
4710
5040
  };
4711
5041
 
4712
5042
  // src/components/MediaElementPlaylist.tsx
4713
- import { useContext as useContext7, useRef as useRef17, useState as useState12, useCallback as useCallback18 } from "react";
5043
+ import { useContext as useContext7, useRef as useRef18, useState as useState13, useCallback as useCallback19 } from "react";
4714
5044
  import { DragDropProvider } from "@dnd-kit/react";
4715
5045
  import { RestrictToHorizontalAxis } from "@dnd-kit/abstract/modifiers";
4716
5046
  import {
@@ -4726,29 +5056,10 @@ import {
4726
5056
  waveformColorToCss as waveformColorToCss4
4727
5057
  } from "@waveform-playlist/ui-components";
4728
5058
 
4729
- // src/plugins/noDropAnimationPlugins.ts
4730
- import { Feedback } from "@dnd-kit/dom";
4731
- var noDropAnimationPlugins = (defaults) => {
4732
- let feedbackFound = false;
4733
- const result = defaults.map((p) => {
4734
- if (p === Feedback) {
4735
- feedbackFound = true;
4736
- return Feedback.configure({ dropAnimation: null });
4737
- }
4738
- return p;
4739
- });
4740
- if (!feedbackFound) {
4741
- console.warn(
4742
- "[waveform-playlist] noDropAnimationPlugins: Feedback plugin not found in defaults \u2014 drop animation may not be disabled. Check @dnd-kit/dom version."
4743
- );
4744
- }
4745
- return result;
4746
- };
4747
-
4748
5059
  // src/components/AnimatedMediaElementPlayhead.tsx
4749
- import { useRef as useRef15, useEffect as useEffect11 } from "react";
5060
+ import { useRef as useRef16, useEffect as useEffect13 } from "react";
4750
5061
  import styled5 from "styled-components";
4751
- import { jsx as jsx12 } from "react/jsx-runtime";
5062
+ import { jsx as jsx13 } from "react/jsx-runtime";
4752
5063
  var PlayheadLine2 = styled5.div`
4753
5064
  position: absolute;
4754
5065
  top: 0;
@@ -4763,11 +5074,11 @@ var PlayheadLine2 = styled5.div`
4763
5074
  var AnimatedMediaElementPlayhead = ({
4764
5075
  color = "#ff0000"
4765
5076
  }) => {
4766
- const playheadRef = useRef15(null);
4767
- const animationFrameRef = useRef15(null);
5077
+ const playheadRef = useRef16(null);
5078
+ const animationFrameRef = useRef16(null);
4768
5079
  const { isPlaying, currentTimeRef } = useMediaElementAnimation();
4769
5080
  const { samplesPerPixel, sampleRate, progressBarWidth } = useMediaElementData();
4770
- useEffect11(() => {
5081
+ useEffect13(() => {
4771
5082
  const updatePosition = () => {
4772
5083
  var _a;
4773
5084
  if (playheadRef.current) {
@@ -4791,7 +5102,7 @@ var AnimatedMediaElementPlayhead = ({
4791
5102
  }
4792
5103
  };
4793
5104
  }, [isPlaying, sampleRate, samplesPerPixel, currentTimeRef]);
4794
- useEffect11(() => {
5105
+ useEffect13(() => {
4795
5106
  var _a;
4796
5107
  if (!isPlaying && playheadRef.current) {
4797
5108
  const time = (_a = currentTimeRef.current) != null ? _a : 0;
@@ -4799,11 +5110,11 @@ var AnimatedMediaElementPlayhead = ({
4799
5110
  playheadRef.current.style.transform = `translate3d(${position}px, 0, 0)`;
4800
5111
  }
4801
5112
  });
4802
- return /* @__PURE__ */ jsx12(PlayheadLine2, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
5113
+ return /* @__PURE__ */ jsx13(PlayheadLine2, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
4803
5114
  };
4804
5115
 
4805
5116
  // src/components/ChannelWithMediaElementProgress.tsx
4806
- import { useRef as useRef16, useEffect as useEffect12 } from "react";
5117
+ import { useRef as useRef17, useEffect as useEffect14 } from "react";
4807
5118
  import styled6 from "styled-components";
4808
5119
  import {
4809
5120
  SmartChannel as SmartChannel2,
@@ -4811,7 +5122,7 @@ import {
4811
5122
  usePlaylistInfo as usePlaylistInfo2,
4812
5123
  waveformColorToCss as waveformColorToCss3
4813
5124
  } from "@waveform-playlist/ui-components";
4814
- import { jsx as jsx13, jsxs as jsxs4 } from "react/jsx-runtime";
5125
+ import { jsx as jsx14, jsxs as jsxs4 } from "react/jsx-runtime";
4815
5126
  var ChannelWrapper2 = styled6.div`
4816
5127
  position: relative;
4817
5128
  `;
@@ -4848,14 +5159,14 @@ var ChannelWithMediaElementProgress = (_a) => {
4848
5159
  "clipStartSample",
4849
5160
  "clipDurationSamples"
4850
5161
  ]);
4851
- const progressRef = useRef16(null);
4852
- const animationFrameRef = useRef16(null);
5162
+ const progressRef = useRef17(null);
5163
+ const animationFrameRef = useRef17(null);
4853
5164
  const theme = useTheme3();
4854
5165
  const { waveHeight } = usePlaylistInfo2();
4855
5166
  const { isPlaying, currentTimeRef } = useMediaElementAnimation();
4856
5167
  const { samplesPerPixel, sampleRate } = useMediaElementData();
4857
5168
  const progressColor = (theme == null ? void 0 : theme.waveProgressColor) || "rgba(0, 0, 0, 0.1)";
4858
- useEffect12(() => {
5169
+ useEffect14(() => {
4859
5170
  const updateProgress = () => {
4860
5171
  var _a2;
4861
5172
  if (progressRef.current) {
@@ -4897,7 +5208,7 @@ var ChannelWithMediaElementProgress = (_a) => {
4897
5208
  smartChannelProps.length,
4898
5209
  currentTimeRef
4899
5210
  ]);
4900
- useEffect12(() => {
5211
+ useEffect14(() => {
4901
5212
  var _a2;
4902
5213
  if (!isPlaying && progressRef.current) {
4903
5214
  const currentTime = (_a2 = currentTimeRef.current) != null ? _a2 : 0;
@@ -4924,7 +5235,7 @@ var ChannelWithMediaElementProgress = (_a) => {
4924
5235
  }
4925
5236
  const backgroundCss = waveformColorToCss3(backgroundColor);
4926
5237
  return /* @__PURE__ */ jsxs4(ChannelWrapper2, { children: [
4927
- /* @__PURE__ */ jsx13(
5238
+ /* @__PURE__ */ jsx14(
4928
5239
  Background2,
4929
5240
  {
4930
5241
  $color: backgroundCss,
@@ -4933,7 +5244,7 @@ var ChannelWithMediaElementProgress = (_a) => {
4933
5244
  $width: smartChannelProps.length
4934
5245
  }
4935
5246
  ),
4936
- /* @__PURE__ */ jsx13(
5247
+ /* @__PURE__ */ jsx14(
4937
5248
  ProgressOverlay2,
4938
5249
  {
4939
5250
  ref: progressRef,
@@ -4942,12 +5253,12 @@ var ChannelWithMediaElementProgress = (_a) => {
4942
5253
  $top: smartChannelProps.index * waveHeight
4943
5254
  }
4944
5255
  ),
4945
- /* @__PURE__ */ jsx13(ChannelContainer2, { children: /* @__PURE__ */ jsx13(SmartChannel2, __spreadProps(__spreadValues({}, smartChannelProps), { isSelected: true, transparentBackground: true })) })
5256
+ /* @__PURE__ */ jsx14(ChannelContainer2, { children: /* @__PURE__ */ jsx14(SmartChannel2, __spreadProps(__spreadValues({}, smartChannelProps), { isSelected: true, transparentBackground: true })) })
4946
5257
  ] });
4947
5258
  };
4948
5259
 
4949
5260
  // src/components/MediaElementPlaylist.tsx
4950
- import { Fragment as Fragment4, jsx as jsx14, jsxs as jsxs5 } from "react/jsx-runtime";
5261
+ import { Fragment as Fragment5, jsx as jsx15, jsxs as jsxs5 } from "react/jsx-runtime";
4951
5262
  var ZERO_REF = { current: 0 };
4952
5263
  var CustomMediaElementPlayhead = ({ renderPlayhead, color, samplesPerPixel, sampleRate }) => {
4953
5264
  var _a;
@@ -4993,11 +5304,11 @@ var MediaElementPlaylist = ({
4993
5304
  fadeIn,
4994
5305
  fadeOut
4995
5306
  } = useMediaElementData();
4996
- const [selectionStart, setSelectionStart] = useState12(0);
4997
- const [selectionEnd, setSelectionEnd] = useState12(0);
4998
- const [isSelecting, setIsSelecting] = useState12(false);
4999
- const scrollContainerRef = useRef17(null);
5000
- const handleScrollContainerRef = useCallback18(
5307
+ const [selectionStart, setSelectionStart] = useState13(0);
5308
+ const [selectionEnd, setSelectionEnd] = useState13(0);
5309
+ const [isSelecting, setIsSelecting] = useState13(false);
5310
+ const scrollContainerRef = useRef18(null);
5311
+ const handleScrollContainerRef = useCallback19(
5001
5312
  (el) => {
5002
5313
  scrollContainerRef.current = el;
5003
5314
  setScrollContainer(el);
@@ -5005,7 +5316,7 @@ var MediaElementPlaylist = ({
5005
5316
  [setScrollContainer]
5006
5317
  );
5007
5318
  const tracksFullWidth = Math.floor(duration * sampleRate / samplesPerPixel);
5008
- const handleAnnotationClick = useCallback18(
5319
+ const handleAnnotationClick = useCallback19(
5009
5320
  (annotation) => __async(null, null, function* () {
5010
5321
  setActiveAnnotationId(annotation.id);
5011
5322
  try {
@@ -5020,7 +5331,7 @@ var MediaElementPlaylist = ({
5020
5331
  }),
5021
5332
  [setActiveAnnotationId, play]
5022
5333
  );
5023
- const handleAnnotationUpdate = useCallback18(
5334
+ const handleAnnotationUpdate = useCallback19(
5024
5335
  (updatedAnnotations) => {
5025
5336
  setAnnotations(updatedAnnotations);
5026
5337
  onAnnotationUpdate == null ? void 0 : onAnnotationUpdate(updatedAnnotations);
@@ -5034,8 +5345,8 @@ var MediaElementPlaylist = ({
5034
5345
  duration,
5035
5346
  linkEndpoints: linkEndpointsProp
5036
5347
  });
5037
- const mouseDownTimeRef = useRef17(0);
5038
- const handleMouseDown = useCallback18(
5348
+ const mouseDownTimeRef = useRef18(0);
5349
+ const handleMouseDown = useCallback19(
5039
5350
  (e) => {
5040
5351
  const rect = e.currentTarget.getBoundingClientRect();
5041
5352
  const x = e.clientX - rect.left;
@@ -5047,7 +5358,7 @@ var MediaElementPlaylist = ({
5047
5358
  },
5048
5359
  [samplesPerPixel, sampleRate]
5049
5360
  );
5050
- const handleMouseMove = useCallback18(
5361
+ const handleMouseMove = useCallback19(
5051
5362
  (e) => {
5052
5363
  if (!isSelecting) return;
5053
5364
  const rect = e.currentTarget.getBoundingClientRect();
@@ -5057,7 +5368,7 @@ var MediaElementPlaylist = ({
5057
5368
  },
5058
5369
  [isSelecting, samplesPerPixel, sampleRate]
5059
5370
  );
5060
- const handleMouseUp = useCallback18(
5371
+ const handleMouseUp = useCallback19(
5061
5372
  (e) => {
5062
5373
  if (!isSelecting) return;
5063
5374
  setIsSelecting(false);
@@ -5087,9 +5398,9 @@ var MediaElementPlaylist = ({
5087
5398
  [isSelecting, selectionStart, samplesPerPixel, sampleRate, seekTo, isPlaying, playoutRef, play]
5088
5399
  );
5089
5400
  if (peaksDataArray.length === 0) {
5090
- return /* @__PURE__ */ jsx14("div", { className, children: "Loading waveform..." });
5401
+ return /* @__PURE__ */ jsx15("div", { className, children: "Loading waveform..." });
5091
5402
  }
5092
- return /* @__PURE__ */ jsx14(DevicePixelRatioProvider2, { children: /* @__PURE__ */ jsx14(
5403
+ return /* @__PURE__ */ jsx15(DevicePixelRatioProvider2, { children: /* @__PURE__ */ jsx15(
5093
5404
  PlaylistInfoContext2.Provider,
5094
5405
  {
5095
5406
  value: {
@@ -5104,7 +5415,7 @@ var MediaElementPlaylist = ({
5104
5415
  barGap,
5105
5416
  roundedBars
5106
5417
  },
5107
- children: /* @__PURE__ */ jsx14(
5418
+ children: /* @__PURE__ */ jsx15(
5108
5419
  Playlist2,
5109
5420
  {
5110
5421
  theme,
@@ -5118,11 +5429,11 @@ var MediaElementPlaylist = ({
5118
5429
  onTracksMouseUp: handleMouseUp,
5119
5430
  scrollContainerRef: handleScrollContainerRef,
5120
5431
  isSelecting,
5121
- timescale: timeScaleHeight > 0 ? /* @__PURE__ */ jsx14(SmartScale2, {}) : void 0,
5122
- children: /* @__PURE__ */ jsxs5(Fragment4, { children: [
5432
+ timescale: timeScaleHeight > 0 ? /* @__PURE__ */ jsx15(SmartScale2, {}) : void 0,
5433
+ children: /* @__PURE__ */ jsxs5(Fragment5, { children: [
5123
5434
  peaksDataArray.map((trackClipPeaks, trackIndex) => {
5124
5435
  const maxChannels = trackClipPeaks.length > 0 ? Math.max(...trackClipPeaks.map((clip) => clip.peaks.data.length)) : 1;
5125
- return /* @__PURE__ */ jsx14(
5436
+ return /* @__PURE__ */ jsx15(
5126
5437
  TrackComponent2,
5127
5438
  {
5128
5439
  numChannels: maxChannels,
@@ -5150,7 +5461,7 @@ var MediaElementPlaylist = ({
5150
5461
  isSelected: true,
5151
5462
  trackId: `media-element-track-${trackIndex}`,
5152
5463
  children: [
5153
- peaksData.data.map((channelPeaks, channelIndex) => /* @__PURE__ */ jsx14(
5464
+ peaksData.data.map((channelPeaks, channelIndex) => /* @__PURE__ */ jsx15(
5154
5465
  ChannelWithMediaElementProgress,
5155
5466
  {
5156
5467
  index: channelIndex,
@@ -5162,7 +5473,7 @@ var MediaElementPlaylist = ({
5162
5473
  },
5163
5474
  `${trackIndex}-${clipIndex}-${channelIndex}`
5164
5475
  )),
5165
- showFades && fadeIn && fadeIn.duration > 0 && /* @__PURE__ */ jsx14(
5476
+ showFades && fadeIn && fadeIn.duration > 0 && /* @__PURE__ */ jsx15(
5166
5477
  FadeOverlay,
5167
5478
  {
5168
5479
  left: 0,
@@ -5171,7 +5482,7 @@ var MediaElementPlaylist = ({
5171
5482
  curveType: fadeIn.type
5172
5483
  }
5173
5484
  ),
5174
- showFades && fadeOut && fadeOut.duration > 0 && /* @__PURE__ */ jsx14(
5485
+ showFades && fadeOut && fadeOut.duration > 0 && /* @__PURE__ */ jsx15(
5175
5486
  FadeOverlay,
5176
5487
  {
5177
5488
  left: width - Math.floor(fadeOut.duration * sampleRate / samplesPerPixel),
@@ -5189,19 +5500,18 @@ var MediaElementPlaylist = ({
5189
5500
  trackIndex
5190
5501
  );
5191
5502
  }),
5192
- annotations.length > 0 && annotationIntegration && /* @__PURE__ */ jsx14(
5503
+ annotations.length > 0 && annotationIntegration && /* @__PURE__ */ jsx15(
5193
5504
  DragDropProvider,
5194
5505
  {
5195
5506
  onDragStart,
5196
5507
  onDragMove,
5197
5508
  onDragEnd,
5198
5509
  modifiers: editable ? [RestrictToHorizontalAxis] : [],
5199
- plugins: noDropAnimationPlugins,
5200
- children: /* @__PURE__ */ jsx14(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
5510
+ children: /* @__PURE__ */ jsx15(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
5201
5511
  const startPosition = annotation.start * sampleRate / samplesPerPixel;
5202
5512
  const endPosition = annotation.end * sampleRate / samplesPerPixel;
5203
5513
  const label = getAnnotationBoxLabel ? getAnnotationBoxLabel(annotation, index) : annotation.id;
5204
- return /* @__PURE__ */ jsx14(
5514
+ return /* @__PURE__ */ jsx15(
5205
5515
  annotationIntegration.AnnotationBox,
5206
5516
  {
5207
5517
  annotationId: annotation.id,
@@ -5219,7 +5529,7 @@ var MediaElementPlaylist = ({
5219
5529
  }) })
5220
5530
  }
5221
5531
  ),
5222
- selectionStart !== selectionEnd && /* @__PURE__ */ jsx14(
5532
+ selectionStart !== selectionEnd && /* @__PURE__ */ jsx15(
5223
5533
  Selection2,
5224
5534
  {
5225
5535
  startPosition: Math.min(selectionStart, selectionEnd) * sampleRate / samplesPerPixel,
@@ -5227,7 +5537,7 @@ var MediaElementPlaylist = ({
5227
5537
  color: theme.selectionColor
5228
5538
  }
5229
5539
  ),
5230
- renderPlayhead ? /* @__PURE__ */ jsx14(
5540
+ renderPlayhead ? /* @__PURE__ */ jsx15(
5231
5541
  CustomMediaElementPlayhead,
5232
5542
  {
5233
5543
  renderPlayhead,
@@ -5235,7 +5545,7 @@ var MediaElementPlaylist = ({
5235
5545
  samplesPerPixel,
5236
5546
  sampleRate
5237
5547
  }
5238
- ) : /* @__PURE__ */ jsx14(AnimatedMediaElementPlayhead, { color: theme.playheadColor })
5548
+ ) : /* @__PURE__ */ jsx15(AnimatedMediaElementPlayhead, { color: theme.playheadColor })
5239
5549
  ] })
5240
5550
  }
5241
5551
  )
@@ -5244,8 +5554,8 @@ var MediaElementPlaylist = ({
5244
5554
  };
5245
5555
 
5246
5556
  // src/components/MediaElementAnnotationList.tsx
5247
- import { useCallback as useCallback19 } from "react";
5248
- import { jsx as jsx15 } from "react/jsx-runtime";
5557
+ import { useCallback as useCallback20 } from "react";
5558
+ import { jsx as jsx16 } from "react/jsx-runtime";
5249
5559
  var MediaElementAnnotationList = ({
5250
5560
  height,
5251
5561
  renderAnnotationItem,
@@ -5260,7 +5570,7 @@ var MediaElementAnnotationList = ({
5260
5570
  const integration = useAnnotationIntegration();
5261
5571
  const { setAnnotations } = useMediaElementControls();
5262
5572
  const resolvedConfig = annotationListConfig != null ? annotationListConfig : { linkEndpoints: false, continuousPlay };
5263
- const handleAnnotationUpdate = useCallback19(
5573
+ const handleAnnotationUpdate = useCallback20(
5264
5574
  (updatedAnnotations) => {
5265
5575
  setAnnotations(updatedAnnotations);
5266
5576
  onAnnotationUpdate == null ? void 0 : onAnnotationUpdate(updatedAnnotations);
@@ -5268,7 +5578,7 @@ var MediaElementAnnotationList = ({
5268
5578
  [setAnnotations, onAnnotationUpdate]
5269
5579
  );
5270
5580
  const { AnnotationText } = integration;
5271
- return /* @__PURE__ */ jsx15(
5581
+ return /* @__PURE__ */ jsx16(
5272
5582
  AnnotationText,
5273
5583
  {
5274
5584
  annotations,
@@ -5287,7 +5597,7 @@ var MediaElementAnnotationList = ({
5287
5597
  };
5288
5598
 
5289
5599
  // src/components/MediaElementWaveform.tsx
5290
- import { Fragment as Fragment5, jsx as jsx16, jsxs as jsxs6 } from "react/jsx-runtime";
5600
+ import { Fragment as Fragment6, jsx as jsx17, jsxs as jsxs6 } from "react/jsx-runtime";
5291
5601
  var MediaElementWaveform = ({
5292
5602
  annotationTextHeight,
5293
5603
  getAnnotationBoxLabel,
@@ -5302,8 +5612,8 @@ var MediaElementWaveform = ({
5302
5612
  className
5303
5613
  }) => {
5304
5614
  const { annotations } = useMediaElementState();
5305
- return /* @__PURE__ */ jsxs6(Fragment5, { children: [
5306
- /* @__PURE__ */ jsx16(
5615
+ return /* @__PURE__ */ jsxs6(Fragment6, { children: [
5616
+ /* @__PURE__ */ jsx17(
5307
5617
  MediaElementPlaylist,
5308
5618
  {
5309
5619
  getAnnotationBoxLabel,
@@ -5315,7 +5625,7 @@ var MediaElementWaveform = ({
5315
5625
  className
5316
5626
  }
5317
5627
  ),
5318
- annotations.length > 0 && /* @__PURE__ */ jsx16(
5628
+ annotations.length > 0 && /* @__PURE__ */ jsx17(
5319
5629
  MediaElementAnnotationList,
5320
5630
  {
5321
5631
  height: annotationTextHeight,
@@ -5390,7 +5700,7 @@ var KeyboardShortcuts = ({
5390
5700
  };
5391
5701
 
5392
5702
  // src/components/ClipInteractionProvider.tsx
5393
- import React16, { useEffect as useEffect13, useMemo as useMemo6 } from "react";
5703
+ import React17, { useEffect as useEffect15, useMemo as useMemo6 } from "react";
5394
5704
  import { DragDropProvider as DragDropProvider2 } from "@dnd-kit/react";
5395
5705
  import { RestrictToHorizontalAxis as RestrictToHorizontalAxis2 } from "@dnd-kit/abstract/modifiers";
5396
5706
  import {
@@ -5480,7 +5790,7 @@ _SnapToGridModifier.configure = configurator2(_SnapToGridModifier);
5480
5790
  var SnapToGridModifier = _SnapToGridModifier;
5481
5791
 
5482
5792
  // src/components/ClipInteractionProvider.tsx
5483
- import { jsx as jsx17 } from "react/jsx-runtime";
5793
+ import { jsx as jsx18 } from "react/jsx-runtime";
5484
5794
  var NOOP_TRACKS_CHANGE = () => {
5485
5795
  };
5486
5796
  var ClipInteractionProvider = ({
@@ -5489,11 +5799,11 @@ var ClipInteractionProvider = ({
5489
5799
  children
5490
5800
  }) => {
5491
5801
  const { tracks, samplesPerPixel, sampleRate, playoutRef, isDraggingRef, onTracksChange } = usePlaylistData();
5492
- const { setSelectedTrackId } = usePlaylistControls();
5802
+ const { setSelectedTrackId, reorderTrack, bumpTrackReorderEpoch, setTrackDragPreview } = usePlaylistControls();
5493
5803
  const beatsAndBars = useBeatsAndBars();
5494
5804
  const useBeatsSnap = snap && beatsAndBars != null && beatsAndBars.scaleMode === "beats" && beatsAndBars.snapTo !== "off";
5495
5805
  const useTimescaleSnap = snap && !useBeatsSnap;
5496
- useEffect13(() => {
5806
+ useEffect15(() => {
5497
5807
  if (onTracksChange == null) {
5498
5808
  console.warn(
5499
5809
  "[waveform-playlist] ClipInteractionProvider: onTracksChange is not set on WaveformPlaylistProvider. Drag and trim edits will not be persisted."
@@ -5529,10 +5839,15 @@ var ClipInteractionProvider = ({
5529
5839
  isDraggingRef,
5530
5840
  snapSamplePosition
5531
5841
  });
5532
- const onDragStart = React16.useCallback(
5842
+ const onDragStart = React17.useCallback(
5533
5843
  (event) => {
5534
- var _a, _b, _c;
5535
- const trackIndex = (_c = (_b = (_a = event.operation) == null ? void 0 : _a.source) == null ? void 0 : _b.data) == null ? void 0 : _c.trackIndex;
5844
+ var _a, _b;
5845
+ const data = (_b = (_a = event.operation) == null ? void 0 : _a.source) == null ? void 0 : _b.data;
5846
+ if ((data == null ? void 0 : data.kind) === "track-reorder") {
5847
+ if (data.trackId) setSelectedTrackId(data.trackId);
5848
+ return;
5849
+ }
5850
+ const trackIndex = data == null ? void 0 : data.trackIndex;
5536
5851
  if (trackIndex !== void 0 && tracks[trackIndex]) {
5537
5852
  setSelectedTrackId(tracks[trackIndex].id);
5538
5853
  }
@@ -5540,6 +5855,39 @@ var ClipInteractionProvider = ({
5540
5855
  },
5541
5856
  [handleDragStart, tracks, setSelectedTrackId]
5542
5857
  );
5858
+ const handleDragOver = React17.useCallback(
5859
+ (event) => {
5860
+ var _a;
5861
+ const data = (_a = event.operation.source) == null ? void 0 : _a.data;
5862
+ if ((data == null ? void 0 : data.kind) !== "track-reorder" || !data.trackId) return;
5863
+ const sortable = event.operation.source.sortable;
5864
+ if (!sortable) return;
5865
+ const trackId = data.trackId;
5866
+ const toIndex = sortable.index;
5867
+ setTrackDragPreview(
5868
+ (prev) => prev && prev.trackId === trackId && prev.toIndex === toIndex ? prev : { trackId, toIndex }
5869
+ );
5870
+ },
5871
+ [setTrackDragPreview]
5872
+ );
5873
+ const handleDragEnd = React17.useCallback(
5874
+ (event) => {
5875
+ var _a;
5876
+ const data = (_a = event.operation.source) == null ? void 0 : _a.data;
5877
+ if ((data == null ? void 0 : data.kind) === "track-reorder") {
5878
+ bumpTrackReorderEpoch();
5879
+ setTrackDragPreview(null);
5880
+ if (event.canceled || !data.trackId) return;
5881
+ const sortable = event.operation.source.sortable;
5882
+ if (sortable && sortable.index !== sortable.initialIndex) {
5883
+ reorderTrack(data.trackId, sortable.index);
5884
+ }
5885
+ return;
5886
+ }
5887
+ onDragEnd(event);
5888
+ },
5889
+ [onDragEnd, reorderTrack, bumpTrackReorderEpoch, setTrackDragPreview]
5890
+ );
5543
5891
  const modifiers = useMemo6(() => {
5544
5892
  const mods = [RestrictToHorizontalAxis2];
5545
5893
  if (useBeatsSnap && beatsAndBars) {
@@ -5565,15 +5913,15 @@ var ClipInteractionProvider = ({
5565
5913
  mods.push(ClipCollisionModifier.configure({ tracks, samplesPerPixel }));
5566
5914
  return mods;
5567
5915
  }, [useBeatsSnap, useTimescaleSnap, beatsAndBars, tracks, samplesPerPixel, sampleRate]);
5568
- return /* @__PURE__ */ jsx17(ClipInteractionContextProvider, { value: true, children: /* @__PURE__ */ jsx17(
5916
+ return /* @__PURE__ */ jsx18(ClipInteractionContextProvider, { value: true, children: /* @__PURE__ */ jsx18(
5569
5917
  DragDropProvider2,
5570
5918
  {
5571
5919
  sensors,
5572
5920
  onDragStart,
5573
5921
  onDragMove,
5574
- onDragEnd,
5922
+ onDragOver: handleDragOver,
5923
+ onDragEnd: handleDragEnd,
5575
5924
  modifiers,
5576
- plugins: noDropAnimationPlugins,
5577
5925
  children
5578
5926
  }
5579
5927
  ) });
@@ -5607,6 +5955,7 @@ export {
5607
5955
  SkipBackwardButton,
5608
5956
  SkipForwardButton,
5609
5957
  SnapToGridModifier,
5958
+ SortableTrackControls,
5610
5959
  SpectrogramIntegrationProvider,
5611
5960
  StopButton,
5612
5961
  TimeFormatSelect,
@@ -5618,7 +5967,6 @@ export {
5618
5967
  getWaveformDataMetadata,
5619
5968
  loadPeaksFromWaveformData,
5620
5969
  loadWaveformData,
5621
- noDropAnimationPlugins,
5622
5970
  useAnnotationDragHandlers,
5623
5971
  useAnnotationIntegration,
5624
5972
  useAnnotationKeyboardControls,