Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playlist block #50664

Open
wants to merge 75 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
8b44789
Basic playlist block
carolinan May 11, 2023
4198e21
try to make some accessibility improvements
carolinan May 12, 2023
ac17285
Park the PHP file until work can continue
carolinan May 12, 2023
1fcbf71
Update index.php
carolinan May 12, 2023
8aed3d3
Update index.php, try to solve merge conflicts
carolinan May 15, 2023
14e1fa5
Remove the style variation
carolinan May 15, 2023
92a3c65
Remove the unused save, add escaping, update css
carolinan May 16, 2023
59bb48f
Update edit.js
carolinan May 16, 2023
4ba31d9
Update edit.js
carolinan May 16, 2023
1e94427
Update edit.js
carolinan May 16, 2023
00d6970
Merge branch 'trunk' into try/playlist2
carolinan May 16, 2023
ca834be
fix CS issues
carolinan May 17, 2023
cce2cc5
Fix two issues with the upload option.
carolinan May 17, 2023
54cc037
Disable uploading and selecting multiple files in the replacement flow.
carolinan May 19, 2023
381650a
Update the placeholder instructions
carolinan May 19, 2023
ff810d2
Merge branch 'trunk' into try/playlist2
carolinan May 19, 2023
dab0e24
Correct a translators comment.
carolinan May 21, 2023
04a8368
Hide tracklist options if the tracklist itself is toggled off
carolinan May 21, 2023
19fc308
Merge branch 'trunk' into try/playlist2
carolinan Jul 11, 2023
7358614
Merge branch 'trunk' into try/playlist2
carolinan Jan 8, 2024
8bb139e
Merge branch 'trunk' into try/playlist2
carolinan Jan 25, 2024
38eaeed
Merge branch 'trunk' into try/playlist2
carolinan Feb 14, 2024
d9ff601
Merge branch 'trunk' into try/playlist2
carolinan Jul 23, 2024
b59aba1
Try to fix CS issues, update to apiVersion 3
carolinan Jul 23, 2024
86b992d
Add since
carolinan Jul 23, 2024
441a72d
Add color block supports
carolinan Jul 23, 2024
1181836
Merge branch 'trunk' into try/playlist2
carolinan Oct 22, 2024
3cf80ae
Add __next40pxDefaultSize and __nextHasNoMarginBottom to various cont…
carolinan Oct 22, 2024
862c4f1
Use the option for the experimental blocks.
carolinan Oct 22, 2024
880db38
WIP: Use the interactivity API.
carolinan Oct 23, 2024
69e1629
Build the core-blocks.md doc to update the block supports
carolinan Oct 24, 2024
9e60534
Merge branch 'trunk' into try/playlist2
carolinan Oct 24, 2024
8f9106e
Index.php: Re-add the conditions for the block options.
carolinan Oct 24, 2024
e0390ec
Index.php: update spacing
carolinan Oct 24, 2024
234738d
Playlist: Add caption
carolinan Oct 24, 2024
6d4a85f
Re-build docs
carolinan Oct 25, 2024
eea92d6
Merge branch 'trunk' into try/playlist2
carolinan Oct 25, 2024
95c425f
Re-add the autoplay of the next track when one track ends.
carolinan Oct 25, 2024
66f32d1
Remove the track title from the current track
carolinan Oct 25, 2024
70b1337
WIP: Update styles
carolinan Oct 25, 2024
e54fa51
Update style.scss
carolinan Oct 25, 2024
86592aa
Merge branch 'trunk' into try/playlist2
carolinan Oct 30, 2024
5999fec
Add placeholder artist and album, remove placeholder image
carolinan Oct 30, 2024
3fa03b8
Update colors to work better when the user selects text and backgroun…
carolinan Oct 30, 2024
e8cfd68
Merge branch 'trunk' into try/playlist2
carolinan Nov 9, 2024
244b979
Merge branch 'trunk' into try/playlist2
carolinan Nov 12, 2024
c4b50bd
Merge branch 'trunk' into try/playlist2
carolinan Nov 13, 2024
3b18ebc
WIP: Use inner blocks for the tracks
carolinan Nov 13, 2024
7ef20d0
Track: Use "Replace" instead of "Edit" in the toolbar
carolinan Nov 13, 2024
f84a718
Track: Set the text align on the button to left.
carolinan Nov 13, 2024
6ef1e5d
Track: Update block supports
carolinan Nov 13, 2024
7ad6159
Playlist: Try showing the inserter at the bottom of the block.
carolinan Nov 13, 2024
7a7b9ec
Adjust the track button CSS class and move the appender
carolinan Nov 14, 2024
01df824
Fix the invalid HTML of the list on the front
carolinan Nov 14, 2024
f8a7492
Track: update block supports
carolinan Nov 14, 2024
f1c7786
WIP: Prevent duplicate tracks
carolinan Nov 14, 2024
d75c10d
Move the tracklist inside `<Disabled>`
carolinan Nov 14, 2024
a86d15f
Playlist: Rename the images attribute to showImages
carolinan Nov 14, 2024
10b5551
Revert placing the tracklist within Disabled since it prevented addin…
carolinan Nov 14, 2024
bf141aa
Revert the prevention of duplicate tracks
carolinan Nov 14, 2024
5c2da88
Playlist: rename the tracklist block attribute to showTracklist
carolinan Nov 14, 2024
358ed29
Playlist: Update the tracks block attribute when the user changes pos…
carolinan Nov 14, 2024
2955deb
Playlist: Fix the display of the album image
carolinan Nov 14, 2024
a6226fc
Re-add the track title to the current track.
carolinan Nov 14, 2024
5f23da3
Try to fix a JS error when a track is re-positioned.
carolinan Nov 14, 2024
845e9ed
Playlist: Add the current title as a data-wp-text
carolinan Nov 14, 2024
2a0329e
Playlist: Correct the position of the artist and album for the curren…
carolinan Nov 14, 2024
5e50c96
Track: Try to improve responsiveness
carolinan Nov 14, 2024
389e86c
First iteration of adding the album cover image to the track
carolinan Nov 14, 2024
6d2cd60
Adjust the CSS
carolinan Nov 15, 2024
c467dbf
Update the monitoring of changes to inner blocks
carolinan Nov 15, 2024
3580672
Update how the current track is managed
carolinan Nov 15, 2024
2512870
Update the appender, prevent grouping inner blocks
carolinan Nov 15, 2024
6990862
Prevent PHP notices when the current track is the media placeholder
carolinan Nov 15, 2024
9ac5f28
Merge branch 'trunk' into try/playlist2
carolinan Nov 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,28 @@ Show a block pattern. ([Source](https://github.com/WordPress/gutenberg/tree/trun
- **Supports:** interactivity (clientNavigation), ~~html~~, ~~inserter~~, ~~renaming~~
- **Attributes:** slug

## Playlist

Embed a simple playlist. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/playlist))

