|
| 1 | +/* |
| 2 | +* Copyright (c) Mike Lischke. All rights reserved. |
| 3 | +* Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | +*/ |
| 5 | + |
| 6 | +import type { ComponentChild } from "preact"; |
| 7 | + |
| 8 | +import type { ISbDmTrack } from "../../../core/ScoreBookDataModel.js"; |
| 9 | +import type { UndoManager } from "../../../core/UndoManager.js"; |
| 10 | +import { requisitions } from "../../../supplement/Requisitions.js"; |
| 11 | +import { Container } from "../framework/Container.js"; |
| 12 | +import { Icon } from "../framework/Icon.js"; |
| 13 | +import { UIIcon } from "../framework/UIIcon.js"; |
| 14 | +import { ChildAlignment, Orientation } from "../framework/ui-types.js"; |
| 15 | +import { UIComponent, type ICommonUIProperties } from "../framework/UIComponent.js"; |
| 16 | + |
| 17 | +export interface ITrackEditSidebarProps extends ICommonUIProperties { |
| 18 | + tracks: ISbDmTrack[]; |
| 19 | + undoManager: UndoManager; |
| 20 | +} |
| 21 | + |
| 22 | +/** |
| 23 | + * A sidebar that appears on the right side of the arrangement viewer when edit mode is active. |
| 24 | + * Each track row shows icon-only action buttons: delete, insert below, duplicate, clear. |
| 25 | + */ |
| 26 | +export class TrackEditSidebar extends UIComponent<ITrackEditSidebarProps> { |
| 27 | + public render(): ComponentChild { |
| 28 | + const { tracks } = this.props; |
| 29 | + |
| 30 | + const className = this.generateFinalClassName([ |
| 31 | + "trackEditSidebar", |
| 32 | + "rounded-xl shadow-md border border-base-200", |
| 33 | + ]); |
| 34 | + |
| 35 | + const trackRows = tracks.map((track) => { |
| 36 | + return ( |
| 37 | + <Container |
| 38 | + key={track.id} |
| 39 | + className="trackEditRow" |
| 40 | + data-track={track.id} |
| 41 | + orientation={Orientation.LeftToRight} |
| 42 | + crossAlignment={ChildAlignment.Center} |
| 43 | + > |
| 44 | + <Container |
| 45 | + className="trackEditActions" |
| 46 | + orientation={Orientation.LeftToRight} |
| 47 | + crossAlignment={ChildAlignment.Center} |
| 48 | + > |
| 49 | + <button |
| 50 | + className="trackEditAction trackEditActionDelete" |
| 51 | + title="Delete track" |
| 52 | + onClick={(e) => { |
| 53 | + this.handleDelete(track); |
| 54 | + e.stopPropagation(); |
| 55 | + }} |
| 56 | + > |
| 57 | + <Icon src={UIIcon.Trash} width={14} height={14} alt="Delete track" /> |
| 58 | + </button> |
| 59 | + <button |
| 60 | + className="trackEditAction trackEditActionInsert" |
| 61 | + title="Insert track below" |
| 62 | + onClick={(e) => { |
| 63 | + this.handleInsert(track); |
| 64 | + e.stopPropagation(); |
| 65 | + }} |
| 66 | + > |
| 67 | + <Icon src={UIIcon.Add} width={14} height={14} alt="Insert track" /> |
| 68 | + </button> |
| 69 | + <button |
| 70 | + className="trackEditAction trackEditActionDuplicate" |
| 71 | + title="Duplicate track" |
| 72 | + onClick={(e) => { |
| 73 | + this.handleDuplicate(track); |
| 74 | + e.stopPropagation(); |
| 75 | + }} |
| 76 | + > |
| 77 | + <Icon src={UIIcon.Copy} width={14} height={14} alt="Duplicate track" /> |
| 78 | + </button> |
| 79 | + <button |
| 80 | + className="trackEditAction trackEditActionClear" |
| 81 | + title="Clear track" |
| 82 | + onClick={(e) => { |
| 83 | + this.handleClear(track); |
| 84 | + e.stopPropagation(); |
| 85 | + }} |
| 86 | + > |
| 87 | + <Icon src={UIIcon.ClearAll} width={14} height={14} alt="Clear track" /> |
| 88 | + </button> |
| 89 | + </Container> |
| 90 | + </Container> |
| 91 | + ); |
| 92 | + }); |
| 93 | + |
| 94 | + const emptyState = tracks.length === 0 ? ( |
| 95 | + <div className="trackEditEmpty">No tracks</div> |
| 96 | + ) : undefined; |
| 97 | + |
| 98 | + return ( |
| 99 | + <Container |
| 100 | + className={className} |
| 101 | + orientation={Orientation.TopDown} |
| 102 | + crossAlignment={ChildAlignment.Stretch} |
| 103 | + > |
| 104 | + <div className="trackEditSidebarHeader">Track Actions</div> |
| 105 | + <Container |
| 106 | + className="trackEditSidebarPanel" |
| 107 | + orientation={Orientation.TopDown} |
| 108 | + crossAlignment={ChildAlignment.Stretch} |
| 109 | + > |
| 110 | + {trackRows} |
| 111 | + {emptyState} |
| 112 | + </Container> |
| 113 | + </Container> |
| 114 | + ); |
| 115 | + } |
| 116 | + |
| 117 | + private handleDelete = (track: ISbDmTrack): void => { |
| 118 | + const { undoManager } = this.props; |
| 119 | + |
| 120 | + undoManager.edit({ |
| 121 | + type: "EditCommand_ArrangementRemoveTrack", |
| 122 | + arrangement: track.arrangement, |
| 123 | + removeTrack: track, |
| 124 | + }); |
| 125 | + }; |
| 126 | + |
| 127 | + private handleInsert = (track: ISbDmTrack): void => { |
| 128 | + // Fire a requisition so the parent can open the instrument browser. |
| 129 | + // The track reference indicates where to insert after. |
| 130 | + void requisitions.execute("insertTrackRequested", track); |
| 131 | + }; |
| 132 | + |
| 133 | + private handleDuplicate = (track: ISbDmTrack): void => { |
| 134 | + const { undoManager } = this.props; |
| 135 | + |
| 136 | + undoManager.edit({ |
| 137 | + type: "EditCommand_ArrangementDuplicateTrack", |
| 138 | + arrangement: track.arrangement, |
| 139 | + duplicateTrack: track, |
| 140 | + }); |
| 141 | + }; |
| 142 | + |
| 143 | + private handleClear = (track: ISbDmTrack): void => { |
| 144 | + const { undoManager } = this.props; |
| 145 | + |
| 146 | + undoManager.edit({ |
| 147 | + type: "EditCommand_TrackClear", |
| 148 | + track, |
| 149 | + command: "clear", |
| 150 | + }); |
| 151 | + }; |
| 152 | +} |
0 commit comments