Make WordPress Core


Ignore:
Timestamp:
01/04/2019 08:18:09 PM (4 years ago)
Author:
desrosj
Message:

Block Editor: Upgrade @WordPress packages to the latest versions.

Updated packages:

  • @wordpress/annotations@1.0.5
  • @wordpress/api-fetch@2.2.7
  • @wordpress/block-library@2.2.12
  • @wordpress/block-serialization-default-parser@2.0.3
  • @wordpress/blocks@6.0.5
  • @wordpress/components@7.0.5
  • @wordpress/core-data@2.0.16
  • @wordpress/data@4.2.0
  • @wordpress/deprecated@2.0.4
  • @wordpress/dom@2.0.8
  • @wordpress/edit-post@3.1.7
  • @wordpress/editor@9.0.7
  • @wordpress/format-library@1.2.10
  • @wordpress/hooks@2.0.4
  • @wordpress/list-reusable-blocks@1.1.18
  • @wordpress/notices@1.1.2
  • @wordpress/nux@3.0.6
  • @wordpress/plugins@2.0.10
  • @wordpress/rich-text@3.0.4
  • @wordpress/url@2.3.3
  • @wordpress/viewport@2.1.0

Props: youknowriad, gziolo, desrosj.

Merges [44389] to the 5.0 branch.
Fixes #45814.

