(()=>{var t={n:e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return t.d(n,{a:n}),n},d:(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};(()=>{"use strict";t.r(e),t.d(e,{extend:()=>Qt,filterGroupMentions:()=>te,filterPostMentions:()=>Yt,filterTagMentions:()=>ne,filterUserMentions:()=>Vt,postFilterGroupMentions:()=>ee,postFilterPostMentions:()=>Zt,postFilterTagMentions:()=>oe,postFilterUserMentions:()=>Xt});const n=flarum.reg.get("core","common/extend"),o=flarum.reg.get("core","forum/app");var s=t.n(o);const r=flarum.reg.get("core","common/utils/string"),i=flarum.reg.get("core","common/helpers/textContrastClass");var a=t.n(i);const u=flarum.reg.get("core","forum/components/Post");var l=t.n(u);const c=flarum.reg.get("core","forum/components/CommentPost");var d=t.n(c);const f=flarum.reg.get("core","forum/components/PostPreview");var p=t.n(f);const h=flarum.reg.get("core","common/components/LoadingIndicator");var g=t.n(h);const b=flarum.reg.get("core","common/components/Link");var y=t.n(b);const v=flarum.reg.get("core","common/helpers/punctuateSeries");var w=t.n(v);const M=flarum.reg.get("core","common/helpers/username");var x=t.n(M);const P=flarum.reg.get("core","common/components/Icon");var C=t.n(P);const A=flarum.reg.get("core","common/components/Button");var T=t.n(A);const B=flarum.reg.get("core","common/components/Modal");var D=t.n(B);const N=flarum.reg.get("core","common/states/PaginatedListState");var _=t.n(N);class S extends(_()){constructor(t,e){void 0===e&&(e=1),t.page={...t.page||{},limit:10},super(t,e,10)}get type(){return"posts"}}flarum.reg.add("flarum-mentions","forum/state/MentionedByModalState",S);const k=flarum.reg.get("core","common/components/Form");var F=t.n(k);class I extends(D()){oninit(t){super.oninit(t),this.state=new S({filter:{mentionedPost:this.attrs.post.id()},sort:"number"}),this.state.refresh()}className(){return"MentionedByModal"}title(){return s().translator.trans("flarum-mentions.forum.mentioned_by.title")}content(){return m("[",null,m("div",{className:"Modal-body"},this.state.isInitialLoading()?m(g(),null):m("[",null,m("ul",{className:"MentionedByModal-list Dropdown-menu Dropdown-menu--inline Post-mentionedBy-preview"},this.state.getPages().map((t=>t.items.map((t=>m("li",{"data-number":t.number()},m(p(),{post:t,onclick:()=>s().modal.close()}))))))))),this.state.hasNext()&&m("div",{className:"Modal-footer"},m(F(),{className:"Form--centered"},m("div",{className:"Form-group"},m(T(),{className:"Button Button--block",onclick:()=>this.state.loadNext(),loading:this.state.isLoadingNext()},s().translator.trans("flarum-mentions.forum.mentioned_by.load_more_button"))))))}}flarum.reg.add("flarum-mentions","forum/components/MentionedByModal",I);const R=flarum.reg.get("core","forum/utils/DiscussionControls");var L=t.n(R);function U(t,e,n){return new Promise((o=>{const r=s().mentionFormats.mentionable("post").replacement(t)+" ";e.fields.content()||(e.body.attrs.originalContent=r);const i=e.editor.getSelectionRange()[0],a=e.fields.content().slice(0,i),m=0==a.length?0:3-a.match(/(\n{0,2})$/)[0].length;return e.editor.insertAtCursor(Array(m).join("\n")+(n?"> "+r+n.trim().replace(/\n/g,"\n> ")+"\n\n":r),!1),o(e)}))}function j(t,e){const n=flarum.reg.checkModule("core","forum/components/EditPostComposer");return n&&s().composer.bodyMatches(n)&&s().composer.body.attrs.post.discussion()===t.discussion()?U(t,s().composer,e):L().replyAction.call(t.discussion()).then((n=>U(t,n,e)))}flarum.reg.add("flarum-mentions","forum/utils/reply",j);const E=flarum.reg.get("core","common/Fragment");var G=t.n(E);class H extends(G()){constructor(t){super(),this.post=t}view(){return m("button",{className:"Button PostQuoteButton",onclick:()=>{j(this.post,this.content)}},m(C(),{name:"fas fa-quote-left",className:"Button-icon"}),s().translator.trans("flarum-mentions.forum.post.quote_button"))}show(t,e){const n=this.$().show(),o=n.offsetParent().offset();n.css("left",t-o.left).css("top",e-o.top),this.hideHandler=this.hide.bind(this),$(document).on("mouseup",this.hideHandler)}showStart(t,e){const n=this.$();this.show(t,$(window).scrollTop()+e-n.outerHeight()-5)}showEnd(t,e){const n=this.$();this.show(t-n.outerWidth(),$(window).scrollTop()+e+5)}hide(){this.$().hide(),$(document).off("mouseup",this.hideHandler)}}function q(t){const e=window.getSelection();if(!e.isCollapsed){const n=e.getRangeAt(0),o=n.commonAncestorContainer;if(t[0]===o||$.contains(t[0],o)){const t=$("
").append(n.cloneContents());return t.find("img.emoji").replaceWith((function(){return this.alt})),t.find("img").replaceWith((function(){return"![](".concat(this.src,")")})),t.find("a").replaceWith((function(){return"[".concat(this.innerText,"](").concat(this.href,")")})),t.text()}}return""}flarum.reg.add("flarum-mentions","forum/fragments/PostQuoteButton",H),flarum.reg.add("flarum-mentions","forum/utils/selectedText",q);const W=flarum.reg.get("core","common/components/TextEditorButton");var O=t.n(W);const J=flarum.reg.get("core","common/utils/KeyboardNavigatable");var z=t.n(J);const K=flarum.reg.get("core","common/utils/AutocompleteReader");var Q=t.n(K);const V=flarum.reg.get("core","common/utils/throttleDebounce");function X(t){return X="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},X(t)}function Y(t,e,n){return o=function(t,e){if("object"!=X(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,"string");if("object"!=X(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(e),(e="symbol"==X(o)?o:o+"")in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t;var o}class Z extends(G()){constructor(){super(...arguments),Y(this,"items",[]),Y(this,"active",!1),Y(this,"index",0),Y(this,"keyWasJustPressed",!1)}view(){return m("ul",{className:"Dropdown-menu MentionsDropdown"},this.items.map((t=>m("li",null,t))))}show(t,e){this.$().show().css({left:t+"px",top:e+"px"}),this.active=!0}hide(){this.$().hide(),this.active=!1}navigate(t){this.keyWasJustPressed=!0,this.setIndex(this.index+t,!0),clearTimeout(this.keyWasJustPressedTimeout),this.keyWasJustPressedTimeout=setTimeout((()=>this.keyWasJustPressed=!1),500)}complete(){this.$("li").eq(this.index).find("button").click()}setIndex(t,e){if(this.keyWasJustPressed&&!e)return;const n=this.$(),o=n.find("li");let s=t;s<0?s=o.length-1:s>=o.length&&(s=0),this.index=s;const r=o.removeClass("active").eq(s).addClass("active");if(e){const t=n.scrollTop(),e=n.offset().top,o=e+n.outerHeight(),s=r.offset().top,i=s+r.outerHeight();let a;so&&(a=t-o+i+parseInt(n.css("padding-bottom"),10)),void 0!==a&&n.stop(!0).animate({scrollTop:a},100)}}}flarum.reg.add("flarum-mentions","forum/fragments/AutocompleteDropdown",Z);const tt=flarum.reg.get("core","common/Component");var et=t.n(tt);const nt=flarum.reg.get("core","common/utils/classList");var ot=t.n(nt);class st extends(et()){view(t){const{mentionable:e,...n}=this.attrs,o=ot()("MentionsDropdownItem","PostPreview","MentionsDropdown-".concat(e.type()));return m("button",Object.assign({className:o},n),m("span",{className:"PostPreview-content"},t.children))}}flarum.reg.add("flarum-mentions","forum/components/MentionsDropdownItem",st);class rt{constructor(t){Y(this,"mentionables",void 0),Y(this,"results",{}),Y(this,"typed",null),Y(this,"searched",[]),Y(this,"dropdownItemAttrs",{}),Y(this,"search",(async()=>{if(!this.typed||this.typed.length<=1)return;const t=this.typed.toLowerCase();if(!this.searched.includes(t)){for(const e of this.mentionables)for(const n of await e.search(t))this.results[e.type()].has(n.id())||this.results[e.type()].set(n.id(),n);return this.searched.push(t),Promise.resolve()}})),this.dropdownItemAttrs=t}init(t){this.typed=null,this.mentionables=t;for(const t of this.mentionables)this.results[t.type()]=new Map(t.initialResults().map((t=>[t.id(),t])))}matches(t,e){var n;return t.matches(e,(null==(n=this.typed)?void 0:n.toLowerCase())||"")}makeSuggestion(t,e){const n=t.suggestion(e,this.typed),o=t.replacement(e),{onclick:s,...r}=this.dropdownItemAttrs;return m(st,Object.assign({mentionable:t,onclick:()=>s(o)},r),n)}buildSuggestions(){const t=[];for(const e of this.mentionables){if(!e.enabled())continue;let n=Array.from(this.results[e.type()].values()).filter((t=>this.matches(e,t)));const o=e.maxStoreMatchedResults();o&&(n=n.splice(0,o));for(const o of n){const n=this.makeSuggestion(e,o);t.push(n)}}return t}}flarum.reg.add("flarum-mentions","forum/mentionables/MentionableModels",rt);class it{constructor(){Y(this,"instances",void 0),Y(this,"mentionables",void 0),Y(this,"extendable",void 0)}makeMentionables(){var t;return null!=(t=this.instances)?t:this.instances=this.mentionables.map((t=>new t(this)))}getMentionable(t){var e;return null!=(e=this.makeMentionables().find((e=>e.type()===t)))?e:null}extend(t){if(!this.extendable)throw new Error("This mention format does not allow extending.");this.mentionables.push(t)}}flarum.reg.add("flarum-mentions","forum/mentionables/formats/MentionFormat",it);const at=flarum.reg.get("core","common/components/Avatar");var mt=t.n(at);const ut=flarum.reg.get("core","common/helpers/highlight");var lt=t.n(ut);class ct{constructor(t){Y(this,"format",void 0),this.format=t}}flarum.reg.add("flarum-mentions","forum/mentionables/MentionableModel",ct);const dt=flarum.reg.get("core","common/utils/extractText");var ft=t.n(dt);const pt=()=>ft()(s().translator.trans("core.lib.username.deleted_text"));function ht(t,e){return void 0===e&&(e=!0),t?((e?t.displayName():t.username())||pt()).replace(/"#[a-z]{0,3}[0-9]+/,"_"):pt().replace(/"#[a-z]{0,3}[0-9]+/,"_")}flarum.reg.add("flarum-mentions","forum/utils/getCleanDisplayName",ht);class gt extends ct{type(){return"user"}initialResults(){return Array.from(s().store.all("users"))}replacement(t){if(s().forum.attribute("allowUsernameMentionFormat")){const e=ht(t,!1);return this.format.format(e)}const e=ht(t);return this.format.format(e,"",t.id())}suggestion(t,e){const n=x()(t,(t=>lt()(t,e)));return m("[",null,m(mt(),{user:t}),n)}matches(t,e){return!!e&&[t.username(),t.displayName()].some((t=>t.toLowerCase().substr(0,e.length)===e))}maxStoreMatchedResults(){return null}async search(t){return await s().store.find("users",{filter:{q:t},page:{limit:5}})}enabled(){return!0}}flarum.reg.add("flarum-mentions","forum/mentionables/UserMention",gt);class bt extends ct{type(){return"post"}initialResults(){const t=flarum.reg.checkModule("core","forum/components/EditPostComposer"),e=flarum.reg.checkModule("core","forum/components/ReplyComposer");if(!(e&&s().composer.bodyMatches(e)||t&&s().composer.bodyMatches(t)))return[];const n=s().composer.body.attrs,o=n.post;return(o&&o.discussion()||n.discussion).posts().filter((t=>t&&"comment"===t.contentType()&&(!o||t.number()e.createdAt().getTime()-t.createdAt().getTime()))}replacement(t){const e=ht(t.user());return this.format.format(e,"p",t.id())}suggestion(t,e){var n;const o=t.user()||null,i=x()(o,(t=>lt()(t,e)));return m("[",null,m(mt(),{user:o}),i,[s().translator.trans("flarum-mentions.forum.composer.reply_to_post_text",{number:t.number()})," — ",(0,r.truncate)(null!=(n=t.contentPlain())?n:"",200)])}matches(t,e){const n=t.user(),o=s().mentionFormats.mentionable("user");return!e||n&&o.matches(n,e)}maxStoreMatchedResults(){return 5}search(t){return Promise.resolve([])}enabled(){return!0}}flarum.reg.add("flarum-mentions","forum/mentionables/PostMention",bt);const yt=flarum.reg.get("core","common/models/Group");var vt=t.n(yt);const wt=flarum.reg.get("core","common/components/Badge");var Mt=t.n(wt);class xt extends ct{type(){return"group"}initialResults(){return Array.from(s().store.all("groups").filter((t=>t.id()!==vt().GUEST_ID&&t.id()!==vt().MEMBER_ID)))}replacement(t){return this.format.format(t.namePlural(),"g",t.id())}suggestion(t,e){let n=t.namePlural();return e&&(n=lt()(n,e)),m("[",null,m(Mt(),{className:"Avatar Badge Badge--group--".concat(t.id()," Badge-icon"),color:t.color(),type:"group",icon:t.icon()}),m("span",{className:"username"},n))}matches(t,e){return!!e&&[t.namePlural().toLowerCase(),t.nameSingular().toLowerCase()].some((t=>t.toLowerCase().substr(0,e.length)===e))}maxStoreMatchedResults(){return null}search(t){return Promise.resolve([])}enabled(){var t,e;return null!=(t=null==(e=s().session)||null==(e=e.user)?void 0:e.canMentionGroups())&&t}}flarum.reg.add("flarum-mentions","forum/mentionables/GroupMention",xt);class Pt extends it{constructor(){super(...arguments),Y(this,"mentionables",[gt,bt,xt]),Y(this,"extendable",!0)}trigger(){return"@"}queryFromTyped(t){const e=t.match(/^["“]?((?:(?!"#).)+)$/);return e?e[1]:null}format(t,e,n){return void 0===e&&(e=""),void 0===n&&(n=null),{simple:"@".concat(t),safe:'@"'.concat(t,'"#').concat(e).concat(n)}[n?"safe":"simple"]}}flarum.reg.add("flarum-mentions","forum/mentionables/formats/AtMentionFormat",Pt);class Ct extends ct{type(){return"tag"}initialResults(){return Array.from(s().store.all("tags"))}replacement(t){return this.format.format(t.slug())}matches(t,e){return!!e&&[t.name().toLowerCase()].some((t=>t.toLowerCase().substr(0,e.length)===e))}maxStoreMatchedResults(){return null}async search(t){return await s().store.find("tags",{filter:{q:t},page:{limit:5}})}suggestion(t,e){let n=t.name();return e&&(n=lt()(n,e)),m("[",null,m(Mt(),{className:"Avatar",icon:t.icon(),color:t.color(),type:"tag"}),m("span",{className:"username"},n))}enabled(){return"flarum-tags"in flarum.extensions}}flarum.reg.add("flarum-mentions","forum/mentionables/TagMention",Ct);class At extends it{constructor(){super(...arguments),Y(this,"mentionables",[Ct]),Y(this,"extendable",!0)}trigger(){return"#"}queryFromTyped(t){const e=t.match(/^[-_\p{L}\p{N}\p{M}]+$/giu);return e?e[0]:null}format(t){return"#".concat(t)}}flarum.reg.add("flarum-mentions","forum/mentionables/formats/HashMentionFormat",At);class Tt{constructor(){Y(this,"formats",[new Pt,new At])}get(t){var e;return null!=(e=this.formats.find((e=>e.trigger()===t)))?e:null}mentionable(t){for(const e of this.formats){const n=e.getMentionable(t);if(n)return n}return null}extend(t){this.formats.push(new t)}}flarum.reg.add("flarum-mentions","forum/mentionables/formats/MentionFormats",Tt);const Bt=flarum.reg.get("core","forum/components/UserPage");var $t=t.n(Bt);const Dt=flarum.reg.get("core","common/components/LinkButton");var Nt=t.n(Dt);const _t=flarum.reg.get("core","common/extenders");var St=t.n(_t);const kt=flarum.reg.get("core","common/models/Post");var Ft=t.n(kt);const It=flarum.reg.get("core","common/models/User");var Rt=t.n(It);const Lt=flarum.reg.get("core","forum/components/PostsUserPage");var Ut=t.n(Lt);class jt extends(Ut()){params(t){return{filter:{type:"comment",mentioned:t.id()}}}}flarum.reg.add("flarum-mentions","forum/components/MentionsUserPage",jt);const Et=flarum.reg.get("core","forum/components/Notification");var Gt=t.n(Et);class Ht extends(Gt()){icon(){return"fas fa-reply"}href(){const t=this.attrs.notification,e=t.subject(),n=t.content();return s().route.discussion(e.discussion(),n&&n.replyNumber)}content(){const t=this.attrs.notification.fromUser();return s().translator.trans("flarum-mentions.forum.notifications.post_mentioned_text",{user:t,count:1})}excerpt(){return(0,r.truncate)(this.attrs.notification.subject().contentPlain()||"",200)}}flarum.reg.add("flarum-mentions","forum/components/PostMentionedNotification",Ht);class qt extends(Gt()){icon(){return"fas fa-at"}href(){const t=this.attrs.notification.subject();return s().route.discussion(t.discussion(),t.number())}content(){const t=this.attrs.notification.fromUser();return s().translator.trans("flarum-mentions.forum.notifications.user_mentioned_text",{user:t})}excerpt(){return(0,r.truncate)(this.attrs.notification.subject().contentPlain(),200)}}flarum.reg.add("flarum-mentions","forum/components/UserMentionedNotification",qt);class Wt extends(Gt()){icon(){return"fas fa-at"}href(){const t=this.attrs.notification.subject();return s().route.discussion(t.discussion(),t.number())}content(){const t=this.attrs.notification.fromUser();return s().translator.trans("flarum-mentions.forum.notifications.group_mentioned_text",{user:t})}excerpt(){return(0,r.truncate)(this.attrs.notification.subject().contentPlain(),200)}}flarum.reg.add("flarum-mentions","forum/components/GroupMentionedNotification",Wt);const Ot=flarum.reg.get("core","common/query/IGambit"),Jt=flarum.reg.get("core","common/app");var zt=t.n(Jt);class Kt extends Ot.KeyValueGambit{key(){return zt().translator.trans("flarum-mentions.lib.gambits.posts.mentioned.key",{},!0)}hint(){return zt().translator.trans("flarum-mentions.lib.gambits.posts.mentioned.hint",{},!0)}filterKey(){return"mentioned"}}flarum.reg.add("flarum-mentions","common/query/posts/MentionedGambit",Kt);const Qt=[(new(St().Search)).gambit("posts",Kt),(new(St().Routes)).add("user.mentions","/u/:username/mentions",jt),new(St().Model)(Ft()).hasMany("mentionedBy").attribute("mentionedByCount"),(new(St().Notification)).add("postMentioned",Ht).add("userMentioned",qt).add("groupMentioned",Wt),new(St().Model)(Rt()).attribute("canMentionGroups")];function Vt(t){let e;if(s().forum.attribute("allowUsernameMentionFormat")&&t.hasAttribute("username")?e=s().store.getBy("users","username",t.getAttribute("username")):t.hasAttribute("id")&&(e=s().store.getById("users",t.getAttribute("id"))),e)return t.setAttribute("id",e.id()),t.setAttribute("slug",e.slug()),t.setAttribute("displayname",ft()(x()(e))),!0;t.invalidate()}function Xt(t){t.setAttribute("deleted",!1)}function Yt(t){const e=s().store.getById("posts",t.getAttribute("id"));if(e)return t.setAttribute("discussionid",e.discussion().id()),t.setAttribute("number",e.number()),t.setAttribute("displayname",ft()(x()(e.user()))),!0}function Zt(t){t.setAttribute("deleted",!1)}function te(t){var e;if(null!=(e=s().session)&&null!=(e=e.user)&&e.canMentionGroups()){const e=s().store.getById("groups",t.getAttribute("id"));if(e)return t.setAttribute("groupname",ft()(e.namePlural())),!0}t.invalidate()}function ee(t){var e;if(null!=(e=s().session)&&null!=(e=e.user)&&e.canMentionGroups()){const e=s().store.getById("groups",t.getAttribute("id"));t.setAttribute("color",e.color()),t.setAttribute("icon",e.icon()),t.setAttribute("deleted",!1)}}function ne(t){if("flarum-tags"in flarum.extensions){const e=s().store.getBy("tags","slug",t.getAttribute("slug"));if(e)return t.setAttribute("id",e.id()),t.setAttribute("tagname",e.name()),!0}t.invalidate()}function oe(t){if("flarum-tags"in flarum.extensions){const e=s().store.getBy("tags","slug",t.getAttribute("slug"));t.setAttribute("icon",e.icon()),t.setAttribute("color",e.color()),t.setAttribute("deleted",!1)}}flarum.reg.add("flarum-mentions","forum/utils/textFormatter",{filterUserMentions:Vt,postFilterUserMentions:Xt,filterPostMentions:Yt,postFilterPostMentions:Zt,filterGroupMentions:te,postFilterGroupMentions:ee,filterTagMentions:ne,postFilterTagMentions:oe}),flarum.reg.add("flarum-mentions","forum/extenders/Mentionables",class{constructor(){Y(this,"formats",[]),Y(this,"mentionables",{})}format(t){return this.formats.push(t),this}mentionable(t,e){return this.mentionables[t]||(this.mentionables[t]=[]),this.mentionables[t].push(e),this}extend(t){for(const e of this.formats)t.mentionFormats.extend(e);for(const e in this.mentionables){const n=t.mentionFormats.get(e);if(n)for(const t of this.mentionables[e])n.extend(t)}}}),s().mentionFormats=new Tt,s().initializers.add("flarum-mentions",(()=>{!function(){function t(){const t=this.attrs.post.contentHtml();if(t===this.oldPostContentHtml||this.isEditing())return;this.oldPostContentHtml=t;const e=this.attrs.post,n=this.$();this.$().on("click",".UserMention:not(.UserMention--deleted), .PostMention:not(.PostMention--deleted), .TagMention:not(.TagMention--deleted)",(function(t){m.route.set(this.getAttribute("href")),t.preventDefault()})),this.$(".PostMention:not(.PostMention--deleted)").each((function(){const t=$(this),o=t.data("id");let s;const r=$('