From 3854c99a316ab8487ddadda8acfa7f71551d23f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=AE=E7=94=B0=20=E6=98=8C=E5=AE=8F?= Date: Wed, 2 Sep 2020 23:17:07 +0900 Subject: [PATCH] =?UTF-8?q?=E9=96=8B=E6=A5=AD=E6=99=82=E3=81=AB=E3=81=9D?= =?UTF-8?q?=E3=81=AE=E8=A1=8C=E3=81=AE=E5=85=88=E9=A0=AD=E3=81=8CCHECKBOX?= =?UTF-8?q?=E3=81=AA=E3=82=89=E6=AC=A1=E3=81=AE=E8=A1=8C=E3=81=AB=E3=82=82?= =?UTF-8?q?CHECKBOX=E3=82=92=E5=85=88=E9=A0=AD=E3=81=AB=E6=8C=BF=E5=85=A5?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/squire-raw.js | 17 +++++++++++++++++ build/squire.js | 4 ++-- package.json | 2 +- source/KeyHandlers.js | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 5eba9671..318e0ed4 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -1430,6 +1430,15 @@ var handleEnter = function ( self, shiftKey, range ) { block = getStartBlockOfRange( range, root ); + // If the block is begining with CHECKBOX, + // the splitted next line should begin with CHECKBOX. + var beginingCheckbox = ( + block.firstChild.nodeName == 'SPAN' && + !block.firstChild.isContentEditable && + block.firstChild.firstChild.nodeName == 'INPUT' && + block.firstChild.firstChild.getAttribute('TYPE') == 'checkbox' + ) && block.firstChild.cloneNode(true) || null; + // Inside a PRE, insert literal newline, unless on blank line. if ( block && ( parent = getNearest( block, root, 'PRE' ) ) ) { moveRangeBoundariesDownTree( range ); @@ -1511,6 +1520,14 @@ var handleEnter = function ( self, shiftKey, range ) { nodeAfterSplit = splitBlock( self, block, range.startContainer, range.startOffset ); + // If the block is begining with CHECKBOX, + // the splitted next line should begin with CHECKBOX, + // and the cursor should located at the next to the CHECKBOX. + if (beginingCheckbox) { + nodeAfterSplit.prepend(beginingCheckbox); + nodeAfterSplit = nodeAfterSplit.firstChild.nextSibling; + } + // Clean up any empty inlines if we hit enter at the beginning of the // block removeZWS( block ); diff --git a/build/squire.js b/build/squire.js index 473a0639..4bde2be6 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||re}function i(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(e){return e.nodeType===w&&!!se[e.nodeName]}function r(e){switch(e.nodeType){case F:return le;case w:case H:if(te&&fe.has(e))return fe.get(e);break;default:return de}var t;return t=i(e.childNodes,a)?ae.test(e.nodeName)?le:ce:he,te&&fe.set(e,t),t}function a(e){return r(e)===le}function s(e){return r(e)===ce}function d(e){return r(e)===he}function l(e,t){var i=new n(t,W,s);return i.currentNode=e,i}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 f(e){return!e.textContent&&!e.querySelector("IMG")}function u(e,t){return!o(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 i in n)if(e.getAttribute(i)!==n[i])return!1;return!0}function g(e,t,n,i){for(;e&&e!==t;){if(p(e,n,i))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,n){var i,o,r,a,s,d="";return e&&e!==t&&(d=v(e.parentNode,t,n),e.nodeType===w&&(d+=(d?">":"")+e.nodeName,(i=e.id)&&(d+="#"+i),(o=e.className.trim())&&(r=o.split(/\s\s*/),r.sort(),d+=".",d+=r.join(".")),(a=e.dir)&&(d+="[dir="+a+"]"),r&&(s=n.classNames,ie.call(r,s.highlight)>-1&&(d+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),ie.call(r,s.colour)>-1&&(d+="[color="+e.style.color.replace(/ /g,"")+"]"),ie.call(r,s.fontFamily)>-1&&(d+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),ie.call(r,s.fontSize)>-1&&(d+="[fontSize="+e.style.fontSize+"]")))),d}function C(e){var t=e.nodeType;return t===w||t===H?e.childNodes.length:e.length||0}function _(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,i=n?n.length:0;i--;)t.appendChild(e.firstChild);return t}function y(e,n,i,o){var r,a,s,d,l=e.createElement(n);if(i instanceof Array&&(o=i,i=null),i)for(r in i)(a=i[r])!==t&&l.setAttribute(r,a);if(o)for(s=0,d=o.length;ss?t.startOffset-=1:t.startOffset===s&&(t.startContainer=i,t.startOffset=C(i))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=i,t.endOffset=C(i))),_(n),n.nodeType===F?i.appendData(n.data):d.push(S(n));else if(n.nodeType===w){for(o=d.length;o--;)n.appendChild(d.pop());k(n,t)}}function L(e,t){if(e.nodeType===F&&(e=e.parentNode),e.nodeType===w){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,i){for(var o,r,a,s=t;(o=s.parentNode)&&o!==i&&o.nodeType===w&&1===o.childNodes.length;)s=o;_(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)}function O(e,t){var n,i,o=e.previousSibling,r=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||r&&/^[OU]L$/.test(r.nodeName))if(o&&u(o,e)){if(!d(o)){if(!s)return;i=y(a,"DIV"),i.appendChild(S(o)),o.appendChild(i)}_(e),n=!d(e),o.appendChild(S(e)),n&&E(o,t),r&&O(r,t)}else s&&(o=y(a,"DIV"),e.insertBefore(o,r),T(o,t))}function A(e){this.isShiftDown=e.shiftKey}function B(e,t,n){var i,o;if(e||(e={}),t)for(i in t)!n&&i in e||(o=t[i],e[i]=o&&o.constructor===Object?B(e[i],o,n):o);return e}function R(e,t){e.nodeType===M&&(e=e.body);var n,i=e.ownerDocument,o=i.defaultView;this._win=o,this._doc=i,this._root=e,this._events={},this._isFocused=!1,this._lastSelection=null,this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this._willUpdatePath=!1,"onselectionchange"in i?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,ee?(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",D),this.addEventListener("mousedown",P),this.addEventListener("touchstart",P),this.addEventListener("focus",U),this._awaitingPaste=!1,this.addEventListener("cut",Je),this.addEventListener("copy",tt),this.addEventListener("keydown",A),this.addEventListener("keyup",A),this.addEventListener("paste",nt),this.addEventListener("drop",it),this.addEventListener("keydown",Ae),this._keyHandlers=Object.create(Ie),this.setConfig(t),e.setAttribute("contenteditable","true"),e.setAttribute("data-gramm","false");try{i.execCommand("enableObjectResizing",!1,"false"),i.execCommand("enableInlineTableEditing",!1,"false")}catch(e){}e.__squire__=this,this.setHTML("")}function D(){this._restoreSelection=!0}function P(){this._restoreSelection=!1}function U(){this._restoreSelection&&this.setSelection(this._lastSelection)}function I(e,t,n){var i,o;for(i=t.firstChild;i;i=o){if(o=i.nextSibling,a(i)){if(i.nodeType===F||"BR"===i.nodeName||"IMG"===i.nodeName){n.appendChild(i);continue}}else if(s(i)){n.appendChild(e.createDefaultBlock([I(e,i,e._doc.createDocumentFragment())]));continue}I(e,i,n)}return n}var w=1,F=3,M=9,H=11,W=1,z="​",q=e.defaultView,K=navigator.userAgent,G=(/Android/.test(K),/Mac OS X/.test(K)),Z=/Windows NT/.test(K),Q=/iP(?:ad|hone|od)/.test(K)||G&&!!navigator.maxTouchPoints,$=/Gecko\//.test(K),j=/Edge\//.test(K),V=!j&&/WebKit\//.test(K),Y=/Trident\/[4567]\./.test(K),X=G?"meta-":"ctrl-",J=V,ee="undefined"!=typeof MutationObserver,te="undefined"!=typeof WeakMap,ne=/[^ \t\r\n]/,ie=Array.prototype.indexOf,oe={1:1,2:2,3:4,8:128,9:256,11:1024},re=function(){return!0};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,i=this.nodeType,o=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)(e=t.nextSibling)||(t=t.parentNode);if(!e)return null;if(oe[e.nodeType]&i&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,i=this.nodeType,o=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(oe[e.nodeType]&i&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,i=this.nodeType,o=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)(e=t.previousSibling)||(t=t.parentNode);if(!e)return null;if(oe[e.nodeType]&i&&o(e))return this.currentNode=e,e;t=e}};var ae=/^(?:#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)$/,se={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},de=0,le=1,ce=2,he=3,fe=te?new WeakMap:null,ue=function(e,t){for(var n=e.childNodes;t&&e.nodeType===w;)e=n[t-1],n=e.childNodes,t=n.length;return e},pe=function(e,t){if(e.nodeType===w){var n=e.childNodes;if(t-1,r=e.compareBoundaryPoints(1,i)<1;return!o&&!r}var a=e.compareBoundaryPoints(0,i)<1,s=e.compareBoundaryPoints(2,i)>-1;return a&&s},Ne=function(e){for(var t,n=e.startContainer,i=e.startOffset,r=e.endContainer,a=e.endOffset,s=!0;n.nodeType!==F&&(t=n.childNodes[i])&&!o(t);)n=t,i=0;if(a)for(;r.nodeType!==F;){if(!(t=r.childNodes[a-1])||o(t)){if(s&&t&&"BR"===t.nodeName){a-=1,s=!1;continue}break}r=t,a=C(r)}else for(;r.nodeType!==F&&(t=r.firstChild)&&!o(t);)r=t;e.collapsed?(e.setStart(r,a),e.setEnd(n,i)):(e.setStart(n,i),e.setEnd(r,a))},Se=function(e,t,n,i){var o,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!==i;)o=r.parentNode,a=ie.call(o.childNodes,r),r=o;for(;;){if(s===n||s===i)break;if(l&&s.nodeType!==F&&s.childNodes[d]&&"BR"===s.childNodes[d].nodeName&&(d+=1,l=!1),d!==C(s))break;o=s.parentNode,d=ie.call(o.childNodes,s)+1,s=o}e.setStart(r,a),e.setEnd(s,d)},ye=function(e,t,n){var i=g(e.endContainer,n,"A");if(i){var o=e.cloneRange();i=i.parentNode,Se(o,i,i,n),o.endContainer===i&&(e.setStart(o.endContainer,o.endOffset),e.setEnd(o.endContainer,o.endOffset))}return e},Te=function(e,t){var n,i=e.startContainer;return a(i)?n=c(i,t):i!==t&&s(i)?n=i:(n=ue(i,e.startOffset),n=h(n,t)),n&&_e(e,n,!0)?n:null},Ee=function(e,t){var n,i,o=e.endContainer;if(a(o))n=c(o,t);else if(o!==t&&s(o))n=o;else{if(!(n=pe(o,e.endOffset))||!m(t,n))for(n=t;i=n.lastChild;)n=i;n=c(n,t)}return n&&_e(e,n,!0)?n:null},be=new n(null,4|W,function(e){return e.nodeType===F?ne.test(e.data):"INPUT"===e.nodeName||"IMG"===e.nodeName||!e.isContentEditable}),ke=function(e,t){var n,i=e.startContainer,o=e.startOffset;if(be.root=null,i.nodeType===F){if(o)return!1;n=i}else if(n=pe(i,o),n&&!m(t,n)&&(n=null),!n&&(n=ue(i,o),n.nodeType===F&&n.length))return!1;return be.currentNode=n,be.root=Te(e,t),!be.previousNode()},Le=function(e,t){var n,i=e.endContainer,o=e.endOffset;if(be.root=null,i.nodeType===F){if((n=i.data.length)&&o)BLOCKQUOTE/.test(o)||!/(?:^|>)[OU]L/.test(o)?n[e]():n[t]()}},Fe=function(e,t){return function(n,i){i.preventDefault();var o=n.getPath();e.test(o)?n.removeList():n[t]()}};Ie[X+"b"]=Re("B"),Ie[X+"i"]=Re("I"),Ie[X+"u"]=Re("U"),Ie[X+"shift-7"]=Re("S"),Ie[X+"shift-5"]=Re("SUB",{tag:"SUP"}),Ie[X+"shift-6"]=Re("SUP",{tag:"SUB"}),Ie[X+"shift-8"]=Fe(/(?:^|>)UL/,"makeUnorderedList"),Ie[X+"shift-9"]=Fe(/(?:^|>)OL/,"makeOrderedList"),Ie[X+"["]=we("decreaseQuoteLevel","decreaseListLevel"),Ie[X+"]"]=we("increaseQuoteLevel","increaseListLevel"),Ie[X+"d"]=Be("toggleCode"),Ie[X+"y"]=Be("redo"),Ie[X+"z"]=Be("undo"),Ie[X+"shift-z"]=Be("redo");var Me={1:10,2:13,3:16,4:18,5:24,6:32,7:48},He={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:ne,replace:function(e,t,n){return y(e,"SPAN",{class:t.fontFamily,style:"font-family:"+n})}},fontSize:{regexp:ne,replace:function(e,t,n){return y(e,"SPAN",{class:t.fontSize,style:"font-size:"+n})}},textDecoration:{regexp:/^underline/i,replace:function(e){return y(e,"U")}}},We=function(e){return function(t,n){var i,o,r,a=y(t.ownerDocument,e),s=t.attributes;for(i=0,o=s.length;i-1||!$&&ie.call(o,"text/plain")>-1&&ie.call(o,"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 g=this._doc.body,m=this.getSelection(),v=m.startContainer,C=m.startOffset,N=m.endContainer,S=m.endOffset,y=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});g.appendChild(y),m.selectNodeContents(y),this.setSelection(m),setTimeout(function(){try{p._awaitingPaste=!1;for(var e,t,n="",i=y;y=i;)i=y.nextSibling,_(y),e=y.firstChild,e&&e===y.lastChild&&"DIV"===e.nodeName&&(y=e),n+=y.innerHTML;t=p.createRange(v,C,N,S),p.setSelection(t),n&&p.insertHTML(n,!0)}catch(e){p.didError(e)}},0)},it=function(e){for(var t=e.dataTransfer.types,n=t.length,i=!1,o=!1;n--;)switch(t[n]){case"text/plain":i=!0;break;case"text/html":o=!0;break;default:return}(o||i)&&this.saveUndoState()},ot=R.prototype,rt=function(e,t,n){var i=n._doc,o=e?DOMPurify.sanitize(e,{ALLOW_UNKNOWN_PROTOCOLS:!0,WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}):null;return o?i.importNode(o,!0):i.createDocumentFragment()};ot.setConfig=function(e){return e=B({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},classNames:{colour:"colour",fontFamily:"font",fontSize:"size",highlight:"highlight"},leafNodeNames:se,undo:{documentSizeThreshold:-1,undoLimit:-1},isInsertedHTMLSanitized:!0,isSetHTMLSanitized:!0,sanitizeToDOMFragment:"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?rt:null,willCutCopy:null,addLinks:!0},e,!0),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},ot.createElement=function(e,t,n){return y(this._doc,e,t,n)},ot.createDefaultBlock=function(e){var t=this._config;return T(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},ot.didError=function(e){console.log(e)},ot.getDocument=function(){return this._doc},ot.getRoot=function(){return this._root},ot.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 at={pathChange:1,select:1,input:1,undoStateChange:1};ot.fireEvent=function(e,t){var n,i,o,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(),i=r.length;i--;){o=r[i];try{o.handleEvent?o.handleEvent(t):o.call(this,t)}catch(t){t.details="Squire: fireEvent error. Event type: "+e,this.didError(t)}}return this},ot.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},ot.handleEvent=function(e){this.fireEvent(e.type,e)},ot.addEventListener=function(e,t){var n=this._events[e],i=this._root;return t?(n||(n=this._events[e]=[],at[e]||("selectionchange"===e&&(i=this._doc),i.addEventListener(e,this,!0))),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},ot.removeEventListener=function(e,t){var n,i=this._events[e],o=this._root;if(i){if(t)for(n=i.length;n--;)i[n]===t&&i.splice(n,1);else i.length=0;i.length||(delete this._events[e],at[e]||("selectionchange"===e&&(o=this._doc),o.removeEventListener(e,this,!0)))}return this},ot.createRange=function(e,t,n,i){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,i):o.setEnd(e,t),o},ot.getCursorPosition=function(e){if(!e&&!(e=this.getSelection())||!e.getBoundingClientRect)return null;var t,n,i=e.getBoundingClientRect();return i&&!i.top&&(this._ignoreChange=!0,t=this._doc.createElement("SPAN"),t.textContent=z,ge(e,t),i=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),L(n,e)),i},ot._moveCursorTo=function(e){var t=this._root,n=this.createRange(t,e?0:t.childNodes.length);return Ne(n),this.setSelection(n),this},ot.moveCursorToStart=function(){return this._moveCursorTo(!0)},ot.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var st=function(e){return e._win.getSelection()||null};ot.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused){Q&&this._win.focus();var t=st(this);t&&t.setBaseAndExtent?t.setBaseAndExtent(e.startContainer,e.startOffset,e.endContainer,e.endOffset):t&&(t.removeAllRanges(),t.addRange(e))}else D.call(this);return this},ot.getSelection=function(){var e,t,n,i,r=st(this),a=this._root;return this._isFocused&&r&&r.rangeCount&&(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&o(t)&&e.setStartBefore(t),n&&o(n)&&e.setEndBefore(n)),e&&m(a,e.commonAncestorContainer)?this._lastSelection=e:(e=this._lastSelection,i=e.commonAncestorContainer,m(i.ownerDocument,i)||(e=null)),e||(e=this.createRange(a.firstChild,0)),e},ot.getSelectedText=function(){var e=this.getSelection();if(!e||e.collapsed)return"";var t,i=new n(e.commonAncestorContainer,4|W,function(t){return _e(e,t,!0)}),o=e.startContainer,r=e.endContainer,s=i.currentNode=o,d="",l=!1;for(i.filter(s)||(s=i.nextNode());s;)s.nodeType===F?(t=s.data)&&/\S/.test(t)&&(s===r&&(t=t.slice(0,e.endOffset)),s===o&&(t=t.slice(e.startOffset)),d+=t,l=!0):("BR"===s.nodeName||l&&!a(s))&&(d+="\n",l=!1),s=i.nextNode();return d},ot.getPath=function(){return this._path};var dt=function(e,t){for(var i,o,r,s=new n(e,4);o=s.nextNode();)for(;(r=o.data.indexOf(z))>-1&&(!t||o.parentNode!==t);){if(1===o.length){do{i=o.parentNode,i.removeChild(o),o=i,s.currentNode=i}while(a(o)&&!C(o));break}o.deleteData(r,1)}};ot._didAddZWS=function(){this._hasZWS=!0},ot._removeZWS=function(){this._hasZWS&&(dt(this._root),this._hasZWS=!1)},ot._updatePath=function(e,t){if(e){var n,i=e.startContainer,o=e.endContainer;(t||i!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=i,this._lastFocusNode=o,n=i&&o?i===o?v(o,this._root,this._config):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),this.fireEvent(e.collapsed?"cursor":"select",{range:e})}},ot._updatePathOnEvent=function(){var e=this;e._isFocused&&!e._willUpdatePath&&(e._willUpdatePath=!0,setTimeout(function(){e._willUpdatePath=!1,e._updatePath(e.getSelection())},0))},ot.focus=function(){return this._root.focus({preventScroll:!0}),Y&&this.fireEvent("focus"),this},ot.blur=function(){return this._root.blur(),Y&&this.fireEvent("blur"),this};var lt="squire-selection-end" -;ot._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:"squire-selection-start",type:"hidden"}),i=this.createElement("INPUT",{id:lt,type:"hidden"});ge(e,n),e.collapse(!1),ge(e,i),2&n.compareDocumentPosition(i)&&(n.id=lt,i.id="squire-selection-start",t=n,n=i,i=t),e.setStartAfter(n),e.setEndBefore(i)},ot._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#squire-selection-start"),i=t.querySelector("#"+lt);if(n&&i){var o=n.parentNode,r=i.parentNode,a=ie.call(o.childNodes,n),s=ie.call(r.childNodes,i);o===r&&(s-=1),_(n),_(i),e||(e=this._doc.createRange()),e.setStart(o,a),e.setEnd(r,s),L(o,e),o!==r&&L(r,e),e.collapsed&&(o=e.startContainer,o.nodeType===F&&(r=o.childNodes[e.startOffset],r&&r.nodeType===F||(r=o.childNodes[e.startOffset-1]),r&&r.nodeType===F&&(e.setStart(r,0),e.collapse(!0))))}return e||null},ot._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(t<16||t>20)||!(t<33||t>45)||this._docWasChanged()},ot._docWasChanged=function(){if(te&&(fe=new WeakMap),!this._ignoreAllChanges){if(ee&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},ot._recordUndoState=function(e,t){if(!this._isInUndoState||t){var n,i=this._undoIndex,o=this._undoStack,r=this._config.undo,a=r.documentSizeThreshold,s=r.undoLimit;t||(i+=1),i-1&&2*n.length>a&&s>-1&&i>s&&(o.splice(0,i-s),i=s,this._undoStackLength=s),o[i]=n,this._undoIndex=i,this._undoStackLength+=1,this._isInUndoState=!0}},ot.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._recordUndoState(e,this._isInUndoState),this._getRangeAndRemoveBookmark(e),this},ot.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},ot.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(e+1c&&h.splitText(c),h===s&&l&&(h=h.splitText(l),d===s&&(d=h,c-=l),s=h,l=0),o=this.createElement(e,t),N(h,o),o.appendChild(h))}while(r.nextNode());d.nodeType!==F&&(h.nodeType===F?(d=h,c=h.length):(d=h.parentNode,c=1)),i=this.createRange(s,l,d,c)}return i},ot._removeFormat=function(e,t,n,i){this._saveRangeToBookmark(n);var o,r=this._doc;n.collapsed&&(J?(o=r.createTextNode(z),this._didAddZWS()):o=r.createTextNode(""),ge(n,o));for(var s=n.commonAncestorContainer;a(s);)s=s.parentNode;var d=n.startContainer,l=n.startOffset,c=n.endContainer,h=n.endOffset,f=[],u=function(e,t){if(!_e(n,e,!1)){var i,o,r=e.nodeType===F;if(!_e(n,e,!0))return void("INPUT"===e.nodeName||r&&!e.data||f.push([t,e]));if(r)e===c&&h!==e.length&&f.push([t,e.splitText(h)]),e===d&&l&&(e.splitText(l),f.push([t,e]));else for(i=e.firstChild;i;i=o)o=i.nextSibling,u(i,t)}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(i){return _e(n,i,!0)&&p(i,e,t)});return i||g.forEach(function(e){u(e,e)}),f.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),g.forEach(function(e){N(e,S(e))}),this._getRangeAndRemoveBookmark(n),o&&n.collapse(!1),L(s,n),n},ot.changeFormat=function(e,t,n,i){return n||(n=this.getSelection())?(this.saveUndoState(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,i)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),ee||this._docWasChanged(),this):this};var ct={DT:"DD",DD:"DT",LI:"LI",PRE:"PRE"},ht=function(e,t,n,i){var o=ct[t.nodeName],r=null,a=b(n,i,t.parentNode,e._root),s=e._config;return o||(o=s.blockTag,r=s.blockAttributes),p(a,o,r)||(t=y(a.ownerDocument,o,r),a.dir&&(t.dir=a.dir),N(a,t),t.appendChild(S(a)),a=t),a};ot.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var i=this._root,o=Te(n,i),r=Ee(n,i);if(o&&r)do{if(e(o)||o===r)break}while(o=h(o,i));return t&&(this.setSelection(n),this._updatePath(n,!0),ee||this._docWasChanged()),this},ot.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._recordUndoState(t,this._isInUndoState);var n,i=this._root;return xe(t,i),Se(t,i,i,i),n=me(t,i,i),ge(t,e.call(this,n)),t.endOffset]+|\([^\s()<>]+\))+(?:[^\s?&`!()\[\]{};:'".,<>«»“”‘’]|\([^\s()<>]+\)))|([\w\-.%+]+@(?:[\w\-]+\.)+[a-z]{2,}\b(?:[?][^&?\s]+=[^\s?&`!()\[\]{};:'".,<>«»“”‘’]+(?:&[^&?\s]+=[^\s?&`!()\[\]{};:'".,<>«»“”‘’]+)*)?))/i;var Nt=function(e,t,i){var o,r,a,s,d,l,c,h,f=e.ownerDocument,u=new n(e,4,function(e){return!g(e,t,"A")}),p=i.linkRegExp,m=i._config.tagAttributes.a;if(p)for(;o=u.nextNode();)for(r=o.data,a=o.parentNode;s=p.exec(r);)d=s.index,l=d+s[0].length,d&&(c=f.createTextNode(r.slice(0,d)),a.insertBefore(c,o)),h=s[1]?/^(?:ht|f)tps?:/i.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[0],c=i.createElement("A",B({href:h},m,!1)),c.textContent=r.slice(d,l),a.insertBefore(c,o),o.data=r=r.slice(l),i.fireEvent("addLink",{link:h})};ot.insertHTML=function(e,t){var n,i,o,r,a,s,d,l=this._config,c=l.isInsertedHTMLSanitized?l.sanitizeToDOMFragment:null,f=this.getSelection(),u=this._doc;"function"==typeof c?r=c(e,t,this):(t&&(n=e.indexOf("\x3c!--StartFragment--\x3e"),i=e.lastIndexOf("\x3c!--EndFragment--\x3e"),n>-1&&i>-1&&(e=e.slice(n+20,i))),/<\/td>((?!<\/tr>)[\s\S])*$/i.test(e)&&(e=""+e+""),/<\/tr>((?!<\/table>)[\s\S])*$/i.test(e)&&(e=""+e+"
"),o=this.createElement("DIV"),o.innerHTML=e,r=u.createDocumentFragment(),r.appendChild(S(o))),this.saveUndoState(f);try{for(a=this._root,s=r,d={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},Nt(r,r,this),Qe(r,l),Ye(r,a,!1),$e(r),r.normalize();s=h(s,r);)T(s,a);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(Ce(f,d.fragment,a),ee||this._docWasChanged(),f.collapse(!1),ye(f,0,a),this._ensureBottomLine()),this.setSelection(f),this._updatePath(f,!0),t&&this.focus()}catch(e){this.didError(e)}return this};var St=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};ot.insertPlainText=function(e,t){var n=this.getSelection();if(n.collapsed&&g(n.startContainer,this._root,"PRE")){var i,o,r=n.startContainer,a=n.startOffset;return r&&r.nodeType===F||(i=this._doc.createTextNode(""),r.insertBefore(i,r.childNodes[a]),r=i,a=0),o={text:e,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},t&&this.fireEvent("willPaste",o),o.defaultPrevented||(e=o.text,r.insertData(a,e),n.setStart(r,a+e.length),n.collapse(!0)),this.setSelection(n),this}var s,d,l,c,h=e.split("\n"),f=this._config,u=f.blockTag,p=f.blockAttributes,m="",v="<"+u;for(s in p)v+=" "+s+'="'+St(p[s])+'"';for(v+=">",d=0,l=h.length;d")+m),h[d]=c;return this.insertHTML(h.join(""),t)};var yt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};ot.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},ot.bold=yt("changeFormat",{tag:"B"}),ot.italic=yt("changeFormat",{tag:"I"}),ot.underline=yt("changeFormat",{tag:"U"}),ot.strikethrough=yt("changeFormat",{tag:"S"}),ot.subscript=yt("changeFormat",{tag:"SUB"},{tag:"SUP"}),ot.superscript=yt("changeFormat",{tag:"SUP"},{tag:"SUB"}),ot.removeBold=yt("changeFormat",null,{tag:"B"}),ot.removeItalic=yt("changeFormat",null,{tag:"I"}),ot.removeUnderline=yt("changeFormat",null,{tag:"U"}),ot.removeStrikethrough=yt("changeFormat",null,{tag:"S"}),ot.removeSubscript=yt("changeFormat",null,{tag:"SUB"}),ot.removeSuperscript=yt("changeFormat",null,{tag:"SUP"}),ot.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var i=e.indexOf(":")+1;if(i)for(;"/"===e[i];)i+=1;ge(n,this._doc.createTextNode(e.slice(i)))}return t=B(B({href:e},t,!0),this._config.tagAttributes.a,!1),this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},ot.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},ot.setFontFace=function(e){var t=this._config.classNames.fontFamily;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{class:t}}),this.focus()},ot.setFontSize=function(e){var t=this._config.classNames.fontSize;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{class:t}}),this.focus()},ot.setTextColour=function(e){var t=this._config.classNames.colour;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"color:"+e}}:null,{tag:"SPAN",attributes:{class:t}}),this.focus()},ot.setHighlightColour=function(e){var t=this._config.classNames.highlight;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{class:t}}),this.focus()},ot.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()},ot.setTextDirection=function(e){return this.forEachBlock(function(t){e?t.dir=e:t.removeAttribute("dir")},!0),this.focus()};var Tt=function(e){for(var t,i=this._root,o=this._doc,r=o.createDocumentFragment(),a=l(e,i);t=a.nextNode();){var s,d,c=t.querySelectorAll("BR"),h=[],f=c.length;for(s=0;s-1;)a.appendChild(d.createTextNode(r.slice(0,s))),a.appendChild(d.createElement("BR")),r=r.slice(s+1);o.parentNode.insertBefore(a,o),o.data=r}E(t,l),N(t,S(t))}return e};ot.code=function(){var e=this.getSelection();return e.collapsed||d(e.commonAncestorContainer)?this.modifyBlocks(Tt,e):this.changeFormat({tag:"CODE",attributes:this._config.tagAttributes.code},null,e),this.focus()},ot.removeCode=function(){var e=this.getSelection();return g(e.commonAncestorContainer,this._root,"PRE")?this.modifyBlocks(Et,e):this.changeFormat(null,{tag:"CODE"},e),this.focus()},ot.toggleCode=function(){return this.hasFormat("PRE")||this.hasFormat("CODE")?this.removeCode():this.code(),this},ot.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||(xe(e,t),n=t),n.nodeType===F)return this;this.saveUndoState(e),Se(e,n,n,t);for(var i,o,r=n.ownerDocument,a=e.startContainer,d=e.startOffset,l=e.endContainer,c=e.endOffset,h=r.createDocumentFragment(),f=r.createDocumentFragment(),u=b(l,c,n,t),p=b(a,d,n,t);p!==u;)i=p.nextSibling,h.appendChild(p),p=i;return I(this,h,f),f.normalize(),p=f.firstChild,i=f.lastChild,o=n.childNodes,p?(n.insertBefore(f,u),d=ie.call(o,p),c=ie.call(o,i)+1):(d=ie.call(o,u),c=d),e.setStart(n,d),e.setEnd(n,c),L(n,e),Ne(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},ot.increaseQuoteLevel=yt("modifyBlocks",ft),ot.decreaseQuoteLevel=yt("modifyBlocks",ut),ot.makeUnorderedList=yt("modifyBlocks",mt),ot.makeOrderedList=yt("modifyBlocks",vt),ot.removeList=yt("modifyBlocks",Ct),R.isInline=a,R.isBlock=s,R.isContainer=d,R.getBlockWalker=l,R.getPreviousBlock=c,R.getNextBlock=h,R.areAlike=u,R.hasTagAttributes=p,R.getNearest=g,R.isOrContains=m,R.detach=_,R.replaceWith=N,R.empty=S,R.getNodeBefore=ue,R.getNodeAfter=pe,R.insertNodeInRange=ge,R.extractContentsOfRange=me,R.deleteContentsOfRange=ve,R.insertTreeFragmentIntoRange=Ce,R.isNodeContainedInRange=_e,R.moveRangeBoundariesDownTree=Ne,R.moveRangeBoundariesUpTree=Se,R.getStartBlockOfRange=Te,R.getEndBlockOfRange=Ee,R.contentWalker=be,R.rangeDoesStartAtBlockBoundary=ke,R.rangeDoesEndAtBlockBoundary=Le,R.expandRangeToBlockBoundaries=xe,R.onCopy=et,R.onPaste=nt,R.addLinks=Nt,R.splitBlock=ht,R.startSelectionId="squire-selection-start",R.endSelectionId=lt,"object"==typeof exports?module.exports=R:"function"==typeof define&&define.amd?define(function(){return R}):(q.Squire=R,top!==q&&"true"===e.documentElement.getAttribute("data-squireinit")&&(q.editor=new R(e),q.onEditorLoad&&(q.onEditorLoad(q.editor),q.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||re}function i(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(e){return e.nodeType===w&&!!se[e.nodeName]}function r(e){switch(e.nodeType){case F:return le;case w:case H:if(te&&fe.has(e))return fe.get(e);break;default:return de}var t;return t=i(e.childNodes,a)?ae.test(e.nodeName)?le:ce:he,te&&fe.set(e,t),t}function a(e){return r(e)===le}function s(e){return r(e)===ce}function d(e){return r(e)===he}function l(e,t){var i=new n(t,W,s);return i.currentNode=e,i}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 f(e){return!e.textContent&&!e.querySelector("IMG")}function u(e,t){return!o(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 i in n)if(e.getAttribute(i)!==n[i])return!1;return!0}function g(e,t,n,i){for(;e&&e!==t;){if(p(e,n,i))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,n){var i,o,r,a,s,d="";return e&&e!==t&&(d=v(e.parentNode,t,n),e.nodeType===w&&(d+=(d?">":"")+e.nodeName,(i=e.id)&&(d+="#"+i),(o=e.className.trim())&&(r=o.split(/\s\s*/),r.sort(),d+=".",d+=r.join(".")),(a=e.dir)&&(d+="[dir="+a+"]"),r&&(s=n.classNames,ie.call(r,s.highlight)>-1&&(d+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),ie.call(r,s.colour)>-1&&(d+="[color="+e.style.color.replace(/ /g,"")+"]"),ie.call(r,s.fontFamily)>-1&&(d+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),ie.call(r,s.fontSize)>-1&&(d+="[fontSize="+e.style.fontSize+"]")))),d}function C(e){var t=e.nodeType;return t===w||t===H?e.childNodes.length:e.length||0}function N(e){var t=e.parentNode;return t&&t.removeChild(e),e}function _(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,i=n?n.length:0;i--;)t.appendChild(e.firstChild);return t}function y(e,n,i,o){var r,a,s,d,l=e.createElement(n);if(i instanceof Array&&(o=i,i=null),i)for(r in i)(a=i[r])!==t&&l.setAttribute(r,a);if(o)for(s=0,d=o.length;ss?t.startOffset-=1:t.startOffset===s&&(t.startContainer=i,t.startOffset=C(i))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=i,t.endOffset=C(i))),N(n),n.nodeType===F?i.appendData(n.data):d.push(S(n));else if(n.nodeType===w){for(o=d.length;o--;)n.appendChild(d.pop());k(n,t)}}function L(e,t){if(e.nodeType===F&&(e=e.parentNode),e.nodeType===w){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,i){for(var o,r,a,s=t;(o=s.parentNode)&&o!==i&&o.nodeType===w&&1===o.childNodes.length;)s=o;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)}function A(e,t){var n,i,o=e.previousSibling,r=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||r&&/^[OU]L$/.test(r.nodeName))if(o&&u(o,e)){if(!d(o)){if(!s)return;i=y(a,"DIV"),i.appendChild(S(o)),o.appendChild(i)}N(e),n=!d(e),o.appendChild(S(e)),n&&E(o,t),r&&A(r,t)}else s&&(o=y(a,"DIV"),e.insertBefore(o,r),T(o,t))}function O(e){this.isShiftDown=e.shiftKey}function B(e,t,n){var i,o;if(e||(e={}),t)for(i in t)!n&&i in e||(o=t[i],e[i]=o&&o.constructor===Object?B(e[i],o,n):o);return e}function R(e,t){e.nodeType===M&&(e=e.body);var n,i=e.ownerDocument,o=i.defaultView;this._win=o,this._doc=i,this._root=e,this._events={},this._isFocused=!1,this._lastSelection=null,this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this._willUpdatePath=!1,"onselectionchange"in i?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,ee?(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",D),this.addEventListener("mousedown",P),this.addEventListener("touchstart",P),this.addEventListener("focus",U),this._awaitingPaste=!1,this.addEventListener("cut",Je),this.addEventListener("copy",tt),this.addEventListener("keydown",O),this.addEventListener("keyup",O),this.addEventListener("paste",nt),this.addEventListener("drop",it),this.addEventListener("keydown",Oe),this._keyHandlers=Object.create(Ie),this.setConfig(t),e.setAttribute("contenteditable","true"),e.setAttribute("data-gramm","false");try{i.execCommand("enableObjectResizing",!1,"false"),i.execCommand("enableInlineTableEditing",!1,"false")}catch(e){}e.__squire__=this,this.setHTML("")}function D(){this._restoreSelection=!0}function P(){this._restoreSelection=!1}function U(){this._restoreSelection&&this.setSelection(this._lastSelection)}function I(e,t,n){var i,o;for(i=t.firstChild;i;i=o){if(o=i.nextSibling,a(i)){if(i.nodeType===F||"BR"===i.nodeName||"IMG"===i.nodeName){n.appendChild(i);continue}}else if(s(i)){n.appendChild(e.createDefaultBlock([I(e,i,e._doc.createDocumentFragment())]));continue}I(e,i,n)}return n}var w=1,F=3,M=9,H=11,W=1,z="​",q=e.defaultView,K=navigator.userAgent,G=(/Android/.test(K),/Mac OS X/.test(K)),Z=/Windows NT/.test(K),Q=/iP(?:ad|hone|od)/.test(K)||G&&!!navigator.maxTouchPoints,$=/Gecko\//.test(K),j=/Edge\//.test(K),V=!j&&/WebKit\//.test(K),Y=/Trident\/[4567]\./.test(K),X=G?"meta-":"ctrl-",J=V,ee="undefined"!=typeof MutationObserver,te="undefined"!=typeof WeakMap,ne=/[^ \t\r\n]/,ie=Array.prototype.indexOf,oe={1:1,2:2,3:4,8:128,9:256,11:1024},re=function(){return!0};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,i=this.nodeType,o=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)(e=t.nextSibling)||(t=t.parentNode);if(!e)return null;if(oe[e.nodeType]&i&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,i=this.nodeType,o=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(oe[e.nodeType]&i&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,i=this.nodeType,o=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)(e=t.previousSibling)||(t=t.parentNode);if(!e)return null;if(oe[e.nodeType]&i&&o(e))return this.currentNode=e,e;t=e}};var ae=/^(?:#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)$/,se={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},de=0,le=1,ce=2,he=3,fe=te?new WeakMap:null,ue=function(e,t){for(var n=e.childNodes;t&&e.nodeType===w;)e=n[t-1],n=e.childNodes,t=n.length;return e},pe=function(e,t){if(e.nodeType===w){var n=e.childNodes;if(t-1,r=e.compareBoundaryPoints(1,i)<1;return!o&&!r}var a=e.compareBoundaryPoints(0,i)<1,s=e.compareBoundaryPoints(2,i)>-1;return a&&s},_e=function(e){for(var t,n=e.startContainer,i=e.startOffset,r=e.endContainer,a=e.endOffset,s=!0;n.nodeType!==F&&(t=n.childNodes[i])&&!o(t);)n=t,i=0;if(a)for(;r.nodeType!==F;){if(!(t=r.childNodes[a-1])||o(t)){if(s&&t&&"BR"===t.nodeName){a-=1,s=!1;continue}break}r=t,a=C(r)}else for(;r.nodeType!==F&&(t=r.firstChild)&&!o(t);)r=t;e.collapsed?(e.setStart(r,a),e.setEnd(n,i)):(e.setStart(n,i),e.setEnd(r,a))},Se=function(e,t,n,i){var o,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!==i;)o=r.parentNode,a=ie.call(o.childNodes,r),r=o;for(;;){if(s===n||s===i)break;if(l&&s.nodeType!==F&&s.childNodes[d]&&"BR"===s.childNodes[d].nodeName&&(d+=1,l=!1),d!==C(s))break;o=s.parentNode,d=ie.call(o.childNodes,s)+1,s=o}e.setStart(r,a),e.setEnd(s,d)},ye=function(e,t,n){var i=g(e.endContainer,n,"A");if(i){var o=e.cloneRange();i=i.parentNode,Se(o,i,i,n),o.endContainer===i&&(e.setStart(o.endContainer,o.endOffset),e.setEnd(o.endContainer,o.endOffset))}return e},Te=function(e,t){var n,i=e.startContainer;return a(i)?n=c(i,t):i!==t&&s(i)?n=i:(n=ue(i,e.startOffset),n=h(n,t)),n&&Ne(e,n,!0)?n:null},Ee=function(e,t){var n,i,o=e.endContainer;if(a(o))n=c(o,t);else if(o!==t&&s(o))n=o;else{if(!(n=pe(o,e.endOffset))||!m(t,n))for(n=t;i=n.lastChild;)n=i;n=c(n,t)}return n&&Ne(e,n,!0)?n:null},be=new n(null,4|W,function(e){return e.nodeType===F?ne.test(e.data):"INPUT"===e.nodeName||"IMG"===e.nodeName||!e.isContentEditable}),ke=function(e,t){var n,i=e.startContainer,o=e.startOffset;if(be.root=null,i.nodeType===F){if(o)return!1;n=i}else if(n=pe(i,o),n&&!m(t,n)&&(n=null),!n&&(n=ue(i,o),n.nodeType===F&&n.length))return!1;return be.currentNode=n,be.root=Te(e,t),!be.previousNode()},Le=function(e,t){var n,i=e.endContainer,o=e.endOffset;if(be.root=null,i.nodeType===F){if((n=i.data.length)&&o)BLOCKQUOTE/.test(o)||!/(?:^|>)[OU]L/.test(o)?n[e]():n[t]()}},Fe=function(e,t){return function(n,i){i.preventDefault();var o=n.getPath();e.test(o)?n.removeList():n[t]()}};Ie[X+"b"]=Re("B"),Ie[X+"i"]=Re("I"),Ie[X+"u"]=Re("U"),Ie[X+"shift-7"]=Re("S"),Ie[X+"shift-5"]=Re("SUB",{tag:"SUP"}),Ie[X+"shift-6"]=Re("SUP",{tag:"SUB"}),Ie[X+"shift-8"]=Fe(/(?:^|>)UL/,"makeUnorderedList"),Ie[X+"shift-9"]=Fe(/(?:^|>)OL/,"makeOrderedList"),Ie[X+"["]=we("decreaseQuoteLevel","decreaseListLevel"),Ie[X+"]"]=we("increaseQuoteLevel","increaseListLevel"),Ie[X+"d"]=Be("toggleCode"),Ie[X+"y"]=Be("redo"),Ie[X+"z"]=Be("undo"),Ie[X+"shift-z"]=Be("redo");var Me={1:10,2:13,3:16,4:18,5:24,6:32,7:48},He={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:ne,replace:function(e,t,n){return y(e,"SPAN",{class:t.fontFamily,style:"font-family:"+n})}},fontSize:{regexp:ne,replace:function(e,t,n){return y(e,"SPAN",{class:t.fontSize,style:"font-size:"+n})}},textDecoration:{regexp:/^underline/i,replace:function(e){return y(e,"U")}}},We=function(e){return function(t,n){var i,o,r,a=y(t.ownerDocument,e),s=t.attributes;for(i=0,o=s.length;i-1||!$&&ie.call(o,"text/plain")>-1&&ie.call(o,"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 g=this._doc.body,m=this.getSelection(),v=m.startContainer,C=m.startOffset,_=m.endContainer,S=m.endOffset,y=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});g.appendChild(y),m.selectNodeContents(y),this.setSelection(m),setTimeout(function(){try{p._awaitingPaste=!1;for(var e,t,n="",i=y;y=i;)i=y.nextSibling,N(y),e=y.firstChild,e&&e===y.lastChild&&"DIV"===e.nodeName&&(y=e),n+=y.innerHTML;t=p.createRange(v,C,_,S),p.setSelection(t),n&&p.insertHTML(n,!0)}catch(e){p.didError(e)}},0)},it=function(e){for(var t=e.dataTransfer.types,n=t.length,i=!1,o=!1;n--;)switch(t[n]){case"text/plain":i=!0;break;case"text/html":o=!0;break;default:return}(o||i)&&this.saveUndoState()},ot=R.prototype,rt=function(e,t,n){var i=n._doc,o=e?DOMPurify.sanitize(e,{ALLOW_UNKNOWN_PROTOCOLS:!0,WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}):null;return o?i.importNode(o,!0):i.createDocumentFragment()};ot.setConfig=function(e){return e=B({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},classNames:{colour:"colour",fontFamily:"font",fontSize:"size",highlight:"highlight"},leafNodeNames:se,undo:{documentSizeThreshold:-1,undoLimit:-1},isInsertedHTMLSanitized:!0,isSetHTMLSanitized:!0,sanitizeToDOMFragment:"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?rt:null,willCutCopy:null,addLinks:!0},e,!0),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},ot.createElement=function(e,t,n){return y(this._doc,e,t,n)},ot.createDefaultBlock=function(e){var t=this._config;return T(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},ot.didError=function(e){console.log(e)},ot.getDocument=function(){return this._doc},ot.getRoot=function(){return this._root},ot.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 at={pathChange:1,select:1,input:1,undoStateChange:1};ot.fireEvent=function(e,t){var n,i,o,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(),i=r.length;i--;){o=r[i];try{o.handleEvent?o.handleEvent(t):o.call(this,t)}catch(t){t.details="Squire: fireEvent error. Event type: "+e,this.didError(t)}}return this},ot.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},ot.handleEvent=function(e){this.fireEvent(e.type,e)},ot.addEventListener=function(e,t){var n=this._events[e],i=this._root;return t?(n||(n=this._events[e]=[],at[e]||("selectionchange"===e&&(i=this._doc),i.addEventListener(e,this,!0))),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},ot.removeEventListener=function(e,t){var n,i=this._events[e],o=this._root;if(i){if(t)for(n=i.length;n--;)i[n]===t&&i.splice(n,1);else i.length=0;i.length||(delete this._events[e],at[e]||("selectionchange"===e&&(o=this._doc),o.removeEventListener(e,this,!0)))}return this},ot.createRange=function(e,t,n,i){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,i):o.setEnd(e,t),o},ot.getCursorPosition=function(e){if(!e&&!(e=this.getSelection())||!e.getBoundingClientRect)return null;var t,n,i=e.getBoundingClientRect();return i&&!i.top&&(this._ignoreChange=!0,t=this._doc.createElement("SPAN"),t.textContent=z,ge(e,t),i=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),L(n,e)),i},ot._moveCursorTo=function(e){var t=this._root,n=this.createRange(t,e?0:t.childNodes.length);return _e(n),this.setSelection(n),this},ot.moveCursorToStart=function(){return this._moveCursorTo(!0)},ot.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var st=function(e){return e._win.getSelection()||null};ot.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused){Q&&this._win.focus();var t=st(this);t&&t.setBaseAndExtent?t.setBaseAndExtent(e.startContainer,e.startOffset,e.endContainer,e.endOffset):t&&(t.removeAllRanges(),t.addRange(e))}else D.call(this);return this},ot.getSelection=function(){var e,t,n,i,r=st(this),a=this._root;return this._isFocused&&r&&r.rangeCount&&(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&o(t)&&e.setStartBefore(t),n&&o(n)&&e.setEndBefore(n)),e&&m(a,e.commonAncestorContainer)?this._lastSelection=e:(e=this._lastSelection,i=e.commonAncestorContainer,m(i.ownerDocument,i)||(e=null)),e||(e=this.createRange(a.firstChild,0)),e},ot.getSelectedText=function(){var e=this.getSelection();if(!e||e.collapsed)return"";var t,i=new n(e.commonAncestorContainer,4|W,function(t){return Ne(e,t,!0)}),o=e.startContainer,r=e.endContainer,s=i.currentNode=o,d="",l=!1;for(i.filter(s)||(s=i.nextNode());s;)s.nodeType===F?(t=s.data)&&/\S/.test(t)&&(s===r&&(t=t.slice(0,e.endOffset)),s===o&&(t=t.slice(e.startOffset)),d+=t,l=!0):("BR"===s.nodeName||l&&!a(s))&&(d+="\n",l=!1),s=i.nextNode();return d},ot.getPath=function(){return this._path};var dt=function(e,t){for(var i,o,r,s=new n(e,4);o=s.nextNode();)for(;(r=o.data.indexOf(z))>-1&&(!t||o.parentNode!==t);){if(1===o.length){do{i=o.parentNode,i.removeChild(o),o=i,s.currentNode=i}while(a(o)&&!C(o));break}o.deleteData(r,1)}};ot._didAddZWS=function(){this._hasZWS=!0},ot._removeZWS=function(){this._hasZWS&&(dt(this._root),this._hasZWS=!1)},ot._updatePath=function(e,t){if(e){var n,i=e.startContainer,o=e.endContainer;(t||i!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=i,this._lastFocusNode=o,n=i&&o?i===o?v(o,this._root,this._config):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),this.fireEvent(e.collapsed?"cursor":"select",{range:e})}},ot._updatePathOnEvent=function(){var e=this;e._isFocused&&!e._willUpdatePath&&(e._willUpdatePath=!0,setTimeout(function(){e._willUpdatePath=!1, +e._updatePath(e.getSelection())},0))},ot.focus=function(){return this._root.focus({preventScroll:!0}),Y&&this.fireEvent("focus"),this},ot.blur=function(){return this._root.blur(),Y&&this.fireEvent("blur"),this};var lt="squire-selection-end";ot._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:"squire-selection-start",type:"hidden"}),i=this.createElement("INPUT",{id:lt,type:"hidden"});ge(e,n),e.collapse(!1),ge(e,i),2&n.compareDocumentPosition(i)&&(n.id=lt,i.id="squire-selection-start",t=n,n=i,i=t),e.setStartAfter(n),e.setEndBefore(i)},ot._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#squire-selection-start"),i=t.querySelector("#"+lt);if(n&&i){var o=n.parentNode,r=i.parentNode,a=ie.call(o.childNodes,n),s=ie.call(r.childNodes,i);o===r&&(s-=1),N(n),N(i),e||(e=this._doc.createRange()),e.setStart(o,a),e.setEnd(r,s),L(o,e),o!==r&&L(r,e),e.collapsed&&(o=e.startContainer,o.nodeType===F&&(r=o.childNodes[e.startOffset],r&&r.nodeType===F||(r=o.childNodes[e.startOffset-1]),r&&r.nodeType===F&&(e.setStart(r,0),e.collapse(!0))))}return e||null},ot._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(t<16||t>20)||!(t<33||t>45)||this._docWasChanged()},ot._docWasChanged=function(){if(te&&(fe=new WeakMap),!this._ignoreAllChanges){if(ee&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},ot._recordUndoState=function(e,t){if(!this._isInUndoState||t){var n,i=this._undoIndex,o=this._undoStack,r=this._config.undo,a=r.documentSizeThreshold,s=r.undoLimit;t||(i+=1),i-1&&2*n.length>a&&s>-1&&i>s&&(o.splice(0,i-s),i=s,this._undoStackLength=s),o[i]=n,this._undoIndex=i,this._undoStackLength+=1,this._isInUndoState=!0}},ot.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._recordUndoState(e,this._isInUndoState),this._getRangeAndRemoveBookmark(e),this},ot.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},ot.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(e+1c&&h.splitText(c),h===s&&l&&(h=h.splitText(l),d===s&&(d=h,c-=l),s=h,l=0),o=this.createElement(e,t),_(h,o),o.appendChild(h))}while(r.nextNode());d.nodeType!==F&&(h.nodeType===F?(d=h,c=h.length):(d=h.parentNode,c=1)),i=this.createRange(s,l,d,c)}return i},ot._removeFormat=function(e,t,n,i){this._saveRangeToBookmark(n);var o,r=this._doc;n.collapsed&&(J?(o=r.createTextNode(z),this._didAddZWS()):o=r.createTextNode(""),ge(n,o));for(var s=n.commonAncestorContainer;a(s);)s=s.parentNode;var d=n.startContainer,l=n.startOffset,c=n.endContainer,h=n.endOffset,f=[],u=function(e,t){if(!Ne(n,e,!1)){var i,o,r=e.nodeType===F;if(!Ne(n,e,!0))return void("INPUT"===e.nodeName||r&&!e.data||f.push([t,e]));if(r)e===c&&h!==e.length&&f.push([t,e.splitText(h)]),e===d&&l&&(e.splitText(l),f.push([t,e]));else for(i=e.firstChild;i;i=o)o=i.nextSibling,u(i,t)}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(i){return Ne(n,i,!0)&&p(i,e,t)});return i||g.forEach(function(e){u(e,e)}),f.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];_(n,t),t.appendChild(n)}),g.forEach(function(e){_(e,S(e))}),this._getRangeAndRemoveBookmark(n),o&&n.collapse(!1),L(s,n),n},ot.changeFormat=function(e,t,n,i){return n||(n=this.getSelection())?(this.saveUndoState(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,i)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),ee||this._docWasChanged(),this):this};var ct={DT:"DD",DD:"DT",LI:"LI",PRE:"PRE"},ht=function(e,t,n,i){var o=ct[t.nodeName],r=null,a=b(n,i,t.parentNode,e._root),s=e._config;return o||(o=s.blockTag,r=s.blockAttributes),p(a,o,r)||(t=y(a.ownerDocument,o,r),a.dir&&(t.dir=a.dir),_(a,t),t.appendChild(S(a)),a=t),a};ot.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var i=this._root,o=Te(n,i),r=Ee(n,i);if(o&&r)do{if(e(o)||o===r)break}while(o=h(o,i));return t&&(this.setSelection(n),this._updatePath(n,!0),ee||this._docWasChanged()),this},ot.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._recordUndoState(t,this._isInUndoState);var n,i=this._root;return xe(t,i),Se(t,i,i,i),n=me(t,i,i),ge(t,e.call(this,n)),t.endOffset]+|\([^\s()<>]+\))+(?:[^\s?&`!()\[\]{};:'".,<>«»“”‘’]|\([^\s()<>]+\)))|([\w\-.%+]+@(?:[\w\-]+\.)+[a-z]{2,}\b(?:[?][^&?\s]+=[^\s?&`!()\[\]{};:'".,<>«»“”‘’]+(?:&[^&?\s]+=[^\s?&`!()\[\]{};:'".,<>«»“”‘’]+)*)?))/i;var _t=function(e,t,i){var o,r,a,s,d,l,c,h,f=e.ownerDocument,u=new n(e,4,function(e){return!g(e,t,"A")}),p=i.linkRegExp,m=i._config.tagAttributes.a;if(p)for(;o=u.nextNode();)for(r=o.data,a=o.parentNode;s=p.exec(r);)d=s.index,l=d+s[0].length,d&&(c=f.createTextNode(r.slice(0,d)),a.insertBefore(c,o)),h=s[1]?/^(?:ht|f)tps?:/i.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[0],c=i.createElement("A",B({href:h},m,!1)),c.textContent=r.slice(d,l),a.insertBefore(c,o),o.data=r=r.slice(l),i.fireEvent("addLink",{link:h})};ot.insertHTML=function(e,t){var n,i,o,r,a,s,d,l=this._config,c=l.isInsertedHTMLSanitized?l.sanitizeToDOMFragment:null,f=this.getSelection(),u=this._doc;"function"==typeof c?r=c(e,t,this):(t&&(n=e.indexOf("\x3c!--StartFragment--\x3e"),i=e.lastIndexOf("\x3c!--EndFragment--\x3e"),n>-1&&i>-1&&(e=e.slice(n+20,i))),/<\/td>((?!<\/tr>)[\s\S])*$/i.test(e)&&(e=""+e+""),/<\/tr>((?!<\/table>)[\s\S])*$/i.test(e)&&(e=""+e+"
"),o=this.createElement("DIV"),o.innerHTML=e,r=u.createDocumentFragment(),r.appendChild(S(o))),this.saveUndoState(f);try{for(a=this._root,s=r,d={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},_t(r,r,this),Qe(r,l),Ye(r,a,!1),$e(r),r.normalize();s=h(s,r);)T(s,a);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(Ce(f,d.fragment,a),ee||this._docWasChanged(),f.collapse(!1),ye(f,0,a),this._ensureBottomLine()),this.setSelection(f),this._updatePath(f,!0),t&&this.focus()}catch(e){this.didError(e)}return this};var St=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};ot.insertPlainText=function(e,t){var n=this.getSelection();if(n.collapsed&&g(n.startContainer,this._root,"PRE")){var i,o,r=n.startContainer,a=n.startOffset;return r&&r.nodeType===F||(i=this._doc.createTextNode(""),r.insertBefore(i,r.childNodes[a]),r=i,a=0),o={text:e,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},t&&this.fireEvent("willPaste",o),o.defaultPrevented||(e=o.text,r.insertData(a,e),n.setStart(r,a+e.length),n.collapse(!0)),this.setSelection(n),this}var s,d,l,c,h=e.split("\n"),f=this._config,u=f.blockTag,p=f.blockAttributes,m="",v="<"+u;for(s in p)v+=" "+s+'="'+St(p[s])+'"';for(v+=">",d=0,l=h.length;d")+m),h[d]=c;return this.insertHTML(h.join(""),t)};var yt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};ot.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},ot.bold=yt("changeFormat",{tag:"B"}),ot.italic=yt("changeFormat",{tag:"I"}),ot.underline=yt("changeFormat",{tag:"U"}),ot.strikethrough=yt("changeFormat",{tag:"S"}),ot.subscript=yt("changeFormat",{tag:"SUB"},{tag:"SUP"}),ot.superscript=yt("changeFormat",{tag:"SUP"},{tag:"SUB"}),ot.removeBold=yt("changeFormat",null,{tag:"B"}),ot.removeItalic=yt("changeFormat",null,{tag:"I"}),ot.removeUnderline=yt("changeFormat",null,{tag:"U"}),ot.removeStrikethrough=yt("changeFormat",null,{tag:"S"}),ot.removeSubscript=yt("changeFormat",null,{tag:"SUB"}),ot.removeSuperscript=yt("changeFormat",null,{tag:"SUP"}),ot.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var i=e.indexOf(":")+1;if(i)for(;"/"===e[i];)i+=1;ge(n,this._doc.createTextNode(e.slice(i)))}return t=B(B({href:e},t,!0),this._config.tagAttributes.a,!1),this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},ot.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},ot.setFontFace=function(e){var t=this._config.classNames.fontFamily;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{class:t}}),this.focus()},ot.setFontSize=function(e){var t=this._config.classNames.fontSize;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{class:t}}),this.focus()},ot.setTextColour=function(e){var t=this._config.classNames.colour;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"color:"+e}}:null,{tag:"SPAN",attributes:{class:t}}),this.focus()},ot.setHighlightColour=function(e){var t=this._config.classNames.highlight;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{class:t}}),this.focus()},ot.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()},ot.setTextDirection=function(e){return this.forEachBlock(function(t){e?t.dir=e:t.removeAttribute("dir")},!0),this.focus()};var Tt=function(e){for(var t,i=this._root,o=this._doc,r=o.createDocumentFragment(),a=l(e,i);t=a.nextNode();){var s,d,c=t.querySelectorAll("BR"),h=[],f=c.length;for(s=0;s-1;)a.appendChild(d.createTextNode(r.slice(0,s))),a.appendChild(d.createElement("BR")),r=r.slice(s+1);o.parentNode.insertBefore(a,o),o.data=r}E(t,l),_(t,S(t))}return e};ot.code=function(){var e=this.getSelection();return e.collapsed||d(e.commonAncestorContainer)?this.modifyBlocks(Tt,e):this.changeFormat({tag:"CODE",attributes:this._config.tagAttributes.code},null,e),this.focus()},ot.removeCode=function(){var e=this.getSelection();return g(e.commonAncestorContainer,this._root,"PRE")?this.modifyBlocks(Et,e):this.changeFormat(null,{tag:"CODE"},e),this.focus()},ot.toggleCode=function(){return this.hasFormat("PRE")||this.hasFormat("CODE")?this.removeCode():this.code(),this},ot.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||(xe(e,t),n=t),n.nodeType===F)return this;this.saveUndoState(e),Se(e,n,n,t);for(var i,o,r=n.ownerDocument,a=e.startContainer,d=e.startOffset,l=e.endContainer,c=e.endOffset,h=r.createDocumentFragment(),f=r.createDocumentFragment(),u=b(l,c,n,t),p=b(a,d,n,t);p!==u;)i=p.nextSibling,h.appendChild(p),p=i;return I(this,h,f),f.normalize(),p=f.firstChild,i=f.lastChild,o=n.childNodes,p?(n.insertBefore(f,u),d=ie.call(o,p),c=ie.call(o,i)+1):(d=ie.call(o,u),c=d),e.setStart(n,d),e.setEnd(n,c),L(n,e),_e(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},ot.increaseQuoteLevel=yt("modifyBlocks",ft),ot.decreaseQuoteLevel=yt("modifyBlocks",ut),ot.makeUnorderedList=yt("modifyBlocks",mt),ot.makeOrderedList=yt("modifyBlocks",vt),ot.removeList=yt("modifyBlocks",Ct),R.isInline=a,R.isBlock=s,R.isContainer=d,R.getBlockWalker=l,R.getPreviousBlock=c,R.getNextBlock=h,R.areAlike=u,R.hasTagAttributes=p,R.getNearest=g,R.isOrContains=m,R.detach=N,R.replaceWith=_,R.empty=S,R.getNodeBefore=ue,R.getNodeAfter=pe,R.insertNodeInRange=ge,R.extractContentsOfRange=me,R.deleteContentsOfRange=ve,R.insertTreeFragmentIntoRange=Ce,R.isNodeContainedInRange=Ne,R.moveRangeBoundariesDownTree=_e,R.moveRangeBoundariesUpTree=Se,R.getStartBlockOfRange=Te,R.getEndBlockOfRange=Ee,R.contentWalker=be,R.rangeDoesStartAtBlockBoundary=ke,R.rangeDoesEndAtBlockBoundary=Le,R.expandRangeToBlockBoundaries=xe,R.onCopy=et,R.onPaste=nt,R.addLinks=_t,R.splitBlock=ht,R.startSelectionId="squire-selection-start",R.endSelectionId=lt,"object"==typeof exports?module.exports=R:"function"==typeof define&&define.amd?define(function(){return R}):(q.Squire=R,top!==q&&"true"===e.documentElement.getAttribute("data-squireinit")&&(q.editor=new R(e),q.onEditorLoad&&(q.onEditorLoad(q.editor),q.onEditorLoad=null)))}(document); \ No newline at end of file diff --git a/package.json b/package.json index ac35cc07..b12889bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "squire-rte", - "version": "1.10.2-1", + "version": "1.10.2-2", "description": "Squire is an HTML5 rich text editor, which provides powerful cross-browser normalisation, whilst being supremely lightweight and flexible.", "main": "build/squire.js", "scripts": { diff --git a/source/KeyHandlers.js b/source/KeyHandlers.js index 850138c6..f61fdc54 100644 --- a/source/KeyHandlers.js +++ b/source/KeyHandlers.js @@ -175,6 +175,15 @@ var handleEnter = function ( self, shiftKey, range ) { block = getStartBlockOfRange( range, root ); + // If the block is begining with CHECKBOX, + // the splitted next line should begin with CHECKBOX. + var beginingCheckbox = ( + block.firstChild.nodeName == 'SPAN' && + !block.firstChild.isContentEditable && + block.firstChild.firstChild.nodeName == 'INPUT' && + block.firstChild.firstChild.getAttribute('TYPE') == 'checkbox' + ) && block.firstChild.cloneNode(true) || null; + // Inside a PRE, insert literal newline, unless on blank line. if ( block && ( parent = getNearest( block, root, 'PRE' ) ) ) { moveRangeBoundariesDownTree( range ); @@ -256,6 +265,14 @@ var handleEnter = function ( self, shiftKey, range ) { nodeAfterSplit = splitBlock( self, block, range.startContainer, range.startOffset ); + // If the block is begining with CHECKBOX, + // the splitted next line should begin with CHECKBOX, + // and the cursor should located at the next to the CHECKBOX. + if (beginingCheckbox) { + nodeAfterSplit.prepend(beginingCheckbox); + nodeAfterSplit = nodeAfterSplit.firstChild.nextSibling; + } + // Clean up any empty inlines if we hit enter at the beginning of the // block removeZWS( block );