How to use the @wordpress/dom.unwrap 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.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 / list-reducer.js View on Github external
prevListItem.appendChild( list );
			parentList.removeChild( parentListItem );
		} else {
			parentList.parentNode.insertBefore( list, parentList );
			parentList.parentNode.removeChild( parentList );
		}
	}

	// Invalid: OL/UL > OL/UL.
	if ( parentElement && isList( parentElement ) ) {
		const prevListItem = node.previousElementSibling;

		if ( prevListItem ) {
			prevListItem.appendChild( node );
		} else {
			unwrap( node );
		}
	}
}
github WordPress / gutenberg / packages / blocks / src / api / raw-handling / utils.js View on Github external
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 / utils.js View on Github external
// If a parent requires certain children, but it does
						// not have them, drop the parent and continue.
						if ( require.length && ! node.querySelector( require.join( ',' ) ) ) {
							cleanNodeList( node.childNodes, doc, schema, inline );
							unwrap( node );
						// If the node is at the top, phrasing content, and
						// contains children that are block content, unwrap
						// the node because it is invalid.
						} 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 );