From 90ef8367307101d4122e1573c0e3f4bf73abfbc1 Mon Sep 17 00:00:00 2001 From: LamGC Date: Tue, 13 Oct 2026 16:41:36 +0800 Subject: [PATCH] Keep editor caption geometry stable during block selection --- .cssnanorc.json | 1 - package.json | 10 ++++++++++ scripts/package.mjs | 2 +- src/edit.js | 2 +- src/editor.css | 5 +++++ 5 files changed, 17 insertions(+), 3 deletions(-) delete mode 100644 .cssnanorc.json diff --git a/.cssnanorc.json b/.cssnanorc.json deleted file mode 100644 index e077074..0000000 --- a/.cssnanorc.json +++ /dev/null @@ -1 +0,0 @@ -{ "preset": ["default", { "discardComments": { "removeAll": false } }] } diff --git a/package.json b/package.json index ccc1b52..3347521 100644 --- a/package.json +++ b/package.json @@ -24,5 +24,15 @@ "@playwright/test": "1.64.0", "@wordpress/env": "11.17.0", "@wordpress/scripts": "36.1.0" + }, + "cssnano": { + "preset": [ + "default", + { + "discardComments": { + "removeAll": false + } + } + ] } } diff --git a/scripts/package.mjs b/scripts/package.mjs index 44e396d..c510db2 100644 --- a/scripts/package.mjs +++ b/scripts/package.mjs @@ -12,7 +12,7 @@ const readme = await readFile(path.join(root, 'readme.txt'), 'utf8'); if (!php.includes(`Version: ${pkg.version}`) || !readme.includes(`Stable tag: ${pkg.version}`)) throw new Error('Version headers disagree.'); const temp = await mkdtemp(path.join(os.tmpdir(), 'wp-asciiplayer-package-')); const target = path.join(temp, 'wp-asciiplayer'); -const inputs = ['asciicast-player.php', 'includes', 'build', 'LICENSE', 'licenses', 'THIRD-PARTY-NOTICES.md', 'README.md', 'README-zh.md', 'readme.txt', 'SOURCE.md', 'src', 'block.json', 'package.json', 'package-lock.json', 'webpack.config.cjs', '.cssnanorc.json', 'babel.config.json', 'scripts']; +const inputs = ['asciicast-player.php', 'includes', 'build', 'LICENSE', 'licenses', 'THIRD-PARTY-NOTICES.md', 'README.md', 'README-zh.md', 'readme.txt', 'SOURCE.md', 'src', 'block.json', 'package.json', 'package-lock.json', 'webpack.config.cjs', 'babel.config.json', 'scripts']; try { await mkdir(target); for (const file of inputs) await cp(path.join(root, file), path.join(target, file), { recursive: true }); diff --git a/src/edit.js b/src/edit.js index cf056d0..5fe3c68 100644 --- a/src/edit.js +++ b/src/edit.js @@ -100,7 +100,7 @@ export default function Edit( { attributes, setAttributes, isSelected } ) { { source && } ) } - { ( isSelected || caption ) && setAttributes( { caption: value } ) } placeholder={ __( 'Add a caption…', 'wp-asciiplayer' ) } aria-label={ __( 'Recording caption', 'wp-asciiplayer' ) } /> } + setAttributes( { caption: value } ) } placeholder={ __( 'Add a caption…', 'wp-asciiplayer' ) } aria-label={ __( 'Recording caption', 'wp-asciiplayer' ) } /> { approvedSource === source && source &&

{ __( 'Use the player controls to play, pause, and seek. Autoplay is disabled only in the editor.', 'wp-asciiplayer' ) }

} { [ 'height', 'both' ].includes( fit ) &&

{ __( 'Height-based previews use the shortcode’s fixed height when available, or a 320px editor frame. Published height still comes from your container style.', 'wp-asciiplayer' ) }

} diff --git a/src/editor.css b/src/editor.css index 615b9e0..e3489c3 100644 --- a/src/editor.css +++ b/src/editor.css @@ -58,3 +58,8 @@ .asciiplayer-example__terminal > span:first-child { color: #a9da76; } .asciiplayer-example__controls { padding: 8px 16px; background: #222; font: 12px/1.5 monospace; } .asciiplayer-example figcaption { padding: 8px; background: #fff; color: #333; text-align: center; font-size: 12px; } + +/* Keep an empty caption's footprint stable when another block is selected. + * Removing it on pointerdown can move the next block's button before pointerup. */ +.asciiplayer-editor .asciiplayer-figure > figcaption { min-height: 1.5em; } +.asciiplayer-editor .asciiplayer-caption-empty { visibility: hidden; }