Make WordPress Core


Ignore:
Timestamp:
11/12/2018 02:26:18 AM (6 years ago)
Author:
pento
Message:

Block Editor: Update @wordpress dependencies to the latest version.

Changes of note:

  • Includes the new Annotations API package.
  • wp-polyfill-ecmascript.js is renamed to wp-polyfill.js.
  • strip_dynamic_blocks() has been removed in favour of excerpt_remove_blocks().
  • The PHP block parser is now syncing from the block-serialization-default-parser package.
  • do_blocks() uses the new parser.
  • The do_block filter has been removed from do_blocks(), in favour of a render_block filter in render_block().

See #45145, #45190, #45264, #45282.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/class-wp-block-parser.php

    r43752 r43884  
    4949    public $innerHTML;
    5050
    51     function __construct( $name, $attrs, $innerBlocks, $innerHTML ) {
     51    /**
     52     * List of string fragments and null markers where inner blocks were found
     53     *
     54     * @example array(
     55     *   'innerHTML'    => 'BeforeInnerAfter',
     56     *   'innerBlocks'  => array( block, block ),
     57     *   'innerContent' => array( 'Before', null, 'Inner', null, 'After' ),
     58     * )
     59     *
     60     * @since 4.2.0
     61     * @var array
     62     */
     63    public $innerContent;
     64
     65    function __construct( $name, $attrs, $innerBlocks, $innerHTML, $innerContent ) {
    5266        $this->blockName   = $name;
    5367        $this->attrs       = $attrs;
    5468        $this->innerBlocks = $innerBlocks;
    5569        $this->innerHTML   = $innerHTML;
     70        $this->innerContent = $innerContent;
    5671    }
    5772}
     
    160175
    161176    /**
     177     * Empty associative array, here due to PHP quirks
     178     *
     179     * @since 4.4.0
     180     * @var array empty associative array
     181     */
     182    public $empty_attrs;
     183
     184    /**
    162185     * Parses a document and returns a list of block structures
    163186     *
     
    172195     */
    173196    function parse( $document ) {
    174         $this->document = $document;
    175         $this->offset   = 0;
    176         $this->output   = array();
    177         $this->stack    = array();
     197        $this->document    = $document;
     198        $this->offset      = 0;
     199        $this->output      = array();
     200        $this->stack       = array();
     201        $this->empty_attrs = json_decode( '{}', true );
    178202
    179203        do {
     
    253277                    }
    254278
    255                     $this->output[] = (array) new WP_Block_Parser_Block( $block_name, $attrs, array(), '' );
     279                    $this->output[] = (array) new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() );
    256280                    $this->offset = $start_offset + $token_length;
    257281                    return true;
     
    260284                // otherwise we found an inner block
    261285                $this->add_inner_block(
    262                     new WP_Block_Parser_Block( $block_name, $attrs, array(), '' ),
     286                    new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ),
    263287                    $start_offset,
    264288                    $token_length
     
    270294                // track all newly-opened blocks on the stack
    271295                array_push( $this->stack, new WP_Block_Parser_Frame(
    272                     new WP_Block_Parser_Block( $block_name, $attrs, array(), '' ),
     296                    new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ),
    273297                    $start_offset,
    274298                    $token_length,
     
    307331                 */
    308332                $stack_top = array_pop( $this->stack );
    309 
    310333                $html = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );
    311                 if ( $stack_top->block->innerBlocks ) {
    312                     $stack_top->block->innerBlocks[] = (array) $this->freeform( $html );
    313                 } else {
    314                     $stack_top->block->innerHTML = $html;
    315                 }
    316 
     334                $stack_top->block->innerHTML .= $html;
     335                $stack_top->block->innerContent[] = $html;
    317336                $stack_top->prev_offset = $start_offset + $token_length;
    318337
     
    355374         */
    356375        $has_match = preg_match(
    357             '/<!--\s+(?<closer>\/)?wp:(?<namespace>[a-z][a-z0-9_-]*\/)?(?<name>[a-z][a-z0-9_-]*)\s+(?<attrs>{(?:(?!}\s+-->).)+?}\s+)?(?<void>\/)?-->/s',
     376            '/<!--\s+(?<closer>\/)?wp:(?<namespace>[a-z][a-z0-9_-]*\/)?(?<name>[a-z][a-z0-9_-]*)\s+(?<attrs>{(?:[^}]+|}+(?=})|(?!}\s+-->).)*?}\s+)?(?<void>\/)?-->/s',
    358377            $this->document,
    359378            $matches,
     
    383402        $attrs = $has_attrs
    384403            ? json_decode( $matches[ 'attrs' ][ 0 ], /* as-associative */ true )
    385             : json_decode( '{}', /* don't ask why, just verify in PHP */ false );
     404            : $this->empty_attrs;
    386405
    387406        /*
     
    413432     * @return WP_Block_Parser_Block freeform block object
    414433     */
    415     static function freeform( $innerHTML ) {
    416         return new WP_Block_Parser_Block( null, array(), array(), $innerHTML );
     434    function freeform( $innerHTML ) {
     435        return new WP_Block_Parser_Block( null, $this->empty_attrs, array(), $innerHTML, array( $innerHTML ) );
    417436    }
    418437
     
    448467    function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) {
    449468        $parent = $this->stack[ count( $this->stack ) - 1 ];
    450         $parent->block->innerBlocks[] = (array) $this->freeform( substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset ) );
    451469        $parent->block->innerBlocks[] = (array) $block;
     470        $html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );
     471
     472        if ( ! empty( $html ) ) {
     473            $parent->block->innerHTML .= $html;
     474            $parent->block->innerContent[] = $html;
     475        }
     476
     477        $parent->block->innerContent[] = null;
    452478        $parent->prev_offset = $last_offset ? $last_offset : $token_start + $token_length;
    453479    }
     
    468494            : substr( $this->document, $prev_offset );
    469495
    470         if ( $stack_top->block->innerBlocks ) {
    471             $stack_top->block->innerBlocks[] = (array) $this->freeform( $html );
    472         } else {
    473             $stack_top->block->innerHTML = $html;
     496        if ( ! empty( $html ) ) {
     497            $stack_top->block->innerHTML .= $html;
     498            $stack_top->block->innerContent[] = $html;
    474499        }
    475500
Note: See TracChangeset for help on using the changeset viewer.