mirror of
https://github.com/tenrok/vue-tribute.git
synced 2026-06-21 16:20:36 +03:00
3 lines
26 KiB
JavaScript
3 lines
26 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueTribute=t()}(this,function(){"use strict";function e(){throw new Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}var t,n,i=(function(t,n){t.exports=function t(n,i,r){function o(a,l){if(!i[a]){if(!n[a]){var s=e;if(!l&&s)return s(a,!0);if(u)return u(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var d=i[a]={exports:{}};n[a][0].call(d.exports,function(e){var t=n[a][1][e];return o(t||e)},d,d.exports,t,n,i,r)}return i[a].exports}for(var u=e,a=0;a<r.length;a++)o(r[a]);return o}({1:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(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(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),r=e("./utils"),o=(h(r),e("./TributeEvents")),u=h(o),a=e("./TributeMenuEvents"),l=h(a),s=e("./TributeRange"),c=h(s),d=e("./TributeSearch"),f=h(d);function h(e){return e&&e.__esModule?e:{default:e}}var v=function(){function e(t){var n,i=this,r=t.values,o=void 0===r?null:r,a=t.iframe,s=void 0===a?null:a,d=t.selectClass,h=void 0===d?"highlight":d,v=t.trigger,p=void 0===v?"@":v,g=t.selectTemplate,m=void 0===g?null:g,b=t.menuItemTemplate,y=void 0===b?null:b,w=t.lookup,T=void 0===w?"key":w,E=t.fillAttr,k=void 0===E?"value":E,x=t.collection,C=void 0===x?null:x,S=t.menuContainer,A=void 0===S?null:S,M=t.noMatchTemplate,N=void 0===M?null:M,I=t.requireLeadingSpace,P=void 0===I||I,L=t.allowSpaces,O=void 0!==L&&L,D=t.replaceTextSuffix,R=void 0===D?null:D,_=t.positionMenu,j=void 0===_||_;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.menuSelected=0,this.current={},this.inputEvent=!1,this.isActive=!1,this.menuContainer=A,this.allowSpaces=O,this.replaceTextSuffix=R,this.positionMenu=j,o)this.collection=[{trigger:p,iframe:s,selectClass:h,selectTemplate:(m||e.defaultSelectTemplate).bind(this),menuItemTemplate:(y||e.defaultMenuItemTemplate).bind(this),noMatchTemplate:(n=N,"function"==typeof n?n.bind(i):function(){return'<li class="no-match">No match!</li>'}.bind(i)),lookup:T,fillAttr:k,values:o,requireLeadingSpace:P}];else{if(!C)throw new Error("[Tribute] No collection specified.");this.collection=C.map(function(t){return{trigger:t.trigger||p,iframe:t.iframe||s,selectClass:t.selectClass||h,selectTemplate:(t.selectTemplate||e.defaultSelectTemplate).bind(i),menuItemTemplate:(t.menuItemTemplate||e.defaultMenuItemTemplate).bind(i),noMatchTemplate:(n=N,"function"==typeof n?n.bind(i):null),lookup:t.lookup||T,fillAttr:t.fillAttr||k,values:t.values,requireLeadingSpace:t.requireLeadingSpace};var n})}new c.default(this),new u.default(this),new l.default(this),new f.default(this)}return i(e,[{key:"triggers",value:function(){return this.collection.map(function(e){return e.trigger})}},{key:"attach",value:function(e){if(!e)throw new Error("[Tribute] Must pass in a DOM node or NodeList.");if("undefined"!=typeof jQuery&&e instanceof jQuery&&(e=e.get()),e.constructor===NodeList||e.constructor===HTMLCollection||e.constructor===Array)for(var t=e.length,n=0;n<t;++n)this._attach(e[n]);else this._attach(e)}},{key:"_attach",value:function(e){e.hasAttribute("data-tribute")&&console.warn("Tribute was already bound to "+e.nodeName),this.ensureEditable(e),this.events.bind(e),e.setAttribute("data-tribute",!0)}},{key:"ensureEditable",value:function(t){if(-1===e.inputTypes().indexOf(t.nodeName)){if(!t.contentEditable)throw new Error("[Tribute] Cannot bind to "+t.nodeName);t.contentEditable=!0}}},{key:"createMenu",value:function(){var e=this.range.getDocument().createElement("div"),t=this.range.getDocument().createElement("ul");return e.className="tribute-container",e.appendChild(t),this.menuContainer?this.menuContainer.appendChild(e):this.range.getDocument().body.appendChild(e)}},{key:"showMenuFor",value:function(e,t){var n=this;if(!this.isActive||this.current.element!==e||this.current.mentionText!==this.currentMentionTextSnapshot){this.currentMentionTextSnapshot=this.current.mentionText,this.menu||(this.menu=this.createMenu(),this.menuEvents.bind(this.menu)),this.isActive=!0,this.menuSelected=0,this.current.mentionText||(this.current.mentionText="");var i=function(e){if(n.isActive){var i=n.search.filter(n.current.mentionText,e,{pre:"<span>",post:"</span>",extract:function(e){if("string"==typeof n.current.collection.lookup)return e[n.current.collection.lookup];if("function"==typeof n.current.collection.lookup)return n.current.collection.lookup(e);throw new Error("Invalid lookup attribute, lookup must be string or function.")}});n.current.filteredItems=i;var r=n.menu.querySelector("ul");if(n.range.positionMenuAtCaret(t),!i.length){var o=new CustomEvent("tribute-no-match",{detail:n.menu});return n.current.element.dispatchEvent(o),void(n.current.collection.noMatchTemplate?r.innerHTML=n.current.collection.noMatchTemplate():n.hideMenu())}r.innerHTML="",i.forEach(function(e,t){var i=n.range.getDocument().createElement("li");i.setAttribute("data-index",t),i.addEventListener("mouseenter",function(e){var t=e.target,i=t.getAttribute("data-index");n.events.setActiveLi(i)}),n.menuSelected===t&&(i.className=n.current.collection.selectClass),i.innerHTML=n.current.collection.menuItemTemplate(e),r.appendChild(i)})}};"function"==typeof this.current.collection.values?this.current.collection.values(this.current.mentionText,i):i(this.current.collection.values)}}},{key:"showMenuForCollection",value:function(e,t){e!==document.activeElement&&this.placeCaretAtEnd(e),this.current.collection=this.collection[t||0],this.current.externalTrigger=!0,this.current.element=e,e.isContentEditable?this.insertTextAtCursor(this.current.collection.trigger):this.insertAtCaret(e,this.current.collection.trigger),this.showMenuFor(e)}},{key:"placeCaretAtEnd",value:function(e){if(e.focus(),void 0!==window.getSelection&&void 0!==document.createRange){var t=document.createRange();t.selectNodeContents(e),t.collapse(!1);var n=window.getSelection();n.removeAllRanges(),n.addRange(t)}else if(void 0!==document.body.createTextRange){var i=document.body.createTextRange();i.moveToElementText(e),i.collapse(!1),i.select()}}},{key:"insertTextAtCursor",value:function(e){var t,n;t=window.getSelection(),(n=t.getRangeAt(0)).deleteContents();var i=document.createTextNode(e);n.insertNode(i),n.selectNodeContents(i),n.collapse(!1),t.removeAllRanges(),t.addRange(n)}},{key:"insertAtCaret",value:function(e,t){var n=e.scrollTop,i=e.selectionStart,r=e.value.substring(0,i),o=e.value.substring(e.selectionEnd,e.value.length);e.value=r+t+o,i+=t.length,e.selectionStart=i,e.selectionEnd=i,e.focus(),e.scrollTop=n}},{key:"hideMenu",value:function(){this.menu&&(this.menu.style.cssText="display: none;",this.isActive=!1,this.menuSelected=0,this.current={})}},{key:"selectItemAtIndex",value:function(e,t){if("number"==typeof(e=parseInt(e))){var n=this.current.filteredItems[e],i=this.current.collection.selectTemplate(n);null!==i&&this.replaceText(i,t,n)}}},{key:"replaceText",value:function(e,t,n){this.range.replaceTriggerText(e,!0,!0,t,n)}},{key:"_append",value:function(e,t,n){if("function"==typeof e.values)throw new Error("Unable to append to values, as it is a function.");e.values=n?t:e.values.concat(t)}},{key:"append",value:function(e,t,n){var i=parseInt(e);if("number"!=typeof i)throw new Error("please provide an index for the collection to update.");var r=this.collection[i];this._append(r,t,n)}},{key:"appendCurrent",value:function(e,t){if(!this.isActive)throw new Error("No active state. Please use append instead and pass an index.");this._append(this.current.collection,e,t)}}],[{key:"defaultSelectTemplate",value:function(e){return void 0===e?null:this.range.isContentEditable(this.current.element)?'<span class="tribute-mention">'+(this.current.collection.trigger+e.original[this.current.collection.fillAttr])+"</span>":this.current.collection.trigger+e.original[this.current.collection.fillAttr]}},{key:"defaultMenuItemTemplate",value:function(e){return e.string}},{key:"inputTypes",value:function(){return["TEXTAREA","INPUT"]}}]),e}();n.default=v,t.exports=n.default},{"./TributeEvents":2,"./TributeMenuEvents":3,"./TributeRange":4,"./TributeSearch":5,"./utils":7}],2:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(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(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),r=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.tribute=t,this.tribute.events=this}return i(e,[{key:"bind",value:function(e){e.addEventListener("keydown",this.keydown.bind(e,this),!1),e.addEventListener("keyup",this.keyup.bind(e,this),!1),e.addEventListener("input",this.input.bind(e,this),!1)}},{key:"keydown",value:function(t,n){t.shouldDeactivate(n)&&(t.tribute.isActive=!1,t.tribute.hideMenu());var i=this;t.commandEvent=!1,e.keys().forEach(function(e){e.key===n.keyCode&&(t.commandEvent=!0,t.callbacks()[e.value.toLowerCase()](n,i))})}},{key:"input",value:function(e,t){e.inputEvent=!0,e.keyup.call(this,e,t)}},{key:"click",value:function(e,t){var n=e.tribute;if(n.menu&&n.menu.contains(t.target)){var i=t.target;for(t.preventDefault(),t.stopPropagation();"li"!==i.nodeName.toLowerCase();)if(!(i=i.parentNode)||i===n.menu)throw new Error("cannot find the <li> container for the click");n.selectItemAtIndex(i.getAttribute("data-index"),t),n.hideMenu()}else n.current.element&&!n.current.externalTrigger&&(n.current.externalTrigger=!1,setTimeout(function(){return n.hideMenu()}))}},{key:"keyup",value:function(e,t){if(e.inputEvent&&(e.inputEvent=!1),e.updateSelection(this),27!==t.keyCode){if(!e.tribute.isActive){var n=e.getKeyCode(e,this,t);if(isNaN(n)||!n)return;var i=e.tribute.triggers().find(function(e){return e.charCodeAt(0)===n});void 0!==i&&e.callbacks().triggerChar(t,this,i)}(e.tribute.current.trigger&&!1===e.commandEvent||e.tribute.isActive&&8===t.keyCode)&&e.tribute.showMenuFor(this,!0)}}},{key:"shouldDeactivate",value:function(t){if(!this.tribute.isActive)return!1;if(0===this.tribute.current.mentionText.length){var n=!1;return e.keys().forEach(function(e){t.keyCode===e.key&&(n=!0)}),!n}return!1}},{key:"getKeyCode",value:function(e,t,n){var i=e.tribute,r=i.range.getTriggerInfo(!1,!1,!0,i.allowSpaces);return!!r&&r.mentionTriggerChar.charCodeAt(0)}},{key:"updateSelection",value:function(e){this.tribute.current.element=e;var t=this.tribute.range.getTriggerInfo(!1,!1,!0,this.tribute.allowSpaces);t&&(this.tribute.current.selectedPath=t.mentionSelectedPath,this.tribute.current.mentionText=t.mentionText,this.tribute.current.selectedOffset=t.mentionSelectedOffset)}},{key:"callbacks",value:function(){var e=this;return{triggerChar:function(t,n,i){var r=e.tribute;r.current.trigger=i;var o=r.collection.find(function(e){return e.trigger===i});r.current.collection=o,r.inputEvent&&r.showMenuFor(n,!0)},enter:function(t,n){e.tribute.isActive&&(t.preventDefault(),t.stopPropagation(),setTimeout(function(){e.tribute.selectItemAtIndex(e.tribute.menuSelected,t),e.tribute.hideMenu()},0))},escape:function(t,n){e.tribute.isActive&&(t.preventDefault(),t.stopPropagation(),e.tribute.isActive=!1,e.tribute.hideMenu())},tab:function(t,n){e.callbacks().enter(t,n)},up:function(t,n){if(e.tribute.isActive){t.preventDefault(),t.stopPropagation();var i=e.tribute.current.filteredItems.length,r=e.tribute.menuSelected;i>r&&r>0?(e.tribute.menuSelected--,e.setActiveLi()):0===r&&(e.tribute.menuSelected=i-1,e.setActiveLi(),e.tribute.menu.scrollTop=e.tribute.menu.scrollHeight)}},down:function(t,n){if(e.tribute.isActive){t.preventDefault(),t.stopPropagation();var i=e.tribute.current.filteredItems.length-1,r=e.tribute.menuSelected;i>r?(e.tribute.menuSelected++,e.setActiveLi()):i===r&&(e.tribute.menuSelected=0,e.setActiveLi(),e.tribute.menu.scrollTop=0)}},delete:function(t,n){e.tribute.isActive&&e.tribute.current.mentionText.length<1?e.tribute.hideMenu():e.tribute.isActive&&e.tribute.showMenuFor(n)}}}},{key:"setActiveLi",value:function(e){var t=this.tribute.menu.querySelectorAll("li"),n=t.length>>>0,i=this.getFullHeight(this.tribute.menu),r=this.getFullHeight(t[0]);e&&(this.tribute.menuSelected=e);for(var o=0;o<n;o++){var u=t[o];if(o===this.tribute.menuSelected){var a=r*(o+1),l=this.tribute.menu.scrollTop,s=l+i;a>s?this.tribute.menu.scrollTop+=r:a<s&&(this.tribute.menu.scrollTop-=r),u.className=this.tribute.current.collection.selectClass}else u.className=""}}},{key:"getFullHeight",value:function(e,t){var n=e.getBoundingClientRect().height;if(t){var i=e.currentStyle||window.getComputedStyle(e);return n+parseFloat(i.marginTop)+parseFloat(i.marginBottom)}return n}}],[{key:"keys",value:function(){return[{key:9,value:"TAB"},{key:8,value:"DELETE"},{key:13,value:"ENTER"},{key:27,value:"ESCAPE"},{key:38,value:"UP"},{key:40,value:"DOWN"}]}}]),e}();n.default=r,t.exports=n.default},{}],3:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(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(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),r=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.tribute=t,this.tribute.menuEvents=this,this.menu=this.tribute.menu}return i(e,[{key:"bind",value:function(e){var t=this;e.addEventListener("keydown",this.tribute.events.keydown.bind(this.menu,this),!1),this.tribute.range.getDocument().addEventListener("mousedown",this.tribute.events.click.bind(null,this),!1),this.tribute.range.getDocument().addEventListener("MSPointerDown",this.tribute.events.click.bind(null,this),!1),window.addEventListener("resize",this.debounce(function(){t.tribute.isActive&&t.tribute.range.positionMenuAtCaret(!0)},300,!1)),this.menuContainer?this.menuContainer.addEventListener("scroll",this.debounce(function(){t.tribute.isActive&&t.tribute.showMenuFor(t.tribute.current.element,!1)},300,!1),!1):window.onscroll=this.debounce(function(){t.tribute.isActive&&t.tribute.showMenuFor(t.tribute.current.element,!1)},300,!1)}},{key:"debounce",value:function(e,t,n){var i,r=this,o=arguments;return function(){var u=r,a=o,l=n&&!i;clearTimeout(i),i=setTimeout(function(){i=null,n||e.apply(u,a)},t),l&&e.apply(u,a)}}}]),e}();n.default=r,t.exports=n.default},{}],4:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(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(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),r=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.tribute=t,this.tribute.range=this}return i(e,[{key:"getDocument",value:function(){var e=void 0;return this.tribute.current.collection&&(e=this.tribute.current.collection.iframe),e?e.contentWindow.document:document}},{key:"positionMenuAtCaret",value:function(e){var t=this.tribute.current,n=void 0,i=this.getTriggerInfo(!1,!1,!0,this.tribute.allowSpaces);if(void 0!==i){if(!this.tribute.positionMenu)return void(this.tribute.menu.style.cssText="display: block;");n=this.isContentEditable(t.element)?this.getContentEditableCaretPosition(i.mentionPosition):this.getTextAreaOrInputUnderlinePosition(this.getDocument().activeElement,i.mentionPosition),this.tribute.menu.style.cssText="top: "+n.top+"px;\n left: "+n.left+"px;\n position: absolute;\n zIndex: 10000;\n display: block;",e&&this.scrollIntoView()}else this.tribute.menu.style.cssText="display: none"}},{key:"selectElement",value:function(e,t,n){var i=void 0,r=e;if(t)for(var o=0;o<t.length;o++){if(void 0===(r=r.childNodes[t[o]]))return;for(;r.length<n;)n-=r.length,r=r.nextSibling;0!==r.childNodes.length||r.length||(r=r.previousSibling)}var u=this.getWindowSelection();(i=this.getDocument().createRange()).setStart(r,n),i.setEnd(r,n),i.collapse(!0);try{u.removeAllRanges()}catch(e){}u.addRange(i),e.focus()}},{key:"resetSelection",value:function(e,t,n){this.isContentEditable(e)?this.selectElement(e,t,n):e!==this.getDocument().activeElement&&e.focus()}},{key:"replaceTriggerText",value:function(e,t,n,i,r){var o=this.tribute.current,u=this.getTriggerInfo(!0,n,t,this.tribute.allowSpaces),a=new CustomEvent("tribute-replaced",{detail:{item:r,event:i}});if(void 0!==u){if(this.isContentEditable(o.element)){var l="string"==typeof this.tribute.replaceTextSuffix?this.tribute.replaceTextSuffix:" ";e+=l,this.pasteHtml(e,u.mentionPosition,u.mentionPosition+u.mentionText.length+1)}else{var s=this.getDocument().activeElement,c="string"==typeof this.tribute.replaceTextSuffix?this.tribute.replaceTextSuffix:" ";e+=c;var d=u.mentionPosition,f=u.mentionPosition+u.mentionText.length+c.length;s.value=s.value.substring(0,d)+e+s.value.substring(f,s.value.length),s.selectionStart=d+e.length,s.selectionEnd=d+e.length}o.element.dispatchEvent(a)}}},{key:"pasteHtml",value:function(e,t,n){var i=void 0,r=void 0;r=this.getWindowSelection(),(i=this.getDocument().createRange()).setStart(r.anchorNode,t),i.setEnd(r.anchorNode,n),i.deleteContents();var o=this.getDocument().createElement("div");o.innerHTML=e;for(var u=this.getDocument().createDocumentFragment(),a=void 0,l=void 0;a=o.firstChild;)l=u.appendChild(a);i.insertNode(u),l&&((i=i.cloneRange()).setStartAfter(l),i.collapse(!0),r.removeAllRanges(),r.addRange(i))}},{key:"getWindowSelection",value:function(){return this.tribute.collection.iframe?this.tribute.collection.iframe.contentWindow.getSelection():window.getSelection()}},{key:"getNodePositionInParent",value:function(e){if(null===e.parentNode)return 0;for(var t=0;t<e.parentNode.childNodes.length;t++){var n=e.parentNode.childNodes[t];if(n===e)return t}}},{key:"getContentEditableSelectedPath",value:function(e){var t=this.getWindowSelection(),n=t.anchorNode,i=[],r=void 0;if(null!=n){for(var o=void 0,u=n.contentEditable;null!==n&&"true"!==u;)o=this.getNodePositionInParent(n),i.push(o),null!==(n=n.parentNode)&&(u=n.contentEditable);return i.reverse(),r=t.getRangeAt(0).startOffset,{selected:n,path:i,offset:r}}}},{key:"getTextPrecedingCurrentSelection",value:function(){var e=this.tribute.current,t="";if(this.isContentEditable(e.element)){var n=this.getWindowSelection().anchorNode;if(null!=n){var i=n.textContent,r=this.getWindowSelection().getRangeAt(0).startOffset;i&&r>=0&&(t=i.substring(0,r))}}else{var o=this.tribute.current.element;if(o){var u=o.selectionStart;o.value&&u>=0&&(t=o.value.substring(0,u))}}return t}},{key:"getTriggerInfo",value:function(e,t,n,i){var r=this,o=this.tribute.current,u=void 0,a=void 0,l=void 0;if(this.isContentEditable(o.element)){var s=this.getContentEditableSelectedPath(o);s&&(u=s.selected,a=s.path,l=s.offset)}else u=this.getDocument().activeElement;var c=this.getTextPrecedingCurrentSelection();if(void 0!==c&&null!==c){var d=-1,f=void 0;if(this.tribute.collection.forEach(function(e){var t=e.trigger,i=e.requireLeadingSpace?r.lastIndexWithLeadingSpace(c,t):c.lastIndexOf(t);i>d&&(d=i,f=t,n=e.requireLeadingSpace)}),d>=0&&(0===d||!n||/[\xA0\s]/g.test(c.substring(d-1,d)))){var h=c.substring(d+1,c.length);f=c.substring(d,d+1);var v=h.substring(0,1),p=h.length>0&&(" "===v||" "===v);t&&(h=h.trim());var g=i?/[^\S ]/g:/[\xA0\s]/g;if(!p&&(e||!g.test(h)))return{mentionPosition:d,mentionText:h,mentionSelectedElement:u,mentionSelectedPath:a,mentionSelectedOffset:l,mentionTriggerChar:f}}}}},{key:"lastIndexWithLeadingSpace",value:function(e,t){for(var n=e.split("").reverse().join(""),i=-1,r=0,o=e.length;r<o;r++){var u=r===e.length-1,a=/\s/.test(n[r+1]),l=t===n[r];if(l&&(u||a)){i=e.length-1-r;break}}return i}},{key:"isContentEditable",value:function(e){return"INPUT"!==e.nodeName&&"TEXTAREA"!==e.nodeName}},{key:"getTextAreaOrInputUnderlinePosition",value:function(e,t){var n=null!==window.mozInnerScreenX,i=this.getDocument().createElement("div");i.id="input-textarea-caret-position-mirror-div",this.getDocument().body.appendChild(i);var r=i.style,o=window.getComputedStyle?getComputedStyle(e):e.currentStyle;r.whiteSpace="pre-wrap","INPUT"!==e.nodeName&&(r.wordWrap="break-word"),r.position="absolute",r.visibility="hidden",["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing"].forEach(function(e){r[e]=o[e]}),n?(r.width=parseInt(o.width)-2+"px",e.scrollHeight>parseInt(o.height)&&(r.overflowY="scroll")):r.overflow="hidden",i.textContent=e.value.substring(0,t),"INPUT"===e.nodeName&&(i.textContent=i.textContent.replace(/\s/g," "));var u=this.getDocument().createElement("span");u.textContent=e.value.substring(t)||".",i.appendChild(u);var a=e.getBoundingClientRect(),l=document.documentElement,s=(window.pageXOffset||l.scrollLeft)-(l.clientLeft||0),c=(window.pageYOffset||l.scrollTop)-(l.clientTop||0),d={top:a.top+c+u.offsetTop+parseInt(o.borderTopWidth)+parseInt(o.fontSize)-e.scrollTop,left:a.left+s+u.offsetLeft+parseInt(o.borderLeftWidth)};return this.getDocument().body.removeChild(i),d}},{key:"getContentEditableCaretPosition",value:function(e){var t=void 0,n="sel_"+(new Date).getTime()+"_"+Math.random().toString().substr(2),i=void 0,r=this.getWindowSelection(),o=r.getRangeAt(0);(i=this.getDocument().createRange()).setStart(r.anchorNode,e),i.setEnd(r.anchorNode,e),i.collapse(!1),(t=this.getDocument().createElement("span")).id=n,t.appendChild(this.getDocument().createTextNode("\ufeff")),i.insertNode(t),r.removeAllRanges(),r.addRange(o);var u=t.getBoundingClientRect(),a=document.documentElement,l=(window.pageXOffset||a.scrollLeft)-(a.clientLeft||0),s=(window.pageYOffset||a.scrollTop)-(a.clientTop||0),c={left:u.left+l,top:u.top+t.offsetHeight+s};return t.parentNode.removeChild(t),c}},{key:"scrollIntoView",value:function(e){var t=void 0,n=this.menu;if(void 0!==n){for(;void 0===t||0===t.height;)if(0===(t=n.getBoundingClientRect()).height&&(void 0===(n=n.childNodes[0])||!n.getBoundingClientRect))return;var i=t.top,r=i+t.height;if(i<0)window.scrollTo(0,window.pageYOffset+t.top-20);else if(r>window.innerHeight){var o=window.pageYOffset+t.top-20;o-window.pageYOffset>100&&(o=window.pageYOffset+100);var u=window.pageYOffset-(window.innerHeight-r);u>o&&(u=o),window.scrollTo(0,u)}}}}]),e}();n.default=r,t.exports=n.default},{}],5:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(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(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),r=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.tribute=t,this.tribute.search=this}return i(e,[{key:"simpleFilter",value:function(e,t){var n=this;return t.filter(function(t){return n.test(e,t)})}},{key:"test",value:function(e,t){return null!==this.match(e,t)}},{key:"match",value:function(e,t,n){n=n||{},t.length;var i=n.pre||"",r=n.post||"",o=n.caseSensitive&&t||t.toLowerCase();e=n.caseSensitive&&e||e.toLowerCase();var u=this.traverse(o,e,0,0,[]);return u?{rendered:this.render(t,u.cache,i,r),score:u.score}:null}},{key:"traverse",value:function(e,t,n,i,r){if(t.length===i)return{score:this.calculateScore(r),cache:r.slice()};if(!(e.length===n||t.length-i>e.length-n)){for(var o=t[i],u=e.indexOf(o,n),a=void 0,l=void 0;u>-1;){if(r.push(u),l=this.traverse(e,t,u+1,i+1,r),r.pop(),!l)return a;(!a||a.score<l.score)&&(a=l),u=e.indexOf(o,u+1)}return a}}},{key:"calculateScore",value:function(e){var t=0,n=1;return e.forEach(function(i,r){r>0&&(e[r-1]+1===i?n+=n+1:n=1),t+=n}),t}},{key:"render",value:function(e,t,n,i){var r=e.substring(0,t[0]);return t.forEach(function(o,u){r+=n+e[o]+i+e.substring(o+1,t[u+1]?t[u+1]:e.length)}),r}},{key:"filter",value:function(e,t,n){var i=this;return n=n||{},t.reduce(function(t,r,o,u){var a=r;n.extract&&((a=n.extract(r))||(a=""));var l=i.match(e,a,n);return null!=l&&(t[t.length]={string:l.rendered,score:l.score,index:o,original:r}),t},[]).sort(function(e,t){var n=t.score-e.score;return n||e.index-t.index})}}]),e}();n.default=r,t.exports=n.default},{}],6:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var i,r=e("./Tribute"),o=(i=r)&&i.__esModule?i:{default:i};n.default=o.default,t.exports=n.default},{"./Tribute":1}],7:[function(e,t,n){if(Array.prototype.find||(Array.prototype.find=function(e){if(null===this)throw new TypeError("Array.prototype.find called on null or undefined");if("function"!=typeof e)throw new TypeError("predicate must be a function");for(var t,n=Object(this),i=n.length>>>0,r=arguments[1],o=0;o<i;o++)if(t=n[o],e.call(r,t,o,n))return t}),window&&"function"!=typeof window.CustomEvent){var i=function(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n};void 0!==window.Event&&(i.prototype=window.Event.prototype),window.CustomEvent=i}},{}]},{},[6])(6)}(t={exports:{}},t.exports),t.exports),r=(n=i)&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n,o={name:"vue-tribute",props:{options:{type:Object,required:!0}},data:function(){return{tribute:null}},mounted:function(){var e=this,t=this.$slots.default[0].elm;this.tribute=new r(this.options),this.tribute.attach(t),t.addEventListener("tribute-replaced",function(t){e.$emit("tribute-replaced",t)}),t.addEventListener("tribute-no-match",function(t){e.$emit("tribute-no-match",t)})},render:function(e){return e("div",{staticClass:"v-tribute"},this.$slots.default)}};return"undefined"!=typeof window&&window.Vue&&window.Vue.component(o.name,o),o});
|
||
//# sourceMappingURL=vue-tribute.min.js.map
|