@behindthemusictree/app-kit-ui 0.0.0-stage → 26.1.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.
@@ -0,0 +1,2385 @@
1
+ import {
2
+ BasePopup_default,
3
+ InternalErrorPopup
4
+ } from "./chunk-VDXUW7PP.js";
5
+
6
+ // src/genre-tree/GenreTreeView.tsx
7
+ import { useCallback as useCallback5, useDeferredValue, useEffect as useEffect4, useMemo as useMemo6, useRef as useRef4, useState as useState4 } from "react";
8
+ import { useIsMutating } from "@tanstack/react-query";
9
+ import { Plus as Plus2 } from "lucide-react";
10
+ import { IconTextButton, Button, SegmentedControl as SegmentedControl2 } from "@behindthemusictree/ui";
11
+ import {
12
+ GenreTreeWheelSkeleton,
13
+ GenreTreeViewSkeleton
14
+ } from "@behindthemusictree/genre-tree-view";
15
+ import {
16
+ useArtistSearch
17
+ } from "@behindthemusictree/app-kit/genre-tree";
18
+ import { useGenreTreeViewState, useArtist as useArtist2, genreUpdateMutationKey } from "@behindthemusictree/app-kit/genre-tree";
19
+ import { usePlayer as usePlayer8 } from "@behindthemusictree/app-kit/player";
20
+ import { usePopup as usePopup4 } from "@behindthemusictree/app-kit/popup";
21
+
22
+ // src/genre-tree/GenreDetailExtras.tsx
23
+ import { Skeleton as Skeleton2 } from "@behindthemusictree/ui";
24
+ import { useFetchGenreOverview } from "@behindthemusictree/app-kit/genre-tree";
25
+
26
+ // src/genre-tree/ClampedText.tsx
27
+ import { useLayoutEffect, useRef, useState } from "react";
28
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
29
+ function ClampedText({ children, className = "" }) {
30
+ const ref = useRef(null);
31
+ const [expanded, setExpanded] = useState(false);
32
+ const [overflows, setOverflows] = useState(false);
33
+ useLayoutEffect(() => {
34
+ const element = ref.current;
35
+ if (!element || expanded) return;
36
+ setOverflows(element.scrollHeight > element.clientHeight);
37
+ }, [children, expanded]);
38
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
39
+ /* @__PURE__ */ jsx("p", { ref, className: `${className} ${expanded ? "" : "line-clamp-3"}`, children }),
40
+ (overflows || expanded) && /* @__PURE__ */ jsx(
41
+ "button",
42
+ {
43
+ type: "button",
44
+ "aria-expanded": expanded,
45
+ onClick: () => setExpanded((value) => !value),
46
+ className: "mt-1 text-xs text-[var(--color-text-muted)] underline hover:text-[var(--color-text)]",
47
+ children: expanded ? "Show less" : "Show more"
48
+ }
49
+ )
50
+ ] });
51
+ }
52
+
53
+ // src/genre-tree/GenrePlaylistTracks.tsx
54
+ import { useEffect, useRef as useRef2 } from "react";
55
+ import { useInfiniteQuery } from "@tanstack/react-query";
56
+ import { z } from "zod";
57
+ import { FaPlay, FaPause } from "react-icons/fa";
58
+ import { RingLoader, Skeleton } from "@behindthemusictree/ui";
59
+ import { useSession } from "@behindthemusictree/app-kit/auth";
60
+ import { useFetchWrapper } from "@behindthemusictree/app-kit/transport";
61
+ import { PaginatedResponseSchema } from "@behindthemusictree/app-kit/transport";
62
+ import { parseWithLog } from "@behindthemusictree/app-kit/transport";
63
+ import { usePlayer } from "@behindthemusictree/app-kit/player";
64
+ import { PlayStates } from "@behindthemusictree/app-kit/player";
65
+ import { usePopup } from "@behindthemusictree/app-kit/popup";
66
+
67
+ // src/genre-tree/UnplayableReason.tsx
68
+ import { FaYoutube } from "react-icons/fa";
69
+ import { NO_VIDEO_LABEL } from "@behindthemusictree/app-kit/genre-tree";
70
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
71
+ function UnplayableReason({ reason }) {
72
+ if (reason !== NO_VIDEO_LABEL) return /* @__PURE__ */ jsx2(Fragment2, { children: reason });
73
+ return /* @__PURE__ */ jsxs2("span", { role: "img", "aria-label": reason, className: "relative inline-flex shrink-0 items-center", children: [
74
+ /* @__PURE__ */ jsx2(FaYoutube, { size: 16, "aria-hidden": "true" }),
75
+ /* @__PURE__ */ jsx2("span", { "aria-hidden": "true", className: "absolute left-1/2 top-1/2 h-0.5 w-[130%] -translate-x-1/2 -translate-y-1/2 -rotate-45 rounded bg-current" })
76
+ ] });
77
+ }
78
+
79
+ // src/genre-tree/GenrePlaylistTracks.tsx
80
+ import { ErrorCode } from "@behindthemusictree/app-kit/transport";
81
+ import { genrePlaylistQueryKeys } from "@behindthemusictree/app-kit/genre-tree";
82
+ import { libraryEndpoints, libraryQueryKeys } from "@behindthemusictree/app-kit/genre-tree";
83
+ import { isSong, songUnplayableReason, SongDetailedSchema } from "@behindthemusictree/app-kit/genre-tree";
84
+ import { useTrackList } from "@behindthemusictree/app-kit/genre-tree";
85
+
86
+ // src/genre-tree/MusicBrainzRecordingLink.tsx
87
+ import { FaExternalLinkAlt } from "react-icons/fa";
88
+ import { musicBrainzRecordingUrl } from "@behindthemusictree/app-kit/genre-tree";
89
+ import { jsx as jsx3 } from "react/jsx-runtime";
90
+ function MusicBrainzRecordingLink({ song }) {
91
+ const url = musicBrainzRecordingUrl(song);
92
+ if (!url) return null;
93
+ return /* @__PURE__ */ jsx3(
94
+ "a",
95
+ {
96
+ href: url,
97
+ target: "_blank",
98
+ rel: "noopener noreferrer",
99
+ "aria-label": `View ${song.title} on MusicBrainz`,
100
+ title: "View on MusicBrainz",
101
+ className: "inline-flex shrink-0 items-center opacity-50 hover:opacity-100 focus-visible:opacity-100",
102
+ onClick: (event) => event.stopPropagation(),
103
+ children: /* @__PURE__ */ jsx3(FaExternalLinkAlt, { size: 10 })
104
+ }
105
+ );
106
+ }
107
+
108
+ // src/genre-tree/GenrePlaylistTracks.tsx
109
+ import { ArtistNames } from "@behindthemusictree/app-kit/genre-tree";
110
+ import { capitalize, useTrackNoun } from "@behindthemusictree/app-kit/track-noun";
111
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
112
+ var CATALOGUE_PAGE_SIZE = 100;
113
+ var SongPageSchema = PaginatedResponseSchema(SongDetailedSchema).extend({
114
+ overallTotal: z.number().nullable(),
115
+ page: z.number().nullable(),
116
+ totalPages: z.number().nullable()
117
+ });
118
+ var TEXT_CELL = "min-w-0 flex-1 truncate [@container(min-width:40rem)]:flex [@container(min-width:40rem)]:gap-2";
119
+ var TITLE_CELL = "[@container(min-width:40rem)]:flex-[2] [@container(min-width:40rem)]:truncate";
120
+ var COLUMN_CELL = "[@container(min-width:40rem)]:flex-1 [@container(min-width:40rem)]:truncate";
121
+ var ALBUM_CELL = `hidden [@container(min-width:40rem)]:block ${COLUMN_CELL}`;
122
+ var SEPARATOR = "[@container(min-width:40rem)]:hidden";
123
+ var nextCursor = (next) => {
124
+ const cursor = new URL(next).searchParams.get("cursor");
125
+ if (!cursor) throw new Error(`Songs next link has no cursor: ${next}`);
126
+ return cursor;
127
+ };
128
+ function GenrePlaylistTracks({
129
+ genreUuid,
130
+ genrePlaylist,
131
+ scope,
132
+ getBackendBaseUrl,
133
+ renderArtistLink,
134
+ renderSongLeading,
135
+ renderSongActions,
136
+ renderTracksToolbar,
137
+ artist = null
138
+ }) {
139
+ const { fetchGenrePlaylistTracksPage, playNewTrackListFromGenrePlaylist, playNewTrackListFromArtist } = useTrackList();
140
+ const { session, sessionRestored } = useSession();
141
+ const { playerTrackObject, playState, handlePlayPauseAction } = usePlayer();
142
+ const { showPopup } = usePopup();
143
+ const trackNoun = useTrackNoun();
144
+ const { uuid } = genrePlaylist;
145
+ const { fetch } = useFetchWrapper(getBackendBaseUrl);
146
+ const { data, isPending, isError, refetch, hasNextPage, isFetchingNextPage, fetchNextPage } = useInfiniteQuery({
147
+ queryKey: scope === "me" ? genrePlaylistQueryKeys.me.tracks(uuid) : artist ? [...libraryQueryKeys.reference.songs.byGenre(getBackendBaseUrl(), genreUuid), "artist", artist.uuid] : libraryQueryKeys.reference.songs.byGenre(getBackendBaseUrl(), genreUuid),
148
+ queryFn: async ({ pageParam }) => {
149
+ if (scope === "me") return fetchGenrePlaylistTracksPage(uuid, scope, Number(pageParam));
150
+ const response = await fetch(
151
+ libraryEndpoints.reference.songs.list(),
152
+ true,
153
+ false,
154
+ {},
155
+ { genre: genreUuid, ...artist && { artist: artist.uuid }, pageSize: CATALOGUE_PAGE_SIZE, withTotal: false, ...pageParam && { cursor: pageParam } }
156
+ );
157
+ const parsed = parseWithLog(SongPageSchema, response, "GenrePlaylistTracks");
158
+ return { tracks: parsed.results, total: parsed.overallTotal, nextPage: parsed.next ? nextCursor(parsed.next) : null };
159
+ },
160
+ initialPageParam: scope === "me" ? 1 : "",
161
+ getNextPageParam: (lastPage) => lastPage.nextPage ?? void 0,
162
+ enabled: scope !== "me" || sessionRestored && !!session?.accessToken
163
+ });
164
+ const sentinelRef = useRef2(null);
165
+ useEffect(() => {
166
+ const sentinel = sentinelRef.current;
167
+ if (!hasNextPage || isFetchingNextPage || !sentinel) return;
168
+ const observer = new IntersectionObserver((entries) => {
169
+ if (entries.some((entry) => entry.isIntersecting)) {
170
+ void fetchNextPage();
171
+ }
172
+ });
173
+ observer.observe(sentinel);
174
+ return () => observer.disconnect();
175
+ }, [hasNextPage, isFetchingNextPage, fetchNextPage]);
176
+ const pages = data?.pages ?? [];
177
+ const tracks = pages.flatMap((page) => page.tracks);
178
+ const total = pages[0]?.total ?? void 0;
179
+ const play = (startSongUuid) => {
180
+ const started = artist ? playNewTrackListFromArtist(artist, scope, { startSongUuid, ordering: "title", genreUuid }) : playNewTrackListFromGenrePlaylist(genrePlaylist, scope, { startSongUuid });
181
+ started.catch((error) => {
182
+ console.error("Failed to play genre playlist:", error);
183
+ showPopup(/* @__PURE__ */ jsx4(InternalErrorPopup, { errorCode: ErrorCode.CLIENT_UNKNOWN }));
184
+ });
185
+ };
186
+ return /* @__PURE__ */ jsxs3("div", { className: "gtv-info-panel-children", children: [
187
+ /* @__PURE__ */ jsxs3("span", { className: "gtv-info-panel-children-title", children: [
188
+ capitalize(trackNoun.plural),
189
+ total !== void 0 && ` (${total})`
190
+ ] }),
191
+ renderTracksToolbar?.(),
192
+ isPending ? /* @__PURE__ */ jsx4(Skeleton, { className: "h-4 w-3/4", "aria-busy": "true" }) : isError && tracks.length === 0 ? /* @__PURE__ */ jsxs3("p", { role: "alert", children: [
193
+ "Couldn't load ",
194
+ trackNoun.plural,
195
+ ".",
196
+ " ",
197
+ /* @__PURE__ */ jsx4("button", { type: "button", className: "underline", onClick: () => void refetch(), children: "Retry" })
198
+ ] }) : tracks.length === 0 ? /* @__PURE__ */ jsx4("p", { children: "\u2014" }) : /* @__PURE__ */ jsxs3("ul", { className: "mt-1 max-h-64 overflow-y-auto text-[0.8125rem] leading-[1.45] [container-type:inline-size]", "aria-label": `${genrePlaylist.name} ${trackNoun.plural}`, children: [
199
+ tracks.map((track, index) => {
200
+ const label = track.artists?.length ? `${track.title} \u2014 ${track.artists.map((artist2) => artist2.name).join(", ")}` : track.title;
201
+ const isCurrent = playerTrackObject?.track.id === track.uuid;
202
+ const isPlaying = isCurrent && playState === PlayStates.PLAYING;
203
+ const text = /* @__PURE__ */ jsxs3("span", { className: TEXT_CELL, children: [
204
+ /* @__PURE__ */ jsx4("span", { className: TITLE_CELL, children: track.title }),
205
+ track.artists?.length ? /* @__PURE__ */ jsx4("span", { className: SEPARATOR, children: " \u2014 " }) : null,
206
+ /* @__PURE__ */ jsx4("span", { className: COLUMN_CELL, children: track.artists?.length ? /* @__PURE__ */ jsx4(ArtistNames, { artists: track.artists, renderArtistLink }) : null }),
207
+ track.album && /* @__PURE__ */ jsx4("span", { className: ALBUM_CELL, children: track.album.name })
208
+ ] });
209
+ const leading = renderSongLeading?.(track, index);
210
+ const actions = renderSongActions?.(track);
211
+ const unplayableReason = isSong(track) ? songUnplayableReason(track) : null;
212
+ if (unplayableReason) {
213
+ return /* @__PURE__ */ jsxs3("li", { className: "flex min-h-8 items-center gap-1 px-1 opacity-50", title: unplayableReason, children: [
214
+ leading,
215
+ /* @__PURE__ */ jsx4(
216
+ "button",
217
+ {
218
+ type: "button",
219
+ disabled: true,
220
+ "aria-disabled": "true",
221
+ "aria-label": `${label} \u2014 ${unplayableReason}`,
222
+ className: "flex h-6 w-6 shrink-0 items-center justify-center rounded-full opacity-0 cursor-not-allowed",
223
+ children: /* @__PURE__ */ jsx4(FaPlay, { size: 10 })
224
+ }
225
+ ),
226
+ text,
227
+ isSong(track) && /* @__PURE__ */ jsx4(MusicBrainzRecordingLink, { song: track }),
228
+ /* @__PURE__ */ jsx4("span", { className: "shrink-0 text-xs", children: /* @__PURE__ */ jsx4(UnplayableReason, { reason: unplayableReason }) }),
229
+ actions
230
+ ] }, track.uuid);
231
+ }
232
+ return /* @__PURE__ */ jsxs3(
233
+ "li",
234
+ {
235
+ className: `group flex min-h-8 items-center gap-1 rounded px-1 hover:bg-[var(--color-neutral-100)] ${isCurrent ? "font-medium text-[var(--color-primary)]" : ""}`,
236
+ children: [
237
+ leading,
238
+ /* @__PURE__ */ jsx4(
239
+ "button",
240
+ {
241
+ type: "button",
242
+ "aria-label": `${isPlaying ? "Pause" : "Play"} ${label}`,
243
+ className: `flex h-6 w-6 shrink-0 items-center justify-center rounded-full cursor-pointer group-hover:opacity-100 focus-visible:opacity-100 ${isCurrent && playState !== PlayStates.STOPPED ? "opacity-100" : "opacity-0 [@media(pointer:coarse)]:opacity-100"}`,
244
+ onClick: () => isCurrent ? handlePlayPauseAction() : play(track.uuid),
245
+ children: isCurrent && playState === PlayStates.LOADING ? /* @__PURE__ */ jsx4(RingLoader, { size: 10 }) : isPlaying ? /* @__PURE__ */ jsx4(FaPause, { size: 10 }) : /* @__PURE__ */ jsx4(FaPlay, { size: 10 })
246
+ }
247
+ ),
248
+ text,
249
+ isSong(track) && /* @__PURE__ */ jsx4(MusicBrainzRecordingLink, { song: track }),
250
+ actions
251
+ ]
252
+ },
253
+ track.uuid
254
+ );
255
+ }),
256
+ hasNextPage && /* @__PURE__ */ jsx4("li", { ref: sentinelRef, "aria-hidden": "true", className: "h-4" })
257
+ ] })
258
+ ] });
259
+ }
260
+
261
+ // src/genre-tree/GenreDetailExtras.tsx
262
+ import { useTrackNoun as useTrackNoun2 } from "@behindthemusictree/app-kit/track-noun";
263
+ import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
264
+ function GenreDetailExtras({
265
+ genreUuid,
266
+ genrePlaylist,
267
+ scope,
268
+ getBackendBaseUrl,
269
+ criteriaOverviewSchema,
270
+ renderGenreDetailExtras,
271
+ renderArtistLink,
272
+ renderSummary,
273
+ renderEssentialTracks,
274
+ family,
275
+ ...trackSlots
276
+ }) {
277
+ const trackNoun = useTrackNoun2();
278
+ const { data: overview, isPending } = useFetchGenreOverview(
279
+ genreUuid,
280
+ scope,
281
+ getBackendBaseUrl,
282
+ criteriaOverviewSchema
283
+ );
284
+ if (isPending) {
285
+ return /* @__PURE__ */ jsxs4(Fragment3, { children: [
286
+ /* @__PURE__ */ jsxs4("div", { className: "gtv-info-panel-children", "aria-busy": "true", "data-testid": "genre-detail-extras-skeleton", children: [
287
+ /* @__PURE__ */ jsx5("span", { className: "gtv-info-panel-children-title", children: "Summary" }),
288
+ /* @__PURE__ */ jsx5(Skeleton2, { className: "h-4 w-3/4" })
289
+ ] }),
290
+ family
291
+ ] });
292
+ }
293
+ if (!overview) return /* @__PURE__ */ jsx5(Fragment3, { children: family });
294
+ const { summary, description, summarySourceUrl, essentialSongs } = overview;
295
+ return /* @__PURE__ */ jsxs4(Fragment3, { children: [
296
+ description && /* @__PURE__ */ jsx5("div", { className: "px-3.5 py-2.5", children: /* @__PURE__ */ jsx5(ClampedText, { className: "text-[0.8125rem] leading-[1.45] text-[var(--color-text-muted)]", children: description }, genreUuid) }),
297
+ renderSummary ? renderSummary(overview) : /* @__PURE__ */ jsxs4("div", { className: "gtv-info-panel-children text-[0.8125rem] leading-[1.45] text-[var(--color-text)]", children: [
298
+ /* @__PURE__ */ jsx5("span", { className: "gtv-info-panel-children-title", children: "Summary" }),
299
+ /* @__PURE__ */ jsx5(ClampedText, { className: "mt-1", children: summary ?? "\u2014" }, genreUuid),
300
+ summarySourceUrl && /* @__PURE__ */ jsx5(
301
+ "a",
302
+ {
303
+ href: summarySourceUrl,
304
+ target: "_blank",
305
+ rel: "noopener noreferrer",
306
+ className: "mt-1 inline-block text-xs text-[var(--color-text-muted)] underline hover:text-[var(--color-text)]",
307
+ children: "Source: Wikipedia"
308
+ }
309
+ )
310
+ ] }),
311
+ renderSummary && summarySourceUrl && /* @__PURE__ */ jsx5(
312
+ "a",
313
+ {
314
+ href: summarySourceUrl,
315
+ target: "_blank",
316
+ rel: "noopener noreferrer",
317
+ className: "mx-3.5 mb-2.5 inline-block text-xs text-[var(--color-text-muted)] underline hover:text-[var(--color-text)]",
318
+ children: "Source: Wikipedia"
319
+ }
320
+ ),
321
+ family,
322
+ renderGenreDetailExtras?.(overview),
323
+ renderEssentialTracks ? renderEssentialTracks(overview) : essentialSongs && /* @__PURE__ */ jsxs4("div", { className: "gtv-info-panel-children text-[0.8125rem] leading-[1.45] text-[var(--color-text)]", children: [
324
+ /* @__PURE__ */ jsxs4("span", { className: "gtv-info-panel-children-title", children: [
325
+ "Essential ",
326
+ trackNoun.plural
327
+ ] }),
328
+ essentialSongs.length > 0 ? /* @__PURE__ */ jsx5("ul", { className: "mt-1 divide-y divide-[var(--color-border)]", children: essentialSongs.map((track) => /* @__PURE__ */ jsx5("li", { className: "py-1", children: track.title }, track.uuid)) }) : /* @__PURE__ */ jsx5("p", { className: "mt-1", children: "\u2014" })
329
+ ] }),
330
+ /* @__PURE__ */ jsx5(
331
+ GenrePlaylistTracks,
332
+ {
333
+ genreUuid,
334
+ genrePlaylist,
335
+ scope,
336
+ getBackendBaseUrl,
337
+ renderArtistLink,
338
+ ...trackSlots
339
+ }
340
+ )
341
+ ] });
342
+ }
343
+
344
+ // src/genre-tree/playlist-tree/TreePerRoot.tsx
345
+ import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
346
+ import {
347
+ GenreTree,
348
+ getGenreTreeColor
349
+ } from "@behindthemusictree/genre-tree-view";
350
+ import { usePlayer as usePlayer2 } from "@behindthemusictree/app-kit/player";
351
+ import { usePopup as usePopup2 } from "@behindthemusictree/app-kit/popup";
352
+ import { ErrorCode as ErrorCode2 } from "@behindthemusictree/app-kit/transport";
353
+
354
+ // src/genre-tree/playlist-tree/useGenrePlaylistPlayback.ts
355
+ import { useCallback, useMemo } from "react";
356
+ import {
357
+ TrackListOriginType,
358
+ useTrackList as useTrackList2
359
+ } from "@behindthemusictree/app-kit/genre-tree";
360
+ function useGenrePlaylistPlayback({
361
+ scope,
362
+ genrePlaylists,
363
+ artist = null
364
+ }) {
365
+ const { trackList, playNewTrackListFromGenrePlaylist, playNewTrackListFromArtist } = useTrackList2();
366
+ const origin = trackList?.origin;
367
+ const playingNodeId = useMemo(() => {
368
+ if (!origin) return null;
369
+ if (!artist) return origin.type === TrackListOriginType.GENRE_PLAYLIST ? origin.uuid : null;
370
+ if (origin.type !== TrackListOriginType.ARTIST || origin.uuid !== artist.uuid) return null;
371
+ const { genreUuid } = origin;
372
+ return genreUuid ? genrePlaylists.find((gp) => gp.criteria?.uuid === genreUuid)?.uuid ?? null : null;
373
+ }, [origin, artist, genrePlaylists]);
374
+ const play = useCallback(
375
+ async (genrePlaylist) => {
376
+ if (!artist) return playNewTrackListFromGenrePlaylist(genrePlaylist, scope);
377
+ if (!genrePlaylist.criteria) return;
378
+ return playNewTrackListFromArtist(artist, scope, { ordering: "title", genreUuid: genrePlaylist.criteria.uuid });
379
+ },
380
+ [artist, scope, playNewTrackListFromGenrePlaylist, playNewTrackListFromArtist]
381
+ );
382
+ return useMemo(() => ({ playingNodeId, play }), [playingNodeId, play]);
383
+ }
384
+
385
+ // src/genre-tree/playlist-tree/TreePerRoot.tsx
386
+ import { capitalize as capitalize2, useTrackNoun as useTrackNoun3 } from "@behindthemusictree/app-kit/track-noun";
387
+ import { jsx as jsx6 } from "react/jsx-runtime";
388
+ function GenrePlaylistTreePerRoot({
389
+ scope,
390
+ className,
391
+ rootUuid,
392
+ genrePlaylistTreePerRoot,
393
+ handleGenreCreationAction,
394
+ handleGenreRenameAction,
395
+ additionalActions,
396
+ onNodeClick,
397
+ onNodeHover,
398
+ renderInfoPanelBody,
399
+ selectedNodeId,
400
+ onSelectedNodeChange,
401
+ hideInfoPanelClose,
402
+ hideInfoPanelTitle,
403
+ readOnly = false,
404
+ showToolbar,
405
+ wheelZoom,
406
+ controlsOrientation,
407
+ defaultViewport,
408
+ onViewportChange,
409
+ playback,
410
+ ...infoPanelCuration
411
+ }) {
412
+ const { isPlaying, setIsPlaying } = usePlayer2();
413
+ const defaultPlayback = useGenrePlaylistPlayback({ scope, genrePlaylists: genrePlaylistTreePerRoot });
414
+ const { playingNodeId, play } = playback ?? defaultPlayback;
415
+ const trackNoun = useTrackNoun3();
416
+ const { showPopup } = usePopup2();
417
+ const nodes = useMemo2(
418
+ () => genrePlaylistTreePerRoot.map((genrePlaylist) => ({
419
+ id: genrePlaylist.uuid,
420
+ parentId: genrePlaylist.parent?.uuid ?? null,
421
+ name: genrePlaylist.name,
422
+ itemCount: genrePlaylist.tracksCount,
423
+ actionable: Boolean(genrePlaylist.criteria),
424
+ side: genrePlaylist.criteria?.side ?? void 0,
425
+ wikidataId: genrePlaylist.criteria?.wikidataId ?? null,
426
+ umbrella: genrePlaylist.isUmbrella
427
+ })),
428
+ [genrePlaylistTreePerRoot]
429
+ );
430
+ const handlePlayPause = useCallback2(
431
+ (nodeId) => {
432
+ const genrePlaylist = genrePlaylistTreePerRoot.find((g) => g.uuid === nodeId);
433
+ if (!genrePlaylist) return;
434
+ if (nodeId === playingNodeId) {
435
+ setIsPlaying(!isPlaying);
436
+ return;
437
+ }
438
+ if (genrePlaylist.tracksCount === 0) {
439
+ return;
440
+ }
441
+ play(genrePlaylist).catch((error) => {
442
+ console.error("Failed to load genre playlist tracks:", error);
443
+ showPopup(/* @__PURE__ */ jsx6(InternalErrorPopup, { errorCode: ErrorCode2.CLIENT_UNKNOWN }));
444
+ });
445
+ },
446
+ [
447
+ genrePlaylistTreePerRoot,
448
+ playingNodeId,
449
+ isPlaying,
450
+ setIsPlaying,
451
+ play,
452
+ showPopup
453
+ ]
454
+ );
455
+ const handleAddChild = useCallback2(
456
+ (parentId) => {
457
+ const genrePlaylist = genrePlaylistTreePerRoot.find((g) => g.uuid === parentId);
458
+ if (!genrePlaylist?.criteria) return;
459
+ handleGenreCreationAction(genrePlaylist.criteria);
460
+ },
461
+ [genrePlaylistTreePerRoot, handleGenreCreationAction]
462
+ );
463
+ const handleRenameRequest = useCallback2(
464
+ (node) => {
465
+ const genrePlaylist = genrePlaylistTreePerRoot.find((g) => g.uuid === node.id);
466
+ if (!genrePlaylist?.criteria) return;
467
+ handleGenreRenameAction(genrePlaylist.criteria);
468
+ },
469
+ [genrePlaylistTreePerRoot, handleGenreRenameAction]
470
+ );
471
+ const handleDeleteRequest = useCallback2((node) => {
472
+ if (confirm(`Are you sure you want to delete "${node.name}"?`)) {
473
+ }
474
+ }, []);
475
+ return /* @__PURE__ */ jsx6(
476
+ GenreTree,
477
+ {
478
+ className,
479
+ nodes,
480
+ itemCountLabel: `${capitalize2(trackNoun.singular)} count`,
481
+ rootColor: getGenreTreeColor(rootUuid),
482
+ playingNodeId,
483
+ playState: isPlaying ? "playing" : "paused",
484
+ onPlayPause: handlePlayPause,
485
+ onAddChild: readOnly ? void 0 : handleAddChild,
486
+ onRenameRequest: readOnly ? void 0 : handleRenameRequest,
487
+ onDeleteRequest: readOnly ? void 0 : handleDeleteRequest,
488
+ additionalActions,
489
+ onNodeClick,
490
+ onNodeHover,
491
+ renderInfoPanelBody,
492
+ selectedNodeId,
493
+ onSelectedNodeChange,
494
+ hideInfoPanelClose,
495
+ hideInfoPanelTitle,
496
+ showToolbar,
497
+ wheelZoom,
498
+ controlsOrientation,
499
+ defaultViewport,
500
+ onViewportChange,
501
+ ...infoPanelCuration,
502
+ readOnly
503
+ }
504
+ );
505
+ }
506
+
507
+ // src/genre-tree/playlist-tree/TreeWheel.tsx
508
+ import { useCallback as useCallback3, useMemo as useMemo3 } from "react";
509
+ import {
510
+ GenreTreeWheel
511
+ } from "@behindthemusictree/genre-tree-view";
512
+ import { usePlayer as usePlayer3 } from "@behindthemusictree/app-kit/player";
513
+ import { usePopup as usePopup3 } from "@behindthemusictree/app-kit/popup";
514
+ import { ErrorCode as ErrorCode3 } from "@behindthemusictree/app-kit/transport";
515
+
516
+ // src/genre-tree/playlist-tree/size-metric.ts
517
+ var genrePlaylistSize = (genrePlaylist, metric) => metric === "views" ? genrePlaylist.viewsCount : genrePlaylist.tracksCount;
518
+
519
+ // src/genre-tree/playlist-tree/TreeWheel.tsx
520
+ import { capitalize as capitalize3, useTrackNoun as useTrackNoun4 } from "@behindthemusictree/app-kit/track-noun";
521
+ import { jsx as jsx7 } from "react/jsx-runtime";
522
+ function GenrePlaylistTreeWheel({
523
+ scope,
524
+ className,
525
+ genrePlaylists,
526
+ handleGenreCreationAction,
527
+ handleGenreRenameAction,
528
+ additionalActions,
529
+ onNodeClick,
530
+ onNodeHover,
531
+ renderInfoPanelBody,
532
+ selectedNodeId,
533
+ onSelectedNodeChange,
534
+ hideInfoPanelClose,
535
+ hideInfoPanelTitle,
536
+ readOnly = false,
537
+ allowWheelRotation,
538
+ showToolbar,
539
+ controlsOrientation,
540
+ sizeMetric = "songs",
541
+ floatingControlsLeading,
542
+ busy,
543
+ defaultViewport,
544
+ onViewportChange,
545
+ playback,
546
+ ...infoPanelCuration
547
+ }) {
548
+ const { isPlaying, setIsPlaying } = usePlayer3();
549
+ const defaultPlayback = useGenrePlaylistPlayback({ scope, genrePlaylists });
550
+ const { playingNodeId, play } = playback ?? defaultPlayback;
551
+ const trackNoun = useTrackNoun4();
552
+ const { showPopup } = usePopup3();
553
+ const nodes = useMemo3(
554
+ () => genrePlaylists.map((genrePlaylist) => ({
555
+ id: genrePlaylist.uuid,
556
+ parentId: genrePlaylist.parent?.uuid ?? null,
557
+ name: genrePlaylist.name,
558
+ itemCount: genrePlaylistSize(genrePlaylist, sizeMetric),
559
+ actionable: Boolean(genrePlaylist.criteria),
560
+ side: genrePlaylist.criteria?.side ?? void 0,
561
+ wikidataId: genrePlaylist.criteria?.wikidataId ?? null
562
+ })),
563
+ [genrePlaylists, sizeMetric]
564
+ );
565
+ const handlePlayPause = useCallback3(
566
+ (nodeId) => {
567
+ const genrePlaylist = genrePlaylists.find((g) => g.uuid === nodeId);
568
+ if (!genrePlaylist) return;
569
+ if (nodeId === playingNodeId) {
570
+ setIsPlaying(!isPlaying);
571
+ return;
572
+ }
573
+ if (genrePlaylist.tracksCount === 0) {
574
+ return;
575
+ }
576
+ play(genrePlaylist).catch((error) => {
577
+ console.error("Failed to load genre playlist tracks:", error);
578
+ showPopup(/* @__PURE__ */ jsx7(InternalErrorPopup, { errorCode: ErrorCode3.CLIENT_UNKNOWN }));
579
+ });
580
+ },
581
+ [
582
+ genrePlaylists,
583
+ playingNodeId,
584
+ isPlaying,
585
+ setIsPlaying,
586
+ play,
587
+ showPopup
588
+ ]
589
+ );
590
+ const handleAddChild = useCallback3(
591
+ (parentId) => {
592
+ const genrePlaylist = genrePlaylists.find((g) => g.uuid === parentId);
593
+ if (!genrePlaylist?.criteria) return;
594
+ handleGenreCreationAction(genrePlaylist.criteria);
595
+ },
596
+ [genrePlaylists, handleGenreCreationAction]
597
+ );
598
+ const handleRenameRequest = useCallback3(
599
+ (node) => {
600
+ const genrePlaylist = genrePlaylists.find((g) => g.uuid === node.id);
601
+ if (!genrePlaylist?.criteria) return;
602
+ handleGenreRenameAction(genrePlaylist.criteria);
603
+ },
604
+ [genrePlaylists, handleGenreRenameAction]
605
+ );
606
+ const handleDeleteRequest = useCallback3((node) => {
607
+ if (confirm(`Are you sure you want to delete "${node.name}"?`)) {
608
+ }
609
+ }, []);
610
+ return /* @__PURE__ */ jsx7(
611
+ GenreTreeWheel,
612
+ {
613
+ className,
614
+ nodes,
615
+ itemCountLabel: sizeMetric === "views" ? "Views" : `${capitalize3(trackNoun.singular)} count`,
616
+ playingNodeId,
617
+ playState: isPlaying ? "playing" : "paused",
618
+ onPlayPause: handlePlayPause,
619
+ onAddChild: readOnly ? void 0 : handleAddChild,
620
+ onRenameRequest: readOnly ? void 0 : handleRenameRequest,
621
+ onDeleteRequest: readOnly ? void 0 : handleDeleteRequest,
622
+ additionalActions,
623
+ onNodeClick,
624
+ onNodeHover,
625
+ renderInfoPanelBody,
626
+ selectedNodeId,
627
+ onSelectedNodeChange,
628
+ hideInfoPanelClose,
629
+ hideInfoPanelTitle,
630
+ allowWheelRotation,
631
+ showToolbar,
632
+ controlsOrientation,
633
+ floatingControlsLeading,
634
+ busy,
635
+ defaultViewport,
636
+ onViewportChange,
637
+ ...infoPanelCuration,
638
+ readOnly
639
+ }
640
+ );
641
+ }
642
+
643
+ // src/genre-tree/playlist-tree/TreeWheelRadialPopCore.tsx
644
+ import { useCallback as useCallback4, useMemo as useMemo4 } from "react";
645
+ import {
646
+ GenreTreeOutline,
647
+ GenreTreeWheelRadialPopCore
648
+ } from "@behindthemusictree/genre-tree-view";
649
+ import { usePlayer as usePlayer4 } from "@behindthemusictree/app-kit/player";
650
+ import { capitalize as capitalize4, useTrackNoun as useTrackNoun5 } from "@behindthemusictree/app-kit/track-noun";
651
+ import { jsx as jsx8 } from "react/jsx-runtime";
652
+ function GenrePlaylistTreeWheelRadialPopCore(props) {
653
+ const {
654
+ scope,
655
+ className,
656
+ genrePlaylists,
657
+ handleGenreCreationAction,
658
+ handleGenreRenameAction,
659
+ additionalActions,
660
+ onNodeClick,
661
+ onNodeHover,
662
+ renderInfoPanelBody,
663
+ selectedNodeId,
664
+ onSelectedNodeChange,
665
+ hideInfoPanelClose,
666
+ hideInfoPanelTitle,
667
+ readOnly = false,
668
+ allowWheelRotation,
669
+ showToolbar,
670
+ controlsOrientation,
671
+ sizeMetric = "songs",
672
+ floatingControlsLeading,
673
+ busy,
674
+ outline = false,
675
+ defaultViewport,
676
+ onViewportChange,
677
+ playback
678
+ } = props;
679
+ const focus = props;
680
+ const infoPanelCuration = {
681
+ renderDangerZone: props.renderDangerZone,
682
+ expanded: props.expanded,
683
+ onExpandedChange: props.onExpandedChange,
684
+ collapsed: props.collapsed,
685
+ hideExpandButton: props.hideExpandButton,
686
+ overlayPanel: props.overlayPanel
687
+ };
688
+ const { isPlaying, setIsPlaying } = usePlayer4();
689
+ const defaultPlayback = useGenrePlaylistPlayback({ scope, genrePlaylists });
690
+ const { playingNodeId, play } = playback ?? defaultPlayback;
691
+ const trackNoun = useTrackNoun5();
692
+ const nodes = useMemo4(
693
+ () => genrePlaylists.map((genrePlaylist) => ({
694
+ id: genrePlaylist.uuid,
695
+ parentId: genrePlaylist.parent?.uuid ?? null,
696
+ name: genrePlaylist.name,
697
+ itemCount: genrePlaylistSize(genrePlaylist, sizeMetric),
698
+ actionable: Boolean(genrePlaylist.criteria),
699
+ detached: !genrePlaylist.criteria,
700
+ side: genrePlaylist.criteria?.side ?? void 0,
701
+ wikidataId: genrePlaylist.criteria?.wikidataId ?? null,
702
+ umbrella: genrePlaylist.isUmbrella,
703
+ scene: genrePlaylist.scene ?? void 0
704
+ })),
705
+ [genrePlaylists, sizeMetric]
706
+ );
707
+ const handlePlayPause = useCallback4(
708
+ (nodeId) => {
709
+ const genrePlaylist = genrePlaylists.find((g) => g.uuid === nodeId);
710
+ if (!genrePlaylist) return;
711
+ if (nodeId === playingNodeId) {
712
+ setIsPlaying(!isPlaying);
713
+ return;
714
+ }
715
+ if (genrePlaylist.tracksCount === 0) {
716
+ return;
717
+ }
718
+ play(genrePlaylist).catch((error) => {
719
+ console.error("Failed to load genre playlist tracks:", error);
720
+ });
721
+ },
722
+ [genrePlaylists, playingNodeId, isPlaying, setIsPlaying, play]
723
+ );
724
+ const handleAddChild = useCallback4(
725
+ (parentId) => {
726
+ const genrePlaylist = genrePlaylists.find((g) => g.uuid === parentId);
727
+ if (!genrePlaylist?.criteria) return;
728
+ handleGenreCreationAction(genrePlaylist.criteria);
729
+ },
730
+ [genrePlaylists, handleGenreCreationAction]
731
+ );
732
+ const handleRenameRequest = useCallback4(
733
+ (node) => {
734
+ const genrePlaylist = genrePlaylists.find((g) => g.uuid === node.id);
735
+ if (!genrePlaylist?.criteria) return;
736
+ handleGenreRenameAction(genrePlaylist.criteria);
737
+ },
738
+ [genrePlaylists, handleGenreRenameAction]
739
+ );
740
+ const handleDeleteRequest = useCallback4((node) => {
741
+ if (confirm(`Are you sure you want to delete "${node.name}"?`)) {
742
+ }
743
+ }, []);
744
+ const treeProps = {
745
+ className,
746
+ nodes,
747
+ itemCountLabel: sizeMetric === "views" ? "Views" : `${capitalize4(trackNoun.singular)} count`,
748
+ playingNodeId,
749
+ playState: isPlaying ? "playing" : "paused",
750
+ onPlayPause: handlePlayPause,
751
+ onAddChild: readOnly ? void 0 : handleAddChild,
752
+ onRenameRequest: readOnly ? void 0 : handleRenameRequest,
753
+ onDeleteRequest: readOnly ? void 0 : handleDeleteRequest,
754
+ additionalActions,
755
+ onNodeClick,
756
+ onNodeHover,
757
+ renderInfoPanelBody,
758
+ selectedNodeId,
759
+ onSelectedNodeChange,
760
+ hideInfoPanelClose,
761
+ hideInfoPanelTitle,
762
+ showToolbar,
763
+ ...infoPanelCuration,
764
+ readOnly
765
+ };
766
+ return outline ? /* @__PURE__ */ jsx8(GenreTreeOutline, { ...treeProps }) : /* @__PURE__ */ jsx8(
767
+ GenreTreeWheelRadialPopCore,
768
+ {
769
+ ...treeProps,
770
+ allowWheelRotation,
771
+ controlsOrientation,
772
+ floatingControlsLeading,
773
+ busy,
774
+ defaultViewport,
775
+ onViewportChange,
776
+ ...focus.onFocusGenreChange ? { focusNodeId: focus.focusGenreUuid, onFocusChange: focus.onFocusGenreChange } : { focusNodeId: void 0, onFocusChange: void 0 }
777
+ }
778
+ );
779
+ }
780
+
781
+ // src/genre-tree/GenreTreeWheelHandoff.tsx
782
+ import { useEffect as useEffect2, useRef as useRef3, useState as useState2 } from "react";
783
+ import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
784
+ function GenreTreeWheelHandoff({ skeleton, children, onRevealedChange }) {
785
+ const [revealed, setRevealed] = useState2(false);
786
+ const onRevealedChangeRef = useRef3(onRevealedChange);
787
+ onRevealedChangeRef.current = onRevealedChange;
788
+ useEffect2(() => {
789
+ let innerFrame = 0;
790
+ const outerFrame = requestAnimationFrame(() => {
791
+ innerFrame = requestAnimationFrame(() => {
792
+ setRevealed(true);
793
+ onRevealedChangeRef.current?.(true);
794
+ });
795
+ });
796
+ return () => {
797
+ onRevealedChangeRef.current?.(false);
798
+ cancelAnimationFrame(outerFrame);
799
+ cancelAnimationFrame(innerFrame);
800
+ };
801
+ }, []);
802
+ return /* @__PURE__ */ jsxs5("div", { className: "relative w-full h-full", children: [
803
+ /* @__PURE__ */ jsx9(
804
+ "div",
805
+ {
806
+ className: "absolute inset-0 transition-opacity duration-150 ease-out",
807
+ style: { opacity: revealed ? 1 : 0, pointerEvents: revealed ? "auto" : "none" },
808
+ "aria-hidden": !revealed,
809
+ children
810
+ }
811
+ ),
812
+ !revealed && /* @__PURE__ */ jsx9("div", { className: "absolute inset-0", "aria-hidden": "true", children: skeleton })
813
+ ] });
814
+ }
815
+
816
+ // src/genre-tree/GenreSearch.tsx
817
+ import { ArrowLeft, LoaderCircle, Search, X } from "lucide-react";
818
+ import { Input } from "@behindthemusictree/ui";
819
+ import { useGenreSearch } from "@behindthemusictree/app-kit/genre-tree";
820
+ import { jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
821
+ function GenreSearch({
822
+ genrePlaylists,
823
+ onSelect,
824
+ selectedName = null,
825
+ onClear,
826
+ onPrevious,
827
+ placeholder,
828
+ onQueryChange,
829
+ extraResults
830
+ }) {
831
+ const { query, setQuery, results, canClear, clear, select } = useGenreSearch({
832
+ genrePlaylists,
833
+ onSelect,
834
+ selectedName,
835
+ onClear
836
+ });
837
+ const extraItems = query !== "" && query !== selectedName ? extraResults?.items ?? [] : [];
838
+ const label = extraResults ? "Search" : "Search a genre";
839
+ const loading = query !== "" && query !== selectedName && (extraResults?.loading ?? false);
840
+ const showList = results.length > 0 || extraItems.length > 0;
841
+ const heading = "px-3 pt-2 pb-1 text-xs font-medium uppercase text-[var(--color-text-muted)]";
842
+ return /* @__PURE__ */ jsxs6("div", { className: "genre-search relative w-[calc(var(--layout-detail-panel-w,25.5rem)-2*var(--layout-panel-inset,1rem))] shrink-0", children: [
843
+ onPrevious && /* @__PURE__ */ jsx10(
844
+ "button",
845
+ {
846
+ type: "button",
847
+ "aria-label": "Previous",
848
+ title: "Previous",
849
+ className: "genre-search-previous absolute left-2 top-1/2 z-10 hidden p-1.5 text-[var(--color-text-muted)] rounded-full -translate-y-1/2 hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)]",
850
+ onClick: onPrevious,
851
+ children: /* @__PURE__ */ jsx10(ArrowLeft, { "aria-hidden": "true", className: "w-4 h-4" })
852
+ }
853
+ ),
854
+ /* @__PURE__ */ jsx10(
855
+ Input,
856
+ {
857
+ type: "text",
858
+ value: query,
859
+ onChange: (event) => {
860
+ setQuery(event.target.value);
861
+ onQueryChange?.(event.target.value);
862
+ },
863
+ placeholder: placeholder ?? `${label}\u2026`,
864
+ "aria-label": label,
865
+ "aria-busy": loading,
866
+ className: "h-[var(--layout-search-h,3rem)] pl-6 pr-20 text-base transition-[padding] duration-200 ease-out motion-reduce:transition-none bg-[var(--color-surface)] border-[var(--color-border)] rounded-full shadow-md"
867
+ }
868
+ ),
869
+ /* @__PURE__ */ jsxs6("div", { className: "absolute right-3 top-1/2 flex items-center -translate-y-1/2", children: [
870
+ /* @__PURE__ */ jsxs6(
871
+ "span",
872
+ {
873
+ "data-loading": loading,
874
+ className: "relative p-2 text-[var(--color-text-muted)] pointer-events-none",
875
+ children: [
876
+ /* @__PURE__ */ jsx10(
877
+ Search,
878
+ {
879
+ "aria-hidden": "true",
880
+ className: `w-6 h-6 transition-opacity duration-200 motion-reduce:transition-none ${loading ? "opacity-0" : ""}`
881
+ }
882
+ ),
883
+ /* @__PURE__ */ jsx10(
884
+ LoaderCircle,
885
+ {
886
+ "aria-hidden": "true",
887
+ className: `absolute inset-2 w-6 h-6 transition-opacity duration-200 motion-reduce:transition-none ${loading ? "opacity-100 delay-300 animate-spin motion-reduce:animate-none" : "opacity-0"}`
888
+ }
889
+ )
890
+ ]
891
+ }
892
+ ),
893
+ canClear && /* @__PURE__ */ jsx10(
894
+ "button",
895
+ {
896
+ type: "button",
897
+ "aria-label": "Clear search",
898
+ className: "p-2 text-[var(--color-text-muted)] rounded-full hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)]",
899
+ onClick: () => {
900
+ clear();
901
+ onQueryChange?.("");
902
+ },
903
+ children: /* @__PURE__ */ jsx10(X, { "aria-hidden": "true", className: "w-6 h-6" })
904
+ }
905
+ )
906
+ ] }),
907
+ extraResults?.status && /* @__PURE__ */ jsx10("p", { role: "status", "aria-live": "polite", className: "sr-only", children: extraResults.status }),
908
+ showList && /* @__PURE__ */ jsxs6("ul", { className: "genre-search-results absolute z-40 w-full max-h-64 mt-1 overflow-y-auto bg-[var(--color-surface)] border border-[var(--color-border)] rounded-xl shadow-md", children: [
909
+ extraResults && results.length > 0 && /* @__PURE__ */ jsx10("li", { className: heading, children: "Genres" }),
910
+ results.map((genrePlaylist) => /* @__PURE__ */ jsx10("li", { children: /* @__PURE__ */ jsxs6(
911
+ "button",
912
+ {
913
+ type: "button",
914
+ className: "w-full px-3 py-1.5 text-left hover:bg-[var(--color-surface-muted)]",
915
+ onClick: () => {
916
+ select(genrePlaylist);
917
+ onQueryChange?.("");
918
+ },
919
+ children: [
920
+ genrePlaylist.name,
921
+ genrePlaylist.isUmbrella && /* @__PURE__ */ jsx10("span", { className: "ml-2 text-xs italic text-[var(--color-text-muted)]", children: "umbrella" })
922
+ ]
923
+ }
924
+ ) }, genrePlaylist.uuid)),
925
+ extraResults && extraItems.length > 0 && /* @__PURE__ */ jsx10("li", { className: heading, children: extraResults.label }),
926
+ extraItems.map((item) => /* @__PURE__ */ jsx10("li", { children: /* @__PURE__ */ jsx10(
927
+ "button",
928
+ {
929
+ type: "button",
930
+ className: "w-full px-3 py-1.5 text-left hover:bg-[var(--color-surface-muted)]",
931
+ onClick: () => {
932
+ setQuery("");
933
+ onQueryChange?.("");
934
+ item.onSelect();
935
+ },
936
+ children: item.content
937
+ }
938
+ ) }, item.key))
939
+ ] })
940
+ ] });
941
+ }
942
+
943
+ // src/genre-tree/GenreActionBand.tsx
944
+ import { MoveUpRight, Pause, Pencil, Play, Plus, ZoomIn } from "lucide-react";
945
+ import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
946
+ function GenreActionBand({
947
+ node,
948
+ onPlayPause,
949
+ isPlaying = false,
950
+ onZoomIn,
951
+ onAddChild,
952
+ onRename,
953
+ onChangeParent,
954
+ additionalActions
955
+ }) {
956
+ const items = [];
957
+ const adminItems = [];
958
+ if (onPlayPause) {
959
+ items.push({
960
+ key: "play-pause",
961
+ label: isPlaying ? "Pause" : "Play",
962
+ icon: isPlaying ? /* @__PURE__ */ jsx11(Pause, { "aria-hidden": "true", className: "w-5 h-5" }) : /* @__PURE__ */ jsx11(Play, { "aria-hidden": "true", className: "w-5 h-5" }),
963
+ onClick: onPlayPause
964
+ });
965
+ }
966
+ if (onZoomIn) {
967
+ items.push({
968
+ key: "zoom-in",
969
+ label: "Focus",
970
+ icon: /* @__PURE__ */ jsx11(ZoomIn, { "aria-hidden": "true", className: "w-5 h-5" }),
971
+ onClick: onZoomIn
972
+ });
973
+ }
974
+ if (onAddChild) {
975
+ adminItems.push({ key: "add-child", label: "Add", icon: /* @__PURE__ */ jsx11(Plus, { "aria-hidden": "true", className: "w-5 h-5" }), onClick: onAddChild });
976
+ }
977
+ if (onRename) {
978
+ adminItems.push({ key: "rename", label: "Rename", icon: /* @__PURE__ */ jsx11(Pencil, { "aria-hidden": "true", className: "w-5 h-5" }), onClick: onRename });
979
+ }
980
+ if (onChangeParent) {
981
+ adminItems.push({ key: "change-parent", label: "Parent", icon: /* @__PURE__ */ jsx11(MoveUpRight, { "aria-hidden": "true", className: "w-5 h-5" }), onClick: onChangeParent });
982
+ }
983
+ for (const action of additionalActions?.(node) ?? []) {
984
+ items.push({
985
+ key: action.key,
986
+ label: action.label(node),
987
+ icon: action.icon(node),
988
+ onClick: (event) => action.onClick(event, node),
989
+ disabled: action.enabled ? !action.enabled(node) : false
990
+ });
991
+ }
992
+ if (items.length === 0 && adminItems.length === 0) return null;
993
+ const renderItems = (list) => list.map((item) => /* @__PURE__ */ jsxs7(
994
+ "button",
995
+ {
996
+ type: "button",
997
+ disabled: item.disabled,
998
+ onClick: item.onClick,
999
+ className: "group flex flex-col items-center gap-1 w-16 text-xs text-center text-[var(--color-text)] focus-visible:outline-none disabled:opacity-50",
1000
+ children: [
1001
+ /* @__PURE__ */ jsx11("span", { className: "flex items-center justify-center w-10 h-10 rounded-full group-focus-visible:ring-2 group-focus-visible:ring-[var(--color-focus-ring)] bg-[var(--color-surface-muted)] transition-colors group-hover:bg-[var(--color-border)] group-disabled:group-hover:bg-[var(--color-surface-muted)]", children: item.icon }),
1002
+ item.label
1003
+ ]
1004
+ },
1005
+ item.key
1006
+ ));
1007
+ return /* @__PURE__ */ jsxs7("div", { className: "genre-action-band border-b border-[var(--color-border)]", children: [
1008
+ items.length > 0 && /* @__PURE__ */ jsx11("div", { className: "flex flex-wrap gap-1 px-3.5 py-3", children: renderItems(items) }),
1009
+ adminItems.length > 0 && /* @__PURE__ */ jsxs7(
1010
+ "section",
1011
+ {
1012
+ "aria-label": "Admin actions",
1013
+ className: `px-3.5 py-3 ${items.length > 0 ? "border-t border-[var(--color-border)]" : ""}`,
1014
+ children: [
1015
+ /* @__PURE__ */ jsx11("h3", { className: "mb-2 text-xs font-semibold uppercase tracking-wide text-[var(--color-text-muted)]", children: "Admin" }),
1016
+ /* @__PURE__ */ jsx11("div", { className: "flex flex-wrap gap-1", children: renderItems(adminItems) })
1017
+ ]
1018
+ }
1019
+ )
1020
+ ] });
1021
+ }
1022
+
1023
+ // src/genre-tree/PanelEdgeTab.tsx
1024
+ import { ChevronLeft, ChevronRight } from "lucide-react";
1025
+ import { twMerge } from "tailwind-merge";
1026
+ import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
1027
+ var buttonClassName = "flex h-12 w-full items-center justify-center p-0 text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)] focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-[var(--color-primary)]";
1028
+ function PanelEdgeTab({ side, edge, center, controls, className }) {
1029
+ if (!edge && !center) return null;
1030
+ const isLeft = side === "left";
1031
+ const EdgeIcon = isLeft ? ChevronLeft : ChevronRight;
1032
+ const CenterIcon = isLeft ? ChevronRight : ChevronLeft;
1033
+ const renderButton = (action, icon) => /* @__PURE__ */ jsx12(
1034
+ "button",
1035
+ {
1036
+ type: "button",
1037
+ "aria-label": action.label,
1038
+ title: action.label,
1039
+ "aria-controls": controls,
1040
+ "aria-expanded": action.expanded,
1041
+ className: buttonClassName,
1042
+ onClick: action.onClick,
1043
+ children: icon
1044
+ }
1045
+ );
1046
+ const edgeButton = edge && renderButton(edge, /* @__PURE__ */ jsx12(EdgeIcon, { "aria-hidden": "true", className: "h-5 w-5" }));
1047
+ const centerButton = center && renderButton(center, /* @__PURE__ */ jsx12(CenterIcon, { "aria-hidden": "true", className: "h-5 w-5" }));
1048
+ const buttons = isLeft ? [edgeButton, centerButton] : [centerButton, edgeButton];
1049
+ return /* @__PURE__ */ jsxs8(
1050
+ "div",
1051
+ {
1052
+ className: twMerge(
1053
+ "panel-edge-tab flex w-[var(--layout-edge-tab-w)] flex-col overflow-hidden bg-[var(--color-surface)] shadow-[0_1px_2px_rgba(60,64,67,0.3),0_2px_6px_2px_rgba(60,64,67,0.15)] [clip-path:inset(-0.5rem_-0.5rem_-0.5rem_0)]",
1054
+ isLeft ? "rounded-r-lg" : "rounded-l-lg [clip-path:inset(-0.5rem_0_-0.5rem_-0.5rem)]",
1055
+ className
1056
+ ),
1057
+ children: [
1058
+ buttons[0],
1059
+ buttons[0] && buttons[1] && /* @__PURE__ */ jsx12("div", { role: "presentation", className: "h-px shrink-0 bg-[var(--color-border)]" }),
1060
+ buttons[1]
1061
+ ]
1062
+ }
1063
+ );
1064
+ }
1065
+
1066
+ // src/genre-tree/ChangeParentPopup.tsx
1067
+ import { useEffect as useEffect3, useMemo as useMemo5 } from "react";
1068
+ import {
1069
+ getReparentCandidates,
1070
+ useUpdateGenre
1071
+ } from "@behindthemusictree/app-kit/genre-tree";
1072
+ import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
1073
+ function ChangeParentPopup({
1074
+ genrePlaylist,
1075
+ genrePlaylists,
1076
+ scope,
1077
+ getBackendBaseUrl,
1078
+ onClose,
1079
+ onParentChanged
1080
+ }) {
1081
+ const { mutate, isPending, formErrors } = useUpdateGenre(scope, getBackendBaseUrl);
1082
+ const candidates = useMemo5(
1083
+ () => getReparentCandidates(genrePlaylists, genrePlaylist.uuid),
1084
+ [genrePlaylists, genrePlaylist.uuid]
1085
+ );
1086
+ const handleSelect = (newParent) => {
1087
+ const genre = genrePlaylist.criteria.uuid;
1088
+ const parentPlaylistUuid = genrePlaylist.parent?.uuid;
1089
+ const from = parentPlaylistUuid ? genrePlaylists.find(({ uuid }) => uuid === parentPlaylistUuid)?.criteria?.uuid ?? null : null;
1090
+ mutate(
1091
+ { uuid: genre, data: { parent: newParent.criteria.uuid } },
1092
+ {
1093
+ onSuccess: () => {
1094
+ onClose();
1095
+ onParentChanged?.({ genre, from, to: newParent.criteria.uuid });
1096
+ }
1097
+ }
1098
+ );
1099
+ };
1100
+ useEffect3(() => {
1101
+ const handleKeyDown = (event) => {
1102
+ if (event.key === "Escape") onClose();
1103
+ };
1104
+ window.addEventListener("keydown", handleKeyDown);
1105
+ return () => window.removeEventListener("keydown", handleKeyDown);
1106
+ }, [onClose]);
1107
+ return /* @__PURE__ */ jsxs9(BasePopup_default, { title: `Change parent of ${genrePlaylist.name}`, onClose, showCancelButton: true, fitContent: true, children: [
1108
+ /* @__PURE__ */ jsxs9("p", { className: "mb-3 text-sm text-[var(--color-text-muted)]", children: [
1109
+ "Current parent: ",
1110
+ genrePlaylist.parent?.name ?? "none"
1111
+ ] }),
1112
+ /* @__PURE__ */ jsx13("div", { "aria-busy": isPending, className: isPending ? "pointer-events-none opacity-60" : void 0, children: /* @__PURE__ */ jsx13(
1113
+ GenreSearch,
1114
+ {
1115
+ genrePlaylists: candidates,
1116
+ onSelect: handleSelect,
1117
+ placeholder: "Search a new parent\u2026"
1118
+ }
1119
+ ) }),
1120
+ formErrors.length > 0 && /* @__PURE__ */ jsx13("p", { role: "alert", className: "mt-3 text-sm text-[var(--color-red-500)]", children: formErrors.map(({ message }) => message).join(" ") })
1121
+ ] });
1122
+ }
1123
+
1124
+ // src/genre-tree/artist/useArtistPanel.tsx
1125
+ import { Skeleton as Skeleton4 } from "@behindthemusictree/ui";
1126
+ import { useArtist } from "@behindthemusictree/app-kit/genre-tree";
1127
+
1128
+ // src/genre-tree/artist/ArtistHeader.tsx
1129
+ import { FieldList } from "@behindthemusictree/ui";
1130
+
1131
+ // src/genre-tree/artist/ArtistLinks.tsx
1132
+ import { Globe, Share2 } from "lucide-react";
1133
+ import {
1134
+ SiBandcamp,
1135
+ SiDiscogs,
1136
+ SiMusicbrainz,
1137
+ SiSoundcloud,
1138
+ SiSpotify,
1139
+ SiWikidata,
1140
+ SiWikipedia,
1141
+ SiYoutube
1142
+ } from "react-icons/si";
1143
+ import { Chip } from "@behindthemusictree/ui";
1144
+ import { jsx as jsx14 } from "react/jsx-runtime";
1145
+ var LINK_KINDS = {
1146
+ official: { label: "Official website", Icon: Globe },
1147
+ wikipedia: { label: "Wikipedia", Icon: SiWikipedia },
1148
+ wikidata: { label: "Wikidata", Icon: SiWikidata },
1149
+ spotify: { label: "Spotify", Icon: SiSpotify },
1150
+ youtube: { label: "YouTube", Icon: SiYoutube },
1151
+ bandcamp: { label: "Bandcamp", Icon: SiBandcamp },
1152
+ soundcloud: { label: "SoundCloud", Icon: SiSoundcloud },
1153
+ discogs: { label: "Discogs", Icon: SiDiscogs },
1154
+ social: { label: "Social", Icon: Share2 }
1155
+ };
1156
+ function socialLabel(url) {
1157
+ try {
1158
+ return new URL(url).hostname.replace(/^www\./, "");
1159
+ } catch {
1160
+ return LINK_KINDS.social.label;
1161
+ }
1162
+ }
1163
+ function artistLinks(artist) {
1164
+ const links = artist.links.map(({ kind, url }) => ({
1165
+ key: `${kind}-${url}`,
1166
+ url,
1167
+ Icon: LINK_KINDS[kind].Icon,
1168
+ label: kind === "social" ? socialLabel(url) : LINK_KINDS[kind].label
1169
+ }));
1170
+ if (artist.musicbrainzArtistId) {
1171
+ links.push({
1172
+ key: "musicbrainz",
1173
+ url: `https://musicbrainz.org/artist/${artist.musicbrainzArtistId}`,
1174
+ Icon: SiMusicbrainz,
1175
+ label: "MusicBrainz"
1176
+ });
1177
+ }
1178
+ return links;
1179
+ }
1180
+ function ArtistLinks({ links }) {
1181
+ return /* @__PURE__ */ jsx14("ul", { className: "flex flex-wrap gap-1.5", children: links.map(({ key, url, Icon, label }) => /* @__PURE__ */ jsx14("li", { children: /* @__PURE__ */ jsx14(Chip, { href: url, icon: /* @__PURE__ */ jsx14(Icon, { className: "h-3.5 w-3.5 shrink-0", "aria-hidden": "true" }), children: label }) }, key)) });
1182
+ }
1183
+
1184
+ // src/genre-tree/artist/formatYears.ts
1185
+ function formatYears(beginYear, endYear, ended) {
1186
+ if (beginYear === null && endYear === null) return ended ? "ended" : null;
1187
+ const end = endYear ?? (ended ? "?" : "present");
1188
+ return `${beginYear ?? "?"}\u2013${end}`;
1189
+ }
1190
+
1191
+ // src/genre-tree/artist/ArtistHeader.tsx
1192
+ import { jsx as jsx15 } from "react/jsx-runtime";
1193
+ var countryNames = new Intl.DisplayNames(["en"], { type: "region" });
1194
+ function ArtistHeader({ artist }) {
1195
+ const fields = [];
1196
+ if (artist.type) fields.push({ label: "Type", value: artist.type.charAt(0).toUpperCase() + artist.type.slice(1) });
1197
+ const country = artist.country && countryNames.of(artist.country);
1198
+ if (country) fields.push({ label: "Country", value: country });
1199
+ const years = formatYears(artist.beginYear, artist.endYear, artist.ended);
1200
+ if (years) fields.push({ label: "Active", value: years });
1201
+ const links = artistLinks(artist);
1202
+ if (links.length > 0) fields.push({ label: "Links", value: /* @__PURE__ */ jsx15(ArtistLinks, { links }) });
1203
+ if (fields.length === 0) return null;
1204
+ return /* @__PURE__ */ jsx15(FieldList, { items: fields });
1205
+ }
1206
+
1207
+ // src/genre-tree/artist/ArtistPhoto.tsx
1208
+ import { jsx as jsx16, jsxs as jsxs10 } from "react/jsx-runtime";
1209
+ function ExternalLink({ href, children }) {
1210
+ return /* @__PURE__ */ jsx16("a", { href, target: "_blank", rel: "noopener noreferrer", className: "underline-offset-2 hover:underline", children });
1211
+ }
1212
+ function ArtistPhoto({ image, name }) {
1213
+ return /* @__PURE__ */ jsxs10("figure", { className: "flex flex-col gap-1.5 px-6 py-2.5", children: [
1214
+ /* @__PURE__ */ jsx16("img", { src: image.url, alt: name, className: "h-64 w-full object-contain bg-[var(--color-surface-muted)] rounded" }),
1215
+ /* @__PURE__ */ jsxs10("figcaption", { className: "text-xs text-[var(--color-text-muted)]", children: [
1216
+ "Photo: ",
1217
+ /* @__PURE__ */ jsx16(ExternalLink, { href: image.pageUrl, children: image.author ?? "Wikimedia Commons" }),
1218
+ ",",
1219
+ " ",
1220
+ image.licenseUrl ? /* @__PURE__ */ jsx16(ExternalLink, { href: image.licenseUrl, children: image.license }) : image.license
1221
+ ] })
1222
+ ] });
1223
+ }
1224
+
1225
+ // src/genre-tree/artist/ArtistMembers.tsx
1226
+ import { PanelGroup, PanelSection } from "@behindthemusictree/ui";
1227
+ import { jsx as jsx17, jsxs as jsxs11 } from "react/jsx-runtime";
1228
+ function MembershipList({ title, memberships, renderArtistLink }) {
1229
+ if (memberships.length === 0) return null;
1230
+ return /* @__PURE__ */ jsx17(PanelGroup, { title, children: /* @__PURE__ */ jsx17("ul", { children: memberships.map((membership, index) => {
1231
+ const details = [
1232
+ formatYears(membership.beginYear, membership.endYear, membership.ended),
1233
+ ...membership.roles
1234
+ ];
1235
+ const detailsText = details.filter(Boolean).join(" \xB7 ");
1236
+ return (
1237
+ // A member can have several periods in the same group.
1238
+ /* @__PURE__ */ jsxs11("li", { className: "truncate py-0.5", title: detailsText || void 0, children: [
1239
+ /* @__PURE__ */ jsx17("span", { className: "font-medium text-[var(--color-text)]", children: renderArtistLink(membership.artist) }),
1240
+ detailsText && /* @__PURE__ */ jsxs11("span", { className: "text-[var(--color-text-muted)]", children: [
1241
+ " \u2014 ",
1242
+ detailsText
1243
+ ] })
1244
+ ] }, `${membership.artist.uuid}-${index}`)
1245
+ );
1246
+ }) }) });
1247
+ }
1248
+ function ArtistMembers({ title, memberships, renderArtistLink }) {
1249
+ if (memberships.length === 0) return null;
1250
+ const isCurrent = (membership) => !membership.ended && membership.endYear === null;
1251
+ return /* @__PURE__ */ jsxs11(PanelSection, { title, children: [
1252
+ /* @__PURE__ */ jsx17(MembershipList, { title: "Current", memberships: memberships.filter(isCurrent), renderArtistLink }),
1253
+ /* @__PURE__ */ jsx17(
1254
+ MembershipList,
1255
+ {
1256
+ title: "Past",
1257
+ memberships: memberships.filter((membership) => !isCurrent(membership)),
1258
+ renderArtistLink
1259
+ }
1260
+ )
1261
+ ] });
1262
+ }
1263
+
1264
+ // src/genre-tree/artist/ArtistDiscography.tsx
1265
+ import { PanelGroup as PanelGroup2, PanelSection as PanelSection2 } from "@behindthemusictree/ui";
1266
+ import { jsx as jsx18, jsxs as jsxs12 } from "react/jsx-runtime";
1267
+ var GROUPS = ["Albums", "EPs", "Singles", "Live", "Compilations", "Other"];
1268
+ var PRIMARY_GROUPS = { album: "Albums", ep: "EPs", single: "Singles" };
1269
+ function discographyGroup({ primaryType, secondaryTypes }) {
1270
+ const secondary = secondaryTypes.map((type) => type.toLowerCase());
1271
+ if (secondary.includes("live")) return "Live";
1272
+ if (secondary.includes("compilation")) return "Compilations";
1273
+ return PRIMARY_GROUPS[primaryType?.toLowerCase() ?? ""] ?? "Other";
1274
+ }
1275
+ function byYear(a, b) {
1276
+ if (a.year !== b.year) {
1277
+ if (a.year === null) return 1;
1278
+ if (b.year === null) return -1;
1279
+ return a.year.localeCompare(b.year);
1280
+ }
1281
+ return a.name.localeCompare(b.name);
1282
+ }
1283
+ function ArtistDiscography({ albums }) {
1284
+ if (albums.length === 0) return null;
1285
+ const sorted = [...albums].sort(byYear);
1286
+ return /* @__PURE__ */ jsx18(PanelSection2, { title: "Discography", children: GROUPS.map((group) => {
1287
+ const groupAlbums = sorted.filter((album) => discographyGroup(album) === group);
1288
+ if (groupAlbums.length === 0) return null;
1289
+ return /* @__PURE__ */ jsx18(PanelGroup2, { title: group, children: /* @__PURE__ */ jsx18("ul", { children: groupAlbums.map((album) => /* @__PURE__ */ jsxs12("li", { className: "grid grid-cols-[2.5rem_minmax(0,1fr)] gap-2 py-0.5", children: [
1290
+ /* @__PURE__ */ jsx18("span", { className: "tabular-nums text-[var(--color-text-muted)]", children: album.year ?? "\u2014" }),
1291
+ /* @__PURE__ */ jsx18("span", { className: "truncate text-[var(--color-text)]", title: album.name, children: album.name })
1292
+ ] }, album.uuid)) }) }, group);
1293
+ }) });
1294
+ }
1295
+
1296
+ // src/genre-tree/artist/ArtistSongs.tsx
1297
+ import { useState as useState3 } from "react";
1298
+ import { keepPreviousData } from "@tanstack/react-query";
1299
+ import { Play as Play2 } from "lucide-react";
1300
+ import { Pagination, PanelSection as PanelSection3, Skeleton as Skeleton3 } from "@behindthemusictree/ui";
1301
+ import { usePlayer as usePlayer7 } from "@behindthemusictree/app-kit/player";
1302
+ import {
1303
+ SongDetailedSchema as SongDetailedSchema2,
1304
+ libraryEndpoints as libraryEndpoints2,
1305
+ songUnplayableReason as songUnplayableReason3,
1306
+ useTrackList as useTrackList4
1307
+ } from "@behindthemusictree/app-kit/genre-tree";
1308
+ import { PaginatedResponseSchema as PaginatedResponseSchema2, useFetchWrapper as useFetchWrapper2, useQueryWithParse } from "@behindthemusictree/app-kit/transport";
1309
+
1310
+ // src/genre-tree/track-list-sidebar/TrackItem.tsx
1311
+ import { usePlayer as usePlayer6 } from "@behindthemusictree/app-kit/player";
1312
+ import { useTrackList as useTrackList3 } from "@behindthemusictree/app-kit/genre-tree";
1313
+
1314
+ // src/genre-tree/TrackPositionPlayPause.tsx
1315
+ import { FaPlay as FaPlay2, FaPause as FaPause2 } from "react-icons/fa";
1316
+ import { usePlayer as usePlayer5 } from "@behindthemusictree/app-kit/player";
1317
+ import { PlayStates as PlayStates2 } from "@behindthemusictree/app-kit/player";
1318
+ import { RingLoader as RingLoader2 } from "@behindthemusictree/ui";
1319
+ import { jsx as jsx19, jsxs as jsxs13 } from "react/jsx-runtime";
1320
+ function TrackPositionPlayPause({ position, uuid, handlePlayPauseClick }) {
1321
+ const { playerTrackObject, playState } = usePlayer5();
1322
+ const isThisTrack = playerTrackObject?.track.id === uuid;
1323
+ return /* @__PURE__ */ jsxs13(
1324
+ "div",
1325
+ {
1326
+ className: "track-position-play-pause flex items-center justify-center text-lg w-16 cursor-pointer",
1327
+ style: { minWidth: "4rem", maxWidth: "4rem" },
1328
+ onClick: handlePlayPauseClick,
1329
+ children: [
1330
+ /* @__PURE__ */ jsx19("div", { className: "group-hover:hidden", children: /* @__PURE__ */ jsx19("div", { children: isThisTrack && playState !== PlayStates2.STOPPED ? /* @__PURE__ */ jsxs13("div", { className: "flex space-x-1 items-end", children: [
1331
+ /* @__PURE__ */ jsx19(
1332
+ "div",
1333
+ {
1334
+ className: `w-playingbar bg-[var(--color-green-500)] h-3 origin-bottom ${playState === PlayStates2.PLAYING ? "animate-scale-pulse" : ""}`
1335
+ }
1336
+ ),
1337
+ /* @__PURE__ */ jsx19(
1338
+ "div",
1339
+ {
1340
+ className: `w-playingbar bg-[var(--color-green-500)] h-4 origin-bottom ${playState === PlayStates2.PLAYING ? "animate-scale-pulse delay-200" : ""}`,
1341
+ style: { animationDelay: "0.2s" }
1342
+ }
1343
+ ),
1344
+ /* @__PURE__ */ jsx19(
1345
+ "div",
1346
+ {
1347
+ className: `w-playingbar bg-[var(--color-green-500)] h-3 origin-bottom ${playState === PlayStates2.PLAYING ? "animate-scale-pulse delay-400" : ""}`,
1348
+ style: { animationDelay: "0.3s" }
1349
+ }
1350
+ )
1351
+ ] }) : position }) }),
1352
+ /* @__PURE__ */ jsx19("div", { className: "hidden group-hover:flex items-center justify-center", children: isThisTrack && playState === PlayStates2.LOADING ? /* @__PURE__ */ jsx19(RingLoader2, { size: 16 }) : isThisTrack && playState === PlayStates2.PLAYING ? /* @__PURE__ */ jsx19(FaPause2, {}) : /* @__PURE__ */ jsx19(FaPlay2, {}) })
1353
+ ]
1354
+ }
1355
+ );
1356
+ }
1357
+
1358
+ // src/genre-tree/track-list-sidebar/TrackItem.tsx
1359
+ import { isSong as isSong2, songUnplayableReason as songUnplayableReason2 } from "@behindthemusictree/app-kit/genre-tree";
1360
+ import { ArtistNames as ArtistNames2 } from "@behindthemusictree/app-kit/genre-tree";
1361
+ import { jsx as jsx20, jsxs as jsxs14 } from "react/jsx-runtime";
1362
+ function TrackItem({
1363
+ track,
1364
+ position,
1365
+ renderDuration,
1366
+ renderActions,
1367
+ renderArtistLink
1368
+ }) {
1369
+ const { handlePlayPauseAction, playerTrackObject, loadTrackForPlayer } = usePlayer6();
1370
+ const { trackList, toTrackAtPosition } = useTrackList3();
1371
+ const scope = trackList?.origin?.scope ?? null;
1372
+ const unplayableReason = isSong2(track) ? songUnplayableReason2(track) : null;
1373
+ const handlePlayPauseClick = (event) => {
1374
+ event.stopPropagation();
1375
+ if (playerTrackObject && playerTrackObject.track.id === track.uuid) {
1376
+ handlePlayPauseAction();
1377
+ } else if (scope != null) {
1378
+ toTrackAtPosition(position);
1379
+ loadTrackForPlayer(track.uuid);
1380
+ }
1381
+ };
1382
+ return /* @__PURE__ */ jsxs14(
1383
+ "div",
1384
+ {
1385
+ className: `track-item flex h-14 text-[var(--color-text)] ${unplayableReason ? "opacity-50" : "hover:bg-[var(--color-surface-muted)] group"}`,
1386
+ title: unplayableReason ?? void 0,
1387
+ children: [
1388
+ unplayableReason ? /* @__PURE__ */ jsx20(
1389
+ "div",
1390
+ {
1391
+ className: "flex items-center justify-center text-lg w-16",
1392
+ style: { minWidth: "4rem", maxWidth: "4rem" },
1393
+ "aria-disabled": "true",
1394
+ children: position
1395
+ }
1396
+ ) : /* @__PURE__ */ jsx20(TrackPositionPlayPause, { position, uuid: track.uuid, handlePlayPauseClick }),
1397
+ /* @__PURE__ */ jsxs14("div", { className: "title-artist-container flex flex-col items-start justify-center min-w-0 flex-1", children: [
1398
+ /* @__PURE__ */ jsxs14("div", { className: "flex max-w-full items-center gap-2", children: [
1399
+ /* @__PURE__ */ jsx20("div", { className: "title text-lg font-bold text-[var(--color-text)] max-w-full truncate", children: track.title }),
1400
+ isSong2(track) && /* @__PURE__ */ jsx20(MusicBrainzRecordingLink, { song: track })
1401
+ ] }),
1402
+ track.artists && track.artists.length > 0 ? /* @__PURE__ */ jsx20("div", { className: "artist text-base max-w-full truncate text-[var(--color-text-muted)]", children: /* @__PURE__ */ jsx20(ArtistNames2, { artists: track.artists, renderArtistLink }) }) : "",
1403
+ unplayableReason && /* @__PURE__ */ jsx20("div", { className: "text-xs", children: /* @__PURE__ */ jsx20(UnplayableReason, { reason: unplayableReason }) })
1404
+ ] }),
1405
+ /* @__PURE__ */ jsx20("div", { className: "album-name items-start justify-center w-1/3 min-w-0 ml-2 max-w-full truncate text-[var(--color-text-muted)]", children: track.album ? track.album.name : "" }),
1406
+ /* @__PURE__ */ jsx20("div", { className: "genre-name-container flex items-center justify-end w-1/6 min-w-0 shrink-0", children: track.genre ? /* @__PURE__ */ jsx20("div", { className: "genre-name font-bold p-1 border border-[var(--color-text-muted)] text-xs max-w-full truncate", children: track.genre.name }) : "" }),
1407
+ renderDuration && /* @__PURE__ */ jsx20(
1408
+ "div",
1409
+ {
1410
+ className: "duration flex text-base w-16 items-center justify-center",
1411
+ style: { minWidth: "4rem", maxWidth: "4rem" },
1412
+ children: renderDuration(track)
1413
+ }
1414
+ ),
1415
+ renderActions && /* @__PURE__ */ jsx20("div", { className: "edit flex text-base w-6 items-center justify-center mr-2 cursor-pointer", children: renderActions(track) })
1416
+ ]
1417
+ }
1418
+ );
1419
+ }
1420
+
1421
+ // src/genre-tree/artist/ArtistSongs.tsx
1422
+ import { Fragment as Fragment4, jsx as jsx21, jsxs as jsxs15 } from "react/jsx-runtime";
1423
+ var SongPageSchema2 = PaginatedResponseSchema2(SongDetailedSchema2);
1424
+ var SORTS = [
1425
+ { ordering: "title", label: "Title" },
1426
+ { ordering: "-albumYear", label: "Year" }
1427
+ ];
1428
+ function ArtistSongs({ artist, getBackendBaseUrl, renderArtistLink }) {
1429
+ const [page, setPage] = useState3(1);
1430
+ const [ordering, setOrdering] = useState3("title");
1431
+ const { fetch } = useFetchWrapper2(getBackendBaseUrl);
1432
+ const { playNewTrackListFromArtist } = useTrackList4();
1433
+ const { playerTrackObject } = usePlayer7();
1434
+ const { data, isPending, isError } = useQueryWithParse({
1435
+ queryKey: ["referenceSongs", "artist", artist.uuid, ordering, page],
1436
+ queryFn: () => fetch(libraryEndpoints2.reference.songs.list(), true, false, void 0, {
1437
+ artist: artist.uuid,
1438
+ ordering,
1439
+ page
1440
+ }),
1441
+ schema: SongPageSchema2,
1442
+ placeholderData: keepPreviousData,
1443
+ context: "ArtistSongs"
1444
+ });
1445
+ const play = (startSongUuid) => playNewTrackListFromArtist({ uuid: artist.uuid, name: artist.name }, "reference", {
1446
+ ordering,
1447
+ startSongUuid
1448
+ });
1449
+ const handleRowClickCapture = (event, song) => {
1450
+ if (!(event.target instanceof Element) || !event.target.closest(".track-position-play-pause")) return;
1451
+ if (playerTrackObject?.track.id === song.uuid || songUnplayableReason3(song) !== null) return;
1452
+ event.stopPropagation();
1453
+ void play(song.uuid);
1454
+ };
1455
+ return /* @__PURE__ */ jsx21(PanelSection3, { title: "Songs", children: isPending ? /* @__PURE__ */ jsx21(Skeleton3, { className: "h-14", "aria-busy": "true" }) : isError ? /* @__PURE__ */ jsx21("p", { className: "text-red-600", children: "Could not load songs." }) : data.results.length === 0 ? /* @__PURE__ */ jsx21("p", { className: "text-[var(--color-text-muted)]", children: "No songs yet." }) : /* @__PURE__ */ jsxs15(Fragment4, { children: [
1456
+ /* @__PURE__ */ jsxs15("div", { className: "flex flex-wrap items-center justify-between gap-2 mb-2", children: [
1457
+ /* @__PURE__ */ jsxs15(
1458
+ "button",
1459
+ {
1460
+ type: "button",
1461
+ onClick: () => void play(),
1462
+ className: "flex w-fit items-center gap-1.5 px-3 py-1 text-xs font-medium bg-gray-900 text-white rounded-full hover:bg-gray-700",
1463
+ children: [
1464
+ /* @__PURE__ */ jsx21(Play2, { className: "h-3.5 w-3.5", "aria-hidden": "true" }),
1465
+ "Play all"
1466
+ ]
1467
+ }
1468
+ ),
1469
+ /* @__PURE__ */ jsx21("div", { role: "group", "aria-label": "Sort songs by", className: "flex gap-1 text-xs", children: SORTS.map((sort) => /* @__PURE__ */ jsx21(
1470
+ "button",
1471
+ {
1472
+ type: "button",
1473
+ "aria-pressed": ordering === sort.ordering,
1474
+ onClick: () => {
1475
+ setOrdering(sort.ordering);
1476
+ setPage(1);
1477
+ },
1478
+ className: "px-2.5 py-0.5 text-[var(--color-text)] rounded-full hover:bg-[var(--color-surface-muted)] aria-pressed:bg-gray-900 aria-pressed:text-white",
1479
+ children: sort.label
1480
+ },
1481
+ sort.ordering
1482
+ )) })
1483
+ ] }),
1484
+ /* @__PURE__ */ jsx21("ul", { className: "overflow-hidden mb-2 bg-zinc-950 rounded-lg", children: data.results.map((song, index) => /* @__PURE__ */ jsx21("li", { onClickCapture: (event) => handleRowClickCapture(event, song), children: /* @__PURE__ */ jsx21(
1485
+ TrackItem,
1486
+ {
1487
+ track: song,
1488
+ position: (page - 1) * data.pageSize + index + 1,
1489
+ renderArtistLink
1490
+ }
1491
+ ) }, song.uuid)) }),
1492
+ /* @__PURE__ */ jsx21(Pagination, { currentPage: page, totalPages: data.totalPages, onPageChange: setPage })
1493
+ ] }) });
1494
+ }
1495
+
1496
+ // src/genre-tree/artist/useArtistPanel.tsx
1497
+ import { Fragment as Fragment5, jsx as jsx22, jsxs as jsxs16 } from "react/jsx-runtime";
1498
+ function useArtistPanel({
1499
+ uuid,
1500
+ getBackendBaseUrl,
1501
+ renderArtistLink,
1502
+ expanded,
1503
+ onExpandedChange,
1504
+ onClose
1505
+ }) {
1506
+ const result = useArtist(uuid, getBackendBaseUrl);
1507
+ const panel = { expanded, onExpandedChange, onClose };
1508
+ switch (result.status) {
1509
+ case "idle":
1510
+ return void 0;
1511
+ case "loading":
1512
+ return {
1513
+ ...panel,
1514
+ title: "Artist",
1515
+ content: /* @__PURE__ */ jsxs16("div", { "aria-busy": "true", className: "flex flex-col gap-2.5 px-6 py-2.5", children: [
1516
+ /* @__PURE__ */ jsx22(Skeleton4, { className: "h-3 w-16" }),
1517
+ /* @__PURE__ */ jsx22(Skeleton4, { className: "h-4 w-32" }),
1518
+ /* @__PURE__ */ jsx22(Skeleton4, { className: "h-3 w-16" }),
1519
+ /* @__PURE__ */ jsx22(Skeleton4, { className: "h-4 w-24" }),
1520
+ /* @__PURE__ */ jsx22(Skeleton4, { className: "h-16 mt-2.5" }),
1521
+ /* @__PURE__ */ jsx22(Skeleton4, { className: "h-16" })
1522
+ ] })
1523
+ };
1524
+ case "not-found":
1525
+ return {
1526
+ ...panel,
1527
+ title: "Artist not found",
1528
+ content: /* @__PURE__ */ jsx22("p", { className: "px-6 py-2.5 text-[var(--color-text-muted)]", children: "This artist does not exist." })
1529
+ };
1530
+ case "error":
1531
+ return {
1532
+ ...panel,
1533
+ title: "Artist",
1534
+ content: /* @__PURE__ */ jsx22("p", { className: "px-6 py-2.5 text-red-600", children: "Could not load this artist." })
1535
+ };
1536
+ case "success": {
1537
+ const { artist } = result;
1538
+ return {
1539
+ ...panel,
1540
+ title: artist.name,
1541
+ content: /* @__PURE__ */ jsxs16(Fragment5, { children: [
1542
+ artist.image && /* @__PURE__ */ jsx22(ArtistPhoto, { image: artist.image, name: artist.name }),
1543
+ /* @__PURE__ */ jsx22(ArtistHeader, { artist }),
1544
+ /* @__PURE__ */ jsx22(ArtistMembers, { title: "Members", memberships: artist.members, renderArtistLink }),
1545
+ /* @__PURE__ */ jsx22(ArtistMembers, { title: "Member of", memberships: artist.memberOf, renderArtistLink }),
1546
+ artist.tracksCount > 0 && /* @__PURE__ */ jsx22(
1547
+ ArtistSongs,
1548
+ {
1549
+ artist: { uuid: artist.uuid, name: artist.name },
1550
+ getBackendBaseUrl,
1551
+ renderArtistLink
1552
+ }
1553
+ )
1554
+ ] }),
1555
+ extraContent: artist.albums.length > 0 ? /* @__PURE__ */ jsx22(ArtistDiscography, { albums: artist.albums }) : void 0
1556
+ };
1557
+ }
1558
+ }
1559
+ }
1560
+
1561
+ // src/genre-tree/SizeMetricToggle.tsx
1562
+ import { MdMusicNote, MdVisibility } from "react-icons/md";
1563
+ import { SegmentedControl } from "@behindthemusictree/ui";
1564
+ import { jsx as jsx23 } from "react/jsx-runtime";
1565
+ function SizeMetricToggle({
1566
+ value,
1567
+ onChange
1568
+ }) {
1569
+ return /* @__PURE__ */ jsx23(
1570
+ SegmentedControl,
1571
+ {
1572
+ "aria-label": "Size nodes by",
1573
+ value,
1574
+ onChange,
1575
+ options: [
1576
+ { value: "songs", label: /* @__PURE__ */ jsx23(MdMusicNote, { size: 18, "aria-hidden": true }), "aria-label": "Size by songs", title: "Node size by song count" },
1577
+ { value: "views", label: /* @__PURE__ */ jsx23(MdVisibility, { size: 18, "aria-hidden": true }), "aria-label": "Size by views", title: "Node size by song views" }
1578
+ ]
1579
+ }
1580
+ );
1581
+ }
1582
+
1583
+ // src/genre-tree/GenreTreeView.tsx
1584
+ import { Fragment as Fragment6, jsx as jsx24, jsxs as jsxs17 } from "react/jsx-runtime";
1585
+ var PREVIOUS_BUTTON_CSS = `
1586
+ .genre-tree-view .search-overlay .gtv-info-panel-previous { display: none; }
1587
+ .genre-tree-view:has(.search-overlay .gtv-info-panel-previous) .genre-search input { padding-left: 2.75rem; }
1588
+ .genre-tree-view:has(.search-overlay .gtv-info-panel-previous) .genre-search-previous { display: flex; }
1589
+ @keyframes genre-tree-view-previous-in { from { opacity: 0; transform: translate(-0.5rem, -50%); } to { opacity: 1; transform: translate(0, -50%); } }
1590
+ @media (prefers-reduced-motion: no-preference) {
1591
+ .genre-search-previous { animation: genre-tree-view-previous-in 200ms ease-out; }
1592
+ }
1593
+ `;
1594
+ function GenreNodeActionBand({ genrePlaylist, scope, playback, ...bandProps }) {
1595
+ const { isPlaying, setIsPlaying } = usePlayer8();
1596
+ const isCurrentTrackList = playback.playingNodeId === genrePlaylist.uuid;
1597
+ const handlePlayPause = () => {
1598
+ if (isCurrentTrackList) {
1599
+ setIsPlaying(!isPlaying);
1600
+ return;
1601
+ }
1602
+ playback.play(genrePlaylist).catch((error) => {
1603
+ console.error("Failed to load genre playlist tracks:", error);
1604
+ });
1605
+ };
1606
+ return /* @__PURE__ */ jsx24(
1607
+ GenreActionBand,
1608
+ {
1609
+ ...bandProps,
1610
+ onPlayPause: genrePlaylist.tracksCount > 0 ? handlePlayPause : void 0,
1611
+ isPlaying: isCurrentTrackList && isPlaying
1612
+ }
1613
+ );
1614
+ }
1615
+ var NO_POP_ROOT_TITLE = "This genre tree has no 'Mainstream Pop' root yet";
1616
+ var REGIONS_CLASS = "[--gtv-center-left:var(--layout-center-left)] [--gtv-center-right:var(--layout-center-right)] [--gtv-center-top:var(--layout-band-top)] [&_.gtv-info-panel--overlay]:[--gtv-info-panel-header-inset:0px]";
1617
+ function GenreTreeView({
1618
+ scope,
1619
+ handleGenreCreationAction,
1620
+ handleGenreRenameAction,
1621
+ onParentChanged,
1622
+ getBackendBaseUrl,
1623
+ additionalActions,
1624
+ viewMode: controlledViewMode,
1625
+ selectedNodeId: controlledSelectedNodeId,
1626
+ onSelectedNodeIdChange,
1627
+ defaultViewport,
1628
+ onViewportChange,
1629
+ readOnly = false,
1630
+ className,
1631
+ showDisplayOptions = true,
1632
+ showAddRoot = true,
1633
+ allowWheelRotation: controlledAllowWheelRotation,
1634
+ criteriaOverviewSchema,
1635
+ renderGenreDetailExtras,
1636
+ controlsOrientation = "horizontal",
1637
+ sizeMetric: controlledSizeMetric,
1638
+ onSizeMetricChange,
1639
+ renderArtistLink,
1640
+ artistUuid: controlledArtistUuid,
1641
+ onArtistUuidChange,
1642
+ artistExpanded: controlledArtistExpanded,
1643
+ onArtistExpandedChange,
1644
+ artistSearch = true,
1645
+ onArtistSelect,
1646
+ artistSearchBaseUrl,
1647
+ renderSummary,
1648
+ renderEssentialTracks,
1649
+ renderSongLeading,
1650
+ renderSongActions,
1651
+ renderTracksToolbar,
1652
+ renderDangerZone,
1653
+ expanded,
1654
+ onExpandedChange,
1655
+ collapsed,
1656
+ onCollapsedChange,
1657
+ overlayPanel,
1658
+ placement = "default",
1659
+ ...focus
1660
+ }) {
1661
+ const [internalArtistUuid, setInternalArtistUuid] = useState4(null);
1662
+ const isArtistControlled = controlledArtistUuid !== void 0;
1663
+ const artistUuid = isArtistControlled ? controlledArtistUuid : internalArtistUuid;
1664
+ const [internalSizeMetric, setInternalSizeMetric] = useState4("songs");
1665
+ const sizeMetric = controlledSizeMetric ?? internalSizeMetric;
1666
+ const deferredSizeMetric = useDeferredValue(sizeMetric);
1667
+ const changeSizeMetric = (metric) => {
1668
+ if (controlledSizeMetric === void 0) setInternalSizeMetric(metric);
1669
+ onSizeMetricChange?.(metric);
1670
+ };
1671
+ const changeArtist = (uuid) => {
1672
+ if (!isArtistControlled) setInternalArtistUuid(uuid);
1673
+ onArtistUuidChange?.(uuid);
1674
+ };
1675
+ const {
1676
+ isLoading,
1677
+ isFetching: isTreeFetching,
1678
+ genrePlaylistByNodeId,
1679
+ visibleGenrePlaylists,
1680
+ groupedGenrePlaylistsByRoot,
1681
+ selectedNodeId,
1682
+ selectedGenrePlaylist,
1683
+ selectNode,
1684
+ selectGenrePlaylist,
1685
+ clearSelection,
1686
+ viewMode,
1687
+ isViewModeControlled: isControlled,
1688
+ setViewMode,
1689
+ canShowPopCore,
1690
+ allowWheelRotation: internalAllowWheelRotation,
1691
+ toggleWheelRotation,
1692
+ onNodeHover: handleNodeHover
1693
+ } = useGenreTreeViewState({
1694
+ scope,
1695
+ getBackendBaseUrl,
1696
+ viewMode: controlledViewMode,
1697
+ selectedNodeId: controlledSelectedNodeId,
1698
+ onSelectedNodeIdChange,
1699
+ criteriaOverviewSchema,
1700
+ artistUuid
1701
+ });
1702
+ const isGenreUpdating = useIsMutating({ mutationKey: genreUpdateMutationKey }) > 0;
1703
+ const busy = deferredSizeMetric !== sizeMetric || isTreeFetching || isGenreUpdating;
1704
+ const artistResult = useArtist2(artistUuid, artistSearchBaseUrl ?? getBackendBaseUrl);
1705
+ const filterArtistName = artistResult.status === "success" ? artistResult.artist.name : null;
1706
+ const filterArtist = useMemo6(
1707
+ () => artistUuid !== null && filterArtistName !== null ? { uuid: artistUuid, name: filterArtistName } : null,
1708
+ [artistUuid, filterArtistName]
1709
+ );
1710
+ const playback = useGenrePlaylistPlayback({ scope, genrePlaylists: visibleGenrePlaylists, artist: filterArtist });
1711
+ const openArtist = (uuid) => {
1712
+ if (selectedNodeId !== null) clearSelection();
1713
+ changeArtist(uuid);
1714
+ };
1715
+ const [expandedArtistUuid, setExpandedArtistUuid] = useState4(null);
1716
+ const artistBaseUrl = artistSearchBaseUrl ?? getBackendBaseUrl;
1717
+ const artistPanel = useArtistPanel({
1718
+ uuid: artistUuid,
1719
+ getBackendBaseUrl: artistBaseUrl,
1720
+ renderArtistLink: renderArtistLink ?? ((artist) => artist.isSpecialPurpose ? artist.name : /* @__PURE__ */ jsx24("button", { type: "button", onClick: () => openArtist(artist.uuid), className: "hover:underline", children: artist.name })),
1721
+ expanded: controlledArtistExpanded ?? (artistUuid !== null && expandedArtistUuid === artistUuid),
1722
+ onExpandedChange: (on) => {
1723
+ if (controlledArtistExpanded === void 0) setExpandedArtistUuid(on ? artistUuid : null);
1724
+ onArtistExpandedChange?.(on);
1725
+ },
1726
+ onClose: () => changeArtist(null)
1727
+ });
1728
+ const builtInArtistPanel = overlayPanel || selectedNodeId !== null ? void 0 : artistPanel;
1729
+ const activeOverlayPanel = overlayPanel ?? (builtInArtistPanel && { ...builtInArtistPanel, hideTitle: true, hideClose: true });
1730
+ const [uncontrolledCollapsed, setUncontrolledCollapsed] = useState4(false);
1731
+ const [uncontrolledExpanded, setUncontrolledExpanded] = useState4(false);
1732
+ const isCollapsed = collapsed ?? uncontrolledCollapsed;
1733
+ const isExpanded = expanded ?? uncontrolledExpanded;
1734
+ const changeCollapsed = (next) => {
1735
+ setUncontrolledCollapsed(next);
1736
+ onCollapsedChange?.(next);
1737
+ };
1738
+ const changeExpanded = (next) => {
1739
+ setUncontrolledExpanded(next);
1740
+ onExpandedChange?.(next);
1741
+ };
1742
+ useEffect4(() => {
1743
+ setUncontrolledCollapsed(false);
1744
+ }, [selectedNodeId, artistUuid]);
1745
+ const isDetailHidden = isCollapsed || !selectedNodeId && !activeOverlayPanel;
1746
+ useEffect4(() => {
1747
+ if (placement !== "regions" || !isDetailHidden) return void 0;
1748
+ const root = document.documentElement;
1749
+ root.style.setProperty("--layout-left-w", "0px");
1750
+ return () => {
1751
+ root.style.removeProperty("--layout-left-w");
1752
+ };
1753
+ }, [placement, isDetailHidden]);
1754
+ const detailOverlay = placement === "regions" && activeOverlayPanel?.onExpandedChange ? activeOverlayPanel : void 0;
1755
+ const detailExpanded = detailOverlay ? !!detailOverlay.expanded : isExpanded;
1756
+ const onDetailExpandedChange = detailOverlay ? detailOverlay.onExpandedChange : changeExpanded;
1757
+ const infoPanelCuration = {
1758
+ renderDangerZone,
1759
+ expanded: placement === "regions" ? isExpanded : expanded,
1760
+ onExpandedChange: placement === "regions" ? changeExpanded : onExpandedChange,
1761
+ collapsed: placement === "regions" ? isCollapsed : void 0,
1762
+ hideExpandButton: placement === "regions" ? true : void 0,
1763
+ overlayPanel: detailOverlay ? { ...detailOverlay, collapsed: isCollapsed, hideExpandButton: true } : activeOverlayPanel
1764
+ };
1765
+ const [isWheelRevealed, setIsWheelRevealed] = useState4(false);
1766
+ const usesHandoff = viewMode === "wheel" || viewMode === "pop-core";
1767
+ const isTreeReady = !isLoading && (!usesHandoff || isWheelRevealed);
1768
+ const rootRef = useRef4(null);
1769
+ const handlePrevious = () => {
1770
+ rootRef.current?.querySelector(".search-overlay .gtv-info-panel-previous")?.click();
1771
+ };
1772
+ const { showPopup, hidePopup } = usePopup4();
1773
+ const [searchText, setSearchText] = useState4("");
1774
+ const artistSearchResult = useArtistSearch(artistBaseUrl, artistSearch ? searchText : "");
1775
+ const artistExtraResults = artistSearch ? {
1776
+ label: "Artists",
1777
+ items: artistSearchResult.artists.map((artist) => ({
1778
+ key: artist.uuid,
1779
+ content: /* @__PURE__ */ jsxs17(Fragment6, { children: [
1780
+ /* @__PURE__ */ jsxs17("span", { className: "block truncate font-medium", children: [
1781
+ artist.name,
1782
+ artist.disambiguation && /* @__PURE__ */ jsxs17("span", { className: "font-normal text-[var(--color-neutral-500)]", children: [
1783
+ " \xB7 ",
1784
+ artist.disambiguation
1785
+ ] })
1786
+ ] }),
1787
+ artist.matchedAlias && /* @__PURE__ */ jsxs17("span", { className: "block truncate text-xs text-[var(--color-neutral-500)]", children: [
1788
+ "also known as ",
1789
+ artist.matchedAlias
1790
+ ] })
1791
+ ] }),
1792
+ onSelect: () => {
1793
+ openArtist(artist.uuid);
1794
+ onArtistSelect?.(artist);
1795
+ }
1796
+ })),
1797
+ status: artistSearchResult.isError ? "Search failed" : artistSearchResult.settled && artistSearchResult.artists.length === 0 ? "No artists found" : "",
1798
+ loading: artistSearchResult.pending
1799
+ } : void 0;
1800
+ const handleSelectedNodeChange = (node) => {
1801
+ selectNode(node);
1802
+ };
1803
+ const handleGenreSearchClear = clearSelection;
1804
+ const handleGenreSearchSelect = (genrePlaylist) => {
1805
+ selectGenrePlaylist(genrePlaylist);
1806
+ };
1807
+ const selectedUuid = selectedGenrePlaylist?.uuid;
1808
+ const selectedChildren = selectedUuid ? visibleGenrePlaylists.filter((genrePlaylist) => genrePlaylist.parent?.uuid === selectedUuid) : [];
1809
+ const canZoomIn = viewMode === "pop-core" && focus.onFocusGenreChange !== void 0 && selectedUuid !== void 0 && focus.focusGenreUuid !== selectedUuid && selectedChildren.length > 0 && selectedChildren.filter((child) => child.criteria?.side === "pop").length <= 1;
1810
+ const handleGenreSearchZoomIn = () => {
1811
+ if (selectedUuid) focus.onFocusGenreChange?.(selectedUuid, "zoom-in");
1812
+ };
1813
+ const zoomInRef = useRef4(void 0);
1814
+ zoomInRef.current = canZoomIn ? handleGenreSearchZoomIn : void 0;
1815
+ const renderInfoPanelBody = useCallback5(
1816
+ (node, { toolbar, ancestors, family }) => {
1817
+ const genrePlaylist = genrePlaylistByNodeId.get(node.id);
1818
+ const criteria = genrePlaylist?.criteria;
1819
+ if (!genrePlaylist || !criteria) return { primary: /* @__PURE__ */ jsxs17(Fragment6, { children: [
1820
+ toolbar,
1821
+ family
1822
+ ] }), aside: ancestors };
1823
+ const genreUuid = criteria.uuid;
1824
+ return {
1825
+ primary: /* @__PURE__ */ jsxs17(Fragment6, { children: [
1826
+ toolbar,
1827
+ /* @__PURE__ */ jsx24(
1828
+ GenreNodeActionBand,
1829
+ {
1830
+ node,
1831
+ genrePlaylist,
1832
+ scope,
1833
+ onZoomIn: zoomInRef.current,
1834
+ onAddChild: readOnly ? void 0 : () => handleGenreCreationAction(criteria),
1835
+ onRename: readOnly ? void 0 : () => handleGenreRenameAction(criteria),
1836
+ onChangeParent: readOnly ? void 0 : () => showPopup(
1837
+ /* @__PURE__ */ jsx24(
1838
+ ChangeParentPopup,
1839
+ {
1840
+ genrePlaylist: { ...genrePlaylist, criteria },
1841
+ genrePlaylists: visibleGenrePlaylists,
1842
+ scope,
1843
+ getBackendBaseUrl,
1844
+ onClose: hidePopup,
1845
+ onParentChanged
1846
+ }
1847
+ )
1848
+ ),
1849
+ additionalActions,
1850
+ playback
1851
+ }
1852
+ ),
1853
+ /* @__PURE__ */ jsx24(
1854
+ GenreDetailExtras,
1855
+ {
1856
+ family,
1857
+ genreUuid,
1858
+ genrePlaylist,
1859
+ scope,
1860
+ getBackendBaseUrl,
1861
+ criteriaOverviewSchema,
1862
+ renderGenreDetailExtras,
1863
+ renderArtistLink,
1864
+ artist: filterArtist,
1865
+ renderSummary,
1866
+ renderEssentialTracks,
1867
+ renderSongLeading,
1868
+ renderSongActions,
1869
+ renderTracksToolbar
1870
+ },
1871
+ genreUuid
1872
+ )
1873
+ ] }),
1874
+ aside: ancestors
1875
+ };
1876
+ },
1877
+ [
1878
+ genrePlaylistByNodeId,
1879
+ additionalActions,
1880
+ readOnly,
1881
+ handleGenreCreationAction,
1882
+ handleGenreRenameAction,
1883
+ showPopup,
1884
+ hidePopup,
1885
+ onParentChanged,
1886
+ visibleGenrePlaylists,
1887
+ playback,
1888
+ filterArtist,
1889
+ scope,
1890
+ getBackendBaseUrl,
1891
+ criteriaOverviewSchema,
1892
+ renderGenreDetailExtras,
1893
+ renderArtistLink,
1894
+ renderSummary,
1895
+ renderEssentialTracks,
1896
+ renderSongLeading,
1897
+ renderSongActions,
1898
+ renderTracksToolbar
1899
+ ]
1900
+ );
1901
+ const isRotationControlled = controlledAllowWheelRotation !== void 0;
1902
+ const allowWheelRotation = controlledAllowWheelRotation ?? internalAllowWheelRotation;
1903
+ const detailTab = placement === "regions" && (selectedNodeId || detailOverlay) ? /* @__PURE__ */ jsx24(
1904
+ PanelEdgeTab,
1905
+ {
1906
+ side: "left",
1907
+ edge: detailExpanded ? { label: "Shrink panel", onClick: () => onDetailExpandedChange?.(false) } : isCollapsed ? null : { label: "Hide panel", onClick: () => changeCollapsed(true) },
1908
+ center: detailExpanded ? null : isCollapsed ? { label: "Show panel", onClick: () => changeCollapsed(false) } : onDetailExpandedChange ? { label: "Extend panel", onClick: () => onDetailExpandedChange(true) } : null
1909
+ }
1910
+ ) : null;
1911
+ const actions = /* @__PURE__ */ jsxs17(Fragment6, { children: [
1912
+ !isLoading && /* @__PURE__ */ jsx24(
1913
+ GenreSearch,
1914
+ {
1915
+ genrePlaylists: visibleGenrePlaylists,
1916
+ onSelect: handleGenreSearchSelect,
1917
+ selectedName: selectedGenrePlaylist?.name ?? builtInArtistPanel?.title ?? null,
1918
+ onClear: builtInArtistPanel ? () => changeArtist(null) : handleGenreSearchClear,
1919
+ onPrevious: handlePrevious,
1920
+ onQueryChange: artistSearch ? setSearchText : void 0,
1921
+ extraResults: artistExtraResults
1922
+ }
1923
+ ),
1924
+ !isLoading && filterArtist && /* @__PURE__ */ jsxs17("span", { className: "inline-flex items-center overflow-hidden rounded-full bg-[var(--color-neutral-100)] text-sm", children: [
1925
+ /* @__PURE__ */ jsx24(
1926
+ "button",
1927
+ {
1928
+ type: "button",
1929
+ className: "py-1 pl-3 pr-2 hover:underline",
1930
+ "aria-label": `Show artist ${filterArtist.name}`,
1931
+ onClick: () => {
1932
+ if (selectedNodeId !== null) clearSelection();
1933
+ },
1934
+ children: filterArtist.name
1935
+ }
1936
+ ),
1937
+ /* @__PURE__ */ jsx24(
1938
+ "button",
1939
+ {
1940
+ type: "button",
1941
+ className: "py-1 pl-1 pr-3 hover:text-[var(--color-text)]",
1942
+ "aria-label": `Clear artist filter ${filterArtist.name}`,
1943
+ onClick: () => changeArtist(null),
1944
+ children: "\xD7"
1945
+ }
1946
+ )
1947
+ ] }),
1948
+ !isLoading && !isControlled && /* @__PURE__ */ jsx24(
1949
+ SegmentedControl2,
1950
+ {
1951
+ "aria-label": "Tree view mode",
1952
+ value: viewMode,
1953
+ onChange: setViewMode,
1954
+ options: [
1955
+ { value: "pop-core", label: "Pop/Core", disabled: !canShowPopCore, title: canShowPopCore ? void 0 : NO_POP_ROOT_TITLE },
1956
+ { value: "wheel", label: "Wheel" },
1957
+ { value: "stacked", label: "Stacked" },
1958
+ { value: "outline", label: "Outline", disabled: !canShowPopCore, title: canShowPopCore ? void 0 : NO_POP_ROOT_TITLE }
1959
+ ]
1960
+ }
1961
+ ),
1962
+ !isLoading && showDisplayOptions && /* @__PURE__ */ jsx24(
1963
+ "div",
1964
+ {
1965
+ className: "flex items-center gap-1",
1966
+ role: "group",
1967
+ "aria-label": "Tree display options",
1968
+ children: !isRotationControlled && viewMode !== "stacked" && viewMode !== "outline" && /* @__PURE__ */ jsx24(
1969
+ Button,
1970
+ {
1971
+ variant: allowWheelRotation ? "default" : "outline",
1972
+ size: "sm",
1973
+ onClick: toggleWheelRotation,
1974
+ children: "Rotation"
1975
+ }
1976
+ )
1977
+ }
1978
+ ),
1979
+ !isLoading && !readOnly && showAddRoot && /* @__PURE__ */ jsx24(
1980
+ IconTextButton,
1981
+ {
1982
+ icon: Plus2,
1983
+ text: "Add root",
1984
+ onClick: () => handleGenreCreationAction(null)
1985
+ }
1986
+ )
1987
+ ] });
1988
+ return /* @__PURE__ */ jsxs17(
1989
+ "div",
1990
+ {
1991
+ ref: rootRef,
1992
+ className: ["genre-tree-view relative flex flex-col h-full", placement === "regions" && REGIONS_CLASS, className].filter(Boolean).join(" "),
1993
+ children: [
1994
+ /* @__PURE__ */ jsx24("style", { children: PREVIOUS_BUTTON_CSS }),
1995
+ /* @__PURE__ */ jsx24(
1996
+ "div",
1997
+ {
1998
+ className: `actions-container absolute z-30 flex items-center gap-2 ${placement === "regions" ? "left-[calc(var(--layout-gutter)+var(--layout-panel-inset))] top-[calc(var(--layout-gutter)+var(--layout-panel-inset))]" : "left-5 top-5"}`,
1999
+ children: actions
2000
+ }
2001
+ ),
2002
+ detailTab && /* @__PURE__ */ jsx24(
2003
+ "div",
2004
+ {
2005
+ className: `absolute top-1/2 z-30 -translate-y-1/2 transition-[opacity,visibility] duration-150 ease-out ${isTreeReady ? "opacity-100" : "pointer-events-none invisible opacity-0"} ${detailExpanded ? "right-[calc(var(--layout-center-right)-var(--layout-edge-tab-w))]" : isCollapsed ? "left-0" : "left-[calc(var(--layout-gutter)+var(--layout-left-w))]"}`,
2006
+ children: detailTab
2007
+ }
2008
+ ),
2009
+ /* @__PURE__ */ jsx24("div", { className: "content-container flex-1 min-h-0 flex flex-row gap-4", children: /* @__PURE__ */ jsx24("div", { className: "tree-view-container flex-1 min-w-0 flex flex-col h-full", children: isLoading ? /* @__PURE__ */ jsx24(GenreTreeViewSkeleton, { viewMode }) : viewMode === "wheel" ? (
2010
+ // The info panel's top edge aligns with the tree's; the search bar floats `--layout-panel-inset` below it,
2011
+ // and the header inset (the bar's height plus that inset) extends the header's fill behind the bar,
2012
+ // Google Maps style; the 8px bottom padding mirrors the inset above the bar, and the hidden title's height is zeroed.
2013
+ // The panel's own Zoom in button is hidden: the search bar carries it.
2014
+ /* @__PURE__ */ jsx24("div", { className: "tree-container search-overlay relative flex-1 w-full min-h-0 [--gtv-info-panel-header-inset:calc(var(--layout-search-h,2.5rem)+var(--layout-panel-inset,0.5rem))] [&_.gtv-info-panel-header]:pb-2 [&_.gtv-info-panel-title--hidden]:h-0 [&_.gtv-toolbar]:hidden", children: /* @__PURE__ */ jsx24(GenreTreeWheelHandoff, { skeleton: /* @__PURE__ */ jsx24(GenreTreeWheelSkeleton, {}), onRevealedChange: setIsWheelRevealed, children: /* @__PURE__ */ jsx24(
2015
+ GenrePlaylistTreeWheel,
2016
+ {
2017
+ scope,
2018
+ genrePlaylists: visibleGenrePlaylists,
2019
+ handleGenreCreationAction,
2020
+ handleGenreRenameAction,
2021
+ additionalActions,
2022
+ onSelectedNodeChange: handleSelectedNodeChange,
2023
+ hideInfoPanelClose: true,
2024
+ hideInfoPanelTitle: true,
2025
+ onNodeHover: handleNodeHover,
2026
+ renderInfoPanelBody,
2027
+ playback,
2028
+ selectedNodeId,
2029
+ readOnly,
2030
+ allowWheelRotation,
2031
+ controlsOrientation,
2032
+ sizeMetric: filterArtist ? "songs" : deferredSizeMetric,
2033
+ busy,
2034
+ floatingControlsLeading: filterArtist ? void 0 : /* @__PURE__ */ jsx24(SizeMetricToggle, { value: sizeMetric, onChange: changeSizeMetric }),
2035
+ defaultViewport,
2036
+ onViewportChange,
2037
+ ...infoPanelCuration
2038
+ }
2039
+ ) }) })
2040
+ ) : viewMode === "pop-core" ? (
2041
+ // Same as the wheel: the header inset extends its fill behind the floating search bar, Google Maps style.
2042
+ /* @__PURE__ */ jsx24("div", { className: "tree-container search-overlay relative flex-1 w-full min-h-0 [--gtv-info-panel-header-inset:calc(var(--layout-search-h,2.5rem)+var(--layout-panel-inset,0.5rem))] [&_.gtv-info-panel-header]:pb-2 [&_.gtv-info-panel-title--hidden]:h-0 [&_.gtv-toolbar]:hidden [&_.gtv-info-panel-zoom-in]:hidden", children: /* @__PURE__ */ jsx24(GenreTreeWheelHandoff, { skeleton: /* @__PURE__ */ jsx24(GenreTreeWheelSkeleton, {}), onRevealedChange: setIsWheelRevealed, children: /* @__PURE__ */ jsx24(
2043
+ GenrePlaylistTreeWheelRadialPopCore,
2044
+ {
2045
+ scope,
2046
+ genrePlaylists: visibleGenrePlaylists,
2047
+ handleGenreCreationAction,
2048
+ handleGenreRenameAction,
2049
+ additionalActions,
2050
+ onSelectedNodeChange: handleSelectedNodeChange,
2051
+ hideInfoPanelClose: true,
2052
+ hideInfoPanelTitle: true,
2053
+ onNodeHover: handleNodeHover,
2054
+ renderInfoPanelBody,
2055
+ playback,
2056
+ selectedNodeId,
2057
+ readOnly,
2058
+ allowWheelRotation,
2059
+ controlsOrientation,
2060
+ sizeMetric: filterArtist ? "songs" : deferredSizeMetric,
2061
+ busy,
2062
+ floatingControlsLeading: filterArtist ? void 0 : /* @__PURE__ */ jsx24(SizeMetricToggle, { value: sizeMetric, onChange: changeSizeMetric }),
2063
+ defaultViewport,
2064
+ onViewportChange,
2065
+ ...infoPanelCuration,
2066
+ ...focus
2067
+ }
2068
+ ) }) })
2069
+ ) : viewMode === "outline" ? /* @__PURE__ */ jsx24("div", { className: "tree-container flex-1 min-h-0 w-full overflow-y-auto relative [--gtv-info-panel-header-inset:calc(var(--layout-search-h,2.5rem)+var(--layout-panel-inset,0.5rem)+0.75rem)] [&_.gtv-toolbar]:hidden", children: /* @__PURE__ */ jsx24(
2070
+ GenrePlaylistTreeWheelRadialPopCore,
2071
+ {
2072
+ outline: true,
2073
+ scope,
2074
+ genrePlaylists: visibleGenrePlaylists,
2075
+ handleGenreCreationAction,
2076
+ handleGenreRenameAction,
2077
+ additionalActions,
2078
+ onSelectedNodeChange: handleSelectedNodeChange,
2079
+ hideInfoPanelClose: true,
2080
+ hideInfoPanelTitle: true,
2081
+ onNodeHover: handleNodeHover,
2082
+ renderInfoPanelBody,
2083
+ playback,
2084
+ selectedNodeId,
2085
+ readOnly,
2086
+ ...infoPanelCuration
2087
+ }
2088
+ ) }) : /* @__PURE__ */ jsx24("div", { className: "tree-container relative flex flex-col gap-4 w-full pt-14 overflow-x-auto overflow-y-auto text-[var(--color-text)] [&_.gtv-toolbar]:hidden", children: Object.entries(groupedGenrePlaylistsByRoot).map(
2089
+ ([uuid, genrePlaylistTreePerRoot], rootIndex) => {
2090
+ return /* @__PURE__ */ jsx24(
2091
+ "div",
2092
+ {
2093
+ className: "tree-per-root-container relative shrink-0 h-[28rem] mt-2 mr-16 p-2 bg-[var(--color-neutral-100)] rounded-lg",
2094
+ children: /* @__PURE__ */ jsx24("div", { className: "graph-container relative z-10 h-full", children: /* @__PURE__ */ jsx24(
2095
+ GenrePlaylistTreePerRoot,
2096
+ {
2097
+ scope,
2098
+ rootUuid: uuid,
2099
+ genrePlaylistTreePerRoot,
2100
+ handleGenreCreationAction,
2101
+ handleGenreRenameAction,
2102
+ additionalActions,
2103
+ onSelectedNodeChange: handleSelectedNodeChange,
2104
+ hideInfoPanelClose: true,
2105
+ hideInfoPanelTitle: true,
2106
+ onNodeHover: handleNodeHover,
2107
+ renderInfoPanelBody,
2108
+ playback,
2109
+ selectedNodeId: uuid === selectedGenrePlaylist?.root.uuid ? selectedNodeId : null,
2110
+ readOnly,
2111
+ wheelZoom: "modifier",
2112
+ controlsOrientation,
2113
+ defaultViewport: uuid === selectedGenrePlaylist?.root.uuid ? defaultViewport : void 0,
2114
+ onViewportChange: uuid === selectedGenrePlaylist?.root.uuid ? onViewportChange : void 0,
2115
+ ...infoPanelCuration,
2116
+ overlayPanel: rootIndex === 0 ? activeOverlayPanel : void 0
2117
+ }
2118
+ ) })
2119
+ },
2120
+ uuid
2121
+ );
2122
+ }
2123
+ ) }) }) })
2124
+ ]
2125
+ }
2126
+ );
2127
+ }
2128
+
2129
+ // src/genre-tree/index.ts
2130
+ import {
2131
+ GenreTreeSkeleton,
2132
+ GenreTreeWheelSkeleton as GenreTreeWheelSkeleton2,
2133
+ GenreTreeViewSkeleton as GenreTreeViewSkeleton2,
2134
+ GenreTreeOutlineSkeleton
2135
+ } from "@behindthemusictree/genre-tree-view";
2136
+
2137
+ // src/genre-tree/track-list-sidebar/TrackListSidebar.tsx
2138
+ import { useEffect as useEffect5, useRef as useRef5 } from "react";
2139
+ import { useTrackList as useTrackList5 } from "@behindthemusictree/app-kit/genre-tree";
2140
+ import { useTrackListSidebarVisibility } from "@behindthemusictree/app-kit/genre-tree";
2141
+ import { TrackListOriginType as TrackListOriginType2 } from "@behindthemusictree/app-kit/genre-tree";
2142
+ import { useTrackNoun as useTrackNoun6 } from "@behindthemusictree/app-kit/track-noun";
2143
+ import { jsx as jsx25, jsxs as jsxs18 } from "react/jsx-runtime";
2144
+ function TrackListSidebar({
2145
+ className = "",
2146
+ renderDuration,
2147
+ renderActions,
2148
+ layout = "fixed",
2149
+ renderArtistLink
2150
+ }) {
2151
+ const { trackList, loadMore } = useTrackList5();
2152
+ const trackNoun = useTrackNoun6();
2153
+ const loadMoreSentinelRef = useRef5(null);
2154
+ const hasMore = !!trackList && trackList.nextPage !== null;
2155
+ useEffect5(() => {
2156
+ const sentinel = loadMoreSentinelRef.current;
2157
+ if (!hasMore || !sentinel) return;
2158
+ const observer = new IntersectionObserver((entries) => {
2159
+ if (entries.some((entry) => entry.isIntersecting)) {
2160
+ loadMore().catch((error) => console.error("Failed to load more tracks:", error));
2161
+ }
2162
+ });
2163
+ observer.observe(sentinel);
2164
+ return () => observer.disconnect();
2165
+ }, [hasMore, loadMore]);
2166
+ const { hideTrackListSidebar } = useTrackListSidebarVisibility();
2167
+ const positionClasses = layout === "inline" ? "relative w-full flex h-full flex-col" : "fixed right-0 w-[50rem]";
2168
+ return trackList ? /* @__PURE__ */ jsxs18(
2169
+ "div",
2170
+ {
2171
+ "data-theme": "dark",
2172
+ className: `track-list-sidebar ${positionClasses} rounded-2xl bg-[var(--color-surface)] pb-1 ${className}`,
2173
+ style: layout === "fixed" ? {
2174
+ bottom: "79px"
2175
+ /* Match player height exactly */
2176
+ } : void 0,
2177
+ children: [
2178
+ /* @__PURE__ */ jsxs18("div", { className: "header flex h-16 px-4 py-2 text-[var(--color-text)]", children: [
2179
+ /* @__PURE__ */ jsxs18("div", { className: "origin flex text-xl ", children: [
2180
+ /* @__PURE__ */ jsx25("div", { className: "from h-auto flex flex-col justify-center items-center mr-2", children: "From" }),
2181
+ /* @__PURE__ */ jsx25("div", { className: "name-container flex flex-col justify-center items-center text-[var(--color-text)] font-bold pr-2 max-w-[27.5rem]", children: /* @__PURE__ */ jsx25("div", { className: "name max-w-full truncate", children: trackList.origin.label }) })
2182
+ ] }),
2183
+ /* @__PURE__ */ jsxs18("div", { className: "info flex flex-col justify-center items-center pt-1 mr-2 text-[var(--color-text-muted)]", children: [
2184
+ trackList.origin.type === TrackListOriginType2.GENRE_PLAYLIST ? "\u2022 Genre playlist \u2022 " : trackList.origin.type === TrackListOriginType2.ARTIST ? "\u2022 Artist \u2022 " : `\u2022 ${trackNoun.singular} playlist \u2022 `,
2185
+ `${trackList.total} ${trackList.total > 1 ? trackNoun.plural : trackNoun.singular} \u2022`
2186
+ ] }),
2187
+ /* @__PURE__ */ jsx25(
2188
+ "button",
2189
+ {
2190
+ type: "button",
2191
+ "aria-label": "Close track list",
2192
+ className: "flex-grow flex flex-col items-end justify-center h-full p-3 cursor-pointer text-inherit",
2193
+ onClick: hideTrackListSidebar,
2194
+ children: "\u2715"
2195
+ }
2196
+ )
2197
+ ] }),
2198
+ /* @__PURE__ */ jsxs18(
2199
+ "ul",
2200
+ {
2201
+ className: layout === "inline" ? "track-list flex-1 min-h-0 overflow-auto list-none p-0 m-0" : "track-list overflow-auto max-h-[calc(100vh-63.5px-79px-56px-3.5px)] list-none p-0 m-0",
2202
+ children: [
2203
+ trackList.tracks.map((track, index) => /* @__PURE__ */ jsx25("li", { children: /* @__PURE__ */ jsx25(
2204
+ TrackItem,
2205
+ {
2206
+ track,
2207
+ position: index + 1,
2208
+ renderDuration,
2209
+ renderActions,
2210
+ renderArtistLink
2211
+ }
2212
+ ) }, track.uuid)),
2213
+ hasMore && /* @__PURE__ */ jsx25("li", { ref: loadMoreSentinelRef, "aria-hidden": "true", className: "h-px" })
2214
+ ]
2215
+ }
2216
+ )
2217
+ ]
2218
+ }
2219
+ ) : null;
2220
+ }
2221
+
2222
+ // src/genre-tree/PlayerPanel.tsx
2223
+ import { useState as useState5 } from "react";
2224
+ import { X as X2 } from "lucide-react";
2225
+ import { twMerge as twMerge2 } from "tailwind-merge";
2226
+ import {
2227
+ usePlayer as usePlayer9,
2228
+ PlayerVideoSurface
2229
+ } from "@behindthemusictree/app-kit/player";
2230
+ import {
2231
+ useTrackListSidebarVisibility as useTrackListSidebarVisibility2
2232
+ } from "@behindthemusictree/app-kit/genre-tree";
2233
+ import { jsx as jsx26, jsxs as jsxs19 } from "react/jsx-runtime";
2234
+ var PANEL_ID = "player-panel";
2235
+ var iconButtonClassName = "flex h-6 w-6 shrink-0 items-center justify-center p-0 rounded-md hover:bg-white/10";
2236
+ var DEFAULT_EXTENDED_WIDTH = "calc(100vw - var(--layout-center-left) - var(--layout-gutter))";
2237
+ function PlayerPanel({
2238
+ className,
2239
+ isVisible = true,
2240
+ onClose,
2241
+ expanded,
2242
+ onExpandedChange,
2243
+ extendedWidth = DEFAULT_EXTENDED_WIDTH,
2244
+ renderArtistLink
2245
+ }) {
2246
+ const { playerTrackObject } = usePlayer9();
2247
+ const { toggleTrackListSidebar, isTrackListSidebarVisible } = useTrackListSidebarVisibility2();
2248
+ const [uncontrolledExtended, setUncontrolledExtended] = useState5(false);
2249
+ const isExtendRequested = expanded ?? uncontrolledExtended;
2250
+ const setIsExtendRequested = (next) => {
2251
+ setUncontrolledExtended(next);
2252
+ onExpandedChange?.(next);
2253
+ };
2254
+ const isExtended = isExtendRequested && isTrackListSidebarVisible;
2255
+ const tabEdge = !isTrackListSidebarVisible ? null : isExtended ? {
2256
+ label: "Shrink song list panel",
2257
+ onClick: () => setIsExtendRequested(false)
2258
+ } : { label: "Hide song list", onClick: toggleTrackListSidebar };
2259
+ const tabCenter = !isTrackListSidebarVisible ? { label: "Show song list", onClick: toggleTrackListSidebar } : isExtended ? null : {
2260
+ label: "Extend song list panel",
2261
+ onClick: () => setIsExtendRequested(true)
2262
+ };
2263
+ return /* @__PURE__ */ jsxs19(
2264
+ "div",
2265
+ {
2266
+ id: PANEL_ID,
2267
+ className: twMerge2(
2268
+ "fixed right-[var(--layout-gutter)] top-[var(--layout-band-top)] z-40 max-h-[calc(100vh-var(--layout-band-top)-3.5rem)]",
2269
+ !isExtended && "w-[var(--layout-right-w)]",
2270
+ isTrackListSidebarVisible && "h-[calc(100vh-var(--layout-band-top)-3.5rem)]",
2271
+ !isVisible && "hidden",
2272
+ className
2273
+ ),
2274
+ style: isExtended ? { width: extendedWidth } : void 0,
2275
+ children: [
2276
+ /* @__PURE__ */ jsx26(
2277
+ PanelEdgeTab,
2278
+ {
2279
+ side: "right",
2280
+ edge: tabEdge,
2281
+ center: tabCenter,
2282
+ controls: PANEL_ID,
2283
+ className: "absolute right-full top-1/2 -translate-y-1/2"
2284
+ }
2285
+ ),
2286
+ /* @__PURE__ */ jsxs19(
2287
+ "div",
2288
+ {
2289
+ className: twMerge2(
2290
+ "flex h-full max-h-[inherit] overflow-hidden rounded-[var(--radius-panel,1rem)] bg-zinc-950 text-zinc-100 shadow-[0_1px_2px_rgba(0,0,0,0.5),0_2px_6px_2px_rgba(0,0,0,0.3)]",
2291
+ isExtended ? "flex-row" : "flex-col"
2292
+ ),
2293
+ children: [
2294
+ /* @__PURE__ */ jsxs19("div", { className: "flex w-[var(--layout-right-w)] shrink-0 flex-col", children: [
2295
+ /* @__PURE__ */ jsxs19("div", { className: "flex shrink-0 items-center justify-between gap-2 border-b border-zinc-800 p-2", children: [
2296
+ /* @__PURE__ */ jsx26("span", { className: "min-w-0 truncate text-sm font-semibold", children: playerTrackObject?.track?.title }),
2297
+ /* @__PURE__ */ jsx26("div", { className: "flex shrink-0 items-center gap-1", children: /* @__PURE__ */ jsx26(
2298
+ "button",
2299
+ {
2300
+ type: "button",
2301
+ onClick: onClose,
2302
+ className: iconButtonClassName,
2303
+ "aria-label": "Close player",
2304
+ children: /* @__PURE__ */ jsx26(X2, { size: 16 })
2305
+ }
2306
+ ) })
2307
+ ] }),
2308
+ /* @__PURE__ */ jsxs19("div", { className: "relative w-full shrink-0", children: [
2309
+ /* @__PURE__ */ jsx26(PlayerVideoSurface, { className: "aspect-video w-full bg-black" }),
2310
+ playerTrackObject?.loadError && /* @__PURE__ */ jsx26("span", { className: "absolute bottom-2 left-2 right-2 text-xs text-red-400", children: playerTrackObject.loadError })
2311
+ ] })
2312
+ ] }),
2313
+ isTrackListSidebarVisible && /* @__PURE__ */ jsx26(
2314
+ TrackListSidebar,
2315
+ {
2316
+ layout: "inline",
2317
+ className: twMerge2(
2318
+ "min-h-0 min-w-0 flex-1",
2319
+ isExtended && "border-l border-zinc-800"
2320
+ ),
2321
+ renderArtistLink
2322
+ }
2323
+ )
2324
+ ]
2325
+ }
2326
+ )
2327
+ ]
2328
+ }
2329
+ );
2330
+ }
2331
+
2332
+ // src/genre-tree/Rating.tsx
2333
+ import { v4 as uuidv4 } from "uuid";
2334
+ import { AiFillStar, AiOutlineStar } from "react-icons/ai";
2335
+ import { FORM_RATING_NULL_VALUE } from "@behindthemusictree/app-kit/genre-tree";
2336
+ import { jsx as jsx27, jsxs as jsxs20 } from "react/jsx-runtime";
2337
+ function Rating({ rating, handleChange }) {
2338
+ const instanceId = uuidv4();
2339
+ return /* @__PURE__ */ jsx27("div", { className: "flex items-center", children: [...Array(6)].map((_, i) => /* @__PURE__ */ jsxs20("div", { className: `relative ${i === 0 ? "mr-4" : "mr-1"}`, children: [
2340
+ /* @__PURE__ */ jsx27(
2341
+ "input",
2342
+ {
2343
+ id: `star-${instanceId}-${i}`,
2344
+ className: "w-6 h-6 opacity-0",
2345
+ type: "radio",
2346
+ name: "rating",
2347
+ value: i === 0 ? FORM_RATING_NULL_VALUE : i,
2348
+ checked: rating === (i === 0 ? null : i),
2349
+ onChange: handleChange
2350
+ }
2351
+ ),
2352
+ /* @__PURE__ */ jsx27("label", { htmlFor: `star-${instanceId}-${i}`, className: "cursor-pointer", children: i === 0 ? /* @__PURE__ */ jsxs20("div", { className: "flex", children: [
2353
+ /* @__PURE__ */ jsx27(
2354
+ AiOutlineStar,
2355
+ {
2356
+ className: `w-7 h-7 absolute top-0 left-0 ${rating === FORM_RATING_NULL_VALUE ? "text-[var(--color-accent-rating)]" : "text-[var(--color-text-muted)]"}`
2357
+ }
2358
+ ),
2359
+ /* @__PURE__ */ jsx27("span", { className: "flex-grow w-8" }),
2360
+ " "
2361
+ ] }) : /* @__PURE__ */ jsx27(
2362
+ AiFillStar,
2363
+ {
2364
+ className: `w-7 h-7 absolute top-0 left-0 ${(rating ?? -1) >= i ? "text-[var(--color-accent-rating)]" : "text-[var(--color-text-muted)]"}`
2365
+ }
2366
+ ) })
2367
+ ] }, i)) });
2368
+ }
2369
+
2370
+ export {
2371
+ GenrePlaylistTreePerRoot,
2372
+ GenreSearch,
2373
+ PanelEdgeTab,
2374
+ TrackPositionPlayPause,
2375
+ TrackItem,
2376
+ GenreTreeView,
2377
+ TrackListSidebar,
2378
+ PlayerPanel,
2379
+ Rating,
2380
+ GenreTreeSkeleton,
2381
+ GenreTreeWheelSkeleton2 as GenreTreeWheelSkeleton,
2382
+ GenreTreeViewSkeleton2 as GenreTreeViewSkeleton,
2383
+ GenreTreeOutlineSkeleton
2384
+ };
2385
+ //# sourceMappingURL=chunk-KPWV4LEJ.js.map