@waveform-playlist/browser 15.3.4 → 15.4.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,146 @@ 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
+
3771
+ // src/utils/dragPopoverHealer.ts
3772
+ function createDragPopoverHealer(element) {
3773
+ if (typeof element.showPopover !== "function") {
3774
+ return () => {
3775
+ };
3776
+ }
3777
+ const heal = () => {
3778
+ if (!element.isConnected || !element.hasAttribute("popover")) return;
3779
+ let open = false;
3780
+ try {
3781
+ open = element.matches(":popover-open");
3782
+ } catch (e) {
3783
+ }
3784
+ if (open) return;
3785
+ try {
3786
+ element.showPopover();
3787
+ } catch (e) {
3788
+ }
3789
+ };
3790
+ const observer = new MutationObserver(heal);
3791
+ observer.observe(element.ownerDocument.body, {
3792
+ childList: true,
3793
+ subtree: true
3794
+ });
3795
+ return () => observer.disconnect();
3796
+ }
3797
+
3798
+ // src/components/SortableTrackControls.tsx
3799
+ import { Fragment, jsx as jsx7 } from "react/jsx-runtime";
3800
+ var SortableTrackControls = ({
3801
+ trackId,
3802
+ index,
3803
+ disabled = false,
3804
+ children
3805
+ }) => {
3806
+ const { ref, handleRef, isDragSource } = useSortable({
3807
+ id: `track-reorder-${trackId}`,
3808
+ index,
3809
+ group: "playlist-tracks",
3810
+ type: "track",
3811
+ accept: ["track"],
3812
+ data: { kind: "track-reorder", trackId },
3813
+ modifiers: [RestrictToVerticalAxis],
3814
+ disabled,
3815
+ // feedback: 'move' (NOT 'none' — see below) disables the Feedback
3816
+ // plugin's placeholder/clone splicing for this sortable while KEEPING its
3817
+ // dragOperation.shape computation alive. That plugin does raw,
3818
+ // React-bypassing DOM surgery on ANY pointer movement during an activated
3819
+ // drag (insertAdjacentElement to splice in a placeholder, then
3820
+ // `placeholder.replaceWith(element)` on drop) — confirmed via
3821
+ // MutationObserver instrumentation to relocate the React-owned row 6
3822
+ // times during a single one-slot drag, leaving its final parent/sibling
3823
+ // different from what React's fiber tree still believes. That desync is
3824
+ // permanent for the session: every later React-driven reorder (button OR
3825
+ // drag) computes the correct data but silently fails to update the DOM
3826
+ // for these rows. The placeholder splice is created only when
3827
+ // `feedback !== 'move'` (@dnd-kit/dom Feedback.ts) — 'move' keeps the
3828
+ // dragged element in the live DOM (no clone/placeholder) while still
3829
+ // running the *unconditional* `dragOperation.shape = ...` assignment.
3830
+ // `feedback: 'none'` looked like the boundary-trim precedent (Clip.tsx /
3831
+ // AnnotationBox.tsx) but is wrong here: 'none' bails out of Feedback's
3832
+ // render function BEFORE dragOperation.shape is ever set, and shape is
3833
+ // the ONLY input CollisionObserver.computeCollisions() checks — with
3834
+ // 'none', collision (and therefore sortable.index) never updates, so
3835
+ // drag-based reordering silently never commits. Boundary trims don't hit
3836
+ // this because they're plain useDraggable (no collision-based commit) —
3837
+ // sortables need shape. `isDragSource` (box-shadow lift feedback below)
3838
+ // is a reactive signal, unaffected either way. See browser/CLAUDE.md
3839
+ // "Track Reordering".
3840
+ feedback: "move"
3841
+ });
3842
+ const elementRef = useRef12(null);
3843
+ const composedRef = useCallback16(
3844
+ (element) => {
3845
+ elementRef.current = element instanceof HTMLElement ? element : null;
3846
+ ref(element);
3847
+ },
3848
+ [ref]
3849
+ );
3850
+ useEffect8(() => {
3851
+ if (!isDragSource || !elementRef.current) return void 0;
3852
+ return createDragPopoverHealer(elementRef.current);
3853
+ }, [isDragSource]);
3854
+ return /* @__PURE__ */ jsx7(Fragment, { children: children({ ref: composedRef, handleRef, isDragSource }) });
3855
+ };
3856
+
3857
+ // src/utils/trackOrderPreview.ts
3858
+ function applyTrackOrderPreview(tracks, preview) {
3859
+ if (!preview) return tracks;
3860
+ const fromIndex = tracks.findIndex((t) => t.id === preview.trackId);
3861
+ if (fromIndex === -1) return tracks;
3862
+ const toIndex = Math.max(0, Math.min(tracks.length - 1, preview.toIndex));
3863
+ if (toIndex === fromIndex) return tracks;
3864
+ const next = tracks.slice();
3865
+ const [moved] = next.splice(fromIndex, 1);
3866
+ next.splice(toIndex, 0, moved);
3867
+ return next;
3868
+ }
3869
+ function computeTrackLayout(orderedIds, heightById) {
3870
+ var _a;
3871
+ const topById = /* @__PURE__ */ new Map();
3872
+ let top = 0;
3873
+ for (const id of orderedIds) {
3874
+ topById.set(id, top);
3875
+ top += (_a = heightById.get(id)) != null ? _a : 0;
3876
+ }
3877
+ return { topById, totalHeight: top };
3878
+ }
3879
+
3880
+ // src/hooks/useTrailingActive.ts
3881
+ import { useEffect as useEffect9, useState as useState11 } from "react";
3882
+ function useTrailingActive(active, trailingMs) {
3883
+ const [trailing, setTrailing] = useState11(active);
3884
+ useEffect9(() => {
3885
+ if (active) {
3886
+ setTrailing(true);
3887
+ return void 0;
3888
+ }
3889
+ const timer = setTimeout(() => setTrailing(false), trailingMs);
3890
+ return () => clearTimeout(timer);
3891
+ }, [active, trailingMs]);
3892
+ return trailing || active;
3893
+ }
3894
+
3895
+ // src/components/PlaylistVisualization.tsx
3724
3896
  import { resolveRecordingOffsetSamples } from "@waveform-playlist/core";
3725
3897
 
3726
3898
  // src/components/AnimatedPlayhead.tsx
3727
- import { useRef as useRef12, useEffect as useEffect8 } from "react";
3899
+ import { useRef as useRef13, useEffect as useEffect10 } from "react";
3728
3900
  import styled2 from "styled-components";
