import { DragEvent } from 'react' ; export const escapeSrc = ( value = '' ) => value . replace ( / src=/g , ' data-src=' ) ; export const unescapeSrc = ( value = '' ) => value . replace ( / data-src=/g , ' src=' ) ; /**
 * Returns whether the element is a node.
 * See  https export const isElement = ( node ) => node && node . nodeType === 1 ; /**
 * Returns the node if it's an element or the parent element if not
 */ export const getElement = ( node ) => ( isElement ( node ) ? ( node as Element ) : node ?. parentElement || null ) ; export const matches = ( element , selector ) => ( element . matches || ( element as any ) . msMatchesSelector ) . call ( element , selector ) ; export const wrap = ( element , html ) => { const container = document . createElement ( 'div' ) ; container . innerHTML = html ; const wrapper = container . firstChild as Element ; wrapper . innerHTML = element . outerHTML ; element . parentNode ?. insertBefore ( wrapper , element ) ; element . remove ( ) ; return wrapper ; } ; export const parseInDiv = ( content ) => { const div = document . createElement ( 'div' ) ; div . innerHTML = content ; return div ; } ; export const isDragFile = ( event ) => event . dataTransfer ?. types . includes ( 'Files' ) ; /**
 * Move the textarea cursor to the front.
 */ export const setTextAreaCursorStart = ( textarea ) => { textarea . selectionStart = 0 ; textarea . selectionEnd = 0 ; textarea . scrollTop = 0 ; } ; /**
 * Check if a HTML content is considered empty
 */ export const isHTMLEmpty = ( html ) => ! html || html === '<div><br /></div>' || html === '<div><br></div>' ; export const createErrorHandler = ( reject ) => { return ( event ) => { const error = new Error ( `Failed to load ${ event ?. target ?. src }` ) ; ( error as any ) . event = event ; reject ( error ) ; } ; } ; export const preloadImage = async ( url ) => new Promise ( ( resolve , reject ) => { const img = document . createElement ( 'img' ) ; img . src = url ; img . onload = resolve ; img . onerror = createErrorHandler ( reject ) ; } ) ;