From 833d7dfdbdc5de661274ed805b42812322f6353b Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Tue, 15 Aug 2017 11:11:48 +1000 Subject: [PATCH] New (increase|decrease)ListLevel algorithms Fixes #287 --- build/squire-raw.js | 221 ++++++++++++++++++++++++++++-------------- build/squire.js | 4 +- source/Editor.js | 211 +++++++++++++++++++++++++++------------- source/KeyHandlers.js | 10 +- 4 files changed, 298 insertions(+), 148 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 7dec44a..95e053e 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -1451,7 +1451,7 @@ var keyHandlers = { // Break list if ( getNearest( block, root, 'UL' ) || getNearest( block, root, 'OL' ) ) { - return self.modifyBlocks( decreaseListLevel, range ); + return self.decreaseListLevel( range ); } // Break blockquote else if ( getNearest( block, root, 'BLOCKQUOTE' ) ) { @@ -1558,7 +1558,7 @@ var keyHandlers = { // Break list if ( getNearest( current, root, 'UL' ) || getNearest( current, root, 'OL' ) ) { - return self.modifyBlocks( decreaseListLevel, range ); + return self.decreaseListLevel( range ); } // Break blockquote else if ( getNearest( current, root, 'BLOCKQUOTE' ) ) { @@ -1653,12 +1653,12 @@ var keyHandlers = { if ( range.collapsed && rangeDoesStartAtBlockBoundary( range, root ) ) { node = getStartBlockOfRange( range, root ); // Iterate through the block's parents - while ( parent = node.parentNode ) { + while ( ( parent = node.parentNode ) ) { // If we find a UL or OL (so are in a list, node must be an LI) if ( parent.nodeName === 'UL' || parent.nodeName === 'OL' ) { // Then increase the list level event.preventDefault(); - self.modifyBlocks( increaseListLevel, range ); + self.increaseListLevel( range ); break; } node = parent; @@ -1676,7 +1676,7 @@ var keyHandlers = { if ( getNearest( node, root, 'UL' ) || getNearest( node, root, 'OL' ) ) { event.preventDefault(); - self.modifyBlocks( decreaseListLevel, range ); + self.decreaseListLevel( range ); } } }, @@ -3888,77 +3888,155 @@ var removeList = function ( frag ) { return frag; }; -var increaseListLevel = function ( frag ) { - var items = frag.querySelectorAll( 'LI' ), - i, l, item, - type, newParent, - tagAttributes = this._config.tagAttributes, - listAttrs; - for ( i = 0, l = items.length; i < l; i += 1 ) { - item = items[i]; - if ( !isContainer( item.firstChild ) ) { - // type => 'UL' or 'OL' - type = item.parentNode.nodeName; - newParent = item.previousSibling; - if ( !newParent || !( newParent = newParent.lastChild ) || - newParent.nodeName !== type ) { - listAttrs = tagAttributes[ type.toLowerCase() ]; - newParent = this.createElement( type, listAttrs ); - - replaceWith( - item, - newParent - ); - } - newParent.appendChild( item ); - } +var getListSelection = function ( range, root ) { + // Get start+end li in single common ancestor + var list = range.commonAncestorContainer; + var startLi = range.startContainer; + var endLi = range.endContainer; + while ( list && list !== root && !/^[OU]L$/.test( list.nodeName ) ) { + list = list.parentNode; } - return frag; + if ( !list || list === root ) { + return null; + } + if ( startLi === list ) { + startLi = startLi.childNodes[ range.startOffset ]; + } + if ( endLi === list ) { + endLi = endLi.childNodes[ range.endOffset ]; + } + while ( startLi && startLi.parentNode !== list ) { + startLi = startLi.parentNode; + } + while ( endLi && endLi.parentNode !== list ) { + endLi = endLi.parentNode; + } + return [ list, startLi, endLi ]; }; -var decreaseListLevel = function ( frag ) { - var root = this._root; - var items = frag.querySelectorAll( 'LI' ); - Array.prototype.filter.call( items, function ( el ) { - return !isContainer( el.firstChild ); - }).forEach( function ( item ) { - var parent = item.parentNode, - newParent = parent.parentNode, - first = item.firstChild, - node = first, - next; - if ( item.previousSibling ) { - parent = split( parent, item, newParent, root ); - } +proto.increaseListLevel = function ( range ) { + if ( !range && !( range = this.getSelection() ) ) { + return this.focus(); + } - // if the new parent is another list then we simply move the node - // e.g. `ul > ul > li` becomes `ul > li` - if ( /^[OU]L$/.test( newParent.nodeName ) ) { - newParent.insertBefore( item, parent ); - if ( !parent.firstChild ) { - newParent.removeChild( parent ); - } - } else { - while ( node ) { - next = node.nextSibling; - if ( isContainer( node ) ) { - break; - } - newParent.insertBefore( node, parent ); - node = next; - } + var listSelection = getListSelection( range, root ); + if ( !listSelection ) { + return this.focus(); + } + + var list = listSelection[0]; + var startLi = listSelection[1]; + var endLi = listSelection[2]; + if ( !startLi || startLi === list.firstChild ) { + return this.focus(); + } + + // Save undo checkpoint and bookmark selection + this._recordUndoState( range, this._isInUndoState ); + + // Increase list depth + var type = list.nodeName; + var newParent = startLi.previousSibling; + var listAttrs, next; + if ( newParent.nodeName !== type ) { + listAttrs = this._config.tagAttributes[ type.toLowerCase() ]; + newParent = this.createElement( type, listAttrs ); + list.insertBefore( newParent, startLi ); + } + do { + next = startLi === endLi ? null : startLi.nextSibling; + newParent.appendChild( startLi ); + } while ( ( startLi = next ) ); + next = newParent.nextSibling; + if ( next ) { + mergeContainers( next, this._root ); + } + + // Restore selection + this._getRangeAndRemoveBookmark( range ); + this.setSelection( range ); + this._updatePath( range, true ); + + // We're not still in an undo state + if ( !canObserveMutations ) { + this._docWasChanged(); + } + + return this.focus(); +}; + +proto.decreaseListLevel = function ( range ) { + if ( !range && !( range = this.getSelection() ) ) { + return this.focus(); + } + + var root = this._root; + var listSelection = getListSelection( range, root ); + if ( !listSelection ) { + return this.focus(); + } + + var list = listSelection[0]; + var startLi = listSelection[1]; + var endLi = listSelection[2]; + if ( !startLi ) { + startLi = list.firstChild; + } + if ( !endLi ) { + endLi = list.lastChild; + } + + // Save undo checkpoint and bookmark selection + this._recordUndoState( range, this._isInUndoState ); + + // Find the new parent list node + var newParent = list.parentNode; + var next; + + // Split list if necesary + var insertBefore = !endLi.nextSibling ? + list.nextSibling : + split( list, endLi.nextSibling, newParent, root ); + + if ( newParent !== root && newParent.nodeName === 'LI' ) { + newParent = newParent.parentNode; + while ( insertBefore ) { + next = insertBefore.nextSibling; + endLi.appendChild( insertBefore ); + insertBefore = next; } - if ( newParent.nodeName === 'LI' && first.previousSibling ) { - split( newParent, first, newParent.parentNode, root ); + insertBefore = list.parentNode.nextSibling; + } + + var makeNotList = !/^[OU]L$/.test( newParent.nodeName ); + do { + next = startLi === endLi ? null : startLi.nextSibling; + list.removeChild( startLi ); + if ( makeNotList && startLi.nodeName === 'LI' ) { + startLi = this.createDefaultBlock([ empty( startLi ) ]); } - while ( item !== frag && !item.childNodes.length ) { - parent = item.parentNode; - parent.removeChild( item ); - item = parent; - } - }, this ); - fixContainer( frag, root ); - return frag; + newParent.insertBefore( startLi, insertBefore ); + } while ( ( startLi = next ) ); + + if ( !list.firstChild ) { + detach( list ); + } + + if ( insertBefore ) { + mergeContainers( insertBefore, root ); + } + + // Restore selection + this._getRangeAndRemoveBookmark( range ); + this.setSelection( range ); + this._updatePath( range, true ); + + // We're not still in an undo state + if ( !canObserveMutations ) { + this._docWasChanged(); + } + + return this.focus(); }; proto._ensureBottomLine = function () { @@ -4554,9 +4632,6 @@ proto.makeUnorderedList = command( 'modifyBlocks', makeUnorderedList ); proto.makeOrderedList = command( 'modifyBlocks', makeOrderedList ); proto.removeList = command( 'modifyBlocks', removeList ); -proto.increaseListLevel = command( 'modifyBlocks', increaseListLevel ); -proto.decreaseListLevel = command( 'modifyBlocks', decreaseListLevel ); - // Node.js exports Squire.isInline = isInline; Squire.isBlock = isBlock; diff --git a/build/squire.js b/build/squire.js index 696758a..9520516 100644 --- a/build/squire.js +++ b/build/squire.js @@ -1,2 +1,2 @@ -!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function o(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function r(e){return e.nodeType===F&&!!St[e.nodeName]}function i(e){switch(e.nodeType){case M:return Tt;case F:case W:if(mt&&kt.has(e))return kt.get(e);break;default:return yt}var t;return t=o(e.childNodes,a)?Ct.test(e.nodeName)?Tt:Et:bt,mt&&kt.set(e,t),t}function a(e){return i(e)===Tt}function s(e){return i(e)===Et}function d(e){return i(e)===bt}function l(e,t){var o=new n(t,z,s);return o.currentNode=e,o}function c(e,t){return e=l(e,t).previousNode(),e!==t?e:null}function u(e,t){return e=l(e,t).nextNode(),e!==t?e:null}function h(e){return!e.textContent&&!e.querySelector("IMG")}function f(e,t){return!r(e)&&e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&"A"!==e.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function p(e,t,n){if(e.nodeName!==t)return!1;for(var o in n)if(e.getAttribute(o)!==n[o])return!1;return!0}function g(e,t,n,o){for(;e&&e!==t;){if(p(e,n,o))return e;e=e.parentNode}return null}function m(e,t){for(;t;){if(t===e)return!0;t=t.parentNode}return!1}function v(e,t){var n,o,r,i,a="";return e&&e!==t&&(a=v(e.parentNode,t),e.nodeType===F&&(a+=(a?">":"")+e.nodeName,(n=e.id)&&(a+="#"+n),(o=e.className.trim())&&(r=o.split(/\s\s*/),r.sort(),a+=".",a+=r.join(".")),(i=e.dir)&&(a+="[dir="+i+"]"),r&&(_t.call(r,Q)>-1&&(a+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),_t.call(r,$)>-1&&(a+="[color="+e.style.color.replace(/ /g,"")+"]"),_t.call(r,V)>-1&&(a+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),_t.call(r,Y)>-1&&(a+="[fontSize="+e.style.fontSize+"]")))),a}function _(e){var t=e.nodeType;return t===F||t===W?e.childNodes.length:e.length||0}function N(e){var t=e.parentNode;return t&&t.removeChild(e),e}function C(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,o=n?n.length:0;o--;)t.appendChild(e.firstChild);return t}function y(e,n,o,r){var i,a,s,d,l=e.createElement(n);if(o instanceof Array&&(r=o,o=null),o)for(i in o)a=o[i],a!==t&&l.setAttribute(i,o[i]);if(r)for(s=0,d=r.length;d>s;s+=1)l.appendChild(r[s]);return l}function T(e,t){var n,o,i=t.__squire__,s=e.ownerDocument,d=e;if(e===t&&((o=e.firstChild)&&"BR"!==o.nodeName||(n=i.createDefaultBlock(),o?e.replaceChild(n,o):e.appendChild(n),e=n,n=null)),e.nodeType===M)return d;if(a(e)){for(o=e.firstChild;ft&&o&&o.nodeType===M&&!o.data;)e.removeChild(o),o=e.firstChild;o||(ft?(n=s.createTextNode(X),i._didAddZWS()):n=s.createTextNode(""))}else if(ht){for(;e.nodeType!==M&&!r(e);){if(o=e.firstChild,!o){n=s.createTextNode("");break}e=o}e.nodeType===M?/^ +$/.test(e.data)&&(e.data=""):r(e)&&e.parentNode.insertBefore(s.createTextNode(""),e)}else if(!e.querySelector("BR"))for(n=y(s,"BR");(o=e.lastElementChild)&&!a(o);)e=o;if(n)try{e.appendChild(n)}catch(l){i.didError({name:"Squire: fixCursor – "+l,message:"Parent: "+e.nodeName+"/"+e.innerHTML+" appendChild: "+n.nodeName})}return d}function E(e,t){var n,o,r,i,s=e.childNodes,l=e.ownerDocument,c=null,u=t.__squire__._config;for(n=0,o=s.length;o>n;n+=1)r=s[n],i="BR"===r.nodeName,!i&&a(r)?(c||(c=y(l,u.blockTag,u.blockAttributes)),c.appendChild(r),n-=1,o-=1):(i||c)&&(c||(c=y(l,u.blockTag,u.blockAttributes)),T(c,t),i?e.replaceChild(c,r):(e.insertBefore(c,r),n+=1,o+=1),c=null),d(r)&&E(r,t);return c&&e.appendChild(T(c,t)),e}function b(e,t,n,o){var r,i,a,s=e.nodeType;if(s===M&&e!==n)return b(e.parentNode,e.splitText(t),n,o);if(s===F){if("number"==typeof t&&(t=ts?t.startOffset-=1:t.startOffset===s&&(t.startContainer=o,t.startOffset=_(o))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=o,t.endOffset=_(o))),N(n),n.nodeType===M?o.appendData(n.data):d.push(S(n));else if(n.nodeType===F){for(r=d.length;r--;)n.appendChild(d.pop());k(n,t)}}function L(e,t){if(e.nodeType===M&&(e=e.parentNode),e.nodeType===F){var n={startContainer:t.startContainer,startOffset:t.startOffset,endContainer:t.endContainer,endOffset:t.endOffset};k(e,n),t.setStart(n.startContainer,n.startOffset),t.setEnd(n.endContainer,n.endOffset)}}function B(e,t,n,o){for(var r,i,a,s=t;(r=s.parentNode)&&r!==o&&r.nodeType===F&&1===r.childNodes.length;)s=r;N(s),a=e.childNodes.length,i=e.lastChild,i&&"BR"===i.nodeName&&(e.removeChild(i),a-=1),e.appendChild(S(t)),n.setStart(e,a),n.collapse(!0),L(e,n),st&&(i=e.lastChild)&&"BR"===i.nodeName&&e.removeChild(i)}function A(e,t){var n,o,r=e.previousSibling,i=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||i&&/^[OU]L$/.test(i.nodeName))if(r&&f(r,e)){if(!d(r)){if(!s)return;o=y(a,"DIV"),o.appendChild(S(r)),r.appendChild(o)}N(e),n=!d(e),r.appendChild(S(e)),n&&E(r,t),i&&A(i,t)}else s&&(r=y(a,"DIV"),e.insertBefore(r,i),T(r,t))}function O(e){this.isShiftDown=e.shiftKey}function x(e,t,n){var o,r;if(e||(e={}),t)for(o in t)!n&&o in e||(r=t[o],e[o]=r&&r.constructor===Object?x(e[o],r,n):r);return e}function D(e,t){e.nodeType===H&&(e=e.body);var n,o=e.ownerDocument,r=o.defaultView;this._win=r,this._doc=o,this._root=e,this._events={},this._isFocused=!1,this._lastSelection=null,pt&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this._willUpdatePath=!1,"onselectionchange"in o?this.addEventListener("selectionchange",this._updatePathOnEvent):(this.addEventListener("keyup",this._updatePathOnEvent),this.addEventListener("mouseup",this._updatePathOnEvent)),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,this._ignoreAllChanges=!1,gt?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(e,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._restoreSelection=!1,this.addEventListener("blur",R),this.addEventListener("mousedown",U),this.addEventListener("touchstart",U),this.addEventListener("focus",P),this._awaitingPaste=!1,this.addEventListener(at?"beforecut":"cut",ln),this.addEventListener("copy",cn),this.addEventListener("keydown",O),this.addEventListener("keyup",O),this.addEventListener(at?"beforepaste":"paste",un),this.addEventListener("drop",hn),this.addEventListener(st?"keypress":"keydown",qt),this._keyHandlers=Object.create(jt),this.setConfig(t),at&&(r.Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,o=this.parentNode,r=this.length-e;return n?o.insertBefore(t,n):o.appendChild(t),r&&this.deleteData(e,r),t}),e.setAttribute("contenteditable","true");try{o.execCommand("enableObjectResizing",!1,"false"),o.execCommand("enableInlineTableEditing",!1,"false")}catch(i){}e.__squire__=this,this.setHTML("")}function R(){this._restoreSelection=!0}function U(){this._restoreSelection=!1}function P(){this._restoreSelection&&this.setSelection(this._lastSelection)}function I(e,t,n){var o,r;for(o=t.firstChild;o;o=r){if(r=o.nextSibling,a(o)){if(o.nodeType===M||"BR"===o.nodeName||"IMG"===o.nodeName){n.appendChild(o);continue}}else if(s(o)){n.appendChild(e.createDefaultBlock([I(e,o,e._doc.createDocumentFragment())]));continue}I(e,o,n)}return n}var w=2,F=1,M=3,H=9,W=11,z=1,q=4,K=0,G=1,Z=2,j=3,Q="highlight",$="colour",V="font",Y="size",X="​",J=e.defaultView,et=navigator.userAgent,tt=/Android/.test(et),nt=/iP(?:ad|hone|od)/.test(et),ot=/Mac OS X/.test(et),rt=/Windows NT/.test(et),it=/Gecko\//.test(et),at=/Trident\/[456]\./.test(et),st=!!J.opera,dt=/Edge\//.test(et),lt=!dt&&/WebKit\//.test(et),ct=/Trident\/[4567]\./.test(et),ut=ot?"meta-":"ctrl-",ht=at||st,ft=at||lt,pt=at,gt="undefined"!=typeof MutationObserver,mt="undefined"!=typeof WeakMap,vt=/[^ \t\r\n]/,_t=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var Nt={1:1,2:2,3:4,8:128,9:256,11:1024};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,o=this.nodeType,r=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)e=t.nextSibling,e||(t=t.parentNode);if(!e)return null;if(Nt[e.nodeType]&o&&r(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,o=this.nodeType,r=this.filter;;){if(t===n)return null;if(e=t.previousSibling)for(;t=e.lastChild;)e=t;else e=t.parentNode;if(!e)return null;if(Nt[e.nodeType]&o&&r(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,o=this.nodeType,r=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)e=t.previousSibling,e||(t=t.parentNode);if(!e)return null;if(Nt[e.nodeType]&o&&r(e))return this.currentNode=e,e;t=e}};var Ct=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|TIME|U|VAR|WBR)$/,St={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},yt=0,Tt=1,Et=2,bt=3,kt=mt?new WeakMap:null,Lt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===F;)e=n[t-1],n=e.childNodes,t=n.length;return e},Bt=function(e,t){if(e.nodeType===F){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(G,o)<1;return!r&&!i}var a=e.compareBoundaryPoints(K,o)<1,s=e.compareBoundaryPoints(Z,o)>-1;return a&&s},Ut=function(e){for(var t,n=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset,s=!0;n.nodeType!==M&&(t=n.childNodes[o],t&&!r(t));)n=t,o=0;if(a)for(;i.nodeType!==M;){if(t=i.childNodes[a-1],!t||r(t)){if(s&&t&&"BR"===t.nodeName){a-=1,s=!1;continue}break}i=t,a=_(i)}else for(;i.nodeType!==M&&(t=i.firstChild,t&&!r(t));)i=t;e.collapsed?(e.setStart(i,a),e.setEnd(n,o)):(e.setStart(n,o),e.setEnd(i,a))},Pt=function(e,t,n,o){var r,i=e.startContainer,a=e.startOffset,s=e.endContainer,d=e.endOffset,l=!0;for(t||(t=e.commonAncestorContainer),n||(n=t);!a&&i!==t&&i!==o;)r=i.parentNode,a=_t.call(r.childNodes,i),i=r;for(;;){if(l&&s.nodeType!==M&&s.childNodes[d]&&"BR"===s.childNodes[d].nodeName&&(d+=1,l=!1),s===n||s===o||d!==_(s))break;r=s.parentNode,d=_t.call(r.childNodes,s)+1,s=r}e.setStart(i,a),e.setEnd(s,d)},It=function(e,t){var n,o=e.startContainer;return a(o)?n=c(o,t):o!==t&&s(o)?n=o:(n=Lt(o,e.startOffset),n=u(n,t)),n&&Rt(e,n,!0)?n:null},wt=function(e,t){var n,o,r=e.endContainer;if(a(r))n=c(r,t);else if(r!==t&&s(r))n=r;else{if(n=Bt(r,e.endOffset),!n||!m(t,n))for(n=t;o=n.lastChild;)n=o;n=c(n,t)}return n&&Rt(e,n,!0)?n:null},Ft=new n(null,q|z,function(e){return e.nodeType===M?vt.test(e.data):"IMG"===e.nodeName}),Mt=function(e,t){var n,o=e.startContainer,r=e.startOffset;if(Ft.root=null,o.nodeType===M){if(r)return!1;n=o}else if(n=Bt(o,r),n&&!m(t,n)&&(n=null),!n&&(n=Lt(o,r),n.nodeType===M&&n.length))return!1;return Ft.currentNode=n,Ft.root=It(e,t),!Ft.previousNode()},Ht=function(e,t){var n,o=e.endContainer,r=e.endOffset;if(Ft.root=null,o.nodeType===M){if(n=o.data.length,n&&n>r)return!1;Ft.currentNode=o}else Ft.currentNode=Lt(o,r);return Ft.root=wt(e,t),!Ft.nextNode()},Wt=function(e,t){var n,o=It(e,t),r=wt(e,t);o&&r&&(n=o.parentNode,e.setStart(n,_t.call(n.childNodes,o)),n=r.parentNode,e.setEnd(n,_t.call(n.childNodes,r)+1))},zt={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},qt=function(e){var t=e.keyCode,n=zt[t],o="",r=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),st&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(o+="alt-"),e.ctrlKey&&(o+="ctrl-"),e.metaKey&&(o+="meta-")),e.shiftKey&&(o+="shift-"),n=o+n,this._keyHandlers[n]?this._keyHandlers[n](this,e,r):1!==n.length||r.collapsed||(this.saveUndoState(r),xt(r,this._root),this._ensureBottomLine(),this.setSelection(r),this._updatePath(r,!0)))},Kt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Gt=function(e,t){return t=t||null,function(n,o){o.preventDefault();var r=n.getSelection();n.hasFormat(e,null,r)?n.changeFormat(null,{tag:e},r):n.changeFormat({tag:e},t,r)}},Zt=function(e,t){try{t||(t=e.getSelection());var n,o=t.startContainer;for(o.nodeType===M&&(o=o.parentNode),n=o;a(n)&&(!n.textContent||n.textContent===X);)o=n,n=o.parentNode;o!==n&&(t.setStart(n,_t.call(n.childNodes,o)),t.collapse(!0),n.removeChild(o),s(n)||(n=c(n,e._root)),T(n,e._root),Ut(t)),o===e._root&&(o=o.firstChild)&&"BR"===o.nodeName&&N(o),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(r){e.didError(r)}},jt={enter:function(e,t,n){var o,r,i,a=e._root;if(t.preventDefault(),e._recordUndoState(n),Dn(n.startContainer,a,e),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||xt(n,a),o=It(n,a),!o||/^T[HD]$/.test(o.nodeName))return r=g(n.endContainer,a,"A"),r&&(r=r.parentNode,Pt(n,r,r,a),n.collapse(!1)),At(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((r=g(o,a,"LI"))&&(o=r),h(o)){if(g(o,a,"UL")||g(o,a,"OL"))return e.modifyBlocks(On,n);if(g(o,a,"BLOCKQUOTE"))return e.modifyBlocks(En,n)}for(i=Sn(e,o,n.startContainer,n.startOffset),vn(o),on(o),T(o,a);i.nodeType===F;){var s,d=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===X)){d=e._doc.createTextNode(""),C(i,d),i=d;break}for(;d&&d.nodeType===M&&!d.data&&(s=d.nextSibling,s&&"BR"!==s.nodeName);)N(d),d=s;if(!d||"BR"===d.nodeName||d.nodeType===M&&!st)break;i=d}n=e._createRange(i,0),e.setSelection(n),e._updatePath(n,!0)},backspace:function(e,t,n){var o=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Mt(n,o)){t.preventDefault();var r,i=It(n,o);if(!i)return;if(E(i.parentNode,o),r=c(i,o)){if(!r.isContentEditable)return void N(r);for(B(r,i,n,o),i=r.parentNode;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(i=i.nextSibling)&&A(i,o),e.setSelection(n)}else if(i){if(g(i,o,"UL")||g(i,o,"OL"))return e.modifyBlocks(On,n);if(g(i,o,"BLOCKQUOTE"))return e.modifyBlocks(Tn,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Zt(e)},0);else t.preventDefault(),xt(n,o),Zt(e,n)},"delete":function(e,t,n){var o,r,i,a,s,d,l=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Ht(n,l)){if(t.preventDefault(),o=It(n,l),!o)return;if(E(o.parentNode,l),r=u(o,l)){if(!r.isContentEditable)return void N(r);for(B(o,r,n,l),r=o.parentNode;r!==l&&!r.nextSibling;)r=r.parentNode;r!==l&&(r=r.nextSibling)&&A(r,l),e.setSelection(n),e._updatePath(n,!0)}}else{if(i=n.cloneRange(),Pt(n,l,l,l),a=n.endContainer,s=n.endOffset,a.nodeType===F&&(d=a.childNodes[s],d&&"IMG"===d.nodeName))return t.preventDefault(),N(d),Ut(n),void Zt(e,n);e.setSelection(i),setTimeout(function(){Zt(e)},0)}else t.preventDefault(),xt(n,l),Zt(e,n)},tab:function(e,t,n){var o,r,i=e._root;if(e._removeZWS(),n.collapsed&&Mt(n,i))for(o=It(n,i);r=o.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){t.preventDefault(),e.modifyBlocks(An,n);break}o=r}},"shift-tab":function(e,t,n){var o,r=e._root;e._removeZWS(),n.collapsed&&Mt(n,r)&&(o=n.startContainer,(g(o,r,"UL")||g(o,r,"OL"))&&(t.preventDefault(),e.modifyBlocks(On,n)))},space:function(e,t,n){var o,r;e._recordUndoState(n),Dn(n.startContainer,e._root,e),e._getRangeAndRemoveBookmark(n),o=n.endContainer,r=o.parentNode,n.collapsed&&"A"===r.nodeName&&!o.nextSibling&&n.endOffset===_(o)?n.setStartAfter(r):n.collapsed||(xt(n,e._root),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};ot&&it&&(jt["meta-left"]=function(e,t){t.preventDefault();var n=mn(e);n&&n.modify&&n.modify("move","backward","lineboundary")},jt["meta-right"]=function(e,t){t.preventDefault();var n=mn(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),ot||(jt.pageup=function(e){e.moveCursorToStart()},jt.pagedown=function(e){e.moveCursorToEnd()}),jt[ut+"b"]=Gt("B"),jt[ut+"i"]=Gt("I"),jt[ut+"u"]=Gt("U"),jt[ut+"shift-7"]=Gt("S"),jt[ut+"shift-5"]=Gt("SUB",{tag:"SUP"}),jt[ut+"shift-6"]=Gt("SUP",{tag:"SUB"}),jt[ut+"shift-8"]=Kt("makeUnorderedList"),jt[ut+"shift-9"]=Kt("makeOrderedList"),jt[ut+"["]=Kt("decreaseQuoteLevel"),jt[ut+"]"]=Kt("increaseQuoteLevel"),jt[ut+"y"]=Kt("redo"),jt[ut+"z"]=Kt("undo"),jt[ut+"shift-z"]=Kt("redo");var Qt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},$t={backgroundColor:{regexp:vt,replace:function(e,t){return y(e,"SPAN",{"class":Q,style:"background-color:"+t})}},color:{regexp:vt,replace:function(e,t){return y(e,"SPAN",{"class":$,style:"color:"+t})}},fontWeight:{regexp:/^bold|^700/i,replace:function(e){return y(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return y(e,"I")}},fontFamily:{regexp:vt,replace:function(e,t){return y(e,"SPAN",{"class":V,style:"font-family:"+t})}},fontSize:{regexp:vt,replace:function(e,t){return y(e,"SPAN",{"class":Y,style:"font-size:"+t})}},textDecoration:{regexp:/^underline/i,replace:function(e){return y(e,"U")}}},Vt=function(e){return function(t,n){var o=y(t.ownerDocument,e);return n.replaceChild(o,t),o.appendChild(S(t)),o}},Yt=function(e,t){var n,o,r,i,a,s,d=e.style,l=e.ownerDocument;for(n in $t)o=$t[n],r=d[n],r&&o.regexp.test(r)&&(s=o.replace(l,r),a||(a=s),i&&i.appendChild(s),i=s,e.style[n]="");return a&&(i.appendChild(S(e)),"SPAN"===e.nodeName?t.replaceChild(a,e):e.appendChild(a)),i||e},Xt={P:Yt,SPAN:Yt,STRONG:Vt("B"),EM:Vt("I"),INS:Vt("U"),STRIKE:Vt("S"),FONT:function(e,t){var n,o,r,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=y(c,"SPAN",{"class":V,style:"font-family:"+s}),a=n,i=n),d&&(o=y(c,"SPAN",{"class":Y,style:"font-size:"+Qt[d]+"px"}),a||(a=o),i&&i.appendChild(o),i=o),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),r=y(c,"SPAN",{"class":$,style:"color:"+l}),a||(a=r),i&&i.appendChild(r),i=r),a||(a=i=y(c,"SPAN")),t.replaceChild(a,e),i.appendChild(S(e)),i},TT:function(e,t){var n=y(e.ownerDocument,"SPAN",{"class":V,style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(S(e)),n}},Jt=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|IGCAPTION|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|COL(?:GROUP)?|UL)$/,en=/^(?:HEAD|META|STYLE)/,tn=new n(null,q|z,function(){return!0}),nn=function Pn(e,t){var n,o,r,i,s,d,l,c,u,h,f,p,g=e.childNodes;for(n=e;a(n);)n=n.parentNode;for(tn.root=n,o=0,r=g.length;r>o;o+=1)if(i=g[o],s=i.nodeName,d=i.nodeType,l=Xt[s],d===F){if(c=i.childNodes.length,l)i=l(i,e);else{if(en.test(s)){e.removeChild(i),o-=1,r-=1;continue}if(!Jt.test(s)&&!a(i)){o-=1,r+=c-1,e.replaceChild(S(i),i);continue}}c&&Pn(i,t||"PRE"===s)}else{if(d===M){if(f=i.data,u=!vt.test(f.charAt(0)),h=!vt.test(f.charAt(f.length-1)),t||!u&&!h)continue;if(u){for(tn.currentNode=i;(p=tn.previousPONode())&&(s=p.nodeName,!("IMG"===s||"#text"===s&&vt.test(p.data)));)if(!a(p)){p=null;break}f=f.replace(/^[ \t\r\n]+/g,p?" ":"")}if(h){for(tn.currentNode=i;(p=tn.nextNode())&&!("IMG"===s||"#text"===s&&vt.test(p.data));)if(!a(p)){p=null;break}f=f.replace(/[ \t\r\n]+$/g,p?" ":"")}if(f){i.data=f;continue}}e.removeChild(i),o-=1,r-=1}return e},on=function In(e){for(var t,n=e.childNodes,o=n.length;o--;)t=n[o],t.nodeType!==F||r(t)?t.nodeType!==M||t.data||e.removeChild(t):(In(t),a(t)&&!t.firstChild&&e.removeChild(t))},rn=function(e){return e.nodeType===F?"BR"===e.nodeName:vt.test(e.data)},an=function(e,t){for(var o,r=e.parentNode;a(r);)r=r.parentNode;return o=new n(r,z|q,rn),o.currentNode=e,!!o.nextNode()||t&&!o.previousNode()},sn=function(e,t,n){var o,r,i,s=e.querySelectorAll("BR"),d=[],l=s.length;for(o=0;l>o;o+=1)d[o]=an(s[o],n);for(;l--;)r=s[l],i=r.parentNode,i&&(d[l]?a(i)||E(i,t):N(r))},dn=function(e,t,n){var o,r,i=t.ownerDocument.body;sn(t,n,!0),t.setAttribute("style","position:fixed;overflow:hidden;bottom:100%;right:100%;"),i.appendChild(t),o=t.innerHTML,r=t.innerText||t.textContent,rt&&(r=r.replace(/\r?\n/g,"\r\n")),e.setData("text/html",o),e.setData("text/plain",r),i.removeChild(t)},ln=function(e){var t,n,o,r,i,a,s,d=e.clipboardData,l=this.getSelection(),c=this._root,u=this;if(l.collapsed)return void e.preventDefault();if(this.saveUndoState(l),dt||nt||!d)setTimeout(function(){try{u._ensureBottomLine()}catch(e){u.didError(e)}},0);else{for(t=It(l,c),n=wt(l,c),o=t===n&&t||c,r=xt(l,c),i=l.commonAncestorContainer,i.nodeType===M&&(i=i.parentNode);i&&i!==o;)a=i.cloneNode(!1),a.appendChild(r),r=a,i=i.parentNode;s=this.createElement("div"),s.appendChild(r),dn(d,s,c),e.preventDefault()}this.setSelection(l)},cn=function(e){var t,n,o,r,i,a,s,d=e.clipboardData,l=this.getSelection(),c=this._root;if(!dt&&!nt&&d){for(t=It(l,c),n=wt(l,c),o=t===n&&t||c,l=l.cloneRange(),Ut(l),Pt(l,o,o,c),r=l.cloneContents(),i=l.commonAncestorContainer,i.nodeType===M&&(i=i.parentNode);i&&i!==o;)a=i.cloneNode(!1),a.appendChild(r),r=a,i=i.parentNode;s=this.createElement("div"),s.appendChild(r),dn(d,s,c),e.preventDefault()}},un=function(e){var t,n,o,r,i,a=e.clipboardData,s=a&&a.items,d=this.isShiftDown,l=!1,c=!1,u=null,h=this;if(!dt&&s){for(e.preventDefault(),t=s.length;t--;){if(n=s[t],o=n.type,!d&&"text/html"===o)return void n.getAsString(function(e){h.insertHTML(e,!0)});"text/plain"===o&&(u=n),!d&&/^image\/.*/.test(o)&&(c=!0)}return void(c?(this.fireEvent("dragover",{dataTransfer:a,preventDefault:function(){l=!0}}),l&&this.fireEvent("drop",{dataTransfer:a})):u&&u.getAsString(function(e){h.insertPlainText(e,!0)}))}if(r=a&&a.types,!dt&&r&&(_t.call(r,"text/html")>-1||!it&&_t.call(r,"text/plain")>-1&&_t.call(r,"text/rtf")<0))return e.preventDefault(),void(!d&&(i=a.getData("text/html"))?this.insertHTML(i,!0):((i=a.getData("text/plain"))||(i=a.getData("text/uri-list")))&&this.insertPlainText(i,!0));this._awaitingPaste=!0;var f=this._doc.body,p=this.getSelection(),g=p.startContainer,m=p.startOffset,v=p.endContainer,_=p.endOffset,C=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(C),p.selectNodeContents(C),this.setSelection(p),setTimeout(function(){try{h._awaitingPaste=!1;for(var e,t,n="",o=C;C=o;)o=C.nextSibling,N(C),e=C.firstChild,e&&e===C.lastChild&&"DIV"===e.nodeName&&(C=e),n+=C.innerHTML;t=h._createRange(g,m,v,_),h.setSelection(t),n&&h.insertHTML(n,!0)}catch(r){h.didError(r)}},0)},hn=function(e){for(var t=e.dataTransfer.types,n=t.length,o=!1,r=!1;n--;)switch(t[n]){case"text/plain":o=!0;break;case"text/html":r=!0;break;default:return}(r||o)&&this.saveUndoState()},fn=D.prototype,pn=function(e,t,n){var o=n._doc,r=e?DOMPurify.sanitize(e,{ALLOW_UNKNOWN_PROTOCOLS:!0,WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}):null;return r?o.importNode(r,!0):o.createDocumentFragment()};fn.setConfig=function(e){return e=x({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},leafNodeNames:St,undo:{documentSizeThreshold:-1,undoLimit:-1},isInsertedHTMLSanitized:!0,isSetHTMLSanitized:!0,sanitizeToDOMFragment:"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?pn:null},e,!0),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},fn.createElement=function(e,t,n){return y(this._doc,e,t,n)},fn.createDefaultBlock=function(e){var t=this._config;return T(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},fn.didError=function(e){console.log(e)},fn.getDocument=function(){return this._doc},fn.getRoot=function(){return this._root},fn.modifyDocument=function(e){var t=this._mutation;t&&(t.takeRecords().length&&this._docWasChanged(),t.disconnect()),this._ignoreAllChanges=!0,e(),this._ignoreAllChanges=!1,t&&(t.observe(this._root,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._ignoreChange=!1)};var gn={pathChange:1,select:1,input:1,undoStateChange:1};fn.fireEvent=function(e,t){var n,o,r,i=this._events[e];if(/^(?:focus|blur)/.test(e))if(n=this._root===this._doc.activeElement,"focus"===e){if(!n||this._isFocused)return this;this._isFocused=!0}else{if(n||!this._isFocused)return this;this._isFocused=!1}if(i)for(t||(t={}),t.type!==e&&(t.type=e),i=i.slice(),o=i.length;o--;){r=i[o];try{r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},fn.destroy=function(){var e,t=this._events;for(e in t)this.removeEventListener(e);this._mutation&&this._mutation.disconnect(),delete this._root.__squire__,this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0},fn.handleEvent=function(e){this.fireEvent(e.type,e)},fn.addEventListener=function(e,t){var n=this._events[e],o=this._root;return t?(n||(n=this._events[e]=[],gn[e]||("selectionchange"===e&&(o=this._doc),o.addEventListener(e,this,!0))),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},fn.removeEventListener=function(e,t){var n,o=this._events[e],r=this._root;if(o){if(t)for(n=o.length;n--;)o[n]===t&&o.splice(n,1);else o.length=0;o.length||(delete this._events[e],gn[e]||("selectionchange"===e&&(r=this._doc),r.removeEventListener(e,this,!0)))}return this},fn._createRange=function(e,t,n,o){if(e instanceof this._win.Range)return e.cloneRange();var r=this._doc.createRange();return r.setStart(e,t),n?r.setEnd(n,o):r.setEnd(e,t),r},fn.getCursorPosition=function(e){if(!e&&!(e=this.getSelection())||!e.getBoundingClientRect)return null;var t,n,o=e.getBoundingClientRect();return o&&!o.top&&(this._ignoreChange=!0,t=this._doc.createElement("SPAN"),t.textContent=X,At(e,t),o=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),L(n,e)),o},fn._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return Ut(n),this.setSelection(n),this},fn.moveCursorToStart=function(){return this._moveCursorTo(!0)},fn.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var mn=function(e){return e._win.getSelection()||null};fn.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused)if(tt&&!this._restoreSelection)R.call(this),this.blur(),this.focus();else{nt&&this._win.focus();var t=mn(this);t&&(t.removeAllRanges(),t.addRange(e))}else R.call(this);return this},fn.getSelection=function(){var e,t,n,o,i=mn(this),a=this._root;return this._isFocused&&i&&i.rangeCount&&(e=i.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&r(t)&&e.setStartBefore(t),n&&r(n)&&e.setEndBefore(n)),e&&m(a,e.commonAncestorContainer)?this._lastSelection=e:(e=this._lastSelection,o=e.commonAncestorContainer,m(o.ownerDocument,o)||(e=null)),e||(e=this._createRange(a.firstChild,0)),e},fn.getSelectedText=function(){var e=this.getSelection();if(!e||e.collapsed)return"";var t,o=new n(e.commonAncestorContainer,q|z,function(t){return Rt(e,t,!0)}),r=e.startContainer,i=e.endContainer,s=o.currentNode=r,d="",l=!1;for(o.filter(s)||(s=o.nextNode());s;)s.nodeType===M?(t=s.data,t&&/\S/.test(t)&&(s===i&&(t=t.slice(0,e.endOffset)),s===r&&(t=t.slice(e.startOffset)),d+=t,l=!0)):("BR"===s.nodeName||l&&!a(s))&&(d+="\n",l=!1),s=o.nextNode();return d},fn.getPath=function(){return this._path};var vn=function(e,t){for(var o,r,i,s=new n(e,q,function(){return!0},!1);r=s.nextNode();)for(;(i=r.data.indexOf(X))>-1&&(!t||r.parentNode!==t);){if(1===r.length){do o=r.parentNode,o.removeChild(r),r=o,s.currentNode=o;while(a(r)&&!_(r));break}r.deleteData(i,1)}};fn._didAddZWS=function(){this._hasZWS=!0},fn._removeZWS=function(){this._hasZWS&&(vn(this._root),this._hasZWS=!1)},fn._updatePath=function(e,t){if(e){var n,o=e.startContainer,r=e.endContainer;(t||o!==this._lastAnchorNode||r!==this._lastFocusNode)&&(this._lastAnchorNode=o,this._lastFocusNode=r,n=o&&r?o===r?v(r,this._root):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),this.fireEvent(e.collapsed?"cursor":"select",{range:e})}},fn._updatePathOnEvent=function(){var e=this;e._isFocused&&!e._willUpdatePath&&(e._willUpdatePath=!0,setTimeout(function(){e._willUpdatePath=!1,e._updatePath(e.getSelection())},0))},fn.focus=function(){return this._root.focus(),ct&&this.fireEvent("focus"),this},fn.blur=function(){return this._root.blur(),ct&&this.fireEvent("blur"),this};var _n="squire-selection-start",Nn="squire-selection-end";fn._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:_n,type:"hidden"}),o=this.createElement("INPUT",{id:Nn,type:"hidden"});At(e,n),e.collapse(!1),At(e,o),n.compareDocumentPosition(o)&w&&(n.id=Nn,o.id=_n,t=n,n=o,o=t),e.setStartAfter(n),e.setEndBefore(o)},fn._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+_n),o=t.querySelector("#"+Nn);if(n&&o){var r=n.parentNode,i=o.parentNode,a=_t.call(r.childNodes,n),s=_t.call(i.childNodes,o);r===i&&(s-=1),N(n),N(o),e||(e=this._doc.createRange()),e.setStart(r,a),e.setEnd(i,s),L(r,e),r!==i&&L(i,e),e.collapsed&&(r=e.startContainer,r.nodeType===M&&(i=r.childNodes[e.startOffset],i&&i.nodeType===M||(i=r.childNodes[e.startOffset-1]),i&&i.nodeType===M&&(e.setStart(i,0),e.collapse(!0))))}return e||null},fn._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},fn._docWasChanged=function(){if(mt&&(kt=new WeakMap),!this._ignoreAllChanges){if(gt&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},fn._recordUndoState=function(e,t){if(!this._isInUndoState||t){var n,o=this._undoIndex,r=this._undoStack,i=this._config.undo,a=i.documentSizeThreshold,s=i.undoLimit; -t||(o+=1),o-1&&2*n.length>a&&s>-1&&o>s&&(r.splice(0,o-s),o=s,this._undoStackLength=s),r[o]=n,this._undoIndex=o,this._undoStackLength+=1,this._isInUndoState=!0}},fn.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._recordUndoState(e,this._isInUndoState),this._getRangeAndRemoveBookmark(e),this},fn.undo=function(){if(0!==this._undoIndex||!this._isInUndoState){this._recordUndoState(this.getSelection(),!1),this._undoIndex-=1,this._setHTML(this._undoStack[this._undoIndex]);var e=this._getRangeAndRemoveBookmark();e&&this.setSelection(e),this._isInUndoState=!0,this.fireEvent("undoStateChange",{canUndo:0!==this._undoIndex,canRedo:!0}),this.fireEvent("input")}return this},fn.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(t>e+1&&this._isInUndoState){this._undoIndex+=1,this._setHTML(this._undoStack[this._undoIndex]);var n=this._getRangeAndRemoveBookmark();n&&this.setSelection(n),this.fireEvent("undoStateChange",{canUndo:!0,canRedo:t>e+2}),this.fireEvent("input")}return this},fn.hasFormat=function(e,t,o){if(e=e.toUpperCase(),t||(t={}),!o&&!(o=this.getSelection()))return!1;!o.collapsed&&o.startContainer.nodeType===M&&o.startOffset===o.startContainer.length&&o.startContainer.nextSibling&&o.setStartBefore(o.startContainer.nextSibling),!o.collapsed&&o.endContainer.nodeType===M&&0===o.endOffset&&o.endContainer.previousSibling&&o.setEndAfter(o.endContainer.previousSibling);var r,i,a=this._root,s=o.commonAncestorContainer;if(g(s,a,e,t))return!0;if(s.nodeType===M)return!1;r=new n(s,q,function(e){return Rt(o,e,!0)},!1);for(var d=!1;i=r.nextNode();){if(!g(i,a,e,t))return!1;d=!0}return d},fn.getFontInfo=function(e){var n,o,r,i={color:t,backgroundColor:t,family:t,size:t},a=0;if(!e&&!(e=this.getSelection()))return i;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===M)for(n.nodeType===M&&(n=n.parentNode);4>a&&n;)(o=n.style)&&(!i.color&&(r=o.color)&&(i.color=r,a+=1),!i.backgroundColor&&(r=o.backgroundColor)&&(i.backgroundColor=r,a+=1),!i.family&&(r=o.fontFamily)&&(i.family=r,a+=1),!i.size&&(r=o.fontSize)&&(i.size=r,a+=1)),n=n.parentNode;return i},fn._addFormat=function(e,t,o){var r,i,s,d,l,c,u,h,f,p=this._root;if(o.collapsed){for(r=T(this.createElement(e,t),p),At(o,r),o.setStart(r.firstChild,r.firstChild.length),o.collapse(!0),f=r;a(f);)f=f.parentNode;vn(f,r)}else{if(i=new n(o.commonAncestorContainer,q|z,function(e){return(e.nodeType===M||"BR"===e.nodeName||"IMG"===e.nodeName)&&Rt(o,e,!0)},!1),s=o.startContainer,l=o.startOffset,d=o.endContainer,c=o.endOffset,i.currentNode=s,i.filter(s)||(s=i.nextNode(),l=0),!s)return o;do u=i.currentNode,h=!g(u,p,e,t),h&&(u===d&&u.length>c&&u.splitText(c),u===s&&l&&(u=u.splitText(l),d===s&&(d=u,c-=l),s=u,l=0),r=this.createElement(e,t),C(u,r),r.appendChild(u));while(i.nextNode());d.nodeType!==M&&(u.nodeType===M?(d=u,c=u.length):(d=u.parentNode,c=1)),o=this._createRange(s,l,d,c)}return o},fn._removeFormat=function(e,t,n,o){this._saveRangeToBookmark(n);var r,i=this._doc;n.collapsed&&(ft?(r=i.createTextNode(X),this._didAddZWS()):r=i.createTextNode(""),At(n,r));for(var s=n.commonAncestorContainer;a(s);)s=s.parentNode;var d=n.startContainer,l=n.startOffset,c=n.endContainer,u=n.endOffset,h=[],f=function(e,t){if(!Rt(n,e,!1)){var o,r,i=e.nodeType===M;if(!Rt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||h.push([t,e]));if(i)e===c&&u!==e.length&&h.push([t,e.splitText(u)]),e===d&&l&&(e.splitText(l),h.push([t,e]));else for(o=e.firstChild;o;o=r)r=o.nextSibling,f(o,t)}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(o){return Rt(n,o,!0)&&p(o,e,t)});return o||g.forEach(function(e){f(e,e)}),h.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];C(n,t),t.appendChild(n)}),g.forEach(function(e){C(e,S(e))}),this._getRangeAndRemoveBookmark(n),r&&n.collapse(!1),L(s,n),n},fn.changeFormat=function(e,t,n,o){return n||(n=this.getSelection())?(this.saveUndoState(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,o)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),gt||this._docWasChanged(),this):this};var Cn={DT:"DD",DD:"DT",LI:"LI"},Sn=function(e,t,n,o){var r=Cn[t.nodeName],i=null,a=b(n,o,t.parentNode,e._root),s=e._config;return r||(r=s.blockTag,i=s.blockAttributes),p(a,r,i)||(t=y(a.ownerDocument,r,i),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(S(a)),a=t),a};fn.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var o=this._root,r=It(n,o),i=wt(n,o);if(r&&i)do if(e(r)||r===i)break;while(r=u(r,o));return t&&(this.setSelection(n),this._updatePath(n,!0),gt||this._docWasChanged()),this},fn.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._recordUndoState(t,this._isInUndoState);var n,o=this._root;return Wt(t,o),Pt(t,o,o,o),n=Ot(t,o,o),At(t,e.call(this,n)),t.endOffsett;t+=1)o=a[t],r=S(o),E(r,l),C(o,r);for(t=0,n=d.length;n>t;t+=1)i=d[t],s(i)?C(i,this.createDefaultBlock([S(i)])):(E(i,l),C(i,S(i)));return e},An=function(e){var t,n,o,r,i,a,s=e.querySelectorAll("LI"),l=this._config.tagAttributes;for(t=0,n=s.length;n>t;t+=1)o=s[t],d(o.firstChild)||(r=o.parentNode.nodeName,i=o.previousSibling,i&&(i=i.lastChild)&&i.nodeName===r||(a=l[r.toLowerCase()],i=this.createElement(r,a),C(o,i)),i.appendChild(o));return e},On=function(e){var t=this._root,n=e.querySelectorAll("LI");return Array.prototype.filter.call(n,function(e){return!d(e.firstChild)}).forEach(function(n){var o,r=n.parentNode,i=r.parentNode,a=n.firstChild,s=a;if(n.previousSibling&&(r=b(r,n,i,t)),/^[OU]L$/.test(i.nodeName))i.insertBefore(n,r),r.firstChild||i.removeChild(r);else for(;s&&(o=s.nextSibling,!d(s));)i.insertBefore(s,r),s=o;for("LI"===i.nodeName&&a.previousSibling&&b(i,a,i.parentNode,t);n!==e&&!n.childNodes.length;)r=n.parentNode,r.removeChild(n),n=r},this),E(e,t),e};fn._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&s(t)||e.appendChild(this.createDefaultBlock())},fn.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},fn._getHTML=function(){return this._root.innerHTML},fn._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do T(n,t);while(n=u(n,t));this._ignoreChange=!0},fn.getHTML=function(e){var t,n,o,r,i,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),ht)for(t=this._root,n=t;n=u(n,t);)n.textContent||n.querySelector("BR")||(o=this.createElement("BR"),n.appendChild(o),s.push(o));if(r=this._getHTML().replace(/\u200B/g,""),ht)for(i=s.length;i--;)N(s[i]);return a&&this._getRangeAndRemoveBookmark(a),r},fn.setHTML=function(e){var t,n,o,r=this._config,i=r.isSetHTMLSanitized?r.sanitizeToDOMFragment:null,a=this._root;"function"==typeof i?n=i(e,!1,this):(t=this.createElement("DIV"),t.innerHTML=e,n=this._doc.createDocumentFragment(),n.appendChild(S(t))),nn(n),sn(n,a,!1),E(n,a);for(var s=n;s=u(s,a);)T(s,a);for(this._ignoreChange=!0;o=a.lastChild;)a.removeChild(o);a.appendChild(n),T(a,a),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;var d=this._getRangeAndRemoveBookmark()||this._createRange(a.firstChild,0);return this.saveUndoState(d),this._lastSelection=d,R.call(this),this._updatePath(d,!0),this},fn.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),a(e))At(t,e),t.setStartAfter(e);else{for(var n,o,r=this._root,i=It(t,r)||r;i!==r&&!i.nextSibling;)i=i.parentNode;i!==r&&(n=i.parentNode,o=b(n,i.nextSibling,r,r)),o?r.insertBefore(e,o):(r.appendChild(e),o=this.createDefaultBlock(),r.appendChild(o)),t.setStart(o,0),t.setEnd(o,0),Ut(t)}return this.focus(),this.setSelection(t),this._updatePath(t),gt||this._docWasChanged(),this},fn.insertImage=function(e,t){var n=this.createElement("IMG",x({src:e},t,!0));return this.insertElement(n),n};var xn=/\b((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)/i,Dn=function(e,t,o){for(var r,i,a,s,d,l,c,u=e.ownerDocument,h=new n(e,q,function(e){return!g(e,t,"A")},!1),f=o._config.tagAttributes.a;r=h.nextNode();)for(i=r.data,a=r.parentNode;s=xn.exec(i);)d=s.index,l=d+s[0].length,d&&(c=u.createTextNode(i.slice(0,d)),a.insertBefore(c,r)),c=o.createElement("A",x({href:s[1]?/^(?:ht|f)tps?:/.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[2]},f,!1)),c.textContent=i.slice(d,l),a.insertBefore(c,r),r.data=i=i.slice(l)};fn.insertHTML=function(e,t){var n,o,r,i,a,s,d,l=this._config,c=l.isInsertedHTMLSanitized?l.sanitizeToDOMFragment:null,h=this.getSelection(),f=this._doc;"function"==typeof c?i=c(e,t,this):(t&&(n=e.indexOf(""),o=e.lastIndexOf(""),n>-1&&o>-1&&(e=e.slice(n+20,o))),/<\/td>((?!<\/tr>)[\s\S])*$/i.test(e)&&(e=""+e+""),/<\/tr>((?!<\/table>)[\s\S])*$/i.test(e)&&(e=""+e+"
"),r=this.createElement("DIV"),r.innerHTML=e,i=f.createDocumentFragment(),i.appendChild(S(r))),this.saveUndoState(h);try{for(a=this._root,s=i,d={fragment:i,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},Dn(i,i,this),nn(i),sn(i,a,!1),on(i),i.normalize();s=u(s,i);)T(s,a);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(Dt(h,d.fragment,a),gt||this._docWasChanged(),h.collapse(!1),this._ensureBottomLine()),this.setSelection(h),this._updatePath(h,!0),t&&this.focus()}catch(p){this.didError(p)}return this};var Rn=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};fn.insertPlainText=function(e,t){var n,o,r,i,a=e.split("\n"),s=this._config,d=s.blockTag,l=s.blockAttributes,c="",u="<"+d;for(n in l)u+=" "+n+'="'+Rn(l[n])+'"';for(u+=">",o=0,r=a.length;r>o;o+=1)i=a[o],i=Rn(i).replace(/ (?= )/g," "),a[o]=u+(i||"
")+c;return this.insertHTML(a.join(""),t)};var Un=function(e,t,n){return function(){return this[e](t,n),this.focus()}};fn.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.appendChild(this._doc.createTextNode(e)),t.appendChild(n)}return this},fn.bold=Un("changeFormat",{tag:"B"}),fn.italic=Un("changeFormat",{tag:"I"}),fn.underline=Un("changeFormat",{tag:"U"}),fn.strikethrough=Un("changeFormat",{tag:"S"}),fn.subscript=Un("changeFormat",{tag:"SUB"},{tag:"SUP"}),fn.superscript=Un("changeFormat",{tag:"SUP"},{tag:"SUB"}),fn.removeBold=Un("changeFormat",null,{tag:"B"}),fn.removeItalic=Un("changeFormat",null,{tag:"I"}),fn.removeUnderline=Un("changeFormat",null,{tag:"U"}),fn.removeStrikethrough=Un("changeFormat",null,{tag:"S"}),fn.removeSubscript=Un("changeFormat",null,{tag:"SUB"}),fn.removeSuperscript=Un("changeFormat",null,{tag:"SUP"}),fn.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var o=e.indexOf(":")+1;if(o)for(;"/"===e[o];)o+=1;At(n,this._doc.createTextNode(e.slice(o)))}return t=x(x({href:e},t,!0),this._config.tagAttributes.a,!1),this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},fn.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},fn.setFontFace=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":V,style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{"class":V}}),this.focus()},fn.setFontSize=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":Y,style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{"class":Y}}),this.focus()},fn.setTextColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":$,style:"color:"+e}}:null,{tag:"SPAN",attributes:{"class":$}}),this.focus()},fn.setHighlightColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":Q,style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{"class":Q}}),this.focus()},fn.setTextAlignment=function(e){return this.forEachBlock(function(t){var n=t.className.split(/\s+/).filter(function(e){return!!e&&!/^align/.test(e)}).join(" ");e?(t.className=n+" align-"+e,t.style.textAlign=e):(t.className=n,t.style.textAlign="")},!0),this.focus()},fn.setTextDirection=function(e){return this.forEachBlock(function(t){e?t.dir=e:t.removeAttribute("dir")},!0),this.focus()},fn.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=this._root,n=e.commonAncestorContainer;n&&!s(n);)n=n.parentNode;if(n||(Wt(e,t),n=t),n.nodeType===M)return this;this.saveUndoState(e),Pt(e,n,n,t);for(var o,r,i=n.ownerDocument,a=e.startContainer,d=e.startOffset,l=e.endContainer,c=e.endOffset,u=i.createDocumentFragment(),h=i.createDocumentFragment(),f=b(l,c,n,t),p=b(a,d,n,t);p!==f;)o=p.nextSibling,u.appendChild(p),p=o;return I(this,u,h),h.normalize(),p=h.firstChild,o=h.lastChild,r=n.childNodes,p?(n.insertBefore(h,f),d=_t.call(r,p),c=_t.call(r,o)+1):(d=_t.call(r,f),c=d),e.setStart(n,d),e.setEnd(n,c),L(n,e),Ut(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},fn.increaseQuoteLevel=Un("modifyBlocks",yn),fn.decreaseQuoteLevel=Un("modifyBlocks",Tn),fn.makeUnorderedList=Un("modifyBlocks",kn),fn.makeOrderedList=Un("modifyBlocks",Ln),fn.removeList=Un("modifyBlocks",Bn),fn.increaseListLevel=Un("modifyBlocks",An),fn.decreaseListLevel=Un("modifyBlocks",On),D.isInline=a,D.isBlock=s,D.isContainer=d,D.getBlockWalker=l,D.getPreviousBlock=c,D.getNextBlock=u,D.areAlike=f,D.hasTagAttributes=p,D.getNearest=g,D.isOrContains=m,D.detach=N,D.replaceWith=C,D.empty=S,D.getNodeBefore=Lt,D.getNodeAfter=Bt,D.insertNodeInRange=At,D.extractContentsOfRange=Ot,D.deleteContentsOfRange=xt,D.insertTreeFragmentIntoRange=Dt,D.isNodeContainedInRange=Rt,D.moveRangeBoundariesDownTree=Ut,D.moveRangeBoundariesUpTree=Pt,D.getStartBlockOfRange=It,D.getEndBlockOfRange=wt,D.contentWalker=Ft,D.rangeDoesStartAtBlockBoundary=Mt,D.rangeDoesEndAtBlockBoundary=Ht,D.expandRangeToBlockBoundaries=Wt,D.onPaste=un,D.addLinks=Dn,D.splitBlock=Sn,D.startSelectionId=_n,D.endSelectionId=Nn,"object"==typeof exports?module.exports=D:"function"==typeof define&&define.amd?define(function(){return D}):(J.Squire=D,top!==J&&"true"===e.documentElement.getAttribute("data-squireinit")&&(J.editor=new D(e),J.onEditorLoad&&(J.onEditorLoad(J.editor),J.onEditorLoad=null)))}(document); \ No newline at end of file +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function o(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function i(e){return e.nodeType===F&&!!St[e.nodeName]}function r(e){switch(e.nodeType){case M:return yt;case F:case W:if(mt&&kt.has(e))return kt.get(e);break;default:return Tt}var t;return t=o(e.childNodes,a)?Ct.test(e.nodeName)?yt:Et:bt,mt&&kt.set(e,t),t}function a(e){return r(e)===yt}function s(e){return r(e)===Et}function d(e){return r(e)===bt}function l(e,t){var o=new n(t,z,s);return o.currentNode=e,o}function c(e,t){return e=l(e,t).previousNode(),e!==t?e:null}function h(e,t){return e=l(e,t).nextNode(),e!==t?e:null}function u(e){return!e.textContent&&!e.querySelector("IMG")}function f(e,t){return!i(e)&&e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&"A"!==e.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function p(e,t,n){if(e.nodeName!==t)return!1;for(var o in n)if(e.getAttribute(o)!==n[o])return!1;return!0}function g(e,t,n,o){for(;e&&e!==t;){if(p(e,n,o))return e;e=e.parentNode}return null}function m(e,t){for(;t;){if(t===e)return!0;t=t.parentNode}return!1}function v(e,t){var n,o,i,r,a="";return e&&e!==t&&(a=v(e.parentNode,t),e.nodeType===F&&(a+=(a?">":"")+e.nodeName,(n=e.id)&&(a+="#"+n),(o=e.className.trim())&&(i=o.split(/\s\s*/),i.sort(),a+=".",a+=i.join(".")),(r=e.dir)&&(a+="[dir="+r+"]"),i&&(_t.call(i,$)>-1&&(a+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),_t.call(i,Q)>-1&&(a+="[color="+e.style.color.replace(/ /g,"")+"]"),_t.call(i,V)>-1&&(a+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),_t.call(i,Y)>-1&&(a+="[fontSize="+e.style.fontSize+"]")))),a}function _(e){var t=e.nodeType;return t===F||t===W?e.childNodes.length:e.length||0}function N(e){var t=e.parentNode;return t&&t.removeChild(e),e}function C(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,o=n?n.length:0;o--;)t.appendChild(e.firstChild);return t}function T(e,n,o,i){var r,a,s,d,l=e.createElement(n);if(o instanceof Array&&(i=o,o=null),o)for(r in o)a=o[r],a!==t&&l.setAttribute(r,o[r]);if(i)for(s=0,d=i.length;d>s;s+=1)l.appendChild(i[s]);return l}function y(e,t){var n,o,r=t.__squire__,s=e.ownerDocument,d=e;if(e===t&&((o=e.firstChild)&&"BR"!==o.nodeName||(n=r.createDefaultBlock(),o?e.replaceChild(n,o):e.appendChild(n),e=n,n=null)),e.nodeType===M)return d;if(a(e)){for(o=e.firstChild;ft&&o&&o.nodeType===M&&!o.data;)e.removeChild(o),o=e.firstChild;o||(ft?(n=s.createTextNode(X),r._didAddZWS()):n=s.createTextNode(""))}else if(ut){for(;e.nodeType!==M&&!i(e);){if(o=e.firstChild,!o){n=s.createTextNode("");break}e=o}e.nodeType===M?/^ +$/.test(e.data)&&(e.data=""):i(e)&&e.parentNode.insertBefore(s.createTextNode(""),e)}else if(!e.querySelector("BR"))for(n=T(s,"BR");(o=e.lastElementChild)&&!a(o);)e=o;if(n)try{e.appendChild(n)}catch(l){r.didError({name:"Squire: fixCursor – "+l,message:"Parent: "+e.nodeName+"/"+e.innerHTML+" appendChild: "+n.nodeName})}return d}function E(e,t){var n,o,i,r,s=e.childNodes,l=e.ownerDocument,c=null,h=t.__squire__._config;for(n=0,o=s.length;o>n;n+=1)i=s[n],r="BR"===i.nodeName,!r&&a(i)?(c||(c=T(l,h.blockTag,h.blockAttributes)),c.appendChild(i),n-=1,o-=1):(r||c)&&(c||(c=T(l,h.blockTag,h.blockAttributes)),y(c,t),r?e.replaceChild(c,i):(e.insertBefore(c,i),n+=1,o+=1),c=null),d(i)&&E(i,t);return c&&e.appendChild(y(c,t)),e}function b(e,t,n,o){var i,r,a,s=e.nodeType;if(s===M&&e!==n)return b(e.parentNode,e.splitText(t),n,o);if(s===F){if("number"==typeof t&&(t=ts?t.startOffset-=1:t.startOffset===s&&(t.startContainer=o,t.startOffset=_(o))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=o,t.endOffset=_(o))),N(n),n.nodeType===M?o.appendData(n.data):d.push(S(n));else if(n.nodeType===F){for(i=d.length;i--;)n.appendChild(d.pop());k(n,t)}}function L(e,t){if(e.nodeType===M&&(e=e.parentNode),e.nodeType===F){var n={startContainer:t.startContainer,startOffset:t.startOffset,endContainer:t.endContainer,endOffset:t.endOffset};k(e,n),t.setStart(n.startContainer,n.startOffset),t.setEnd(n.endContainer,n.endOffset)}}function x(e,t,n,o){for(var i,r,a,s=t;(i=s.parentNode)&&i!==o&&i.nodeType===F&&1===i.childNodes.length;)s=i;N(s),a=e.childNodes.length,r=e.lastChild,r&&"BR"===r.nodeName&&(e.removeChild(r),a-=1),e.appendChild(S(t)),n.setStart(e,a),n.collapse(!0),L(e,n),st&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function O(e,t){var n,o,i=e.previousSibling,r=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||r&&/^[OU]L$/.test(r.nodeName))if(i&&f(i,e)){if(!d(i)){if(!s)return;o=T(a,"DIV"),o.appendChild(S(i)),i.appendChild(o)}N(e),n=!d(e),i.appendChild(S(e)),n&&E(i,t),r&&O(r,t)}else s&&(i=T(a,"DIV"),e.insertBefore(i,r),y(i,t))}function A(e){this.isShiftDown=e.shiftKey}function B(e,t,n){var o,i;if(e||(e={}),t)for(o in t)!n&&o in e||(i=t[o],e[o]=i&&i.constructor===Object?B(e[o],i,n):i);return e}function D(e,t){e.nodeType===H&&(e=e.body);var n,o=e.ownerDocument,i=o.defaultView;this._win=i,this._doc=o,this._root=e,this._events={},this._isFocused=!1,this._lastSelection=null,pt&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this._willUpdatePath=!1,"onselectionchange"in o?this.addEventListener("selectionchange",this._updatePathOnEvent):(this.addEventListener("keyup",this._updatePathOnEvent),this.addEventListener("mouseup",this._updatePathOnEvent)),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,this._ignoreAllChanges=!1,gt?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(e,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._restoreSelection=!1,this.addEventListener("blur",R),this.addEventListener("mousedown",U),this.addEventListener("touchstart",U),this.addEventListener("focus",P),this._awaitingPaste=!1,this.addEventListener(at?"beforecut":"cut",ln),this.addEventListener("copy",cn),this.addEventListener("keydown",A),this.addEventListener("keyup",A),this.addEventListener(at?"beforepaste":"paste",hn),this.addEventListener("drop",un),this.addEventListener(st?"keypress":"keydown",qt),this._keyHandlers=Object.create(jt),this.setConfig(t),at&&(i.Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,o=this.parentNode,i=this.length-e;return n?o.insertBefore(t,n):o.appendChild(t),i&&this.deleteData(e,i),t}),e.setAttribute("contenteditable","true");try{o.execCommand("enableObjectResizing",!1,"false"),o.execCommand("enableInlineTableEditing",!1,"false")}catch(r){}e.__squire__=this,this.setHTML("")}function R(){this._restoreSelection=!0}function U(){this._restoreSelection=!1}function P(){this._restoreSelection&&this.setSelection(this._lastSelection)}function I(e,t,n){var o,i;for(o=t.firstChild;o;o=i){if(i=o.nextSibling,a(o)){if(o.nodeType===M||"BR"===o.nodeName||"IMG"===o.nodeName){n.appendChild(o);continue}}else if(s(o)){n.appendChild(e.createDefaultBlock([I(e,o,e._doc.createDocumentFragment())]));continue}I(e,o,n)}return n}var w=2,F=1,M=3,H=9,W=11,z=1,q=4,K=0,G=1,Z=2,j=3,$="highlight",Q="colour",V="font",Y="size",X="​",J=e.defaultView,et=navigator.userAgent,tt=/Android/.test(et),nt=/iP(?:ad|hone|od)/.test(et),ot=/Mac OS X/.test(et),it=/Windows NT/.test(et),rt=/Gecko\//.test(et),at=/Trident\/[456]\./.test(et),st=!!J.opera,dt=/Edge\//.test(et),lt=!dt&&/WebKit\//.test(et),ct=/Trident\/[4567]\./.test(et),ht=ot?"meta-":"ctrl-",ut=at||st,ft=at||lt,pt=at,gt="undefined"!=typeof MutationObserver,mt="undefined"!=typeof WeakMap,vt=/[^ \t\r\n]/,_t=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var Nt={1:1,2:2,3:4,8:128,9:256,11:1024};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,o=this.nodeType,i=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)e=t.nextSibling,e||(t=t.parentNode);if(!e)return null;if(Nt[e.nodeType]&o&&i(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,o=this.nodeType,i=this.filter;;){if(t===n)return null;if(e=t.previousSibling)for(;t=e.lastChild;)e=t;else e=t.parentNode;if(!e)return null;if(Nt[e.nodeType]&o&&i(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,o=this.nodeType,i=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)e=t.previousSibling,e||(t=t.parentNode);if(!e)return null;if(Nt[e.nodeType]&o&&i(e))return this.currentNode=e,e;t=e}};var Ct=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|TIME|U|VAR|WBR)$/,St={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},Tt=0,yt=1,Et=2,bt=3,kt=mt?new WeakMap:null,Lt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===F;)e=n[t-1],n=e.childNodes,t=n.length;return e},xt=function(e,t){if(e.nodeType===F){var n=e.childNodes;if(t-1,r=e.compareBoundaryPoints(G,o)<1;return!i&&!r}var a=e.compareBoundaryPoints(K,o)<1,s=e.compareBoundaryPoints(Z,o)>-1;return a&&s},Ut=function(e){for(var t,n=e.startContainer,o=e.startOffset,r=e.endContainer,a=e.endOffset,s=!0;n.nodeType!==M&&(t=n.childNodes[o],t&&!i(t));)n=t,o=0;if(a)for(;r.nodeType!==M;){if(t=r.childNodes[a-1],!t||i(t)){if(s&&t&&"BR"===t.nodeName){a-=1,s=!1;continue}break}r=t,a=_(r)}else for(;r.nodeType!==M&&(t=r.firstChild,t&&!i(t));)r=t;e.collapsed?(e.setStart(r,a),e.setEnd(n,o)):(e.setStart(n,o),e.setEnd(r,a))},Pt=function(e,t,n,o){var i,r=e.startContainer,a=e.startOffset,s=e.endContainer,d=e.endOffset,l=!0;for(t||(t=e.commonAncestorContainer),n||(n=t);!a&&r!==t&&r!==o;)i=r.parentNode,a=_t.call(i.childNodes,r),r=i;for(;;){if(l&&s.nodeType!==M&&s.childNodes[d]&&"BR"===s.childNodes[d].nodeName&&(d+=1,l=!1),s===n||s===o||d!==_(s))break;i=s.parentNode,d=_t.call(i.childNodes,s)+1,s=i}e.setStart(r,a),e.setEnd(s,d)},It=function(e,t){var n,o=e.startContainer;return a(o)?n=c(o,t):o!==t&&s(o)?n=o:(n=Lt(o,e.startOffset),n=h(n,t)),n&&Rt(e,n,!0)?n:null},wt=function(e,t){var n,o,i=e.endContainer;if(a(i))n=c(i,t);else if(i!==t&&s(i))n=i;else{if(n=xt(i,e.endOffset),!n||!m(t,n))for(n=t;o=n.lastChild;)n=o;n=c(n,t)}return n&&Rt(e,n,!0)?n:null},Ft=new n(null,q|z,function(e){return e.nodeType===M?vt.test(e.data):"IMG"===e.nodeName}),Mt=function(e,t){var n,o=e.startContainer,i=e.startOffset;if(Ft.root=null,o.nodeType===M){if(i)return!1;n=o}else if(n=xt(o,i),n&&!m(t,n)&&(n=null),!n&&(n=Lt(o,i),n.nodeType===M&&n.length))return!1;return Ft.currentNode=n,Ft.root=It(e,t),!Ft.previousNode()},Ht=function(e,t){var n,o=e.endContainer,i=e.endOffset;if(Ft.root=null,o.nodeType===M){if(n=o.data.length,n&&n>i)return!1;Ft.currentNode=o}else Ft.currentNode=Lt(o,i);return Ft.root=wt(e,t),!Ft.nextNode()},Wt=function(e,t){var n,o=It(e,t),i=wt(e,t);o&&i&&(n=o.parentNode,e.setStart(n,_t.call(n.childNodes,o)),n=i.parentNode,e.setEnd(n,_t.call(n.childNodes,i)+1))},zt={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},qt=function(e){var t=e.keyCode,n=zt[t],o="",i=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),st&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(o+="alt-"),e.ctrlKey&&(o+="ctrl-"),e.metaKey&&(o+="meta-")),e.shiftKey&&(o+="shift-"),n=o+n,this._keyHandlers[n]?this._keyHandlers[n](this,e,i):1!==n.length||i.collapsed||(this.saveUndoState(i),Bt(i,this._root),this._ensureBottomLine(),this.setSelection(i),this._updatePath(i,!0)))},Kt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Gt=function(e,t){return t=t||null,function(n,o){o.preventDefault();var i=n.getSelection();n.hasFormat(e,null,i)?n.changeFormat(null,{tag:e},i):n.changeFormat({tag:e},t,i)}},Zt=function(e,t){try{t||(t=e.getSelection());var n,o=t.startContainer;for(o.nodeType===M&&(o=o.parentNode),n=o;a(n)&&(!n.textContent||n.textContent===X);)o=n,n=o.parentNode;o!==n&&(t.setStart(n,_t.call(n.childNodes,o)),t.collapse(!0),n.removeChild(o),s(n)||(n=c(n,e._root)),y(n,e._root),Ut(t)),o===e._root&&(o=o.firstChild)&&"BR"===o.nodeName&&N(o),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(i){e.didError(i)}},jt={enter:function(e,t,n){var o,i,r,a=e._root;if(t.preventDefault(),e._recordUndoState(n),Bn(n.startContainer,a,e),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||Bt(n,a),o=It(n,a),!o||/^T[HD]$/.test(o.nodeName))return i=g(n.endContainer,a,"A"),i&&(i=i.parentNode,Pt(n,i,i,a),n.collapse(!1)),Ot(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((i=g(o,a,"LI"))&&(o=i),u(o)){if(g(o,a,"UL")||g(o,a,"OL"))return e.decreaseListLevel(n);if(g(o,a,"BLOCKQUOTE"))return e.modifyBlocks(En,n)}for(r=Sn(e,o,n.startContainer,n.startOffset),vn(o),on(o),y(o,a);r.nodeType===F;){var s,d=r.firstChild;if("A"===r.nodeName&&(!r.textContent||r.textContent===X)){d=e._doc.createTextNode(""),C(r,d),r=d;break}for(;d&&d.nodeType===M&&!d.data&&(s=d.nextSibling,s&&"BR"!==s.nodeName);)N(d),d=s;if(!d||"BR"===d.nodeName||d.nodeType===M&&!st)break;r=d}n=e._createRange(r,0),e.setSelection(n),e._updatePath(n,!0)},backspace:function(e,t,n){var o=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Mt(n,o)){t.preventDefault();var i,r=It(n,o);if(!r)return;if(E(r.parentNode,o),i=c(r,o)){if(!i.isContentEditable)return void N(i);for(x(i,r,n,o),r=i.parentNode;r!==o&&!r.nextSibling;)r=r.parentNode;r!==o&&(r=r.nextSibling)&&O(r,o),e.setSelection(n)}else if(r){if(g(r,o,"UL")||g(r,o,"OL"))return e.decreaseListLevel(n);if(g(r,o,"BLOCKQUOTE"))return e.modifyBlocks(yn,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Zt(e)},0);else t.preventDefault(),Bt(n,o),Zt(e,n)},"delete":function(e,t,n){var o,i,r,a,s,d,l=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Ht(n,l)){if(t.preventDefault(),o=It(n,l),!o)return;if(E(o.parentNode,l),i=h(o,l)){if(!i.isContentEditable)return void N(i);for(x(o,i,n,l),i=o.parentNode;i!==l&&!i.nextSibling;)i=i.parentNode;i!==l&&(i=i.nextSibling)&&O(i,l),e.setSelection(n),e._updatePath(n,!0)}}else{if(r=n.cloneRange(),Pt(n,l,l,l),a=n.endContainer,s=n.endOffset,a.nodeType===F&&(d=a.childNodes[s],d&&"IMG"===d.nodeName))return t.preventDefault(),N(d),Ut(n),void Zt(e,n);e.setSelection(r),setTimeout(function(){Zt(e)},0)}else t.preventDefault(),Bt(n,l),Zt(e,n)},tab:function(e,t,n){var o,i,r=e._root;if(e._removeZWS(),n.collapsed&&Mt(n,r))for(o=It(n,r);i=o.parentNode;){if("UL"===i.nodeName||"OL"===i.nodeName){t.preventDefault(),e.increaseListLevel(n);break}o=i}},"shift-tab":function(e,t,n){var o,i=e._root;e._removeZWS(),n.collapsed&&Mt(n,i)&&(o=n.startContainer,(g(o,i,"UL")||g(o,i,"OL"))&&(t.preventDefault(),e.decreaseListLevel(n)))},space:function(e,t,n){var o,i;e._recordUndoState(n),Bn(n.startContainer,e._root,e),e._getRangeAndRemoveBookmark(n),o=n.endContainer,i=o.parentNode,n.collapsed&&"A"===i.nodeName&&!o.nextSibling&&n.endOffset===_(o)?n.setStartAfter(i):n.collapsed||(Bt(n,e._root),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};ot&&rt&&(jt["meta-left"]=function(e,t){t.preventDefault();var n=mn(e);n&&n.modify&&n.modify("move","backward","lineboundary")},jt["meta-right"]=function(e,t){t.preventDefault();var n=mn(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),ot||(jt.pageup=function(e){e.moveCursorToStart()},jt.pagedown=function(e){e.moveCursorToEnd()}),jt[ht+"b"]=Gt("B"),jt[ht+"i"]=Gt("I"),jt[ht+"u"]=Gt("U"),jt[ht+"shift-7"]=Gt("S"),jt[ht+"shift-5"]=Gt("SUB",{tag:"SUP"}),jt[ht+"shift-6"]=Gt("SUP",{tag:"SUB"}),jt[ht+"shift-8"]=Kt("makeUnorderedList"),jt[ht+"shift-9"]=Kt("makeOrderedList"),jt[ht+"["]=Kt("decreaseQuoteLevel"),jt[ht+"]"]=Kt("increaseQuoteLevel"),jt[ht+"y"]=Kt("redo"),jt[ht+"z"]=Kt("undo"),jt[ht+"shift-z"]=Kt("redo");var $t={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Qt={backgroundColor:{regexp:vt,replace:function(e,t){return T(e,"SPAN",{"class":$,style:"background-color:"+t})}},color:{regexp:vt,replace:function(e,t){return T(e,"SPAN",{"class":Q,style:"color:"+t})}},fontWeight:{regexp:/^bold|^700/i,replace:function(e){return T(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return T(e,"I")}},fontFamily:{regexp:vt,replace:function(e,t){return T(e,"SPAN",{"class":V,style:"font-family:"+t})}},fontSize:{regexp:vt,replace:function(e,t){return T(e,"SPAN",{"class":Y,style:"font-size:"+t})}},textDecoration:{regexp:/^underline/i,replace:function(e){return T(e,"U")}}},Vt=function(e){return function(t,n){var o=T(t.ownerDocument,e);return n.replaceChild(o,t),o.appendChild(S(t)),o}},Yt=function(e,t){var n,o,i,r,a,s,d=e.style,l=e.ownerDocument;for(n in Qt)o=Qt[n],i=d[n],i&&o.regexp.test(i)&&(s=o.replace(l,i),a||(a=s),r&&r.appendChild(s),r=s,e.style[n]="");return a&&(r.appendChild(S(e)),"SPAN"===e.nodeName?t.replaceChild(a,e):e.appendChild(a)),r||e},Xt={P:Yt,SPAN:Yt,STRONG:Vt("B"),EM:Vt("I"),INS:Vt("U"),STRIKE:Vt("S"),FONT:function(e,t){var n,o,i,r,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=T(c,"SPAN",{"class":V,style:"font-family:"+s}),a=n,r=n),d&&(o=T(c,"SPAN",{"class":Y,style:"font-size:"+$t[d]+"px"}),a||(a=o),r&&r.appendChild(o),r=o),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),i=T(c,"SPAN",{"class":Q,style:"color:"+l}),a||(a=i),r&&r.appendChild(i),r=i),a||(a=r=T(c,"SPAN")),t.replaceChild(a,e),r.appendChild(S(e)),r},TT:function(e,t){var n=T(e.ownerDocument,"SPAN",{"class":V,style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(S(e)),n}},Jt=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|IGCAPTION|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|COL(?:GROUP)?|UL)$/,en=/^(?:HEAD|META|STYLE)/,tn=new n(null,q|z,function(){return!0}),nn=function Un(e,t){var n,o,i,r,s,d,l,c,h,u,f,p,g=e.childNodes;for(n=e;a(n);)n=n.parentNode;for(tn.root=n,o=0,i=g.length;i>o;o+=1)if(r=g[o],s=r.nodeName,d=r.nodeType,l=Xt[s],d===F){if(c=r.childNodes.length,l)r=l(r,e);else{if(en.test(s)){e.removeChild(r),o-=1,i-=1;continue}if(!Jt.test(s)&&!a(r)){o-=1,i+=c-1,e.replaceChild(S(r),r);continue}}c&&Un(r,t||"PRE"===s)}else{if(d===M){if(f=r.data,h=!vt.test(f.charAt(0)),u=!vt.test(f.charAt(f.length-1)),t||!h&&!u)continue;if(h){for(tn.currentNode=r;(p=tn.previousPONode())&&(s=p.nodeName,!("IMG"===s||"#text"===s&&vt.test(p.data)));)if(!a(p)){p=null;break}f=f.replace(/^[ \t\r\n]+/g,p?" ":"")}if(u){for(tn.currentNode=r;(p=tn.nextNode())&&!("IMG"===s||"#text"===s&&vt.test(p.data));)if(!a(p)){p=null;break}f=f.replace(/[ \t\r\n]+$/g,p?" ":"")}if(f){r.data=f;continue}}e.removeChild(r),o-=1,i-=1}return e},on=function Pn(e){for(var t,n=e.childNodes,o=n.length;o--;)t=n[o],t.nodeType!==F||i(t)?t.nodeType!==M||t.data||e.removeChild(t):(Pn(t),a(t)&&!t.firstChild&&e.removeChild(t))},rn=function(e){return e.nodeType===F?"BR"===e.nodeName:vt.test(e.data)},an=function(e,t){for(var o,i=e.parentNode;a(i);)i=i.parentNode;return o=new n(i,z|q,rn),o.currentNode=e,!!o.nextNode()||t&&!o.previousNode()},sn=function(e,t,n){var o,i,r,s=e.querySelectorAll("BR"),d=[],l=s.length;for(o=0;l>o;o+=1)d[o]=an(s[o],n);for(;l--;)i=s[l],r=i.parentNode,r&&(d[l]?a(r)||E(r,t):N(i))},dn=function(e,t,n){var o,i,r=t.ownerDocument.body;sn(t,n,!0),t.setAttribute("style","position:fixed;overflow:hidden;bottom:100%;right:100%;"),r.appendChild(t),o=t.innerHTML,i=t.innerText||t.textContent,it&&(i=i.replace(/\r?\n/g,"\r\n")),e.setData("text/html",o),e.setData("text/plain",i),r.removeChild(t)},ln=function(e){var t,n,o,i,r,a,s,d=e.clipboardData,l=this.getSelection(),c=this._root,h=this;if(l.collapsed)return void e.preventDefault();if(this.saveUndoState(l),dt||nt||!d)setTimeout(function(){try{h._ensureBottomLine()}catch(e){h.didError(e)}},0);else{for(t=It(l,c),n=wt(l,c),o=t===n&&t||c,i=Bt(l,c),r=l.commonAncestorContainer,r.nodeType===M&&(r=r.parentNode);r&&r!==o;)a=r.cloneNode(!1),a.appendChild(i),i=a,r=r.parentNode;s=this.createElement("div"),s.appendChild(i),dn(d,s,c),e.preventDefault()}this.setSelection(l)},cn=function(e){var t,n,o,i,r,a,s,d=e.clipboardData,l=this.getSelection(),c=this._root;if(!dt&&!nt&&d){for(t=It(l,c),n=wt(l,c),o=t===n&&t||c,l=l.cloneRange(),Ut(l),Pt(l,o,o,c),i=l.cloneContents(),r=l.commonAncestorContainer,r.nodeType===M&&(r=r.parentNode);r&&r!==o;)a=r.cloneNode(!1),a.appendChild(i),i=a,r=r.parentNode;s=this.createElement("div"),s.appendChild(i),dn(d,s,c),e.preventDefault()}},hn=function(e){var t,n,o,i,r,a=e.clipboardData,s=a&&a.items,d=this.isShiftDown,l=!1,c=!1,h=null,u=this;if(!dt&&s){for(e.preventDefault(),t=s.length;t--;){if(n=s[t],o=n.type,!d&&"text/html"===o)return void n.getAsString(function(e){u.insertHTML(e,!0)});"text/plain"===o&&(h=n),!d&&/^image\/.*/.test(o)&&(c=!0)}return void(c?(this.fireEvent("dragover",{dataTransfer:a,preventDefault:function(){l=!0}}),l&&this.fireEvent("drop",{dataTransfer:a})):h&&h.getAsString(function(e){u.insertPlainText(e,!0)}))}if(i=a&&a.types,!dt&&i&&(_t.call(i,"text/html")>-1||!rt&&_t.call(i,"text/plain")>-1&&_t.call(i,"text/rtf")<0))return e.preventDefault(),void(!d&&(r=a.getData("text/html"))?this.insertHTML(r,!0):((r=a.getData("text/plain"))||(r=a.getData("text/uri-list")))&&this.insertPlainText(r,!0));this._awaitingPaste=!0;var f=this._doc.body,p=this.getSelection(),g=p.startContainer,m=p.startOffset,v=p.endContainer,_=p.endOffset,C=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(C),p.selectNodeContents(C),this.setSelection(p),setTimeout(function(){try{u._awaitingPaste=!1;for(var e,t,n="",o=C;C=o;)o=C.nextSibling,N(C),e=C.firstChild,e&&e===C.lastChild&&"DIV"===e.nodeName&&(C=e),n+=C.innerHTML;t=u._createRange(g,m,v,_),u.setSelection(t),n&&u.insertHTML(n,!0)}catch(i){u.didError(i)}},0)},un=function(e){for(var t=e.dataTransfer.types,n=t.length,o=!1,i=!1;n--;)switch(t[n]){case"text/plain":o=!0;break;case"text/html":i=!0;break;default:return}(i||o)&&this.saveUndoState()},fn=D.prototype,pn=function(e,t,n){var o=n._doc,i=e?DOMPurify.sanitize(e,{ALLOW_UNKNOWN_PROTOCOLS:!0,WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}):null;return i?o.importNode(i,!0):o.createDocumentFragment()};fn.setConfig=function(e){return e=B({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},leafNodeNames:St,undo:{documentSizeThreshold:-1,undoLimit:-1},isInsertedHTMLSanitized:!0,isSetHTMLSanitized:!0,sanitizeToDOMFragment:"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?pn:null},e,!0),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},fn.createElement=function(e,t,n){return T(this._doc,e,t,n)},fn.createDefaultBlock=function(e){var t=this._config;return y(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},fn.didError=function(e){console.log(e)},fn.getDocument=function(){return this._doc},fn.getRoot=function(){return this._root},fn.modifyDocument=function(e){var t=this._mutation;t&&(t.takeRecords().length&&this._docWasChanged(),t.disconnect()),this._ignoreAllChanges=!0,e(),this._ignoreAllChanges=!1,t&&(t.observe(this._root,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._ignoreChange=!1)};var gn={pathChange:1,select:1,input:1,undoStateChange:1};fn.fireEvent=function(e,t){var n,o,i,r=this._events[e];if(/^(?:focus|blur)/.test(e))if(n=this._root===this._doc.activeElement,"focus"===e){if(!n||this._isFocused)return this;this._isFocused=!0}else{if(n||!this._isFocused)return this;this._isFocused=!1}if(r)for(t||(t={}),t.type!==e&&(t.type=e),r=r.slice(),o=r.length;o--;){i=r[o];try{i.handleEvent?i.handleEvent(t):i.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},fn.destroy=function(){var e,t=this._events;for(e in t)this.removeEventListener(e);this._mutation&&this._mutation.disconnect(),delete this._root.__squire__,this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0},fn.handleEvent=function(e){this.fireEvent(e.type,e)},fn.addEventListener=function(e,t){var n=this._events[e],o=this._root;return t?(n||(n=this._events[e]=[],gn[e]||("selectionchange"===e&&(o=this._doc),o.addEventListener(e,this,!0))),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},fn.removeEventListener=function(e,t){var n,o=this._events[e],i=this._root;if(o){if(t)for(n=o.length;n--;)o[n]===t&&o.splice(n,1);else o.length=0;o.length||(delete this._events[e],gn[e]||("selectionchange"===e&&(i=this._doc),i.removeEventListener(e,this,!0)))}return this},fn._createRange=function(e,t,n,o){if(e instanceof this._win.Range)return e.cloneRange();var i=this._doc.createRange();return i.setStart(e,t),n?i.setEnd(n,o):i.setEnd(e,t),i},fn.getCursorPosition=function(e){if(!e&&!(e=this.getSelection())||!e.getBoundingClientRect)return null;var t,n,o=e.getBoundingClientRect();return o&&!o.top&&(this._ignoreChange=!0,t=this._doc.createElement("SPAN"),t.textContent=X,Ot(e,t),o=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),L(n,e)),o},fn._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return Ut(n),this.setSelection(n),this},fn.moveCursorToStart=function(){return this._moveCursorTo(!0)},fn.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var mn=function(e){return e._win.getSelection()||null};fn.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused)if(tt&&!this._restoreSelection)R.call(this),this.blur(),this.focus();else{nt&&this._win.focus();var t=mn(this);t&&(t.removeAllRanges(),t.addRange(e))}else R.call(this);return this},fn.getSelection=function(){var e,t,n,o,r=mn(this),a=this._root;return this._isFocused&&r&&r.rangeCount&&(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&i(t)&&e.setStartBefore(t),n&&i(n)&&e.setEndBefore(n)),e&&m(a,e.commonAncestorContainer)?this._lastSelection=e:(e=this._lastSelection,o=e.commonAncestorContainer,m(o.ownerDocument,o)||(e=null)),e||(e=this._createRange(a.firstChild,0)),e},fn.getSelectedText=function(){var e=this.getSelection();if(!e||e.collapsed)return"";var t,o=new n(e.commonAncestorContainer,q|z,function(t){return Rt(e,t,!0)}),i=e.startContainer,r=e.endContainer,s=o.currentNode=i,d="",l=!1;for(o.filter(s)||(s=o.nextNode());s;)s.nodeType===M?(t=s.data,t&&/\S/.test(t)&&(s===r&&(t=t.slice(0,e.endOffset)),s===i&&(t=t.slice(e.startOffset)),d+=t,l=!0)):("BR"===s.nodeName||l&&!a(s))&&(d+="\n",l=!1),s=o.nextNode();return d},fn.getPath=function(){return this._path};var vn=function(e,t){for(var o,i,r,s=new n(e,q,function(){return!0},!1);i=s.nextNode();)for(;(r=i.data.indexOf(X))>-1&&(!t||i.parentNode!==t);){if(1===i.length){do o=i.parentNode,o.removeChild(i),i=o,s.currentNode=o;while(a(i)&&!_(i));break}i.deleteData(r,1)}};fn._didAddZWS=function(){this._hasZWS=!0},fn._removeZWS=function(){this._hasZWS&&(vn(this._root),this._hasZWS=!1)},fn._updatePath=function(e,t){if(e){var n,o=e.startContainer,i=e.endContainer;(t||o!==this._lastAnchorNode||i!==this._lastFocusNode)&&(this._lastAnchorNode=o,this._lastFocusNode=i,n=o&&i?o===i?v(i,this._root):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),this.fireEvent(e.collapsed?"cursor":"select",{range:e})}},fn._updatePathOnEvent=function(){var e=this;e._isFocused&&!e._willUpdatePath&&(e._willUpdatePath=!0,setTimeout(function(){e._willUpdatePath=!1,e._updatePath(e.getSelection())},0))},fn.focus=function(){return this._root.focus(),ct&&this.fireEvent("focus"),this},fn.blur=function(){return this._root.blur(),ct&&this.fireEvent("blur"),this};var _n="squire-selection-start",Nn="squire-selection-end";fn._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:_n,type:"hidden"}),o=this.createElement("INPUT",{id:Nn,type:"hidden"});Ot(e,n),e.collapse(!1),Ot(e,o),n.compareDocumentPosition(o)&w&&(n.id=Nn,o.id=_n,t=n,n=o,o=t),e.setStartAfter(n),e.setEndBefore(o)},fn._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+_n),o=t.querySelector("#"+Nn);if(n&&o){var i=n.parentNode,r=o.parentNode,a=_t.call(i.childNodes,n),s=_t.call(r.childNodes,o);i===r&&(s-=1),N(n),N(o),e||(e=this._doc.createRange()),e.setStart(i,a),e.setEnd(r,s),L(i,e),i!==r&&L(r,e),e.collapsed&&(i=e.startContainer,i.nodeType===M&&(r=i.childNodes[e.startOffset],r&&r.nodeType===M||(r=i.childNodes[e.startOffset-1]),r&&r.nodeType===M&&(e.setStart(r,0),e.collapse(!0))))}return e||null},fn._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},fn._docWasChanged=function(){if(mt&&(kt=new WeakMap),!this._ignoreAllChanges){if(gt&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},fn._recordUndoState=function(e,t){if(!this._isInUndoState||t){var n,o=this._undoIndex,i=this._undoStack,r=this._config.undo,a=r.documentSizeThreshold,s=r.undoLimit; +t||(o+=1),o-1&&2*n.length>a&&s>-1&&o>s&&(i.splice(0,o-s),o=s,this._undoStackLength=s),i[o]=n,this._undoIndex=o,this._undoStackLength+=1,this._isInUndoState=!0}},fn.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._recordUndoState(e,this._isInUndoState),this._getRangeAndRemoveBookmark(e),this},fn.undo=function(){if(0!==this._undoIndex||!this._isInUndoState){this._recordUndoState(this.getSelection(),!1),this._undoIndex-=1,this._setHTML(this._undoStack[this._undoIndex]);var e=this._getRangeAndRemoveBookmark();e&&this.setSelection(e),this._isInUndoState=!0,this.fireEvent("undoStateChange",{canUndo:0!==this._undoIndex,canRedo:!0}),this.fireEvent("input")}return this},fn.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(t>e+1&&this._isInUndoState){this._undoIndex+=1,this._setHTML(this._undoStack[this._undoIndex]);var n=this._getRangeAndRemoveBookmark();n&&this.setSelection(n),this.fireEvent("undoStateChange",{canUndo:!0,canRedo:t>e+2}),this.fireEvent("input")}return this},fn.hasFormat=function(e,t,o){if(e=e.toUpperCase(),t||(t={}),!o&&!(o=this.getSelection()))return!1;!o.collapsed&&o.startContainer.nodeType===M&&o.startOffset===o.startContainer.length&&o.startContainer.nextSibling&&o.setStartBefore(o.startContainer.nextSibling),!o.collapsed&&o.endContainer.nodeType===M&&0===o.endOffset&&o.endContainer.previousSibling&&o.setEndAfter(o.endContainer.previousSibling);var i,r,a=this._root,s=o.commonAncestorContainer;if(g(s,a,e,t))return!0;if(s.nodeType===M)return!1;i=new n(s,q,function(e){return Rt(o,e,!0)},!1);for(var d=!1;r=i.nextNode();){if(!g(r,a,e,t))return!1;d=!0}return d},fn.getFontInfo=function(e){var n,o,i,r={color:t,backgroundColor:t,family:t,size:t},a=0;if(!e&&!(e=this.getSelection()))return r;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===M)for(n.nodeType===M&&(n=n.parentNode);4>a&&n;)(o=n.style)&&(!r.color&&(i=o.color)&&(r.color=i,a+=1),!r.backgroundColor&&(i=o.backgroundColor)&&(r.backgroundColor=i,a+=1),!r.family&&(i=o.fontFamily)&&(r.family=i,a+=1),!r.size&&(i=o.fontSize)&&(r.size=i,a+=1)),n=n.parentNode;return r},fn._addFormat=function(e,t,o){var i,r,s,d,l,c,h,u,f,p=this._root;if(o.collapsed){for(i=y(this.createElement(e,t),p),Ot(o,i),o.setStart(i.firstChild,i.firstChild.length),o.collapse(!0),f=i;a(f);)f=f.parentNode;vn(f,i)}else{if(r=new n(o.commonAncestorContainer,q|z,function(e){return(e.nodeType===M||"BR"===e.nodeName||"IMG"===e.nodeName)&&Rt(o,e,!0)},!1),s=o.startContainer,l=o.startOffset,d=o.endContainer,c=o.endOffset,r.currentNode=s,r.filter(s)||(s=r.nextNode(),l=0),!s)return o;do h=r.currentNode,u=!g(h,p,e,t),u&&(h===d&&h.length>c&&h.splitText(c),h===s&&l&&(h=h.splitText(l),d===s&&(d=h,c-=l),s=h,l=0),i=this.createElement(e,t),C(h,i),i.appendChild(h));while(r.nextNode());d.nodeType!==M&&(h.nodeType===M?(d=h,c=h.length):(d=h.parentNode,c=1)),o=this._createRange(s,l,d,c)}return o},fn._removeFormat=function(e,t,n,o){this._saveRangeToBookmark(n);var i,r=this._doc;n.collapsed&&(ft?(i=r.createTextNode(X),this._didAddZWS()):i=r.createTextNode(""),Ot(n,i));for(var s=n.commonAncestorContainer;a(s);)s=s.parentNode;var d=n.startContainer,l=n.startOffset,c=n.endContainer,h=n.endOffset,u=[],f=function(e,t){if(!Rt(n,e,!1)){var o,i,r=e.nodeType===M;if(!Rt(n,e,!0))return void("INPUT"===e.nodeName||r&&!e.data||u.push([t,e]));if(r)e===c&&h!==e.length&&u.push([t,e.splitText(h)]),e===d&&l&&(e.splitText(l),u.push([t,e]));else for(o=e.firstChild;o;o=i)i=o.nextSibling,f(o,t)}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(o){return Rt(n,o,!0)&&p(o,e,t)});return o||g.forEach(function(e){f(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];C(n,t),t.appendChild(n)}),g.forEach(function(e){C(e,S(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1),L(s,n),n},fn.changeFormat=function(e,t,n,o){return n||(n=this.getSelection())?(this.saveUndoState(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,o)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),gt||this._docWasChanged(),this):this};var Cn={DT:"DD",DD:"DT",LI:"LI"},Sn=function(e,t,n,o){var i=Cn[t.nodeName],r=null,a=b(n,o,t.parentNode,e._root),s=e._config;return i||(i=s.blockTag,r=s.blockAttributes),p(a,i,r)||(t=T(a.ownerDocument,i,r),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(S(a)),a=t),a};fn.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var o=this._root,i=It(n,o),r=wt(n,o);if(i&&r)do if(e(i)||i===r)break;while(i=h(i,o));return t&&(this.setSelection(n),this._updatePath(n,!0),gt||this._docWasChanged()),this},fn.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._recordUndoState(t,this._isInUndoState);var n,o=this._root;return Wt(t,o),Pt(t,o,o,o),n=At(t,o,o),Ot(t,e.call(this,n)),t.endOffsett;t+=1)o=a[t],i=S(o),E(i,l),C(o,i);for(t=0,n=d.length;n>t;t+=1)r=d[t],s(r)?C(r,this.createDefaultBlock([S(r)])):(E(r,l),C(r,S(r)));return e},On=function(e,t){for(var n=e.commonAncestorContainer,o=e.startContainer,i=e.endContainer;n&&n!==t&&!/^[OU]L$/.test(n.nodeName);)n=n.parentNode;if(!n||n===t)return null;for(o===n&&(o=o.childNodes[e.startOffset]),i===n&&(i=i.childNodes[e.endOffset]);o&&o.parentNode!==n;)o=o.parentNode;for(;i&&i.parentNode!==n;)i=i.parentNode;return[n,o,i]};fn.increaseListLevel=function(e){if(!e&&!(e=this.getSelection()))return this.focus();var t=On(e,root);if(!t)return this.focus();var n=t[0],o=t[1],i=t[2];if(!o||o===n.firstChild)return this.focus();this._recordUndoState(e,this._isInUndoState);var r,a,s=n.nodeName,d=o.previousSibling;d.nodeName!==s&&(r=this._config.tagAttributes[s.toLowerCase()],d=this.createElement(s,r),n.insertBefore(d,o));do a=o===i?null:o.nextSibling,d.appendChild(o);while(o=a);return a=d.nextSibling,a&&O(a,this._root),this._getRangeAndRemoveBookmark(e),this.setSelection(e),this._updatePath(e,!0),gt||this._docWasChanged(),this.focus()},fn.decreaseListLevel=function(e){if(!e&&!(e=this.getSelection()))return this.focus();var t=this._root,n=On(e,t);if(!n)return this.focus();var o=n[0],i=n[1],r=n[2];i||(i=o.firstChild),r||(r=o.lastChild),this._recordUndoState(e,this._isInUndoState);var a,s=o.parentNode,d=r.nextSibling?b(o,r.nextSibling,s,t):o.nextSibling;if(s!==t&&"LI"===s.nodeName){for(s=s.parentNode;d;)a=d.nextSibling,r.appendChild(d),d=a;d=o.parentNode.nextSibling}var l=!/^[OU]L$/.test(s.nodeName);do a=i===r?null:i.nextSibling,o.removeChild(i),l&&"LI"===i.nodeName&&(i=this.createDefaultBlock([S(i)])),s.insertBefore(i,d);while(i=a);return o.firstChild||N(o),d&&O(d,t),this._getRangeAndRemoveBookmark(e),this.setSelection(e),this._updatePath(e,!0),gt||this._docWasChanged(),this.focus()},fn._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&s(t)||e.appendChild(this.createDefaultBlock())},fn.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},fn._getHTML=function(){return this._root.innerHTML},fn._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do y(n,t);while(n=h(n,t));this._ignoreChange=!0},fn.getHTML=function(e){var t,n,o,i,r,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),ut)for(t=this._root,n=t;n=h(n,t);)n.textContent||n.querySelector("BR")||(o=this.createElement("BR"),n.appendChild(o),s.push(o));if(i=this._getHTML().replace(/\u200B/g,""),ut)for(r=s.length;r--;)N(s[r]);return a&&this._getRangeAndRemoveBookmark(a),i},fn.setHTML=function(e){var t,n,o,i=this._config,r=i.isSetHTMLSanitized?i.sanitizeToDOMFragment:null,a=this._root;"function"==typeof r?n=r(e,!1,this):(t=this.createElement("DIV"),t.innerHTML=e,n=this._doc.createDocumentFragment(),n.appendChild(S(t))),nn(n),sn(n,a,!1),E(n,a);for(var s=n;s=h(s,a);)y(s,a);for(this._ignoreChange=!0;o=a.lastChild;)a.removeChild(o);a.appendChild(n),y(a,a),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;var d=this._getRangeAndRemoveBookmark()||this._createRange(a.firstChild,0);return this.saveUndoState(d),this._lastSelection=d,R.call(this),this._updatePath(d,!0),this},fn.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),a(e))Ot(t,e),t.setStartAfter(e);else{for(var n,o,i=this._root,r=It(t,i)||i;r!==i&&!r.nextSibling;)r=r.parentNode;r!==i&&(n=r.parentNode,o=b(n,r.nextSibling,i,i)),o?i.insertBefore(e,o):(i.appendChild(e),o=this.createDefaultBlock(),i.appendChild(o)),t.setStart(o,0),t.setEnd(o,0),Ut(t)}return this.focus(),this.setSelection(t),this._updatePath(t),gt||this._docWasChanged(),this},fn.insertImage=function(e,t){var n=this.createElement("IMG",B({src:e},t,!0));return this.insertElement(n),n};var An=/\b((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)/i,Bn=function(e,t,o){for(var i,r,a,s,d,l,c,h=e.ownerDocument,u=new n(e,q,function(e){return!g(e,t,"A")},!1),f=o._config.tagAttributes.a;i=u.nextNode();)for(r=i.data,a=i.parentNode;s=An.exec(r);)d=s.index,l=d+s[0].length,d&&(c=h.createTextNode(r.slice(0,d)),a.insertBefore(c,i)),c=o.createElement("A",B({href:s[1]?/^(?:ht|f)tps?:/.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[2]},f,!1)),c.textContent=r.slice(d,l),a.insertBefore(c,i),i.data=r=r.slice(l)};fn.insertHTML=function(e,t){var n,o,i,r,a,s,d,l=this._config,c=l.isInsertedHTMLSanitized?l.sanitizeToDOMFragment:null,u=this.getSelection(),f=this._doc;"function"==typeof c?r=c(e,t,this):(t&&(n=e.indexOf(""),o=e.lastIndexOf(""),n>-1&&o>-1&&(e=e.slice(n+20,o))),/<\/td>((?!<\/tr>)[\s\S])*$/i.test(e)&&(e=""+e+""),/<\/tr>((?!<\/table>)[\s\S])*$/i.test(e)&&(e=""+e+"
"),i=this.createElement("DIV"),i.innerHTML=e,r=f.createDocumentFragment(),r.appendChild(S(i))),this.saveUndoState(u);try{for(a=this._root,s=r,d={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},Bn(r,r,this),nn(r),sn(r,a,!1),on(r),r.normalize();s=h(s,r);)y(s,a);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(Dt(u,d.fragment,a),gt||this._docWasChanged(),u.collapse(!1),this._ensureBottomLine()),this.setSelection(u),this._updatePath(u,!0),t&&this.focus()}catch(p){this.didError(p)}return this};var Dn=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};fn.insertPlainText=function(e,t){var n,o,i,r,a=e.split("\n"),s=this._config,d=s.blockTag,l=s.blockAttributes,c="",h="<"+d;for(n in l)h+=" "+n+'="'+Dn(l[n])+'"';for(h+=">",o=0,i=a.length;i>o;o+=1)r=a[o],r=Dn(r).replace(/ (?= )/g," "),a[o]=h+(r||"
")+c;return this.insertHTML(a.join(""),t)};var Rn=function(e,t,n){return function(){return this[e](t,n),this.focus()}};fn.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.appendChild(this._doc.createTextNode(e)),t.appendChild(n)}return this},fn.bold=Rn("changeFormat",{tag:"B"}),fn.italic=Rn("changeFormat",{tag:"I"}),fn.underline=Rn("changeFormat",{tag:"U"}),fn.strikethrough=Rn("changeFormat",{tag:"S"}),fn.subscript=Rn("changeFormat",{tag:"SUB"},{tag:"SUP"}),fn.superscript=Rn("changeFormat",{tag:"SUP"},{tag:"SUB"}),fn.removeBold=Rn("changeFormat",null,{tag:"B"}),fn.removeItalic=Rn("changeFormat",null,{tag:"I"}),fn.removeUnderline=Rn("changeFormat",null,{tag:"U"}),fn.removeStrikethrough=Rn("changeFormat",null,{tag:"S"}),fn.removeSubscript=Rn("changeFormat",null,{tag:"SUB"}),fn.removeSuperscript=Rn("changeFormat",null,{tag:"SUP"}),fn.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var o=e.indexOf(":")+1;if(o)for(;"/"===e[o];)o+=1;Ot(n,this._doc.createTextNode(e.slice(o)))}return t=B(B({href:e},t,!0),this._config.tagAttributes.a,!1),this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},fn.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},fn.setFontFace=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":V,style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{"class":V}}),this.focus()},fn.setFontSize=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":Y,style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{"class":Y}}),this.focus()},fn.setTextColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":Q,style:"color:"+e}}:null,{tag:"SPAN",attributes:{"class":Q}}),this.focus()},fn.setHighlightColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":$,style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{"class":$}}),this.focus()},fn.setTextAlignment=function(e){return this.forEachBlock(function(t){var n=t.className.split(/\s+/).filter(function(e){return!!e&&!/^align/.test(e)}).join(" ");e?(t.className=n+" align-"+e,t.style.textAlign=e):(t.className=n,t.style.textAlign="")},!0),this.focus()},fn.setTextDirection=function(e){return this.forEachBlock(function(t){e?t.dir=e:t.removeAttribute("dir")},!0),this.focus()},fn.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=this._root,n=e.commonAncestorContainer;n&&!s(n);)n=n.parentNode;if(n||(Wt(e,t),n=t),n.nodeType===M)return this;this.saveUndoState(e),Pt(e,n,n,t);for(var o,i,r=n.ownerDocument,a=e.startContainer,d=e.startOffset,l=e.endContainer,c=e.endOffset,h=r.createDocumentFragment(),u=r.createDocumentFragment(),f=b(l,c,n,t),p=b(a,d,n,t);p!==f;)o=p.nextSibling,h.appendChild(p),p=o;return I(this,h,u),u.normalize(),p=u.firstChild,o=u.lastChild,i=n.childNodes,p?(n.insertBefore(u,f),d=_t.call(i,p),c=_t.call(i,o)+1):(d=_t.call(i,f),c=d),e.setStart(n,d),e.setEnd(n,c),L(n,e),Ut(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},fn.increaseQuoteLevel=Rn("modifyBlocks",Tn),fn.decreaseQuoteLevel=Rn("modifyBlocks",yn),fn.makeUnorderedList=Rn("modifyBlocks",kn),fn.makeOrderedList=Rn("modifyBlocks",Ln),fn.removeList=Rn("modifyBlocks",xn),D.isInline=a,D.isBlock=s,D.isContainer=d,D.getBlockWalker=l,D.getPreviousBlock=c,D.getNextBlock=h,D.areAlike=f,D.hasTagAttributes=p,D.getNearest=g,D.isOrContains=m,D.detach=N,D.replaceWith=C,D.empty=S,D.getNodeBefore=Lt,D.getNodeAfter=xt,D.insertNodeInRange=Ot,D.extractContentsOfRange=At,D.deleteContentsOfRange=Bt,D.insertTreeFragmentIntoRange=Dt,D.isNodeContainedInRange=Rt,D.moveRangeBoundariesDownTree=Ut,D.moveRangeBoundariesUpTree=Pt,D.getStartBlockOfRange=It,D.getEndBlockOfRange=wt,D.contentWalker=Ft,D.rangeDoesStartAtBlockBoundary=Mt,D.rangeDoesEndAtBlockBoundary=Ht,D.expandRangeToBlockBoundaries=Wt,D.onPaste=hn,D.addLinks=Bn,D.splitBlock=Sn,D.startSelectionId=_n,D.endSelectionId=Nn,"object"==typeof exports?module.exports=D:"function"==typeof define&&define.amd?define(function(){return D}):(J.Squire=D,top!==J&&"true"===e.documentElement.getAttribute("data-squireinit")&&(J.editor=new D(e),J.onEditorLoad&&(J.onEditorLoad(J.editor),J.onEditorLoad=null)))}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index f7d4421..3257c34 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -1454,77 +1454,155 @@ var removeList = function ( frag ) { return frag; }; -var increaseListLevel = function ( frag ) { - var items = frag.querySelectorAll( 'LI' ), - i, l, item, - type, newParent, - tagAttributes = this._config.tagAttributes, - listAttrs; - for ( i = 0, l = items.length; i < l; i += 1 ) { - item = items[i]; - if ( !isContainer( item.firstChild ) ) { - // type => 'UL' or 'OL' - type = item.parentNode.nodeName; - newParent = item.previousSibling; - if ( !newParent || !( newParent = newParent.lastChild ) || - newParent.nodeName !== type ) { - listAttrs = tagAttributes[ type.toLowerCase() ]; - newParent = this.createElement( type, listAttrs ); - - replaceWith( - item, - newParent - ); - } - newParent.appendChild( item ); - } +var getListSelection = function ( range, root ) { + // Get start+end li in single common ancestor + var list = range.commonAncestorContainer; + var startLi = range.startContainer; + var endLi = range.endContainer; + while ( list && list !== root && !/^[OU]L$/.test( list.nodeName ) ) { + list = list.parentNode; } - return frag; + if ( !list || list === root ) { + return null; + } + if ( startLi === list ) { + startLi = startLi.childNodes[ range.startOffset ]; + } + if ( endLi === list ) { + endLi = endLi.childNodes[ range.endOffset ]; + } + while ( startLi && startLi.parentNode !== list ) { + startLi = startLi.parentNode; + } + while ( endLi && endLi.parentNode !== list ) { + endLi = endLi.parentNode; + } + return [ list, startLi, endLi ]; }; -var decreaseListLevel = function ( frag ) { - var root = this._root; - var items = frag.querySelectorAll( 'LI' ); - Array.prototype.filter.call( items, function ( el ) { - return !isContainer( el.firstChild ); - }).forEach( function ( item ) { - var parent = item.parentNode, - newParent = parent.parentNode, - first = item.firstChild, - node = first, - next; - if ( item.previousSibling ) { - parent = split( parent, item, newParent, root ); - } +proto.increaseListLevel = function ( range ) { + if ( !range && !( range = this.getSelection() ) ) { + return this.focus(); + } - // if the new parent is another list then we simply move the node - // e.g. `ul > ul > li` becomes `ul > li` - if ( /^[OU]L$/.test( newParent.nodeName ) ) { - newParent.insertBefore( item, parent ); - if ( !parent.firstChild ) { - newParent.removeChild( parent ); - } - } else { - while ( node ) { - next = node.nextSibling; - if ( isContainer( node ) ) { - break; - } - newParent.insertBefore( node, parent ); - node = next; - } + var listSelection = getListSelection( range, root ); + if ( !listSelection ) { + return this.focus(); + } + + var list = listSelection[0]; + var startLi = listSelection[1]; + var endLi = listSelection[2]; + if ( !startLi || startLi === list.firstChild ) { + return this.focus(); + } + + // Save undo checkpoint and bookmark selection + this._recordUndoState( range, this._isInUndoState ); + + // Increase list depth + var type = list.nodeName; + var newParent = startLi.previousSibling; + var listAttrs, next; + if ( newParent.nodeName !== type ) { + listAttrs = this._config.tagAttributes[ type.toLowerCase() ]; + newParent = this.createElement( type, listAttrs ); + list.insertBefore( newParent, startLi ); + } + do { + next = startLi === endLi ? null : startLi.nextSibling; + newParent.appendChild( startLi ); + } while ( ( startLi = next ) ); + next = newParent.nextSibling; + if ( next ) { + mergeContainers( next, this._root ); + } + + // Restore selection + this._getRangeAndRemoveBookmark( range ); + this.setSelection( range ); + this._updatePath( range, true ); + + // We're not still in an undo state + if ( !canObserveMutations ) { + this._docWasChanged(); + } + + return this.focus(); +}; + +proto.decreaseListLevel = function ( range ) { + if ( !range && !( range = this.getSelection() ) ) { + return this.focus(); + } + + var root = this._root; + var listSelection = getListSelection( range, root ); + if ( !listSelection ) { + return this.focus(); + } + + var list = listSelection[0]; + var startLi = listSelection[1]; + var endLi = listSelection[2]; + if ( !startLi ) { + startLi = list.firstChild; + } + if ( !endLi ) { + endLi = list.lastChild; + } + + // Save undo checkpoint and bookmark selection + this._recordUndoState( range, this._isInUndoState ); + + // Find the new parent list node + var newParent = list.parentNode; + var next; + + // Split list if necesary + var insertBefore = !endLi.nextSibling ? + list.nextSibling : + split( list, endLi.nextSibling, newParent, root ); + + if ( newParent !== root && newParent.nodeName === 'LI' ) { + newParent = newParent.parentNode; + while ( insertBefore ) { + next = insertBefore.nextSibling; + endLi.appendChild( insertBefore ); + insertBefore = next; } - if ( newParent.nodeName === 'LI' && first.previousSibling ) { - split( newParent, first, newParent.parentNode, root ); + insertBefore = list.parentNode.nextSibling; + } + + var makeNotList = !/^[OU]L$/.test( newParent.nodeName ); + do { + next = startLi === endLi ? null : startLi.nextSibling; + list.removeChild( startLi ); + if ( makeNotList && startLi.nodeName === 'LI' ) { + startLi = this.createDefaultBlock([ empty( startLi ) ]); } - while ( item !== frag && !item.childNodes.length ) { - parent = item.parentNode; - parent.removeChild( item ); - item = parent; - } - }, this ); - fixContainer( frag, root ); - return frag; + newParent.insertBefore( startLi, insertBefore ); + } while ( ( startLi = next ) ); + + if ( !list.firstChild ) { + detach( list ); + } + + if ( insertBefore ) { + mergeContainers( insertBefore, root ); + } + + // Restore selection + this._getRangeAndRemoveBookmark( range ); + this.setSelection( range ); + this._updatePath( range, true ); + + // We're not still in an undo state + if ( !canObserveMutations ) { + this._docWasChanged(); + } + + return this.focus(); }; proto._ensureBottomLine = function () { @@ -2119,6 +2197,3 @@ proto.decreaseQuoteLevel = command( 'modifyBlocks', decreaseBlockQuoteLevel ); proto.makeUnorderedList = command( 'modifyBlocks', makeUnorderedList ); proto.makeOrderedList = command( 'modifyBlocks', makeOrderedList ); proto.removeList = command( 'modifyBlocks', removeList ); - -proto.increaseListLevel = command( 'modifyBlocks', increaseListLevel ); -proto.decreaseListLevel = command( 'modifyBlocks', decreaseListLevel ); diff --git a/source/KeyHandlers.js b/source/KeyHandlers.js index e3d9172..d6e6d9c 100644 --- a/source/KeyHandlers.js +++ b/source/KeyHandlers.js @@ -192,7 +192,7 @@ var keyHandlers = { // Break list if ( getNearest( block, root, 'UL' ) || getNearest( block, root, 'OL' ) ) { - return self.modifyBlocks( decreaseListLevel, range ); + return self.decreaseListLevel( range ); } // Break blockquote else if ( getNearest( block, root, 'BLOCKQUOTE' ) ) { @@ -299,7 +299,7 @@ var keyHandlers = { // Break list if ( getNearest( current, root, 'UL' ) || getNearest( current, root, 'OL' ) ) { - return self.modifyBlocks( decreaseListLevel, range ); + return self.decreaseListLevel( range ); } // Break blockquote else if ( getNearest( current, root, 'BLOCKQUOTE' ) ) { @@ -394,12 +394,12 @@ var keyHandlers = { if ( range.collapsed && rangeDoesStartAtBlockBoundary( range, root ) ) { node = getStartBlockOfRange( range, root ); // Iterate through the block's parents - while ( parent = node.parentNode ) { + while ( ( parent = node.parentNode ) ) { // If we find a UL or OL (so are in a list, node must be an LI) if ( parent.nodeName === 'UL' || parent.nodeName === 'OL' ) { // Then increase the list level event.preventDefault(); - self.modifyBlocks( increaseListLevel, range ); + self.increaseListLevel( range ); break; } node = parent; @@ -417,7 +417,7 @@ var keyHandlers = { if ( getNearest( node, root, 'UL' ) || getNearest( node, root, 'OL' ) ) { event.preventDefault(); - self.modifyBlocks( decreaseListLevel, range ); + self.decreaseListLevel( range ); } } },