- **Name:** core/playlist
- **Experimental:** true
- **Category:** media
- **Allowed Blocks:** core/playlist-track
- **Supports:** align, anchor, color (background, gradients, link, text), interactivity, spacing (margin, padding)
- **Attributes:** caption, currentTrack, order, showArtists, showImages, showNumbers, showTracklist, tracks, type

## Playlist track

Playlist track. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/playlist-track))

- **Name:** core/playlist-track
- **Experimental:** true
- **Category:** media
- **Parent:** core/playlist
- **Supports:** interactivity (clientNavigation), ~~html~~, ~~reusable~~
- **Attributes:** album, artist, id, image, length, title, type, url

## Author

Display post author details such as name, avatar, and bio. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/post-author))
Expand Down
4 changes: 4 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function gutenberg_reregister_core_block_types() {
'more',
'nextpage',
'paragraph',
'playlist',
'playlist-track',
'preformatted',
'pullquote',
'quote',
Expand Down Expand Up @@ -88,6 +90,8 @@ function gutenberg_reregister_core_block_types() {
'post-author.php' => 'core/post-author',
'post-author-name.php' => 'core/post-author-name',
'post-author-biography.php' => 'core/post-author-biography',
'playlist.php' => 'core/playlist',
'playlist-track.php' => 'core/playlist-track',
'post-comment.php' => 'core/post-comment',
'post-comments-count.php' => 'core/post-comments-count',
'post-comments-form.php' => 'core/post-comments-form',
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"./file/view": "./build-module/file/view.js",
"./image/view": "./build-module/image/view.js",
"./navigation/view": "./build-module/navigation/view.js",
"./playlist/view": "./build-module/playlist/view.js",
"./query/view": "./build-module/query/view.js",
"./search/view": "./build-module/search/view.js"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ import * as pattern from './pattern';
import * as pageList from './page-list';
import * as pageListItem from './page-list-item';
import * as paragraph from './paragraph';
import * as playlist from './playlist';
import * as playlistTrack from './playlist-track';
import * as postAuthor from './post-author';
import * as postAuthorName from './post-author-name';
import * as postAuthorBiography from './post-author-biography';
Expand Down Expand Up @@ -239,6 +241,11 @@ const getAllBlocks = () => {
blocks.push( formSubmissionNotification );
}

if ( window?.__experimentalEnableBlockExperiments ) {
blocks.push( playlist );
blocks.push( playlistTrack );
}

// When in a WordPress context, conditionally
// add the classic block and TinyMCE editor
// under any of the following conditions:
Expand Down
49 changes: 49 additions & 0 deletions packages/block-library/src/playlist-track/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"__experimental": true,
"name": "core/playlist-track",
"title": "Playlist track",
"category": "media",
"parent": [ "core/playlist" ],
"description": "Playlist track.",
"keywords": [ "music", "sound" ],
"textdomain": "default",
"usesContext": [ "showArtists", "currentTrack" ],
"attributes": {
"id": {
"type": "number"
},
"type": {
"type": "string",
"default": "audio"
},
"album": {
"type": "string"
},
"artist": {
"type": "string"
},
"image": {
"type": "string"
},
"length": {
"type": "string"
},
"title": {
"type": "string"
},
"url": {
"type": "string"
}
},
"supports": {
"html": false,
"interactivity": {
"clientNavigation": true
},
"reusable": false
},
"editorStyle": "wp-block-playlist-track-editor",
"style": "wp-block-playlist-track"
}
244 changes: 244 additions & 0 deletions packages/block-library/src/playlist-track/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
/**
* WordPress dependencies
*/
import { useCallback, useRef } from '@wordpress/element';
import {
MediaPlaceholder,
MediaReplaceFlow,
MediaUpload,
MediaUploadCheck,
BlockIcon,
useBlockProps,
BlockControls,
InspectorControls,
RichText,
} from '@wordpress/block-editor';
import {
Button,
PanelBody,
TextControl,
BaseControl,
} from '@wordpress/components';
import { useDispatch } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';
import { __ } from '@wordpress/i18n';
import { audio as icon } from '@wordpress/icons';
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';

const ALLOWED_MEDIA_TYPES = [ 'audio' ];
const ALBUM_COVER_ALLOWED_MEDIA_TYPES = [ 'image' ];

const PlaylistTrackEdit = ( { attributes, setAttributes, context } ) => {
const { id, album, artist, image, length, title, url } = attributes;
const showArtists = context?.showArtists;
const currentTrack = context?.currentTrack;
const imageButton = useRef();
const blockProps = useBlockProps();
const { createErrorNotice } = useDispatch( noticesStore );
function onUploadError( message ) {
createErrorNotice( message, { type: 'snackbar' } );
}

const onSelectTrack = useCallback(
( media ) => {
if ( ! media ) {
return;
}
setAttributes( {
id: media.id,
artist:
media.artist ||
media?.meta?.artist ||
__( 'Unknown artist' ),
album:
media.album || media?.meta?.album || __( 'Unknown album' ),
// Prevent using the default media attachment icon as the track image.
image:
media?.image?.src &&
media?.image?.src.endsWith( '/images/media/audio.svg' )
? ''
: media?.image?.src,
length: media.fileLength,
title: media.title,
url: media.url,
} );
},
[ setAttributes ]
);

function onSelectAlbumCoverImage( coverImage ) {
setAttributes( { image: coverImage.url } );
}

function onRemoveAlbumCoverImage() {
setAttributes( { image: undefined } );

// Move focus back to the Media Upload button.
imageButton.current.focus();
}

if ( ! id ) {
return (
<div { ...blockProps }>
<MediaPlaceholder
icon={ <BlockIcon icon={ icon } /> }
labels={ {
title: __( 'Track' ),
instructions: __(
'Upload an audio file or pick one from your media library.'
),
} }
onSelect={ onSelectTrack }
accept="audio/*"
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ attributes }
onError={ onUploadError }
/>
</div>
);
}

return (
<>
<BlockControls group="other">
<MediaReplaceFlow
name={ __( 'Replace' ) }
onSelect={ ( value ) => onSelectTrack( value ) }
accept="audio/*"
addToPlaylist
mediaIds={ id }
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ attributes }
onError={ onUploadError }
/>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Artist' ) }
value={ artist ? stripHTML( artist ) : '' }
onChange={ ( artistValue ) => {
setAttributes( { artist: artistValue } );
} }
/>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Album' ) }
value={ album ? stripHTML( album ) : '' }
onChange={ ( albumValue ) => {
setAttributes( { album: albumValue } );
} }
/>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Title' ) }
value={ title ? stripHTML( title ) : '' }
onChange={ ( titleValue ) => {
setAttributes( { title: titleValue } );
} }
/>
<MediaUploadCheck>
<div className="editor-video-poster-control">
<BaseControl.VisualLabel>
{ __( 'Album cover image' ) }
</BaseControl.VisualLabel>
{ !! image && (
<img
src={ image }
alt={ __(
'Preview of the album cover image'
) }
/>
) }
<MediaUpload
title={ __( 'Select image' ) }
onSelect={ onSelectAlbumCoverImage }
allowedTypes={ ALBUM_COVER_ALLOWED_MEDIA_TYPES }
render={ ( { open } ) => (
<Button
__next40pxDefaultSize
variant="primary"
onClick={ open }
ref={ imageButton }
>
{ ! image
? __( 'Select' )
: __( 'Replace' ) }
</Button>
) }
/>
{ !! image && (
<Button
__next40pxDefaultSize
onClick={ onRemoveAlbumCoverImage }
variant="tertiary"
>
{ __( 'Remove' ) }
</Button>
) }
</div>
</MediaUploadCheck>
</PanelBody>
</InspectorControls>
<li { ...blockProps }>
<Button
className="wp-block-playlist-track__button"
__next40pxDefaultSize
data-playlist-track-url={ url }
data-playlist-track-title={ stripHTML( title ) }
data-playlist-track-artist={ stripHTML( artist ) }
data-playlist-track-album={ stripHTML( album ) }
data-playlist-track-image-src={ image ?? null }
aria-current={ currentTrack === id ? 'true' : 'false' }
>
<RichText
tagName="span"
className="wp-block-playlist-track__title"
value={ title }
placeholder={ __( 'Add title' ) }
onChange={ ( value ) =>
setAttributes( { title: value } )
}
keepPlaceholderOnFocus
allowedFormats={ [] }
withoutInteractiveFormatting
/>
{ showArtists && (
<RichText
tagName="span"
className="wp-block-playlist-track__artist"
value={ artist }
placeholder={ __( 'Add artist' ) }
onChange={ ( value ) =>
setAttributes( { artist: value } )
}
keepPlaceholderOnFocus
allowedFormats={ [] }
withoutInteractiveFormatting
/>
) }
<span className="wp-block-playlist-track__length">
{ length && (
<span className="screen-reader-text">
{
/* translators: %s: Visually hidden label for the track length (screen reader text). */
__( 'Length:' )
}
</span>
) }
{ length }
</span>
<span className="screen-reader-text">
{ __( 'Select to play this track' ) }
</span>
</Button>
</li>
</>
);
};

export default PlaylistTrackEdit;
21 changes: 21 additions & 0 deletions packages/block-library/src/playlist-track/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* WordPress dependencies
*/
import { audio as icon } from '@wordpress/icons';

/**
* Internal dependencies
*/
import initBlock from '../utils/init-block';
import metadata from './block.json';
import edit from './edit';

const { name } = metadata;
export { metadata, name };

export const settings = {
icon,
edit,
};

export const init = () => initBlock( { name, metadata, settings } );
Loading
Loading