Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ Embed a simple playlist.
- **Category:** [media](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-media/)
- **Allowed Blocks:** core/playlist-track
- **Supports:** align, anchor, color (background, gradients, link, text), interactivity, spacing (margin, padding)
- **Attributes:** caption, order, showArtists, showImages, showNumbers, showTrackLength, showTracklist, type
- **Attributes:** caption, order, showArtists, showImages, showNumbers, showTrackLength, showTracklist, type, waveformStyle

## Playlist track

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function StyleInspectorSlots( {
label={ __( 'Background' ) }
className="background-block-support-panel__inner-wrapper"
/>
<InspectorControls.Slot group="styles" />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will affect all consumers using this slot group, won't it? Why is this reordering necessary?

By the way, for all block-specific settings, we use a panel labeled "Settings".

See: #67813

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't have been there. Thanks for catching!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in #80111

<InspectorControls.Slot group="layout" label={ __( 'Layout' ) } />
<InspectorControls.Slot
group="dimensions"
Expand All @@ -82,7 +83,6 @@ function StyleInspectorSlots( {
className="elements-block-support-panel__inner-wrapper"
/>
{ showPositionControls && <PositionControls /> }
<InspectorControls.Slot group="styles" />
{ showBindingsControls && (
<InspectorControls.Slot group="bindings" />
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const StylesTab = ( {
label={ __( 'Background' ) }
className="background-block-support-panel__inner-wrapper"
/>
<InspectorControls.Slot group="styles" />

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in #80111

<InspectorControls.Slot group="filter" />
<InspectorControls.Slot
group="layout"
Expand All @@ -159,7 +160,6 @@ const StylesTab = ( {
className="elements-block-support-panel__inner-wrapper"
/>
<PositionControls />
<InspectorControls.Slot group="styles" />
</>
) }
</>
Expand Down
16 changes: 2 additions & 14 deletions packages/block-library/src/playlist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ _Defined via the [`attributes`](https://developer.wordpress.org/block-editor/ref
| `showArtists` | `boolean` | `true` | — |
| `showNumbers` | `boolean` | `true` | — |
| `showTrackLength` | `boolean` | `true` | — |
| `waveformStyle` | `string` | `"bars"` | [Enum](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#enum-validation): `bars`, `mirror`, `line`, `blocks`, `dots`, `seekbar` |
| `caption` | `string` | — | — |

## Supports
Expand All @@ -54,25 +55,12 @@ _Defined via the [`usesContext` and `providesContext`](https://developer.wordpre
- `showArtists` → attribute `showArtists`
- `showImages` → attribute `showImages`

## Block Styles

_Defined via the [`styles`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-styles/) property in block.json._

| Style Name | Label | Default |
|------------|-------|---------|
| `bars` | Bars | Yes |
| `mirror` | Mirror | No |
| `line` | Line | No |
| `blocks` | Blocks | No |
| `dots` | Dots | No |
| `seekbar` | Seekbar | No |

## Block Markup

This is a [**hybrid block**](https://developer.wordpress.org/block-editor/getting-started/fundamentals/static-dynamic-rendering/). It saves static markup that the server may enhance during rendering.

```html
<!-- wp:playlist {"type":"audio","order":"asc","showTracklist":true,"showImages":true,"showArtists":true,"showNumbers":true,"showTrackLength":true} -->
<!-- wp:playlist {"type":"audio","order":"asc","showTracklist":true,"showImages":true,"showArtists":true,"showNumbers":true,"showTrackLength":true,"waveformStyle":"bars"} -->
<!-- Content... -->
<!-- /wp:playlist -->
```
Expand Down
13 changes: 5 additions & 8 deletions packages/block-library/src/playlist/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
"type": "boolean",
"default": true
},
"waveformStyle": {
"type": "string",
"enum": [ "bars", "mirror", "line", "blocks", "dots", "seekbar" ],
"default": "bars"
},
"caption": {
"type": "string"
}
Expand Down Expand Up @@ -73,14 +78,6 @@
"padding": true
}
},
"styles": [
{ "name": "bars", "label": "Bars", "isDefault": true },
{ "name": "mirror", "label": "Mirror" },
{ "name": "line", "label": "Line" },
{ "name": "blocks", "label": "Blocks" },
{ "name": "dots", "label": "Dots" },
{ "name": "seekbar", "label": "Seekbar" }
],
"editorStyle": "wp-block-playlist-editor",
"style": "wp-block-playlist"
}
57 changes: 54 additions & 3 deletions packages/block-library/src/playlist/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ import { PlaylistContext } from './context';
import { getTrackAttributes } from './utils';

const ALLOWED_MEDIA_TYPES = [ 'audio' ];
const DEFAULT_WAVEFORM_STYLE = 'bars';
const WAVEFORM_STYLE_OPTIONS = [
{ label: __( 'Bars' ), value: 'bars' },
{ label: __( 'Mirror' ), value: 'mirror' },
{ label: __( 'Line' ), value: 'line' },
{ label: __( 'Blocks' ), value: 'blocks' },
{ label: __( 'Dots' ), value: 'dots' },
{ label: __( 'Seekbar' ), value: 'seekbar' },
];
Comment on lines +45 to +52

@t-hamano t-hamano Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not immediately clear what these terms refer to, so I think we need to add a translation context.


const PlaylistEdit = ( {
attributes,
Expand All @@ -56,12 +65,11 @@ const PlaylistEdit = ( {
showImages,
showArtists,
showTrackLength,
waveformStyle = DEFAULT_WAVEFORM_STYLE,
} = attributes;

// Extract the waveform style from the block style variation class.
const waveformStyle =
attributes.className?.match( /is-style-([\w-]+)/ )?.[ 1 ] || 'bars';
const blockProps = useBlockProps();
const waveformPanelId = `${ clientId }-waveform`;
const { replaceInnerBlocks } = useDispatch( blockEditorStore );
const { createErrorNotice } = useDispatch( noticesStore );
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
Expand Down Expand Up @@ -189,6 +197,18 @@ const PlaylistEdit = ( {
};
}

const onChangeWaveformStyle = useCallback(
( newWaveformStyle ) => {
setAttributes( {
waveformStyle:
newWaveformStyle === DEFAULT_WAVEFORM_STYLE
? undefined
: newWaveformStyle,
} );
},
[ setAttributes ]
);

const hasSelectedChild = useSelect(
( select ) =>
select( blockEditorStore ).hasSelectedInnerBlock( clientId ),
Expand Down Expand Up @@ -358,6 +378,37 @@ const PlaylistEdit = ( {
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>
<InspectorControls group="styles">
<ToolsPanel
label={ __( 'Waveform' ) }
resetAll={ () => {
setAttributes( {
waveformStyle: undefined,
} );
} }
panelId={ waveformPanelId }
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
label={ __( 'Shape' ) }
isShownByDefault
hasValue={ () =>
waveformStyle !== DEFAULT_WAVEFORM_STYLE
}
onDeselect={ () =>
onChangeWaveformStyle( DEFAULT_WAVEFORM_STYLE )
}
panelId={ waveformPanelId }
>
<SelectControl
label={ __( 'Shape' ) }
value={ waveformStyle }
options={ WAVEFORM_STYLE_OPTIONS }
onChange={ onChangeWaveformStyle }
/>
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>
<figure { ...blockProps }>
<Disabled isDisabled={ ! isSelected }>
<WaveformPlayer
Expand Down
7 changes: 2 additions & 5 deletions packages/block-library/src/playlist/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,8 @@ function render_block_core_playlist( $attributes, $content, $block ) {
$processor = new WP_HTML_Tag_Processor( $content );
$processor->next_tag( 'figure' );
$processor->set_attribute( 'data-wp-interactive', 'core/playlist' );
// Extract the waveform style from the block style variation class.
$waveform_style = 'bars';
if ( ! empty( $attributes['className'] ) && preg_match( '/is-style-([\w-]+)/', $attributes['className'], $matches ) ) {
$waveform_style = $matches[1];
}

$waveform_style = $attributes['waveformStyle'] ?? 'bars';

$processor->set_attribute(
'data-wp-context',
Expand Down
16 changes: 6 additions & 10 deletions phpunit/blocks/render-block-playlist-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ public function test_renders_waveform_player_container() {
/**
* @covers ::render_block_core_playlist
*/
public function test_waveform_style_extracted_from_single_word_style_class() {
public function test_waveform_style_uses_attribute() {
$markup = $this->build_playlist_markup(
array(
'className' => 'is-style-mirror',
'waveformStyle' => 'dots',
),
array(
array(
Expand All @@ -175,20 +175,16 @@ public function test_waveform_style_extracted_from_single_word_style_class() {
$p->next_tag( 'figure' );

$context = json_decode( $p->get_attribute( 'data-wp-context' ), true );
$this->assertSame( 'mirror', $context['waveformStyle'] );
$this->assertSame( 'dots', $context['waveformStyle'] );
}

/**
* A hyphenated block style slug (e.g. one registered by a theme) must be
* extracted in full. The `\w+` pattern stops at the first hyphen and would
* yield 'thin' instead of 'thin-line'.
*
* @covers ::render_block_core_playlist
*/
public function test_waveform_style_extracted_from_hyphenated_style_class() {
public function test_waveform_style_defaults_to_bars_for_invalid_attribute() {
$markup = $this->build_playlist_markup(
array(
'className' => 'is-style-thin-line',
'waveformStyle' => 'thin-line',
),
array(
array(
Expand All @@ -204,7 +200,7 @@ public function test_waveform_style_extracted_from_hyphenated_style_class() {
$p->next_tag( 'figure' );

$context = json_decode( $p->get_attribute( 'data-wp-context' ), true );
$this->assertSame( 'thin-line', $context['waveformStyle'] );
$this->assertSame( 'bars', $context['waveformStyle'] );
}

/**
Expand Down
Loading