framework/extensions/mentions/js/dist/forum.js
flarum-bot 2e0f026dde Bundled output for commit bf52743510
Includes transpiled JS/TS, and Typescript declaration files (typings).

[skip ci]
2023-01-22 13:16:48 +00:00

2 lines
20 KiB
JavaScript
Generated

(()=>{var t={n:n=>{var e=n&&n.__esModule?()=>n.default:()=>n;return t.d(e,{a:e}),e},d:(n,e)=>{for(var o in e)t.o(e,o)&&!t.o(n,o)&&Object.defineProperty(n,o,{enumerable:!0,get:e[o]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},n={};(()=>{"use strict";t.r(n),t.d(n,{extend:()=>It,filterGroupMentions:()=>jt,filterPostMentions:()=>Ut,filterUserMentions:()=>Dt});var e={};t.r(e),t.d(e,{default:()=>F,insertMention:()=>J});var o={};t.r(o),t.d(o,{filterGroupMentions:()=>jt,filterPostMentions:()=>Ut,filterUserMentions:()=>Dt});const r=flarum.core.compat["common/extend"],s=flarum.core.compat["forum/app"];var i=t.n(s);const a=flarum.core.compat["forum/components/NotificationGrid"];var u=t.n(a);const c=flarum.core.compat["common/utils/string"],f=flarum.core.compat["common/helpers/textContrastClass"];var l=t.n(f);const d=flarum.core.compat["forum/components/Post"];var p=t.n(d);const h=flarum.core.compat["forum/components/CommentPost"];var v=t.n(h);const g=flarum.core.compat["forum/components/PostPreview"];var y=t.n(g);const b=flarum.core.compat["common/components/LoadingIndicator"];var w=t.n(b);const P=flarum.core.compat["common/Model"];var x=t.n(P);const M=flarum.core.compat["common/models/Post"];var C=t.n(M);const _=flarum.core.compat["common/components/Link"];var T=t.n(_);const B=flarum.core.compat["common/helpers/punctuateSeries"];var A=t.n(B);const N=flarum.core.compat["common/helpers/username"];var k=t.n(N);const S=flarum.core.compat["common/helpers/icon"];var I=t.n(S);const D=flarum.core.compat["common/components/Button"];var U=t.n(D);const j=flarum.core.compat["forum/utils/DiscussionControls"];var E=t.n(j);const H=flarum.core.compat["forum/components/EditPostComposer"];var L=t.n(H);const O=flarum.core.compat["common/utils/extractText"];var W=t.n(O),G=function(){return W()(i().translator.trans("core.lib.username.deleted_text"))};function R(t,n){return void 0===n&&(n=!0),t?((n?t.displayName():t.username())||G()).replace(/"#[a-z]{0,3}[0-9]+/,"_"):G().replace(/"#[a-z]{0,3}[0-9]+/,"_")}function q(t,n,e){if(void 0!==t&&void 0===n)return i().forum.attribute("allowUsernameMentionFormat")?"@"+R(t,!1):'@"'+R(t)+'"#'+t.id();if(void 0!==t&&void 0!==n)return'@"'+R(t)+'"#p'+n;if(void 0!==e)return'@"'+e.namePlural()+'"#g'+e.id();throw"No parameters were passed"}function J(t,n,e){return new Promise((function(o){var r=q(t.user(),t.id())+" ";n.fields.content()||(n.body.attrs.originalContent=r);var s=n.editor.getSelectionRange()[0],i=n.fields.content().slice(0,s),a=0==i.length?0:3-i.match(/(\n{0,2})$/)[0].length;return n.editor.insertAtCursor(Array(a).join("\n")+(e?"> "+r+e.trim().replace(/\n/g,"\n> ")+"\n\n":r),!1),o(n)}))}function F(t,n){return i().composer.bodyMatches(L())&&i().composer.body.attrs.post.discussion()===t.discussion()?J(t,i().composer,n):E().replyAction.call(t.discussion()).then((function(e){return J(t,e,n)}))}function z(t,n){return z=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},z(t,n)}function Q(t,n){t.prototype=Object.create(n.prototype),t.prototype.constructor=t,z(t,n)}const X=flarum.core.compat["common/Fragment"];var Y=t.n(X),K=function(t){function n(n){var e;return(e=t.call(this)||this).post=n,e}Q(n,t);var e=n.prototype;return e.view=function(){var t=this;return m("button",{class:"Button PostQuoteButton",onclick:function(){F(t.post,t.content)}},I()("fas fa-quote-left",{className:"Button-icon"}),i().translator.trans("flarum-mentions.forum.post.quote_button"))},e.show=function(t,n){var e=this.$().show(),o=e.offsetParent().offset();e.css("left",t-o.left).css("top",n-o.top),this.hideHandler=this.hide.bind(this),$(document).on("mouseup",this.hideHandler)},e.showStart=function(t,n){var e=this.$();this.show(t,$(window).scrollTop()+n-e.outerHeight()-5)},e.showEnd=function(t,n){var e=this.$();this.show(t-e.outerWidth(),$(window).scrollTop()+n+5)},e.hide=function(){this.$().hide(),$(document).off("mouseup",this.hideHandler)},n}(Y());function V(t){var n=window.getSelection();if(!n.isCollapsed){var e=n.getRangeAt(0),o=e.commonAncestorContainer;if(t[0]===o||$.contains(t[0],o)){var r=$("<div>").append(e.cloneContents());return r.find("img.emoji").replaceWith((function(){return this.alt})),r.find("img").replaceWith((function(){return"![]("+this.src+")"})),r.find("a").replaceWith((function(){return"["+this.innerText+"]("+this.href+")"})),r.text()}}return""}const Z=flarum.core.compat["common/components/TextEditor"];var tt=t.n(Z);const nt=flarum.core.compat["common/components/TextEditorButton"];var et=t.n(nt);const ot=flarum.core.compat["forum/components/ReplyComposer"];var rt=t.n(ot);const st=flarum.core.compat["common/helpers/avatar"];var it=t.n(st);const at=flarum.core.compat["common/helpers/highlight"];var ut=t.n(at);const ct=flarum.core.compat["common/utils/KeyboardNavigatable"];var mt=t.n(ct);const ft=flarum.core.compat["common/utils/throttleDebounce"],lt=flarum.core.compat["common/components/Badge"];var dt=t.n(lt);const pt=flarum.core.compat["common/models/Group"];var ht=t.n(pt),vt=function(t){function n(){for(var n,e=arguments.length,o=new Array(e),r=0;r<e;r++)o[r]=arguments[r];return(n=t.call.apply(t,[this].concat(o))||this).items=[],n.active=!1,n.index=0,n.keyWasJustPressed=!1,n}Q(n,t);var e=n.prototype;return e.view=function(){return m("ul",{className:"Dropdown-menu MentionsDropdown"},this.items.map((function(t){return m("li",null,t)})))},e.show=function(t,n){this.$().show().css({left:t+"px",top:n+"px"}),this.active=!0},e.hide=function(){this.$().hide(),this.active=!1},e.navigate=function(t){var n=this;this.keyWasJustPressed=!0,this.setIndex(this.index+t,!0),clearTimeout(this.keyWasJustPressedTimeout),this.keyWasJustPressedTimeout=setTimeout((function(){return n.keyWasJustPressed=!1}),500)},e.complete=function(){this.$("li").eq(this.index).find("button").click()},e.setIndex=function(t,n){if(!this.keyWasJustPressed||n){var e=this.$(),o=e.find("li"),r=t;r<0?r=o.length-1:r>=o.length&&(r=0),this.index=r;var s=o.removeClass("active").eq(r).addClass("active");if(n){var i,a=e.scrollTop(),u=e.offset().top,c=u+e.outerHeight(),m=s.offset().top,f=m+s.outerHeight();m<u?i=a-u+m-parseInt(e.css("padding-top"),10):f>c&&(i=a-c+f+parseInt(e.css("padding-bottom"),10)),void 0!==i&&e.stop(!0).animate({scrollTop:i},100)}}},n}(Y()),gt=(0,ft.throttle)(250,(function(t,n,e,o,r,s){var a=t.toLowerCase();n.includes(a)||(i().store.find("users",{filter:{q:t},page:{limit:5}}).then((function(t){t.forEach((function(t){o.has(t.id())||(o.add(t.id()),e.push(t))})),s()})),n.push(a))}));const yt=flarum.core.compat["forum/components/Notification"];var bt=t.n(yt),wt=function(t){function n(){return t.apply(this,arguments)||this}Q(n,t);var e=n.prototype;return e.icon=function(){return"fas fa-reply"},e.href=function(){var t=this.attrs.notification,n=t.subject(),e=t.content();return i().route.discussion(n.discussion(),e&&e.replyNumber)},e.content=function(){var t=this.attrs.notification.fromUser();return i().translator.trans("flarum-mentions.forum.notifications.post_mentioned_text",{user:t,count:1})},e.excerpt=function(){return(0,c.truncate)(this.attrs.notification.subject().contentPlain()||"",200)},n}(bt()),Pt=function(t){function n(){return t.apply(this,arguments)||this}Q(n,t);var e=n.prototype;return e.icon=function(){return"fas fa-at"},e.href=function(){var t=this.attrs.notification.subject();return i().route.discussion(t.discussion(),t.number())},e.content=function(){var t=this.attrs.notification.fromUser();return i().translator.trans("flarum-mentions.forum.notifications.user_mentioned_text",{user:t})},e.excerpt=function(){return(0,c.truncate)(this.attrs.notification.subject().contentPlain(),200)},n}(bt()),xt=function(t){function n(){return t.apply(this,arguments)||this}Q(n,t);var e=n.prototype;return e.icon=function(){return"fas fa-at"},e.href=function(){var t=this.attrs.notification.subject();return i().route.discussion(t.discussion(),t.number())},e.content=function(){var t=this.attrs.notification.fromUser();return i().translator.trans("flarum-mentions.forum.notifications.group_mentioned_text",{user:t})},e.excerpt=function(){return(0,c.truncate)(this.attrs.notification.subject().contentPlain(),200)},n}(bt());const Mt=flarum.core.compat["forum/components/UserPage"];var Ct=t.n(Mt);const $t=flarum.core.compat["common/components/LinkButton"];var _t=t.n($t);const Tt=flarum.core.compat["common/models/User"];var Bt=t.n(Tt);const At=flarum.core.compat["common/extenders"];var Nt=t.n(At);const kt=flarum.core.compat["forum/components/PostsUserPage"];var St=function(t){function n(){return t.apply(this,arguments)||this}return Q(n,t),n.prototype.loadResults=function(t){return i().store.find("posts",{filter:{type:"comment",mentioned:this.user.id()},page:{offset:t,limit:this.loadLimit},sort:"-createdAt"})},n}(t.n(kt)());const It=[(new(Nt().Routes)).add("user.mentions","/u/:username/mentions",St)];function Dt(t){var n;if(i().forum.attribute("allowUsernameMentionFormat")&&t.hasAttribute("username")?n=i().store.getBy("users","username",t.getAttribute("username")):t.hasAttribute("id")&&(n=i().store.getById("users",t.getAttribute("id"))),n)return t.setAttribute("id",n.id()),t.setAttribute("slug",n.slug()),t.setAttribute("displayname",W()(k()(n))),!0;t.invalidate()}function Ut(t){var n=i().store.getById("posts",t.getAttribute("id"));if(n)return t.setAttribute("discussionid",n.discussion().id()),t.setAttribute("number",n.number()),t.setAttribute("displayname",W()(k()(n.user()))),!0}function jt(t){var n,e;if(null!=(n=i().session)&&null!=(e=n.user)&&e.canMentionGroups()){var o=i().store.getById("groups",t.getAttribute("id"));if(o)return t.setAttribute("groupname",W()(o.namePlural())),t.setAttribute("icon",o.icon()),t.setAttribute("color",o.color()),!0}t.invalidate()}const Et={"mentions/components/MentionsUserPage":St,"mentions/components/PostMentionedNotification":wt,"mentions/components/UserMentionedNotification":Pt,"mentions/components/GroupMentionedNotification":xt,"mentions/fragments/AutocompleteDropdown":vt,"mentions/fragments/PostQuoteButton":K,"mentions/utils/getCleanDisplayName":R,"mentions/utils/getMentionText":q,"mentions/utils/reply":e,"mentions/utils/selectedText":V,"mentions/utils/textFormatter":o},Ht=flarum.core;i().initializers.add("flarum-mentions",(function(){var t,n;Bt().prototype.canMentionGroups=x().attribute("canMentionGroups"),function(){function t(){var t=this.attrs.post.contentHtml();if(t!==this.oldPostContentHtml&&!this.isEditing()){this.oldPostContentHtml=t;var n=this.attrs.post,e=this.$();this.$().on("click",".UserMention:not(.UserMention--deleted), .PostMention:not(.PostMention--deleted)",(function(t){m.route.set(this.getAttribute("href")),t.preventDefault()})),this.$(".PostMention:not(.PostMention--deleted)").each((function(){var t,o=$(this),r=o.data("id"),s=$('<ul class="Dropdown-menu PostMention-preview fade"/>');e.append(s);var i=function(){return $('.PostStream-item[data-id="'+r+'"]')},a=function(){var t=i(),a=!1;if(t.length){var u=t.offset().top,c=window.pageYOffset;u>c&&u+t.height()<c+$(window).height()&&(t.addClass("pulsate"),a=!0)}if(!a){var f=function(){var t=s.outerHeight(!0),n=0;o.offset().top-t<$(window).scrollTop()+$("#header").outerHeight()?n+=o.outerHeight(!0):n-=t,s.show().css("top",o.offset().top-e.offset().top+n).css("left",o.offsetParent().offset().left-e.offset().left).css("max-width",o.offsetParent().width())},l=function(t){var e=t.discussion();m.render(s[0],[e!==n.discussion()?m("li",null,m("span",{className:"PostMention-preview-discussion"},e.title())):"",m("li",null,y().component({post:t}))]),f()},d=app.store.getById("posts",r);d&&d.discussion()?l(d):(m.render(s[0],w().component()),app.store.find("posts",r).then(l),f()),setTimeout((function(){return s.off("transitionend").addClass("in")}))}},u=function(){i().removeClass("pulsate"),s.hasClass("in")&&s.removeClass("in").one("transitionend",(function(){return s.hide()}))};o.on("touchend",(function(t){t.cancelable&&t.preventDefault()})),o.add(s).hover((function(){clearTimeout(t),t=setTimeout(a,250)}),(function(){clearTimeout(t),i().removeClass("pulsate"),t=setTimeout(u,250)})).on("touchend",(function(t){a(),t.stopPropagation()})),$(document).on("touchend",u)}))}}(0,r.extend)(v().prototype,"oncreate",t),(0,r.extend)(v().prototype,"onupdate",t)}(),function(){function t(){this.$(".Post-mentionedBy-preview").removeClass("in").one("transitionend",(function(){$(this).hide()}))}C().prototype.mentionedBy=x().hasMany("mentionedBy"),(0,r.extend)(v().prototype,"oncreate",(function(){var n,e=this,o=this.attrs.post.mentionedBy();if(o&&o.length){var r=$('<ul class="Dropdown-menu Post-mentionedBy-preview fade"/>');this.$().append(r);var s=this.$(),i=this.$(".Post-mentionedBy"),a=function(){!r.hasClass("in")&&r.is(":visible")||(m.render(r[0],o.map((function(n){return m("li",{"data-number":n.number()},y().component({post:n,onclick:t.bind(e)}))}))),r.show().css("top",i.offset().top-s.offset().top+i.outerHeight(!0)).css("left",i.offsetParent().offset().left-s.offset().left).css("max-width",s.width()),setTimeout((function(){return r.off("transitionend").addClass("in")})))};i.add(r).hover((function(){clearTimeout(n),n=setTimeout(a,250)}),(function(){clearTimeout(n),n=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,r.extend)(v().prototype,"footerItems",(function(n){var e=this,o=this.attrs.post.mentionedBy();if(o&&o.length){var r=[],s=o.sort((function(t){return t.user()===i().session.user?-1:0})).filter((function(t){var n=t.user();if(-1===r.indexOf(n))return r.push(n),!0})),a=s.length>4,u=s.slice(0,a?3:4).map((function(n){var o=n.user();return m(T(),{href:i().route.post(n),onclick:t.bind(e),"data-number":n.number()},i().session.user===o?i().translator.trans("flarum-mentions.forum.post.you_text"):k()(o))}));if(a){var c=s.length-u.length;u.push(i().translator.trans("flarum-mentions.forum.post.others_text",{count:c}))}n.add("replies",m("div",{className:"Post-mentionedBy"},m("span",{className:"Post-mentionedBy-summary"},I()("fas fa-reply"),i().translator.trans("flarum-mentions.forum.post.mentioned_by"+(s[0].user()===i().session.user?"_self":"")+"_text",{count:u.length,users:A()(u)}))))}}))}(),(0,r.extend)(v().prototype,"actionItems",(function(t){var n=this.attrs.post;n.isHidden()||i().session.user&&!n.discussion().canReply()||t.add("reply",m(U(),{className:"Button Button--link",onclick:function(){return F(n)}},i().translator.trans("flarum-mentions.forum.post.reply_link")))})),(0,r.extend)(v().prototype,"oncreate",(function(){var t=this.attrs.post;if(!(t.isHidden()||i().session.user&&!t.discussion().canReply())){var n=this.$(".Post-body"),e=$('<div class="Post-quoteButtonContainer"></div>'),o=new K(t),r=function(t){setTimeout((function(){var r=V(n);if(r){o.content=r,m.render(e[0],o.render());var s=window.getSelection().getRangeAt(0).getClientRects(),i=s[0];if(t.clientY<i.bottom&&t.clientX-i.right<i.left-t.clientX)o.showStart(i.left,i.top);else{var a=s[s.length-1];o.showEnd(a.right,a.bottom)}}}),1)};this.$().after(e).on("mouseup",r),"ontouchstart"in window&&document.addEventListener("selectionchange",r,!1)}})),t=$('<div class="ComposerBody-mentionsDropdownContainer"></div>'),n=new vt,(0,r.extend)(tt().prototype,"oncreate",(function(){var e=this.$(".TextEditor-editor").wrap('<div class="ComposerBody-mentionsWrapper"></div>');this.navigator=new(mt()),this.navigator.when((function(){return n.active})).onUp((function(){return n.navigate(-1)})).onDown((function(){return n.navigate(1)})).onSelect(n.complete.bind(n)).onCancel(n.hide.bind(n)).bindTo(e),e.after(t)})),(0,r.extend)(tt().prototype,"buildEditorParams",(function(e){var o,r,s,a,u=this,f=[],l=Array.from(i().store.all("users")),d=new Set(l.map((function(t){return t.id()}))),p=Array.from(i().store.all("groups").filter((function(t){return t.id()!=ht().GUEST_ID&&t.id()!=ht().MEMBER_ID}))),h=function(t){u.attrs.composer.editor.replaceBeforeCursor(r-1,t+" "),n.hide()};e.inputListeners.push((function(){var e=u.attrs.composer.editor.getSelectionRange(),v=e[0];if(!(e[1]-v>0)){var g=u.attrs.composer.editor.getLastNChars(30);r=0;for(var y=g.length-1;y>=0;y--)if("@"===g.substr(y,1)&&(0==y||/\s/.test(g.substr(y-1,1)))){o=y+1,r=v-g.length+y+1;break}if(n.hide(),n.active=!1,r){s=g.substring(o).toLowerCase(),a=s.match(/^["|“]((?:(?!"#).)+)$/),s=a&&a[1]||s;var b=function(t,e,o,r){void 0===r&&(r="");var i=k()(t);return s&&(i.children=[ut()(i.text,s)],delete i.text),m("button",{className:"PostPreview "+r,onclick:function(){return h(e)},onmouseenter:function(){n.setIndex($(this).parent().index())}},m("span",{className:"PostPreview-content"},it()(t),i," ",o))},w=function(t){return[t.username(),t.displayName()].some((function(t){return t.toLowerCase().substr(0,s.length)===s}))},P=function(){var e,o,a=[];if(s&&(l.forEach((function(t){w(t)&&a.push(b(t,q(t),"","MentionsDropdown-user"))})),null!=(e=i().session)&&null!=(o=e.user)&&o.canMentionGroups()&&p.forEach((function(t){(function(t){return[t.nameSingular(),t.namePlural()].some((function(t){return t.toLowerCase().substr(0,s.length)===s}))})(t)&&a.push(function(t,e,o,r){void 0===r&&(r="");var i=t.namePlural().toLowerCase();return s&&(i=ut()(i,s)),m("button",{className:"PostPreview "+r,onclick:function(){return h(e)},onmouseenter:function(){n.setIndex($(this).parent().index())}},m("span",{className:"PostPreview-content"},m(dt(),{class:"Avatar Badge Badge--group--"+t.id()+" Badge-icon ",color:t.color(),type:"group",icon:t.icon()}),m("span",{className:"username"},i)))}(t,q(void 0,void 0,t),0,"MentionsDropdown-group"))}))),u.attrs.composer.bodyMatches(rt())||u.attrs.composer.bodyMatches(L())){var f=u.attrs.composer.body.attrs,d=f.post,v=d&&d.discussion()||f.discussion;v&&v.posts().filter((function(t){return t&&"comment"===t.contentType()&&(!d||t.number()<d.number())})).sort((function(t,n){return n.createdAt()-t.createdAt()})).filter((function(t){var n=t.user();return n&&w(n)})).splice(0,5).forEach((function(t){var n=t.user();a.push(b(n,q(n,t.id()),[i().translator.trans("flarum-mentions.forum.composer.reply_to_post_text",{number:t.number()})," — ",(0,c.truncate)(t.contentPlain(),200)],"MentionsDropdown-post"))}))}if(a.length){n.items=a,m.render(t[0],n.render()),n.show();var g=u.attrs.composer.editor.getCaretCoordinates(r),y=n.$().outerWidth(),P=n.$().outerHeight(),x=n.$().offsetParent(),M=g.left,C=g.top+15;C+P>x.height()&&(C=g.top-P-15),M+y>x.width()&&(M=x.width()-y),C=Math.max(-(x.offset().top-$(document).scrollTop()),C),M=Math.max(-x.offset().left,M),n.show(M,C)}else n.active=!1,n.hide()};n.active=!0,P(),n.setIndex(0),n.$().scrollTop(0),s.length>1&&i().forum.attribute("canSearchUsers")&&gt(s,f,l,d,n,P)}}}))})),(0,r.extend)(tt().prototype,"toolbarItems",(function(t){var n=this;t.add("mention",m(et(),{onclick:function(){return n.attrs.composer.editor.insertAtCursor(" @")},icon:"fas fa-at"},i().translator.trans("flarum-mentions.forum.composer.mention_tooltip")))})),i().notificationComponents.postMentioned=wt,i().notificationComponents.userMentioned=Pt,i().notificationComponents.groupMentioned=xt,(0,r.extend)(u().prototype,"notificationTypes",(function(t){t.add("postMentioned",{name:"postMentioned",icon:"fas fa-reply",label:i().translator.trans("flarum-mentions.forum.settings.notify_post_mentioned_label")}),t.add("userMentioned",{name:"userMentioned",icon:"fas fa-at",label:i().translator.trans("flarum-mentions.forum.settings.notify_user_mentioned_label")}),t.add("groupMentioned",{name:"groupMentioned",icon:"fas fa-at",label:i().translator.trans("flarum-mentions.forum.settings.notify_group_mentioned_label")})})),(0,r.extend)(Ct().prototype,"navItems",(function(t){var n=this.user;t.add("mentions",_t().component({href:i().route("user.mentions",{username:n.slug()}),name:"mentions",icon:"fas fa-at"},i().translator.trans("flarum-mentions.forum.user.mentions_link")),80)})),c.getPlainContent.removeSelectors.push("a.PostMention"),(0,r.extend)(p().prototype,"oncreate",(function(){this.$(".GroupMention--colored").each((function(){this.classList.add(l()(getComputedStyle(this).getPropertyValue("--group-color")))}))}))})),Object.assign(Ht.compat,Et)})(),module.exports=n})();
//# sourceMappingURL=forum.js.map