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.Component},function(e,t){e.exports=flarum.core.compat["components/TextEditor"]},function(e,t){e.exports=flarum.core.compat["utils/BasicEditorDriver"]},function(e,t,n){e.exports=function(){"use strict";const e=/^[ \t]*(?:(?:[-+*]|\d+\.)[ \t]+(?:\[[ x]][ \t]+)?|>[ \t]*)*(?::[ \t]*)?/,t=/(?:[-+*]|\d+\.)[ \t]+(?:\[[ x]][ \t]+)?$/,n=/[-+*\[\]x\d.]/g,i=/[^ \t]/g,r=/(\d+)\.(?=[ \t]+$)/,o=/(?:(?:^[ \t]+)?(?:[-+*]|\d+\.|[>:])(?:[ \t]+\[[ x]])?[ \t]*|^[ \t]+)$/,l=/[*_]/,s=/[-=\s"'`<>\[\](){}+*^$\\.|]$/,c=/^(?:\n|$)/,a=/^(?!$)/gm,u={"`":/^``$/m,"~":/^~~$/m},d={"[":"]","(":")","{":"}","<":">"},f={"]":"[",")":"(","}":"{",">":"<"},h={enter:(n,i,l,s,a)=>{const u=l?null:function(t){const n=t.lastIndexOf("\n")+1,i=t.substring(n),r=e.exec(i);return{line:i,offset:n,prefix:r&&r[0]}}(i);if(u)if(u.line&&u.line.charAt(u.line.length-1)in d){const e=u.prefix?y(u.prefix,!0):"";s="\n"+e+s,a.shiftKey||(i+="\n"+e+n.indent)}else u.prefix?!a.shiftKey&&u.prefix===u.line&&c.test(s)?i=i.substring(0,u.offset)+function(e){return e.replace(o,"")}(u.prefix):!a.shiftKey&&function(e){return t.test(e)}(u.prefix)?i+="\n"+function(e){return e.replace(r,(function(e,t){return parseInt(t)+1+"."}))}(u.prefix):i+="\n"+y(u.prefix,a.shiftKey):i+="\n";else i+="\n";return{v:i+s,s:i.length}},indent:(e,t,n,i)=>{let r=t.length,o=t.lastIndexOf("\n")+1;return o{let r=t.length,o=t.lastIndexOf("\n")+1;return on||r.key in d||i.charAt(0)!==r.key?n||("'"!==r.key||s.test(t))&&!(r.key in f)?!n&&r.key in u&&u[r.key].test(t)?{v:t+r.key+"language\n"+r.key+r.key+r.key+("\n"!==i.charAt(0)?"\n":"")+i,s:t.length+1,e:t.length+9}:r.key===t.slice(-1)&&r.key===i.slice(0,1)?{v:t.slice(0,-1)+n+i.slice(1),s:t.length-1,e:t.length-1+n.length}:{v:t+(f[r.key]||r.key)+n+(d[r.key]||r.key)+i,s:t.length+1,e:t.length+1+n.length}:{v:t+r.key+i,s:t.length+1}:{v:t+(l.test(r.key)?r.key+r.key:"")+i,s:t.length+1}};class p{constructor(e){this.options=e}handleKey(e,t,n,i){const r=this.options.keyMap.find(e=>function(e,t){for(const n in t)if(t.hasOwnProperty(n)&&e[n]!==t[n])return!1;return!0}(i,e.key));if(r&&h[r.action])return h[r.action](this.options,e,t,n,i)}}function y(e,t){return e.replace(t?i:n," ")}const m=/mac|iphone|ipad|ipod/i.test(navigator.platform),v=/firefox/i.test(navigator.userAgent),x=m?"metaKey":"ctrlKey",g={enter:["Enter","Shift+Enter"],indent:["Tab","Cmd+m"],outdent:["Shift+Tab","Cmd+Shift+m"],inline:['"',"'","`","*","_","[","]","(",")","{","}","<",">"]};function k(e={}){const t={},n=[];for(let i in g)if(g.hasOwnProperty(i)){let r=e[i]||g[i];Array.isArray(r)||(r=r.toString().trim().split(/\s*[|,]\s*/g)),n.push.apply(n,r.map(e=>{const n=b(e);return n.key in t||(t[n.key]=0),++t[n.key],{key:n,action:i}}))}return n.forEach(e=>{var n;t[e.key.key]>1&&("ctrlKey"in(n=e.key)||(n.ctrlKey=!1),"altKey"in n||(n.altKey=!1),"shiftKey"in n||(n.shiftKey=!1),"metaKey"in n||(n.metaKey=!1))}),n}function b(e){const t={};return e.trim().split(/\s*\+\s*/g).forEach((function(e){switch(e.toLowerCase()){case"cmd":t[x]=!0;break;case"ctrl":case"alt":case"shift":case"meta":t[e.toLowerCase()+"Key"]=!0;break;default:t.key=e}})),t}function E(){const e=document.createElement("div");return e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e.contentEditable=!0,e.textContent="0",e.addEventListener("focus",()=>setTimeout(()=>e.blur(),0)),e.style.position="fixed",e.style.overflow="hidden",e.style.left="-1000px",e.style.top="50%",e.style.width=e.style.height="1px",e.style.opacity="0",e}function S(e,t=!1){return{s:e.selectionStart,e:e.selectionEnd,x:e.scrollLeft,y:e.scrollTop,v:e.value.replace(/\u00A0/g," "),c:t}}function w(e,t){e.lock=!0;const n=void 0===t.e?t.s:t.e,i=void 0===t.x?e.elem.scrollLeft:t.x,r=void 0===t.y?e.elem.scrollTop:t.y;T(e,{...t,e:n,x:i,y:r,c:!0},!0),e.lock=!1}function O(e,t){if(!e.elem||t.defaultPrevented)return;if(v&&t[x]&&"z"===t.key)return void e.elem.blur();const n=S(e.elem),i=n.v.substring(0,n.s),r=n.v.substring(n.s,n.e),o=n.v.substring(n.e);for(let n=0,l=e.options.extensions.length;ne.cleanup&&e.cleanup(this)),this.ed.elem.removeEventListener("input",this.ed.onInput),this.ed.elem.removeEventListener("keydown",this.ed.onKeyDown)),this.ed.elem=e,e.addEventListener("keydown",this.ed.onKeyDown),e.addEventListener("input",this.ed.onInput),C(this.ed),this.ed.options.extensions.forEach(e=>e.init&&e.init(this))}getValue(){return this.ed.elem.value.replace(/\u00A0/g," ")}setValue(e,t=!1){this.ed.elem.value=e,t||C(this.ed)}pushState(e){w(this.ed,e)}destroy(){return this.ed.options.extensions.forEach(e=>e.cleanup&&e.cleanup(this)),this.ed.elem.removeEventListener("keydown",this.ed.onKeyDown),this.ed.elem.removeEventListener("input",this.ed.onInput),this.ed.helper.removeEventListener("input",this.ed.onUndo),document.body.removeChild(this.ed.helper),this.ed.options.extensions.forEach(e=>e.destroy&&e.destroy()),Object.assign(this.ed,{elem:null,helper:null,options:null,reOutdent:null,onKeyDown:null,onInput:null,onUndo:null,history:null}),Object.assign(this,{ed:null}),null}}return function(e){e.version="v2.0.9"}(I||(I={})),I}()},function(e,t){e.exports=flarum.core.compat["helpers/icon"]},function(e,t,n){"use strict";n.r(t);var i=n(0),r=n(2),o=n.n(r),l=n(3),s=n.n(l),c=n(4),a=n.n(c);function u(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var d=n(1),f=n.n(d),h=navigator.userAgent.match(/Macintosh/)?"Meta":"Control",p=function(e){function t(){return e.apply(this,arguments)||this}u(t,e);var n=t.prototype;return n.oncreate=function(t){e.prototype.oncreate.call(this,t),this.attrs.setShortcutHandler(this.shortcut.bind(this))},n.view=function(e){return m("div",{id:"MarkdownToolbar","data-for":this.attrs.for,style:{display:"inline-block"}},e.children)},n.shortcut=function(e){if(e.metaKey&&"Meta"===h||e.ctrlKey&&"Control"===h){var t=this.element.querySelector('[data-hotkey="'+e.key+'"]');t&&(t.click(),e.preventDefault())}},t}(f.a),y=n(5),v=n.n(y);function x(){return(x=Object.assign||function(e){for(var t=1;t1}function b(e,t){return Array(t+1).join(e)}function E(e,t){for(var n=t;e[n]&&null!=e[n-1]&&!e[n-1].match(/\s/);)n--;return n}function S(e,t,n){for(var i=t,r=n?/\n/:/\s/;e[i]&&!e[i].match(r);)i++;return i}function w(e){var t,n,i=e.value.slice(0,e.selectionStart),r=e.value.slice(e.selectionEnd),o=i.match(/\n*$/),l=r.match(/^\n*/),s=o?o[0].length:0,c=l?l[0].length:0;return i.match(/\S/)&&s<2&&(t=b("\n",2-s)),r.match(/\S/)&&c<2&&(n=b("\n",2-c)),null==t&&(t=""),null==n&&(n=""),{newlinesToAppend:t,newlinesToPrepend:n}}var O=function(e,t){var n=t.prefix,i=t.suffix,r=t.blockPrefix,o=t.blockSuffix,l=t.replaceNext,s=t.prefixSpace,c=t.scanFor,a=t.surroundWithNewlines,u=e.selectionStart,d=e.selectionEnd,f=e.value.slice(e.selectionStart,e.selectionEnd),h=k(f)&&r.length>0?r+"\n":n,p=k(f)&&o.length>0?"\n"+o:i;if(s){var y=e.value[e.selectionStart-1];0===e.selectionStart||null==y||y.match(/\s/)||(h=" "+h)}f=function(e,t,n){var i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(e.selectionStart===e.selectionEnd)e.selectionStart=E(e.value,e.selectionStart),e.selectionEnd=S(e.value,e.selectionEnd,i);else{var r=e.selectionStart-t.length,o=e.selectionEnd+n.length,l=e.value.slice(r,e.selectionStart)===t,s=e.value.slice(e.selectionEnd,o)===n;l&&s&&(e.selectionStart=r,e.selectionEnd=o)}return e.value.slice(e.selectionStart,e.selectionEnd)}(e,h,p,t.multiline);var m=e.selectionStart,v=e.selectionEnd,x=l.length>0&&p.indexOf(l)>-1&&f.length>0;if(a){var g=w(e);h=g.newlinesToAppend+n,p+=g.newlinesToPrepend}if(f.startsWith(h)&&f.endsWith(p)){var b=f.slice(h.length,f.length-p.length);if(u===d){var O=u-h.length;O=Math.max(O,m),m=v=O=Math.min(O,m+b.length)}else v=m+b.length;return{text:b,selectionStart:m,selectionEnd:v}}if(x)return c.length>0&&f.match(c)?{text:h+(p=p.replace(l,f)),selectionStart:m=v=m+h.length,selectionEnd:v}:{text:h+f+p,selectionStart:m=m+h.length+f.length+p.indexOf(l),selectionEnd:v=m+l.length};var j=h+f+p;m=u+h.length,v=d+h.length;var K=f.match(/^\s*|\s*$/g);if(t.trimFirst&&K){var C=K[0]||"",T=K[1]||"";j=C+h+f.trim()+p+T,m+=C.length,v-=T.length}return{text:j,selectionStart:m,selectionEnd:v}},j=function(e,t){var n,i=e.value.slice(e.selectionStart,e.selectionEnd);n=t.orderedList?function(e){var t,n,i,r,o=/^\d+\.\s+/,l=e.selectionStart===e.selectionEnd,s=e.value.slice(e.selectionStart,e.selectionEnd),c=s,a=s.split("\n");if(l){var u=e.value.slice(0,e.selectionStart).split(/\n/);i=e.selectionStart-u[u.length-1].length,r=S(e.value,e.selectionStart,!0),c=e.value.slice(i,r)}var d=c.split("\n");if(d.every((function(e){return o.test(e)}))){if(s=(a=d.map((function(e){return e.replace(o,"")}))).join("\n"),l&&i&&r){var f=d[0].length-a[0].length;n=t=e.selectionStart-f,e.selectionStart=i,e.selectionEnd=r}}else{s=(a=function(){var e,t,n,i=[];for(n=e=0,t=a.length;e"),e},t}(f.a),T=function(){};app.initializers.add("flarum-markdown",(function(e){var t=1;Object(i.extend)(o.a.prototype,"oninit",(function(){this.textareaId="textarea"+t++})),Object(i.extend)(o.a.prototype,"buildEditorParams",(function(e){e.textareaId=this.textareaId})),Object(i.extend)(s.a.prototype,"build",(function(e,t,n){this.el.id=n.textareaId,this.el.addEventListener("keydown",(function(e){return T.apply(void 0,arguments)})),this.mdarea=new a.a(this.el,{keyMap:{indent:["Ctrl+m"],outdent:["Ctrl+M"],inline:[]}})})),Object(i.override)(s.a.prototype,"destroy",(function(e){this.mdarea.destroy(),e()})),Object(i.extend)(o.a.prototype,"toolbarItems",(function(t){var n=function(t){return e.translator.trans("flarum-markdown.forum.composer."+t+"_tooltip")};t.add("markdown",m(p,{for:this.textareaId,setShortcutHandler:function(e){return T=e}},m(C,{title:n("header"),icon:"fas fa-heading",style:{prefix:"### "}}),m(C,{title:n("bold"),icon:"fas fa-bold",style:{prefix:"**",suffix:"**",trimFirst:!0},hotkey:"b"}),m(C,{title:n("italic"),icon:"fas fa-italic",style:{prefix:"_",suffix:"_",trimFirst:!0},hotkey:"i"}),m(C,{title:n("quote"),icon:"fas fa-quote-left",style:{prefix:"> ",multiline:!0,surroundWithNewlines:!0}}),m(C,{title:n("code"),icon:"fas fa-code",style:{prefix:"`",suffix:"`",blockPrefix:"```",blockSuffix:"```"}}),m(C,{title:n("link"),icon:"fas fa-link",style:{prefix:"[",suffix:"](https://)",replaceNext:"https://",scanFor:"https?://"}}),m(C,{title:n("image"),icon:"fas fa-image",style:{prefix:"![",suffix:"](https://)",replaceNext:"https://",scanFor:"https?://"}}),m(C,{title:n("unordered_list"),icon:"fas fa-list-ul",style:{prefix:"- ",multiline:!0,surroundWithNewlines:!0}}),m(C,{title:n("ordered_list"),icon:"fas fa-list-ol",style:{prefix:"1. ",multiline:!0,orderedList:!0}})),100)}))}))}]); //# sourceMappingURL=forum.js.map