mirror of
https://github.com/flarum/core.git
synced 2025-06-28 13:44:21 +02:00
2 lines
17 KiB
JavaScript
2 lines
17 KiB
JavaScript
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<o&&(n=e.substring(l)+n,e=e.substring(0,l)),(l<o||!n)&&(o+=r.length),n?n=n.replace(c,r):e+=r,m(t,e+n+i,o,n?l+n.length:o)}(this._elem,p,v,g,this._indent);else if("Tab"===h.key&&h.shiftKey||"o"===h.key&&h[t])!function(t,e,n,i,r,o){var l=e.length,s=e.lastIndexOf("\n")+1;s<l&&(n=e.substring(s)+n,e=e.substring(0,s),n.substring(0,r.length)===r&&(l-=r.length)),n=n.replace(o,""),m(t,e+n+i,l,s+n.length)}(this._elem,p,v,g,this._indent,this._reOutdent);else{if(!e.test(h.key))return;!function(t,e,i,r,o){i||o in d||r.charAt(0)!==o?!i&&("'"===o||o in f)?m(t,e+o+r,e.length+1):!i&&o in u&&u[o].test(e)?m(t,e+o+"language\n"+o+o+o+("\n"!==r.charAt(0)?"\n":"")+r,e.length+1,e.length+9):m(t,e+(f[o]||o)+i+(d[o]||o)+r,e.length+1,e.length+1+i.length):m(t,e+(n.test(o)?o+o:"")+r,e.length+1)}(this._elem,p,v,g,h.key)}else!function(t,e,n,c,u){var d=n?null:function(t){var e=t.lastIndexOf("\n")+1,n=t.substring(e),r=i.exec(n);return{line:n,offset:e,prefix:r&&r[0]}}(e);!n&&d.prefix?u||d.prefix!==d.line?!u&&function(t){return r.test(t)}(d.prefix)?e+="\n"+function(t){return t.replace(s,function(t,e){return parseInt(e)+1+"."})}(d.prefix):e+="\n"+function(t,e){return t.replace(e?l:o," ")}(d.prefix,u):e=e.substring(0,d.offset)+function(t){return t.replace(a,"")}(d.prefix):e+="\n",m(t,e+c,e.length)}(this._elem,p,v,g,h.shiftKey);h.preventDefault()}}},h})?i.apply(e,r):i)||(t.exports=o)},function(t,e,n){"use strict";function i(){return(i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}n.r(e);var r=n(1),o=n(2),l=n.n(o),s=n(0),a=n.n(s),c=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},u=function t(e,n,i){null===e&&(e=Function.prototype);var r=Object.getOwnPropertyDescriptor(e,n);if(void 0===r){var o=Object.getPrototypeOf(e);return null===o?void 0:t(o,n,i)}if("value"in r)return r.value;var l=r.get;return void 0!==l?l.call(i):void 0},d=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}();function f(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function h(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function p(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function v(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}Object.setPrototypeOf(v.prototype,HTMLElement.prototype),Object.setPrototypeOf(v,HTMLElement);var g=new WeakMap,_=function(t){function e(){f(this,e);var t=h(this,(e.__proto__||Object.getPrototypeOf(e)).call(this)),n=function(){var e=g.get(t);e&&N(t,e)};return t.addEventListener("keydown",function(t){return function(e){" "!==e.key&&"Enter"!==e.key||(e.preventDefault(),t(e))}}(n)),t.addEventListener("click",n),t}return p(e,v),d(e,[{key:"connectedCallback",value:function(){this.hasAttribute("tabindex")||this.setAttribute("tabindex","0"),this.hasAttribute("role")||this.setAttribute("role","button")}},{key:"click",value:function(){var t=g.get(this);t&&N(this,t)}}]),e}(),y=function(t){function e(){f(this,e);var t=h(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return g.set(t,{prefix:"### "}),t}return p(e,_),e}();window.customElements.get("md-header")||(window.MarkdownHeaderButtonElement=y,window.customElements.define("md-header",y));var b=function(t){function e(){f(this,e);var t=h(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return g.set(t,{prefix:"**",suffix:"**",trimFirst:!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","b")}}]),e}();window.customElements.get("md-bold")||(window.MarkdownBoldButtonElement=b,window.customElements.define("md-bold",b));var w=function(t){function e(){f(this,e);var t=h(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return g.set(t,{prefix:"_",suffix:"_",trimFirst:!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","i")}}]),e}();window.customElements.get("md-italic")||(window.MarkdownItalicButtonElement=w,window.customElements.define("md-italic",w));var E=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-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;t<e;n=++t){var r=o[n];i.push(n+1+". "+r)}return i}(),r=o.join("\n");var l=W(t),s=l.newlinesToAppend,a=l.newlinesToPrepend;i=t.selectionStart+s.length,n=i+r.length,r=s+r+a}return{text:r,selectionStart:i,selectionEnd:n}}(t):e.multiline&&A(n)?function(t,e){var n=e.prefix,i=e.suffix,r=e.surroundWithNewlines,o=t.value.slice(t.selectionStart,t.selectionEnd),l=t.selectionStart,s=t.selectionEnd,a=o.split("\n");if(a.every(function(t){return t.startsWith(n)&&t.endsWith(i)}))o=a.map(function(t){return t.slice(n.length,t.length-i.length)}).join("\n"),s=l+o.length;else if(o=a.map(function(t){return n+t+i}).join("\n"),r){var c=W(t),u=c.newlinesToAppend,d=c.newlinesToPrepend;l+=u.length,s=l+o.length,o=u+o+d}return{text:o,selectionStart:l,selectionEnd:s}}(t,e):function(t,e){var n=void 0,i=void 0,r=e.prefix,o=e.suffix,l=e.blockPrefix,s=e.blockSuffix,a=e.replaceNext,c=e.prefixSpace,u=e.scanFor,d=e.surroundWithNewlines,f=t.selectionStart,h=t.selectionEnd,p=t.value.slice(t.selectionStart,t.selectionEnd),m=A(p)&&l.length>0?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")+" <cmd-b>"},n),a()("fas fa-bold")),m("md-italic",i({title:r("italic")+" <cmd-i>"},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")+" <cmd-k>"},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
|