Skip to content

Commit

Permalink
Fix list filter on paste for RN mobile. (#17550)
Browse files Browse the repository at this point in the history
* Fix method for RN mobile.

* Use array.From instead of slice.

* Remove comment and use Array.from directly

* Convert from NodeList spreadable to Array.from

* Fix lint errors.

* Fix documentation examples to use Array.from

* Add empty line.
  • Loading branch information
SergioEstevao committed Sep 26, 2019
1 parent df025a6 commit d8b0d83
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/blocks/src/api/raw-handling/list-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function isList( node ) {
}

function shallowTextContent( element ) {
return [ ...element.childNodes ]
return Array.from( element.childNodes )
.map( ( { nodeValue = '' } ) => nodeValue )
.join( '' );
}
Expand Down
8 changes: 4 additions & 4 deletions packages/blocks/src/api/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const REGEXP_STYLE_URL_TYPE = /^url\s*\(['"\s]*(.*?)['"\s]*\)$/;
* See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes
* Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3
*
* Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]
* Object.keys( Array.from( document.querySelectorAll( '#attributes-1 > tbody > tr' ) )
* .filter( ( tr ) => tr.lastChild.textContent.indexOf( 'Boolean attribute' ) !== -1 )
* .reduce( ( result, tr ) => Object.assign( result, {
* [ tr.firstChild.textContent.trim() ]: true
Expand Down Expand Up @@ -97,7 +97,7 @@ const BOOLEAN_ATTRIBUTES = [
* See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#enumerated-attribute
* Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3
*
* Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]
* Object.keys( Array.from( document.querySelectorAll( '#attributes-1 > tbody > tr' ) )
* .filter( ( tr ) => /^("(.+?)";?\s*)+/.test( tr.lastChild.textContent.trim() ) )
* .reduce( ( result, tr ) => Object.assign( result, {
* [ tr.firstChild.textContent.trim() ]: true
Expand Down Expand Up @@ -164,9 +164,9 @@ const TEXT_NORMALIZATIONS = [
* Tested aginst "12.5 Named character references":
*
* ```
* const references = [ ...document.querySelectorAll(
* const references = Array.from( document.querySelectorAll(
* '#named-character-references-table tr[id^=entity-] td:first-child'
* ) ].map( ( code ) => code.textContent )
* ) ).map( ( code ) => code.textContent )
* references.every( ( reference ) => /^[\da-z]+$/i.test( reference ) )
* ```
*
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/disabled/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jest.mock( '@wordpress/dom', () => {
// In JSDOM, all elements have zero'd widths and height.
// This is a metric for focusable's `isVisible`, so find
// and apply an arbitrary non-zero width.
[ ...context.querySelectorAll( '*' ) ].forEach( ( element ) => {
Array.from( context.querySelectorAll( '*' ) ).forEach( ( element ) => {
Object.defineProperties( element, {
offsetWidth: {
get: () => 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/draggable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Draggable extends Component {
}

// Hack: Remove iFrames as it's causing the embeds drag clone to freeze
[ ...clone.querySelectorAll( 'iframe' ) ].forEach( ( child ) => child.parentNode.removeChild( child ) );
Array.from( clone.querySelectorAll( 'iframe' ) ).forEach( ( child ) => child.parentNode.removeChild( child ) );

this.cloneWrapper.appendChild( clone );
elementWrapper.appendChild( this.cloneWrapper );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default createHigherOrderComponent(
}

focusRegion( offset ) {
const regions = [ ...this.container.querySelectorAll( '[role="region"]' ) ];
const regions = Array.from( this.container.querySelectorAll( '[role="region"]' ) );
if ( ! regions.length ) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dom/src/focusable.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function isValidFocusableArea( element ) {
export function find( context ) {
const elements = context.querySelectorAll( SELECTOR );

return [ ...elements ].filter( ( element ) => {
return Array.from( elements ).filter( ( element ) => {
if ( ! isVisible( element ) ) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/components/admin-notices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const NOTICE_CLASS_STATUSES = {
function getAdminNotices() {
// The order is reversed to match expectations of rendered order, since a
// NoticesList is itself rendered in reverse order (newest to oldest).
return [ ...document.querySelectorAll( '#wpbody-content > .notice' ) ].reverse();
return Array.from( document.querySelectorAll( '#wpbody-content > .notice' ) ).reverse();
}

/**
Expand Down

0 comments on commit d8b0d83

Please sign in to comment.