Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lilium-text

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lilium-text - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

1

build/liliumtext.js

@@ -87,2 +87,3 @@ "use strict";

case "italic":
case "i":
case "em":

@@ -89,0 +90,0 @@ return "italic";

2

build/liliumtext.min.js

@@ -1,1 +0,1 @@

"use strict";var _slicedToArray=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],i=!0,o=!1,r=void 0;try{for(var s,a=e[Symbol.iterator]();!(i=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);i=!0);}catch(e){o=!0,r=e}finally{try{!i&&a.return&&a.return()}finally{if(o)throw r}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},_createClass=function(){function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}}();function _toConsumableArray(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var LiliumTextCommand=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"execute",value:function(){throw new Error("execute() method was not overridden in child class.")}},{key:"make",value:function(t){var n=this;this.editor=t;var e=document.createElement("i");if(e.className="liliumtext-topbar-command liliumtext-topbar-command-"+this.webName+" "+(this.cssClass||"liliumtext-topbar-noicon"),e.dataset.command=this.webName,this.text){var i=document.createElement("span");i.className="liliumtext-command-text",i.textContent=this.text,e.classList.add("liliumtext-command-withtext"),e.appendChild(i)}return e.addEventListener("mousedown",function(e){return e.preventDefault(),e.stopPropagation(),!1}),e.addEventListener("mouseup",function(e){return e.preventDefault(),e.stopPropagation(),t.log("Executed command "+n.webName+(n.param?" with parameter '"+n.param+"'":"")),t.fire("command",n.webName),n.execute(e,n,t),!1}),e}}]),e}(),LiliumTextBrowserCompat=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"runCommandOrFallback",value:function(e,t,n){document.execCommand(e,!1,t)||n(e,t)}},{key:"nodeToCommand",value:function(e){switch(e){case"strong":case"b":return"bold";case"italic":case"em":return"italic";case"underline":case"u":return"underline";case"strike":case"s":return"strikeThrough";default:return}}},{key:"getStrategyKind",value:function(){return window.navigator?document.execCommand?"exec":"logic":"old"}}]),e}(),LiliumTextWebCommand=function(e){function s(e,t,n,i,o){_classCallCheck(this,s);var r=_possibleConstructorReturn(this,(s.__proto__||Object.getPrototypeOf(s)).call(this));return r.webName=e,r.param=t,r.cssClass=n,r.imageURL=i,r.text=o,r}return _inherits(s,LiliumTextCommand),_createClass(s,[{key:"highlightNode",value:function(e){var t=this.editor.restoreSelection(),n=document.createRange();this.editor.log("Highlighting node "+e.nodeName+" from Web Command"),n.selectNode(e),t.removeAllRanges(),t.addRange(n),this.editor.storeRange(n)}},{key:"executeText",value:function(){var S=this,T=this.editor.restoreSelection(),L=this.param,e=LiliumTextBrowserCompat.nodeToCommand(L);LiliumTextBrowserCompat.runCommandOrFallback(e,this.param,function(){if("Caret"==T.type){var e=S.editor.createSelectionContext(T.focusNode).find(function(e){return e.type==L});e&&(S.editor.log("Unwrapping element of node type "+L),S.editor.unwrap(e))}else if("Range"==T.type){var t=L.toUpperCase(),n=T.anchorNode.compareDocumentPosition(T.focusNode)&Node.DOCUMENT_POSITION_FOLLOWING?[T.anchorNode,T.focusNode]:[T.focusNode,T.anchorNode],i=_slicedToArray(n,2),o=i[0],r=i[1],s=[S.editor.createSelectionContext(o),S.editor.createSelectionContext(r)],a=s[1],l=[s[0].find(function(e){return e.nodeName==t}),a.find(function(e){return e.nodeName==t})],c=l[0],u=l[1];S.editor.log("Long logic with range using node type "+L);var h=T.getRangeAt(0).extractContents(),d=!c&&!u&&h.querySelectorAll(L);if(o.parentElement!==r.parentElement||c||d.length)if(!c!=!u){S.editor.log("XOR range wrapper extension of node type "+L);var m=document.createElement(L);m.appendChild(h),T.getRangeAt(0).insertNode(m);var f=c||u;Array.prototype.forEach.call(f.querySelectorAll(L),function(e){S.editor.unwrap(e)}),S.highlightNode(node)}else if(0!=d.length)S.editor.log("Fragment child unwrap with node type "+L),Array.prototype.forEach.call(d,function(e){for(;e.firstChild;)e.parentNode?e.parentNode.insertBefore(e.firstChild,e):h.insertBefore(e.firstChild,h)}),Array.prototype.forEach.call(d,function(e){return e&&e.remove&&e.remove()}),T.getRangeAt(0).insertNode(h);else if(c&&u&&c===u){S.editor.log("Placeholder unwrap from two sources with node types : "+L);var p=document.createElement("liliumtext-placeholder");T.getRangeAt(0).insertNode(p);var g=c,v=g.cloneNode(!0);g.parentNode.insertBefore(v,g);for(var y=v.querySelector("liliumtext-placeholder");y.nextSibling;)y.nextSibling.remove();for(;p.previousSibling;)p.previousSibling.remove();g.parentNode.insertBefore(h,g),p.remove(),y.remove(),S.highlightNode(v)}else if(c&&u){S.editor.log("Merge wrap from two sources with node types : "+L);for(var C=h.firstChild,k=h.lastChild;C.nextSibling!=k;)C.appendChild(C.nextSibling);for(;k.firstChild;)C.appendChild(k.firstChild);k.remove(),T.getRangeAt(0).insertNode(h)}else if(1==h.childNodes.length&&h.childNodes[0].nodeName==L){S.editor.log("Single unwrap of node type : "+L);for(var b=h.childNodes[0];b.lastChild;)T.getRangeAt(0).insertNode(b.lastChild)}else{S.editor.log("Fragment wrap with node type : "+L);var x=document.createElement(L);x.appendChild(h);var w=T.getRangeAt(0);w.insertNode(x),w.selectNode(x),T.removeAllRanges(),T.addRange(w)}else{S.editor.log("Quick range wrap with element of node type "+L);var _=document.createElement(L);_.appendChild(h),T.getRangeAt(0).insertNode(_),S.highlightNode(_)}}})}},{key:"executeExec",value:function(){this.editor.restoreSelection(),document.execCommand(this.param)}},{key:"executeBlock",value:function(){var i=this,o=this.editor.restoreSelection(),r=o.getRangeAt(0),s=this.param,e=s.toUpperCase();LiliumTextBrowserCompat.runCommandOrFallback("formatBlock",e,function(){var e=i.editor.createSelectionContext(o.focusNode),t=(i.editor.settings.blockelements,e&&e.length?e[e.length-1]:i.editor.contentel.children[o.focusOffset]);if(t.nodeName!=s){var n=document.createElement(s);if(t.parentElement.insertBefore(n,t),t.data)n.appendChild(t);else{for(;t.firstChild;)n.appendChild(t.firstChild);t.remove()}r.setStart(n,0),r.collapse(!0),o.removeAllRanges(),o.addRange(r)}})}},{key:"executeRemove",value:function(){if("a"==this.param)this.editor.restoreSelection(),document.execCommand("unlink",!1);else if(this.param){var e=this.editor.restoreSelection().focusNode.parentNode,t=this.editor.createSelectionContext(e),n=this.param.toUpperCase(),i=t.find(function(e){return e.nodeName==n});i&&(this.editor.log("Unwrapping node "+this.param),this.editor.unwrap(i))}else this.editor.log("Executing native command removeFormat"),this.editor.restoreSelection(),document.execCommand("removeFormat",!1,"")}},{key:"executeInsert",value:function(){var e=this.param,t=document.createElement(e),n=this.editor.restoreSelection(),i=n.focusNode;if(i==this.editor.contentel)this.editor.contentel.insertBefore(t,this.editor.contentel.children[n.focusOffset]);else{var o=this.editor.createSelectionContext(i),r=o[o.length-1];if(this.editor.contentel.insertBefore(t,r.nextElementSibling),0==n.focusOffset);else{var s=n.getRangeAt(0);s.setStart(t.nextElementSibling||r.nextElementSibling||t,0),s.collapse(!0),n.removeAllRanges(),n.addRange(s)}}}},{key:"execute",value:function(e){switch(this.webName){case"text":this.executeText();break;case"exec":this.executeExec();break;case"block":this.executeBlock();break;case"remove":this.executeRemove();break;case"insert":this.executeInsert();break;default:this.editor.log("Warning : Tried to execute command with unknown webName ["+this.webName+"]")}return this.editor.takeSnapshot(),e.stopPropagation(),e.preventDefault(),!1}}]),s}(),LiliumTextCustomCommand=function(e){function s(e,t,n,i,o){_classCallCheck(this,s);var r=_possibleConstructorReturn(this,(s.__proto__||Object.getPrototypeOf(s)).call(this));return r.webName=e,r.callback=t,r.cssClass=n,r.imageURL=i,r.text=o,r}return _inherits(s,LiliumTextCommand),_createClass(s,[{key:"execute",value:function(){return this.callback.apply(this,arguments)&&this.editor.takeSnapshot(),!1}}]),s}(),LiliumTextHistoryEntry=function(){function i(e){_classCallCheck(this,i),this.type=e}return _createClass(i,[{key:"undo",value:function(){}}],[{key:"makeStaticClassesBecauseJavascriptIsStillWeird",value:function(){i.ChildListHistoryEntry=function(e){function n(e){_classCallCheck(this,n);var t=_possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,"ChildList"));return t.record=e,t.target=e.target,t.previousState=e.oldValue,t}return _inherits(n,i),n}(),i.TextHistoryEntry=function(e){function n(e){_classCallCheck(this,n);var t=_possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,"Text"));return t.record=e,t}return _inherits(n,i),n}(),i.AttributesHistoryEntry=function(e){function n(e){_classCallCheck(this,n);var t=_possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,"Attributes"));return t.record=e,t}return _inherits(n,i),n}(),i.AutomaticSnapshotEntry=function(e){function n(e){_classCallCheck(this,n);var t=_possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,"AutomaticSnapshot"));return t.markup=e,t}return _inherits(n,i),_createClass(n,[{key:"undo",value:function(e){if(e.content!=this.markup)return e.content=this.markup,!0}}]),n}(),i.ManualSnapshotEntry=function(e){function n(e){_classCallCheck(this,n);var t=_possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,"ManualSnapshot"));return t.markup=e,t}return _inherits(n,i),_createClass(n,[{key:"undo",value:function(e){if(e.content!=this.markup)return e.content=this.markup,!0}}]),n}()}},{key:"fromRecord",value:function(e){switch(e.type){case"childList":return new i.ChildListHistoryEntry(e);case"characterData":return new i.TextHistoryEntry(e);case"attributes":return new i.AttributesHistoryEntry(e)}}},{key:"fromSnapshot",value:function(e,t){return t?new i.ManualSnapshotEntry(e):new i.AutomaticSnapshotEntry(e)}}]),i}();LiliumTextHistoryEntry.makeStaticClassesBecauseJavascriptIsStillWeird();var LiliumTextPlugin=function(){function t(e){_classCallCheck(this,t),this.identifier=e,this.active=!1}return _createClass(t,[{key:"register",value:function(){}},{key:"unregister",value:function(){}}]),t}(),LiliumText=function(){function i(e){var t=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(_classCallCheck(this,i),this.initat=window.performance.now(),this.initialized=!1,this.destroyed=!1,this.codeview=!1,this.focused=!1,this._historylastState="",this.hooks={},this._plugins=[],this.wrapperel="string"==typeof e?document.querySelector(e)||document.getElementById(e):e,!this.wrapperel)throw new Error("LiliumText - Invalid element, DOM selector, or DOM element ID.");this.id=this.wrapperel.id||"liliumtext-"+btoa(Math.random().toString()).slice(0,-2),(i.instances[this.id]=this).settings=Object.assign(i.defaultSettings,n),this.commandsets=this.settings.commandsets||i.createDefaultCommands(this),this.log=this.settings.dev?i.makeLogFunction():function(){},this.log("Created LiliumText instance"),this.log("Firing document event"),document.dispatchEvent(new CustomEvent("liliumTextCreated",{detail:this})),this.wrapperel.classList.add("liliumtext"),this.wrapperel.classList.add("theme-"+this.settings.theme),Object.keys(this.settings.hooks).forEach(function(e){t.bind(e,t.settings.hooks[e])}),this._init(),this.settings.initrender&&this.render(),this.log("Ready in "+(window.performance.now()-this.initat)+"ms")}return _createClass(i,null,[{key:"createDefaultCommands",value:function(e){return[[new LiliumTextWebCommand("text",e.settings.boldnode||"strong","far fa-bold"),new LiliumTextWebCommand("text",e.settings.italicnode||"em","far fa-italic"),new LiliumTextWebCommand("text",e.settings.underlinenode||"u","far fa-underline"),new LiliumTextWebCommand("text",e.settings.strikenode||"strike","far fa-strikethrough"),new LiliumTextWebCommand("remove",void 0,"far fa-eraser")],[new LiliumTextCustomCommand("undo",e.undo.bind(e),"far fa-undo"),new LiliumTextCustomCommand("redo",e.redo.bind(e),"far fa-redo")],[new LiliumTextWebCommand("block",e.settings.breaktag||"p","far fa-paragraph"),new LiliumTextWebCommand("block","h1","far fa-h1"),new LiliumTextWebCommand("block","h2","far fa-h2"),new LiliumTextWebCommand("block","h3","far fa-h3"),new LiliumTextWebCommand("block","blockquote","far fa-quote-right")],[new LiliumTextWebCommand("insert","hr","far fa-minus")],[new LiliumTextWebCommand("exec","insertOrderedList","far fa-list-ol"),new LiliumTextWebCommand("exec","insertUnorderedList","far fa-list-ul"),new LiliumTextWebCommand("remove","a","far fa-unlink")],[new LiliumTextCustomCommand("code",e.toggleCode.bind(e),"far fa-code")]]}},{key:"makeLogFunction",value:function(){return function(e){return console.log("[LiliumText] "+e)}}},{key:"defaultSettings",get:function(){return{initrender:!0,removepastedstyles:!0,dev:!1,hooks:{},plugins:[],theme:"minim",width:"auto",boldnode:"strong",italicnode:"em",historyInterval:5e3,maxHistoryStack:100,underlinenode:"u",strikenode:"strike",height:"420px",breaktag:"p",blockelements:["p","h1","h2","h3","h4","h5","h6","blockquote","pre","ol","ul","article","dd","dl","dt","figure","header","hr","main","section","table","tfoot"],inlineelements:["a","b","big","code","em","i","img","small","span","strong","sub","sup","time","var"],content:"",urldetection:/^((https?):\/)\/?([^:\/\s]+)((\/\w+)*\/?)([\w\-\.])+/i}}}]),_createClass(i,[{key:"destroy",value:function(e){for(this.fire("destroy");this.wrapperel.firstElementChild;)this.wrapperel.firstElementChild.remove();for(var t in e?delete i.instances[this.id]:i.instances[this.id]=void 0,this)this[t]=void 0;this.destroyed=!0,document.dispatchEvent(new CustomEvent("liliumTextDestroyed",{detail:this}))}},{key:"lock",value:function(){this.contentel.removeAttribute("contenteditable")}},{key:"unlock",value:function(){this.contentel.contentEditable=!0}},{key:"createSelectionContext",value:function(e){for(var t=[];e!=this.contentel&&e;)t.push(e),e=e.parentNode;return t}},{key:"selectWord",value:function(e){var t=document.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset);var n=t.collapsed;t.detach();var i=e.focusNode,o=e.focusOffset;e.collapse(e.anchorNode,e.anchorOffset);var r=n?["backward","forward"]:["forward","backward"];e.modify("move",r[0],"character"),e.modify("move",r[1],"word"),e.extend(i,o),e.modify("extend",r[1],"character"),e.modify("extend",r[0],"word")}},{key:"selectParent",value:function(e,t){var n=document.createRange();n.selectNode(t||e.focusNode.parentNode),window.getSelection().removeAllRanges(),window.getSelection().addRange(n)}},{key:"unwrap",value:function(e){for(var t=e.parentNode;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},{key:"_pushToHistory",value:function(e){this.fire("history",e),this.log("Pushing new entry to history"),this._history.mutations.push(e)>this.settings.maxHistoryStack&&this._history.mutations.shift(),this._history.undoStack=[]}},{key:"_observe",value:function(e){var t=this;e.forEach(function(e){return t._pushToHistory(LiliumTextHistoryEntry.fromRecord(e))})}},{key:"_takeSnapshot",value:function(e){this.contentel.innerHTML!=this._historylastState&&(this._historylastState=this.contentel.innerHTML,this._pushToHistory(LiliumTextHistoryEntry.fromSnapshot(this._historylastState,e)))}},{key:"_startHistory",value:function(){var e=this;this.snapshotTimerID=setInterval(function(){e._takeSnapshot()},this.settings.historyInterval)}},{key:"resetSnapshot",value:function(){this.snapshotTimerID&&clearInterval(this.snapshotTimerID),this._startHistory()}},{key:"takeSnapshot",value:function(){this.resetSnapshot(),this._takeSnapshot(!0)}},{key:"isRangeInEditor",value:function(e){return e&&e.startContainer.compareDocumentPosition(this.contentel)&Node.DOCUMENT_POSITION_CONTAINS}},{key:"insert",value:function(e){var t=this.restoreSelection(),n=this.getRange();this.isRangeInEditor(n)||(this.contentel.focus(),n=this.storeRange()),n.insertNode(e),n.setStartAfter(e),t.removeAllRanges(),t.addRange(n)}},{key:"insertBlock",value:function(e){var t=this.restoreSelection(),n=this.createSelectionContext(t.focusNode),i=n[n.length-1];if(t.focusNode==this.contentel){this.contentel.insertBefore(e,this.contentel.children[t.focusOffset]);var o=t.getRangeAt(0).cloneRange();o.setEndAfter(e),o.collapse(!1),t.removeAllRanges(),t.addRange(o)}else{if(i&&i.nextSibling){var r=i;r&&r.parentNode.insertBefore(e,0==t.focusOffset?r:r.nextSibling)}else this.contentel.appendChild(e);if(0!=t.focusOffset){var s=t.getRangeAt(0).cloneRange();s.setEndAfter(e),s.collapse(!1),t.removeAllRanges(),t.addRange(s)}}}},{key:"_focused",value:function(){var e=this.fire("focus");this.focused=!0,e&&e.includes(!1)||(this._tempSelection=void 0,this._tempRange=void 0,document.execCommand("defaultParagraphSeparator",!1,this.settings.breaktag))}},{key:"_clicked",value:function(e){var t=window.getSelection();if(t.focusNode&&t.focusNode.parentElement){var n=this.createSelectionContext(t.focusNode),i=t.focusNode.parentElement;this.fire("clicked",{context:n,event:e,selection:t,element:i})}else this.fire("clicked",{selection:t,event:e});if(e.target==this.contentel&&this.contentel.offsetHeight-e.offsetY<60&&editor.contentel.scrollHeight-this.contentel.getBoundingClientRect().height-this.contentel.scrollTop<30){var o=document.createElement(this.settings.breaktag);o.appendChild(document.createElement("br")),this.contentel.appendChild(o);var r=document.createRange();r.selectNode(o),r.collapse(!0),t.removeAllRanges(),t.addRange(r),this.contentel.scrollTop=editor.contentel.scrollHeight-this.contentel.getBoundingClientRect().height}}},{key:"redo",value:function(){if(0!=this._history.undoStack.length){this.log("Restoring from undo stack");var e=this._history.undoStack.pop();this._history.mutations.push(e.mutation),this.content=e.markup,this.resetSnapshot(),this.fire("redo")}return!1}},{key:"undo",value:function(){if(0!=this._history.mutations.length){this.log("Going up one state in history");var e=this._history.mutations.pop(),t=this.content;if(!e.undo(this))return this.undo();this.log("Pushing to undo stack"),this._history.undoStack.push({markup:t,mutation:e}),this.resetSnapshot(),this.fire("undo")}else this.log("Restored original content"),this.content=this.settings.content;return!1}},{key:"storeRange",value:function(e){if(e)this._tempRange=e;else{var t=window.getSelection();if("None"!=t.type&&t.focusNode)this._tempRange=t.getRangeAt(0).cloneRange();else{var n=document.createRange();n.setStart(this.contentel,0),this._tempRange=n}}return this._tempRange}},{key:"restoreSelection",value:function(){var e=window.getSelection();return this.focused||(e.removeAllRanges(),e.addRange(this.getRange())),e}},{key:"getRange",value:function(){return this._tempRange||this.storeRange()}},{key:"_blurred",value:function(){this.focused=!1,this.storeRange(),this.fire("blur")}},{key:"_keydown",value:function(e){if((e.ctrlKey||e.metaKey)&&"z"==String.fromCharCode(e.which).toLowerCase())return e.preventDefault(),this.undo(),!1}},{key:"_pasted",value:function(e){var t=e.clipboardData||window.clipboardData,n=this.fire("paste",{dataTransfer:t,event:e});if(!n||!n.includes(!1))if(t.types.includes("text/html")){e.stopPropagation(),e.preventDefault();var i=t.getData("text/html"),o=document.createElement("div");o.innerHTML=i,this.settings.removepastedstyles&&(Array.prototype.forEach.call(o.querySelectorAll("*"),function(e){return e.removeAttribute("style")}),Array.prototype.forEach.call(o.querySelectorAll("style"),function(e){return e.remove()})),document.execCommand("insertHTML",!1,o.innerHTML)}else{var r=t.getData("text");this.settings.urldetection.exec(r)&&(e.stopPropagation(),e.preventDefault(),document.execCommand("createLink",!1,r))}}},{key:"_registerAllPlugins",value:function(){var t=this;this.settings.plugins&&this.settings.plugins.forEach(function(e){return t.registerPlugin(e)})}},{key:"registerPlugin",value:function(e){var t=new e(this);this.log("Registering plugin with id "+t.identifier),t.register(),this._plugins.push(t)}},{key:"unregisterPlugin",value:function(n){var i=-1,e=this._plugins.find(function(e,t){if(e.identifier==n)return i=t,e});e&&(e&&e.unregister(),this._plugins.splice(i,1))}},{key:"_init",value:function(){this.log("Initializing LiliumText instance"),this.toolbarel=document.createElement("div"),this.toolbarel.className="liliumtext-topbar",this.contentel=document.createElement("div"),this.contentel.contentEditable=!0,this.contentel.className="liliumtext-editor",this.codeel=document.createElement("pre"),this.codeel.contentEditable=!0,this.codeel.className="liliumtext-code",this.wrapperel.appendChild(this.toolbarel),this.wrapperel.appendChild(this.contentel),this.wrapperel.appendChild(this.codeel),this.settings.content&&this.settings.initrender?this.contentel.innerHTML=this.settings.content:this.contentel.appendChild(document.createElement(this.settings.breaktag)),this.contentel.addEventListener("paste",this.settings.onpaste||this._pasted.bind(this)),this.contentel.addEventListener("focus",this._focused.bind(this)),this.contentel.addEventListener("blur",this._blurred.bind(this)),this.contentel.addEventListener("click",this._clicked.bind(this)),this.contentel.addEventListener("keydown",this._keydown.bind(this)),this._history={mutations:[],undoStack:[]},this._startHistory(),this._registerAllPlugins(),this.fire("init"),this.log("Initialized LiliumText instance"),this.initialized=!0}},{key:"createCommandSet",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],t=arguments[1],n=!(2<arguments.length&&void 0!==arguments[2])||arguments[2];-1===t?this.commandsets=[e].concat(_toConsumableArray(this.commandsets)):t<this.commandsets.length?this.commandsets=[].concat(_toConsumableArray(this.commandsets.slice(0,t)),[e],_toConsumableArray(this.commandsets.slice(t))):this.commandsets.push(e),n&&this.render()}},{key:"addCommand",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.commandsets.length-1,n=!(2<arguments.length&&void 0!==arguments[2])||arguments[2],i=this.commandsets[t];i?i.push(e):this.commandsets.push([e]),n&&this.render()}},{key:"bind",value:function(e,t){this.hooks[e]?this.hooks[e].push(t):this.hooks[e]=[t]}},{key:"fire",value:function(e,t){var n=this;return this.hooks[e]&&this.hooks[e].map(function(e){return e(n,t)})}},{key:"toggleCode",value:function(){return this.log("Toggled code view"),this.codeview=!this.codeview,this.codeview?this.codeel.textContent=this.contentel.innerHTML:this.contentel.innerHTML=this.codeel.textContent,this.codeel.classList[this.codeview?"add":"remove"]("visible"),this.contentel.classList[this.codeview?"add":"remove"]("invisible"),this.fire("code",this.codeview),!0}},{key:"render",value:function(){var n=this;this.log("Rendering LiliumText instance"),this.fire("willrender"),this.log("Clearing toolbar"),this.toolbarel.firstElementChild&&this.toolbarel.firstElementChild.remove(),this.log("Rendering toolbar");var i=document.createElement("div");i.className="liliumtext-commands",this.commandsets.forEach(function(e){var t=document.createElement("div");t.className="liliumtext-commandset",i.appendChild(t),e.forEach(function(e){t.appendChild(e.make(n))})}),this.contentel.style.height=this.settings.height,this.codeel.style.height=this.settings.height,this.wrapperel.style.width=this.settings.width,this.toolbarel.appendChild(i),this.fire("render"),this.log("Done rendering")}},{key:"toString",value:function(){return this.content}},{key:"describe",value:function(){var n=this;return this.settings.dev?"[Development LiliumText Editor instance] Wraps DOM element with ID "+(this.wrapperel.id||"[No ID]")+". This instance currently has "+Object.keys(this.hooks).reduce(function(e,t){return e+n.hooks[t].length},0)+" event hooks.":"[LiliumText Editor]"}},{key:"content",set:function(e){var t={markup:e};this.fire("set",t),this.contentel.innerHTML=t.markup},get:function(){var e={markup:this.contentel.innerHTML};this.fire("get",e);return e.markup}}]),i}();LiliumText.instances={},"undefined"!=typeof module&&(module.exports={LiliumText:LiliumText,LiliumTextCustomCommand:LiliumTextCustomCommand,LiliumTextWebCommand:LiliumTextWebCommand,LiliumTextCommand:LiliumTextCommand,LiliumTextPlugin:LiliumTextPlugin});
"use strict";var _slicedToArray=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],i=!0,o=!1,r=void 0;try{for(var s,a=e[Symbol.iterator]();!(i=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);i=!0);}catch(e){o=!0,r=e}finally{try{!i&&a.return&&a.return()}finally{if(o)throw r}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},_createClass=function(){function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}}();function _toConsumableArray(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var LiliumTextCommand=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"execute",value:function(){throw new Error("execute() method was not overridden in child class.")}},{key:"make",value:function(t){var n=this;this.editor=t;var e=document.createElement("i");if(e.className="liliumtext-topbar-command liliumtext-topbar-command-"+this.webName+" "+(this.cssClass||"liliumtext-topbar-noicon"),e.dataset.command=this.webName,this.text){var i=document.createElement("span");i.className="liliumtext-command-text",i.textContent=this.text,e.classList.add("liliumtext-command-withtext"),e.appendChild(i)}return e.addEventListener("mousedown",function(e){return e.preventDefault(),e.stopPropagation(),!1}),e.addEventListener("mouseup",function(e){return e.preventDefault(),e.stopPropagation(),t.log("Executed command "+n.webName+(n.param?" with parameter '"+n.param+"'":"")),t.fire("command",n.webName),n.execute(e,n,t),!1}),e}}]),e}(),LiliumTextBrowserCompat=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"runCommandOrFallback",value:function(e,t,n){document.execCommand(e,!1,t)||n(e,t)}},{key:"nodeToCommand",value:function(e){switch(e){case"strong":case"b":return"bold";case"italic":case"i":case"em":return"italic";case"underline":case"u":return"underline";case"strike":case"s":return"strikeThrough";default:return}}},{key:"getStrategyKind",value:function(){return window.navigator?document.execCommand?"exec":"logic":"old"}}]),e}(),LiliumTextWebCommand=function(e){function s(e,t,n,i,o){_classCallCheck(this,s);var r=_possibleConstructorReturn(this,(s.__proto__||Object.getPrototypeOf(s)).call(this));return r.webName=e,r.param=t,r.cssClass=n,r.imageURL=i,r.text=o,r}return _inherits(s,LiliumTextCommand),_createClass(s,[{key:"highlightNode",value:function(e){var t=this.editor.restoreSelection(),n=document.createRange();this.editor.log("Highlighting node "+e.nodeName+" from Web Command"),n.selectNode(e),t.removeAllRanges(),t.addRange(n),this.editor.storeRange(n)}},{key:"executeText",value:function(){var S=this,T=this.editor.restoreSelection(),L=this.param,e=LiliumTextBrowserCompat.nodeToCommand(L);LiliumTextBrowserCompat.runCommandOrFallback(e,this.param,function(){if("Caret"==T.type){var e=S.editor.createSelectionContext(T.focusNode).find(function(e){return e.type==L});e&&(S.editor.log("Unwrapping element of node type "+L),S.editor.unwrap(e))}else if("Range"==T.type){var t=L.toUpperCase(),n=T.anchorNode.compareDocumentPosition(T.focusNode)&Node.DOCUMENT_POSITION_FOLLOWING?[T.anchorNode,T.focusNode]:[T.focusNode,T.anchorNode],i=_slicedToArray(n,2),o=i[0],r=i[1],s=[S.editor.createSelectionContext(o),S.editor.createSelectionContext(r)],a=s[1],l=[s[0].find(function(e){return e.nodeName==t}),a.find(function(e){return e.nodeName==t})],c=l[0],u=l[1];S.editor.log("Long logic with range using node type "+L);var h=T.getRangeAt(0).extractContents(),d=!c&&!u&&h.querySelectorAll(L);if(o.parentElement!==r.parentElement||c||d.length)if(!c!=!u){S.editor.log("XOR range wrapper extension of node type "+L);var m=document.createElement(L);m.appendChild(h),T.getRangeAt(0).insertNode(m);var f=c||u;Array.prototype.forEach.call(f.querySelectorAll(L),function(e){S.editor.unwrap(e)}),S.highlightNode(node)}else if(0!=d.length)S.editor.log("Fragment child unwrap with node type "+L),Array.prototype.forEach.call(d,function(e){for(;e.firstChild;)e.parentNode?e.parentNode.insertBefore(e.firstChild,e):h.insertBefore(e.firstChild,h)}),Array.prototype.forEach.call(d,function(e){return e&&e.remove&&e.remove()}),T.getRangeAt(0).insertNode(h);else if(c&&u&&c===u){S.editor.log("Placeholder unwrap from two sources with node types : "+L);var p=document.createElement("liliumtext-placeholder");T.getRangeAt(0).insertNode(p);var g=c,v=g.cloneNode(!0);g.parentNode.insertBefore(v,g);for(var y=v.querySelector("liliumtext-placeholder");y.nextSibling;)y.nextSibling.remove();for(;p.previousSibling;)p.previousSibling.remove();g.parentNode.insertBefore(h,g),p.remove(),y.remove(),S.highlightNode(v)}else if(c&&u){S.editor.log("Merge wrap from two sources with node types : "+L);for(var C=h.firstChild,k=h.lastChild;C.nextSibling!=k;)C.appendChild(C.nextSibling);for(;k.firstChild;)C.appendChild(k.firstChild);k.remove(),T.getRangeAt(0).insertNode(h)}else if(1==h.childNodes.length&&h.childNodes[0].nodeName==L){S.editor.log("Single unwrap of node type : "+L);for(var b=h.childNodes[0];b.lastChild;)T.getRangeAt(0).insertNode(b.lastChild)}else{S.editor.log("Fragment wrap with node type : "+L);var x=document.createElement(L);x.appendChild(h);var w=T.getRangeAt(0);w.insertNode(x),w.selectNode(x),T.removeAllRanges(),T.addRange(w)}else{S.editor.log("Quick range wrap with element of node type "+L);var _=document.createElement(L);_.appendChild(h),T.getRangeAt(0).insertNode(_),S.highlightNode(_)}}})}},{key:"executeExec",value:function(){this.editor.restoreSelection(),document.execCommand(this.param)}},{key:"executeBlock",value:function(){var i=this,o=this.editor.restoreSelection(),r=o.getRangeAt(0),s=this.param,e=s.toUpperCase();LiliumTextBrowserCompat.runCommandOrFallback("formatBlock",e,function(){var e=i.editor.createSelectionContext(o.focusNode),t=(i.editor.settings.blockelements,e&&e.length?e[e.length-1]:i.editor.contentel.children[o.focusOffset]);if(t.nodeName!=s){var n=document.createElement(s);if(t.parentElement.insertBefore(n,t),t.data)n.appendChild(t);else{for(;t.firstChild;)n.appendChild(t.firstChild);t.remove()}r.setStart(n,0),r.collapse(!0),o.removeAllRanges(),o.addRange(r)}})}},{key:"executeRemove",value:function(){if("a"==this.param)this.editor.restoreSelection(),document.execCommand("unlink",!1);else if(this.param){var e=this.editor.restoreSelection().focusNode.parentNode,t=this.editor.createSelectionContext(e),n=this.param.toUpperCase(),i=t.find(function(e){return e.nodeName==n});i&&(this.editor.log("Unwrapping node "+this.param),this.editor.unwrap(i))}else this.editor.log("Executing native command removeFormat"),this.editor.restoreSelection(),document.execCommand("removeFormat",!1,"")}},{key:"executeInsert",value:function(){var e=this.param,t=document.createElement(e),n=this.editor.restoreSelection(),i=n.focusNode;if(i==this.editor.contentel)this.editor.contentel.insertBefore(t,this.editor.contentel.children[n.focusOffset]);else{var o=this.editor.createSelectionContext(i),r=o[o.length-1];if(this.editor.contentel.insertBefore(t,r.nextElementSibling),0==n.focusOffset);else{var s=n.getRangeAt(0);s.setStart(t.nextElementSibling||r.nextElementSibling||t,0),s.collapse(!0),n.removeAllRanges(),n.addRange(s)}}}},{key:"execute",value:function(e){switch(this.webName){case"text":this.executeText();break;case"exec":this.executeExec();break;case"block":this.executeBlock();break;case"remove":this.executeRemove();break;case"insert":this.executeInsert();break;default:this.editor.log("Warning : Tried to execute command with unknown webName ["+this.webName+"]")}return this.editor.takeSnapshot(),e.stopPropagation(),e.preventDefault(),!1}}]),s}(),LiliumTextCustomCommand=function(e){function s(e,t,n,i,o){_classCallCheck(this,s);var r=_possibleConstructorReturn(this,(s.__proto__||Object.getPrototypeOf(s)).call(this));return r.webName=e,r.callback=t,r.cssClass=n,r.imageURL=i,r.text=o,r}return _inherits(s,LiliumTextCommand),_createClass(s,[{key:"execute",value:function(){return this.callback.apply(this,arguments)&&this.editor.takeSnapshot(),!1}}]),s}(),LiliumTextHistoryEntry=function(){function i(e){_classCallCheck(this,i),this.type=e}return _createClass(i,[{key:"undo",value:function(){}}],[{key:"makeStaticClassesBecauseJavascriptIsStillWeird",value:function(){i.ChildListHistoryEntry=function(e){function n(e){_classCallCheck(this,n);var t=_possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,"ChildList"));return t.record=e,t.target=e.target,t.previousState=e.oldValue,t}return _inherits(n,i),n}(),i.TextHistoryEntry=function(e){function n(e){_classCallCheck(this,n);var t=_possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,"Text"));return t.record=e,t}return _inherits(n,i),n}(),i.AttributesHistoryEntry=function(e){function n(e){_classCallCheck(this,n);var t=_possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,"Attributes"));return t.record=e,t}return _inherits(n,i),n}(),i.AutomaticSnapshotEntry=function(e){function n(e){_classCallCheck(this,n);var t=_possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,"AutomaticSnapshot"));return t.markup=e,t}return _inherits(n,i),_createClass(n,[{key:"undo",value:function(e){if(e.content!=this.markup)return e.content=this.markup,!0}}]),n}(),i.ManualSnapshotEntry=function(e){function n(e){_classCallCheck(this,n);var t=_possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,"ManualSnapshot"));return t.markup=e,t}return _inherits(n,i),_createClass(n,[{key:"undo",value:function(e){if(e.content!=this.markup)return e.content=this.markup,!0}}]),n}()}},{key:"fromRecord",value:function(e){switch(e.type){case"childList":return new i.ChildListHistoryEntry(e);case"characterData":return new i.TextHistoryEntry(e);case"attributes":return new i.AttributesHistoryEntry(e)}}},{key:"fromSnapshot",value:function(e,t){return t?new i.ManualSnapshotEntry(e):new i.AutomaticSnapshotEntry(e)}}]),i}();LiliumTextHistoryEntry.makeStaticClassesBecauseJavascriptIsStillWeird();var LiliumTextPlugin=function(){function t(e){_classCallCheck(this,t),this.identifier=e,this.active=!1}return _createClass(t,[{key:"register",value:function(){}},{key:"unregister",value:function(){}}]),t}(),LiliumText=function(){function i(e){var t=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(_classCallCheck(this,i),this.initat=window.performance.now(),this.initialized=!1,this.destroyed=!1,this.codeview=!1,this.focused=!1,this._historylastState="",this.hooks={},this._plugins=[],this.wrapperel="string"==typeof e?document.querySelector(e)||document.getElementById(e):e,!this.wrapperel)throw new Error("LiliumText - Invalid element, DOM selector, or DOM element ID.");this.id=this.wrapperel.id||"liliumtext-"+btoa(Math.random().toString()).slice(0,-2),(i.instances[this.id]=this).settings=Object.assign(i.defaultSettings,n),this.commandsets=this.settings.commandsets||i.createDefaultCommands(this),this.log=this.settings.dev?i.makeLogFunction():function(){},this.log("Created LiliumText instance"),this.log("Firing document event"),document.dispatchEvent(new CustomEvent("liliumTextCreated",{detail:this})),this.wrapperel.classList.add("liliumtext"),this.wrapperel.classList.add("theme-"+this.settings.theme),Object.keys(this.settings.hooks).forEach(function(e){t.bind(e,t.settings.hooks[e])}),this._init(),this.settings.initrender&&this.render(),this.log("Ready in "+(window.performance.now()-this.initat)+"ms")}return _createClass(i,null,[{key:"createDefaultCommands",value:function(e){return[[new LiliumTextWebCommand("text",e.settings.boldnode||"strong","far fa-bold"),new LiliumTextWebCommand("text",e.settings.italicnode||"em","far fa-italic"),new LiliumTextWebCommand("text",e.settings.underlinenode||"u","far fa-underline"),new LiliumTextWebCommand("text",e.settings.strikenode||"strike","far fa-strikethrough"),new LiliumTextWebCommand("remove",void 0,"far fa-eraser")],[new LiliumTextCustomCommand("undo",e.undo.bind(e),"far fa-undo"),new LiliumTextCustomCommand("redo",e.redo.bind(e),"far fa-redo")],[new LiliumTextWebCommand("block",e.settings.breaktag||"p","far fa-paragraph"),new LiliumTextWebCommand("block","h1","far fa-h1"),new LiliumTextWebCommand("block","h2","far fa-h2"),new LiliumTextWebCommand("block","h3","far fa-h3"),new LiliumTextWebCommand("block","blockquote","far fa-quote-right")],[new LiliumTextWebCommand("insert","hr","far fa-minus")],[new LiliumTextWebCommand("exec","insertOrderedList","far fa-list-ol"),new LiliumTextWebCommand("exec","insertUnorderedList","far fa-list-ul"),new LiliumTextWebCommand("remove","a","far fa-unlink")],[new LiliumTextCustomCommand("code",e.toggleCode.bind(e),"far fa-code")]]}},{key:"makeLogFunction",value:function(){return function(e){return console.log("[LiliumText] "+e)}}},{key:"defaultSettings",get:function(){return{initrender:!0,removepastedstyles:!0,dev:!1,hooks:{},plugins:[],theme:"minim",width:"auto",boldnode:"strong",italicnode:"em",historyInterval:5e3,maxHistoryStack:100,underlinenode:"u",strikenode:"strike",height:"420px",breaktag:"p",blockelements:["p","h1","h2","h3","h4","h5","h6","blockquote","pre","ol","ul","article","dd","dl","dt","figure","header","hr","main","section","table","tfoot"],inlineelements:["a","b","big","code","em","i","img","small","span","strong","sub","sup","time","var"],content:"",urldetection:/^((https?):\/)\/?([^:\/\s]+)((\/\w+)*\/?)([\w\-\.])+/i}}}]),_createClass(i,[{key:"destroy",value:function(e){for(this.fire("destroy");this.wrapperel.firstElementChild;)this.wrapperel.firstElementChild.remove();for(var t in e?delete i.instances[this.id]:i.instances[this.id]=void 0,this)this[t]=void 0;this.destroyed=!0,document.dispatchEvent(new CustomEvent("liliumTextDestroyed",{detail:this}))}},{key:"lock",value:function(){this.contentel.removeAttribute("contenteditable")}},{key:"unlock",value:function(){this.contentel.contentEditable=!0}},{key:"createSelectionContext",value:function(e){for(var t=[];e!=this.contentel&&e;)t.push(e),e=e.parentNode;return t}},{key:"selectWord",value:function(e){var t=document.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset);var n=t.collapsed;t.detach();var i=e.focusNode,o=e.focusOffset;e.collapse(e.anchorNode,e.anchorOffset);var r=n?["backward","forward"]:["forward","backward"];e.modify("move",r[0],"character"),e.modify("move",r[1],"word"),e.extend(i,o),e.modify("extend",r[1],"character"),e.modify("extend",r[0],"word")}},{key:"selectParent",value:function(e,t){var n=document.createRange();n.selectNode(t||e.focusNode.parentNode),window.getSelection().removeAllRanges(),window.getSelection().addRange(n)}},{key:"unwrap",value:function(e){for(var t=e.parentNode;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},{key:"_pushToHistory",value:function(e){this.fire("history",e),this.log("Pushing new entry to history"),this._history.mutations.push(e)>this.settings.maxHistoryStack&&this._history.mutations.shift(),this._history.undoStack=[]}},{key:"_observe",value:function(e){var t=this;e.forEach(function(e){return t._pushToHistory(LiliumTextHistoryEntry.fromRecord(e))})}},{key:"_takeSnapshot",value:function(e){this.contentel.innerHTML!=this._historylastState&&(this._historylastState=this.contentel.innerHTML,this._pushToHistory(LiliumTextHistoryEntry.fromSnapshot(this._historylastState,e)))}},{key:"_startHistory",value:function(){var e=this;this.snapshotTimerID=setInterval(function(){e._takeSnapshot()},this.settings.historyInterval)}},{key:"resetSnapshot",value:function(){this.snapshotTimerID&&clearInterval(this.snapshotTimerID),this._startHistory()}},{key:"takeSnapshot",value:function(){this.resetSnapshot(),this._takeSnapshot(!0)}},{key:"isRangeInEditor",value:function(e){return e&&e.startContainer.compareDocumentPosition(this.contentel)&Node.DOCUMENT_POSITION_CONTAINS}},{key:"insert",value:function(e){var t=this.restoreSelection(),n=this.getRange();this.isRangeInEditor(n)||(this.contentel.focus(),n=this.storeRange()),n.insertNode(e),n.setStartAfter(e),t.removeAllRanges(),t.addRange(n)}},{key:"insertBlock",value:function(e){var t=this.restoreSelection(),n=this.createSelectionContext(t.focusNode),i=n[n.length-1];if(t.focusNode==this.contentel){this.contentel.insertBefore(e,this.contentel.children[t.focusOffset]);var o=t.getRangeAt(0).cloneRange();o.setEndAfter(e),o.collapse(!1),t.removeAllRanges(),t.addRange(o)}else{if(i&&i.nextSibling){var r=i;r&&r.parentNode.insertBefore(e,0==t.focusOffset?r:r.nextSibling)}else this.contentel.appendChild(e);if(0!=t.focusOffset){var s=t.getRangeAt(0).cloneRange();s.setEndAfter(e),s.collapse(!1),t.removeAllRanges(),t.addRange(s)}}}},{key:"_focused",value:function(){var e=this.fire("focus");this.focused=!0,e&&e.includes(!1)||(this._tempSelection=void 0,this._tempRange=void 0,document.execCommand("defaultParagraphSeparator",!1,this.settings.breaktag))}},{key:"_clicked",value:function(e){var t=window.getSelection();if(t.focusNode&&t.focusNode.parentElement){var n=this.createSelectionContext(t.focusNode),i=t.focusNode.parentElement;this.fire("clicked",{context:n,event:e,selection:t,element:i})}else this.fire("clicked",{selection:t,event:e});if(e.target==this.contentel&&this.contentel.offsetHeight-e.offsetY<60&&editor.contentel.scrollHeight-this.contentel.getBoundingClientRect().height-this.contentel.scrollTop<30){var o=document.createElement(this.settings.breaktag);o.appendChild(document.createElement("br")),this.contentel.appendChild(o);var r=document.createRange();r.selectNode(o),r.collapse(!0),t.removeAllRanges(),t.addRange(r),this.contentel.scrollTop=editor.contentel.scrollHeight-this.contentel.getBoundingClientRect().height}}},{key:"redo",value:function(){if(0!=this._history.undoStack.length){this.log("Restoring from undo stack");var e=this._history.undoStack.pop();this._history.mutations.push(e.mutation),this.content=e.markup,this.resetSnapshot(),this.fire("redo")}return!1}},{key:"undo",value:function(){if(0!=this._history.mutations.length){this.log("Going up one state in history");var e=this._history.mutations.pop(),t=this.content;if(!e.undo(this))return this.undo();this.log("Pushing to undo stack"),this._history.undoStack.push({markup:t,mutation:e}),this.resetSnapshot(),this.fire("undo")}else this.log("Restored original content"),this.content=this.settings.content;return!1}},{key:"storeRange",value:function(e){if(e)this._tempRange=e;else{var t=window.getSelection();if("None"!=t.type&&t.focusNode)this._tempRange=t.getRangeAt(0).cloneRange();else{var n=document.createRange();n.setStart(this.contentel,0),this._tempRange=n}}return this._tempRange}},{key:"restoreSelection",value:function(){var e=window.getSelection();return this.focused||(e.removeAllRanges(),e.addRange(this.getRange())),e}},{key:"getRange",value:function(){return this._tempRange||this.storeRange()}},{key:"_blurred",value:function(){this.focused=!1,this.storeRange(),this.fire("blur")}},{key:"_keydown",value:function(e){if((e.ctrlKey||e.metaKey)&&"z"==String.fromCharCode(e.which).toLowerCase())return e.preventDefault(),this.undo(),!1}},{key:"_pasted",value:function(e){var t=e.clipboardData||window.clipboardData,n=this.fire("paste",{dataTransfer:t,event:e});if(!n||!n.includes(!1))if(t.types.includes("text/html")){e.stopPropagation(),e.preventDefault();var i=t.getData("text/html"),o=document.createElement("div");o.innerHTML=i,this.settings.removepastedstyles&&(Array.prototype.forEach.call(o.querySelectorAll("*"),function(e){return e.removeAttribute("style")}),Array.prototype.forEach.call(o.querySelectorAll("style"),function(e){return e.remove()})),document.execCommand("insertHTML",!1,o.innerHTML)}else{var r=t.getData("text");this.settings.urldetection.exec(r)&&(e.stopPropagation(),e.preventDefault(),document.execCommand("createLink",!1,r))}}},{key:"_registerAllPlugins",value:function(){var t=this;this.settings.plugins&&this.settings.plugins.forEach(function(e){return t.registerPlugin(e)})}},{key:"registerPlugin",value:function(e){var t=new e(this);this.log("Registering plugin with id "+t.identifier),t.register(),this._plugins.push(t)}},{key:"unregisterPlugin",value:function(n){var i=-1,e=this._plugins.find(function(e,t){if(e.identifier==n)return i=t,e});e&&(e&&e.unregister(),this._plugins.splice(i,1))}},{key:"_init",value:function(){this.log("Initializing LiliumText instance"),this.toolbarel=document.createElement("div"),this.toolbarel.className="liliumtext-topbar",this.contentel=document.createElement("div"),this.contentel.contentEditable=!0,this.contentel.className="liliumtext-editor",this.codeel=document.createElement("pre"),this.codeel.contentEditable=!0,this.codeel.className="liliumtext-code",this.wrapperel.appendChild(this.toolbarel),this.wrapperel.appendChild(this.contentel),this.wrapperel.appendChild(this.codeel),this.settings.content&&this.settings.initrender?this.contentel.innerHTML=this.settings.content:this.contentel.appendChild(document.createElement(this.settings.breaktag)),this.contentel.addEventListener("paste",this.settings.onpaste||this._pasted.bind(this)),this.contentel.addEventListener("focus",this._focused.bind(this)),this.contentel.addEventListener("blur",this._blurred.bind(this)),this.contentel.addEventListener("click",this._clicked.bind(this)),this.contentel.addEventListener("keydown",this._keydown.bind(this)),this._history={mutations:[],undoStack:[]},this._startHistory(),this._registerAllPlugins(),this.fire("init"),this.log("Initialized LiliumText instance"),this.initialized=!0}},{key:"createCommandSet",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],t=arguments[1],n=!(2<arguments.length&&void 0!==arguments[2])||arguments[2];-1===t?this.commandsets=[e].concat(_toConsumableArray(this.commandsets)):t<this.commandsets.length?this.commandsets=[].concat(_toConsumableArray(this.commandsets.slice(0,t)),[e],_toConsumableArray(this.commandsets.slice(t))):this.commandsets.push(e),n&&this.render()}},{key:"addCommand",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.commandsets.length-1,n=!(2<arguments.length&&void 0!==arguments[2])||arguments[2],i=this.commandsets[t];i?i.push(e):this.commandsets.push([e]),n&&this.render()}},{key:"bind",value:function(e,t){this.hooks[e]?this.hooks[e].push(t):this.hooks[e]=[t]}},{key:"fire",value:function(e,t){var n=this;return this.hooks[e]&&this.hooks[e].map(function(e){return e(n,t)})}},{key:"toggleCode",value:function(){return this.log("Toggled code view"),this.codeview=!this.codeview,this.codeview?this.codeel.textContent=this.contentel.innerHTML:this.contentel.innerHTML=this.codeel.textContent,this.codeel.classList[this.codeview?"add":"remove"]("visible"),this.contentel.classList[this.codeview?"add":"remove"]("invisible"),this.fire("code",this.codeview),!0}},{key:"render",value:function(){var n=this;this.log("Rendering LiliumText instance"),this.fire("willrender"),this.log("Clearing toolbar"),this.toolbarel.firstElementChild&&this.toolbarel.firstElementChild.remove(),this.log("Rendering toolbar");var i=document.createElement("div");i.className="liliumtext-commands",this.commandsets.forEach(function(e){var t=document.createElement("div");t.className="liliumtext-commandset",i.appendChild(t),e.forEach(function(e){t.appendChild(e.make(n))})}),this.contentel.style.height=this.settings.height,this.codeel.style.height=this.settings.height,this.wrapperel.style.width=this.settings.width,this.toolbarel.appendChild(i),this.fire("render"),this.log("Done rendering")}},{key:"toString",value:function(){return this.content}},{key:"describe",value:function(){var n=this;return this.settings.dev?"[Development LiliumText Editor instance] Wraps DOM element with ID "+(this.wrapperel.id||"[No ID]")+". This instance currently has "+Object.keys(this.hooks).reduce(function(e,t){return e+n.hooks[t].length},0)+" event hooks.":"[LiliumText Editor]"}},{key:"content",set:function(e){var t={markup:e};this.fire("set",t),this.contentel.innerHTML=t.markup},get:function(){var e={markup:this.contentel.innerHTML};this.fire("get",e);return e.markup}}]),i}();LiliumText.instances={},"undefined"!=typeof module&&(module.exports={LiliumText:LiliumText,LiliumTextCustomCommand:LiliumTextCustomCommand,LiliumTextWebCommand:LiliumTextWebCommand,LiliumTextCommand:LiliumTextCommand,LiliumTextPlugin:LiliumTextPlugin});

@@ -51,2 +51,3 @@ class LiliumTextCommand {

case "italic":
case "i":
case "em":

@@ -53,0 +54,0 @@ return "italic";

{
"name": "lilium-text",
"version": "1.3.1",
"version": "1.3.2",
"description": "Web rich text editor. Ready to be used in a test environment.",

@@ -5,0 +5,0 @@ "main": "build/liliumtext.min.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc