Adds playlist and favorite affordances to the player and lists

This commit is contained in:
BinaryAlley committed 2026-10-22 22:09:57 +03:00
1 parent 525ac1348d
commit 3e32068573
23 files changed
+411 -39

No files matched your search

+1 -1
View File
@@ -37,7 +37,7 @@ Lumina is growing, and this is what works right now:
- **Media libraries that scan themselves.** Point Lumina at a folder or a drive, tell it what kind of media lives there, and it gets to work discovering and indexing what it finds. Scans run in the background, report their progress as they go, and can be started, cancelled or resumed.
- **Written content.** Add a written content library and Lumina scans it, cataloguing the books and e-books it contains and dressing them up with metadata for browsing in the client. Open one and it renders in the browser through a reader plugin; the EPUB and PDF readers are bundled and can be enabled per library.
- **Music.** Add a music library and Lumina indexes the artists, albums and tracks it contains, reading metadata from the tags inside the audio files. If you want more, enable a metadata provider and Lumina fills in the gaps from online sources, and artwork can come from your folders or from remote sources. You can also build your own playlists, order them the way you want and play them in the browser.
- **Favorites.** Mark the artists, albums, tracks and books you love as favorites and come back to them from one page, filtered by kind. Favorites are private to your account.
- **Favorites.** Mark the artists, albums, tracks and books you love as favorites, from their lists or from the player, and come back to them from one page, filtered by kind. Favorites are private to your account.
- **Metadata and artwork from plugins.** Plugins do the knowing. They supply the metadata and the artwork of a library, and you decide, library by library, which ones are switched on and which one wins when several of them recognize the same item.
- **A file system browser.** Reach the drives, folders and files of the server machine from anywhere you can open the client, as if you were sitting right in front of it. Poke around, walk a path to its root or to its parent, and let Lumina generate thumbnails for what it finds.
- **Accounts, roles, permissions and policies.** Create accounts, sign in with a password and optional two factor authentication, and hand out access through roles, fine grained permissions and policies that decide who may reach which library or content. Administrators manage all of it from the administration area.
+4 -4
View File
@@ -69,11 +69,11 @@ Opening a music library shows a page with the library title, a search box, a sor
- **The alpha picker** jumps to names starting with a chosen character. It offers All, then the number and symbol keys, then A to Z. You can also press a letter key to filter, and press Escape to clear the filter.
- **Pagination** splits the list into pages when you have it enabled, with previous and next buttons and a page indicator. When it is off, the whole list is shown and the count is the total.
Each artist is a card; selecting it opens the artist's page, and the card's actions menu offers **View details**, **Play**, **Shuffle** and **Delete**.
Each artist is a card; selecting it opens the artist's page, and the card's actions menu offers **View details**, **Play**, **Shuffle**, **Add to playlist** and **Delete**. The heart on the card marks the artist as a favorite.
The artist page is also where you edit the artist. It lists the artist's albums as cards, each leading to its own album page, followed by the artist's general information, contributors, ratings, genres, tags, aliases, areas and identifiers. The album page holds the album's information and its tracks, and the track page holds the track's details. The album page also shows the artwork Lumina stored for the album as a strip of thumbnails beside the main image, and selecting a thumbnail displays that image in place of the cover. Deleting an artist, album or track removes it from Lumina's catalogue; your files are not touched.
The music pages also play what they show. The artist page has a **Play all** control that plays the artist's releases in the order the page presents them, one release after another. The actions menu of a music library card on the home page, of an artist card, and of an album card offers **Play** and **Shuffle**. Play starts the library at its first artist and continues through the remaining artists in artist page order, starts the artist's discography in the order the artist page presents it, or starts the release in disc and track order. Shuffle starts the library, the artist's discography or the release with a list of up to 100 tracks sampled uniformly at random from every track of that scope, and continues in random order without repeating a track that is already queued. The album page has a **Play album** control that plays the release in disc and track order, and every track row has its own play control that plays just that track. The track page has a **Play track** control for the track it shows. Every track row on the album page also has an actions menu: **Add to playlist** opens the playlist picker for that track, **Add to play queue** appends it to the end of the player queue or starts it when the queue is empty, and **Play all from here** replaces the queue with that track and the rest of the album and starts playing. Starting playback opens the player bar at the bottom of the window. It keeps playing while you move between pages, and the bar shows the track name, with the album name underneath when the track belongs to a named album, the progress of the current track, a segmented VU meter that follows the level of the track, and the volume, together with previous, play or pause, stop, next and repeat controls. When you expand it, it also shows the cover art, the current track name, the release type, the release name and year, the artist name, and a carousel of the album's stored artwork, next to the queue, where every entry carries its album cover, including when only one track is queued. Selecting an artwork in the carousel shows it as the main cover. The expanded queue moves the current track to the top whenever playback advances, so it stays visible even in a long list. The double chevron at the right points up to expand the bar and down to collapse it. Stop is the square control next to play or pause; in the condensed bar it stops playback and slides the bar out of view.
The music pages also play what they show. The artist page has a **Play all** control that plays the artist's releases in the order the page presents them, one release after another. The actions menu of a music library card on the home page, of an artist card, and of an album card offers **Play** and **Shuffle**. Play starts the library at its first artist and continues through the remaining artists in artist page order, starts the artist's discography in the order the artist page presents it, or starts the release in disc and track order. Shuffle starts the library, the artist's discography or the release with a list of up to 100 tracks sampled uniformly at random from every track of that scope, and continues in random order without repeating a track that is already queued. The album page has a **Play album** control that plays the release in disc and track order, and every track row has its own play control that plays just that track. The track page has a **Play track** control for the track it shows. Every track row on the album page also has an actions menu: **Add to playlist** opens the playlist picker for that track, **Add to play queue** appends it to the end of the player queue or starts it when the queue is empty, and **Play all from here** replaces the queue with that track and the rest of the album and starts playing. Starting playback opens the player bar at the bottom of the window. It keeps playing while you move between pages, and the bar shows the track name, with the album name underneath when the track belongs to a named album, the progress of the current track, a segmented VU meter that follows the level of the track, and the volume, together with previous, play or pause, stop, next and repeat controls. When you expand it, it also shows the cover art, the current track name, the release type, the release name and year, the artist name, and a carousel of the album's stored artwork, next to the queue, where every entry carries its album cover, including when only one track is queued. Selecting an artwork in the carousel shows it as the main cover. The expanded queue moves the current track to the top whenever playback advances, so it stays visible even in a long list. The current track's favorite is the heart on the bar between the repeat and mute controls, and every entry of the expanded queue carries its own heart. The queue's own playlist picker appends the whole queue, in order, to one of your playlists. The double chevron at the right points up to expand the bar and down to collapse it. Stop is the square control next to play or pause; in the condensed bar it stops playback and slides the bar out of view.
## Playlists
@@ -84,7 +84,7 @@ From the playlists page you can open a playlist or select **Create** to open the
- **Add a track** by choosing a music library, then an artist, an album and a track, and selecting **Add**. A track can appear more than once in the same playlist.
- **Reorder the tracks** by dragging a row by its handle, or with the up and down controls on each row. The order is saved immediately.
- **Remove a track** from the playlist. The track itself, and the file behind it, are not touched.
- **Play a single track** with its play control, or **Play playlist** to hand the whole ordered list to the player in one go. While something is playing, the expanded player's **Add to playlist** button appends its current queue to one of your playlists.
- **Play a single track** with its play control, or **Play playlist** to hand the whole ordered list to the player in one go. Each row also has a heart that marks the track as a favorite and a plus control that adds it to another playlist. While something is playing, the expanded player's **Add to playlist** button appends its current queue to one of your playlists.
- **Add a whole library, artist or album** from the card menu of its page: choose **Add to playlist**, pick a playlist, and the tracks of that scope are appended in catalogue order. The same dialog lets you create a playlist when you have none yet.
- **Edit the name and description**, and **delete the playlist** when you no longer need it. Deleting a playlist never deletes any track.
@@ -94,7 +94,7 @@ The playlist reflects the catalogue at the moment you open it. If a track is del
A favorite is a mark you place on an artist, album, track or book so you can find it again quickly. Favorites belong to your account and are not shared with other users. Marking an item never changes the item or its files. Videos and photos are not available as favorites yet.
Select the heart on an item's card, or on its row on an album page, to add or remove the mark. A blue heart means the item is not a favorite; a red heart means it is.
Select the heart on an item's card, on its row on an album page or in a playlist, on the player bar for the current track, or on any queue entry of the player, to add or remove the mark. A blue heart means the item is not a favorite; a red heart means it is.
The **Favorites** page in the library section lists everything you marked, most recent first, with a count that follows the filter.
+20 -6
View File
@@ -311,6 +311,7 @@ The markup inside the bar exposes the hook attributes the audio player script bi
| `data-audio-player-now-playing-release` | The release name of the current track's album in the expanded player. It is left empty when the album has no displayable title. |
| `data-audio-player-now-playing-year` | The release year of the current track's album in the expanded player. It is left empty when the year is not known. |
| `data-audio-player-now-playing-artist` | The artist name of the current track's album in the expanded player. It is left empty until the album details are available. |
| `data-audio-player-favorite` | The favorite toggle of the current track, in the condensed bar between repeat and mute. The player sets its media kind and track Id, and hides it while no track is loaded. A missing hook gets the built-in toggle in that place. |
| `data-audio-player-artwork-carousel` | The carousel of the stored artwork of the current track's album. The player appends one `button.artwork-carousel-item` per stored image, carrying `data-artwork-path`, and toggles the `selected` class and `aria-pressed` on the chosen item. The element is hidden with the `hidden` attribute while the album has no stored artwork. |
| `data-audio-player-cover-thumbnail`, `data-audio-player-cover-image` | The cover art of the condensed bar and of the expanded bar. Choosing an album artwork in the carousel replaces both images until the next track. |
| `data-audio-player-vu-meter` | The root of the VU meter of the condensed bar, between the album art and the current time label. The player fills it with its channels, segments and peak markers, exactly as described in [The VU Meter](#the-vu-meter). A theme that does not render the hook gets the built-in meter inserted in that place. |
@@ -408,10 +409,10 @@ The sub templates are rendered client side by the audio player script with the s
| Template | Fields |
| --- | --- |
| `queue-item` | `entryId` (the identity of this occurrence in the queue), `index` (the one based position in the queue), `trackId`, `albumId`, `artistId`, `libraryId`, `title`, `duration` (the formatted `m:ss` duration), `durationSeconds`, `coverArtUrl` (the resolved cover art URL, which is the music placeholder when the entry has no artwork), `isCurrent`, `isPlayed`, `isLast`, `isContinuation` (the entry was added by the autoplay continuation) and `isShuffled` (the entry was added by a shuffle batch). The item root must keep the `audio-player-queue-item` class, the stylesheet hook of a queue item: the player appends the rendered element as-is, so the class is what lets the theme style it. The player writes `is-current`, `is-played`, `is-continuation` and `is-shuffled` on the root itself, so a theme item does not need to render those state classes, and it writes `data-audio-player-queue-entry-id`, so a theme item does not need to render the identity either. |
| `queue-item` | `entryId` (the identity of this occurrence in the queue), `index` (the one based position in the queue), `trackId`, `albumId`, `artistId`, `libraryId`, `title`, `duration` (the formatted `m:ss` duration), `durationSeconds`, `coverArtUrl` (the resolved cover art URL, which is the music placeholder when the entry has no artwork), `isCurrent`, `isPlayed`, `isLast`, `isContinuation` (the entry was added by the autoplay continuation) and `isShuffled` (the entry was added by a shuffle batch). The item root must keep the `audio-player-queue-item` class, the stylesheet hook of a queue item: the player appends the rendered element as-is, so the class is what lets the theme style it. The player writes `is-current`, `is-played`, `is-continuation` and `is-shuffled` on the root itself, so a theme item does not need to render those state classes, and it writes `data-audio-player-queue-entry-id`, so a theme item does not need to render the identity either. A theme item should render the favorite toggle with the `data-favorite-toggle`, `data-favorite-media-kind` and `data-favorite-media-item-id` attributes. The player appends the built-in toggle when it is missing. |
| `playlist-item` | `index`, `trackId`, `albumId`, `artistId`, `libraryId`, `title`, `duration`, `durationSeconds`, `coverArtUrl` and `isCurrent`. The item root must keep the `audio-player-playlist-item` class, the stylesheet hook of a playlist item. The shell inlines this sub template for theme authors, but the player does not render a saved playlist list with it yet; the saved playlist page renders its own rows from the page data described below. |
A theme can omit either sub template: the player then renders that part with its own built-in markup. When a theme replaces the shell, it must keep the two plain text script element ids above, the element hooks of the bar, and the `audio-player-container`, `not-shown` and `expanded` classes the player toggles.
A theme can omit any sub template: the player then renders that part with its own built-in markup. When a theme replaces the shell, it must keep the two plain text script element ids above, the element hooks of the bar, and the `audio-player-container`, `not-shown` and `expanded` classes the player toggles.
Every field of the `queue-item` and `playlist-item` models is untrusted: titles and identifiers come from file metadata and the music endpoints. Render these fields with the escaped form, `{{field}}`. The template engine also supports the unescaped form `{{{field}}}`, but these models contain no trusted HTML, so unescaped tags must not be used for them. Escaping does not neutralise whitespace in an unquoted attribute, so every model value placed in an attribute must sit inside quoted attribute marks, for example `data-track-id="{{trackId}}"` and never `data-track-id={{trackId}}`.
@@ -551,7 +552,7 @@ The fallback views keep these element hooks, which the application script drives
The playlist rows use the same play affordance contract as the music pages: an element with `data-audio-player-play` and the `data-track-id`, `data-library-id`, `data-album-id`, `data-artist-id`, `data-title`, `data-album-title`, `data-duration` and `data-cover-art-path` attributes is handed to the global player by event delegation. The page fills `data-track-id` from the entry `mediaItemId`, because a music entry references a track. The Play playlist control fetches every page of the playlist in order, builds an explicit queue from the playable entries and starts it through the player control API, so a theme template must keep the `play-playlist-button` hook for that control.
The playlist rows are reordered by dragging the handle with the `playlist-entry-drag-handle` class, and the row carries the `is-dragging` class while it is being dragged. The up and down controls remain available for keyboard and touch users, and the page uses the `playlist-entry-move-up`, `playlist-entry-move-down` and `playlist-entry-remove` classes to disable them while an entry mutation is in flight. A theme template that changes the row structure must keep the `playlist-entry` class and the `data-entry-id` attribute on the row, so the page script can find the row and commit its new position.
The playlist rows are reordered by dragging the handle with the `playlist-entry-drag-handle` class, and the row carries the `is-dragging` class while it is being dragged. The up and down controls remain available for keyboard and touch users, and the page uses the `playlist-entry-move-up`, `playlist-entry-move-down` and `playlist-entry-remove` classes to disable them while an entry mutation is in flight. A theme template that changes the row structure must keep the `playlist-entry` class and the `data-entry-id` attribute on the row, so the page script can find the row and commit its new position. A playable row also renders the heart of the global favorites script (`data-favorite-toggle`, with the kind `MusicTrack`) and the declarative add-to-playlist action (`data-playlist-add` with the track, library, album, artist and title attributes), so the row can be favorited and saved without leaving the playlist. A theme template that replaces the row must keep both controls to keep those actions reachable.
#### The Shared Add to Playlist Action
@@ -559,6 +560,19 @@ The music library card on the home page, the artist cards, the album cards and t
The dialog is rendered by the application, not by the theme: it is a standard application dialog surface with a standard `enlightenment-combobox` of the playlists of the current user. When the scope carries a `trackId`, the dialog appends that single track through the single entry route. Otherwise, the server resolves the ordered track Ids of the scope and appends them to the selected playlist in one batch request. In both cases it shows the result notification and dispatches the `lumina:playlist-updated` event so an open playlist page refreshes. A theme that renders the dialog itself does not get this behavior; it must keep the action wired to the shared helper or reimplement the whole flow.
A page or a theme template can also render a declarative action that needs no script of its own. The global playlist script binds one click listener on the document, so the action works anywhere in the swapped page content, inside the player bar, and on controls that a page renders later. The action is any focusable element, normally a `button`, that carries these attributes:
| Attribute | Meaning |
| --- | --- |
| `data-playlist-add` | Required. Marks the element as an add-to-playlist action. |
| `data-playlist-library-id` | Required. The Id of the media library the scope belongs to. An action without it is inert, because a scope is always resolved inside one library. |
| `data-playlist-track-id` | Optional. The Id of a single track. When present, the action appends that track through the single entry route and the album and artist attributes are only descriptive. |
| `data-playlist-album-id` | Optional. The Id of the album of a scope that is not a single track. |
| `data-playlist-artist-id` | Optional. The Id of the artist of a scope that is not a single track. |
| `data-playlist-title` | Optional. The title shown in the dialog, so the user sees what the action will add. |
The default action is prevented and the event stops propagating at the document listener, so link navigation is suppressed. An ancestor handler that already ran is not undone. A disabled action stays inert. Playlist rows and theme markup use these attributes; the player queue action uses its own combobox and button instead.
The layout provides the shared configuration as `window.playlistConfiguration`:
| Field | Content |
@@ -569,7 +583,7 @@ The layout provides the shared configuration as `window.playlistConfiguration`:
| `createPlaylistUrl` | The route of the dedicated create playlist page, linked from the empty state of the dialog. |
| `strings` | The localized dialog labels, including `selectPlaylist`, `noPlaylists`, `createPlaylist`, `tracksAdded`, `tracksAddFailed` and `noTracksToAdd`. |
The player queue action does not use `addToPlaylistLabel`. Its label comes from the `PlaylistAddToPlaylist` layout resource, exposed to the player as `strings.addToPlaylist` in the audio player configuration.
The player queue action does not use the declarative attributes. Its label comes from the `PlaylistAddToPlaylist` layout resource, exposed to the player as `strings.addToPlaylist` in the audio player configuration.
#### The Album Track Actions Menu
@@ -600,7 +614,7 @@ The fallback view renders one card per favorite, from the most recently favorite
#### Favorite Toggles
A favorite toggle is the heart of a media card or of a track row. It is rendered by a page or by a theme template, and it is driven entirely by the global script `wwwroot/js/favorites.js`, which every layout loads next to `playlists.js`. The script binds one click listener and one mutation observer on the document, so a toggle works anywhere in the swapped page content, including toggles that a page script adds later, and a page needs no script of its own. A theme owns the look of the toggle, and the script never renders markup: it only writes the attributes, the class and the texts described below.
A favorite toggle is the heart of a media card, of a track row, or of the condensed audio player bar. It is rendered by a page or by a theme template, and it is driven entirely by the global script `wwwroot/js/favorites.js`, which every layout loads next to `playlists.js`. The script binds one click listener and one mutation observer on the document, so a toggle works anywhere in the swapped page content, including toggles that a page script adds later, and a page needs no script of its own. A theme owns the look of the toggle, and the script never renders markup: it only writes the attributes, the class and the texts described below.
A toggle is any focusable element, normally a `button`, that carries these attributes:
@@ -645,7 +659,7 @@ The script also exposes `window.LuminaFavorites` for page scripts that need more
| `isFavorite(mediaKind, mediaItemId)` | Returns a promise of whether the item is a favorite. The answer always comes from the server, and the check is batched with the others of the same tick. It rejects when the kind or the Id is invalid, or when the request failed. |
| `setFavoriteAsync(mediaKind, mediaItemId, shouldFavorite)` | Adds or removes the favorite, with the same in-flight rule, synchronization and failure notification from the global API helper as a click, and returns a promise of whether the item now has the requested state. A call for an item that is already being changed returns the running change when it asks for the same state, and `false` otherwise. |
The hearts are rendered on the cards of the books list, of the artists list and of the albums on the artist page (the kinds `Book`, `MusicArtist` and `MusicAlbum`), on the cards of the favorites page, and on the rows of the track table of the album page (the kind `MusicTrack`, after the duration). The detail pages of an artist, an album, a track and a book render no toggle. The audio player bar and the playlist rows have none either, so a theme should not assume they exist.
The hearts are rendered on the cards of the books list, of the artists list and of the albums on the artist page (the kinds `Book`, `MusicArtist` and `MusicAlbum`), on the cards of the favorites page, on the rows of the track table of the album page (the kind `MusicTrack`, after the duration), on the rows of a saved playlist, on the favorite toggle of the condensed audio player bar for the current track, and on every queue item of the player (the kind `MusicTrack`). The detail pages of an artist, an album, a track and a book render no toggle. A theme that replaces a list must render the hearts again to keep favoriting reachable from it, and a theme queue item uses the same `data-favorite-toggle` contract.
A card heart is a plain `button` with the `card-favorite-toggle` class, with the three data attributes and nothing else, appended to the `media-card` element as a sibling of the `media-panel` link and of the `card-actions-trigger`. The stylesheet draws the heart with `::after`, like the dots of the actions trigger. The heart has the box of the actions trigger, sits immediately on its left, is shown on hover, while the actions menu of the card is open, and while any control of the card has the focus, shows the heart in the blue of the trigger, and shows it in red when the item is a favorite (`aria-pressed="true"` or the `is-favorite` class). A heart in the `loading` state is dimmed, and one in the `failed` state has an error border. A `media-card` that has no `card-actions-trigger`, like the cards of the favorites page, gets the heart in the place of the trigger, always visible so that it stays reachable by keyboard and on touch screens. A track row heart is a `button` with the `card-favorite-toggle track-favorite-toggle` classes inside a `td` with the `track-favorite-cell` class that follows the duration cell, and the `colgroup` of the table gets a `col` with the `track-favorite-column` class after the duration column. It is static, always visible and centered, like the actions trigger of the row. The hover text of every heart is the `title` that the script writes.
@@ -138,4 +138,7 @@
<data name="LoadMore" xml:space="preserve">
<value>تحميل المزيد</value>
</data>
<data name="AddToPlaylist" xml:space="preserve">
<value>إضافة إلى قائمة التشغيل</value>
</data>
</root>
@@ -138,4 +138,7 @@
<data name="LoadMore" xml:space="preserve">
<value>Mehr laden</value>
</data>
<data name="AddToPlaylist" xml:space="preserve">
<value>Zur Wiedergabeliste hinzufügen</value>
</data>
</root>
@@ -138,4 +138,7 @@
<data name="LoadMore" xml:space="preserve">
<value>Load more</value>
</data>
<data name="AddToPlaylist" xml:space="preserve">
<value>Add to playlist</value>
</data>
</root>
@@ -138,4 +138,7 @@
<data name="LoadMore" xml:space="preserve">
<value>Cargar más</value>
</data>
<data name="AddToPlaylist" xml:space="preserve">
<value>Añadir a la lista de reproducción</value>
</data>
</root>
@@ -138,4 +138,7 @@
<data name="LoadMore" xml:space="preserve">
<value>Charger plus</value>
</data>
<data name="AddToPlaylist" xml:space="preserve">
<value>Ajouter à la liste de lecture</value>
</data>
</root>
@@ -138,4 +138,7 @@
<data name="LoadMore" xml:space="preserve">
<value>Carica altro</value>
</data>
<data name="AddToPlaylist" xml:space="preserve">
<value>Aggiungi alla playlist</value>
</data>
</root>
@@ -138,4 +138,7 @@
<data name="LoadMore" xml:space="preserve">
<value>さらに読み込む</value>
</data>
<data name="AddToPlaylist" xml:space="preserve">
<value>プレイリストに追加</value>
</data>
</root>
@@ -138,4 +138,7 @@
<data name="LoadMore" xml:space="preserve">
<value>Load more</value>
</data>
<data name="AddToPlaylist" xml:space="preserve">
<value>Add to playlist</value>
</data>
</root>
@@ -138,4 +138,7 @@
<data name="LoadMore" xml:space="preserve">
<value>Încarcă mai multe</value>
</data>
<data name="AddToPlaylist" xml:space="preserve">
<value>Adaugă în listă de redare</value>
</data>
</root>
@@ -138,4 +138,7 @@
<data name="LoadMore" xml:space="preserve">
<value>Завантажити більше</value>
</data>
<data name="AddToPlaylist" xml:space="preserve">
<value>Додати до списку відтворення</value>
</data>
</root>
@@ -138,4 +138,7 @@
<data name="LoadMore" xml:space="preserve">
<value>加载更多</value>
</data>
<data name="AddToPlaylist" xml:space="preserve">
<value>添加到播放列表</value>
</data>
</root>
@@ -53,6 +53,7 @@
["album"] = _localizer["Album"].Value,
["track"] = _localizer["Track"].Value,
["add"] = _localizer["Add"].Value,
["addToPlaylist"] = _localizer["AddToPlaylist"].Value,
["addFailed"] = _localizer["AddFailed"].Value,
["refreshFailed"] = _localizer["RefreshFailed"].Value,
["selectLibrary"] = _localizer["SelectLibrary"].Value,
@@ -751,6 +752,33 @@
if (entry.coverPath)
playButton.dataset.coverArtPath = entry.coverPath;
row.appendChild(playButton);
// The favorite heart and the add-to-playlist action of the row work through the global favorites and playlist
// scripts, so the row binds no listener of its own and a themed row only has to render the same attributes.
const favoriteToggle = document.createElement('button');
favoriteToggle.type = 'button';
favoriteToggle.className = 'card-favorite-toggle playlist-entry-favorite';
favoriteToggle.setAttribute('data-favorite-toggle', '');
favoriteToggle.setAttribute('data-favorite-media-kind', 'MusicTrack');
favoriteToggle.setAttribute('data-favorite-media-item-id', entry.mediaItemId);
row.appendChild(favoriteToggle);
const addToPlaylistButton = document.createElement('button');
addToPlaylistButton.type = 'button';
addToPlaylistButton.className = 'confirm-button playlist-entry-add-to-playlist';
addToPlaylistButton.textContent = '+';
// An empty localized string must not replace the accessible name and the hover text with empty values.
if (strings.addToPlaylist) {
addToPlaylistButton.setAttribute('aria-label', strings.addToPlaylist);
addToPlaylistButton.title = strings.addToPlaylist;
}
addToPlaylistButton.dataset.playlistAdd = '';
addToPlaylistButton.dataset.playlistLibraryId = entry.libraryId;
addToPlaylistButton.dataset.playlistTrackId = entry.mediaItemId;
addToPlaylistButton.dataset.playlistAlbumId = entry.collectionId;
addToPlaylistButton.dataset.playlistArtistId = entry.creatorId;
addToPlaylistButton.dataset.playlistTitle = entry.mediaItemTitle || '';
row.appendChild(addToPlaylistButton);
}
// The index passed to this function is local to the rendered rows. Disabling the move controls requires the global position,
@@ -31,7 +31,10 @@
- The hook attributes the audio player binds: 'data-audio-player-play-pause', '-stop', '-previous', '-next', '-repeat',
'-progress', '-progress-played', '-progress-downloaded', '-progress-undownloaded', '-current-time', '-total-time',
'-track-name', '-album-name', '-now-playing-title', '-now-playing-release-type', '-now-playing-release',
'-now-playing-year', '-now-playing-artist', '-artwork-carousel', '-cover-thumbnail', '-cover-image', '-volume', '-volume-level', '-mute', '-queue', '-playlist-combobox' and '-add-queue-to-playlist'.
'-now-playing-year', '-now-playing-artist', '-favorite', '-artwork-carousel', '-cover-thumbnail', '-cover-image',
'-volume', '-volume-level', '-mute', '-queue', '-playlist-combobox' and '-add-queue-to-playlist'.
The favorite toggle ('-favorite') sits in the condensed bar, between repeat and mute. The player sets its media kind
and current track Id and hides it while no track is loaded. A missing hook gets the built-in toggle in that place.
The queue-to-playlist action is a standard application combo box, so a theme renders the usual 'enlightenment-combobox'
markup and puts the '-playlist-combobox' hook on its root. The player only reads the 'data-value' of the selected text
when the add button is pressed. A theme that renders one half of the action gets a complete built-in pair, placed in a
@@ -72,8 +75,11 @@
'library'), a whole library play affordance uses 'data-audio-player-play-library' with 'data-library-id', a whole library
shuffle affordance uses 'data-audio-player-play-library-shuffled' with 'data-library-id', and a play next affordance uses
'data-audio-player-play-next'. A track trigger must carry libraryId, trackId, albumId and artistId, because the playback
manifest route needs all four Ids. The 'Play Affordances on the Music Pages' section of
docs/technical/theming/Theming.md documents this contract for theme authors.
manifest route needs all four Ids. The add-to-playlist actions of the music pages and playlist rows use the
'data-playlist-add' marker with the 'data-playlist-library-id', '-track-id', '-album-id', '-artist-id' and '-title'
scope attributes, handled by the global playlist script the layout loads. The 'Play Affordances on the Music Pages'
and 'The Shared Add to Playlist Action' sections of docs/technical/theming/Theming.md document both contracts for
theme authors.
*@
<div class="audio-player-container not-shown" hidden>
@@ -146,6 +152,11 @@
<span class="audio-player-repeat-one-badge" aria-hidden="true">1</span>
</button>
</div>
<!-- Favorite toggle of the current track: icon only, no rectangle, between repeat and mute. The player writes its favorite attributes when a track plays. -->
<button type="button" class="audio-player-button audio-player-favorite" data-audio-player-favorite
aria-label="@localizer["FavoritesAdd"]" hidden>
<span class="audio-player-favorite-icon" aria-hidden="true"></span>
</button>
<div class="audio-player-volume-control">
<button type="button" class="audio-player-button audio-player-mute" data-audio-player-mute aria-label="@localizer["AudioPlayerMute"]" aria-pressed="false">
<span class="audio-player-mute-icon"></span>
@@ -101,7 +101,8 @@
tracksAdded: '@localizer["PlaylistTracksAdded"]',
tracksAddFailed: '@localizer["PlaylistTracksAddFailed"]',
noTracksToAdd: '@localizer["PlaylistNoTracksToAdd"]',
add: '@localizer["AudioPlayerAdd"]'
add: '@localizer["AudioPlayerAdd"]',
addToPlaylist: '@localizer["PlaylistAddToPlaylist"]'
}
};
// The endpoints and labels of the favorite toggles that every media page and theme template can render. The script reads which
@@ -1328,6 +1328,24 @@ body {
margin: 0 auto;
}
/* The hearts of a playlist row and of a player queue item are inline actions, so they are always visible and never take the position of a card heart. */
.playlist-entry-favorite.card-favorite-toggle,
.audio-player-queue-item-actions .card-favorite-toggle {
position: static;
display: flex;
flex: 0 0 auto;
margin: 0;
}
/* The add-to-playlist action of a playlist row is compact, because it sits in a row that already carries the playback, reordering and removal controls. */
.playlist-entry-add-to-playlist {
width: 22px;
min-width: 22px;
height: 22px;
padding: 0;
line-height: 1;
}
.card-actions-menu {
display: none;
position: fixed;
@@ -1762,6 +1780,35 @@ html.audio-player-initializing .audio-player-container {
cursor: default;
}
/* The favorite toggle of the condensed bar is icon only, with no rectangle of its own: it reuses the transparent box of a transport button, and the stylesheet draws the heart. */
.audio-player-favorite[hidden] {
display: none;
}
.audio-player-favorite-icon {
display: block;
font-size: 16px;
line-height: 1;
color: #E6E6E6;
}
.audio-player-favorite-icon::after {
content: '\2665';
}
.audio-player-favorite:hover .audio-player-favorite-icon {
color: #FFFFFF;
}
.audio-player-favorite.is-favorite .audio-player-favorite-icon {
color: #FF5D5D;
}
.audio-player-favorite[data-favorite-state="loading"] {
opacity: 0.5;
cursor: progress;
}
/* The skip icons are drawn with CSS, so a theme restyles them without an image. */
.audio-player-previous-icon,
.audio-player-next-icon {
@@ -2159,6 +2206,18 @@ html.audio-player-initializing .audio-player-container {
font-variant-numeric: tabular-nums;
}
/* The favorite and add-to-playlist actions of a queue item sit after its duration, so a queued track can be saved without starting it. A queue item without a track renders the container empty. */
.audio-player-queue-item-actions {
display: flex;
flex: 0 0 auto;
align-items: center;
gap: 4px;
}
.audio-player-queue-item-actions:empty {
display: none;
}
/* The shared playlist picker of the add-to-playlist card actions. It reuses the application dialog surface on its own
overlay, so it never takes part in the queue of the global dialog service. */
.playlist-picker-overlay {
@@ -11,7 +11,8 @@
* controls, the keyboard shortcuts, and the loading state a seek into a not yet downloaded position shows; the volume
* and mute the controls change are persisted to the stored playback state of the user on their own. The expanded bar also
* offers appending the current queue, in order, to one of the playlists of the user, through a theme hook with a built-in
* fallback when the theme does not render it.
* fallback when the theme does not render it. The condensed bar also renders the favorite toggle of the current track,
* and every queue item carries its own favorite toggle, so a user can favorite what is playing and what is queued without leaving the bar.
*
* Public control API (window.LuminaAudioPlayer.instance)
* ----------------------------------------
@@ -723,6 +724,9 @@
this.vuMeterAnalyser = null;
// The raw theme sub templates of the dynamic content, read once with the bar elements and null when the theme does not provide them.
this.subTemplates = { queueItem: null, playlistItem: null };
// The track whose favorite toggle is currently shown in the bar, so a repeated render of the same track does
// not rewrite the attributes the favorites script already hydrated.
this.renderedFavoriteTrackId = null;
// The playlists of the user, used by the control that adds the current queue to a playlist, and the in flight load of
// them, so an expansion and a focus on the select share one request instead of racing each other.
this.playlists = [];
@@ -771,6 +775,7 @@
this.isAvailable = true;
this.collectDomReferences();
this.ensureFavoriteControl();
this.ensureVuMeter();
this.bindPlaybackControls();
this.bindKeyboardShortcuts();
@@ -781,8 +786,7 @@
this.suppressInitialTransitions();
this.applyHiddenState();
this.releaseInitialHiddenState();
// The volume and mute controls are rendered from the state the player already holds, so the bar shows the
// default volume even before the stored state is read.
// The volume and mute controls are rendered from the state the player already holds, so the bar shows the default volume even before the stored state is read.
this.renderVolume();
this.renderTransportState();
@@ -823,6 +827,7 @@
this.dom.nowPlayingYear = query('[data-audio-player-now-playing-year]');
this.dom.nowPlayingArtist = query('[data-audio-player-now-playing-artist]');
this.dom.artworkCarousel = query('[data-audio-player-artwork-carousel]');
this.dom.favorite = query('[data-audio-player-favorite]');
// The sub template sources are read once, with the bar elements, because the theme markup is part of the bar
// the player was bound to, and the player is never recreated by a navigation.
this.subTemplates = {
@@ -869,6 +874,75 @@
this.vuMeterUnsubscribe = this.events.on(LuminaAudioPlayer.PlayerEvent.PREFERENCES_CHANGED, () => this.applyVuMeterSettings());
}
/**
* Creates the favorite toggle of the condensed bar when the active theme does not render the hook.
*
* The favorite belongs to the bar rather than to a page, so it is created once with the bar elements and survives
* every in-place navigation. A theme that renders the 'data-audio-player-favorite' hook owns where the control
* sits; a theme that does not gets a built-in icon-only button between the repeat and mute controls.
*/
ensureFavoriteControl() {
if (this.dom.favorite)
return;
const bar = this.container.querySelector('.audio-player-bar');
if (!bar)
return;
const favorite = document.createElement('button');
favorite.type = 'button';
favorite.className = 'audio-player-button audio-player-favorite';
favorite.dataset.audioPlayerFavorite = '';
favorite.hidden = true;
const icon = document.createElement('span');
icon.className = 'audio-player-favorite-icon';
icon.setAttribute('aria-hidden', 'true');
favorite.appendChild(icon);
// The volume control follows the repeat control in the bar. Inserting before it keeps the built-in favorite
// between the two, exactly where the fallback markup places it.
const volumeControl = this.container.querySelector('.audio-player-volume-control');
if (volumeControl && volumeControl.parentNode === bar)
bar.insertBefore(favorite, volumeControl);
else
bar.appendChild(favorite);
this.dom.favorite = favorite;
}
/**
* Shows the favorite toggle of the current track in the condensed bar.
*
* The favorites script hydrates the toggle when the player writes the Id of a new track. Writing the same Id again
* would make the script observe an attribute change and request a state it already shows, so an unchanged track
* skips the write. The toggle is hidden while there is no track to favorite.
*/
renderFavorite() {
const favorite = this.dom.favorite;
if (!favorite)
return;
const descriptor = this.descriptor;
const trackId = descriptor && descriptor.trackId ? descriptor.trackId : '';
if (!trackId) {
favorite.hidden = true;
favorite.removeAttribute('data-favorite-toggle');
favorite.removeAttribute('data-favorite-media-kind');
favorite.removeAttribute('data-favorite-media-item-id');
this.renderedFavoriteTrackId = null;
return;
}
favorite.hidden = false;
if (this.renderedFavoriteTrackId === trackId)
return;
// The player shows the toggle before the favorites script hydrates it, so it borrows the label of the action
// once. The script replaces it with the add or remove label as soon as the state arrives.
const favoritesStrings = window.favoritesConfiguration && window.favoritesConfiguration.strings;
if (favoritesStrings && favoritesStrings.add && !favorite.hasAttribute('aria-label'))
favorite.setAttribute('aria-label', favoritesStrings.add);
// The favorites script owns the state, the labels and the pressed state from this point on. The attributes are
// written together, so the observer sees one item change and hydrates it once.
favorite.setAttribute('data-favorite-toggle', '');
favorite.setAttribute('data-favorite-media-kind', 'MusicTrack');
favorite.setAttribute('data-favorite-media-item-id', trackId);
this.renderedFavoriteTrackId = trackId;
}
/**
* Applies the current preferences to the VU meter, so a settings change that arrives after the bar was built, or
* a change saved on the settings page, takes effect without recreating the player.
@@ -4156,6 +4230,7 @@
// The artwork chosen from the carousel belongs to the album that was showing when it was chosen. A new track resets the selection to the cover of its own album.
this.nowPlayingArtworkPath = descriptor ? (descriptor.coverArtPath || '') : '';
this.renderNowPlayingDetails();
this.renderFavorite();
if (this.dom.totalTime)
this.dom.totalTime.textContent = formatDuration(this.duration);
this.renderTransportState();
@@ -5100,6 +5175,7 @@
* Renders one queue item, from the theme sub template when the theme provides one and from the built-in markup
* otherwise. The rendered root always carries the 'data-audio-player-queue-entry-id' attribute, whatever the theme
* markup is, so the queue list can start the entry the user clicked without the theme repeating the identity.
* Every entry that references a track also carries its favorite toggle and add-to-playlist action, either from the theme sub template or from the built-in markup.
* @param {Object} entry - The queue entry, with an entryId, a descriptor and a source.
* @param {number} index - The zero based position of the item in the queue.
* @param {number} totalItems - The number of items in the queue.
@@ -5138,6 +5214,16 @@
}
if (!rendered)
rendered = this.buildDefaultQueueItem(viewModel);
// An older theme queue item may predate the favorite toggle. Appending the built-in one keeps every queue entry
// favoritable, exactly as the condensed bar always falls back. querySelector does not match the root itself, so
// a theme that puts the marker on the item root is checked with matches as well.
const hasFavoriteToggle = rendered.matches('[data-favorite-toggle]')
|| rendered.querySelector('[data-favorite-toggle]') !== null;
if (!hasFavoriteToggle) {
const favorite = this.buildQueueItemFavorite(viewModel);
if (favorite)
rendered.appendChild(favorite);
}
rendered.setAttribute('data-audio-player-queue-entry-id', entry.entryId);
// The player writes the state classes on the item root itself, so a theme queue item template keeps the current and played distinction even when its markup omits the state classes.
rendered.classList.toggle('is-current', viewModel.isCurrent);
@@ -5181,8 +5267,33 @@
entry.appendChild(cover);
entry.appendChild(title);
entry.appendChild(duration);
entry.appendChild(this.buildQueueItemFavorite(viewModel));
return entry;
}
/**
* Builds the favorite toggle of a queue item.
*
* Every queue entry that references a track can be favorited without starting it. The control is built through the
* DOM, so the track title cannot break out of an attribute, and it carries the same attributes a theme sub template
* renders, so both paths use the global favorites script.
* @param {Object} viewModel - The queue item model, per {@link LuminaAudioPlayer.AudioPlayer#renderQueueItem}.
* @returns {HTMLElement} The favorite container of the item.
*/
buildQueueItemFavorite(viewModel) {
const actions = document.createElement('span');
actions.className = 'audio-player-queue-item-actions';
if (!viewModel.trackId)
return actions;
const favoriteToggle = document.createElement('button');
favoriteToggle.type = 'button';
favoriteToggle.className = 'card-favorite-toggle audio-player-queue-item-favorite';
favoriteToggle.setAttribute('data-favorite-toggle', '');
favoriteToggle.setAttribute('data-favorite-media-kind', 'MusicTrack');
favoriteToggle.setAttribute('data-favorite-media-item-id', viewModel.trackId);
actions.appendChild(favoriteToggle);
return actions;
}
}
LuminaAudioPlayer.AudioPlayer = AudioPlayer;
@@ -1,6 +1,7 @@
/**
* Favorite toggles: the hearts of the media cards (books, artists and albums, and the cards of the favorites page) and of the
* track rows of the album page. The detail pages of an item have no toggle.
* Favorite toggles: the hearts of the media cards (books, artists and albums, and the cards of the favorites page), of the
* track rows of the album page, of the rows of a saved playlist, and of the current track and the queue items of the audio
* player bar. The detail pages of an item have no toggle.
*
* A toggle is any focusable element, normally a button, that carries the `data-favorite-toggle` marker together with the
* `data-favorite-media-kind` (`MusicArtist`, `MusicAlbum`, `MusicTrack` or `Book`) and `data-favorite-media-item-id`
@@ -142,19 +143,46 @@
}
/**
* Finds every toggle of the document that refers to an item.
* Builds the index of every toggle of the document, grouped by item key.
*
* A page can render the same item more than once, for example the artist in a header and in a list, and every one of
* them must show the same state. The toggles are looked up when a state is written, not remembered, so a toggle that
* was added while a request was in flight is also updated and a removed one is not touched.
* @param {string} key - The key of the item.
* @returns {Array<Element>} The toggles of the item.
* A status flush resolves many items at once, and every resolved item has to write its state on all of its toggles.
* Reading the document once and grouping the toggles by key keeps that write linear in the number of toggles,
* instead of rescanning the whole document for every item. The toggles a caller passes in are added as well, so an
* element that is not attached to the document yet is still updated.
* @param {Array<Element>} [additionalToggles] - The toggles to include besides the ones of the document.
* @returns {Map<string, Array<Element>>} The toggles of each item key.
*/
function findToggles(key) {
return collectToggles(document).filter(toggle => {
function buildToggleIndex(additionalToggles) {
const index = new Map();
const seenToggles = new Set();
const addToggle = toggle => {
// The document pass and the list a caller passed in can hold the same element, so it is added only once.
if (seenToggles.has(toggle))
return;
seenToggles.add(toggle);
const item = readToggleItem(toggle);
return item !== null && item.key === key;
});
if (!item)
return;
const toggles = index.get(item.key);
if (toggles)
toggles.push(toggle);
else
index.set(item.key, [toggle]);
};
collectToggles(document).forEach(addToggle);
if (Array.isArray(additionalToggles))
additionalToggles.forEach(addToggle);
return index;
}
/**
* Gets the toggles of an item from a built index.
* @param {Map<string, Array<Element>>} index - The index built by {@link buildToggleIndex}.
* @param {string} key - The key of the item.
* @returns {Array<Element>} The toggles of the item, or an empty array when the item has none.
*/
function getIndexedToggles(index, key) {
return index.get(key) || [];
}
/**
@@ -215,9 +243,12 @@
* Writes the settled state of an item on every toggle that shows it.
* @param {string} key - The key of the item.
* @param {boolean} isFavorite - Whether the item is a favorite of the current user.
* @param {Map<string, Array<Element>>} [index] - An already built toggle index, so a batch of items does not scan the document once per item.
*/
function applyFavoriteState(key, isFavorite) {
findToggles(key).forEach(toggle => renderToggle(toggle, isFavorite ? 'favorited' : 'not-favorited', isFavorite));
function applyFavoriteState(key, isFavorite, index) {
const toggleIndex = index || buildToggleIndex();
getIndexedToggles(toggleIndex, key)
.forEach(toggle => renderToggle(toggle, isFavorite ? 'favorited' : 'not-favorited', isFavorite));
}
/**
@@ -353,13 +384,20 @@
if (!checks.has(item.key))
checks.set(item.key, { item, revision: getRevision(item.key) });
}
// Nothing to ask and nothing to write, so the document is not scanned for an empty batch.
if (checks.size === 0)
return;
// One document pass serves every item of the batch, so hydrating a queue of N tracks with one toggle per item
// costs one scan of the document instead of N scans, which is what made the previous lookup quadratic. A toggle
// added while the requests are in flight is picked up by the observer of the document and hydrated on its own.
const index = buildToggleIndex(toggles);
await Promise.all(Array.from(checks.values(), check => queueStatusCheck(check.item).then(
isFavorite => {
if (getRevision(check.item.key) === check.revision && !mutationsInFlight.has(check.item.key))
applyFavoriteState(check.item.key, isFavorite);
applyFavoriteState(check.item.key, isFavorite, index);
},
() => {
findToggles(check.item.key)
getIndexedToggles(index, check.item.key)
.filter(toggle => toggle.getAttribute('data-favorite-state') === 'loading')
.forEach(toggle => renderToggle(toggle, 'failed', isPressed(toggle)));
})));
@@ -376,7 +414,8 @@
*/
async function changeFavoriteAsync(item, shouldFavorite) {
const previousStates = new Map();
findToggles(item.key).forEach(toggle => {
const initialIndex = buildToggleIndex();
getIndexedToggles(initialIndex, item.key).forEach(toggle => {
previousStates.set(toggle, { state: toggle.getAttribute('data-favorite-state'), isFavorite: isPressed(toggle) });
renderToggle(toggle, 'loading', isPressed(toggle));
});
@@ -412,7 +451,8 @@
}
// A toggle added while the request was in flight has no remembered state, so it gets the state that was true before the change.
findToggles(item.key).forEach(toggle => {
const restoreIndex = buildToggleIndex();
getIndexedToggles(restoreIndex, item.key).forEach(toggle => {
const previous = previousStates.get(toggle) || { state: shouldFavorite ? 'not-favorited' : 'favorited', isFavorite: !shouldFavorite };
const state = previous.state === 'favorited' || previous.state === 'not-favorited' ? previous.state : 'failed';
renderToggle(toggle, state, previous.isFavorite);
@@ -526,8 +566,15 @@
continue;
}
mutation.addedNodes.forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE)
collectToggles(node).forEach(toggle => toggles.add(toggle));
if (node.nodeType !== Node.ELEMENT_NODE)
return;
collectToggles(node).forEach(toggle => {
// A re-appended row, such as the rows of a playlist after a drag reorder, keeps the state it already
// shows. Re-checking it would send a status request for a heart that is already settled on screen.
const state = toggle.getAttribute('data-favorite-state');
if (state !== 'favorited' && state !== 'not-favorited')
toggles.add(toggle);
});
});
}
if (toggles.size > 0)
@@ -4,7 +4,9 @@
* The module owns one modal playlist picker. A page opens it with the scope or the single track it wants to add. A scope
* is resolved by the server into its ordered track Ids and appended in one request; a single track is appended through
* the single entry route. The actual card and track menu items are small wrappers that give the menu item its scope and
* call <c>LuminaPlaylists.showAddScopeDialogAsync</c>.
* call <c>LuminaPlaylists.showAddScopeDialogAsync</c>. A theme template or a page script can also render a declarative
* action, which needs no script of its own: an element with the `data-playlist-add` marker and the scope attributes
* documented in the theming guide opens the same picker through the delegated click listener of this module.
*
* The scope is resolved on the server so the browser never enumerates a whole library, and the server can add all of its
* tracks to the playlist atomically. A single track is already identified, so it uses the cheaper single-entry route
@@ -15,6 +17,15 @@
(function () {
'use strict';
// The layout may render this script on a page that already ran it, and the in-place navigation can evaluate scripts
// again. A second set of listeners would send every request twice, so the first load owns the document.
if (window.LuminaPlaylists)
return;
// The declarative add action: an element that carries the marker and the scope attributes documented in the theming
// guide. The listener reads them when the user clicks, so a page can render the action before its data is known.
const ADD_TRIGGER_SELECTOR = '[data-playlist-add]';
// The layout renders the playlist id of the route as an empty Guid because the id is not known until the user picks
// a playlist here. Replacing this sentinel keeps the route construction in one place and avoids hand-built paths.
const EMPTY_GUID = '00000000-0000-0000-0000-000000000000';
@@ -443,6 +454,63 @@
});
}
/**
* Reads the scope of a declarative add action from its data attributes.
*
* The attributes are read when the click happens, so a page or a theme may render the action before the scope is
* known and write the values later, which is what the audio player does for the current track. A missing library Id
* makes the action a no-op, because every scope is resolved inside one library.
* @param {Element} trigger - The element that carries the `data-playlist-add` marker.
* @returns {Object|null} The scope, or null when the action has no library to resolve the scope in.
*/
function readScopeFromTrigger(trigger) {
const dataset = trigger && trigger.dataset ? trigger.dataset : null;
if (!dataset || !dataset.playlistLibraryId)
return null;
return {
libraryId: dataset.playlistLibraryId,
trackId: dataset.playlistTrackId || '',
albumId: dataset.playlistAlbumId || '',
artistId: dataset.playlistArtistId || '',
title: dataset.playlistTitle || '',
addToPlaylistLabel: getStrings().addToPlaylist || '',
returnFocus: trigger
};
}
/**
* Opens the picker for a declarative add action, through event delegation.
*
* The module binds one listener on the document, so a control works anywhere in the swapped page content and inside
* the player bar, including controls that a page or a theme renders later. The default action is prevented, so a link
* does not navigate, and further bubbling is stopped once the event reaches the document. A handler on an ancestor
* that already ran before the document listener is not undone; the player queue ignores controls inside its entries,
* and a menu that hosts such an action closes itself in its own handler.
* @param {MouseEvent} event - The click event.
*/
function handleAddTriggerClick(event) {
const target = event.target;
if (!target || typeof target.closest !== 'function')
return;
const trigger = target.closest(ADD_TRIGGER_SELECTOR);
if (!trigger)
return;
// A disabled control explains itself through its text; opening a picker from it would be a surprising action.
if (trigger.disabled === true || trigger.getAttribute('aria-disabled') === 'true')
return;
const scope = readScopeFromTrigger(trigger);
if (!scope)
return;
event.preventDefault();
event.stopPropagation();
showAddScopeDialogAsync(scope).catch(error => {
console.error('Playlists: opening the add-to-playlist picker failed.', error);
showNotification(getStrings().tracksAddFailed, true);
});
}
document.addEventListener('click', handleAddTriggerClick);
window.LuminaPlaylists = {
showAddScopeDialogAsync
};