public/be-assets/node_modules/@yaireo/tagify/dist/tagify.esm.js
/**
     *
     * @param {Object} m an object representing the observed DOM changes
     */
@param {Object} m an object representing the observed DOM changes
@param { Object } m an object representing the observed DOM changes
onInputDOMChange(m) {
      m.forEach(record => {
        record.addedNodes.forEach(addedNode => {
          if (addedNode) {
            if (addedNode.outerHTML == '<div><br></div>') {
              addedNode.replaceWith(document.createElement('br'));
            } 
            else if (addedNode.nodeType == 1 && addedNode.querySelector(this.settings.classNames.tagSelector)) {
              let newlineText = document.createTextNode('');
              if (addedNode.childNodes[0].nodeType == 3 && addedNode.previousSibling.nodeName != 'BR') newlineText = document.createTextNode('\n'); 
              addedNode.replaceWith(...[newlineText, ...[...addedNode.childNodes].slice(0, -1)]);
              this.placeCaretAfterNode(newlineText.previousSibling);
            } 
            else if (isNodeTag.call(this, addedNode)) {
              if (addedNode.previousSibling && addedNode.previousSibling.nodeName == 'BR') {
                addedNode.previousSibling.replaceWith('\n\u200B'); 
                this.placeCaretAfterNode(addedNode.previousSibling.previousSibling);
              }
            }
          }
        });
        record.removedNodes.forEach(removedNode => {
          if (removedNode && removedNode.nodeName == 'BR' && isNodeTag.call(this, lastInputChild)) {
            this.removeTags(lastInputChild);
            this.fixFirefoxLastTagNoCaret();
          }
        });
      }); 
      var lastInputChild = this.DOM.input.lastChild;
      if (lastInputChild && lastInputChild.nodeValue == '') lastInputChild.remove(); 
      if (!lastInputChild || lastInputChild.nodeName != 'BR') {
        this.DOM.input.appendChild(document.createElement('br'));
      }
    }
onInputDOMChange ( m ) { m . forEach ( record => { record . addedNodes . forEach ( addedNode => { if ( addedNode ) { if ( addedNode . outerHTML == '<div><br></div>' ) { addedNode . replaceWith ( document . createElement ( 'br' ) ) ; } else if ( addedNode . nodeType == 1 && addedNode . querySelector ( this . settings . classNames . tagSelector ) ) { let newlineText = document . createTextNode ( '' ) ; if ( addedNode . childNodes [ 0 ] . nodeType == 3 && addedNode . previousSibling . nodeName != 'BR' ) newlineText = document . createTextNode ( '\n' ) ; addedNode . replaceWith ( ... [ newlineText , ... [ ... addedNode . childNodes ] . slice ( 0 , - 1 ) ] ) ; this . placeCaretAfterNode ( newlineText . previousSibling ) ; } else if ( isNodeTag . call ( this , addedNode ) ) { if ( addedNode . previousSibling && addedNode . previousSibling . nodeName == 'BR' ) { addedNode . previousSibling . replaceWith ( '\n\u200B' ) ; this . placeCaretAfterNode ( addedNode . previousSibling . previousSibling ) ; } } } } ) ; record . removedNodes . forEach ( removedNode => { if ( removedNode && removedNode . nodeName == 'BR' && isNodeTag . call ( this , lastInputChild ) ) { this . removeTags ( lastInputChild ) ; this . fixFirefoxLastTagNoCaret ( ) ; } } ) ; } ) ; var lastInputChild = this . DOM . input . lastChild ; if ( lastInputChild && lastInputChild . nodeValue == '' ) lastInputChild . remove ( ) ; if ( ! lastInputChild || lastInputChild . nodeName != 'BR' ) { this . DOM . input . appendChild ( document . createElement ( 'br' ) ) ; } }
@param {Object} m an object representing the observed DOM changes
@param { Object } m an object representing the observed DOM changes
// iterate all DOm mutation // only the ADDED nodes // fix chrome's placing '<div><br></div>' everytime ENTER key is pressed, and replace with just `<br' // if the added element is a div containing a tag within it (chrome does this when pressing ENTER before a tag) // unwrap the useless div // chrome adds a BR at the end which should be removed // if this is a tag // and it is the first node in a new line // allows placing the caret just before the tag, when the tag is the first node in that line // when hitting ENTER for new line just before a tag // when trying to delete a tag which is in a new line and there's nothing else there (caret is after the tag) // get the last child only after the above DOM modifications // check these scenarios: // 1. after a single line, press ENTER once - should add only 1 BR // 2. presss ENTER right before a tag // 3. press enter within a text node before a tag // make sure the last element is always a BR