3729
- import { jsx as jsx7 } from "react/jsx-runtime";
3901
+ import { jsx as jsx8 } from "react/jsx-runtime";
3730
3902
  var PlayheadLine = styled2.div.attrs((props) => ({
3731
3903
  style: {
3732
3904
  width: `${props.$width}px`,
@@ -3742,7 +3914,7 @@ var PlayheadLine = styled2.div.attrs((props) => ({
3742
3914
  will-change: transform;
3743
3915
  `;
3744
3916
  var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3745
- const playheadRef = useRef12(null);
3917
+ const playheadRef = useRef13(null);
3746
3918
  const {
3747
3919
  isPlaying,
3748
3920
  currentTimeRef,
@@ -3751,7 +3923,7 @@ var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3751
3923
  unregisterFrameCallback
3752
3924
  } = usePlaybackAnimation();
3753
3925
  const { samplesPerPixel, sampleRate, progressBarWidth } = usePlaylistData();
3754
- useEffect8(() => {
3926
+ useEffect10(() => {
3755
3927
  const id = "playhead";
3756
3928
  if (isPlaying) {
3757
3929
  registerFrameCallback(id, ({ visualTime, sampleRate: sr, samplesPerPixel: spp }) => {
@@ -3763,7 +3935,7 @@ var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3763
3935
  }
3764
3936
  return () => unregisterFrameCallback(id);
3765
3937
  }, [isPlaying, registerFrameCallback, unregisterFrameCallback]);
3766
- useEffect8(() => {
3938
+ useEffect10(() => {
3767
3939
  var _a, _b;
3768
3940
  if (!isPlaying && playheadRef.current) {
3769
3941
  const time = (_b = (_a = visualTimeRef.current) != null ? _a : currentTimeRef.current) != null ? _b : 0;
@@ -3771,11 +3943,11 @@ var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3771
3943
  playheadRef.current.style.transform = `translate3d(${position}px, 0, 0)`;
3772
3944
  }
3773
3945
  });
3774
- return /* @__PURE__ */ jsx7(PlayheadLine, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
3946
+ return /* @__PURE__ */ jsx8(PlayheadLine, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
3775
3947
  };
3776
3948
 
3777
3949
  // src/components/ChannelWithProgress.tsx
3778
- import { useId, useRef as useRef13, useEffect as useEffect9 } from "react";
3950
+ import { useId, useRef as useRef14, useEffect as useEffect11 } from "react";
3779
3951
  import styled3 from "styled-components";
3780
3952
  import {
3781
3953
  clipPixelWidth as computeClipPixelWidth
@@ -3786,7 +3958,7 @@ import {
3786
3958
  usePlaylistInfo,
3787
3959
  waveformColorToCss
3788
3960
  } from "@waveform-playlist/ui-components";
3789
- import { Fragment, jsx as jsx8, jsxs } from "react/jsx-runtime";
3961
+ import { Fragment as Fragment2, jsx as jsx9, jsxs } from "react/jsx-runtime";
3790
3962
  var ChannelWrapper = styled3.div`
3791
3963
  position: relative;
3792
3964
  `;
@@ -3840,7 +4012,7 @@ var ChannelWithProgress = (_a) => {
3840
4012
  "clipSampleRate",
3841
4013
  "clipOffsetSeconds"
3842
4014
  ]);
3843
- const progressRef = useRef13(null);
4015
+ const progressRef = useRef14(null);
3844
4016
  const callbackId = useId();
3845
4017
  const theme = useTheme();
3846
4018
  const { waveHeight } = usePlaylistInfo();
@@ -3858,7 +4030,7 @@ var ChannelWithProgress = (_a) => {
3858
4030
  clipDurationSamples,
3859
4031
  samplesPerPixel
3860
4032
  );
3861
- useEffect9(() => {
4033
+ useEffect11(() => {
3862
4034
  if (isPlaying) {
3863
4035
  registerFrameCallback(callbackId, ({ visualTime, sampleRate: sr }) => {
3864
4036
  if (progressRef.current) {
@@ -3886,7 +4058,7 @@ var ChannelWithProgress = (_a) => {
3886
4058
  registerFrameCallback,
3887
4059
  unregisterFrameCallback
3888
4060
  ]);
3889
- useEffect9(() => {
4061
+ useEffect11(() => {
3890
4062
  var _a2, _b2;
3891
4063
  if (!isPlaying && progressRef.current) {
3892
4064
  const currentTime = (_b2 = (_a2 = visualTimeRef.current) != null ? _a2 : currentTimeRef.current) != null ? _b2 : 0;
@@ -3920,8 +4092,8 @@ var ChannelWithProgress = (_a) => {
3920
4092
  const effectiveTop = isBothMode ? smartChannelProps.index * waveHeight : smartChannelProps.index * waveHeight;
3921
4093
  const waveformBackgroundCss = waveformColorToCss(backgroundColor);
3922
4094
  return /* @__PURE__ */ jsxs(ChannelWrapper, { children: [
3923
- isBothMode ? /* @__PURE__ */ jsxs(Fragment, { children: [
3924
- /* @__PURE__ */ jsx8(
4095
+ isBothMode ? /* @__PURE__ */ jsxs(Fragment2, { children: [
4096
+ /* @__PURE__ */ jsx9(
3925
4097
  Background,
3926
4098
  {
3927
4099
  $color: "#000",
@@ -3930,7 +4102,7 @@ var ChannelWithProgress = (_a) => {
3930
4102
  $width: smartChannelProps.length
3931
4103
  }
3932
4104
  ),
3933
- /* @__PURE__ */ jsx8(
4105
+ /* @__PURE__ */ jsx9(
3934
4106
  Background,
3935
4107
  {
3936
4108
  $color: waveformBackgroundCss,
@@ -3939,7 +4111,7 @@ var ChannelWithProgress = (_a) => {
3939
4111
  $width: smartChannelProps.length
3940
4112
  }
3941
4113
  )
3942
- ] }) : /* @__PURE__ */ jsx8(
4114
+ ] }) : /* @__PURE__ */ jsx9(
3943
4115
  Background,
3944
4116
  {
3945
4117
  $color: backgroundCss,
@@ -3948,7 +4120,7 @@ var ChannelWithProgress = (_a) => {
3948
4120
  $width: smartChannelProps.length
3949
4121
  }
3950
4122
  ),
3951
- !isPianoRollMode && /* @__PURE__ */ jsx8(
4123
+ !isPianoRollMode && /* @__PURE__ */ jsx9(
3952
4124
  ProgressOverlay,
3953
4125
  {
3954
4126
  ref: progressRef,
@@ -3958,7 +4130,7 @@ var ChannelWithProgress = (_a) => {
3958
4130
  $width: clipPixelWidth
3959
4131
  }
3960
4132
  ),
3961
- /* @__PURE__ */ jsx8(ChannelContainer, { children: /* @__PURE__ */ jsx8(
4133
+ /* @__PURE__ */ jsx9(ChannelContainer, { children: /* @__PURE__ */ jsx9(
3962
4134
  SmartChannel,
3963
4135
  __spreadProps(__spreadValues({}, smartChannelProps), {
3964
4136
  transparentBackground: true,
@@ -3985,15 +4157,42 @@ function useSpectrogramIntegration() {
3985
4157
  }
3986
4158
 
3987
4159
  // src/components/PlaylistVisualization.tsx
3988
- import { Fragment as Fragment2, jsx as jsx9, jsxs as jsxs2 } from "react/jsx-runtime";
4160
+ import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs2 } from "react/jsx-runtime";
3989
4161
  var DEFAULT_EMPTY_TRACK_DURATION = 60;
3990
- var ControlSlot = styled4.div.attrs((props) => ({
4162
+ var DRAG_SOURCE_SHADOW = "0 4px 12px rgba(0, 0, 0, 0.35)";
4163
+ var TracksLayout = styled4.div.attrs((props) => ({
3991
4164
  style: { height: `${props.$height}px` }
3992
4165
  }))`
4166
+ position: relative;
4167
+ `;
4168
+ var TrackRowPositioner = styled4.div.attrs((props) => ({
4169
+ style: { top: `${props.$top}px` }
4170
+ }))`
4171
+ position: absolute;
4172
+ left: 0;
4173
+ right: 0;
4174
+ ${(props) => props.$animate && "transition: top 150ms ease;"}
4175
+ @media (prefers-reduced-motion: reduce) {
4176
+ transition: none;
4177
+ }
4178
+ `;
4179
+ var ControlSlot = styled4.div.attrs((props) => ({
4180
+ style: {
4181
+ height: `${props.$height}px`,
4182
+ top: `${props.$top}px`
4183
+ }
4184
+ }))`
4185
+ position: absolute;
4186
+ left: 0;
4187
+ right: 0;
3993
4188
  overflow: hidden;
3994
4189
  pointer-events: auto;
3995
4190
  background: ${(props) => props.theme.surfaceColor};
3996
4191
  transition: background 0.15s ease-in-out;
4192
+ ${(props) => props.$animate && "transition: top 150ms ease, background 0.15s ease-in-out;"}
4193
+ @media (prefers-reduced-motion: reduce) {
4194
+ transition: background 0.15s ease-in-out;
4195
+ }
3997
4196
  ${(props) => props.$isSelected && `background: ${props.theme.selectedTrackControlsBackground};`}
3998
4197
  `;
3999
4198
  var CustomPlayhead = ({ renderPlayhead, color, samplesPerPixel, sampleRate }) => {
@@ -4028,6 +4227,133 @@ function getTrackChannelCount(trackClipPeaks, recordingState, trackId, mono) {
4028
4227
  const recordingChannels = (recordingState == null ? void 0 : recordingState.isRecording) && recordingState.trackId === trackId ? mono ? 1 : recordingState.peaks.length : 0;
4029
4228
  return Math.max(clipChannels, recordingChannels);
4030
4229
  }
4230
+ function DefaultTrackControls({
4231
+ trackIndex,
4232
+ track,
4233
+ trackState,
4234
+ effectiveRenderMode,
4235
+ selectTrack,
4236
+ onRemoveTrack,
4237
+ setTrackMute,
4238
+ setTrackSolo,
4239
+ setTrackVolume,
4240
+ setTrackPan,
4241
+ spectrogram,
4242
+ setSettingsModalTrackId,
4243
+ trackReordering,
4244
+ reorderTrack,
4245
+ trackCount,
4246
+ gripRef
4247
+ }) {
4248
+ return /* @__PURE__ */ jsxs2(
4249
+ Controls,
4250
+ {
4251
+ onClick: () => selectTrack(trackIndex),
4252
+ style: trackReordering ? { position: "relative", paddingLeft: 18, paddingRight: 18 } : void 0,
4253
+ children: [
4254
+ /* @__PURE__ */ jsxs2(Header, { style: { justifyContent: "center", position: "relative" }, children: [
4255
+ onRemoveTrack && /* @__PURE__ */ jsx10(
4256
+ CloseButton,
4257
+ {
4258
+ onClick: (e) => {
4259
+ e.stopPropagation();
4260
+ onRemoveTrack(trackIndex);
4261
+ }
4262
+ }
4263
+ ),
4264
+ /* @__PURE__ */ jsx10(
4265
+ "span",
4266
+ {
4267
+ style: {
4268
+ overflow: "hidden",
4269
+ textOverflow: "ellipsis",
4270
+ whiteSpace: "nowrap",
4271
+ padding: "0 24px",
4272
+ display: "block"
4273
+ },
4274
+ children: trackState.name || `Track ${trackIndex + 1}`
4275
+ }
4276
+ ),
4277
+ (spectrogram == null ? void 0 : spectrogram.renderMenuItems) && /* @__PURE__ */ jsx10("span", { style: { position: "absolute", right: 0, top: 0 }, children: /* @__PURE__ */ jsx10(
4278
+ TrackMenu,
4279
+ {
4280
+ items: (onClose) => spectrogram.renderMenuItems({
4281
+ renderMode: effectiveRenderMode,
4282
+ onRenderModeChange: (mode) => spectrogram.setTrackRenderMode(track.id, mode),
4283
+ onOpenSettings: () => setSettingsModalTrackId(track.id),
4284
+ onClose
4285
+ })
4286
+ }
4287
+ ) })
4288
+ ] }),
4289
+ /* @__PURE__ */ jsxs2(ButtonGroup, { children: [
4290
+ /* @__PURE__ */ jsx10(
4291
+ Button,
4292
+ {
4293
+ $variant: trackState.muted ? "danger" : "outline",
4294
+ onClick: () => setTrackMute(trackIndex, !trackState.muted),
4295
+ children: "Mute"
4296
+ }
4297
+ ),
4298
+ /* @__PURE__ */ jsx10(
4299
+ Button,
4300
+ {
4301
+ $variant: trackState.soloed ? "info" : "outline",
4302
+ onClick: () => setTrackSolo(trackIndex, !trackState.soloed),
4303
+ children: "Solo"
4304
+ }
4305
+ )
4306
+ ] }),
4307
+ /* @__PURE__ */ jsxs2(SliderWrapper, { children: [
4308
+ /* @__PURE__ */ jsx10(VolumeDownIcon, {}),
4309
+ /* @__PURE__ */ jsx10(
4310
+ Slider,
4311
+ {
4312
+ min: "0",
4313
+ max: "1",
4314
+ step: "0.01",
4315
+ value: trackState.volume,
4316
+ onChange: (e) => setTrackVolume(trackIndex, parseFloat(e.target.value))
4317
+ }
4318
+ ),
4319
+ /* @__PURE__ */ jsx10(VolumeUpIcon, {})
4320
+ ] }),
4321
+ /* @__PURE__ */ jsxs2(SliderWrapper, { children: [
4322
+ /* @__PURE__ */ jsx10("span", { children: "L" }),
4323
+ /* @__PURE__ */ jsx10(
4324
+ Slider,
4325
+ {
4326
+ min: "-1",
4327
+ max: "1",
4328
+ step: "0.01",
4329
+ value: trackState.pan,
4330
+ onChange: (e) => setTrackPan(trackIndex, parseFloat(e.target.value))
4331
+ }
4332
+ ),
4333
+ /* @__PURE__ */ jsx10("span", { children: "R" })
4334
+ ] }),
4335
+ trackReordering && /* @__PURE__ */ jsx10(
4336
+ ReorderRail,
4337
+ {
4338
+ style: { position: "absolute", right: 2, top: "50%", transform: "translateY(-50%)" },
4339
+ gripRef,
4340
+ onGripClick: (e) => e.stopPropagation(),
4341
+ upDisabled: trackIndex === 0,
4342
+ downDisabled: trackIndex === trackCount - 1,
4343
+ onMoveUp: (e) => {
4344
+ e.stopPropagation();
4345
+ reorderTrack(track.id, trackIndex - 1);
4346
+ },
4347
+ onMoveDown: (e) => {
4348
+ e.stopPropagation();
4349
+ reorderTrack(track.id, trackIndex + 1);
4350
+ }
4351
+ }
4352
+ )
4353
+ ]
4354
+ }
4355
+ );
4356
+ }
4031
4357
  var PlaylistVisualization = ({
4032
4358
  renderTrackControls,
4033
4359
  renderTick,
@@ -4040,7 +4366,8 @@ var PlaylistVisualization = ({
4040
4366
  showFades = false,
4041
4367
  touchOptimized = false,
4042
4368
  onRemoveTrack,
4043
- recordingState
4369
+ recordingState,
4370
+ trackReordering = false
4044
4371
  }) => {
4045
4372
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
4046
4373
  const theme = useTheme2();
@@ -4074,7 +4401,8 @@ var PlaylistVisualization = ({
4074
4401
  setSelectedTrackId,
4075
4402
  setCurrentTime,
4076
4403
  setLoopRegion,
4077
- setRecordingActive
4404
+ setRecordingActive,
4405
+ reorderTrack
4078
4406
  } = usePlaylistControls();
4079
4407
  const {
4080
4408
  peaksDataArray,
@@ -4090,12 +4418,14 @@ var PlaylistVisualization = ({
4090
4418
  barGap,
4091
4419
  roundedBars,
4092
4420
  isReady,
4093
- mono
4421
+ trackReorderEpoch,
4422
+ mono,
4423
+ trackDragPreview
4094
4424
  } = usePlaylistData();
4095
4425
  const spectrogram = useContext6(SpectrogramIntegrationContext);
4096
4426
  const recordingActive = !!(recordingState == null ? void 0 : recordingState.isRecording);
4097
4427
  const armedTrackId = (_a = recordingState == null ? void 0 : recordingState.trackId) != null ? _a : null;
4098
- useEffect10(() => {
4428
+ useEffect12(() => {
4099
4429
  if (!recordingActive) return void 0;
4100
4430
  setRecordingActive(true, armedTrackId);
4101
4431
  return () => setRecordingActive(false);
@@ -4119,11 +4449,11 @@ var PlaylistVisualization = ({
4119
4449
  });
4120
4450
  return helpers;
4121
4451
  }, [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(
4452
+ const [settingsModalTrackId, setSettingsModalTrackId] = useState12(null);
4453
+ const [isSelecting, setIsSelecting] = useState12(false);
4454
+ const mouseDownTimeRef = useRef15(0);
4455
+ const scrollContainerRef = useRef15(null);
4456
+ const handleScrollContainerRef = useCallback17(
4127
4457
  (element) => {
4128
4458
  scrollContainerRef.current = element;
4129
4459
  setScrollContainer(element);
@@ -4161,7 +4491,7 @@ var PlaylistVisualization = ({
4161
4491
  );
4162
4492
  }
4163
4493
  });
4164
- const selectTrack = useCallback16(
4494
+ const selectTrack = useCallback17(
4165
4495
  (trackIndex) => {
4166
4496
  if (trackIndex >= 0 && trackIndex < tracks.length) {
4167
4497
  const track = tracks[trackIndex];
@@ -4229,120 +4559,99 @@ var PlaylistVisualization = ({
4229
4559
  setSelection(start, end);
4230
4560
  }
4231
4561
  };
4562
+ const trackHeightById = useMemo5(() => {
4563
+ const m = /* @__PURE__ */ new Map();
4564
+ peaksDataArray.forEach((trackClipPeaks, trackIndex) => {
4565
+ const track = tracks[trackIndex];
4566
+ if (!track) return;
4567
+ const maxChannels = getTrackChannelCount(trackClipPeaks, recordingState, track.id, mono);
4568
+ m.set(track.id, waveHeight * maxChannels + (showClipHeaders ? CLIP_HEADER_HEIGHT : 0));
4569
+ });
4570
+ return m;
4571
+ }, [peaksDataArray, tracks, recordingState, mono, waveHeight, showClipHeaders]);
4572
+ const displayOrderIds = useMemo5(
4573
+ () => applyTrackOrderPreview(tracks, trackDragPreview).map((t) => t.id),
4574
+ [tracks, trackDragPreview]
4575
+ );
4576
+ const trackLayout = useMemo5(
4577
+ () => computeTrackLayout(displayOrderIds, trackHeightById),
4578
+ [displayOrderIds, trackHeightById]
4579
+ );
4580
+ const animateTrackLayout = useTrailingActive(trackDragPreview !== null, 200);
4232
4581
  const hasClips = tracks.some((track) => track.clips.length > 0);
4233
4582
  if (hasClips && peaksDataArray.length === 0) {
4234
- return /* @__PURE__ */ jsx9("div", { className, children: "Loading waveform..." });
4583
+ return /* @__PURE__ */ jsx10("div", { className, children: "Loading waveform..." });
4235
4584
  }
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,
4585
+ const trackControlsSlots = controls.show ? [
4586
+ /* @__PURE__ */ jsx10(TracksLayout, { $height: trackLayout.totalHeight, children: peaksDataArray.map((trackClipPeaks, trackIndex) => {
4587
+ var _a2, _b2, _c2, _d2, _e2;
4588
+ const track = tracks[trackIndex];
4589
+ if (!track) return null;
4590
+ const trackState = trackStates[trackIndex] || {
4591
+ name: `Track ${trackIndex + 1}`,
4592
+ muted: false,
4593
+ soloed: false,
4594
+ volume: 1,
4595
+ pan: 0
4596
+ };
4597
+ const hasMidiNotes = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
4598
+ 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";
4599
+ const slotHeight = (_d2 = trackHeightById.get(track.id)) != null ? _d2 : 0;
4600
+ const defaultControlProps = {
4601
+ trackIndex,
4602
+ track,
4603
+ trackState,
4604
+ effectiveRenderMode,
4605
+ selectTrack,
4606
+ onRemoveTrack,
4607
+ setTrackMute,
4608
+ setTrackSolo,
4609
+ setTrackVolume,
4610
+ setTrackPan,
4611
+ spectrogram,
4612
+ setSettingsModalTrackId,
4613
+ trackReordering,
4614
+ reorderTrack,
4615
+ trackCount: peaksDataArray.length
4616
+ };
4617
+ const trackControlContent = renderTrackControls ? renderTrackControls(trackIndex) : trackReordering ? /* @__PURE__ */ jsx10(SortableTrackControls, { trackId: track.id, index: trackIndex, children: ({ ref, handleRef, isDragSource }) => /* @__PURE__ */ jsx10(
4618
+ "div",
4619
+ {
4620
+ ref,
4621
+ style: {
4622
+ height: "100%",
4623
+ boxShadow: isDragSource ? DRAG_SOURCE_SHADOW : void 0,
4624
+ // Opaque background for the floating (top-layer, popover-based)
4625
+ // drag-source row — without it the row underneath shows through.
4626
+ // onDragStart selects the dragged track, so its slot always shows
4627
+ // the selected-track background while lifted.
4628
+ background: isDragSource ? theme.selectedTrackControlsBackground : void 0
4629
+ },
4630
+ children: /* @__PURE__ */ jsx10(DefaultTrackControls, __spreadProps(__spreadValues({}, defaultControlProps), { gripRef: handleRef }))
4631
+ }
4632
+ ) }) : /* @__PURE__ */ jsx10(DefaultTrackControls, __spreadValues({}, defaultControlProps));
4633
+ return (
4634
+ // key includes trackReorderEpoch: forces a remount after every
4635
+ // track-reorder drag, discarding @dnd-kit sortable-plugin DOM
4636
+ // corruption (see bumpTrackReorderEpoch's doc comment in
4637
+ // WaveformPlaylistContext). Stays at `-0` — a no-op suffix — for
4638
+ // consumers that never enable trackReordering.
4639
+ /* @__PURE__ */ jsx10(
4640
+ ControlSlot,
4298
4641
  {
4299
- $variant: trackState.soloed ? "info" : "outline",
4300
- onClick: () => setTrackSolo(trackIndex, !trackState.soloed),
4301
- children: "Solo"
4302
- }
4642
+ $height: slotHeight,
4643
+ $top: (_e2 = trackLayout.topById.get(track.id)) != null ? _e2 : 0,
4644
+ $animate: animateTrackLayout,
4645
+ $isSelected: track.id === selectedTrackId,
4646
+ children: trackControlContent
4647
+ },
4648
+ `${track.id}-${trackReorderEpoch}`
4303
4649
  )
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;
4650
+ );
4651
+ }) }, "control-slots-layout")
4652
+ ] : void 0;
4344
4653
  return /* @__PURE__ */ jsxs2(DevicePixelRatioProvider, { children: [
4345
- /* @__PURE__ */ jsx9(
4654
+ /* @__PURE__ */ jsx10(
4346
4655
  PlaylistInfoContext.Provider,
4347
4656
  {
4348
4657
  value: {
@@ -4357,7 +4666,7 @@ var PlaylistVisualization = ({
4357
4666
  barGap,
4358
4667
  roundedBars
4359
4668
  },
4360
- children: /* @__PURE__ */ jsx9(
4669
+ children: /* @__PURE__ */ jsx10(
4361
4670
  Playlist,
4362
4671
  {
4363
4672
  theme,
@@ -4374,9 +4683,9 @@ var PlaylistVisualization = ({
4374
4683
  "data-playlist-state": isReady ? "ready" : "loading",
4375
4684
  trackControlsSlots,
4376
4685
  timescaleGapHeight: timeScaleHeight > 0 ? timeScaleHeight + 1 : 0,
4377
- timescale: timeScaleHeight > 0 ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
4378
- /* @__PURE__ */ jsx9(SmartScale, { renderTick }),
4379
- isLoopEnabled && /* @__PURE__ */ jsx9(
4686
+ timescale: timeScaleHeight > 0 ? /* @__PURE__ */ jsxs2(Fragment3, { children: [
4687
+ /* @__PURE__ */ jsx10(SmartScale, { renderTick }),
4688
+ isLoopEnabled && /* @__PURE__ */ jsx10(
4380
4689
  TimescaleLoopRegion,
4381
4690
  {
4382
4691
  startPosition: Math.min(loopStart, loopEnd) * sampleRate / samplesPerPixel,
@@ -4393,9 +4702,9 @@ var PlaylistVisualization = ({
4393
4702
  }
4394
4703
  )
4395
4704
  ] }) : void 0,
4396
- children: /* @__PURE__ */ jsxs2(Fragment2, { children: [
4397
- peaksDataArray.map((trackClipPeaks, trackIndex) => {
4398
- var _a2, _b2, _c2, _d2;
4705
+ children: /* @__PURE__ */ jsxs2(Fragment3, { children: [
4706
+ /* @__PURE__ */ jsx10(TracksLayout, { $height: trackLayout.totalHeight, children: peaksDataArray.map((trackClipPeaks, trackIndex) => {
4707
+ var _a2, _b2, _c2, _d2, _e2;
4399
4708
  const track = tracks[trackIndex];
4400
4709
  if (!track) return null;
4401
4710
  const hasMidiNotes = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
@@ -4406,153 +4715,163 @@ var PlaylistVisualization = ({
4406
4715
  track.id,
4407
4716
  mono
4408
4717
  );
4409
- return /* @__PURE__ */ jsxs2(
4410
- TrackComponent,
4718
+ return /* @__PURE__ */ jsx10(
4719
+ TrackRowPositioner,
4411
4720
  {
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;
4721
+ $top: (_d2 = trackLayout.topById.get(track.id)) != null ? _d2 : 0,
4722
+ $animate: animateTrackLayout,
4723
+ "data-track-row": "",
4724
+ "data-track-id": track.id,
4725
+ "data-track-drag-source": (trackDragPreview == null ? void 0 : trackDragPreview.trackId) === track.id ? "true" : void 0,
4726
+ children: /* @__PURE__ */ jsxs2(
4727
+ TrackComponent,
4728
+ {
4729
+ numChannels: maxChannels,
4730
+ backgroundColor: effectiveRenderMode === "piano-roll" ? theme.pianoRollBackgroundColor || "#1a1a2e" : waveformColorToCss2(theme.waveOutlineColor),
4731
+ offset: 0,
4732
+ width: tracksFullWidth,
4733
+ hasClipHeaders: showClipHeaders,
4734
+ trackId: track.id,
4735
+ isSelected: track.id === selectedTrackId,
4736
+ children: [
4737
+ effectiveRenderMode !== "waveform" && (() => {
4738
+ var _a3, _b3;
4739
+ const helpers = perTrackSpectrogramHelpers.get(track.id);
4740
+ const trackCfg = helpers == null ? void 0 : helpers.config;
4741
+ if (!(trackCfg == null ? void 0 : trackCfg.labels) || !helpers) return null;
4742
+ return /* @__PURE__ */ jsx10(
4743
+ SpectrogramLabels,
4744
+ {
4745
+ waveHeight,
4746
+ numChannels: maxChannels,
4747
+ frequencyScaleFn: helpers.frequencyScaleFn,
4748
+ minFrequency: (_a3 = trackCfg.minFrequency) != null ? _a3 : 0,
4749
+ maxFrequency: (_b3 = trackCfg.maxFrequency) != null ? _b3 : sampleRate / 2,
4750
+ labelsColor: trackCfg.labelsColor,
4751
+ labelsBackground: trackCfg.labelsBackground,
4752
+ renderMode: effectiveRenderMode,
4753
+ hasClipHeaders: showClipHeaders
4469
4754
  }
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
4755
+ );
4756
+ })(),
4757
+ trackClipPeaks.map((clip, clipIndex) => {
4758
+ const peaksData = clip.peaks;
4759
+ const width = peaksData.length;
4760
+ return /* @__PURE__ */ jsx10(
4761
+ Clip,
4762
+ {
4763
+ clipId: clip.clipId,
4764
+ trackIndex,
4765
+ clipIndex,
4766
+ trackName: clip.trackName,
4767
+ startSample: clip.startSample,
4768
+ durationSamples: clip.durationSamples,
4769
+ samplesPerPixel,
4770
+ showHeader: showClipHeaders,
4771
+ disableHeaderDrag: !interactiveClips,
4772
+ isSelected: track.id === selectedTrackId,
4773
+ trackId: track.id,
4774
+ fadeIn: clip.fadeIn,
4775
+ fadeOut: clip.fadeOut,
4776
+ sampleRate,
4777
+ showFades,
4778
+ touchOptimized,
4779
+ onMouseDown: (e) => {
4780
+ const target = e.target;
4781
+ const isDraggable = target.closest(
4782
+ '[role="button"][aria-roledescription="draggable"]'
4783
+ );
4784
+ if (isDraggable) {
4785
+ return;
4786
+ }
4787
+ selectTrack(trackIndex);
4491
4788
  },
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,
4789
+ children: peaksData.data.map((channelPeaks, channelIndex) => {
4790
+ return /* @__PURE__ */ jsx10(
4791
+ ChannelWithProgress,
4792
+ {
4793
+ index: channelIndex,
4794
+ data: channelPeaks,
4795
+ bits: peaksData.bits,
4796
+ length: width,
4797
+ isSelected: track.id === selectedTrackId,
4798
+ clipStartSample: clip.startSample,
4799
+ clipDurationSamples: clip.durationSamples,
4800
+ renderMode: clip.midiNotes ? "piano-roll" : effectiveRenderMode,
4801
+ midiNotes: clip.midiNotes,
4802
+ clipSampleRate: clip.sampleRate,
4803
+ clipOffsetSeconds: clip.offsetSamples != null ? clip.offsetSamples / (clip.sampleRate || sampleRate) : 0,
4804
+ samplesPerPixel,
4805
+ spectrogramClipId: clip.clipId,
4806
+ spectrogramOnCanvasRegister: spectrogram ? spectrogram.registerSpectrogramCanvas : void 0,
4807
+ spectrogramOnCanvasUnregister: spectrogram ? spectrogram.unregisterSpectrogramCanvas : void 0
4808
+ },
4809
+ `${clip.clipId}-${channelIndex}`
4810
+ );
4811
+ })
4812
+ },
4813
+ clip.clipId
4814
+ );
4815
+ }),
4816
+ (recordingState == null ? void 0 : recordingState.isRecording) && recordingState.trackId === track.id && ((_e2 = recordingState.peaks[0]) == null ? void 0 : _e2.length) > 0 && (() => {
4817
+ const latencyOffsetSamples = resolveRecordingOffsetSamples({
4818
+ overrideSeconds: recordingState.latencyOffset,
4819
+ outputLatency: getOutputLatency(),
4820
+ lookAhead: getLookAhead(),
4821
+ sampleRate
4822
+ });
4823
+ const latencyPixels = Math.floor(latencyOffsetSamples / samplesPerPixel);
4824
+ const skipPeakElements = latencyPixels * 2;
4825
+ const previewDuration = Math.max(
4826
+ 0,
4827
+ recordingState.durationSamples - latencyOffsetSamples
4828
+ );
4829
+ const previewChannels = (mono ? recordingState.peaks.slice(0, 1) : recordingState.peaks).map(
4830
+ (channelPeaks) => skipPeakElements > 0 && skipPeakElements < channelPeaks.length ? channelPeaks.subarray(skipPeakElements) : channelPeaks
4831
+ );
4832
+ return /* @__PURE__ */ jsx10(
4833
+ Clip,
4531
4834
  {
4532
- index: chIdx,
4533
- data: channelPeaks,
4534
- bits: recordingState.bits,
4535
- length: Math.floor(channelPeaks.length / 2),
4835
+ clipId: "recording-preview",
4836
+ trackIndex,
4837
+ clipIndex: trackClipPeaks.length,
4838
+ trackName: "Recording...",
4839
+ startSample: recordingState.startSample,
4840
+ durationSamples: previewDuration,
4841
+ samplesPerPixel,
4842
+ showHeader: showClipHeaders,
4843
+ disableHeaderDrag: true,
4536
4844
  isSelected: track.id === selectedTrackId,
4537
- clipStartSample: recordingState.startSample,
4538
- clipDurationSamples: previewDuration
4845
+ trackId: track.id,
4846
+ children: previewChannels.map((channelPeaks, chIdx) => /* @__PURE__ */ jsx10(
4847
+ ChannelWithProgress,
4848
+ {
4849
+ index: chIdx,
4850
+ data: channelPeaks,
4851
+ bits: recordingState.bits,
4852
+ length: Math.floor(channelPeaks.length / 2),
4853
+ isSelected: track.id === selectedTrackId,
4854
+ clipStartSample: recordingState.startSample,
4855
+ clipDurationSamples: previewDuration
4856
+ },
4857
+ `${track.id}-recording-${chIdx}`
4858
+ ))
4539
4859
  },
4540
- `${track.id}-recording-${chIdx}`
4541
- ))
4542
- },
4543
- `${track.id}-recording`
4544
- );
4545
- })()
4546
- ]
4860
+ `${track.id}-recording`
4861
+ );
4862
+ })()
4863
+ ]
4864
+ }
4865
+ )
4547
4866
  },
4548
4867
  track.id
4549
4868
  );
4550
- }),
4551
- annotations.length > 0 && annotationIntegration && /* @__PURE__ */ jsx9(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
4869
+ }) }),
4870
+ annotations.length > 0 && annotationIntegration && /* @__PURE__ */ jsx10(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
4552
4871
  const startPosition = annotation.start * sampleRate / samplesPerPixel;
4553
4872
  const endPosition = annotation.end * sampleRate / samplesPerPixel;
4554
4873
  const label = getAnnotationBoxLabel ? getAnnotationBoxLabel(annotation, index) : annotation.id;
4555
- return /* @__PURE__ */ jsx9(
4874
+ return /* @__PURE__ */ jsx10(
4556
4875
  annotationIntegration.AnnotationBox,
4557
4876
  {
4558
4877
  annotationId: annotation.id,
@@ -4568,7 +4887,7 @@ var PlaylistVisualization = ({
4568
4887
  annotation.id
4569
4888
  );
4570
4889
  }) }),
4571
- selectionStart !== selectionEnd && /* @__PURE__ */ jsx9(
4890
+ selectionStart !== selectionEnd && /* @__PURE__ */ jsx10(
4572
4891
  Selection,
4573
4892
  {
4574
4893
  startPosition: Math.min(selectionStart, selectionEnd) * sampleRate / samplesPerPixel,
@@ -4576,7 +4895,7 @@ var PlaylistVisualization = ({
4576
4895
  color: theme.selectionColor
4577
4896
  }
4578
4897
  ),
4579
- (isPlaying || selectionStart === selectionEnd) && (renderPlayhead ? /* @__PURE__ */ jsx9(
4898
+ (isPlaying || selectionStart === selectionEnd) && (renderPlayhead ? /* @__PURE__ */ jsx10(
4580
4899
  CustomPlayhead,
4581
4900
  {
4582
4901
  renderPlayhead,
@@ -4584,14 +4903,14 @@ var PlaylistVisualization = ({
4584
4903
  samplesPerPixel,
4585
4904
  sampleRate
4586
4905
  }
4587
- ) : /* @__PURE__ */ jsx9(AnimatedPlayhead, { color: theme.playheadColor }))
4906
+ ) : /* @__PURE__ */ jsx10(AnimatedPlayhead, { color: theme.playheadColor }))
4588
4907
  ] })
4589
4908
  }
4590
4909
  )
4591
4910
  }
4592
4911
  ),
4593
4912
  (spectrogram == null ? void 0 : spectrogram.SettingsModal) && typeof document !== "undefined" && createPortal(
4594
- /* @__PURE__ */ jsx9(
4913
+ /* @__PURE__ */ jsx10(
4595
4914
  spectrogram.SettingsModal,
4596
4915
  {
4597
4916
  open: settingsModalTrackId !== null,
@@ -4611,8 +4930,8 @@ var PlaylistVisualization = ({
4611
4930
  };
4612
4931
 
4613
4932
  // src/components/PlaylistAnnotationList.tsx
4614
- import { useCallback as useCallback17 } from "react";
4615
- import { jsx as jsx10 } from "react/jsx-runtime";
4933
+ import { useCallback as useCallback18 } from "react";
4934
+ import { jsx as jsx11 } from "react/jsx-runtime";
4616
4935
  var PlaylistAnnotationList = ({
4617
4936
  height,
4618
4937
  renderAnnotationItem,
@@ -4626,7 +4945,7 @@ var PlaylistAnnotationList = ({
4626
4945
  const integration = useAnnotationIntegration();
4627
4946
  const { setAnnotations } = usePlaylistControls();
4628
4947
  const resolvedConfig = annotationListConfig != null ? annotationListConfig : { linkEndpoints, continuousPlay };
4629
- const handleAnnotationUpdate = useCallback17(
4948
+ const handleAnnotationUpdate = useCallback18(
4630
4949
  (updatedAnnotations) => {
4631
4950
  setAnnotations(updatedAnnotations);
4632
4951
  onAnnotationUpdate == null ? void 0 : onAnnotationUpdate(updatedAnnotations);
@@ -4634,7 +4953,7 @@ var PlaylistAnnotationList = ({
4634
4953
  [setAnnotations, onAnnotationUpdate]
4635
4954
  );
4636
4955
  const { AnnotationText } = integration;
4637
- return /* @__PURE__ */ jsx10(
4956
+ return /* @__PURE__ */ jsx11(
4638
4957
  AnnotationText,
4639
4958
  {
4640
4959
  annotations,
@@ -4653,7 +4972,7 @@ var PlaylistAnnotationList = ({
4653
4972
  };
4654
4973
 
4655
4974
  // src/components/Waveform.tsx
4656
- import { Fragment as Fragment3, jsx as jsx11, jsxs as jsxs3 } from "react/jsx-runtime";
4975
+ import { Fragment as Fragment4, jsx as jsx12, jsxs as jsxs3 } from "react/jsx-runtime";
4657
4976
  var Waveform = ({
4658
4977
  renderTrackControls,
4659
4978
  renderTick,
@@ -4672,13 +4991,14 @@ var Waveform = ({
4672
4991
  showFades = false,
4673
4992
  touchOptimized = false,
4674
4993
  onRemoveTrack,
4994
+ trackReordering = false,
4675
4995
  recordingState
4676
4996
  }) => {
4677
4997
  const { annotations } = usePlaylistState();
4678
4998
  const clipInteractionEnabled = useClipInteractionEnabled();
4679
4999
  const effectiveInteractiveClips = interactiveClips || clipInteractionEnabled;
4680
- return /* @__PURE__ */ jsxs3(Fragment3, { children: [
4681
- /* @__PURE__ */ jsx11(
5000
+ return /* @__PURE__ */ jsxs3(Fragment4, { children: [
5001
+ /* @__PURE__ */ jsx12(
4682
5002
  PlaylistVisualization,
4683
5003
  {
4684
5004
  renderTrackControls,
@@ -4692,10 +5012,11 @@ var Waveform = ({
4692
5012
  showFades,
4693
5013
  touchOptimized,
4694
5014
  onRemoveTrack,
5015
+ trackReordering,
4695
5016
  recordingState
4696
5017
  }
4697
5018
  ),
4698
- annotations.length > 0 && /* @__PURE__ */ jsx11(
5019
+ annotations.length > 0 && /* @__PURE__ */ jsx12(
4699
5020
  PlaylistAnnotationList,
4700
5021
  {
4701
5022
  height: annotationTextHeight,
@@ -4710,7 +5031,7 @@ var Waveform = ({
4710
5031
  };
4711
5032
 
4712
5033
  // src/components/MediaElementPlaylist.tsx
4713
- import { useContext as useContext7, useRef as useRef17, useState as useState12, useCallback as useCallback18 } from "react";
5034
+ import { useContext as useContext7, useRef as useRef18, useState as useState13, useCallback as useCallback19 } from "react";
4714
5035
  import { DragDropProvider } from "@dnd-kit/react";
4715
5036
  import { RestrictToHorizontalAxis } from "@dnd-kit/abstract/modifiers";
4716
5037
  import {
@@ -4746,9 +5067,9 @@ var noDropAnimationPlugins = (defaults) => {
4746
5067
  };
4747
5068
 
4748
5069
  // src/components/AnimatedMediaElementPlayhead.tsx
4749
- import { useRef as useRef15, useEffect as useEffect11 } from "react";
5070
+ import { useRef as useRef16, useEffect as useEffect13 } from "react";
4750
5071
  import styled5 from "styled-components";
4751
- import { jsx as jsx12 } from "react/jsx-runtime";
5072
+ import { jsx as jsx13 } from "react/jsx-runtime";
4752
5073
  var PlayheadLine2 = styled5.div`
4753
5074
  position: absolute;
4754
5075
  top: 0;
@@ -4763,11 +5084,11 @@ var PlayheadLine2 = styled5.div`
4763
5084
  var AnimatedMediaElementPlayhead = ({
4764
5085
  color = "#ff0000"
4765
5086
  }) => {
4766
- const playheadRef = useRef15(null);
4767
- const animationFrameRef = useRef15(null);
5087
+ const playheadRef = useRef16(null);
5088
+ const animationFrameRef = useRef16(null);
4768
5089
  const { isPlaying, currentTimeRef } = useMediaElementAnimation();
4769
5090
  const { samplesPerPixel, sampleRate, progressBarWidth } = useMediaElementData();
4770
- useEffect11(() => {
5091
+ useEffect13(() => {
4771
5092
  const updatePosition = () => {
4772
5093
  var _a;
4773
5094
  if (playheadRef.current) {
@@ -4791,7 +5112,7 @@ var AnimatedMediaElementPlayhead = ({
4791
5112
  }
4792
5113
  };
4793
5114
  }, [isPlaying, sampleRate, samplesPerPixel, currentTimeRef]);
4794
- useEffect11(() => {
5115
+ useEffect13(() => {
4795
5116
  var _a;
4796
5117
  if (!isPlaying && playheadRef.current) {
4797
5118
  const time = (_a = currentTimeRef.current) != null ? _a : 0;
@@ -4799,11 +5120,11 @@ var AnimatedMediaElementPlayhead = ({
4799
5120
  playheadRef.current.style.transform = `translate3d(${position}px, 0, 0)`;
4800
5121
  }
4801
5122
  });
4802
- return /* @__PURE__ */ jsx12(PlayheadLine2, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
5123
+ return /* @__PURE__ */ jsx13(PlayheadLine2, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
4803
5124
  };
4804
5125
 
4805
5126
  // src/components/ChannelWithMediaElementProgress.tsx
4806
- import { useRef as useRef16, useEffect as useEffect12 } from "react";
5127
+ import { useRef as useRef17, useEffect as useEffect14 } from "react";
4807
5128
  import styled6 from "styled-components";
4808
5129
  import {
4809
5130
  SmartChannel as SmartChannel2,
@@ -4811,7 +5132,7 @@ import {
4811
5132
  usePlaylistInfo as usePlaylistInfo2,
4812
5133
  waveformColorToCss as waveformColorToCss3
4813
5134
  } from "@waveform-playlist/ui-components";
4814
- import { jsx as jsx13, jsxs as jsxs4 } from "react/jsx-runtime";
5135
+ import { jsx as jsx14, jsxs as jsxs4 } from "react/jsx-runtime";
4815
5136
  var ChannelWrapper2 = styled6.div`
4816
5137
  position: relative;
4817
5138
  `;
@@ -4848,14 +5169,14 @@ var ChannelWithMediaElementProgress = (_a) => {
4848
5169
  "clipStartSample",
4849
5170
  "clipDurationSamples"
4850
5171
  ]);
4851
- const progressRef = useRef16(null);
4852
- const animationFrameRef = useRef16(null);
5172
+ const progressRef = useRef17(null);
5173
+ const animationFrameRef = useRef17(null);
4853
5174
  const theme = useTheme3();
4854
5175
  const { waveHeight } = usePlaylistInfo2();
4855
5176
  const { isPlaying, currentTimeRef } = useMediaElementAnimation();
4856
5177
  const { samplesPerPixel, sampleRate } = useMediaElementData();
4857
5178
  const progressColor = (theme == null ? void 0 : theme.waveProgressColor) || "rgba(0, 0, 0, 0.1)";
4858
- useEffect12(() => {
5179
+ useEffect14(() => {
4859
5180
  const updateProgress = () => {
4860
5181
  var _a2;
4861
5182
  if (progressRef.current) {
@@ -4897,7 +5218,7 @@ var ChannelWithMediaElementProgress = (_a) => {
4897
5218
  smartChannelProps.length,
4898
5219
  currentTimeRef
4899
5220
  ]);
4900
- useEffect12(() => {
5221
+ useEffect14(() => {
4901
5222
  var _a2;
4902
5223
  if (!isPlaying && progressRef.current) {
4903
5224
  const currentTime = (_a2 = currentTimeRef.current) != null ? _a2 : 0;
@@ -4924,7 +5245,7 @@ var ChannelWithMediaElementProgress = (_a) => {
4924
5245
  }
4925
5246
  const backgroundCss = waveformColorToCss3(backgroundColor);
4926
5247
  return /* @__PURE__ */ jsxs4(ChannelWrapper2, { children: [
4927
- /* @__PURE__ */ jsx13(
5248
+ /* @__PURE__ */ jsx14(
4928
5249
  Background2,
4929
5250
  {
4930
5251
  $color: backgroundCss,
@@ -4933,7 +5254,7 @@ var ChannelWithMediaElementProgress = (_a) => {
4933
5254
  $width: smartChannelProps.length
4934
5255
  }
4935
5256
  ),
4936
- /* @__PURE__ */ jsx13(
5257
+ /* @__PURE__ */ jsx14(
4937
5258
  ProgressOverlay2,
4938
5259
  {
4939
5260
  ref: progressRef,
@@ -4942,12 +5263,12 @@ var ChannelWithMediaElementProgress = (_a) => {
4942
5263
  $top: smartChannelProps.index * waveHeight
4943
5264
  }
4944
5265
  ),
4945
- /* @__PURE__ */ jsx13(ChannelContainer2, { children: /* @__PURE__ */ jsx13(SmartChannel2, __spreadProps(__spreadValues({}, smartChannelProps), { isSelected: true, transparentBackground: true })) })
5266
+ /* @__PURE__ */ jsx14(ChannelContainer2, { children: /* @__PURE__ */ jsx14(SmartChannel2, __spreadProps(__spreadValues({}, smartChannelProps), { isSelected: true, transparentBackground: true })) })
4946
5267
  ] });
4947
5268
  };
4948
5269
 
4949
5270
  // src/components/MediaElementPlaylist.tsx
4950
- import { Fragment as Fragment4, jsx as jsx14, jsxs as jsxs5 } from "react/jsx-runtime";
5271
+ import { Fragment as Fragment5, jsx as jsx15, jsxs as jsxs5 } from "react/jsx-runtime";
4951
5272
  var ZERO_REF = { current: 0 };
4952
5273
  var CustomMediaElementPlayhead = ({ renderPlayhead, color, samplesPerPixel, sampleRate }) => {
4953
5274
  var _a;
@@ -4993,11 +5314,11 @@ var MediaElementPlaylist = ({
4993
5314
  fadeIn,
4994
5315
  fadeOut
4995
5316
  } = 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(
5317
+ const [selectionStart, setSelectionStart] = useState13(0);
5318
+ const [selectionEnd, setSelectionEnd] = useState13(0);
5319
+ const [isSelecting, setIsSelecting] = useState13(false);
5320
+ const scrollContainerRef = useRef18(null);
5321
+ const handleScrollContainerRef = useCallback19(
5001
5322
  (el) => {
5002
5323
  scrollContainerRef.current = el;
5003
5324
  setScrollContainer(el);
@@ -5005,7 +5326,7 @@ var MediaElementPlaylist = ({
5005
5326
  [setScrollContainer]
5006
5327
  );
5007
5328
  const tracksFullWidth = Math.floor(duration * sampleRate / samplesPerPixel);
5008
- const handleAnnotationClick = useCallback18(
5329
+ const handleAnnotationClick = useCallback19(
5009
5330
  (annotation) => __async(null, null, function* () {
5010
5331
  setActiveAnnotationId(annotation.id);
5011
5332
  try {
@@ -5020,7 +5341,7 @@ var MediaElementPlaylist = ({
5020
5341
  }),
5021
5342
  [setActiveAnnotationId, play]
5022
5343
  );
5023
- const handleAnnotationUpdate = useCallback18(
5344
+ const handleAnnotationUpdate = useCallback19(
5024
5345
  (updatedAnnotations) => {
5025
5346
  setAnnotations(updatedAnnotations);
5026
5347
  onAnnotationUpdate == null ? void 0 : onAnnotationUpdate(updatedAnnotations);
@@ -5034,8 +5355,8 @@ var MediaElementPlaylist = ({
5034
5355
  duration,
5035
5356
  linkEndpoints: linkEndpointsProp
5036
5357
  });
5037
- const mouseDownTimeRef = useRef17(0);
5038
- const handleMouseDown = useCallback18(
5358
+ const mouseDownTimeRef = useRef18(0);
5359
+ const handleMouseDown = useCallback19(
5039
5360
  (e) => {
5040
5361
  const rect = e.currentTarget.getBoundingClientRect();
5041
5362
  const x = e.clientX - rect.left;
@@ -5047,7 +5368,7 @@ var MediaElementPlaylist = ({
5047
5368
  },
5048
5369
  [samplesPerPixel, sampleRate]
5049
5370
  );
5050
- const handleMouseMove = useCallback18(
5371
+ const handleMouseMove = useCallback19(
5051
5372
  (e) => {
5052
5373
  if (!isSelecting) return;
5053
5374
  const rect = e.currentTarget.getBoundingClientRect();
@@ -5057,7 +5378,7 @@ var MediaElementPlaylist = ({
5057
5378
  },
5058
5379
  [isSelecting, samplesPerPixel, sampleRate]
5059
5380
  );
5060
- const handleMouseUp = useCallback18(
5381
+ const handleMouseUp = useCallback19(
5061
5382
  (e) => {
5062
5383
  if (!isSelecting) return;
5063
5384
  setIsSelecting(false);
@@ -5087,9 +5408,9 @@ var MediaElementPlaylist = ({
5087
5408
  [isSelecting, selectionStart, samplesPerPixel, sampleRate, seekTo, isPlaying, playoutRef, play]
5088
5409
  );
5089
5410
  if (peaksDataArray.length === 0) {
5090
- return /* @__PURE__ */ jsx14("div", { className, children: "Loading waveform..." });
5411
+ return /* @__PURE__ */ jsx15("div", { className, children: "Loading waveform..." });
5091
5412
  }
5092
- return /* @__PURE__ */ jsx14(DevicePixelRatioProvider2, { children: /* @__PURE__ */ jsx14(
5413
+ return /* @__PURE__ */ jsx15(DevicePixelRatioProvider2, { children: /* @__PURE__ */ jsx15(
5093
5414
  PlaylistInfoContext2.Provider,
5094
5415
  {
5095
5416
  value: {
@@ -5104,7 +5425,7 @@ var MediaElementPlaylist = ({
5104
5425
  barGap,
5105
5426
  roundedBars
5106
5427
  },
5107
- children: /* @__PURE__ */ jsx14(
5428
+ children: /* @__PURE__ */ jsx15(
5108
5429
  Playlist2,
5109
5430
  {
5110
5431
  theme,
@@ -5118,11 +5439,11 @@ var MediaElementPlaylist = ({
5118
5439
  onTracksMouseUp: handleMouseUp,
5119
5440
  scrollContainerRef: handleScrollContainerRef,
5120
5441
  isSelecting,
5121
- timescale: timeScaleHeight > 0 ? /* @__PURE__ */ jsx14(SmartScale2, {}) : void 0,
5122
- children: /* @__PURE__ */ jsxs5(Fragment4, { children: [
5442
+ timescale: timeScaleHeight > 0 ? /* @__PURE__ */ jsx15(SmartScale2, {}) : void 0,
5443
+ children: /* @__PURE__ */ jsxs5(Fragment5, { children: [
5123
5444
  peaksDataArray.map((trackClipPeaks, trackIndex) => {
5124
5445
  const maxChannels = trackClipPeaks.length > 0 ? Math.max(...trackClipPeaks.map((clip) => clip.peaks.data.length)) : 1;
5125
- return /* @__PURE__ */ jsx14(
5446
+ return /* @__PURE__ */ jsx15(
5126
5447
  TrackComponent2,
5127
5448
  {
5128
5449
  numChannels: maxChannels,
@@ -5150,7 +5471,7 @@ var MediaElementPlaylist = ({
5150
5471
  isSelected: true,
5151
5472
  trackId: `media-element-track-${trackIndex}`,
5152
5473
  children: [
5153
- peaksData.data.map((channelPeaks, channelIndex) => /* @__PURE__ */ jsx14(
5474
+ peaksData.data.map((channelPeaks, channelIndex) => /* @__PURE__ */ jsx15(
5154
5475
  ChannelWithMediaElementProgress,
5155
5476
  {
5156
5477
  index: channelIndex,
@@ -5162,7 +5483,7 @@ var MediaElementPlaylist = ({
5162
5483
  },
5163
5484
  `${trackIndex}-${clipIndex}-${channelIndex}`
5164
5485
  )),
5165
- showFades && fadeIn && fadeIn.duration > 0 && /* @__PURE__ */ jsx14(
5486
+ showFades && fadeIn && fadeIn.duration > 0 && /* @__PURE__ */ jsx15(
5166
5487
  FadeOverlay,
5167
5488
  {
5168
5489
  left: 0,
@@ -5171,7 +5492,7 @@ var MediaElementPlaylist = ({
5171
5492
  curveType: fadeIn.type
5172
5493
  }
5173
5494
  ),
5174
- showFades && fadeOut && fadeOut.duration > 0 && /* @__PURE__ */ jsx14(
5495
+ showFades && fadeOut && fadeOut.duration > 0 && /* @__PURE__ */ jsx15(
5175
5496
  FadeOverlay,
5176
5497
  {
5177
5498
  left: width - Math.floor(fadeOut.duration * sampleRate / samplesPerPixel),
@@ -5189,7 +5510,7 @@ var MediaElementPlaylist = ({
5189
5510
  trackIndex
5190
5511
  );
5191
5512
  }),
5192
- annotations.length > 0 && annotationIntegration && /* @__PURE__ */ jsx14(
5513
+ annotations.length > 0 && annotationIntegration && /* @__PURE__ */ jsx15(
5193
5514
  DragDropProvider,
5194
5515
  {
5195
5516
  onDragStart,
@@ -5197,11 +5518,11 @@ var MediaElementPlaylist = ({
5197
5518
  onDragEnd,
5198
5519
  modifiers: editable ? [RestrictToHorizontalAxis] : [],
5199
5520
  plugins: noDropAnimationPlugins,
5200
- children: /* @__PURE__ */ jsx14(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
5521
+ children: /* @__PURE__ */ jsx15(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
5201
5522
  const startPosition = annotation.start * sampleRate / samplesPerPixel;
5202
5523
  const endPosition = annotation.end * sampleRate / samplesPerPixel;
5203
5524
  const label = getAnnotationBoxLabel ? getAnnotationBoxLabel(annotation, index) : annotation.id;
5204
- return /* @__PURE__ */ jsx14(
5525
+ return /* @__PURE__ */ jsx15(
5205
5526
  annotationIntegration.AnnotationBox,
5206
5527
  {
5207
5528
  annotationId: annotation.id,
@@ -5219,7 +5540,7 @@ var MediaElementPlaylist = ({
5219
5540
  }) })
5220
5541
  }
5221
5542
  ),
5222
- selectionStart !== selectionEnd && /* @__PURE__ */ jsx14(
5543
+ selectionStart !== selectionEnd && /* @__PURE__ */ jsx15(
5223
5544
  Selection2,
5224
5545
  {
5225
5546
  startPosition: Math.min(selectionStart, selectionEnd) * sampleRate / samplesPerPixel,
@@ -5227,7 +5548,7 @@ var MediaElementPlaylist = ({
5227
5548
  color: theme.selectionColor
5228
5549
  }
5229
5550
  ),
5230
- renderPlayhead ? /* @__PURE__ */ jsx14(
5551
+ renderPlayhead ? /* @__PURE__ */ jsx15(
5231
5552
  CustomMediaElementPlayhead,
5232
5553
  {
5233
5554
  renderPlayhead,
@@ -5235,7 +5556,7 @@ var MediaElementPlaylist = ({
5235
5556
  samplesPerPixel,
5236
5557
  sampleRate
5237
5558
  }
5238
- ) : /* @__PURE__ */ jsx14(AnimatedMediaElementPlayhead, { color: theme.playheadColor })
5559
+ ) : /* @__PURE__ */ jsx15(AnimatedMediaElementPlayhead, { color: theme.playheadColor })
5239
5560
  ] })
5240
5561
  }
5241
5562
  )
@@ -5244,8 +5565,8 @@ var MediaElementPlaylist = ({
5244
5565
  };
5245
5566
 
5246
5567
  // src/components/MediaElementAnnotationList.tsx
5247
- import { useCallback as useCallback19 } from "react";
5248
- import { jsx as jsx15 } from "react/jsx-runtime";
5568
+ import { useCallback as useCallback20 } from "react";
5569
+ import { jsx as jsx16 } from "react/jsx-runtime";
5249
5570
  var MediaElementAnnotationList = ({
5250
5571
  height,
5251
5572
  renderAnnotationItem,
@@ -5260,7 +5581,7 @@ var MediaElementAnnotationList = ({
5260
5581
  const integration = useAnnotationIntegration();
5261
5582
  const { setAnnotations } = useMediaElementControls();
5262
5583
  const resolvedConfig = annotationListConfig != null ? annotationListConfig : { linkEndpoints: false, continuousPlay };
5263
- const handleAnnotationUpdate = useCallback19(
5584
+ const handleAnnotationUpdate = useCallback20(
5264
5585
  (updatedAnnotations) => {
5265
5586
  setAnnotations(updatedAnnotations);
5266
5587
  onAnnotationUpdate == null ? void 0 : onAnnotationUpdate(updatedAnnotations);
@@ -5268,7 +5589,7 @@ var MediaElementAnnotationList = ({
5268
5589
  [setAnnotations, onAnnotationUpdate]
5269
5590
  );
5270
5591
  const { AnnotationText } = integration;
5271
- return /* @__PURE__ */ jsx15(
5592
+ return /* @__PURE__ */ jsx16(
5272
5593
  AnnotationText,
5273
5594
  {
5274
5595
  annotations,
@@ -5287,7 +5608,7 @@ var MediaElementAnnotationList = ({
5287
5608
  };
5288
5609
 
5289
5610
  // src/components/MediaElementWaveform.tsx
5290
- import { Fragment as Fragment5, jsx as jsx16, jsxs as jsxs6 } from "react/jsx-runtime";
5611
+ import { Fragment as Fragment6, jsx as jsx17, jsxs as jsxs6 } from "react/jsx-runtime";
5291
5612
  var MediaElementWaveform = ({
5292
5613
  annotationTextHeight,
5293
5614
  getAnnotationBoxLabel,
@@ -5302,8 +5623,8 @@ var MediaElementWaveform = ({
5302
5623
  className
5303
5624
  }) => {
5304
5625
  const { annotations } = useMediaElementState();
5305
- return /* @__PURE__ */ jsxs6(Fragment5, { children: [
5306
- /* @__PURE__ */ jsx16(
5626
+ return /* @__PURE__ */ jsxs6(Fragment6, { children: [
5627
+ /* @__PURE__ */ jsx17(
5307
5628
  MediaElementPlaylist,
5308
5629
  {
5309
5630
  getAnnotationBoxLabel,
@@ -5315,7 +5636,7 @@ var MediaElementWaveform = ({
5315
5636
  className
5316
5637
  }
5317
5638
  ),
5318
- annotations.length > 0 && /* @__PURE__ */ jsx16(
5639
+ annotations.length > 0 && /* @__PURE__ */ jsx17(
5319
5640
  MediaElementAnnotationList,
5320
5641
  {
5321
5642
  height: annotationTextHeight,
@@ -5390,7 +5711,7 @@ var KeyboardShortcuts = ({
5390
5711
  };
5391
5712
 
5392
5713
  // src/components/ClipInteractionProvider.tsx
5393
- import React16, { useEffect as useEffect13, useMemo as useMemo6 } from "react";
5714
+ import React17, { useEffect as useEffect15, useMemo as useMemo6 } from "react";
5394
5715
  import { DragDropProvider as DragDropProvider2 } from "@dnd-kit/react";
5395
5716
  import { RestrictToHorizontalAxis as RestrictToHorizontalAxis2 } from "@dnd-kit/abstract/modifiers";
5396
5717
  import {
@@ -5480,7 +5801,7 @@ _SnapToGridModifier.configure = configurator2(_SnapToGridModifier);
5480
5801
  var SnapToGridModifier = _SnapToGridModifier;
5481
5802
 
5482
5803
  // src/components/ClipInteractionProvider.tsx
5483
- import { jsx as jsx17 } from "react/jsx-runtime";
5804
+ import { jsx as jsx18 } from "react/jsx-runtime";
5484
5805
  var NOOP_TRACKS_CHANGE = () => {
5485
5806
  };
5486
5807
  var ClipInteractionProvider = ({
@@ -5489,11 +5810,11 @@ var ClipInteractionProvider = ({
5489
5810
  children
5490
5811
  }) => {
5491
5812
  const { tracks, samplesPerPixel, sampleRate, playoutRef, isDraggingRef, onTracksChange } = usePlaylistData();
5492
- const { setSelectedTrackId } = usePlaylistControls();
5813
+ const { setSelectedTrackId, reorderTrack, bumpTrackReorderEpoch, setTrackDragPreview } = usePlaylistControls();
5493
5814
  const beatsAndBars = useBeatsAndBars();
5494
5815
  const useBeatsSnap = snap && beatsAndBars != null && beatsAndBars.scaleMode === "beats" && beatsAndBars.snapTo !== "off";
5495
5816
  const useTimescaleSnap = snap && !useBeatsSnap;
5496
- useEffect13(() => {
5817
+ useEffect15(() => {
5497
5818
  if (onTracksChange == null) {
5498
5819
  console.warn(
5499
5820
  "[waveform-playlist] ClipInteractionProvider: onTracksChange is not set on WaveformPlaylistProvider. Drag and trim edits will not be persisted."
@@ -5529,10 +5850,15 @@ var ClipInteractionProvider = ({
5529
5850
  isDraggingRef,
5530
5851
  snapSamplePosition
5531
5852
  });
5532
- const onDragStart = React16.useCallback(
5853
+ const onDragStart = React17.useCallback(
5533
5854
  (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;
5855
+ var _a, _b;
5856
+ const data = (_b = (_a = event.operation) == null ? void 0 : _a.source) == null ? void 0 : _b.data;
5857
+ if ((data == null ? void 0 : data.kind) === "track-reorder") {
5858
+ if (data.trackId) setSelectedTrackId(data.trackId);
5859
+ return;
5860
+ }
5861
+ const trackIndex = data == null ? void 0 : data.trackIndex;
5536
5862
  if (trackIndex !== void 0 && tracks[trackIndex]) {
5537
5863
  setSelectedTrackId(tracks[trackIndex].id);
5538
5864
  }
@@ -5540,6 +5866,39 @@ var ClipInteractionProvider = ({
5540
5866
  },
5541
5867
  [handleDragStart, tracks, setSelectedTrackId]
5542
5868
  );
5869
+ const handleDragOver = React17.useCallback(
5870
+ (event) => {
5871
+ var _a;
5872
+ const data = (_a = event.operation.source) == null ? void 0 : _a.data;
5873
+ if ((data == null ? void 0 : data.kind) !== "track-reorder" || !data.trackId) return;
5874
+ const sortable = event.operation.source.sortable;
5875
+ if (!sortable) return;
5876
+ const trackId = data.trackId;
5877
+ const toIndex = sortable.index;
5878
+ setTrackDragPreview(
5879
+ (prev) => prev && prev.trackId === trackId && prev.toIndex === toIndex ? prev : { trackId, toIndex }
5880
+ );
5881
+ },
5882
+ [setTrackDragPreview]
5883
+ );
5884
+ const handleDragEnd = React17.useCallback(
5885
+ (event) => {
5886
+ var _a;
5887
+ const data = (_a = event.operation.source) == null ? void 0 : _a.data;
5888
+ if ((data == null ? void 0 : data.kind) === "track-reorder") {
5889
+ bumpTrackReorderEpoch();
5890
+ setTrackDragPreview(null);
5891
+ if (event.canceled || !data.trackId) return;
5892
+ const sortable = event.operation.source.sortable;
5893
+ if (sortable && sortable.index !== sortable.initialIndex) {
5894
+ reorderTrack(data.trackId, sortable.index);
5895
+ }
5896
+ return;
5897
+ }
5898
+ onDragEnd(event);
5899
+ },
5900
+ [onDragEnd, reorderTrack, bumpTrackReorderEpoch, setTrackDragPreview]
5901
+ );
5543
5902
  const modifiers = useMemo6(() => {
5544
5903
  const mods = [RestrictToHorizontalAxis2];
5545
5904
  if (useBeatsSnap && beatsAndBars) {
@@ -5565,13 +5924,14 @@ var ClipInteractionProvider = ({
5565
5924
  mods.push(ClipCollisionModifier.configure({ tracks, samplesPerPixel }));
5566
5925
  return mods;
5567
5926
  }, [useBeatsSnap, useTimescaleSnap, beatsAndBars, tracks, samplesPerPixel, sampleRate]);
5568
- return /* @__PURE__ */ jsx17(ClipInteractionContextProvider, { value: true, children: /* @__PURE__ */ jsx17(
5927
+ return /* @__PURE__ */ jsx18(ClipInteractionContextProvider, { value: true, children: /* @__PURE__ */ jsx18(
5569
5928
  DragDropProvider2,
5570
5929
  {
5571
5930
  sensors,
5572
5931
  onDragStart,
5573
5932
  onDragMove,
5574
- onDragEnd,
5933
+ onDragOver: handleDragOver,
5934
+ onDragEnd: handleDragEnd,
5575
5935
  modifiers,
5576
5936
  plugins: noDropAnimationPlugins,
5577
5937
  children
@@ -5607,6 +5967,7 @@ export {
5607
5967
  SkipBackwardButton,
5608
5968
  SkipForwardButton,
5609
5969
  SnapToGridModifier,
5970
+ SortableTrackControls,
5610
5971
  SpectrogramIntegrationProvider,
5611
5972
  StopButton,
5612
5973
  TimeFormatSelect,