mirror of
https://github.com/flarum/framework.git
synced 2025-02-02 23:11:44 +08:00
ab56aefeaa
Includes transpiled JS/TS, and Typescript declaration files (typings). [skip ci]
2 lines
20 KiB
JavaScript
Generated
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,{filterGroupMentions:()=>Nt,filterPostMentions:()=>kt,filterUserMentions:()=>At});var e={};t.r(e),t.d(e,{default:()=>W,insertMention:()=>L});var o={};t.r(o),t.d(o,{filterGroupMentions:()=>Nt,filterPostMentions:()=>kt,filterUserMentions:()=>At});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["forum/components/CommentPost"];var l=t.n(f);const d=flarum.core.compat["forum/components/PostPreview"];var p=t.n(d);const h=flarum.core.compat["common/components/LoadingIndicator"];var v=t.n(h);const g=flarum.core.compat["common/Model"];var y=t.n(g);const b=flarum.core.compat["common/models/Post"];var w=t.n(b);const P=flarum.core.compat["common/components/Link"];var x=t.n(P);const M=flarum.core.compat["common/helpers/punctuateSeries"];var C=t.n(M);const _=flarum.core.compat["common/helpers/username"];var T=t.n(_);const B=flarum.core.compat["common/helpers/icon"];var A=t.n(B);const k=flarum.core.compat["common/components/Button"];var N=t.n(k);const S=flarum.core.compat["forum/utils/DiscussionControls"];var D=t.n(S);const I=flarum.core.compat["forum/components/EditPostComposer"];var U=t.n(I);const j=flarum.core.compat["common/utils/extractText"];var E=t.n(j),H=function(){return E()(i().translator.trans("core.lib.username.deleted_text"))};function O(t,n){return void 0===n&&(n=!0),t?((n?t.displayName():t.username())||H()).replace(/"#[a-z]{0,3}[0-9]+/,"_"):H().replace(/"#[a-z]{0,3}[0-9]+/,"_")}function G(t,n,e){if(void 0!==t&&void 0===n)return i().forum.attribute("allowUsernameMentionFormat")?"@"+O(t,!1):'@"'+O(t)+'"#'+t.id();if(void 0!==t&&void 0!==n)return'@"'+O(t)+'"#p'+n;if(void 0!==e)return'@"'+e.namePlural()+'"#g'+e.id();throw"No parameters were passed"}function L(t,n,e){return new Promise((function(o){var r=G(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 W(t,n){return i().composer.bodyMatches(U())&&i().composer.body.attrs.post.discussion()===t.discussion()?L(t,i().composer,n):D().replyAction.call(t.discussion()).then((function(e){return L(t,e,n)}))}function R(t,n){return R=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},R(t,n)}function q(t,n){t.prototype=Object.create(n.prototype),t.prototype.constructor=t,R(t,n)}const J=flarum.core.compat["common/Fragment"];var F=t.n(J),z=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(){W(t.post,t.content)}},A()("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}(F());function Q(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 X=flarum.core.compat["common/components/TextEditor"];var Y=t.n(X);const K=flarum.core.compat["common/components/TextEditorButton"];var V=t.n(K);const Z=flarum.core.compat["forum/components/ReplyComposer"];var tt=t.n(Z);const nt=flarum.core.compat["common/helpers/avatar"];var et=t.n(nt);const ot=flarum.core.compat["common/helpers/highlight"];var rt=t.n(ot);const st=flarum.core.compat["forum/utils/KeyboardNavigatable"];var it=t.n(st);const at=flarum.core.compat["common/utils/throttleDebounce"],ut=flarum.core.compat["common/components/Badge"];var ct=t.n(ut);const mt=flarum.core.compat["common/models/Group"];var ft=t.n(mt),lt=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}(F()),dt=(0,at.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 pt=flarum.core.compat["forum/components/Notification"];var ht=t.n(pt),vt=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}(ht()),gt=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}(ht()),yt=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}(ht());const bt=flarum.core.compat["forum/components/UserPage"];var wt=t.n(bt);const Pt=flarum.core.compat["common/components/LinkButton"];var xt=t.n(Pt);const Mt=flarum.core.compat["forum/components/PostsUserPage"];var $t=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(Mt)());const Ct=flarum.core.compat["common/models/User"];var _t=t.n(Ct);const Tt=flarum.core.compat["common/utils/isDark"];var Bt=t.n(Tt);function At(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",E()(T()(n))),!0;t.invalidate()}function kt(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",E()(T()(n.user()))),!0}function Nt(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",E()(o.namePlural())),t.setAttribute("icon",o.icon()),t.setAttribute("color",o.color()),t.setAttribute("class",Bt()(o.color())?"GroupMention--light":"GroupMention--dark"),!0}t.invalidate()}const St={"mentions/components/MentionsUserPage":$t,"mentions/components/PostMentionedNotification":vt,"mentions/components/UserMentionedNotification":gt,"mentions/components/GroupMentionedNotification":yt,"mentions/fragments/AutocompleteDropdown":lt,"mentions/fragments/PostQuoteButton":z,"mentions/utils/getCleanDisplayName":O,"mentions/utils/getMentionText":G,"mentions/utils/reply":e,"mentions/utils/selectedText":Q,"mentions/utils/textFormatter":o},Dt=flarum.core;i().initializers.add("flarum-mentions",(function(){var t,n;_t().prototype.canMentionGroups=y().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,p().component({post:t}))]),f()},d=app.store.getById("posts",r);d&&d.discussion()?l(d):(m.render(s[0],v().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)(l().prototype,"oncreate",t),(0,r.extend)(l().prototype,"onupdate",t)}(),function(){function t(){this.$(".Post-mentionedBy-preview").removeClass("in").one("transitionend",(function(){$(this).hide()}))}w().prototype.mentionedBy=y().hasMany("mentionedBy"),(0,r.extend)(l().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()},p().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)(l().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(x(),{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"):T()(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"},A()("fas fa-reply"),i().translator.trans("flarum-mentions.forum.post.mentioned_by"+(s[0].user()===i().session.user?"_self":"")+"_text",{count:u.length,users:C()(u)}))))}}))}(),(0,r.extend)(l().prototype,"actionItems",(function(t){var n=this.attrs.post;n.isHidden()||i().session.user&&!n.discussion().canReply()||t.add("reply",m(N(),{className:"Button Button--link",onclick:function(){return W(n)}},i().translator.trans("flarum-mentions.forum.post.reply_link")))})),(0,r.extend)(l().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 z(t),r=function(t){setTimeout((function(){var r=Q(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 lt,(0,r.extend)(Y().prototype,"oncreate",(function(){var e=this.$(".TextEditor-editor").wrap('<div class="ComposerBody-mentionsWrapper"></div>');this.navigator=new(it()),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)(Y().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()!=ft().GUEST_ID&&t.id()!=ft().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=T()(t);return s&&(i.children=[rt()(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"},et()(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,G(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=rt()(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(ct(),{class:"Avatar Badge Badge--group--"+t.id()+" Badge-icon ",color:t.color(),type:"group",icon:t.icon()}),m("span",{className:"username"},i)))}(t,G(void 0,void 0,t),0,"MentionsDropdown-group"))}))),u.attrs.composer.bodyMatches(tt())||u.attrs.composer.bodyMatches(U())){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,G(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")&&dt(s,f,l,d,n,P)}}}))})),(0,r.extend)(Y().prototype,"toolbarItems",(function(t){var n=this;t.add("mention",m(V(),{onclick:function(){return n.attrs.composer.editor.insertAtCursor(" @")},icon:"fas fa-at"},i().translator.trans("flarum-mentions.forum.composer.mention_tooltip")))})),i().notificationComponents.postMentioned=vt,i().notificationComponents.userMentioned=gt,i().notificationComponents.groupMentioned=yt,(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")})})),i().routes["user.mentions"]={path:"/u/:username/mentions",component:$t},(0,r.extend)(wt().prototype,"navItems",(function(t){var n=this.user;t.add("mentions",xt().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")})),Object.assign(Dt.compat,St)})(),module.exports=n})();
|
|
//# sourceMappingURL=forum.js.map
|