@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.js CHANGED
@@ -107,6 +107,7 @@ __export(index_exports, {
107
107
  SkipBackwardButton: () => SkipBackwardButton,
108
108
  SkipForwardButton: () => SkipForwardButton,
109
109
  SnapToGridModifier: () => SnapToGridModifier,
110
+ SortableTrackControls: () => SortableTrackControls,
110
111
  SpectrogramIntegrationProvider: () => SpectrogramIntegrationProvider,
111
112
  StopButton: () => StopButton,
112
113
  TimeFormatSelect: () => TimeFormatSelect,
@@ -118,7 +119,6 @@ __export(index_exports, {
118
119
  getWaveformDataMetadata: () => getWaveformDataMetadata,
119
120
  loadPeaksFromWaveformData: () => loadPeaksFromWaveformData,
120
121
  loadWaveformData: () => loadWaveformData,
121
- noDropAnimationPlugins: () => noDropAnimationPlugins,
122
122
  useAnnotationDragHandlers: () => useAnnotationDragHandlers,
123
123
  useAnnotationIntegration: () => useAnnotationIntegration,
124
124
  useAnnotationKeyboardControls: () => useAnnotationKeyboardControls,
@@ -670,7 +670,7 @@ function useClipDragHandlers({
670
670
  (event) => {
671
671
  var _a;
672
672
  const data = (_a = event.operation.source) == null ? void 0 : _a.data;
673
- if (!data) return;
673
+ if (!data || data.kind === "track-reorder") return;
674
674
  if (!data.boundary) {
675
675
  originalClipStateRef.current = null;
676
676
  if (engineRef.current) {
@@ -706,7 +706,7 @@ function useClipDragHandlers({
706
706
  (event) => {
707
707
  var _a, _b, _c;
708
708
  const data = (_a = event.operation.source) == null ? void 0 : _a.data;
709
- if (!data) return;
709
+ if (!data || data.kind === "track-reorder") return;
710
710
  if (!data.boundary) return;
711
711
  if (!originalClipStateRef.current) return;
712
712
  const { boundary, trackIndex, clipIndex } = data;
@@ -766,10 +766,12 @@ function useClipDragHandlers({
766
766
  );
767
767
  const onDragEnd = import_react8.default.useCallback(
768
768
  (event) => {
769
- var _a, _b, _c, _d, _e, _f, _g;
769
+ var _a, _b, _c, _d, _e, _f, _g, _h;
770
+ const kindData = (_a = event.operation.source) == null ? void 0 : _a.data;
771
+ if ((kindData == null ? void 0 : kindData.kind) === "track-reorder") return;
770
772
  if (event.canceled) {
771
773
  if (originalClipStateRef.current) {
772
- const cancelData = (_a = event.operation.source) == null ? void 0 : _a.data;
774
+ const cancelData = (_b = event.operation.source) == null ? void 0 : _b.data;
773
775
  if (cancelData) {
774
776
  const { trackIndex: trackIndex2, clipIndex } = cancelData;
775
777
  const original = originalClipStateRef.current;
@@ -791,25 +793,25 @@ function useClipDragHandlers({
791
793
  isDraggingRef.current = false;
792
794
  originalClipStateRef.current = null;
793
795
  lastBoundaryDeltaRef.current = 0;
794
- (_b = engineRef.current) == null ? void 0 : _b.abortTransaction();
796
+ (_c = engineRef.current) == null ? void 0 : _c.abortTransaction();
795
797
  return;
796
798
  }
797
- const data = (_c = event.operation.source) == null ? void 0 : _c.data;
799
+ const data = (_d = event.operation.source) == null ? void 0 : _d.data;
798
800
  if (!data) {
799
801
  isDraggingRef.current = false;
800
- (_d = engineRef.current) == null ? void 0 : _d.abortTransaction();
802
+ (_e = engineRef.current) == null ? void 0 : _e.abortTransaction();
801
803
  return;
802
804
  }
803
805
  const { trackIndex, clipId, boundary } = data;
804
806
  const sampleDelta = boundary ? lastBoundaryDeltaRef.current : event.operation.transform.x * samplesPerPixel;
805
- const trackId = (_e = tracks[trackIndex]) == null ? void 0 : _e.id;
807
+ const trackId = (_f = tracks[trackIndex]) == null ? void 0 : _f.id;
806
808
  if (boundary) {
807
809
  isDraggingRef.current = false;
808
810
  if (!trackId) {
809
811
  console.warn(
810
812
  `[waveform-playlist] onDragEnd: track at index ${trackIndex} not found \u2014 trim not synced to adapter`
811
813
  );
812
- (_f = engineRef.current) == null ? void 0 : _f.abortTransaction();
814
+ (_g = engineRef.current) == null ? void 0 : _g.abortTransaction();
813
815
  } else if (!engineRef.current) {
814
816
  console.warn("[waveform-playlist] engineRef is null \u2014 trim not synced to adapter");
815
817
  } else {
@@ -824,7 +826,7 @@ function useClipDragHandlers({
824
826
  console.warn(
825
827
  `[waveform-playlist] onDragEnd: track at index ${trackIndex} not found \u2014 move not synced to adapter`
826
828
  );
827
- (_g = engineRef.current) == null ? void 0 : _g.abortTransaction();
829
+ (_h = engineRef.current) == null ? void 0 : _h.abortTransaction();
828
830
  } else if (!engineRef.current) {
829
831
  console.warn("[waveform-playlist] engineRef is null \u2014 move not synced to adapter");
830
832
  } else {
@@ -1931,6 +1933,8 @@ var WaveformPlaylistProvider = ({
1931
1933
  const [linkEndpoints, setLinkEndpoints] = (0, import_react17.useState)((_b = annotationList == null ? void 0 : annotationList.linkEndpoints) != null ? _b : false);
1932
1934
  const [annotationsEditable, setAnnotationsEditable] = (0, import_react17.useState)((_c = annotationList == null ? void 0 : annotationList.editable) != null ? _c : false);
1933
1935
  const [isReady, setIsReady] = (0, import_react17.useState)(false);
1936
+ const [trackReorderEpoch, setTrackReorderEpoch] = (0, import_react17.useState)(0);
1937
+ const [trackDragPreview, setTrackDragPreview] = (0, import_react17.useState)(null);
1934
1938
  const engineRef = (0, import_react17.useRef)(null);
1935
1939
  const adapterRef = (0, import_react17.useRef)(null);
1936
1940
  const audioInitializedRef = (0, import_react17.useRef)(false);
@@ -2270,6 +2274,19 @@ var WaveformPlaylistProvider = ({
2270
2274
  if (!suppressTracksMirroring && state.tracksVersion !== lastTracksVersionRef.current) {
2271
2275
  lastTracksVersionRef.current = state.tracksVersion;
2272
2276
  engineTracksRef.current = state.tracks;
2277
+ const oldTracks = tracksRef.current;
2278
+ const oldStates = trackStatesRef.current;
2279
+ if (oldTracks.length === oldStates.length && oldTracks.length === state.tracks.length) {
2280
+ const idToState = new Map(oldTracks.map((t, i) => [t.id, oldStates[i]]));
2281
+ const reordered = state.tracks.map((t, i) => {
2282
+ var _a4;
2283
+ return (_a4 = idToState.get(t.id)) != null ? _a4 : oldStates[i];
2284
+ });
2285
+ const orderChanged = reordered.some((s, i) => s !== oldStates[i]);
2286
+ if (orderChanged) {
2287
+ setTrackStates(reordered);
2288
+ }
2289
+ }
2273
2290
  if (onTracksChange) {
2274
2291
  onTracksChange(state.tracks);
2275
2292
  } else {
@@ -2752,6 +2769,19 @@ var WaveformPlaylistProvider = ({
2752
2769
  },
2753
2770
  [trackStates]
2754
2771
  );
2772
+ const reorderTrack = (0, import_react17.useCallback)(
2773
+ (trackId, toIndex) => {
2774
+ if (!engineRef.current) {
2775
+ console.warn("[waveform-playlist] reorderTrack: engine not ready, call ignored");
2776
+ return;
2777
+ }
2778
+ engineRef.current.reorderTrack(trackId, toIndex);
2779
+ },
2780
+ [engineRef]
2781
+ );
2782
+ const bumpTrackReorderEpoch = (0, import_react17.useCallback)(() => {
2783
+ setTrackReorderEpoch((epoch) => epoch + 1);
2784
+ }, []);
2755
2785
  const setSelection = (0, import_react17.useCallback)(
2756
2786
  (start, end) => {
2757
2787
  setSelectionEngine(start, end);
@@ -2881,6 +2911,9 @@ var WaveformPlaylistProvider = ({
2881
2911
  setTrackSolo,
2882
2912
  setTrackVolume,
2883
2913
  setTrackPan,
2914
+ reorderTrack,
2915
+ bumpTrackReorderEpoch,
2916
+ setTrackDragPreview,
2884
2917
  // Selection
2885
2918
  setSelection,
2886
2919
  setSelectedTrackId: setSelectedTrackIdControl,
@@ -2923,6 +2956,9 @@ var WaveformPlaylistProvider = ({
2923
2956
  setTrackSolo,
2924
2957
  setTrackVolume,
2925
2958
  setTrackPan,
2959
+ reorderTrack,
2960
+ bumpTrackReorderEpoch,
2961
+ setTrackDragPreview,
2926
2962
  setSelection,
2927
2963
  setSelectedTrackIdControl,
2928
2964
  setTimeFormat,
@@ -2970,6 +3006,8 @@ var WaveformPlaylistProvider = ({
2970
3006
  roundedBars,
2971
3007
  progressBarWidth,
2972
3008
  isReady,
3009
+ trackReorderEpoch,
3010
+ trackDragPreview,
2973
3011
  mono,
2974
3012
  isDraggingRef,
2975
3013
  onTracksChange
@@ -2996,6 +3034,8 @@ var WaveformPlaylistProvider = ({
2996
3034
  roundedBars,
2997
3035
  progressBarWidth,
2998
3036
  isReady,
3037
+ trackReorderEpoch,
3038
+ trackDragPreview,
2999
3039
  mono,
3000
3040
  isDraggingRef,
3001
3041
  onTracksChange
@@ -3755,16 +3795,156 @@ function useClipInteractionEnabled() {
3755
3795
  }
3756
3796
 
3757
3797
  // src/components/PlaylistVisualization.tsx
3758
- var import_react26 = require("react");
3798
+ var import_react28 = require("react");
3759
3799
  var import_react_dom = require("react-dom");
3760
3800
  var import_styled_components6 = __toESM(require("styled-components"));
3761
3801
  var import_ui_components8 = require("@waveform-playlist/ui-components");
3802
+
3803
+ // src/components/SortableTrackControls.tsx
3804
+ var import_react23 = require("react");
3805
+ var import_sortable = require("@dnd-kit/react/sortable");
3806
+ var import_modifiers = require("@dnd-kit/abstract/modifiers");
3807
+ var import_dom2 = require("@dnd-kit/dom");
3808
+
3809
+ // src/utils/dragPopoverHealer.ts
3810
+ function createDragPopoverHealer(element) {
3811
+ if (typeof element.showPopover !== "function") {
3812
+ return () => {
3813
+ };
3814
+ }
3815
+ const heal = () => {
3816
+ if (!element.isConnected || !element.hasAttribute("popover")) return;
3817
+ let open = false;
3818
+ try {
3819
+ open = element.matches(":popover-open");
3820
+ } catch (e) {
3821
+ }
3822
+ if (open) return;
3823
+ try {
3824
+ element.showPopover();
3825
+ } catch (e) {
3826
+ }
3827
+ };
3828
+ const observer = new MutationObserver(heal);
3829
+ observer.observe(element.ownerDocument.body, {
3830
+ childList: true,
3831
+ subtree: true
3832
+ });
3833
+ return () => observer.disconnect();
3834
+ }
3835
+
3836
+ // src/components/SortableTrackControls.tsx
3837
+ var import_jsx_runtime7 = require("react/jsx-runtime");
3838
+ var MOVE_FEEDBACK = import_dom2.Feedback.configure({ feedback: "move" });
3839
+ var withMoveFeedback = (defaults) => [...defaults, MOVE_FEEDBACK];
3840
+ var SortableTrackControls = ({
3841
+ trackId,
3842
+ index,
3843
+ disabled = false,
3844
+ children
3845
+ }) => {
3846
+ const { ref, handleRef, isDragSource } = (0, import_sortable.useSortable)({
3847
+ id: `track-reorder-${trackId}`,
3848
+ index,
3849
+ group: "playlist-tracks",
3850
+ type: "track",
3851
+ accept: ["track"],
3852
+ data: { kind: "track-reorder", trackId },
3853
+ modifiers: [import_modifiers.RestrictToVerticalAxis],
3854
+ disabled,
3855
+ // Per-entity Feedback config (@dnd-kit 0.5+ moved `feedback` out of the
3856
+ // hook options into `plugins`). The FUNCTION form extends the sortable's
3857
+ // default plugins — a bare array would silently drop
3858
+ // OptimisticSortingPlugin, which drives the live `sortable.index` that
3859
+ // drag-commit reads (covered by sortableTrackControlsFeedbackPlugins.test).
3860
+ //
3861
+ // feedback: 'move' (NOT 'none' — see below) disables the Feedback
3862
+ // plugin's placeholder/clone splicing for this sortable while KEEPING its
3863
+ // dragOperation.shape computation alive. That plugin does raw,
3864
+ // React-bypassing DOM surgery on ANY pointer movement during an activated
3865
+ // drag (insertAdjacentElement to splice in a placeholder, then
3866
+ // `placeholder.replaceWith(element)` on drop) — confirmed via
3867
+ // MutationObserver instrumentation to relocate the React-owned row 6
3868
+ // times during a single one-slot drag, leaving its final parent/sibling
3869
+ // different from what React's fiber tree still believes. That desync is
3870
+ // permanent for the session: every later React-driven reorder (button OR
3871
+ // drag) computes the correct data but silently fails to update the DOM
3872
+ // for these rows. The placeholder splice is created only when
3873
+ // `feedback !== 'move'` (@dnd-kit/dom Feedback.ts) — 'move' keeps the
3874
+ // dragged element in the live DOM (no clone/placeholder) while still
3875
+ // running the *unconditional* `dragOperation.shape = ...` assignment.
3876
+ // `feedback: 'none'` looked like the boundary-trim precedent (Clip.tsx /
3877
+ // AnnotationBox.tsx) but is wrong here: 'none' bails out of Feedback's
3878
+ // render function BEFORE dragOperation.shape is ever set, and shape is
3879
+ // the ONLY input CollisionObserver.computeCollisions() checks — with
3880
+ // 'none', collision (and therefore sortable.index) never updates, so
3881
+ // drag-based reordering silently never commits. Boundary trims don't hit
3882
+ // this because they're plain useDraggable (no collision-based commit) —
3883
+ // sortables need shape. `isDragSource` (box-shadow lift feedback below)
3884
+ // is a reactive signal, unaffected either way. See browser/CLAUDE.md
3885
+ // "Track Reordering".
3886
+ plugins: withMoveFeedback
3887
+ });
3888
+ const elementRef = (0, import_react23.useRef)(null);
3889
+ const composedRef = (0, import_react23.useCallback)(
3890
+ (element) => {
3891
+ elementRef.current = element instanceof HTMLElement ? element : null;
3892
+ ref(element);
3893
+ },
3894
+ [ref]
3895
+ );
3896
+ (0, import_react23.useEffect)(() => {
3897
+ if (!isDragSource || !elementRef.current) return void 0;
3898
+ return createDragPopoverHealer(elementRef.current);
3899
+ }, [isDragSource]);
3900
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: children({ ref: composedRef, handleRef, isDragSource }) });
3901
+ };
3902
+
3903
+ // src/utils/trackOrderPreview.ts
3904
+ function applyTrackOrderPreview(tracks, preview) {
3905
+ if (!preview) return tracks;
3906
+ const fromIndex = tracks.findIndex((t) => t.id === preview.trackId);
3907
+ if (fromIndex === -1) return tracks;
3908
+ const toIndex = Math.max(0, Math.min(tracks.length - 1, preview.toIndex));
3909
+ if (toIndex === fromIndex) return tracks;
3910
+ const next = tracks.slice();
3911
+ const [moved] = next.splice(fromIndex, 1);
3912
+ next.splice(toIndex, 0, moved);
3913
+ return next;
3914
+ }
3915
+ function computeTrackLayout(orderedIds, heightById) {
3916
+ var _a;
3917
+ const topById = /* @__PURE__ */ new Map();
3918
+ let top = 0;
3919
+ for (const id of orderedIds) {
3920
+ topById.set(id, top);
3921
+ top += (_a = heightById.get(id)) != null ? _a : 0;
3922
+ }
3923
+ return { topById, totalHeight: top };
3924
+ }
3925
+
3926
+ // src/hooks/useTrailingActive.ts
3927
+ var import_react24 = require("react");
3928
+ function useTrailingActive(active, trailingMs) {
3929
+ const [trailing, setTrailing] = (0, import_react24.useState)(active);
3930
+ (0, import_react24.useEffect)(() => {
3931
+ if (active) {
3932
+ setTrailing(true);
3933
+ return void 0;
3934
+ }
3935
+ const timer = setTimeout(() => setTrailing(false), trailingMs);
3936
+ return () => clearTimeout(timer);
3937
+ }, [active, trailingMs]);
3938
+ return trailing || active;
3939
+ }
3940
+
3941
+ // src/components/PlaylistVisualization.tsx
3762
3942
  var import_core4 = require("@waveform-playlist/core");
3763
3943
 
3764
3944
  // src/components/AnimatedPlayhead.tsx
3765
- var import_react23 = require("react");
3945
+ var import_react25 = require("react");
3766
3946
  var import_styled_components4 = __toESM(require("styled-components"));
3767
- var import_jsx_runtime7 = require("react/jsx-runtime");
3947
+ var import_jsx_runtime8 = require("react/jsx-runtime");
3768
3948
  var PlayheadLine = import_styled_components4.default.div.attrs((props) => ({
3769
3949
  style: {
3770
3950
  width: `${props.$width}px`,
@@ -3780,7 +3960,7 @@ var PlayheadLine = import_styled_components4.default.div.attrs((props) => ({
3780
3960
  will-change: transform;
3781
3961
  `;
3782
3962
  var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3783
- const playheadRef = (0, import_react23.useRef)(null);
3963
+ const playheadRef = (0, import_react25.useRef)(null);
3784
3964
  const {
3785
3965
  isPlaying,
3786
3966
  currentTimeRef,
@@ -3789,7 +3969,7 @@ var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3789
3969
  unregisterFrameCallback
3790
3970
  } = usePlaybackAnimation();
3791
3971
  const { samplesPerPixel, sampleRate, progressBarWidth } = usePlaylistData();
3792
- (0, import_react23.useEffect)(() => {
3972
+ (0, import_react25.useEffect)(() => {
3793
3973
  const id = "playhead";
3794
3974
  if (isPlaying) {
3795
3975
  registerFrameCallback(id, ({ visualTime, sampleRate: sr, samplesPerPixel: spp }) => {
@@ -3801,7 +3981,7 @@ var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3801
3981
  }
3802
3982
  return () => unregisterFrameCallback(id);
3803
3983
  }, [isPlaying, registerFrameCallback, unregisterFrameCallback]);
3804
- (0, import_react23.useEffect)(() => {
3984
+ (0, import_react25.useEffect)(() => {
3805
3985
  var _a, _b;
3806
3986
  if (!isPlaying && playheadRef.current) {
3807
3987
  const time = (_b = (_a = visualTimeRef.current) != null ? _a : currentTimeRef.current) != null ? _b : 0;
@@ -3809,15 +3989,15 @@ var AnimatedPlayhead = ({ color = "#ff0000" }) => {
3809
3989
  playheadRef.current.style.transform = `translate3d(${position}px, 0, 0)`;
3810
3990
  }
3811
3991
  });
3812
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PlayheadLine, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
3992
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PlayheadLine, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
3813
3993
  };
3814
3994
 
3815
3995
  // src/components/ChannelWithProgress.tsx
3816
- var import_react24 = require("react");
3996
+ var import_react26 = require("react");
3817
3997
  var import_styled_components5 = __toESM(require("styled-components"));
3818
3998
  var import_core3 = require("@waveform-playlist/core");
3819
3999
  var import_ui_components7 = require("@waveform-playlist/ui-components");
3820
- var import_jsx_runtime8 = require("react/jsx-runtime");
4000
+ var import_jsx_runtime9 = require("react/jsx-runtime");
3821
4001
  var ChannelWrapper = import_styled_components5.default.div`
3822
4002
  position: relative;
3823
4003
  `;
@@ -3871,8 +4051,8 @@ var ChannelWithProgress = (_a) => {
3871
4051
  "clipSampleRate",
3872
4052
  "clipOffsetSeconds"
3873
4053
  ]);
3874
- const progressRef = (0, import_react24.useRef)(null);
3875
- const callbackId = (0, import_react24.useId)();
4054
+ const progressRef = (0, import_react26.useRef)(null);
4055
+ const callbackId = (0, import_react26.useId)();
3876
4056
  const theme = (0, import_ui_components7.useTheme)();
3877
4057
  const { waveHeight } = (0, import_ui_components7.usePlaylistInfo)();
3878
4058
  const {
@@ -3889,7 +4069,7 @@ var ChannelWithProgress = (_a) => {
3889
4069
  clipDurationSamples,
3890
4070
  samplesPerPixel
3891
4071
  );
3892
- (0, import_react24.useEffect)(() => {
4072
+ (0, import_react26.useEffect)(() => {
3893
4073
  if (isPlaying) {
3894
4074
  registerFrameCallback(callbackId, ({ visualTime, sampleRate: sr }) => {
3895
4075
  if (progressRef.current) {
@@ -3917,7 +4097,7 @@ var ChannelWithProgress = (_a) => {
3917
4097
  registerFrameCallback,
3918
4098
  unregisterFrameCallback
3919
4099
  ]);
3920
- (0, import_react24.useEffect)(() => {
4100
+ (0, import_react26.useEffect)(() => {
3921
4101
  var _a2, _b2;
3922
4102
  if (!isPlaying && progressRef.current) {
3923
4103
  const currentTime = (_b2 = (_a2 = visualTimeRef.current) != null ? _a2 : currentTimeRef.current) != null ? _b2 : 0;
@@ -3950,9 +4130,9 @@ var ChannelWithProgress = (_a) => {
3950
4130
  const effectiveHeight = waveHeight;
3951
4131
  const effectiveTop = isBothMode ? smartChannelProps.index * waveHeight : smartChannelProps.index * waveHeight;
3952
4132
  const waveformBackgroundCss = (0, import_ui_components7.waveformColorToCss)(backgroundColor);
3953
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(ChannelWrapper, { children: [
3954
- isBothMode ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
3955
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4133
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(ChannelWrapper, { children: [
4134
+ isBothMode ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
4135
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3956
4136
  Background,
3957
4137
  {
3958
4138
  $color: "#000",
@@ -3961,7 +4141,7 @@ var ChannelWithProgress = (_a) => {
3961
4141
  $width: smartChannelProps.length
3962
4142
  }
3963
4143
  ),
3964
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4144
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3965
4145
  Background,
3966
4146
  {
3967
4147
  $color: waveformBackgroundCss,
@@ -3970,7 +4150,7 @@ var ChannelWithProgress = (_a) => {
3970
4150
  $width: smartChannelProps.length
3971
4151
  }
3972
4152
  )
3973
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4153
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3974
4154
  Background,
3975
4155
  {
3976
4156
  $color: backgroundCss,
@@ -3979,7 +4159,7 @@ var ChannelWithProgress = (_a) => {
3979
4159
  $width: smartChannelProps.length
3980
4160
  }
3981
4161
  ),
3982
- !isPianoRollMode && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4162
+ !isPianoRollMode && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3983
4163
  ProgressOverlay,
3984
4164
  {
3985
4165
  ref: progressRef,
@@ -3989,7 +4169,7 @@ var ChannelWithProgress = (_a) => {
3989
4169
  $width: clipPixelWidth
3990
4170
  }
3991
4171
  ),
3992
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ChannelContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4172
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ChannelContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3993
4173
  import_ui_components7.SmartChannel,
3994
4174
  __spreadProps(__spreadValues({}, smartChannelProps), {
3995
4175
  transparentBackground: true,
@@ -4002,11 +4182,11 @@ var ChannelWithProgress = (_a) => {
4002
4182
  };
4003
4183
 
4004
4184
  // src/SpectrogramIntegrationContext.tsx
4005
- var import_react25 = require("react");
4006
- var SpectrogramIntegrationContext = (0, import_react25.createContext)(null);
4185
+ var import_react27 = require("react");
4186
+ var SpectrogramIntegrationContext = (0, import_react27.createContext)(null);
4007
4187
  var SpectrogramIntegrationProvider = SpectrogramIntegrationContext.Provider;
4008
4188
  function useSpectrogramIntegration() {
4009
- const context = (0, import_react25.useContext)(SpectrogramIntegrationContext);
4189
+ const context = (0, import_react27.useContext)(SpectrogramIntegrationContext);
4010
4190
  if (!context) {
4011
4191
  throw new Error(
4012
4192
  "useSpectrogramIntegration must be used within <SpectrogramProvider>. Install @waveform-playlist/spectrogram and wrap your app with <SpectrogramProvider>."
@@ -4016,15 +4196,42 @@ function useSpectrogramIntegration() {
4016
4196
  }
4017
4197
 
4018
4198
  // src/components/PlaylistVisualization.tsx
4019
- var import_jsx_runtime9 = require("react/jsx-runtime");
4199
+ var import_jsx_runtime10 = require("react/jsx-runtime");
4020
4200
  var DEFAULT_EMPTY_TRACK_DURATION = 60;
4021
- var ControlSlot = import_styled_components6.default.div.attrs((props) => ({
4201
+ var DRAG_SOURCE_SHADOW = "0 4px 12px rgba(0, 0, 0, 0.35)";
4202
+ var TracksLayout = import_styled_components6.default.div.attrs((props) => ({
4022
4203
  style: { height: `${props.$height}px` }
4023
4204
  }))`
4205
+ position: relative;
4206
+ `;
4207
+ var TrackRowPositioner = import_styled_components6.default.div.attrs((props) => ({
4208
+ style: { top: `${props.$top}px` }
4209
+ }))`
4210
+ position: absolute;
4211
+ left: 0;
4212
+ right: 0;
4213
+ ${(props) => props.$animate && "transition: top 150ms ease;"}
4214
+ @media (prefers-reduced-motion: reduce) {
4215
+ transition: none;
4216
+ }
4217
+ `;
4218
+ var ControlSlot = import_styled_components6.default.div.attrs((props) => ({
4219
+ style: {
4220
+ height: `${props.$height}px`,
4221
+ top: `${props.$top}px`
4222
+ }
4223
+ }))`
4224
+ position: absolute;
4225
+ left: 0;
4226
+ right: 0;
4024
4227
  overflow: hidden;
4025
4228
  pointer-events: auto;
4026
4229
  background: ${(props) => props.theme.surfaceColor};
4027
4230
  transition: background 0.15s ease-in-out;
4231
+ ${(props) => props.$animate && "transition: top 150ms ease, background 0.15s ease-in-out;"}
4232
+ @media (prefers-reduced-motion: reduce) {
4233
+ transition: background 0.15s ease-in-out;
4234
+ }
4028
4235
  ${(props) => props.$isSelected && `background: ${props.theme.selectedTrackControlsBackground};`}
4029
4236
  `;
4030
4237
  var CustomPlayhead = ({ renderPlayhead, color, samplesPerPixel, sampleRate }) => {
@@ -4059,6 +4266,133 @@ function getTrackChannelCount(trackClipPeaks, recordingState, trackId, mono) {
4059
4266
  const recordingChannels = (recordingState == null ? void 0 : recordingState.isRecording) && recordingState.trackId === trackId ? mono ? 1 : recordingState.peaks.length : 0;
4060
4267
  return Math.max(clipChannels, recordingChannels);
4061
4268
  }
4269
+ function DefaultTrackControls({
4270
+ trackIndex,
4271
+ track,
4272
+ trackState,
4273
+ effectiveRenderMode,
4274
+ selectTrack,
4275
+ onRemoveTrack,
4276
+ setTrackMute,
4277
+ setTrackSolo,
4278
+ setTrackVolume,
4279
+ setTrackPan,
4280
+ spectrogram,
4281
+ setSettingsModalTrackId,
4282
+ trackReordering,
4283
+ reorderTrack,
4284
+ trackCount,
4285
+ gripRef
4286
+ }) {
4287
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
4288
+ import_ui_components8.Controls,
4289
+ {
4290
+ onClick: () => selectTrack(trackIndex),
4291
+ style: trackReordering ? { position: "relative", paddingLeft: 18, paddingRight: 18 } : void 0,
4292
+ children: [
4293
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui_components8.Header, { style: { justifyContent: "center", position: "relative" }, children: [
4294
+ onRemoveTrack && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4295
+ import_ui_components8.CloseButton,
4296
+ {
4297
+ onClick: (e) => {
4298
+ e.stopPropagation();
4299
+ onRemoveTrack(trackIndex);
4300
+ }
4301
+ }
4302
+ ),
4303
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4304
+ "span",
4305
+ {
4306
+ style: {
4307
+ overflow: "hidden",
4308
+ textOverflow: "ellipsis",
4309
+ whiteSpace: "nowrap",
4310
+ padding: "0 24px",
4311
+ display: "block"
4312
+ },
4313
+ children: trackState.name || `Track ${trackIndex + 1}`
4314
+ }
4315
+ ),
4316
+ (spectrogram == null ? void 0 : spectrogram.renderMenuItems) && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { style: { position: "absolute", right: 0, top: 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4317
+ import_ui_components8.TrackMenu,
4318
+ {
4319
+ items: (onClose) => spectrogram.renderMenuItems({
4320
+ renderMode: effectiveRenderMode,
4321
+ onRenderModeChange: (mode) => spectrogram.setTrackRenderMode(track.id, mode),
4322
+ onOpenSettings: () => setSettingsModalTrackId(track.id),
4323
+ onClose
4324
+ })
4325
+ }
4326
+ ) })
4327
+ ] }),
4328
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui_components8.ButtonGroup, { children: [
4329
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4330
+ import_ui_components8.Button,
4331
+ {
4332
+ $variant: trackState.muted ? "danger" : "outline",
4333
+ onClick: () => setTrackMute(trackIndex, !trackState.muted),
4334
+ children: "Mute"
4335
+ }
4336
+ ),
4337
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4338
+ import_ui_components8.Button,
4339
+ {
4340
+ $variant: trackState.soloed ? "info" : "outline",
4341
+ onClick: () => setTrackSolo(trackIndex, !trackState.soloed),
4342
+ children: "Solo"
4343
+ }
4344
+ )
4345
+ ] }),
4346
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui_components8.SliderWrapper, { children: [
4347
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui_components8.VolumeDownIcon, {}),
4348
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4349
+ import_ui_components8.Slider,
4350
+ {
4351
+ min: "0",
4352
+ max: "1",
4353
+ step: "0.01",
4354
+ value: trackState.volume,
4355
+ onChange: (e) => setTrackVolume(trackIndex, parseFloat(e.target.value))
4356
+ }
4357
+ ),
4358
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui_components8.VolumeUpIcon, {})
4359
+ ] }),
4360
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui_components8.SliderWrapper, { children: [
4361
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "L" }),
4362
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4363
+ import_ui_components8.Slider,
4364
+ {
4365
+ min: "-1",
4366
+ max: "1",
4367
+ step: "0.01",
4368
+ value: trackState.pan,
4369
+ onChange: (e) => setTrackPan(trackIndex, parseFloat(e.target.value))
4370
+ }
4371
+ ),
4372
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "R" })
4373
+ ] }),
4374
+ trackReordering && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4375
+ import_ui_components8.ReorderRail,
4376
+ {
4377
+ style: { position: "absolute", right: 2, top: "50%", transform: "translateY(-50%)" },
4378
+ gripRef,
4379
+ onGripClick: (e) => e.stopPropagation(),
4380
+ upDisabled: trackIndex === 0,
4381
+ downDisabled: trackIndex === trackCount - 1,
4382
+ onMoveUp: (e) => {
4383
+ e.stopPropagation();
4384
+ reorderTrack(track.id, trackIndex - 1);
4385
+ },
4386
+ onMoveDown: (e) => {
4387
+ e.stopPropagation();
4388
+ reorderTrack(track.id, trackIndex + 1);
4389
+ }
4390
+ }
4391
+ )
4392
+ ]
4393
+ }
4394
+ );
4395
+ }
4062
4396
  var PlaylistVisualization = ({
4063
4397
  renderTrackControls,
4064
4398
  renderTick,
@@ -4071,7 +4405,8 @@ var PlaylistVisualization = ({
4071
4405
  showFades = false,
4072
4406
  touchOptimized = false,
4073
4407
  onRemoveTrack,
4074
- recordingState
4408
+ recordingState,
4409
+ trackReordering = false
4075
4410
  }) => {
4076
4411
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
4077
4412
  const theme = (0, import_ui_components8.useTheme)();
@@ -4091,7 +4426,7 @@ var PlaylistVisualization = ({
4091
4426
  indefinitePlayback,
4092
4427
  fillViewport
4093
4428
  } = usePlaylistState();
4094
- const annotationIntegration = (0, import_react26.useContext)(AnnotationIntegrationContext);
4429
+ const annotationIntegration = (0, import_react28.useContext)(AnnotationIntegrationContext);
4095
4430
  const {
4096
4431
  setAnnotations: _setAnnotations,
4097
4432
  setActiveAnnotationId,
@@ -4105,7 +4440,8 @@ var PlaylistVisualization = ({
4105
4440
  setSelectedTrackId,
4106
4441
  setCurrentTime,
4107
4442
  setLoopRegion,
4108
- setRecordingActive
4443
+ setRecordingActive,
4444
+ reorderTrack
4109
4445
  } = usePlaylistControls();
4110
4446
  const {
4111
4447
  peaksDataArray,
@@ -4121,17 +4457,19 @@ var PlaylistVisualization = ({
4121
4457
  barGap,
4122
4458
  roundedBars,
4123
4459
  isReady,
4124
- mono
4460
+ trackReorderEpoch,
4461
+ mono,
4462
+ trackDragPreview
4125
4463
  } = usePlaylistData();
4126
- const spectrogram = (0, import_react26.useContext)(SpectrogramIntegrationContext);
4464
+ const spectrogram = (0, import_react28.useContext)(SpectrogramIntegrationContext);
4127
4465
  const recordingActive = !!(recordingState == null ? void 0 : recordingState.isRecording);
4128
4466
  const armedTrackId = (_a = recordingState == null ? void 0 : recordingState.trackId) != null ? _a : null;
4129
- (0, import_react26.useEffect)(() => {
4467
+ (0, import_react28.useEffect)(() => {
4130
4468
  if (!recordingActive) return void 0;
4131
4469
  setRecordingActive(true, armedTrackId);
4132
4470
  return () => setRecordingActive(false);
4133
4471
  }, [recordingActive, armedTrackId, setRecordingActive]);
4134
- const perTrackSpectrogramHelpers = (0, import_react26.useMemo)(() => {
4472
+ const perTrackSpectrogramHelpers = (0, import_react28.useMemo)(() => {
4135
4473
  if (!spectrogram)
4136
4474
  return /* @__PURE__ */ new Map();
4137
4475
  const helpers = /* @__PURE__ */ new Map();
@@ -4150,11 +4488,11 @@ var PlaylistVisualization = ({
4150
4488
  });
4151
4489
  return helpers;
4152
4490
  }, [tracks, spectrogram]);
4153
- const [settingsModalTrackId, setSettingsModalTrackId] = (0, import_react26.useState)(null);
4154
- const [isSelecting, setIsSelecting] = (0, import_react26.useState)(false);
4155
- const mouseDownTimeRef = (0, import_react26.useRef)(0);
4156
- const scrollContainerRef = (0, import_react26.useRef)(null);
4157
- const handleScrollContainerRef = (0, import_react26.useCallback)(
4491
+ const [settingsModalTrackId, setSettingsModalTrackId] = (0, import_react28.useState)(null);
4492
+ const [isSelecting, setIsSelecting] = (0, import_react28.useState)(false);
4493
+ const mouseDownTimeRef = (0, import_react28.useRef)(0);
4494
+ const scrollContainerRef = (0, import_react28.useRef)(null);
4495
+ const handleScrollContainerRef = (0, import_react28.useCallback)(
4158
4496
  (element) => {
4159
4497
  scrollContainerRef.current = element;
4160
4498
  setScrollContainer(element);
@@ -4192,7 +4530,7 @@ var PlaylistVisualization = ({
4192
4530
  );
4193
4531
  }
4194
4532
  });
4195
- const selectTrack = (0, import_react26.useCallback)(
4533
+ const selectTrack = (0, import_react28.useCallback)(
4196
4534
  (trackIndex) => {
4197
4535
  if (trackIndex >= 0 && trackIndex < tracks.length) {
4198
4536
  const track = tracks[trackIndex];
@@ -4260,120 +4598,99 @@ var PlaylistVisualization = ({
4260
4598
  setSelection(start, end);
4261
4599
  }
4262
4600
  };
4601
+ const trackHeightById = (0, import_react28.useMemo)(() => {
4602
+ const m = /* @__PURE__ */ new Map();
4603
+ peaksDataArray.forEach((trackClipPeaks, trackIndex) => {
4604
+ const track = tracks[trackIndex];
4605
+ if (!track) return;
4606
+ const maxChannels = getTrackChannelCount(trackClipPeaks, recordingState, track.id, mono);
4607
+ m.set(track.id, waveHeight * maxChannels + (showClipHeaders ? import_ui_components8.CLIP_HEADER_HEIGHT : 0));
4608
+ });
4609
+ return m;
4610
+ }, [peaksDataArray, tracks, recordingState, mono, waveHeight, showClipHeaders]);
4611
+ const displayOrderIds = (0, import_react28.useMemo)(
4612
+ () => applyTrackOrderPreview(tracks, trackDragPreview).map((t) => t.id),
4613
+ [tracks, trackDragPreview]
4614
+ );
4615
+ const trackLayout = (0, import_react28.useMemo)(
4616
+ () => computeTrackLayout(displayOrderIds, trackHeightById),
4617
+ [displayOrderIds, trackHeightById]
4618
+ );
4619
+ const animateTrackLayout = useTrailingActive(trackDragPreview !== null, 200);
4263
4620
  const hasClips = tracks.some((track) => track.clips.length > 0);
4264
4621
  if (hasClips && peaksDataArray.length === 0) {
4265
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className, children: "Loading waveform..." });
4622
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className, children: "Loading waveform..." });
4266
4623
  }
4267
- const trackControlsSlots = controls.show ? peaksDataArray.map((trackClipPeaks, trackIndex) => {
4268
- var _a2, _b2, _c2;
4269
- const track = tracks[trackIndex];
4270
- if (!track) return null;
4271
- const trackState = trackStates[trackIndex] || {
4272
- name: `Track ${trackIndex + 1}`,
4273
- muted: false,
4274
- soloed: false,
4275
- volume: 1,
4276
- pan: 0
4277
- };
4278
- const hasMidiNotes = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
4279
- 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";
4280
- const maxChannels = getTrackChannelCount(trackClipPeaks, recordingState, track.id, mono);
4281
- const slotHeight = waveHeight * maxChannels + (showClipHeaders ? import_ui_components8.CLIP_HEADER_HEIGHT : 0);
4282
- const trackControlContent = renderTrackControls ? renderTrackControls(trackIndex) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.Controls, { onClick: () => selectTrack(trackIndex), children: [
4283
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.Header, { style: { justifyContent: "center", position: "relative" }, children: [
4284
- onRemoveTrack && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4285
- import_ui_components8.CloseButton,
4286
- {
4287
- onClick: (e) => {
4288
- e.stopPropagation();
4289
- onRemoveTrack(trackIndex);
4290
- }
4291
- }
4292
- ),
4293
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4294
- "span",
4295
- {
4296
- style: {
4297
- overflow: "hidden",
4298
- textOverflow: "ellipsis",
4299
- whiteSpace: "nowrap",
4300
- padding: "0 24px",
4301
- display: "block"
4302
- },
4303
- children: trackState.name || `Track ${trackIndex + 1}`
4304
- }
4305
- ),
4306
- (spectrogram == null ? void 0 : spectrogram.renderMenuItems) && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { style: { position: "absolute", right: 0, top: 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4307
- import_ui_components8.TrackMenu,
4308
- {
4309
- items: (onClose) => spectrogram.renderMenuItems({
4310
- renderMode: effectiveRenderMode,
4311
- onRenderModeChange: (mode) => spectrogram.setTrackRenderMode(track.id, mode),
4312
- onOpenSettings: () => setSettingsModalTrackId(track.id),
4313
- onClose
4314
- })
4315
- }
4316
- ) })
4317
- ] }),
4318
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.ButtonGroup, { children: [
4319
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4320
- import_ui_components8.Button,
4321
- {
4322
- $variant: trackState.muted ? "danger" : "outline",
4323
- onClick: () => setTrackMute(trackIndex, !trackState.muted),
4324
- children: "Mute"
4325
- }
4326
- ),
4327
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4328
- import_ui_components8.Button,
4624
+ const trackControlsSlots = controls.show ? [
4625
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TracksLayout, { $height: trackLayout.totalHeight, children: peaksDataArray.map((trackClipPeaks, trackIndex) => {
4626
+ var _a2, _b2, _c2, _d2, _e2;
4627
+ const track = tracks[trackIndex];
4628
+ if (!track) return null;
4629
+ const trackState = trackStates[trackIndex] || {
4630
+ name: `Track ${trackIndex + 1}`,
4631
+ muted: false,
4632
+ soloed: false,
4633
+ volume: 1,
4634
+ pan: 0
4635
+ };
4636
+ const hasMidiNotes = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
4637
+ 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";
4638
+ const slotHeight = (_d2 = trackHeightById.get(track.id)) != null ? _d2 : 0;
4639
+ const defaultControlProps = {
4640
+ trackIndex,
4641
+ track,
4642
+ trackState,
4643
+ effectiveRenderMode,
4644
+ selectTrack,
4645
+ onRemoveTrack,
4646
+ setTrackMute,
4647
+ setTrackSolo,
4648
+ setTrackVolume,
4649
+ setTrackPan,
4650
+ spectrogram,
4651
+ setSettingsModalTrackId,
4652
+ trackReordering,
4653
+ reorderTrack,
4654
+ trackCount: peaksDataArray.length
4655
+ };
4656
+ const trackControlContent = renderTrackControls ? renderTrackControls(trackIndex) : trackReordering ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SortableTrackControls, { trackId: track.id, index: trackIndex, children: ({ ref, handleRef, isDragSource }) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4657
+ "div",
4658
+ {
4659
+ ref,
4660
+ style: {
4661
+ height: "100%",
4662
+ boxShadow: isDragSource ? DRAG_SOURCE_SHADOW : void 0,
4663
+ // Opaque background for the floating (top-layer, popover-based)
4664
+ // drag-source row — without it the row underneath shows through.
4665
+ // onDragStart selects the dragged track, so its slot always shows
4666
+ // the selected-track background while lifted.
4667
+ background: isDragSource ? theme.selectedTrackControlsBackground : void 0
4668
+ },
4669
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(DefaultTrackControls, __spreadProps(__spreadValues({}, defaultControlProps), { gripRef: handleRef }))
4670
+ }
4671
+ ) }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(DefaultTrackControls, __spreadValues({}, defaultControlProps));
4672
+ return (
4673
+ // key includes trackReorderEpoch: forces a remount after every
4674
+ // track-reorder drag, discarding @dnd-kit sortable-plugin DOM
4675
+ // corruption (see bumpTrackReorderEpoch's doc comment in
4676
+ // WaveformPlaylistContext). Stays at `-0` — a no-op suffix — for
4677
+ // consumers that never enable trackReordering.
4678
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4679
+ ControlSlot,
4329
4680
  {
4330
- $variant: trackState.soloed ? "info" : "outline",
4331
- onClick: () => setTrackSolo(trackIndex, !trackState.soloed),
4332
- children: "Solo"
4333
- }
4681
+ $height: slotHeight,
4682
+ $top: (_e2 = trackLayout.topById.get(track.id)) != null ? _e2 : 0,
4683
+ $animate: animateTrackLayout,
4684
+ $isSelected: track.id === selectedTrackId,
4685
+ children: trackControlContent
4686
+ },
4687
+ `${track.id}-${trackReorderEpoch}`
4334
4688
  )
4335
- ] }),
4336
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.SliderWrapper, { children: [
4337
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui_components8.VolumeDownIcon, {}),
4338
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4339
- import_ui_components8.Slider,
4340
- {
4341
- min: "0",
4342
- max: "1",
4343
- step: "0.01",
4344
- value: trackState.volume,
4345
- onChange: (e) => setTrackVolume(trackIndex, parseFloat(e.target.value))
4346
- }
4347
- ),
4348
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui_components8.VolumeUpIcon, {})
4349
- ] }),
4350
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.SliderWrapper, { children: [
4351
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "L" }),
4352
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4353
- import_ui_components8.Slider,
4354
- {
4355
- min: "-1",
4356
- max: "1",
4357
- step: "0.01",
4358
- value: trackState.pan,
4359
- onChange: (e) => setTrackPan(trackIndex, parseFloat(e.target.value))
4360
- }
4361
- ),
4362
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "R" })
4363
- ] })
4364
- ] });
4365
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4366
- ControlSlot,
4367
- {
4368
- $height: slotHeight,
4369
- $isSelected: track.id === selectedTrackId,
4370
- children: trackControlContent
4371
- },
4372
- track.id
4373
- );
4374
- }) : void 0;
4375
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.DevicePixelRatioProvider, { children: [
4376
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4689
+ );
4690
+ }) }, "control-slots-layout")
4691
+ ] : void 0;
4692
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_ui_components8.DevicePixelRatioProvider, { children: [
4693
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4377
4694
  import_ui_components8.PlaylistInfoContext.Provider,
4378
4695
  {
4379
4696
  value: {
@@ -4388,7 +4705,7 @@ var PlaylistVisualization = ({
4388
4705
  barGap,
4389
4706
  roundedBars
4390
4707
  },
4391
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4708
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4392
4709
  import_ui_components8.Playlist,
4393
4710
  {
4394
4711
  theme,
@@ -4405,9 +4722,9 @@ var PlaylistVisualization = ({
4405
4722
  "data-playlist-state": isReady ? "ready" : "loading",
4406
4723
  trackControlsSlots,
4407
4724
  timescaleGapHeight: timeScaleHeight > 0 ? timeScaleHeight + 1 : 0,
4408
- timescale: timeScaleHeight > 0 ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
4409
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui_components8.SmartScale, { renderTick }),
4410
- isLoopEnabled && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4725
+ timescale: timeScaleHeight > 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
4726
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ui_components8.SmartScale, { renderTick }),
4727
+ isLoopEnabled && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4411
4728
  import_ui_components8.TimescaleLoopRegion,
4412
4729
  {
4413
4730
  startPosition: Math.min(loopStart, loopEnd) * sampleRate / samplesPerPixel,
@@ -4424,9 +4741,9 @@ var PlaylistVisualization = ({
4424
4741
  }
4425
4742
  )
4426
4743
  ] }) : void 0,
4427
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
4428
- peaksDataArray.map((trackClipPeaks, trackIndex) => {
4429
- var _a2, _b2, _c2, _d2;
4744
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
4745
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TracksLayout, { $height: trackLayout.totalHeight, children: peaksDataArray.map((trackClipPeaks, trackIndex) => {
4746
+ var _a2, _b2, _c2, _d2, _e2;
4430
4747
  const track = tracks[trackIndex];
4431
4748
  if (!track) return null;
4432
4749
  const hasMidiNotes = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
@@ -4437,153 +4754,163 @@ var PlaylistVisualization = ({
4437
4754
  track.id,
4438
4755
  mono
4439
4756
  );
4440
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
4441
- import_ui_components8.Track,
4757
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4758
+ TrackRowPositioner,
4442
4759
  {
4443
- numChannels: maxChannels,
4444
- backgroundColor: effectiveRenderMode === "piano-roll" ? theme.pianoRollBackgroundColor || "#1a1a2e" : (0, import_ui_components8.waveformColorToCss)(theme.waveOutlineColor),
4445
- offset: 0,
4446
- width: tracksFullWidth,
4447
- hasClipHeaders: showClipHeaders,
4448
- trackId: track.id,
4449
- isSelected: track.id === selectedTrackId,
4450
- children: [
4451
- effectiveRenderMode !== "waveform" && (() => {
4452
- var _a3, _b3;
4453
- const helpers = perTrackSpectrogramHelpers.get(track.id);
4454
- const trackCfg = helpers == null ? void 0 : helpers.config;
4455
- if (!(trackCfg == null ? void 0 : trackCfg.labels) || !helpers) return null;
4456
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4457
- import_ui_components8.SpectrogramLabels,
4458
- {
4459
- waveHeight,
4460
- numChannels: maxChannels,
4461
- frequencyScaleFn: helpers.frequencyScaleFn,
4462
- minFrequency: (_a3 = trackCfg.minFrequency) != null ? _a3 : 0,
4463
- maxFrequency: (_b3 = trackCfg.maxFrequency) != null ? _b3 : sampleRate / 2,
4464
- labelsColor: trackCfg.labelsColor,
4465
- labelsBackground: trackCfg.labelsBackground,
4466
- renderMode: effectiveRenderMode,
4467
- hasClipHeaders: showClipHeaders
4468
- }
4469
- );
4470
- })(),
4471
- trackClipPeaks.map((clip, clipIndex) => {
4472
- const peaksData = clip.peaks;
4473
- const width = peaksData.length;
4474
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4475
- import_ui_components8.Clip,
4476
- {
4477
- clipId: clip.clipId,
4478
- trackIndex,
4479
- clipIndex,
4480
- trackName: clip.trackName,
4481
- startSample: clip.startSample,
4482
- durationSamples: clip.durationSamples,
4483
- samplesPerPixel,
4484
- showHeader: showClipHeaders,
4485
- disableHeaderDrag: !interactiveClips,
4486
- isSelected: track.id === selectedTrackId,
4487
- trackId: track.id,
4488
- fadeIn: clip.fadeIn,
4489
- fadeOut: clip.fadeOut,
4490
- sampleRate,
4491
- showFades,
4492
- touchOptimized,
4493
- onMouseDown: (e) => {
4494
- const target = e.target;
4495
- const isDraggable = target.closest(
4496
- '[role="button"][aria-roledescription="draggable"]'
4497
- );
4498
- if (isDraggable) {
4499
- return;
4760
+ $top: (_d2 = trackLayout.topById.get(track.id)) != null ? _d2 : 0,
4761
+ $animate: animateTrackLayout,
4762
+ "data-track-row": "",
4763
+ "data-track-id": track.id,
4764
+ "data-track-drag-source": (trackDragPreview == null ? void 0 : trackDragPreview.trackId) === track.id ? "true" : void 0,
4765
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
4766
+ import_ui_components8.Track,
4767
+ {
4768
+ numChannels: maxChannels,
4769
+ backgroundColor: effectiveRenderMode === "piano-roll" ? theme.pianoRollBackgroundColor || "#1a1a2e" : (0, import_ui_components8.waveformColorToCss)(theme.waveOutlineColor),
4770
+ offset: 0,
4771
+ width: tracksFullWidth,
4772
+ hasClipHeaders: showClipHeaders,
4773
+ trackId: track.id,
4774
+ isSelected: track.id === selectedTrackId,
4775
+ children: [
4776
+ effectiveRenderMode !== "waveform" && (() => {
4777
+ var _a3, _b3;
4778
+ const helpers = perTrackSpectrogramHelpers.get(track.id);
4779
+ const trackCfg = helpers == null ? void 0 : helpers.config;
4780
+ if (!(trackCfg == null ? void 0 : trackCfg.labels) || !helpers) return null;
4781
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4782
+ import_ui_components8.SpectrogramLabels,
4783
+ {
4784
+ waveHeight,
4785
+ numChannels: maxChannels,
4786
+ frequencyScaleFn: helpers.frequencyScaleFn,
4787
+ minFrequency: (_a3 = trackCfg.minFrequency) != null ? _a3 : 0,
4788
+ maxFrequency: (_b3 = trackCfg.maxFrequency) != null ? _b3 : sampleRate / 2,
4789
+ labelsColor: trackCfg.labelsColor,
4790
+ labelsBackground: trackCfg.labelsBackground,
4791
+ renderMode: effectiveRenderMode,
4792
+ hasClipHeaders: showClipHeaders
4500
4793
  }
4501
- selectTrack(trackIndex);
4502
- },
4503
- children: peaksData.data.map((channelPeaks, channelIndex) => {
4504
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4505
- ChannelWithProgress,
4506
- {
4507
- index: channelIndex,
4508
- data: channelPeaks,
4509
- bits: peaksData.bits,
4510
- length: width,
4511
- isSelected: track.id === selectedTrackId,
4512
- clipStartSample: clip.startSample,
4513
- clipDurationSamples: clip.durationSamples,
4514
- renderMode: clip.midiNotes ? "piano-roll" : effectiveRenderMode,
4515
- midiNotes: clip.midiNotes,
4516
- clipSampleRate: clip.sampleRate,
4517
- clipOffsetSeconds: clip.offsetSamples != null ? clip.offsetSamples / (clip.sampleRate || sampleRate) : 0,
4518
- samplesPerPixel,
4519
- spectrogramClipId: clip.clipId,
4520
- spectrogramOnCanvasRegister: spectrogram ? spectrogram.registerSpectrogramCanvas : void 0,
4521
- spectrogramOnCanvasUnregister: spectrogram ? spectrogram.unregisterSpectrogramCanvas : void 0
4794
+ );
4795
+ })(),
4796
+ trackClipPeaks.map((clip, clipIndex) => {
4797
+ const peaksData = clip.peaks;
4798
+ const width = peaksData.length;
4799
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4800
+ import_ui_components8.Clip,
4801
+ {
4802
+ clipId: clip.clipId,
4803
+ trackIndex,
4804
+ clipIndex,
4805
+ trackName: clip.trackName,
4806
+ startSample: clip.startSample,
4807
+ durationSamples: clip.durationSamples,
4808
+ samplesPerPixel,
4809
+ showHeader: showClipHeaders,
4810
+ disableHeaderDrag: !interactiveClips,
4811
+ isSelected: track.id === selectedTrackId,
4812
+ trackId: track.id,
4813
+ fadeIn: clip.fadeIn,
4814
+ fadeOut: clip.fadeOut,
4815
+ sampleRate,
4816
+ showFades,
4817
+ touchOptimized,
4818
+ onMouseDown: (e) => {
4819
+ const target = e.target;
4820
+ const isDraggable = target.closest(
4821
+ '[role="button"][aria-roledescription="draggable"]'
4822
+ );
4823
+ if (isDraggable) {
4824
+ return;
4825
+ }
4826
+ selectTrack(trackIndex);
4522
4827
  },
4523
- `${clip.clipId}-${channelIndex}`
4524
- );
4525
- })
4526
- },
4527
- clip.clipId
4528
- );
4529
- }),
4530
- (recordingState == null ? void 0 : recordingState.isRecording) && recordingState.trackId === track.id && ((_d2 = recordingState.peaks[0]) == null ? void 0 : _d2.length) > 0 && (() => {
4531
- const latencyOffsetSamples = (0, import_core4.resolveRecordingOffsetSamples)({
4532
- overrideSeconds: recordingState.latencyOffset,
4533
- outputLatency: getOutputLatency(),
4534
- lookAhead: getLookAhead(),
4535
- sampleRate
4536
- });
4537
- const latencyPixels = Math.floor(latencyOffsetSamples / samplesPerPixel);
4538
- const skipPeakElements = latencyPixels * 2;
4539
- const previewDuration = Math.max(
4540
- 0,
4541
- recordingState.durationSamples - latencyOffsetSamples
4542
- );
4543
- const previewChannels = (mono ? recordingState.peaks.slice(0, 1) : recordingState.peaks).map(
4544
- (channelPeaks) => skipPeakElements > 0 && skipPeakElements < channelPeaks.length ? channelPeaks.subarray(skipPeakElements) : channelPeaks
4545
- );
4546
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4547
- import_ui_components8.Clip,
4548
- {
4549
- clipId: "recording-preview",
4550
- trackIndex,
4551
- clipIndex: trackClipPeaks.length,
4552
- trackName: "Recording...",
4553
- startSample: recordingState.startSample,
4554
- durationSamples: previewDuration,
4555
- samplesPerPixel,
4556
- showHeader: showClipHeaders,
4557
- disableHeaderDrag: true,
4558
- isSelected: track.id === selectedTrackId,
4559
- trackId: track.id,
4560
- children: previewChannels.map((channelPeaks, chIdx) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4561
- ChannelWithProgress,
4828
+ children: peaksData.data.map((channelPeaks, channelIndex) => {
4829
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4830
+ ChannelWithProgress,
4831
+ {
4832
+ index: channelIndex,
4833
+ data: channelPeaks,
4834
+ bits: peaksData.bits,
4835
+ length: width,
4836
+ isSelected: track.id === selectedTrackId,
4837
+ clipStartSample: clip.startSample,
4838
+ clipDurationSamples: clip.durationSamples,
4839
+ renderMode: clip.midiNotes ? "piano-roll" : effectiveRenderMode,
4840
+ midiNotes: clip.midiNotes,
4841
+ clipSampleRate: clip.sampleRate,
4842
+ clipOffsetSeconds: clip.offsetSamples != null ? clip.offsetSamples / (clip.sampleRate || sampleRate) : 0,
4843
+ samplesPerPixel,
4844
+ spectrogramClipId: clip.clipId,
4845
+ spectrogramOnCanvasRegister: spectrogram ? spectrogram.registerSpectrogramCanvas : void 0,
4846
+ spectrogramOnCanvasUnregister: spectrogram ? spectrogram.unregisterSpectrogramCanvas : void 0
4847
+ },
4848
+ `${clip.clipId}-${channelIndex}`
4849
+ );
4850
+ })
4851
+ },
4852
+ clip.clipId
4853
+ );
4854
+ }),
4855
+ (recordingState == null ? void 0 : recordingState.isRecording) && recordingState.trackId === track.id && ((_e2 = recordingState.peaks[0]) == null ? void 0 : _e2.length) > 0 && (() => {
4856
+ const latencyOffsetSamples = (0, import_core4.resolveRecordingOffsetSamples)({
4857
+ overrideSeconds: recordingState.latencyOffset,
4858
+ outputLatency: getOutputLatency(),
4859
+ lookAhead: getLookAhead(),
4860
+ sampleRate
4861
+ });
4862
+ const latencyPixels = Math.floor(latencyOffsetSamples / samplesPerPixel);
4863
+ const skipPeakElements = latencyPixels * 2;
4864
+ const previewDuration = Math.max(
4865
+ 0,
4866
+ recordingState.durationSamples - latencyOffsetSamples
4867
+ );
4868
+ const previewChannels = (mono ? recordingState.peaks.slice(0, 1) : recordingState.peaks).map(
4869
+ (channelPeaks) => skipPeakElements > 0 && skipPeakElements < channelPeaks.length ? channelPeaks.subarray(skipPeakElements) : channelPeaks
4870
+ );
4871
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4872
+ import_ui_components8.Clip,
4562
4873
  {
4563
- index: chIdx,
4564
- data: channelPeaks,
4565
- bits: recordingState.bits,
4566
- length: Math.floor(channelPeaks.length / 2),
4874
+ clipId: "recording-preview",
4875
+ trackIndex,
4876
+ clipIndex: trackClipPeaks.length,
4877
+ trackName: "Recording...",
4878
+ startSample: recordingState.startSample,
4879
+ durationSamples: previewDuration,
4880
+ samplesPerPixel,
4881
+ showHeader: showClipHeaders,
4882
+ disableHeaderDrag: true,
4567
4883
  isSelected: track.id === selectedTrackId,
4568
- clipStartSample: recordingState.startSample,
4569
- clipDurationSamples: previewDuration
4884
+ trackId: track.id,
4885
+ children: previewChannels.map((channelPeaks, chIdx) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4886
+ ChannelWithProgress,
4887
+ {
4888
+ index: chIdx,
4889
+ data: channelPeaks,
4890
+ bits: recordingState.bits,
4891
+ length: Math.floor(channelPeaks.length / 2),
4892
+ isSelected: track.id === selectedTrackId,
4893
+ clipStartSample: recordingState.startSample,
4894
+ clipDurationSamples: previewDuration
4895
+ },
4896
+ `${track.id}-recording-${chIdx}`
4897
+ ))
4570
4898
  },
4571
- `${track.id}-recording-${chIdx}`
4572
- ))
4573
- },
4574
- `${track.id}-recording`
4575
- );
4576
- })()
4577
- ]
4899
+ `${track.id}-recording`
4900
+ );
4901
+ })()
4902
+ ]
4903
+ }
4904
+ )
4578
4905
  },
4579
4906
  track.id
4580
4907
  );
4581
- }),
4582
- annotations.length > 0 && annotationIntegration && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
4908
+ }) }),
4909
+ annotations.length > 0 && annotationIntegration && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
4583
4910
  const startPosition = annotation.start * sampleRate / samplesPerPixel;
4584
4911
  const endPosition = annotation.end * sampleRate / samplesPerPixel;
4585
4912
  const label = getAnnotationBoxLabel ? getAnnotationBoxLabel(annotation, index) : annotation.id;
4586
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4913
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4587
4914
  annotationIntegration.AnnotationBox,
4588
4915
  {
4589
4916
  annotationId: annotation.id,
@@ -4599,7 +4926,7 @@ var PlaylistVisualization = ({
4599
4926
  annotation.id
4600
4927
  );
4601
4928
  }) }),
4602
- selectionStart !== selectionEnd && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4929
+ selectionStart !== selectionEnd && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4603
4930
  import_ui_components8.Selection,
4604
4931
  {
4605
4932
  startPosition: Math.min(selectionStart, selectionEnd) * sampleRate / samplesPerPixel,
@@ -4607,7 +4934,7 @@ var PlaylistVisualization = ({
4607
4934
  color: theme.selectionColor
4608
4935
  }
4609
4936
  ),
4610
- (isPlaying || selectionStart === selectionEnd) && (renderPlayhead ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4937
+ (isPlaying || selectionStart === selectionEnd) && (renderPlayhead ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4611
4938
  CustomPlayhead,
4612
4939
  {
4613
4940
  renderPlayhead,
@@ -4615,14 +4942,14 @@ var PlaylistVisualization = ({
4615
4942
  samplesPerPixel,
4616
4943
  sampleRate
4617
4944
  }
4618
- ) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AnimatedPlayhead, { color: theme.playheadColor }))
4945
+ ) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(AnimatedPlayhead, { color: theme.playheadColor }))
4619
4946
  ] })
4620
4947
  }
4621
4948
  )
4622
4949
  }
4623
4950
  ),
4624
4951
  (spectrogram == null ? void 0 : spectrogram.SettingsModal) && typeof document !== "undefined" && (0, import_react_dom.createPortal)(
4625
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4952
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4626
4953
  spectrogram.SettingsModal,
4627
4954
  {
4628
4955
  open: settingsModalTrackId !== null,
@@ -4642,8 +4969,8 @@ var PlaylistVisualization = ({
4642
4969
  };
4643
4970
 
4644
4971
  // src/components/PlaylistAnnotationList.tsx
4645
- var import_react27 = require("react");
4646
- var import_jsx_runtime10 = require("react/jsx-runtime");
4972
+ var import_react29 = require("react");
4973
+ var import_jsx_runtime11 = require("react/jsx-runtime");
4647
4974
  var PlaylistAnnotationList = ({
4648
4975
  height,
4649
4976
  renderAnnotationItem,
@@ -4657,7 +4984,7 @@ var PlaylistAnnotationList = ({
4657
4984
  const integration = useAnnotationIntegration();
4658
4985
  const { setAnnotations } = usePlaylistControls();
4659
4986
  const resolvedConfig = annotationListConfig != null ? annotationListConfig : { linkEndpoints, continuousPlay };
4660
- const handleAnnotationUpdate = (0, import_react27.useCallback)(
4987
+ const handleAnnotationUpdate = (0, import_react29.useCallback)(
4661
4988
  (updatedAnnotations) => {
4662
4989
  setAnnotations(updatedAnnotations);
4663
4990
  onAnnotationUpdate == null ? void 0 : onAnnotationUpdate(updatedAnnotations);
@@ -4665,7 +4992,7 @@ var PlaylistAnnotationList = ({
4665
4992
  [setAnnotations, onAnnotationUpdate]
4666
4993
  );
4667
4994
  const { AnnotationText } = integration;
4668
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4995
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
4669
4996
  AnnotationText,
4670
4997
  {
4671
4998
  annotations,
@@ -4684,7 +5011,7 @@ var PlaylistAnnotationList = ({
4684
5011
  };
4685
5012
 
4686
5013
  // src/components/Waveform.tsx
4687
- var import_jsx_runtime11 = require("react/jsx-runtime");
5014
+ var import_jsx_runtime12 = require("react/jsx-runtime");
4688
5015
  var Waveform = ({
4689
5016
  renderTrackControls,
4690
5017
  renderTick,
@@ -4703,13 +5030,14 @@ var Waveform = ({
4703
5030
  showFades = false,
4704
5031
  touchOptimized = false,
4705
5032
  onRemoveTrack,
5033
+ trackReordering = false,
4706
5034
  recordingState
4707
5035
  }) => {
4708
5036
  const { annotations } = usePlaylistState();
4709
5037
  const clipInteractionEnabled = useClipInteractionEnabled();
4710
5038
  const effectiveInteractiveClips = interactiveClips || clipInteractionEnabled;
4711
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
4712
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
5039
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
5040
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
4713
5041
  PlaylistVisualization,
4714
5042
  {
4715
5043
  renderTrackControls,
@@ -4723,10 +5051,11 @@ var Waveform = ({
4723
5051
  showFades,
4724
5052
  touchOptimized,
4725
5053
  onRemoveTrack,
5054
+ trackReordering,
4726
5055
  recordingState
4727
5056
  }
4728
5057
  ),
4729
- annotations.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
5058
+ annotations.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
4730
5059
  PlaylistAnnotationList,
4731
5060
  {
4732
5061
  height: annotationTextHeight,
@@ -4741,34 +5070,15 @@ var Waveform = ({
4741
5070
  };
4742
5071
 
4743
5072
  // src/components/MediaElementPlaylist.tsx
4744
- var import_react30 = require("react");
4745
- var import_react31 = require("@dnd-kit/react");
4746
- var import_modifiers = require("@dnd-kit/abstract/modifiers");
5073
+ var import_react32 = require("react");
5074
+ var import_react33 = require("@dnd-kit/react");
5075
+ var import_modifiers2 = require("@dnd-kit/abstract/modifiers");
4747
5076
  var import_ui_components10 = require("@waveform-playlist/ui-components");
4748
5077
 
4749
- // src/plugins/noDropAnimationPlugins.ts
4750
- var import_dom2 = require("@dnd-kit/dom");
4751
- var noDropAnimationPlugins = (defaults) => {
4752
- let feedbackFound = false;
4753
- const result = defaults.map((p) => {
4754
- if (p === import_dom2.Feedback) {
4755
- feedbackFound = true;
4756
- return import_dom2.Feedback.configure({ dropAnimation: null });
4757
- }
4758
- return p;
4759
- });
4760
- if (!feedbackFound) {
4761
- console.warn(
4762
- "[waveform-playlist] noDropAnimationPlugins: Feedback plugin not found in defaults \u2014 drop animation may not be disabled. Check @dnd-kit/dom version."
4763
- );
4764
- }
4765
- return result;
4766
- };
4767
-
4768
5078
  // src/components/AnimatedMediaElementPlayhead.tsx
4769
- var import_react28 = require("react");
5079
+ var import_react30 = require("react");
4770
5080
  var import_styled_components7 = __toESM(require("styled-components"));
4771
- var import_jsx_runtime12 = require("react/jsx-runtime");
5081
+ var import_jsx_runtime13 = require("react/jsx-runtime");
4772
5082
  var PlayheadLine2 = import_styled_components7.default.div`
4773
5083
  position: absolute;
4774
5084
  top: 0;
@@ -4783,11 +5093,11 @@ var PlayheadLine2 = import_styled_components7.default.div`
4783
5093
  var AnimatedMediaElementPlayhead = ({
4784
5094
  color = "#ff0000"
4785
5095
  }) => {
4786
- const playheadRef = (0, import_react28.useRef)(null);
4787
- const animationFrameRef = (0, import_react28.useRef)(null);
5096
+ const playheadRef = (0, import_react30.useRef)(null);
5097
+ const animationFrameRef = (0, import_react30.useRef)(null);
4788
5098
  const { isPlaying, currentTimeRef } = useMediaElementAnimation();
4789
5099
  const { samplesPerPixel, sampleRate, progressBarWidth } = useMediaElementData();
4790
- (0, import_react28.useEffect)(() => {
5100
+ (0, import_react30.useEffect)(() => {
4791
5101
  const updatePosition = () => {
4792
5102
  var _a;
4793
5103
  if (playheadRef.current) {
@@ -4811,7 +5121,7 @@ var AnimatedMediaElementPlayhead = ({
4811
5121
  }
4812
5122
  };
4813
5123
  }, [isPlaying, sampleRate, samplesPerPixel, currentTimeRef]);
4814
- (0, import_react28.useEffect)(() => {
5124
+ (0, import_react30.useEffect)(() => {
4815
5125
  var _a;
4816
5126
  if (!isPlaying && playheadRef.current) {
4817
5127
  const time = (_a = currentTimeRef.current) != null ? _a : 0;
@@ -4819,14 +5129,14 @@ var AnimatedMediaElementPlayhead = ({
4819
5129
  playheadRef.current.style.transform = `translate3d(${position}px, 0, 0)`;
4820
5130
  }
4821
5131
  });
4822
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(PlayheadLine2, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
5132
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(PlayheadLine2, { ref: playheadRef, $color: color, $width: progressBarWidth, "data-playhead": true });
4823
5133
  };
4824
5134
 
4825
5135
  // src/components/ChannelWithMediaElementProgress.tsx
4826
- var import_react29 = require("react");
5136
+ var import_react31 = require("react");
4827
5137
  var import_styled_components8 = __toESM(require("styled-components"));
4828
5138
  var import_ui_components9 = require("@waveform-playlist/ui-components");
4829
- var import_jsx_runtime13 = require("react/jsx-runtime");
5139
+ var import_jsx_runtime14 = require("react/jsx-runtime");
4830
5140
  var ChannelWrapper2 = import_styled_components8.default.div`
4831
5141
  position: relative;
4832
5142
  `;
@@ -4863,14 +5173,14 @@ var ChannelWithMediaElementProgress = (_a) => {
4863
5173
  "clipStartSample",
4864
5174
  "clipDurationSamples"
4865
5175
  ]);
4866
- const progressRef = (0, import_react29.useRef)(null);
4867
- const animationFrameRef = (0, import_react29.useRef)(null);
5176
+ const progressRef = (0, import_react31.useRef)(null);
5177
+ const animationFrameRef = (0, import_react31.useRef)(null);
4868
5178
  const theme = (0, import_ui_components9.useTheme)();
4869
5179
  const { waveHeight } = (0, import_ui_components9.usePlaylistInfo)();
4870
5180
  const { isPlaying, currentTimeRef } = useMediaElementAnimation();
4871
5181
  const { samplesPerPixel, sampleRate } = useMediaElementData();
4872
5182
  const progressColor = (theme == null ? void 0 : theme.waveProgressColor) || "rgba(0, 0, 0, 0.1)";
4873
- (0, import_react29.useEffect)(() => {
5183
+ (0, import_react31.useEffect)(() => {
4874
5184
  const updateProgress = () => {
4875
5185
  var _a2;
4876
5186
  if (progressRef.current) {
@@ -4912,7 +5222,7 @@ var ChannelWithMediaElementProgress = (_a) => {
4912
5222
  smartChannelProps.length,
4913
5223
  currentTimeRef
4914
5224
  ]);
4915
- (0, import_react29.useEffect)(() => {
5225
+ (0, import_react31.useEffect)(() => {
4916
5226
  var _a2;
4917
5227
  if (!isPlaying && progressRef.current) {
4918
5228
  const currentTime = (_a2 = currentTimeRef.current) != null ? _a2 : 0;
@@ -4938,8 +5248,8 @@ var ChannelWithMediaElementProgress = (_a) => {
4938
5248
  backgroundColor = (theme == null ? void 0 : theme.selectedWaveOutlineColor) || (theme == null ? void 0 : theme.waveOutlineColor) || "grey";
4939
5249
  }
4940
5250
  const backgroundCss = (0, import_ui_components9.waveformColorToCss)(backgroundColor);
4941
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(ChannelWrapper2, { children: [
4942
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5251
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(ChannelWrapper2, { children: [
5252
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4943
5253
  Background2,
4944
5254
  {
4945
5255
  $color: backgroundCss,
@@ -4948,7 +5258,7 @@ var ChannelWithMediaElementProgress = (_a) => {
4948
5258
  $width: smartChannelProps.length
4949
5259
  }
4950
5260
  ),
4951
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5261
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
4952
5262
  ProgressOverlay2,
4953
5263
  {
4954
5264
  ref: progressRef,
@@ -4957,12 +5267,12 @@ var ChannelWithMediaElementProgress = (_a) => {
4957
5267
  $top: smartChannelProps.index * waveHeight
4958
5268
  }
4959
5269
  ),
4960
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ChannelContainer2, { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ui_components9.SmartChannel, __spreadProps(__spreadValues({}, smartChannelProps), { isSelected: true, transparentBackground: true })) })
5270
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ChannelContainer2, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui_components9.SmartChannel, __spreadProps(__spreadValues({}, smartChannelProps), { isSelected: true, transparentBackground: true })) })
4961
5271
  ] });
4962
5272
  };
4963
5273
 
4964
5274
  // src/components/MediaElementPlaylist.tsx
4965
- var import_jsx_runtime14 = require("react/jsx-runtime");
5275
+ var import_jsx_runtime15 = require("react/jsx-runtime");
4966
5276
  var ZERO_REF = { current: 0 };
4967
5277
  var CustomMediaElementPlayhead = ({ renderPlayhead, color, samplesPerPixel, sampleRate }) => {
4968
5278
  var _a;
@@ -4991,7 +5301,7 @@ var MediaElementPlaylist = ({
4991
5301
  const theme = (0, import_ui_components10.useTheme)();
4992
5302
  const { isPlaying } = useMediaElementAnimation();
4993
5303
  const { annotations, activeAnnotationId } = useMediaElementState();
4994
- const annotationIntegration = (0, import_react30.useContext)(AnnotationIntegrationContext);
5304
+ const annotationIntegration = (0, import_react32.useContext)(AnnotationIntegrationContext);
4995
5305
  const { play, seekTo, setActiveAnnotationId, setAnnotations, setScrollContainer } = useMediaElementControls();
4996
5306
  const {
4997
5307
  duration,
@@ -5008,11 +5318,11 @@ var MediaElementPlaylist = ({
5008
5318
  fadeIn,
5009
5319
  fadeOut
5010
5320
  } = useMediaElementData();
5011
- const [selectionStart, setSelectionStart] = (0, import_react30.useState)(0);
5012
- const [selectionEnd, setSelectionEnd] = (0, import_react30.useState)(0);
5013
- const [isSelecting, setIsSelecting] = (0, import_react30.useState)(false);
5014
- const scrollContainerRef = (0, import_react30.useRef)(null);
5015
- const handleScrollContainerRef = (0, import_react30.useCallback)(
5321
+ const [selectionStart, setSelectionStart] = (0, import_react32.useState)(0);
5322
+ const [selectionEnd, setSelectionEnd] = (0, import_react32.useState)(0);
5323
+ const [isSelecting, setIsSelecting] = (0, import_react32.useState)(false);
5324
+ const scrollContainerRef = (0, import_react32.useRef)(null);
5325
+ const handleScrollContainerRef = (0, import_react32.useCallback)(
5016
5326
  (el) => {
5017
5327
  scrollContainerRef.current = el;
5018
5328
  setScrollContainer(el);
@@ -5020,7 +5330,7 @@ var MediaElementPlaylist = ({
5020
5330
  [setScrollContainer]
5021
5331
  );
5022
5332
  const tracksFullWidth = Math.floor(duration * sampleRate / samplesPerPixel);
5023
- const handleAnnotationClick = (0, import_react30.useCallback)(
5333
+ const handleAnnotationClick = (0, import_react32.useCallback)(
5024
5334
  (annotation) => __async(null, null, function* () {
5025
5335
  setActiveAnnotationId(annotation.id);
5026
5336
  try {
@@ -5035,7 +5345,7 @@ var MediaElementPlaylist = ({
5035
5345
  }),
5036
5346
  [setActiveAnnotationId, play]
5037
5347
  );
5038
- const handleAnnotationUpdate = (0, import_react30.useCallback)(
5348
+ const handleAnnotationUpdate = (0, import_react32.useCallback)(
5039
5349
  (updatedAnnotations) => {
5040
5350
  setAnnotations(updatedAnnotations);
5041
5351
  onAnnotationUpdate == null ? void 0 : onAnnotationUpdate(updatedAnnotations);
@@ -5049,8 +5359,8 @@ var MediaElementPlaylist = ({
5049
5359
  duration,
5050
5360
  linkEndpoints: linkEndpointsProp
5051
5361
  });
5052
- const mouseDownTimeRef = (0, import_react30.useRef)(0);
5053
- const handleMouseDown = (0, import_react30.useCallback)(
5362
+ const mouseDownTimeRef = (0, import_react32.useRef)(0);
5363
+ const handleMouseDown = (0, import_react32.useCallback)(
5054
5364
  (e) => {
5055
5365
  const rect = e.currentTarget.getBoundingClientRect();
5056
5366
  const x = e.clientX - rect.left;
@@ -5062,7 +5372,7 @@ var MediaElementPlaylist = ({
5062
5372
  },
5063
5373
  [samplesPerPixel, sampleRate]
5064
5374
  );
5065
- const handleMouseMove = (0, import_react30.useCallback)(
5375
+ const handleMouseMove = (0, import_react32.useCallback)(
5066
5376
  (e) => {
5067
5377
  if (!isSelecting) return;
5068
5378
  const rect = e.currentTarget.getBoundingClientRect();
@@ -5072,7 +5382,7 @@ var MediaElementPlaylist = ({
5072
5382
  },
5073
5383
  [isSelecting, samplesPerPixel, sampleRate]
5074
5384
  );
5075
- const handleMouseUp = (0, import_react30.useCallback)(
5385
+ const handleMouseUp = (0, import_react32.useCallback)(
5076
5386
  (e) => {
5077
5387
  if (!isSelecting) return;
5078
5388
  setIsSelecting(false);
@@ -5102,9 +5412,9 @@ var MediaElementPlaylist = ({
5102
5412
  [isSelecting, selectionStart, samplesPerPixel, sampleRate, seekTo, isPlaying, playoutRef, play]
5103
5413
  );
5104
5414
  if (peaksDataArray.length === 0) {
5105
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className, children: "Loading waveform..." });
5415
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className, children: "Loading waveform..." });
5106
5416
  }
5107
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui_components10.DevicePixelRatioProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5417
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_ui_components10.DevicePixelRatioProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5108
5418
  import_ui_components10.PlaylistInfoContext.Provider,
5109
5419
  {
5110
5420
  value: {
@@ -5119,7 +5429,7 @@ var MediaElementPlaylist = ({
5119
5429
  barGap,
5120
5430
  roundedBars
5121
5431
  },
5122
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5432
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5123
5433
  import_ui_components10.Playlist,
5124
5434
  {
5125
5435
  theme,
@@ -5133,11 +5443,11 @@ var MediaElementPlaylist = ({
5133
5443
  onTracksMouseUp: handleMouseUp,
5134
5444
  scrollContainerRef: handleScrollContainerRef,
5135
5445
  isSelecting,
5136
- timescale: timeScaleHeight > 0 ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_ui_components10.SmartScale, {}) : void 0,
5137
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
5446
+ timescale: timeScaleHeight > 0 ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_ui_components10.SmartScale, {}) : void 0,
5447
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
5138
5448
  peaksDataArray.map((trackClipPeaks, trackIndex) => {
5139
5449
  const maxChannels = trackClipPeaks.length > 0 ? Math.max(...trackClipPeaks.map((clip) => clip.peaks.data.length)) : 1;
5140
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5450
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5141
5451
  import_ui_components10.Track,
5142
5452
  {
5143
5453
  numChannels: maxChannels,
@@ -5150,7 +5460,7 @@ var MediaElementPlaylist = ({
5150
5460
  children: trackClipPeaks.map((clip, clipIndex) => {
5151
5461
  const peaksData = clip.peaks;
5152
5462
  const width = peaksData.length;
5153
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
5463
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
5154
5464
  import_ui_components10.Clip,
5155
5465
  {
5156
5466
  clipId: clip.clipId,
@@ -5165,7 +5475,7 @@ var MediaElementPlaylist = ({
5165
5475
  isSelected: true,
5166
5476
  trackId: `media-element-track-${trackIndex}`,
5167
5477
  children: [
5168
- peaksData.data.map((channelPeaks, channelIndex) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5478
+ peaksData.data.map((channelPeaks, channelIndex) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5169
5479
  ChannelWithMediaElementProgress,
5170
5480
  {
5171
5481
  index: channelIndex,
@@ -5177,7 +5487,7 @@ var MediaElementPlaylist = ({
5177
5487
  },
5178
5488
  `${trackIndex}-${clipIndex}-${channelIndex}`
5179
5489
  )),
5180
- showFades && fadeIn && fadeIn.duration > 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5490
+ showFades && fadeIn && fadeIn.duration > 0 && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5181
5491
  import_ui_components10.FadeOverlay,
5182
5492
  {
5183
5493
  left: 0,
@@ -5186,7 +5496,7 @@ var MediaElementPlaylist = ({
5186
5496
  curveType: fadeIn.type
5187
5497
  }
5188
5498
  ),
5189
- showFades && fadeOut && fadeOut.duration > 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5499
+ showFades && fadeOut && fadeOut.duration > 0 && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5190
5500
  import_ui_components10.FadeOverlay,
5191
5501
  {
5192
5502
  left: width - Math.floor(fadeOut.duration * sampleRate / samplesPerPixel),
@@ -5204,19 +5514,18 @@ var MediaElementPlaylist = ({
5204
5514
  trackIndex
5205
5515
  );
5206
5516
  }),
5207
- annotations.length > 0 && annotationIntegration && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5208
- import_react31.DragDropProvider,
5517
+ annotations.length > 0 && annotationIntegration && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5518
+ import_react33.DragDropProvider,
5209
5519
  {
5210
5520
  onDragStart,
5211
5521
  onDragMove,
5212
5522
  onDragEnd,
5213
- modifiers: editable ? [import_modifiers.RestrictToHorizontalAxis] : [],
5214
- plugins: noDropAnimationPlugins,
5215
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
5523
+ modifiers: editable ? [import_modifiers2.RestrictToHorizontalAxis] : [],
5524
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(annotationIntegration.AnnotationBoxesWrapper, { height: 30, width: tracksFullWidth, children: annotations.map((annotation, index) => {
5216
5525
  const startPosition = annotation.start * sampleRate / samplesPerPixel;
5217
5526
  const endPosition = annotation.end * sampleRate / samplesPerPixel;
5218
5527
  const label = getAnnotationBoxLabel ? getAnnotationBoxLabel(annotation, index) : annotation.id;
5219
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5528
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5220
5529
  annotationIntegration.AnnotationBox,
5221
5530
  {
5222
5531
  annotationId: annotation.id,
@@ -5234,7 +5543,7 @@ var MediaElementPlaylist = ({
5234
5543
  }) })
5235
5544
  }
5236
5545
  ),
5237
- selectionStart !== selectionEnd && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5546
+ selectionStart !== selectionEnd && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5238
5547
  import_ui_components10.Selection,
5239
5548
  {
5240
5549
  startPosition: Math.min(selectionStart, selectionEnd) * sampleRate / samplesPerPixel,
@@ -5242,7 +5551,7 @@ var MediaElementPlaylist = ({
5242
5551
  color: theme.selectionColor
5243
5552
  }
5244
5553
  ),
5245
- renderPlayhead ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
5554
+ renderPlayhead ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5246
5555
  CustomMediaElementPlayhead,
5247
5556
  {
5248
5557
  renderPlayhead,
@@ -5250,7 +5559,7 @@ var MediaElementPlaylist = ({
5250
5559
  samplesPerPixel,
5251
5560
  sampleRate
5252
5561
  }
5253
- ) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(AnimatedMediaElementPlayhead, { color: theme.playheadColor })
5562
+ ) : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(AnimatedMediaElementPlayhead, { color: theme.playheadColor })
5254
5563
  ] })
5255
5564
  }
5256
5565
  )
@@ -5259,8 +5568,8 @@ var MediaElementPlaylist = ({
5259
5568
  };
5260
5569
 
5261
5570
  // src/components/MediaElementAnnotationList.tsx
5262
- var import_react32 = require("react");
5263
- var import_jsx_runtime15 = require("react/jsx-runtime");
5571
+ var import_react34 = require("react");
5572
+ var import_jsx_runtime16 = require("react/jsx-runtime");
5264
5573
  var MediaElementAnnotationList = ({
5265
5574
  height,
5266
5575
  renderAnnotationItem,
@@ -5275,7 +5584,7 @@ var MediaElementAnnotationList = ({
5275
5584
  const integration = useAnnotationIntegration();
5276
5585
  const { setAnnotations } = useMediaElementControls();
5277
5586
  const resolvedConfig = annotationListConfig != null ? annotationListConfig : { linkEndpoints: false, continuousPlay };
5278
- const handleAnnotationUpdate = (0, import_react32.useCallback)(
5587
+ const handleAnnotationUpdate = (0, import_react34.useCallback)(
5279
5588
  (updatedAnnotations) => {
5280
5589
  setAnnotations(updatedAnnotations);
5281
5590
  onAnnotationUpdate == null ? void 0 : onAnnotationUpdate(updatedAnnotations);
@@ -5283,7 +5592,7 @@ var MediaElementAnnotationList = ({
5283
5592
  [setAnnotations, onAnnotationUpdate]
5284
5593
  );
5285
5594
  const { AnnotationText } = integration;
5286
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
5595
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
5287
5596
  AnnotationText,
5288
5597
  {
5289
5598
  annotations,
@@ -5302,7 +5611,7 @@ var MediaElementAnnotationList = ({
5302
5611
  };
5303
5612
 
5304
5613
  // src/components/MediaElementWaveform.tsx
5305
- var import_jsx_runtime16 = require("react/jsx-runtime");
5614
+ var import_jsx_runtime17 = require("react/jsx-runtime");
5306
5615
  var MediaElementWaveform = ({
5307
5616
  annotationTextHeight,
5308
5617
  getAnnotationBoxLabel,
@@ -5317,8 +5626,8 @@ var MediaElementWaveform = ({
5317
5626
  className
5318
5627
  }) => {
5319
5628
  const { annotations } = useMediaElementState();
5320
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [
5321
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
5629
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
5630
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
5322
5631
  MediaElementPlaylist,
5323
5632
  {
5324
5633
  getAnnotationBoxLabel,
@@ -5330,7 +5639,7 @@ var MediaElementWaveform = ({
5330
5639
  className
5331
5640
  }
5332
5641
  ),
5333
- annotations.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
5642
+ annotations.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
5334
5643
  MediaElementAnnotationList,
5335
5644
  {
5336
5645
  height: annotationTextHeight,
@@ -5405,9 +5714,9 @@ var KeyboardShortcuts = ({
5405
5714
  };
5406
5715
 
5407
5716
  // src/components/ClipInteractionProvider.tsx
5408
- var import_react33 = __toESM(require("react"));
5409
- var import_react34 = require("@dnd-kit/react");
5410
- var import_modifiers2 = require("@dnd-kit/abstract/modifiers");
5717
+ var import_react35 = __toESM(require("react"));
5718
+ var import_react36 = require("@dnd-kit/react");
5719
+ var import_modifiers3 = require("@dnd-kit/abstract/modifiers");
5411
5720
  var import_core6 = require("@waveform-playlist/core");
5412
5721
  var import_ui_components11 = require("@waveform-playlist/ui-components");
5413
5722
 
@@ -5477,7 +5786,7 @@ _SnapToGridModifier.configure = (0, import_abstract2.configurator)(_SnapToGridMo
5477
5786
  var SnapToGridModifier = _SnapToGridModifier;
5478
5787
 
5479
5788
  // src/components/ClipInteractionProvider.tsx
5480
- var import_jsx_runtime17 = require("react/jsx-runtime");
5789
+ var import_jsx_runtime18 = require("react/jsx-runtime");
5481
5790
  var NOOP_TRACKS_CHANGE = () => {
5482
5791
  };
5483
5792
  var ClipInteractionProvider = ({
@@ -5486,18 +5795,18 @@ var ClipInteractionProvider = ({
5486
5795
  children
5487
5796
  }) => {
5488
5797
  const { tracks, samplesPerPixel, sampleRate, playoutRef, isDraggingRef, onTracksChange } = usePlaylistData();
5489
- const { setSelectedTrackId } = usePlaylistControls();
5798
+ const { setSelectedTrackId, reorderTrack, bumpTrackReorderEpoch, setTrackDragPreview } = usePlaylistControls();
5490
5799
  const beatsAndBars = (0, import_ui_components11.useBeatsAndBars)();
5491
5800
  const useBeatsSnap = snap && beatsAndBars != null && beatsAndBars.scaleMode === "beats" && beatsAndBars.snapTo !== "off";
5492
5801
  const useTimescaleSnap = snap && !useBeatsSnap;
5493
- (0, import_react33.useEffect)(() => {
5802
+ (0, import_react35.useEffect)(() => {
5494
5803
  if (onTracksChange == null) {
5495
5804
  console.warn(
5496
5805
  "[waveform-playlist] ClipInteractionProvider: onTracksChange is not set on WaveformPlaylistProvider. Drag and trim edits will not be persisted."
5497
5806
  );
5498
5807
  }
5499
5808
  }, [onTracksChange]);
5500
- const snapSamplePosition = (0, import_react33.useMemo)(() => {
5809
+ const snapSamplePosition = (0, import_react35.useMemo)(() => {
5501
5810
  if (useBeatsSnap && beatsAndBars) {
5502
5811
  const { bpm, timeSignature, snapTo } = beatsAndBars;
5503
5812
  const gridTicks = snapTo === "bar" ? (0, import_core6.ticksPerBar)(timeSignature) : (0, import_core6.ticksPerBeat)(timeSignature);
@@ -5526,10 +5835,15 @@ var ClipInteractionProvider = ({
5526
5835
  isDraggingRef,
5527
5836
  snapSamplePosition
5528
5837
  });
5529
- const onDragStart = import_react33.default.useCallback(
5838
+ const onDragStart = import_react35.default.useCallback(
5530
5839
  (event) => {
5531
- var _a, _b, _c;
5532
- const trackIndex = (_c = (_b = (_a = event.operation) == null ? void 0 : _a.source) == null ? void 0 : _b.data) == null ? void 0 : _c.trackIndex;
5840
+ var _a, _b;
5841
+ const data = (_b = (_a = event.operation) == null ? void 0 : _a.source) == null ? void 0 : _b.data;
5842
+ if ((data == null ? void 0 : data.kind) === "track-reorder") {
5843
+ if (data.trackId) setSelectedTrackId(data.trackId);
5844
+ return;
5845
+ }
5846
+ const trackIndex = data == null ? void 0 : data.trackIndex;
5533
5847
  if (trackIndex !== void 0 && tracks[trackIndex]) {
5534
5848
  setSelectedTrackId(tracks[trackIndex].id);
5535
5849
  }
@@ -5537,8 +5851,41 @@ var ClipInteractionProvider = ({
5537
5851
  },
5538
5852
  [handleDragStart, tracks, setSelectedTrackId]
5539
5853
  );
5540
- const modifiers = (0, import_react33.useMemo)(() => {
5541
- const mods = [import_modifiers2.RestrictToHorizontalAxis];
5854
+ const handleDragOver = import_react35.default.useCallback(
5855
+ (event) => {
5856
+ var _a;
5857
+ const data = (_a = event.operation.source) == null ? void 0 : _a.data;
5858
+ if ((data == null ? void 0 : data.kind) !== "track-reorder" || !data.trackId) return;
5859
+ const sortable = event.operation.source.sortable;
5860
+ if (!sortable) return;
5861
+ const trackId = data.trackId;
5862
+ const toIndex = sortable.index;
5863
+ setTrackDragPreview(
5864
+ (prev) => prev && prev.trackId === trackId && prev.toIndex === toIndex ? prev : { trackId, toIndex }
5865
+ );
5866
+ },
5867
+ [setTrackDragPreview]
5868
+ );
5869
+ const handleDragEnd = import_react35.default.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") {
5874
+ bumpTrackReorderEpoch();
5875
+ setTrackDragPreview(null);
5876
+ if (event.canceled || !data.trackId) return;
5877
+ const sortable = event.operation.source.sortable;
5878
+ if (sortable && sortable.index !== sortable.initialIndex) {
5879
+ reorderTrack(data.trackId, sortable.index);
5880
+ }
5881
+ return;
5882
+ }
5883
+ onDragEnd(event);
5884
+ },
5885
+ [onDragEnd, reorderTrack, bumpTrackReorderEpoch, setTrackDragPreview]
5886
+ );
5887
+ const modifiers = (0, import_react35.useMemo)(() => {
5888
+ const mods = [import_modifiers3.RestrictToHorizontalAxis];
5542
5889
  if (useBeatsSnap && beatsAndBars) {
5543
5890
  mods.push(
5544
5891
  SnapToGridModifier.configure({
@@ -5562,15 +5909,15 @@ var ClipInteractionProvider = ({
5562
5909
  mods.push(ClipCollisionModifier.configure({ tracks, samplesPerPixel }));
5563
5910
  return mods;
5564
5911
  }, [useBeatsSnap, useTimescaleSnap, beatsAndBars, tracks, samplesPerPixel, sampleRate]);
5565
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ClipInteractionContextProvider, { value: true, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
5566
- import_react34.DragDropProvider,
5912
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ClipInteractionContextProvider, { value: true, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
5913
+ import_react36.DragDropProvider,
5567
5914
  {
5568
5915
  sensors,
5569
5916
  onDragStart,
5570
5917
  onDragMove,
5571
- onDragEnd,
5918
+ onDragOver: handleDragOver,
5919
+ onDragEnd: handleDragEnd,
5572
5920
  modifiers,
5573
- plugins: noDropAnimationPlugins,
5574
5921
  children
5575
5922
  }
5576
5923
  ) });
@@ -5605,6 +5952,7 @@ var ClipInteractionProvider = ({
5605
5952
  SkipBackwardButton,
5606
5953
  SkipForwardButton,
5607
5954
  SnapToGridModifier,
5955
+ SortableTrackControls,
5608
5956
  SpectrogramIntegrationProvider,
5609
5957
  StopButton,
5610
5958
  TimeFormatSelect,
@@ -5616,7 +5964,6 @@ var ClipInteractionProvider = ({
5616
5964
  getWaveformDataMetadata,
5617
5965
  loadPeaksFromWaveformData,
5618
5966
  loadWaveformData,
5619
- noDropAnimationPlugins,
5620
5967
  useAnnotationDragHandlers,
5621
5968
  useAnnotationIntegration,
5622
5969
  useAnnotationKeyboardControls,