Location:
branches/5.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0

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

    r43955 r44390  
    11<?php
     2/**
     3 * Block Serialization Parser
     4 *
     5 * @package WordPress
     6 */
    27
    38/**
     
    6368    public $innerContent;
    6469
     70    /**
     71     * Constructor.
     72     *
     73     * Will populate object properties from the provided arguments.
     74     *
     75     * @since 3.8.0
     76     *
     77     * @param string $name         Name of block.
     78     * @param array  $attrs        Optional set of attributes from block comment delimiters.
     79     * @param array  $innerBlocks  List of inner blocks (of this same class).
     80     * @param string $innerHTML    Resultant HTML from inside block comment delimiters after removing inner blocks.
     81     * @param array  $innerContent List of string fragments and null markers where inner blocks were found.
     82     */
    6583    function __construct( $name, $attrs, $innerBlocks, $innerHTML, $innerContent ) {
    66         $this->blockName   = $name;
    67         $this->attrs       = $attrs;
    68         $this->innerBlocks = $innerBlocks;
    69         $this->innerHTML   = $innerHTML;
     84        $this->blockName    = $name;
     85        $this->attrs        = $attrs;
     86        $this->innerBlocks  = $innerBlocks;
     87        $this->innerHTML    = $innerHTML;
    7088        $this->innerContent = $innerContent;
    7189    }
     
    122140    public $leading_html_start;
    123141
     142    /**
     143     * Constructor
     144     *
     145     * Will populate object properties from the provided arguments.
     146     *
     147     * @since 3.8.0
     148     *
     149     * @param WP_Block_Parser_Block $block              Full or partial block.
     150     * @param int                   $token_start        Byte offset into document for start of parse token.
     151     * @param int                   $token_length       Byte length of entire parse token string.
     152     * @param int                   $prev_offset        Byte offset into document for after parse token ends.
     153     * @param int                   $leading_html_start Byte offset into document where leading HTML before token starts.
     154     */
    124155    function __construct( $block, $token_start, $token_length, $prev_offset = null, $leading_html_start = null ) {
    125156        $this->block              = $block;
     
    191222     * @since 3.8.0
    192223     *
    193      * @param string $document
     224     * @param string $document Input document being parsed.
    194225     * @return WP_Block_Parser_Block[]
    195226     */
     
    202233
    203234        do {
    204             // twiddle our thumbs
     235            // twiddle our thumbs.
    205236        } while ( $this->proceed() );
    206237
     
    227258        $stack_depth = count( $this->stack );
    228259
    229         // we may have some HTML soup before the next block
     260        // we may have some HTML soup before the next block.
    230261        $leading_html_start = $start_offset > $this->offset ? $this->offset : null;
    231262
    232263        switch ( $token_type ) {
    233264            case 'no-more-tokens':
    234                 // if not in a block then flush output
     265                // if not in a block then flush output.
    235266                if ( 0 === $stack_depth ) {
    236267                    $this->add_freeform();
     
    247278                 */
    248279
    249                 // for the easy case we'll assume an implicit closer
     280                // for the easy case we'll assume an implicit closer.
    250281                if ( 1 === $stack_depth ) {
    251282                    $this->add_block_from_stack();
     
    270301                if ( 0 === $stack_depth ) {
    271302                    if ( isset( $leading_html_start ) ) {
    272                         $this->output[] = (array) self::freeform( substr(
    273                             $this->document,
    274                             $leading_html_start,
    275                             $start_offset - $leading_html_start
    276                         ) );
     303                        $this->output[] = (array) self::freeform(
     304                            substr(
     305                                $this->document,
     306                                $leading_html_start,
     307                                $start_offset - $leading_html_start
     308                            )
     309                        );
    277310                    }
    278311
    279312                    $this->output[] = (array) new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() );
    280                     $this->offset = $start_offset + $token_length;
     313                    $this->offset   = $start_offset + $token_length;
    281314                    return true;
    282315                }
    283316
    284                 // otherwise we found an inner block
     317                // otherwise we found an inner block.
    285318                $this->add_inner_block(
    286319                    new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ),
     
    292325
    293326            case 'block-opener':
    294                 // track all newly-opened blocks on the stack
    295                 array_push( $this->stack, new WP_Block_Parser_Frame(
    296                     new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ),
    297                     $start_offset,
    298                     $token_length,
    299                     $start_offset + $token_length,
    300                     $leading_html_start
    301                 ) );
     327                // track all newly-opened blocks on the stack.
     328                array_push(
     329                    $this->stack,
     330                    new WP_Block_Parser_Frame(
     331                        new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ),
     332                        $start_offset,
     333                        $token_length,
     334                        $start_offset + $token_length,
     335                        $leading_html_start
     336                    )
     337                );
    302338                $this->offset = $start_offset + $token_length;
    303339                return true;
     
    319355                }
    320356
    321                 // if we're not nesting then this is easy - close the block
     357                // if we're not nesting then this is easy - close the block.
    322358                if ( 1 === $stack_depth ) {
    323359                    $this->add_block_from_stack( $start_offset );
     
    330366                 * block and add it as a new innerBlock to the parent
    331367                 */
    332                 $stack_top = array_pop( $this->stack );
    333                 $html = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );
    334                 $stack_top->block->innerHTML .= $html;
     368                $stack_top                        = array_pop( $this->stack );
     369                $html                             = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );
     370                $stack_top->block->innerHTML     .= $html;
    335371                $stack_top->block->innerContent[] = $html;
    336                 $stack_top->prev_offset = $start_offset + $token_length;
     372                $stack_top->prev_offset           = $start_offset + $token_length;
    337373
    338374                $this->add_inner_block(
     
    346382
    347383            default:
    348                 // This is an error
     384                // This is an error.
    349385                $this->add_freeform();
    350386                return false;
     
    382418        );
    383419
    384         // if we get here we probably have catastrophic backtracking or out-of-memory in the PCRE
     420        // if we get here we probably have catastrophic backtracking or out-of-memory in the PCRE.
    385421        if ( false === $has_match ) {
    386422            return array( 'no-more-tokens', null, null, null, null );
    387423        }
    388424
    389         // we have no more tokens
     425        // we have no more tokens.
    390426        if ( 0 === $has_match ) {
    391427            return array( 'no-more-tokens', null, null, null, null );
    392428        }
    393429
    394         list( $match, $started_at ) = $matches[ 0 ];
     430        list( $match, $started_at ) = $matches[0];
    395431
    396432        $length    = strlen( $match );
    397         $is_closer = isset( $matches[ 'closer' ] ) && -1 !== $matches[ 'closer' ][ 1 ];
    398         $is_void   = isset( $matches[ 'void' ] ) && -1 !== $matches[ 'void' ][ 1 ];
    399         $namespace = $matches[ 'namespace' ];
    400         $namespace = ( isset( $namespace ) && -1 !== $namespace[ 1 ] ) ? $namespace[ 0 ] : 'core/';
    401         $name      = $namespace . $matches[ 'name' ][ 0 ];
    402         $has_attrs = isset( $matches[ 'attrs' ] ) && -1 !== $matches[ 'attrs' ][ 1 ];
     433        $is_closer = isset( $matches['closer'] ) && -1 !== $matches['closer'][1];
     434        $is_void   = isset( $matches['void'] ) && -1 !== $matches['void'][1];
     435        $namespace = $matches['namespace'];
     436        $namespace = ( isset( $namespace ) && -1 !== $namespace[1] ) ? $namespace[0] : 'core/';
     437        $name      = $namespace . $matches['name'][0];
     438        $has_attrs = isset( $matches['attrs'] ) && -1 !== $matches['attrs'][1];
    403439
    404440        /*
     
    407443         */
    408444        $attrs = $has_attrs
    409             ? json_decode( $matches[ 'attrs' ][ 0 ], /* as-associative */ true )
     445            ? json_decode( $matches['attrs'][0], /* as-associative */ true )
    410446            : $this->empty_attrs;
    411447
     
    415451         */
    416452        if ( $is_closer && ( $is_void || $has_attrs ) ) {
    417             // we can ignore them since they don't hurt anything
     453            // we can ignore them since they don't hurt anything.
    418454        }
    419455
     
    435471     * @since 3.9.0
    436472     *
    437      * @param string $innerHTML HTML content of block
    438      * @return WP_Block_Parser_Block freeform block object
     473     * @param string $innerHTML HTML content of block.
     474     * @return WP_Block_Parser_Block freeform block object.
    439475     */
    440476    function freeform( $innerHTML ) {
     
    444480    /**
    445481     * Pushes a length of text from the input document
    446      * to the output list as a freeform block
     482     * to the output list as a freeform block.
    447483     *
    448484     * @internal
    449485     * @since 3.8.0
    450      * @param null $length how many bytes of document text to output
     486     * @param null $length how many bytes of document text to output.
    451487     */
    452488    function add_freeform( $length = null ) {
     
    462498    /**
    463499     * Given a block structure from memory pushes
    464      * a new block to the output list
     500     * a new block to the output list.
    465501     *
    466502     * @internal
    467503     * @since 3.8.0
    468      * @param WP_Block_Parser_Block $block the block to add to the output
    469      * @param int $token_start byte offset into the document where the first token for the block starts
    470      * @param int $token_length byte length of entire block from start of opening token to end of closing token
    471      * @param int|null $last_offset last byte offset into document if continuing form earlier output
     504     * @param WP_Block_Parser_Block $block        The block to add to the output.
     505     * @param int                   $token_start  Byte offset into the document where the first token for the block starts.
     506     * @param int                   $token_length Byte length of entire block from start of opening token to end of closing token.
     507     * @param int|null              $last_offset  Last byte offset into document if continuing form earlier output.
    472508     */
    473509    function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) {
    474         $parent = $this->stack[ count( $this->stack ) - 1 ];
     510        $parent                       = $this->stack[ count( $this->stack ) - 1 ];
    475511        $parent->block->innerBlocks[] = (array) $block;
    476         $html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );
     512        $html                         = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );
    477513
    478514        if ( ! empty( $html ) ) {
    479             $parent->block->innerHTML .= $html;
     515            $parent->block->innerHTML     .= $html;
    480516            $parent->block->innerContent[] = $html;
    481517        }
    482518
    483519        $parent->block->innerContent[] = null;
    484         $parent->prev_offset = $last_offset ? $last_offset : $token_start + $token_length;
    485     }
    486 
    487     /**
    488      * Pushes the top block from the parsing stack to the output list
     520        $parent->prev_offset           = $last_offset ? $last_offset : $token_start + $token_length;
     521    }
     522
     523    /**
     524     * Pushes the top block from the parsing stack to the output list.
    489525     *
    490526     * @internal
    491527     * @since 3.8.0
    492      * @param int|null $end_offset byte offset into document for where we should stop sending text output as HTML
     528     * @param int|null $end_offset byte offset into document for where we should stop sending text output as HTML.
    493529     */
    494530    function add_block_from_stack( $end_offset = null ) {
     
    501537
    502538        if ( ! empty( $html ) ) {
    503             $stack_top->block->innerHTML .= $html;
     539            $stack_top->block->innerHTML     .= $html;
    504540            $stack_top->block->innerContent[] = $html;
    505541        }
    506542
    507543        if ( isset( $stack_top->leading_html_start ) ) {
    508             $this->output[] = (array) self::freeform( substr(
    509                 $this->document,
    510                 $stack_top->leading_html_start,
    511                 $stack_top->token_start - $stack_top->leading_html_start
    512             ) );
     544            $this->output[] = (array) self::freeform(
     545                substr(
     546                    $this->document,
     547                    $stack_top->leading_html_start,
     548                    $stack_top->token_start - $stack_top->leading_html_start
     549                )
     550            );
    513551        }
    514552
Note: See TracChangeset for help on using the changeset viewer.