diff --git a/inc/functions.php b/inc/functions.php index 2b32c6f4..6ef16ffb 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -210,22 +210,8 @@ function init(): void { if ( $block instanceof WP_Block_Type ) { register_editor_assets( $block ); - - if ( property_exists( $block, 'editor_script_handles' ) ) { - // As of WP>=6.1. - $block->editor_script_handles[] = EDITOR_SCRIPT_HANDLE; - } else { - /* @noinspection PhpUndefinedFieldInspection */ - $block->editor_script = EDITOR_SCRIPT_HANDLE; - } - - if ( property_exists( $block, 'editor_style_handles' ) ) { - // As of WP>=6.1. - $block->editor_style_handles[] = EDITOR_STYLE_HANDLE; - } else { - /* @noinspection PhpUndefinedFieldInspection */ - $block->editor_style = EDITOR_STYLE_HANDLE; - } + $block->editor_script_handles[] = EDITOR_SCRIPT_HANDLE; + $block->editor_style_handles[] = EDITOR_STYLE_HANDLE; } } diff --git a/package-lock.json b/package-lock.json index 23b3a48f..d60a60bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "devDependencies": { "@wordpress/api-fetch": "6.43.0", "@wordpress/block-editor": "12.14.0", + "@wordpress/blocks": "12.23.0", "@wordpress/components": "25.12.0", "@wordpress/editor": "13.23.0", "@wordpress/element": "5.23.0", @@ -6729,10 +6730,10 @@ "@wordpress/data": "^9.16.0", "@wordpress/deprecated": "^3.46.0", "@wordpress/dom": "^3.46.0", - "@wordpress/element": "5.23.0", - "@wordpress/hooks": "3.46.0", + "@wordpress/element": "^5.23.0", + "@wordpress/hooks": "^3.46.0", "@wordpress/html-entities": "^3.46.0", - "@wordpress/i18n": "4.46.0", + "@wordpress/i18n": "^4.46.0", "@wordpress/is-shallow-equal": "^4.46.0", "@wordpress/private-apis": "^0.28.0", "@wordpress/shortcode": "^3.46.0", diff --git a/package.json b/package.json index defddbf8..fbb25d53 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "devDependencies": { "@wordpress/api-fetch": "6.43.0", "@wordpress/block-editor": "12.14.0", + "@wordpress/blocks": "12.23.0", "@wordpress/components": "25.12.0", "@wordpress/editor": "13.23.0", "@wordpress/element": "5.23.0", diff --git a/phpstan-baseline.php b/phpstan-baseline.php deleted file mode 100644 index 7fc00531..00000000 --- a/phpstan-baseline.php +++ /dev/null @@ -1,27 +0,0 @@ - '#^Access to an undefined property WP_Block_Type\\:\\:\\$editor_script\\.$#', - 'count' => 1, - 'path' => '*', // Originally `__DIR__ . '/syntax-highlighting-code-block.php'`, but see https://youtrack.jetbrains.com/issue/WI-63891/PHPStan-ignoreErrors-configuration-isnt-working-with-inspections#focus=Comments-27-6188783.0-0 -]; -$ignoreErrors[] = [ - 'message' => '#^Access to an undefined property WP_Block_Type\\:\\:\\$editor_style\\.$#', - 'count' => 1, - 'path' => '*', -]; - -// See . -$ignoreErrors[] = [ - 'message' => '#^Call to function property_exists\\(\\) with WP_Block_Type and \'editor_script…\' will always evaluate to true\\.$#', - 'count' => 1, - 'path' => '*', -]; -$ignoreErrors[] = [ - 'message' => '#^Call to function property_exists\\(\\) with WP_Block_Type and \'editor_style_handles\' will always evaluate to true\\.$#', - 'count' => 1, - 'path' => '*', -]; - -return [ 'parameters' => [ 'ignoreErrors' => $ignoreErrors ] ]; diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 6d2268b4..d2850281 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,7 +2,6 @@ includes: # @see https://github.com/phpstan/phpstan-src/blob/b9f62d63f2deaa0a5e97f51073e41a422c48aa01/conf/bleedingEdge.neon - phar://phpstan.phar/conf/bleedingEdge.neon - vendor/szepeviktor/phpstan-wordpress/extension.neon - - phpstan-baseline.php parameters: level: 9 paths: diff --git a/src/edit.js b/src/edit.js index af73843a..661dcd62 100644 --- a/src/edit.js +++ b/src/edit.js @@ -18,6 +18,7 @@ import { PanelBody, PanelRow, } from '@wordpress/components'; +import { createBlock, getDefaultBlockName } from '@wordpress/blocks'; /** * External dependencies @@ -110,7 +111,13 @@ const parseHighlightedLines = (highlightedLines) => { return highlightedLinesSet; }; -export default function CodeEdit({ attributes, setAttributes, onRemove }) { +export default function CodeEdit({ + attributes, + setAttributes, + onRemove, + insertBlocksAfter, + mergeBlocks, +}) { const blockProps = useBlockProps(); const updateLanguage = (language) => { @@ -138,16 +145,21 @@ export default function CodeEdit({ attributes, setAttributes, onRemove }) { ); const richTextProps = { - // These RichText props must mirror core . + // These RichText props must mirror core . ...{ tagName: 'code', + identifier: 'content', value: attributes.content, onChange: (content) => setAttributes({ content }), onRemove, + onMerge: mergeBlocks, placeholder: __('Write code…'), 'aria-label': __('Code'), preserveWhiteSpace: true, __unstablePastePlainText: true, // See . + __unstableOnSplitAtDoubleLineEnd: () => { + insertBlocksAfter(createBlock(getDefaultBlockName())); + }, }, // Additional props unique to HighlightableTextArea. @@ -231,7 +243,7 @@ export default function CodeEdit({ attributes, setAttributes, onRemove }) { - {/* Keep in sync with https://github.com/WordPress/gutenberg/blob/a42fd75/packages/block-library/src/code/edit.js#L10-L21 */} + {/* Keep in sync with https://github.com/WordPress/gutenberg/blob/e95bb8c9530bbdef1db623eca11b80bd73493197/packages/block-library/src/code/edit.js#L17 */}