- md5
- f2880c56854f954710468b79f1539a11
- sha1
- 79274f98df8a0b369767731e8897c21e01437678
- sha256
- 23efba6160c0051d60115e39d654bb9d6fe0b89908e55cd05a8ffdb9921ee094
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
// packages/block-library/build-module/playlist/view.mjs
import { store, getContext, getElement } from "@wordpress/interactivity";
store(
"core/playlist",
{
state: {
playlists: {},
get currentTrack() {
const { currentId, playlistId } = getContext();
if (!currentId || !playlistId) {
return {};
}
const playlist = this.playlists[playlistId];
if (!playlist) {
return {};
}
return playlist.tracks[currentId] || {};
},
get isCurrentTrack() {
const { currentId, uniqueId } = getContext();
return currentId === uniqueId;
}
},
actions: {
changeTrack() {
const context = getContext();
context.currentId = context.uniqueId;
context.isPlaying = true;
},
isPlaying() {
const context = getContext();
context.isPlaying = true;
},
isPaused() {
const context = getContext();
context.isPlaying = false;
},
nextSong() {
const context = getContext();
const currentIndex = context.tracks.findIndex(
(uniqueId) => uniqueId === context.currentId
);
const nextTrack = context.tracks[currentIndex + 1];
if (nextTrack) {
context.currentId = nextTrack;
const { ref } = getElement();
setTimeout(() => {
ref.play();
}, 1e3);
}
}
},
callbacks: {
autoPlay() {
const context = getContext();
const { ref } = getElement();
if (context.currentId && context.isPlaying) {
ref.play();
}
}
}
},
{ lock: true }
);
The same content is in 3 releases, WordPress 7.0-beta1 to 7.0-beta3. See them all, or every version of this file.