module.exports=function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=6)}([function(e,t){e.exports=flarum.core.compat.extend},function(e,t){e.exports=flarum.core.compat["components/TextEditor"]},function(e,t){e.exports=flarum.core.compat.Component},function(e,t,n){var i,r,l;"undefined"!=typeof self&&self,r=[],void 0===(l="function"==typeof(i=function(){var e=/mac|iphone|ipad|ipod/i.test(navigator.platform)?"metaKey":"ctrlKey",t=/^["'`*_[({<>})\]]$/,n=/[*_]/,i=/^[ \t]*(?:(?:[-+*]|\d+\.)[ \t]+(?:\[[ x]][ \t]+)?|>[ \t]*)*(?::[ \t]*)?/,r=/(?:[-+*]|\d+\.)[ \t]+(?:\[[ x]][ \t]+)?$/,l=/[-+*\[\]x\d.]/g,o=/[^ \t]/g,s=/(\d+)\.(?=[ \t]+$)/,a=/(?:(?:^[ \t]+)?(?:[-+*]|\d+\.|[>:])(?:[ \t]+\[[ x]])?[ \t]*|^[ \t]+)$/,c=/^(?!$)/gm,u={"`":/^``$/m,"~":/^~~$/m},f={"[":"]","(":")","{":"}","<":">"},h={"]":"[",")":"(","}":"{",">":"<"};function d(e){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(e)}function p(e,t){return new RegExp("^(?:Enter"+(e?"|Tab":"")+"|[io"+(t?"\"'`*_([{<>}\\])":"")+"])$")}function g(e,t,n,i){if(e.value=t,e.selectionStart=n,e.selectionEnd=3this.length)&&(t=this.length),this.substring(t-e.length,t)===e})},function(e,t,n){"use strict";n.r(t);var i=n(0),r=n(1),l=n.n(r),o=n(3),s=n.n(o);n(5);function a(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var c=n(2),u=n.n(c),f=navigator.userAgent.match(/Macintosh/)?"Meta":"Control",h=function(e){function t(){return e.apply(this,arguments)||this}a(t,e);var n=t.prototype;return n.config=function(e){e||document.getElementById(this.props.for).addEventListener("keydown",this.shortcut.bind(this))},n.view=function(){return m("div",{id:"MarkdownToolbar","data-for":this.props.for,style:{display:"inline-block"}},this.props.children)},n.shortcut=function(e){if(e.metaKey&&"Meta"===f||e.ctrlKey&&"Control"===f){var t=this.element.querySelector('[data-hotkey="'+e.key+'"]');t&&(t.click(),e.preventDefault())}},t}(u.a),d=n(4),p=n.n(d);function g(){return(g=Object.assign||function(e){for(var t=1;t1}function x(e,t){return Array(t+1).join(e)}function b(e,t,n){for(var i=t,r=n?/\n/:/\s/;e[i]&&!e[i].match(r);)i++;return i}function _(e){var t,n,i=e.value.slice(0,e.selectionStart),r=e.value.slice(e.selectionEnd),l=i.match(/\n*$/),o=r.match(/^\n*/),s=l?l[0].length:0,a=o?o[0].length:0;return i.match(/\S/)&&s<2&&(t=x("\n",2-s)),r.match(/\S/)&&a<2&&(n=x("\n",2-a)),null==t&&(t=""),null==n&&(n=""),{newlinesToAppend:t,newlinesToPrepend:n}}var E=function(e,t){var n=t.prefix,i=t.suffix,r=t.blockPrefix,l=t.blockSuffix,o=t.replaceNext,s=t.prefixSpace,a=t.scanFor,c=t.surroundWithNewlines,u=e.selectionStart,f=e.selectionEnd,h=e.value.slice(e.selectionStart,e.selectionEnd),d=y(h)&&r.length>0?r+"\n":n,p=y(h)&&l.length>0?"\n"+l:i;if(s){var g=e.value[e.selectionStart-1];0===e.selectionStart||null==g||g.match(/\s/)||(d=" "+d)}h=function(e,t,n){var i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(e.selectionStart===e.selectionEnd)e.selectionStart=function(e,t){for(var n=t;e[n]&&null!=e[n-1]&&!e[n-1].match(/\s/);)n--;return n}(e.value,e.selectionStart),e.selectionEnd=b(e.value,e.selectionEnd,i);else{var r=e.selectionStart-t.length,l=e.selectionEnd+n.length,o=e.value.slice(r,e.selectionStart)===t,s=e.value.slice(e.selectionEnd,l)===n;o&&s&&(e.selectionStart=r,e.selectionEnd=l)}return e.value.slice(e.selectionStart,e.selectionEnd)}(e,d,p,t.multiline);var m=e.selectionStart,v=e.selectionEnd,x=o.length>0&&p.indexOf(o)>-1&&h.length>0;if(c){var E=_(e);d=E.newlinesToAppend+n,p+=E.newlinesToPrepend}if(h.startsWith(d)&&h.endsWith(p)){var S=h.slice(d.length,h.length-p.length);if(u===f){var k=u-d.length;k=Math.max(k,m),m=v=k=Math.min(k,m+S.length)}else v=m+S.length;return{text:S,selectionStart:m,selectionEnd:v}}if(x)return a.length>0&&h.match(a)?{text:d+(p=p.replace(o,h)),selectionStart:m=v=m+d.length,selectionEnd:v}:{text:d+h+p,selectionStart:m=m+d.length+h.length+p.indexOf(o),selectionEnd:v=m+o.length};var w=d+h+p;m=u+d.length,v=f+d.length;var T=h.match(/^\s*|\s*$/g);if(t.trimFirst&&T){var O=T[0]||"",I=T[1]||"";w=O+d+h.trim()+p+I,m+=O.length,v-=I.length}return{text:w,selectionStart:m,selectionEnd:v}},S=function(e,t){var n,i=e.value.slice(e.selectionStart,e.selectionEnd);n=t.orderedList?function(e){var t,n,i,r,l=/^\d+\.\s+/,o=e.selectionStart===e.selectionEnd,s=e.value.slice(e.selectionStart,e.selectionEnd),a=s,c=s.split("\n");if(o){var u=e.value.slice(0,e.selectionStart).split(/\n/);i=e.selectionStart-u[u.length-1].length,r=b(e.value,e.selectionStart,!0),a=e.value.slice(i,r)}var f=a.split("\n");if(f.every(function(e){return l.test(e)})){if(s=(c=f.map(function(e){return e.replace(l,"")})).join("\n"),o&&i&&r){var h=f[0].length-c[0].length;n=t=e.selectionStart-h,e.selectionStart=i,e.selectionEnd=r}}else{s=(c=function(){var e,t,n,i=[];for(n=e=0,t=c.length;e"),e},t}(u.a);app.initializers.add("flarum-markdown",function(e){var t=1;Object(i.extend)(l.a.prototype,"init",function(){this.textareaId="textarea"+t++}),Object(i.extend)(l.a.prototype,"view",function(e){e.children[0].attrs.id=this.textareaId}),Object(i.extend)(l.a.prototype,"configTextarea",function(e,t,n,i){if(!n){var r=new s.a(t);r.disableInline(),r.ignoreTab(),i.onunload=function(){r.destroy()}}}),Object(i.extend)(l.a.prototype,"toolbarItems",function(t){var n=function(t){return e.translator.trans("flarum-markdown.forum.composer."+t+"_tooltip")};t.add("markdown",m(h,{for:this.textareaId},m(w,{title:n("header"),icon:"fas fa-heading",style:{prefix:"### "}}),m(w,{title:n("bold"),icon:"fas fa-bold",style:{prefix:"**",suffix:"**",trimFirst:!0},hotkey:"b"}),m(w,{title:n("italic"),icon:"fas fa-italic",style:{prefix:"_",suffix:"_",trimFirst:!0},hotkey:"i"}),m(w,{title:n("quote"),icon:"fas fa-quote-left",style:{prefix:"> ",multiline:!0,surroundWithNewlines:!0}}),m(w,{title:n("code"),icon:"fas fa-code",style:{prefix:"`",suffix:"`",blockPrefix:"```",blockSuffix:"```"}}),m(w,{title:n("link"),icon:"fas fa-link",style:{prefix:"[",suffix:"](url)",replaceNext:"url",scanFor:"https?://"}}),m(w,{title:n("image"),icon:"fas fa-image",style:{prefix:"![",suffix:"](src)",replaceNext:"src",scanFor:"https?://"}}),m(w,{title:n("unordered_list"),icon:"fas fa-list-ul",style:{prefix:"- ",multiline:!0,surroundWithNewlines:!0}}),m(w,{title:n("ordered_list"),icon:"fas fa-list-ol",style:{prefix:"1. ",multiline:!0,orderedList:!0}})),100)})})}]); //# sourceMappingURL=forum.js.map