framework/extensions/mentions/js/dist/forum.js
flarum-bot 9feb9dd4eb Bundled output for commit 016503d8c3
Includes transpiled JS/TS, and Typescript declaration files (typings).

[skip ci]
2023-06-29 18:24:31 +00:00

2 lines
27 KiB
JavaScript
Generated

(()=>{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:()=>Xt,filterGroupMentions:()=>te,filterPostMentions:()=>Vt,filterTagMentions:()=>ne,filterUserMentions:()=>Yt,postFilterGroupMentions:()=>ee,postFilterPostMentions:()=>Zt,postFilterTagMentions:()=>oe,postFilterUserMentions:()=>Kt});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","forum/components/NotificationGrid");var i=t.n(r);const a=flarum.reg.get("core","common/utils/string"),u=flarum.reg.get("core","common/helpers/textContrastClass");var l=t.n(u);const c=flarum.reg.get("core","forum/components/Post");var d=t.n(c);const f=flarum.reg.get("core","forum/components/CommentPost");var p=t.n(f);const h=flarum.reg.get("core","forum/components/PostPreview");var g=t.n(h);const b=flarum.reg.get("core","common/components/LoadingIndicator");var y=t.n(b);const v=flarum.reg.get("core","common/components/Link");var w=t.n(v);const M=flarum.reg.get("core","common/helpers/punctuateSeries");var x=t.n(M);const P=flarum.reg.get("core","common/helpers/username");var C=t.n(P);const T=flarum.reg.get("core","common/helpers/icon");var A=t.n(T);const B=flarum.reg.get("core","common/components/Button");var _=t.n(B);const N=flarum.reg.get("core","common/components/Modal");var S=t.n(N);const k=flarum.reg.get("core","common/states/PaginatedListState");var F=t.n(k);class I extends(F()){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",I);class L extends(S()){oninit(t){super.oninit(t),this.state=new I({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(y(),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(g(),{post:t,onclick:()=>s().modal.close()}))))))))),this.state.hasNext()&&m("div",{className:"Modal-footer"},m("div",{className:"Form Form--centered"},m("div",{className:"Form-group"},m(_(),{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",L);const R=flarum.reg.get("core","forum/utils/DiscussionControls");var D=t.n(R);const U=flarum.reg.get("core","forum/components/EditPostComposer");var j=t.n(U);function H(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),u=0==a.length?0:3-a.match(/(\n{0,2})$/)[0].length;return e.editor.insertAtCursor(Array(u).join("\n")+(n?"> "+r+n.trim().replace(/\n/g,"\n> ")+"\n\n":r),!1),o(e)}))}function E(t,e){return s().composer.bodyMatches(j())&&s().composer.body.attrs.post.discussion()===t.discussion()?H(t,s().composer,e):D().replyAction.call(t.discussion()).then((n=>H(t,n,e)))}flarum.reg.add("flarum-mentions","forum/utils/reply",E);const G=flarum.reg.get("core","common/Fragment");var W=t.n(G);class q extends(W()){constructor(t){super(),this.post=t}view(){return m("button",{className:"Button PostQuoteButton",onclick:()=>{E(this.post,this.content)}},A()("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 O(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=$("<div>").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",q),flarum.reg.add("flarum-mentions","forum/utils/selectedText",O);const J=flarum.reg.get("core","common/components/TextEditor");var z=t.n(J);const Q=flarum.reg.get("core","common/components/TextEditorButton");var X=t.n(Q);const Y=flarum.reg.get("core","common/utils/KeyboardNavigatable");var K=t.n(Y);function V(t){return V="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},V(t)}function Z(t,e,n){return(e=function(t){var e=function(t,e){if("object"!==V(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,e);if("object"!==V(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"===V(e)?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}class tt extends(W()){constructor(){super(...arguments),Z(this,"items",[]),Z(this,"active",!1),Z(this,"index",0),Z(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;s<e?a=t-e+s-parseInt(n.css("padding-top"),10):i>o&&(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",tt);class et{constructor(){Z(this,"instances",void 0),Z(this,"mentionables",void 0),Z(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",et);const nt=flarum.reg.get("core","common/helpers/avatar");var ot=t.n(nt);const st=flarum.reg.get("core","common/helpers/highlight");var rt=t.n(st);class it{constructor(t){Z(this,"format",void 0),this.format=t}}flarum.reg.add("flarum-mentions","forum/mentionables/MentionableModel",it);const at=flarum.reg.get("core","common/utils/extractText");var ut=t.n(at);const mt=()=>ut()(s().translator.trans("core.lib.username.deleted_text"));function lt(t,e){return void 0===e&&(e=!0),t?((e?t.displayName():t.username())||mt()).replace(/"#[a-z]{0,3}[0-9]+/,"_"):mt().replace(/"#[a-z]{0,3}[0-9]+/,"_")}flarum.reg.add("flarum-mentions","forum/utils/getCleanDisplayName",lt);class ct extends it{type(){return"user"}initialResults(){return Array.from(s().store.all("users"))}replacement(t){if(s().forum.attribute("allowUsernameMentionFormat")){const e=lt(t,!1);return this.format.format(e)}const e=lt(t);return this.format.format(e,"",t.id())}suggestion(t,e){const n=C()(t,(t=>rt()(t,e)));return m("[",null,ot()(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",ct);const dt=flarum.reg.get("core","forum/components/ReplyComposer");var ft=t.n(dt);class pt extends it{type(){return"post"}initialResults(){if(!s().composer.bodyMatches(ft())&&!s().composer.bodyMatches(j()))return[];const t=s().composer.body.attrs,e=t.post;return(e&&e.discussion()||t.discussion).posts().filter((t=>t&&"comment"===t.contentType()&&(!e||t.number()<e.number()))).sort(((t,e)=>e.createdAt().getTime()-t.createdAt().getTime()))}replacement(t){const e=lt(t.user());return this.format.format(e,"p",t.id())}suggestion(t,e){var n;const o=t.user()||null,r=C()(o,(t=>rt()(t,e)));return m("[",null,ot()(o),r,[s().translator.trans("flarum-mentions.forum.composer.reply_to_post_text",{number:t.number()})," — ",(0,a.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",pt);const ht=flarum.reg.get("core","common/models/Group");var gt=t.n(ht);const bt=flarum.reg.get("core","common/components/Badge");var yt=t.n(bt);class vt extends it{type(){return"group"}initialResults(){return Array.from(s().store.all("groups").filter((t=>t.id()!==gt().GUEST_ID&&t.id()!==gt().MEMBER_ID)))}replacement(t){return this.format.format(t.namePlural(),"g",t.id())}suggestion(t,e){let n=t.namePlural();return e&&(n=rt()(n,e)),m("[",null,m(yt(),{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,n;return null!=(t=null==(e=s().session)||null==(n=e.user)?void 0:n.canMentionGroups())&&t}}flarum.reg.add("flarum-mentions","forum/mentionables/GroupMention",vt);class wt extends et{constructor(){super(...arguments),Z(this,"mentionables",[ct,pt,vt]),Z(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",wt);class Mt extends it{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=rt()(n,e)),m("[",null,m(yt(),{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",Mt);class xt extends et{constructor(){super(...arguments),Z(this,"mentionables",[Mt]),Z(this,"extendable",!1)}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",xt);class Pt{constructor(){Z(this,"formats",[new wt,new xt])}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",Pt);const Ct=flarum.reg.get("core","common/Component");var Tt=t.n(Ct);const At=flarum.reg.get("core","common/utils/classList");var Bt=t.n(At);class $t extends(Tt()){view(t){const{mentionable:e,...n}=this.attrs,o=Bt()("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",$t);const _t=flarum.reg.get("core","common/utils/throttleDebounce");class Nt{constructor(t){Z(this,"mentionables",void 0),Z(this,"results",{}),Z(this,"typed",null),Z(this,"searched",[]),Z(this,"dropdownItemAttrs",{}),Z(this,"search",(0,_t.throttle)(250,(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($t,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",Nt);const St=flarum.reg.get("core","forum/components/Notification");var kt=t.n(St);class Ft extends(kt()){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,a.truncate)(this.attrs.notification.subject().contentPlain()||"",200)}}flarum.reg.add("flarum-mentions","forum/components/PostMentionedNotification",Ft);class It extends(kt()){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,a.truncate)(this.attrs.notification.subject().contentPlain(),200)}}flarum.reg.add("flarum-mentions","forum/components/UserMentionedNotification",It);class Lt extends(kt()){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,a.truncate)(this.attrs.notification.subject().contentPlain(),200)}}flarum.reg.add("flarum-mentions","forum/components/GroupMentionedNotification",Lt);const Rt=flarum.reg.get("core","forum/components/UserPage");var Dt=t.n(Rt);const Ut=flarum.reg.get("core","common/components/LinkButton");var jt=t.n(Ut);const Ht=flarum.reg.get("core","common/extenders");var Et=t.n(Ht);const Gt=flarum.reg.get("core","common/models/Post");var Wt=t.n(Gt);const qt=flarum.reg.get("core","common/models/User");var Ot=t.n(qt);const Jt=flarum.reg.get("core","forum/components/PostsUserPage");var zt=t.n(Jt);class Qt extends(zt()){loadResults(t){return s().store.find("posts",{filter:{type:"comment",mentioned:this.user.id()},page:{offset:t,limit:this.loadLimit},sort:"-createdAt"})}}flarum.reg.add("flarum-mentions","forum/components/MentionsUserPage",Qt);const Xt=[(new(Et().Routes)).add("user.mentions","/u/:username/mentions",Qt),new(Et().Model)(Wt()).hasMany("mentionedBy").attribute("mentionedByCount"),new(Et().Model)(Ot()).attribute("canMentionGroups")];function Yt(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",ut()(C()(e))),!0;t.invalidate()}function Kt(t){t.setAttribute("deleted",!1)}function Vt(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",ut()(C()(e.user()))),!0}function Zt(t){t.setAttribute("deleted",!1)}function te(t){var e,n;if(null!=(e=s().session)&&null!=(n=e.user)&&n.canMentionGroups()){const e=s().store.getById("groups",t.getAttribute("id"));if(e)return t.setAttribute("groupname",ut()(e.namePlural())),!0}t.invalidate()}function ee(t){var e,n;if(null!=(e=s().session)&&null!=(n=e.user)&&n.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:Yt,postFilterUserMentions:Kt,filterPostMentions:Vt,postFilterPostMentions:Zt,filterGroupMentions:te,postFilterGroupMentions:ee,filterTagMentions:ne,postFilterTagMentions:oe}),flarum.reg.add("flarum-mentions","forum/utils/getMentionText",(function(t,e,n){if(void 0!==t&&void 0===e)return s().mentionables.get("user").replacement(t);if(void 0!==t&&void 0!==e)return s().mentionables.get("post").replacement(s().store.getById("posts",e));if(void 0!==n)return s().mentionables.get("group").replacement(n);throw"No parameters were passed"})),flarum.reg.add("flarum-mentions","forum/extenders/Mentionables",class{constructor(){Z(this,"formats",[]),Z(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().initializers.add("flarum-mentions",(function(){!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=$('<ul class="Dropdown-menu PostMention-preview fade"/>');n.append(r);const i=()=>$('.PostStream-item[data-id="'.concat(o,'"]')),a=()=>{const s=i();let a=!1;if(s.length){const t=s.offset().top,e=window.pageYOffset;t>e&&t+s.height()<e+$(window).height()&&(s.addClass("pulsate"),a=!0)}if(!a){const s=()=>{const e=r.outerHeight(!0);let o=0;t.offset().top-e<$(window).scrollTop()+$("#header").outerHeight()?o+=t.outerHeight(!0):o-=e,r.show().css("top",t.offset().top-n.offset().top+o).css("left",t.offsetParent().offset().left-n.offset().left).css("max-width",t.offsetParent().width())},i=t=>{const n=t.discussion();m.render(r[0],[n!==e.discussion()&&m("li",null,m("span",{className:"PostMention-preview-discussion"},n.title())),m("li",null,m(g(),{post:t}))]),s()},a=app.store.getById("posts",o);a&&a.discussion()?i(a):(m.render(r[0],m(y(),null)),app.store.find("posts",o).then(i),s()),setTimeout((()=>r.off("transitionend").addClass("in")))}},u=()=>{i().removeClass("pulsate"),r.hasClass("in")&&r.removeClass("in").one("transitionend",(()=>r.hide()))};t.on("touchend",(t=>{t.cancelable&&t.preventDefault()})),t.add(r).hover((()=>{clearTimeout(s),s=setTimeout(a,250)}),(()=>{clearTimeout(s),i().removeClass("pulsate"),s=setTimeout(u,250)})).on("touchend",(t=>{a(),t.stopPropagation()})),$(document).on("touchend",u)}))}(0,n.extend)(p().prototype,"oncreate",t),(0,n.extend)(p().prototype,"onupdate",t)}(),function(){function t(){this.$(".Post-mentionedBy-preview").removeClass("in").one("transitionend",(function(){$(this).hide()}))}(0,n.extend)(p().prototype,"oncreate",(function(){let e;const n=this.attrs.post,o=n.mentionedBy();if(o&&o.length){const r=$('<ul class="Dropdown-menu Post-mentionedBy-preview fade"/>');this.$().append(r);const i=this.$(),a=this.$(".Post-mentionedBy"),u=()=>{!r.hasClass("in")&&r.is(":visible")||(m.render(r[0],m("[",null,o.map((e=>m("li",{"data-number":e.number()},m(g(),{post:e,onclick:t.bind(this)})))),o.length<n.mentionedByCount()&&m("li",{className:"Post-mentionedBy-preview-more"},m(_(),{className:"PostPreview Button",onclick:()=>{t.call(this),s().modal.show(L,{post:n})}},m("span",{className:"PostPreview-content"},m("span",{className:"PostPreview-badge Avatar"},A()("fas fa-reply-all")),m("span",null,s().translator.trans("flarum-mentions.forum.post.mentioned_by_more_text",{count:n.mentionedByCount()-o.length}))))))),r.show().css("top",a.offset().top-i.offset().top+a.outerHeight(!0)).css("left",a.offsetParent().offset().left-i.offset().left).css("max-width",i.width()),setTimeout((()=>r.off("transitionend").addClass("in"))))};a.add(r).hover((()=>{clearTimeout(e),e=setTimeout(u,250)}),(()=>{clearTimeout(e),e=setTimeout(t,250)})),this.$().find(".Post-mentionedBy-summary a").hover((function(){r.find('[data-number="'+$(this).data("number")+'"]').addClass("active")}),(function(){r.find("[data-number]").removeClass("active")}))}})),(0,n.extend)(p().prototype,"footerItems",(function(e){const n=this.attrs.post.mentionedBy();if(n&&n.length){const o=[],r=n.sort((t=>t.user()===s().session.user?-1:0)).filter((t=>{const e=t.user();if(-1===o.indexOf(e))return o.push(e),!0})),i=4,a=r.length>i,u=r.slice(0,a?i-1:i).map((e=>{const n=e.user();return m(w(),{href:s().route.post(e),onclick:t.bind(this),"data-number":e.number()},s().session.user===n?s().translator.trans("flarum-mentions.forum.post.you_text"):C()(n))}));if(a){const t=r.length-u.length;u.push(s().translator.trans("flarum-mentions.forum.post.others_text",{count:t}))}e.add("replies",m("div",{className:"Post-mentionedBy"},m("span",{className:"Post-mentionedBy-summary"},A()("fas fa-reply"),s().translator.trans("flarum-mentions.forum.post.mentioned_by".concat(r[0].user()===s().session.user?"_self":"","_text"),{count:u.length,users:x()(u)}))))}}))}(),(0,n.extend)(p().prototype,"actionItems",(function(t){const e=this.attrs.post;e.isHidden()||s().session.user&&!e.discussion().canReply()||t.add("reply",m(_(),{className:"Button Button--link",onclick:()=>E(e)},s().translator.trans("flarum-mentions.forum.post.reply_link")))})),(0,n.extend)(p().prototype,"oncreate",(function(){const t=this.attrs.post;if(t.isHidden()||s().session.user&&!t.discussion().canReply())return;const e=this.$(".Post-body"),n=$('<div class="Post-quoteButtonContainer"></div>'),o=new q(t),r=function(t){setTimeout((()=>{const s=O(e);if(s){o.content=s,m.render(n[0],o.render());const e=window.getSelection().getRangeAt(0).getClientRects(),r=e[0];if(t.clientY<r.bottom&&t.clientX-r.right<r.left-t.clientX)o.showStart(r.left,r.top);else{const t=e[e.length-1];o.showEnd(t.right,t.bottom)}}}),1)};this.$().after(n).on("mouseup",r),"ontouchstart"in window&&document.addEventListener("selectionchange",r,!1)})),function(){s().mentionFormats=new Pt;const t=$('<div class="ComposerBody-mentionsDropdownContainer"></div>'),e=new tt;(0,n.extend)(z().prototype,"oncreate",(function(){const n=this.$(".TextEditor-editor").wrap('<div class="ComposerBody-mentionsWrapper"></div>');this.navigator=new(K()),this.navigator.when((()=>e.active)).onUp((()=>e.navigate(-1))).onDown((()=>e.navigate(1))).onSelect(e.complete.bind(e)).onCancel(e.hide.bind(e)).bindTo(n),n.after(t)})),(0,n.extend)(z().prototype,"buildEditorParams",(function(n){let o,r,i,a=new Nt({onmouseenter:function(){e.setIndex($(this).parent().index())},onclick:t=>{this.attrs.composer.editor.replaceBeforeCursor(r-1,t+" "),e.hide()}});n.inputListeners.push((()=>{const n=this.attrs.composer.editor.getSelectionRange(),u=n[0];if(n[1]-u>0)return;const l=this.attrs.composer.editor.getLastNChars(30);r=0;let c=null;for(let t=l.length-1;t>=0;t--){const e=l.substr(t,1);if(c=s().mentionFormats.get(e),c&&(0===t||/\s/.test(l.substr(t-1,1)))){o=t+1,r=u-l.length+t+1,a.init(c.makeMentionables());break}}if(e.hide(),e.active=!1,r){var d;const n=l.substring(o).toLowerCase();if(i=c.queryFromTyped(n),!i)return;a.typed=i;const s=()=>{const n=a.buildSuggestions();if(n.length){e.items=n,m.render(t[0],e.render()),e.show();const o=this.attrs.composer.editor.getCaretCoordinates(r),s=e.$().outerWidth(),i=e.$().outerHeight(),a=e.$().offsetParent();let u=o.left,l=o.top+15;l+i>a.height()&&(l=o.top-i-15),u+s>a.width()&&(u=a.width()-s),l=Math.max(-(a.offset().top-$(document).scrollTop()),l),u=Math.max(-a.offset().left,u),e.show(u,l)}else e.active=!1,e.hide()};e.active=!0,s(),e.setIndex(0),e.$().scrollTop(0),null==(d=a.search())||d.then(s)}}))})),(0,n.extend)(z().prototype,"toolbarItems",(function(t){t.add("mention",m(X(),{onclick:()=>this.attrs.composer.editor.insertAtCursor(" @"),icon:"fas fa-at"},s().translator.trans("flarum-mentions.forum.composer.mention_tooltip")))}))}(),s().notificationComponents.postMentioned=Ft,s().notificationComponents.userMentioned=It,s().notificationComponents.groupMentioned=Lt,(0,n.extend)(i().prototype,"notificationTypes",(function(t){t.add("postMentioned",{name:"postMentioned",icon:"fas fa-reply",label:s().translator.trans("flarum-mentions.forum.settings.notify_post_mentioned_label")}),t.add("userMentioned",{name:"userMentioned",icon:"fas fa-at",label:s().translator.trans("flarum-mentions.forum.settings.notify_user_mentioned_label")}),t.add("groupMentioned",{name:"groupMentioned",icon:"fas fa-at",label:s().translator.trans("flarum-mentions.forum.settings.notify_group_mentioned_label")})})),(0,n.extend)(Dt().prototype,"navItems",(function(t){const e=this.user;t.add("mentions",m(jt(),{href:s().route("user.mentions",{username:e.slug()}),name:"mentions",icon:"fas fa-at"},s().translator.trans("flarum-mentions.forum.user.mentions_link")),80)})),a.getPlainContent.removeSelectors.push("a.PostMention"),(0,n.extend)(d().prototype,"oncreate",(function(){this.$(".GroupMention--colored, .TagMention--colored").each((function(){this.classList.add(l()(getComputedStyle(this).getPropertyValue("--color")))}))}))}))})(),module.exports=e})();
//# sourceMappingURL=forum.js.map