mirror of
https://github.com/LamGC/wp-asciiplayer.git
synced 2026-11-26 20:55:48 +00:00
Build and WordPress integration / PHP 7.4 syntax and regression tests (push) Canceled after 0s
Build and WordPress integration / PHP 8.3 syntax and regression tests (push) Canceled after 0s
Build and WordPress integration / WordPress 6.3 / PHP 7.4 (push) Canceled after 0s
Build and WordPress integration / WordPress latest / PHP 8.2 (push) Canceled after 0s
* Refresh player with native block editor preview and local assets Preserve shortcode rendering, normalize options, bundle the player locally, and add reproducible packaging and WordPress integration tests. * Fix emitted frontend boot and verify bundled runtime initialization * Record verified WordPress 7.1.3 compatibility * Use WordPress readme major-version compatibility format * Add responsive player layout, captions and native terminal sizing * Keep editor caption geometry stable during block selection * Respect WordPress editor gutters with border-box sizing * Improve automatic previews and toolbar terminal sizing (1.2.1) * Show native cast dimensions and add Media Library recordings (1.2.2) * Fix Media Library test storage and scope sidebar selectors * Document bounded temporary-upload stream exceptions * Move block explanations into collapsed sidebar help (1.2.3) * Add bundled English and Simplified Chinese UI translations (1.1.0-dev) * Use native RichText labels and supported Chinese HTML language tags in locale tests
47 lines
1.9 KiB
JavaScript
47 lines
1.9 KiB
JavaScript
import { createBlock, registerBlockType } from '@wordpress/blocks';
|
|
import { next } from '@wordpress/shortcode';
|
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
import metadata from '../block.json';
|
|
import { _x } from '@wordpress/i18n';
|
|
import Edit from './edit.js';
|
|
import { attributesFromShortcode, canTransformShortcode, normalizeSource } from './options.js';
|
|
import './style.css';
|
|
import './editor.css';
|
|
|
|
function matchShortcodeBlock( text = '' ) {
|
|
const match = next( 'asciiplayer', text );
|
|
return match && text.trim() === match.content.trim() && canTransformShortcode( match.shortcode.attrs ) && normalizeSource( decodeEntities( match.shortcode.content ) ) ? match : null;
|
|
}
|
|
|
|
registerBlockType( metadata.name, {
|
|
...metadata,
|
|
title: _x( 'Asciicast Player', 'block title', 'wp-asciiplayer' ),
|
|
description: _x( 'Embed and preview a terminal recording with the locally bundled asciinema player.', 'block description', 'wp-asciiplayer' ),
|
|
keywords: [ _x( 'asciinema', 'block keyword', 'wp-asciiplayer' ), _x( 'terminal', 'block keyword', 'wp-asciiplayer' ), _x( 'recording', 'block keyword', 'wp-asciiplayer' ) ],
|
|
edit: Edit,
|
|
save: () => null,
|
|
transforms: {
|
|
from: [
|
|
{
|
|
type: 'shortcode',
|
|
tag: 'asciiplayer',
|
|
isMatch: canTransformShortcode,
|
|
transform: ( { named }, match ) => {
|
|
const source = decodeEntities( match.shortcode.content || '' );
|
|
if ( ! normalizeSource( source ) ) return createBlock( 'core/shortcode', { text: match.content } );
|
|
return createBlock( metadata.name, attributesFromShortcode( named, source ) );
|
|
},
|
|
},
|
|
{
|
|
type: 'block',
|
|
blocks: [ 'core/shortcode' ],
|
|
isMatch: ( { text } ) => Boolean( matchShortcodeBlock( text ) ),
|
|
transform: ( { text } ) => {
|
|
const match = matchShortcodeBlock( text );
|
|
return createBlock( metadata.name, attributesFromShortcode( match.shortcode.attrs.named, decodeEntities( match.shortcode.content ) ) );
|
|
},
|
|
},
|
|
],
|
|
},
|
|
} );
|