diff --git a/packages/blocks/src/api/raw-handling/figure-content-reducer.js b/packages/blocks/src/api/raw-handling/figure-content-reducer.js index 47144bc9b4311..4dfb24f2c9781 100644 --- a/packages/blocks/src/api/raw-handling/figure-content-reducer.js +++ b/packages/blocks/src/api/raw-handling/figure-content-reducer.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { has } from 'lodash'; - /** * WordPress dependencies */ @@ -25,7 +20,7 @@ function isFigureContent( node, schema ) { return false; } - return has( schema, [ 'figure', 'children', tag ] ); + return tag in ( schema?.figure?.children ?? {} ); } /** @@ -39,7 +34,7 @@ function isFigureContent( node, schema ) { function canHaveAnchor( node, schema ) { const tag = node.nodeName.toLowerCase(); - return has( schema, [ 'figure', 'children', 'a', 'children', tag ] ); + return tag in ( schema?.figure?.children?.a?.children ?? {} ); } /** diff --git a/packages/blocks/src/api/raw-handling/get-raw-transforms.js b/packages/blocks/src/api/raw-handling/get-raw-transforms.js index cc7d77053a910..060c72d00f847 100644 --- a/packages/blocks/src/api/raw-handling/get-raw-transforms.js +++ b/packages/blocks/src/api/raw-handling/get-raw-transforms.js @@ -1,16 +1,12 @@ -/** - * External dependencies - */ -import { filter } from 'lodash'; - /** * Internal dependencies */ import { getBlockTransforms } from '../factory'; export function getRawTransforms() { - return filter( getBlockTransforms( 'from' ), { type: 'raw' } ).map( - ( transform ) => { + return getBlockTransforms( 'from' ) + .filter( ( { type } ) => type === 'raw' ) + .map( ( transform ) => { return transform.isMatch ? transform : { @@ -19,6 +15,5 @@ export function getRawTransforms() { transform.selector && node.matches( transform.selector ), }; - } - ); + } ); } diff --git a/packages/blocks/src/api/raw-handling/phrasing-content-reducer.js b/packages/blocks/src/api/raw-handling/phrasing-content-reducer.js index d1e3a3e43439a..c72a5ffaf6771 100644 --- a/packages/blocks/src/api/raw-handling/phrasing-content-reducer.js +++ b/packages/blocks/src/api/raw-handling/phrasing-content-reducer.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { includes } from 'lodash'; - /** * WordPress dependencies */ @@ -33,7 +28,7 @@ export default function phrasingContentReducer( node, doc ) { // fallback. if ( textDecorationLine === 'line-through' || - includes( textDecoration, 'line-through' ) + textDecoration.includes( 'line-through' ) ) { wrap( doc.createElement( 's' ), node ); } diff --git a/packages/blocks/src/api/raw-handling/shortcode-converter.js b/packages/blocks/src/api/raw-handling/shortcode-converter.js index aedbd055248e5..3434717553a98 100644 --- a/packages/blocks/src/api/raw-handling/shortcode-converter.js +++ b/packages/blocks/src/api/raw-handling/shortcode-converter.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { some, castArray, find, mapValues, pickBy, includes } from 'lodash'; - /** * WordPress dependencies */ @@ -16,6 +11,9 @@ import { getBlockType } from '../registration'; import { getBlockAttributes } from '../parser/get-block-attributes'; import { applyBuiltInValidationFixes } from '../parser/apply-built-in-validation-fixes'; +const castArray = ( maybeArray ) => + Array.isArray( maybeArray ) ? maybeArray : [ maybeArray ]; + function segmentHTMLToShortcodeBlock( HTML, lastIndex = 0, @@ -29,7 +27,7 @@ function segmentHTMLToShortcodeBlock( ( transform ) => excludedBlockNames.indexOf( transform.blockName ) === -1 && transform.type === 'shortcode' && - some( castArray( transform.tag ), ( tag ) => + castArray( transform.tag ).some( ( tag ) => regexp( tag ).test( HTML ) ) ); @@ -39,7 +37,7 @@ function segmentHTMLToShortcodeBlock( } const transformTags = castArray( transformation.tag ); - const transformTag = find( transformTags, ( tag ) => + const transformTag = transformTags.find( ( tag ) => regexp( tag ).test( HTML ) ); @@ -56,7 +54,7 @@ function segmentHTMLToShortcodeBlock( // consider the shortcode as inline text, and thus skip conversion for // this segment. if ( - ! includes( match.shortcode.content || '', '<' ) && + ! match.shortcode.content?.includes( '<' ) && ! ( /(\n|

)\s*$/.test( beforeHTML ) && /^\s*(\n|<\/p>)/.test( afterHTML ) @@ -102,16 +100,17 @@ function segmentHTMLToShortcodeBlock( ); } ); } else { - const attributes = mapValues( - pickBy( - transformation.attributes, - ( schema ) => schema.shortcode - ), - // Passing all of `match` as second argument is intentionally broad - // but shouldn't be too relied upon. - // - // See: https://github.com/WordPress/gutenberg/pull/3610#discussion_r152546926 - ( schema ) => schema.shortcode( match.shortcode.attrs, match ) + const attributes = Object.fromEntries( + Object.entries( transformation.attributes ) + .filter( ( [ , schema ] ) => schema.shortcode ) + // Passing all of `match` as second argument is intentionally broad + // but shouldn't be too relied upon. + // + // See: https://github.com/WordPress/gutenberg/pull/3610#discussion_r152546926 + .map( ( [ key, schema ] ) => [ + key, + schema.shortcode( match.shortcode.attrs, match ), + ] ) ); const blockType = getBlockType( transformation.blockName );