How to use the @wordpress/dom.remove function in @wordpress/dom

To help you get started, we’ve selected a few @wordpress/dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / wordpress__dom / wordpress__dom-tests.ts View on Github external
dom.isVerticalEdge(element, false);

// $ExpectType void
dom.placeCaretAtHorizontalEdge(element, true);

// $ExpectType void
dom.placeCaretAtHorizontalEdge(undefined, false);

// $ExpectType void
dom.placeCaretAtVerticalEdge(element, true);

// $ExpectType void
dom.placeCaretAtVerticalEdge(undefined, false);

// $ExpectType void
dom.remove(node);

// $ExpectType void
dom.replace(node, node);

// $ExpectType HTMLParagraphElement
dom.replaceTag(node, 'p');

// $ExpectType HTMLSpanElement
dom.replaceTag(node, 'span');

// $ExpectType void
dom.unwrap(node);

// $ExpectType void
dom.wrap(node, node);
github WordPress / gutenberg / packages / blocks / src / api / raw-handling / utils.js View on Github external
schema.hasOwnProperty( tag ) &&
			( ! schema[ tag ].isMatch || schema[ tag ].isMatch( node ) )
		) {
			if ( node.nodeType === ELEMENT_NODE ) {
				const {
					attributes = [],
					classes = [],
					children,
					require = [],
					allowEmpty,
				} = schema[ tag ];

				// If the node is empty and it's supposed to have children,
				// remove the node.
				if ( children && ! allowEmpty && isEmpty( node ) ) {
					remove( node );
					return;
				}

				if ( node.hasAttributes() ) {
					// Strip invalid attributes.
					Array.from( node.attributes ).forEach( ( { name } ) => {
						if ( name !== 'class' && ! includes( attributes, name ) ) {
							node.removeAttribute( name );
						}
					} );

					// Strip invalid classes.
					// In jsdom-jscore, 'node.classList' can be undefined.
					// TODO: Explore patching this in jsdom-jscore.
					if ( node.classList && node.classList.length ) {
						const mattchers = classes.map( ( item ) => {
github WordPress / gutenberg / packages / blocks / src / api / raw-handling / utils.js View on Github external
} else if (
							node.parentNode.nodeName === 'BODY' &&
							isPhrasingContent( node )
						) {
							cleanNodeList( node.childNodes, doc, schema, inline );

							if ( Array.from( node.childNodes ).some( ( child ) => ! isPhrasingContent( child ) ) ) {
								unwrap( node );
							}
						} else {
							cleanNodeList( node.childNodes, doc, children, inline );
						}
					// Remove children if the node is not supposed to have any.
					} else {
						while ( node.firstChild ) {
							remove( node.firstChild );
						}
					}
				}
			}
		// Invalid child. Continue with schema at the same place and unwrap.
		} else {
			cleanNodeList( node.childNodes, doc, schema, inline );

			// For inline mode, insert a line break when unwrapping nodes that
			// are not phrasing content.
			if ( inline && ! isPhrasingContent( node ) && node.nextElementSibling ) {
				insertAfter( doc.createElement( 'br' ), node );
			}

			unwrap( node );
		}
github WordPress / gutenberg / packages / blocks / src / api / raw-handling / special-comment-converter.js View on Github external
const customText = node.nodeValue.slice( 4 ).trim();

		/*
		 * When a `` comment is found, we need to look for any
		 * `` sibling, but it may not be a direct sibling
		 * (whitespace typically lies in between)
		 */
		let sibling = node;
		let noTeaser = false;
		while ( ( sibling = sibling.nextSibling ) ) {
			if (
				sibling.nodeType === COMMENT_NODE &&
				sibling.nodeValue === 'noteaser'
			) {
				noTeaser = true;
				remove( sibling );
				break;
			}
		}

		replace( node, createMore( customText, noTeaser, doc ) );
	}
}
github WordPress / gutenberg / packages / blocks / src / api / raw-handling / iframe-remover.js View on Github external
export default function( node ) {
	if ( node.nodeName === 'IFRAME' ) {
		remove( node );
	}
}