initial
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// 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 }
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array(), 'module_dependencies' => array(array('id' => '@wordpress/interactivity', 'import' => 'static')), 'version' => '99f747d731f80246db11');
|
||||
@@ -0,0 +1 @@
|
||||
import{store as a,getContext as e,getElement as s}from"@wordpress/interactivity";a("core/playlist",{state:{playlists:{},get currentTrack(){let{currentId:t,playlistId:n}=e();if(!t||!n)return{};let r=this.playlists[n];return r?r.tracks[t]||{}:{}},get isCurrentTrack(){let{currentId:t,uniqueId:n}=e();return t===n}},actions:{changeTrack(){let t=e();t.currentId=t.uniqueId,t.isPlaying=!0},isPlaying(){let t=e();t.isPlaying=!0},isPaused(){let t=e();t.isPlaying=!1},nextSong(){let t=e(),n=t.tracks.findIndex(c=>c===t.currentId),r=t.tracks[n+1];if(r){t.currentId=r;let{ref:c}=s();setTimeout(()=>{c.play()},1e3)}}},callbacks:{autoPlay(){let t=e(),{ref:n}=s();t.currentId&&t.isPlaying&&n.play()}}},{lock:!0});
|
||||
Reference in New Issue
Block a user