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
4 changes: 2 additions & 2 deletions .wordpress-org/blueprints/blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"pluginData": {
"resource": "git:directory",
"url": "https://github.com/BeAPI/blockparty-button-icon",
"ref": "playground/blueprint-preview",
"refType": "branch"
"ref": "1.0.0",
"refType": "tag"
},
"options": {
"activate": true,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Be API Github Banner](.github/banner-github.png)](https://beapi.fr)

[![Test with WordPress Playground](https://img.shields.io/badge/Test%20with-WordPress%20Playground-0073aa?style=for-the-badge&logo=wordpress&logoColor=white)](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/BeAPI/blockparty-button-icon/refs/heads/playground/blueprint-preview/.wordpress-org/blueprints/blueprint.json)
[![Test with WordPress Playground](https://img.shields.io/badge/Test%20with-WordPress%20Playground-0073aa?style=for-the-badge&logo=wordpress&logoColor=white)](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/BeAPI/blockparty-button-icon/refs/heads/main/.wordpress-org/blueprints/blueprint.json)

# Blockparty Button Icon

Expand Down
1 change: 0 additions & 1 deletion build/index-rtl.css

This file was deleted.

16 changes: 0 additions & 16 deletions build/index.asset.php

This file was deleted.

1 change: 0 additions & 1 deletion build/index.css

This file was deleted.

1 change: 0 additions & 1 deletion build/index.js

This file was deleted.

1 change: 0 additions & 1 deletion build/style-index-rtl.css

This file was deleted.

1 change: 0 additions & 1 deletion build/style-index.css

This file was deleted.

7 changes: 0 additions & 7 deletions src/editor.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
$wp-block-button-icon-size: 1.25em;

.wp-block-button.blockparty-button-icon {
.wp-block-button__link {
display: inline-flex;
Expand All @@ -22,11 +20,6 @@ $wp-block-button-icon-size: 1.25em;
line-height: 0;
vertical-align: middle;
}

.block-editor-block-list__block > .wp-block-icon {
width: $wp-block-button-icon-size;
height: $wp-block-button-icon-size;
}
}

&.blockparty-button-icon--right .wp-block-button__link {
Expand Down
66 changes: 54 additions & 12 deletions src/extend-core-button/open-icon-inserter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,62 @@
import { __ } from '@wordpress/i18n';
import { dispatch } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';

const MAX_ATTEMPTS = 8;
const RETRY_DELAY_MS = 50;

/**
* Normalize toolbar button label text for comparison.
*
* @param {string} text Raw label text.
* @return {string} Normalized label.
*/
function normalizeLabel( text ) {
return text.replace( /\s+/g, ' ' ).trim().toLowerCase();
}

/**
* Labels used by core/icon to open the icon library modal.
*
* @return {Set<string>} Normalized labels.
*/
function getIconLibraryOpenLabels() {
// Match core/icon toolbar labels (default text domain).
return new Set(
[ __( 'Choose icon' ), __( 'Replace' ) ].map( normalizeLabel )
);
}

/**
* Whether a toolbar button opens the core/icon library.
*
* Must not match the parent button's text-only "Remove icon" control, which
* can still be in the DOM right after selectBlock switches to core/icon.
*
* @param {HTMLElement} button Toolbar button element.
* @return {boolean} True when the control opens the icon library.
*/
export function isIconLibraryToolbarButton( button ) {
if (
button.disabled ||
button.getAttribute( 'aria-disabled' ) === 'true'
) {
return false;
}

const text = button.textContent?.replace( /\s+/g, ' ' ).trim();
if ( ! text ) {
return false;
}

// core/icon uses a text-only control; icon-only buttons are unrelated.
if ( button.querySelector( 'svg' ) ) {
return false;
}

return getIconLibraryOpenLabels().has( normalizeLabel( text ) );
}

/**
* Clicks the core/icon toolbar control that opens the icon library modal.
*
Expand All @@ -20,18 +73,7 @@ function clickIconLibraryToolbarButton() {
);

for ( const button of buttons ) {
if (
button.disabled ||
button.getAttribute( 'aria-disabled' ) === 'true'
) {
continue;
}

const text = button.textContent?.replace( /\s+/g, ' ' ).trim();
const hasSvg = Boolean( button.querySelector( 'svg' ) );

// core/icon uses a text-only toolbar button for Choose icon / Replace.
if ( text && text.length >= 2 && ! hasSvg ) {
if ( isIconLibraryToolbarButton( button ) ) {
button.click();
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/bin/check-release-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ if [ -f .wordpress-org/blueprints/blueprint.json ]; then
echo "::error::.wordpress-org/blueprints/blueprint.json pluginData.ref must be '${NEW_VER}' (got '${BP_REF}')"
fail=1
fi

BP_REF_TYPE=$(jq -r '.steps[] | select(.pluginData) | .pluginData.refType' .wordpress-org/blueprints/blueprint.json | head -1)
if [ "$BP_REF_TYPE" != "tag" ]; then
echo "::error::.wordpress-org/blueprints/blueprint.json pluginData.refType must be 'tag' (got '${BP_REF_TYPE}')"
fail=1
fi
fi

if [ -f blockparty-button-icon.php ]; then
Expand Down
Loading
Loading