4 lines
9.2 KiB
JavaScript
4 lines
9.2 KiB
JavaScript
(()=>{"use strict";var e,t={5771(e,t,s){const a=window.wp.element,i=window.wp.apiFetch;var n=s.n(i);const r=window.wp.data,o=window.wp.coreData,l=window.wp.components,c=window.wp.i18n,p=window.ReactJSXRuntime;function u({comparison:e,userComparison:t,blogComparison:s,commentTypes:a,canUseUserActor:i,canUseBlogActor:n}){if(!e)return null;const r=[];return i&&t?.followers&&r.push({key:"followers-user",label:(0,c.__)("New Followers","activitypub"),value:t.followers.current??0,change:t.followers.change??0}),n&&s?.followers&&r.push({key:"followers-blog",label:(0,c.__)("New Followers (Blog)","activitypub"),value:s.followers.current??0,change:s.followers.change??0}),r.push({key:"posts",label:(0,c.__)("Posts","activitypub"),value:e.posts?.current??0,change:e.posts?.change??0}),a&&Object.entries(a).forEach(([t,s])=>{const a=e[t];a&&"object"==typeof a&&"current"in a&&r.push({key:t,label:s.label,value:a.current??0,change:a.change??0})}),(0,p.jsxs)("div",{className:"activitypub-stats-highlights main",children:[(0,p.jsx)("h3",{children:(0,c.__)("Monthly Comparison","activitypub")}),(0,p.jsx)("ul",{children:r.map(e=>{const t=function(e){switch(e){case"followers":case"followers-user":return"users.php?page=activitypub-followers-list";case"followers-blog":return"options-general.php?page=activitypub&tab=followers";case"posts":return"edit.php";default:return`edit-comments.php?comment_type=${e}`}}(e.key),s=(0,p.jsxs)(p.Fragment,{children:[e.value.toLocaleString()," ",e.label]});return(0,p.jsxs)("li",{className:`activitypub-${e.key.replace("-user","").replace("-blog","")}-count`,children:[t?(0,p.jsx)("a",{href:t,children:s}):(0,p.jsx)("span",{children:s}),0!==e.change&&" ",0!==e.change&&(0,p.jsxs)("span",{className:"stat-change "+(e.change>0?"positive":"negative"),children:["(",e.change>0?"+":"",e.change.toLocaleString(),")"]})]},e.key)})})]})}const h=window.wp.compose,d={like:{slug:"luminous-vivid-amber",hex:"#fcb900"},repost:{slug:"vivid-green-cyan",hex:"#00d084"},comment:{slug:"vivid-red",hex:"#cf2e2e"}},v=[{slug:"vivid-purple",hex:"#9b51e0"},{slug:"luminous-vivid-orange",hex:"#ff6900"},{slug:"pale-pink",hex:"#f78da7"}];let m=0;function b(e){const t=d[e];if(t)return`var(--wp--preset--color--${t.slug}, ${t.hex})`;const s=v[m%v.length];return m++,`var(--wp--preset--color--${s.slug}, ${s.hex})`}function y({monthly:e,commentTypes:t}){const s=(0,h.useInstanceId)(y,"activitypub-chart");if(!e?.length)return null;m=0;const a=`areaGradient-${s}`,i="var(--wp--preset--color--vivid-cyan-blue, #0693e3)",n=20,r=150,o=t?Object.keys(t):[],l=Math.max(...e.map(e=>e.engagement||0),...o.flatMap(t=>e.map(e=>e[`${t}_count`]||0)),1),u=e.map((t,s)=>40+s/(e.length-1||1)*540),d=e.map((e,t)=>({x:u[t],y:170-(e.engagement||0)/l*r,month:e})),v=d.map((e,t)=>0===t?`M ${e.x} ${e.y}`:`L ${e.x} ${e.y}`).join(" "),g=v+` L ${d[d.length-1].x} 170`+` L ${d[0].x} 170 Z`,x=t=>e.map((e,s)=>{const a=e[`${t}_count`]||0,i=u[s],n=170-a/l*r;return 0===s?`M ${i} ${n}`:`L ${i} ${n}`}).join(" "),f=[(0,c.__)("Jan","activitypub"),(0,c.__)("Feb","activitypub"),(0,c.__)("Mar","activitypub"),(0,c.__)("Apr","activitypub"),(0,c.__)("May","activitypub"),(0,c.__)("Jun","activitypub"),(0,c.__)("Jul","activitypub"),(0,c.__)("Aug","activitypub"),(0,c.__)("Sep","activitypub"),(0,c.__)("Oct","activitypub"),(0,c.__)("Nov","activitypub"),(0,c.__)("Dec","activitypub")],_=[{key:"engagement",label:(0,c.__)("Total Engagement","activitypub"),color:i}];return t&&Object.entries(t).forEach(([e,t])=>{_.push({key:e,label:t.label,color:b(e)})}),(0,p.jsxs)("div",{className:"activitypub-stats-chart",children:[(0,p.jsx)("h3",{children:(0,c.__)("Engagement Over Time","activitypub")}),(0,p.jsxs)("div",{className:"activitypub-chart-container",children:[(0,p.jsxs)("svg",{viewBox:"0 0 600 200",className:"activitypub-line-chart",role:"img","aria-labelledby":`${s}-title`,children:[(0,p.jsx)("title",{id:`${s}-title`,children:(0,c.__)("Line chart showing engagement trends over the past 12 months","activitypub")}),(0,p.jsx)("defs",{children:(0,p.jsxs)("linearGradient",{id:a,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:[(0,p.jsx)("stop",{offset:"0%",stopColor:i,stopOpacity:.3}),(0,p.jsx)("stop",{offset:"100%",stopColor:i,stopOpacity:.05})]})}),[0,.25,.5,.75,1].map(e=>(0,p.jsx)("line",{x1:40,y1:n+r*(1-e),x2:580,y2:n+r*(1-e),stroke:"#e0e0e0",strokeWidth:"1"},e)),(0,p.jsx)("path",{d:g,fill:`url(#${a})`}),o.map(e=>(0,p.jsx)("path",{d:x(e),fill:"none",stroke:b(e),strokeWidth:"2",strokeOpacity:"0.7"},e)),(0,p.jsx)("path",{d:v,fill:"none",stroke:i,strokeWidth:"2"}),d.map((e,t)=>(0,p.jsx)("circle",{cx:e.x,cy:e.y,r:"4",fill:i},t)),d.map((e,t)=>(0,p.jsx)("text",{x:e.x,y:195,textAnchor:"middle",className:"chart-label",children:f[e.month.month-1]},t)),[0,.5,1].map(e=>(0,p.jsx)("text",{x:35,y:n+r*(1-e)+4,textAnchor:"end",className:"chart-label",children:Math.round(l*e)},e))]}),(0,p.jsx)("div",{className:"activitypub-chart-legend",children:_.map(e=>(0,p.jsxs)("div",{className:"activitypub-legend-item",children:[(0,p.jsx)("span",{className:"legend-color",style:{backgroundColor:e.color}}),e.label]},e.key))})]})]})}function g({multiplicator:e}){return e?.name?(0,p.jsxs)("div",{className:"activitypub-stats-multiplicator",children:[(0,p.jsx)("h3",{children:(0,c.__)("Top Supporter","activitypub")}),(0,p.jsxs)("p",{children:[(0,p.jsx)(l.ExternalLink,{href:e.url,children:e.name})," ",(0,c.sprintf)(/* translators: %s: number of boosts */ /* translators: %s: number of boosts */
|
|
(0,c._n)("(%s boost)","(%s boosts)",e.count,"activitypub"),e.count.toLocaleString())]})]}):null}function x({posts:e}){return e?.length?(0,p.jsxs)("div",{className:"activitypub-stats-top-posts",children:[(0,p.jsx)("h3",{children:(0,c.__)("Top Posts","activitypub")}),(0,p.jsx)("ul",{children:e.map(e=>{const t=e.title||(0,c.__)("(no title)","activitypub");return(0,p.jsxs)("li",{children:[(0,p.jsx)("a",{href:e.url,"aria-label":/* translators: %s: post title */ /* translators: %s: post title */
|
|
(0,c.sprintf)((0,c.__)("View %s","activitypub"),t),children:t}),(0,p.jsx)("span",{className:"engagement-count",children:(0,c.sprintf)(/* translators: %s: engagement count */ /* translators: %s: engagement count */
|
|
(0,c.__)("%s engagements","activitypub"),e.engagement_count.toLocaleString())})]},e.post_id)})})]}):null}const f="actor_blog";function _(){const{currentUser:e,actorMode:t,hasUserCap:s,hasBlogCap:i,isResolving:h}=(0,r.useSelect)(e=>({currentUser:e(o.store).getCurrentUser(),actorMode:e(o.store).getEntityRecord("root","site")?.activitypub_actor_mode??f,hasUserCap:e(o.store).canUser("create",{kind:"postType",name:"ap_extrafield"}),hasBlogCap:e(o.store).canUser("create",{kind:"postType",name:"ap_extrafield_blog"}),isResolving:e(o.store).isResolving("getCurrentUser",[])}),[]),d=("actor"===t||t===f)&&s&&!!e?.id,v=("blog"===t||t===f)&&i,[m,b]=(0,a.useState)(null),[_,w]=(0,a.useState)(null),[j,k]=(0,a.useState)(null),[$,N]=(0,a.useState)(!0);return(0,a.useEffect)(()=>{if(h)return;const t=new AbortController,{signal:s}=t;N(!0);const a=window.activitypubDashboardStats,i=v&&a?.blogStatsUrl?n()({url:a.blogStatsUrl,signal:s}).catch(()=>null):Promise.resolve(null),r=d&&e?.id&&a?.userStatsUrl?n()({url:`${a.userStatsUrl}${e.id}`,signal:s}).catch(()=>null):Promise.resolve(null);return Promise.all([i,r]).then(([e,t])=>{s.aborted||(b(e??t),k(e),w(t))}).finally(()=>{s.aborted||N(!1)}),()=>t.abort()},[h,d,v,e?.id]),h||$?(0,p.jsx)("div",{className:"activitypub-stats-widget",children:(0,p.jsx)("div",{className:"activitypub-stats-loading",children:(0,p.jsx)(l.Spinner,{})})}):m?(0,p.jsxs)("div",{className:"activitypub-stats-widget",children:[(0,p.jsx)(u,{comparison:m.comparison,userComparison:_?.comparison??null,blogComparison:j?.comparison??null,commentTypes:m.comment_types,canUseUserActor:d,canUseBlogActor:v}),(0,p.jsx)(y,{monthly:m.monthly,commentTypes:m.comment_types}),(0,p.jsx)(g,{multiplicator:m.stats?.top_multiplicator}),(0,p.jsx)(x,{posts:m.stats?.top_posts})]}):(0,p.jsx)("div",{className:"activitypub-stats-widget",children:(0,p.jsx)("p",{className:"activitypub-stats-empty",children:(0,c.__)("No statistics available yet.","activitypub")})})}window.activitypub=window.activitypub||{},window.activitypub.dashboardStats={initialize:function(e){const t=document.getElementById(e);t&&(0,a.createRoot)(t).render((0,p.jsx)(_,{}))}}}},s={};function a(e){var i=s[e];if(void 0!==i)return i.exports;var n=s[e]={exports:{}};return t[e](n,n.exports,a),n.exports}a.m=t,e=[],a.O=(t,s,i,n)=>{if(!s){var r=1/0;for(p=0;p<e.length;p++){for(var[s,i,n]=e[p],o=!0,l=0;l<s.length;l++)(!1&n||r>=n)&&Object.keys(a.O).every(e=>a.O[e](s[l]))?s.splice(l--,1):(o=!1,n<r&&(r=n));if(o){e.splice(p--,1);var c=i();void 0!==c&&(t=c)}}return t}n=n||0;for(var p=e.length;p>0&&e[p-1][2]>n;p--)e[p]=e[p-1];e[p]=[s,i,n]},a.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var s in t)a.o(t,s)&&!a.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={306:0,598:0};a.O.j=t=>0===e[t];var t=(t,s)=>{var i,n,[r,o,l]=s,c=0;if(r.some(t=>0!==e[t])){for(i in o)a.o(o,i)&&(a.m[i]=o[i]);if(l)var p=l(a)}for(t&&t(s);c<r.length;c++)n=r[c],a.o(e,n)&&e[n]&&e[n][0](),e[n]=0;return a.O(p)},s=globalThis.webpackChunkwordpress_activitypub=globalThis.webpackChunkwordpress_activitypub||[];s.forEach(t.bind(null,0)),s.push=t.bind(null,s.push.bind(s))})();var i=a.O(void 0,[598],()=>a(5771));i=a.O(i)})(); |