module.exports=function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=4)}([function(t,e){t.exports=flarum.core.compat["helpers/icon"]},function(t,e){t.exports=flarum.core.compat.extend},function(t,e){t.exports=flarum.core.compat["components/TextEditor"]},function(t,e,n){var i,r,o;"undefined"!=typeof self&&self,r=[],void 0===(o="function"==typeof(i=function(){var t=/mac|iphone|ipad|ipod/i.test(navigator.platform)?"metaKey":"ctrlKey",e=/^["'`*_[({<>})\]]$/,n=/[*_]/,i=/^[ \t]*(?:(?:[-+*]|\d+\.)[ \t]+(?:\[[ x]][ \t]+)?|>[ \t]*)*(?::[ \t]*)?/,r=/(?:[-+*]|\d+\.)[ \t]+(?:\[[ x]][ \t]+)?$/,o=/[-+*\[\]x\d.]/g,l=/[^ \t]/g,s=/(\d+)\.(?=[ \t]+$)/,a=/(?:(?:^[ \t]+)?(?:[-+*]|\d+\.|[>:])(?:[ \t]+\[[ x]])?[ \t]*|^[ \t]+)$/,c=/^(?!$)/gm,u={"`":/^``$/m,"~":/^~~$/m},d={"[":"]","(":")","{":"}","<":">"},f={"]":"[",")":"(","}":"{",">":"<"};function h(t){this._useTab=!0,this._useInline=!0,this._indent=" ",this._reOutdent=/^[ ]{4}/gm,this._reKey=p(!0,!0),this._handleKey=this._handleKey.bind(this),this.setElement(t)}function p(t,e){return new RegExp("^(?:Enter"+(t?"|Tab":"")+"|[io"+(e?"\"'`*_([{<>}\\])":"")+"])$")}function m(t,e,n,i){if(t.value=e,t.selectionStart=n,t.selectionEnd=arguments.length>3?i:n,"InputEvent"in window)try{var r=new InputEvent("input");t.dispatchEvent(r)}catch(i){}}return h.prototype={constructor:h,getElement:function(){return this._elem},setElement:function(t){this._elem&&this._elem.removeEventListener("keydown",this._handleKey),this._elem=t,t.addEventListener("keydown",this._handleKey)},getValue:function(){return this._elem.value},setValue:function(t){this._elem.value=t},getIndent:function(){return this._indent},setIndent:function(t){this._indent="number"==typeof t?new Array(t+1).join(" "):(t+"").replace(/[^ \t]/g," "),this._reOutdent=new RegExp("^"+this._indent,"mg")},isTabUsed:function(){return this._useTab},useTab:function(){this._useTab=!0,this._reKey=p(!0,this._useInline)},ignoreTab:function(){this._useTab=!1,this._reKey=p(!1,this._useInline)},isInlineEnabled:function(){return this._useInline},enableInline:function(){this._useInline=!0,this._reKey=p(this._useTab,!0)},disableInline:function(){this._useInline=!1,this._reKey=p(this._useTab,!1)},destroy:function(){this._elem.removeEventListener("keydown",this._handleKey),this._elem=this._reKey=this._handleKey=this._indent=this._reOutdent=null},_handleKey:function(h){if(!h.defaultPrevented&&this._reKey.test(h.key)){var p=h.target.value.substring(0,h.target.selectionStart),v=h.target.value.substring(h.target.selectionStart,h.target.selectionEnd),g=h.target.value.substring(h.target.selectionEnd);if("Enter"!==h.key||h.ctrlKey||h.altKey||h.metaKey)if("Tab"===h.key&&!h.shiftKey||"i"===h.key&&h[t])!function(t,e,n,i,r){var o=e.length,l=e.lastIndexOf("\n")+1;l ",multiline:!0,surroundWithNewlines:!0}),t}return p(e,_),e}();window.customElements.get("md-quote")||(window.MarkdownQuoteButtonElement=E,window.customElements.define("md-quote",E));var x=function(t){function e(){f(this,e);var t=h(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return g.set(t,{prefix:"`",suffix:"`",blockPrefix:"```",blockSuffix:"```"}),t}return p(e,_),e}();window.customElements.get("md-code")||(window.MarkdownCodeButtonElement=x,window.customElements.define("md-code",x));var k=function(t){function e(){f(this,e);var t=h(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return g.set(t,{prefix:"[",suffix:"](url)",replaceNext:"url",scanFor:"https?://"}),t}return p(e,_),d(e,[{key:"connectedCallback",value:function(){u(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"connectedCallback",this).call(this),this.setAttribute("hotkey","k")}}]),e}();window.customElements.get("md-link")||(window.MarkdownLinkButtonElement=k,window.customElements.define("md-link",k));var O=function(t){function e(){f(this,e);var t=h(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return g.set(t,{prefix:"- ",multiline:!0,surroundWithNewlines:!0}),t}return p(e,_),e}();window.customElements.get("md-unordered-list")||(window.MarkdownUnorderedListButtonElement=O,window.customElements.define("md-unordered-list",O));var S=function(t){function e(){f(this,e);var t=h(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return g.set(t,{prefix:"1. ",multiline:!0,orderedList:!0}),t}return p(e,_),e}();window.customElements.get("md-ordered-list")||(window.MarkdownOrderedListButtonElement=S,window.customElements.define("md-ordered-list",S));var j=function(t){function e(){f(this,e);var t=h(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return g.set(t,{prefix:"- [ ] ",multiline:!0,surroundWithNewlines:!0}),t}return p(e,_),d(e,[{key:"connectedCallback",value:function(){u(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"connectedCallback",this).call(this),this.setAttribute("hotkey","L")}}]),e}();window.customElements.get("md-task-list")||(window.MarkdownTaskListButtonElement=j,window.customElements.define("md-task-list",j));var P=function(t){function e(){f(this,e);var t=h(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return g.set(t,{prefix:"@",prefixSpace:!0}),t}return p(e,_),e}();window.customElements.get("md-mention")||(window.MarkdownMentionButtonElement=P,window.customElements.define("md-mention",P));var T=function(t){function e(){f(this,e);var t=h(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return g.set(t,{prefix:"#",prefixSpace:!0}),t}return p(e,_),e}();window.customElements.get("md-ref")||(window.MarkdownRefButtonElement=T,window.customElements.define("md-ref",T));var M=navigator.userAgent.match(/Macintosh/)?"Meta":"Control",I=function(t){function e(){return f(this,e),h(this,(e.__proto__||Object.getPrototypeOf(e)).call(this))}return p(e,v),d(e,[{key:"connectedCallback",value:function(){var t=function(t,e){if(e.metaKey&&"Meta"===M||e.ctrlKey&&"Control"===M){var n=t.querySelector('[hotkey="'+e.key+'"]');n&&(n.click(),e.preventDefault())}}.bind(null,this);this.field&&(this.field.addEventListener("keydown",t),K.set(this,t))}},{key:"disconnectedCallback",value:function(){var t=K.get(this);t&&this.field&&(this.field.removeEventListener("keydown",t),K.delete(this))}},{key:"field",get:function(){var t=this.getAttribute("for");if(t){var e=document.getElementById(t);return e instanceof HTMLTextAreaElement?e:null}}}]),e}(),K=new WeakMap;function A(t){return t.trim().split("\n").length>1}function C(t,e){return Array(e+1).join(t)}window.customElements.get("markdown-toolbar")||(window.MarkdownToolbarElement=I,window.customElements.define("markdown-toolbar",I));var L=null;function B(t,e){var n=t.value.slice(t.selectionStart,t.selectionEnd),i=void 0;i=e.orderedList?function(t){var e=/^\d+\.\s+/,n=void 0,i=void 0,r=t.value.slice(t.selectionStart,t.selectionEnd),o=r.split("\n");if(o.every(function(t){return e.test(t)}))o=o.map(function(t){return t.replace(e,"")}),r=o.join("\n");else{o=function(){var t=void 0,e=void 0,n=void 0,i=[];for(n=t=0,e=o.length;t0?l+"\n":r,v=A(p)&&s.length>0?"\n"+s:o;if(c){var g=t.value[t.selectionStart-1];0===t.selectionStart||null==g||g.match(/\s/)||(m=" "+m)}p=function(t,e,n){if(t.selectionStart===t.selectionEnd)t.selectionStart=function(t,e){for(;t[e]&&null!=t[e-1]&&!t[e-1].match(/\s/);)e--;return e}(t.value,t.selectionStart),t.selectionEnd=function(t,e){for(;t[e]&&!t[e].match(/\s/);)e++;return e}(t.value,t.selectionEnd);else{var i=t.selectionStart-e.length,r=t.selectionEnd+n.length,o=t.value.slice(i,t.selectionStart)===e,l=t.value.slice(t.selectionEnd,r)===n;o&&l&&(t.selectionStart=i,t.selectionEnd=r)}return t.value.slice(t.selectionStart,t.selectionEnd)}(t,m,v);var _=t.selectionStart,y=t.selectionEnd,b=a.length>0&&v.indexOf(a)>-1&&p.length>0;if(d){var w=W(t);n=w.newlinesToAppend,i=w.newlinesToPrepend,m=n+r,v+=i}if(p.startsWith(m)&&p.endsWith(v)){var E=p.slice(m.length,p.length-v.length);if(f===h){var x=f-m.length;x=Math.max(x,_),x=Math.min(x,_+E.length),_=y=x}else y=_+E.length;return{text:E,selectionStart:_,selectionEnd:y}}if(b){if(u.length>0&&p.match(u)){v=v.replace(a,p);var k=m+v;return _=y=_+m.length,{text:k,selectionStart:_,selectionEnd:y}}var O=m+p+v;return _=_+m.length+p.length+v.indexOf(a),y=_+a.length,{text:O,selectionStart:_,selectionEnd:y}}var S=m+p+v;_=f+m.length,y=h+m.length;var j=p.match(/^\s*|\s*$/g);if(e.trimFirst&&j){var P=j[0]||"",T=j[1]||"";S=P+m+p.trim()+v+T,_+=P.length,y-=T.length}return{text:S,selectionStart:_,selectionEnd:y}}(t,e),function(t,e){var n=e.text,i=e.selectionStart,r=e.selectionEnd,o=t.selectionStart,l=t.value.slice(0,o),s=t.value.slice(t.selectionEnd);if(null===L||!0===L){t.contentEditable="true";try{L=document.execCommand("insertText",!1,n)}catch(t){L=!1}t.contentEditable="false"}if(L&&!t.value.slice(0,t.selectionStart).endsWith(n)&&(L=!1),!L){try{document.execCommand("ms-beginUndoUnit")}catch(t){}t.value=l+n+s;try{document.execCommand("ms-endUndoUnit")}catch(t){}t.dispatchEvent(new CustomEvent("input",{bubbles:!0,cancelable:!0}))}null!=i&&null!=r?t.setSelectionRange(i,r):t.setSelectionRange(o,t.selectionEnd)}(t,i)}function W(t){var e=t.value.slice(0,t.selectionStart),n=t.value.slice(t.selectionEnd),i=e.match(/\n*$/),r=n.match(/^\n*/),o=i?i[0].length:0,l=r?r[0].length:0,s=void 0,a=void 0;return e.match(/\S/)&&o<2&&(s=C("\n",2-o)),n.match(/\S/)&&l<2&&(a=C("\n",2-l)),null==s&&(s=""),null==a&&(a=""),{newlinesToAppend:s,newlinesToPrepend:a}}function N(t,e){var n=t.closest("markdown-toolbar");if(n instanceof I){var i=c({},{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,trimFirst:!1},e),r=n.field;r&&(r.focus(),B(r,i))}}var F=n(3),R=n.n(F);app.initializers.add("flarum-markdown",function(t){var e=1;Object(r.extend)(l.a.prototype,"init",function(){this.textareaId="textarea"+e++}),Object(r.extend)(l.a.prototype,"view",function(t){t.children[0].attrs.id=this.textareaId}),Object(r.extend)(l.a.prototype,"configTextarea",function(t,e,n,i){if(!n){var r=new R.a(e);r.disableInline(),i.onunload=function(){r.destroy()}}}),Object(r.extend)(l.a.prototype,"toolbarItems",function(e){var n={className:"Button Button--icon Button--link",config:function(t){return $(t).tooltip()}},r=function(e){return t.translator.trans("flarum-markdown.forum.composer."+e+"_tooltip")};e.add("markdown",m("markdown-toolbar",{for:this.textareaId},m("md-header",i({title:r("header")},n),a()("fas fa-heading")),m("md-bold",i({title:r("bold")+" "},n),a()("fas fa-bold")),m("md-italic",i({title:r("italic")+" "},n),a()("fas fa-italic")),m("md-quote",i({title:r("quote")},n),a()("fas fa-quote-left")),m("md-code",i({title:r("code")},n),a()("fas fa-code")),m("md-link",i({title:r("link")+" "},n),a()("fas fa-link")),m("md-unordered-list",i({title:r("unordered_list")},n),a()("fas fa-list-ul")),m("md-ordered-list",i({title:r("ordered_list")},n),a()("fas fa-list-ol"))),100)})})}]); //# sourceMappingURL=forum.js.map