From a6722097ef99620ac8652a26b79b48fc79e96f1b Mon Sep 17 00:00:00 2001 From: Jerry Jones Date: Thu, 9 Jul 2026 09:39:27 -0500 Subject: [PATCH] Move styles into specific waveform styles dropdown area --- docs/reference-guides/core-blocks/README.md | 2 +- .../src/components/block-inspector/index.js | 2 +- .../inspector-controls-tabs/styles-tab.js | 2 +- packages/block-library/src/playlist/README.md | 16 +----- .../block-library/src/playlist/block.json | 13 ++--- packages/block-library/src/playlist/edit.js | 57 ++++++++++++++++++- packages/block-library/src/playlist/index.php | 7 +-- phpunit/blocks/render-block-playlist-test.php | 16 ++---- 8 files changed, 72 insertions(+), 43 deletions(-) diff --git a/docs/reference-guides/core-blocks/README.md b/docs/reference-guides/core-blocks/README.md index d0cbbf6858e0e3..52241b671c5405 100644 --- a/docs/reference-guides/core-blocks/README.md +++ b/docs/reference-guides/core-blocks/README.md @@ -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 diff --git a/packages/block-editor/src/components/block-inspector/index.js b/packages/block-editor/src/components/block-inspector/index.js index 4a61c045bbe3c2..23741a0f93d5e5 100644 --- a/packages/block-editor/src/components/block-inspector/index.js +++ b/packages/block-editor/src/components/block-inspector/index.js @@ -70,6 +70,7 @@ function StyleInspectorSlots( { label={ __( 'Background' ) } className="background-block-support-panel__inner-wrapper" /> + { showPositionControls && } - { showBindingsControls && ( ) } diff --git a/packages/block-editor/src/components/inspector-controls-tabs/styles-tab.js b/packages/block-editor/src/components/inspector-controls-tabs/styles-tab.js index b691b3ff08eead..d56079dc57ed8a 100644 --- a/packages/block-editor/src/components/inspector-controls-tabs/styles-tab.js +++ b/packages/block-editor/src/components/inspector-controls-tabs/styles-tab.js @@ -140,6 +140,7 @@ const StylesTab = ( { label={ __( 'Background' ) } className="background-block-support-panel__inner-wrapper" /> + - ) } diff --git a/packages/block-library/src/playlist/README.md b/packages/block-library/src/playlist/README.md index 5657c0052938e1..b1182ddd4490f9 100644 --- a/packages/block-library/src/playlist/README.md +++ b/packages/block-library/src/playlist/README.md @@ -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 @@ -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 - + ``` diff --git a/packages/block-library/src/playlist/block.json b/packages/block-library/src/playlist/block.json index fa806140209dee..ea9cc974b48952 100644 --- a/packages/block-library/src/playlist/block.json +++ b/packages/block-library/src/playlist/block.json @@ -38,6 +38,11 @@ "type": "boolean", "default": true }, + "waveformStyle": { + "type": "string", + "enum": [ "bars", "mirror", "line", "blocks", "dots", "seekbar" ], + "default": "bars" + }, "caption": { "type": "string" } @@ -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" } diff --git a/packages/block-library/src/playlist/edit.js b/packages/block-library/src/playlist/edit.js index 054b7577914a52..b464790a1a9264 100644 --- a/packages/block-library/src/playlist/edit.js +++ b/packages/block-library/src/playlist/edit.js @@ -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' }, +]; const PlaylistEdit = ( { attributes, @@ -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(); @@ -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 ), @@ -358,6 +378,37 @@ const PlaylistEdit = ( { + + { + setAttributes( { + waveformStyle: undefined, + } ); + } } + panelId={ waveformPanelId } + dropdownMenuProps={ dropdownMenuProps } + > + + waveformStyle !== DEFAULT_WAVEFORM_STYLE + } + onDeselect={ () => + onChangeWaveformStyle( DEFAULT_WAVEFORM_STYLE ) + } + panelId={ waveformPanelId } + > + + + +
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', diff --git a/phpunit/blocks/render-block-playlist-test.php b/phpunit/blocks/render-block-playlist-test.php index 38aab5107d27c7..8fdc46102fc147 100644 --- a/phpunit/blocks/render-block-playlist-test.php +++ b/phpunit/blocks/render-block-playlist-test.php @@ -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( @@ -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( @@ -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'] ); } /**