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){e.exports=flarum.core.compat["helpers/icon"]},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]+)$/,s=/[*_]/,l=/[-=\s"'`<>\[\](){}+*^$\\.|]$/,a=/^(?:\n|$)/,c=/^(?!$)/gm,u={"`":/^``$/m,"~":/^~~$/m},d={"[":"]","(":")","{":"}","<":">"},f={"]":"[",")":"(","}":"{",">":"<"},h={enter:(n,i,s,l,c)=>{const u=s?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):"";l="\n"+e+l,c.shiftKey||(i+="\n"+e+n.indent)}else u.prefix?!c.shiftKey&&u.prefix===u.line&&a.test(l)?i=i.substring(0,u.offset)+function(e){return e.replace(o,"")}(u.prefix):!c.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,c.shiftKey):i+="\n";else i+="\n";return{v:i+l,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||l.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+(s.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,s=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),L(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||L(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"}(P||(P={})),P}()},function(e,t){e.exports=flarum.core.compat["utils/BasicEditorDriver"]},function(e,t,n){"use strict";n.r(t);var i=n(0),r=n(1),o=n.n(r);function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var l=n(2),a=n.n(l),c=navigator.userAgent.match(/Macintosh/)?"Meta":"Control",u=function(e){function t(){return e.apply(this,arguments)||this}s(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"===c||e.ctrlKey&&"Control"===c){var t=this.element.querySelector('[data-hotkey="'+e.key+'"]');t&&(t.click(),e.preventDefault())}},t}(a.a),d=n(3),f=n.n(d);function h(){return(h=Object.assign||function(e){for(var t=1;t1}function v(e,t){return Array(t+1).join(e)}function x(e,t){for(var n=t;e[n]&&null!=e[n-1]&&!e[n-1].match(/\s/);)n--;return n}function g(e,t,n){for(var i=t,r=n?/\n/:/\s/;e[i]&&!e[i].match(r);)i++;return i}function k(e){var t,n,i=e.value.slice(0,e.selectionStart),r=e.value.slice(e.selectionEnd),o=i.match(/\n*$/),s=r.match(/^\n*/),l=o?o[0].length:0,a=s?s[0].length:0;return i.match(/\S/)&&l<2&&(t=v("\n",2-l)),r.match(/\S/)&&a<2&&(n=v("\n",2-a)),null==t&&(t=""),null==n&&(n=""),{newlinesToAppend:t,newlinesToPrepend:n}}var b=function(e,t){var n=t.prefix,i=t.suffix,r=t.blockPrefix,o=t.blockSuffix,s=t.replaceNext,l=t.prefixSpace,a=t.scanFor,c=t.surroundWithNewlines,u=e.selectionStart,d=e.selectionEnd,f=e.value.slice(e.selectionStart,e.selectionEnd),h=y(f)&&r.length>0?r+"\n":n,p=y(f)&&o.length>0?"\n"+o:i;if(l){var m=e.value[e.selectionStart-1];0===e.selectionStart||null==m||m.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=x(e.value,e.selectionStart),e.selectionEnd=g(e.value,e.selectionEnd,i);else{var r=e.selectionStart-t.length,o=e.selectionEnd+n.length,s=e.value.slice(r,e.selectionStart)===t,l=e.value.slice(e.selectionEnd,o)===n;s&&l&&(e.selectionStart=r,e.selectionEnd=o)}return e.value.slice(e.selectionStart,e.selectionEnd)}(e,h,p,t.multiline);var v=e.selectionStart,b=e.selectionEnd,E=s.length>0&&p.indexOf(s)>-1&&f.length>0;if(c){var S=k(e);h=S.newlinesToAppend+n,p+=S.newlinesToPrepend}if(f.startsWith(h)&&f.endsWith(p)){var w=f.slice(h.length,f.length-p.length);if(u===d){var O=u-h.length;O=Math.max(O,v),v=b=O=Math.min(O,v+w.length)}else b=v+w.length;return{text:w,selectionStart:v,selectionEnd:b}}if(E)return a.length>0&&f.match(a)?{text:h+(p=p.replace(s,f)),selectionStart:v=b=v+h.length,selectionEnd:b}:{text:h+f+p,selectionStart:v=v+h.length+f.length+p.indexOf(s),selectionEnd:b=v+s.length};var K=h+f+p;v=u+h.length,b=d+h.length;var j=f.match(/^\s*|\s*$/g);if(t.trimFirst&&j){var L=j[0]||"",T=j[1]||"";K=L+h+f.trim()+p+T,v+=L.length,b-=T.length}return{text:K,selectionStart:v,selectionEnd:b}},E=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+/,s=e.selectionStart===e.selectionEnd,l=e.value.slice(e.selectionStart,e.selectionEnd),a=l,c=l.split("\n");if(s){var u=e.value.slice(0,e.selectionStart).split(/\n/);i=e.selectionStart-u[u.length-1].length,r=g(e.value,e.selectionStart,!0),a=e.value.slice(i,r)}var d=a.split("\n");if(d.every((function(e){return o.test(e)}))){if(l=(c=d.map((function(e){return e.replace(o,"")}))).join("\n"),s&&i&&r){var f=d[0].length-c[0].length;n=t=e.selectionStart-f,e.selectionStart=i,e.selectionEnd=r}}else{l=(c=function(){var e,t,n,i=[];for(n=e=0,t=c.length;e"),e},t}(a.a),O=n(4),K=n.n(O),j=n(5),L=n.n(j),T=function(){function e(e,t,n){this.oninput=e,this.callInputListeners=t,this.onsubmit=n}return e.prototype.handleKey=function(e,t,n,i){var r=this;setTimeout((function(){if(r.oninput(i.target.value),(i.metaKey||i.ctrlKey)&&"Enter"===i.key)return r.onsubmit();r.callInputListeners(i)}))},e}(),C=function(e){function t(){return e.apply(this,arguments)||this}s(t,e);var n=t.prototype;return n.build=function(e,t){this.el.className=t.classNames.join(" "),this.el.disabled=t.disabled,this.el.placeholder=t.placeholder,this.el.value=t.value,this.el.id=t.textareaId,e.append(this.el),this.el.addEventListener("keydown",(function(e){return t.shortcutHandler.apply(t,arguments)}));var n=function(e){t.inputListeners.forEach((function(e){e()})),e.redraw=!1};this.el.addEventListener("click",n),this.mdarea=new K.a(this.el,{keyMap:{indent:["Ctrl+m"],outdent:["Ctrl+M"],inline:[]},extensions:[new T(t.oninput,n,t.onsubmit)]})},n.destroy=function(){this.mdarea.destroy(),e.prototype.destroy.call(this)},t}(L.a),I=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.override)(o.a.prototype,"buildEditor",(function(e,t){return new C(t,this.buildEditorParams())})),Object(i.extend)(o.a.prototype,"buildEditorParams",(function(e){e.textareaId=this.textareaId,e.shortcutHandler=I})),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(u,{for:this.textareaId,setShortcutHandler:function(e){return I=e}},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:"](https://)",replaceNext:"https://",scanFor:"https?://"}}),m(w,{title:n("image"),icon:"fas fa-image",style:{prefix:"![",suffix:"](https://)",replaceNext:"https://",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