Files
laipower/wp-content/plugins/activitypub/build/dashboard-stats/index.js

4 lines
9.4 KiB
JavaScript

(()=>{"use strict";var e={771(e,t,s){const a=window.wp.element,n=window.wp.apiFetch;var i=s.n(n);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:n,canUseBlogActor:i}){if(!e)return null;const r=[];return n&&t?.followers&&r.push({key:"followers-user",label:(0,c.__)("New Followers","activitypub"),value:t.followers.current??0,change:t.followers.change??0}),i&&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 d=window.wp.compose,h={like:{slug:"luminous-vivid-amber",hex:"#fcb900"},repost:{slug:"vivid-green-cyan",hex:"#00d084"},comment:{slug:"vivid-red",hex:"#cf2e2e"}},m=[{slug:"vivid-purple",hex:"#9b51e0"},{slug:"luminous-vivid-orange",hex:"#ff6900"},{slug:"pale-pink",hex:"#f78da7"}];let v=0;function b(e){const t=h[e];if(t)return`var(--wp--preset--color--${t.slug}, ${t.hex})`;const s=m[v%m.length];return v++,`var(--wp--preset--color--${s.slug}, ${s.hex})`}function y({monthly:e,commentTypes:t}){const s=(0,d.useInstanceId)(y,"activitypub-chart");if(!e?.length)return null;v=0;const a=`areaGradient-${s}`,n="var(--wp--preset--color--vivid-cyan-blue, #0693e3)",i=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),h=e.map((e,t)=>({x:u[t],y:170-(e.engagement||0)/l*r,month:e})),m=h.map((e,t)=>0===t?`M ${e.x} ${e.y}`:`L ${e.x} ${e.y}`).join(" "),g=m+` L ${h[h.length-1].x} 170`+` L ${h[0].x} 170 Z`,x=t=>e.map((e,s)=>{const a=e[`${t}_count`]||0,n=u[s],i=170-a/l*r;return 0===s?`M ${n} ${i}`:`L ${n} ${i}`}).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:n}];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:n,stopOpacity:.3}),(0,p.jsx)("stop",{offset:"100%",stopColor:n,stopOpacity:.05})]})}),[0,.25,.5,.75,1].map(e=>(0,p.jsx)("line",{x1:40,y1:i+r*(1-e),x2:580,y2:i+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:m,fill:"none",stroke:n,strokeWidth:"2"}),h.map((e,t)=>(0,p.jsx)("circle",{cx:e.x,cy:e.y,r:"4",fill:n},t)),h.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:i+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,rel:"external noreferrer noopener",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:n,isResolving:d}=(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",[])}),[]),h=("actor"===t||t===f)&&s&&!!e?.id,m=("blog"===t||t===f)&&n,[v,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(d)return;const t=new AbortController,{signal:s}=t;N(!0);const a=window.activitypubDashboardStats,n=m&&a?.blogStatsUrl?i()({url:a.blogStatsUrl,signal:s}).catch(()=>null):Promise.resolve(null),r=h&&e?.id&&a?.userStatsUrl?i()({url:`${a.userStatsUrl}${e.id}`,signal:s}).catch(()=>null):Promise.resolve(null);return Promise.all([n,r]).then(([e,t])=>{s.aborted||(b(e??t),k(e),w(t))}).finally(()=>{s.aborted||N(!1)}),()=>t.abort()},[d,h,m,e?.id]),d||$?(0,p.jsx)("div",{className:"activitypub-stats-widget",children:(0,p.jsx)("div",{className:"activitypub-stats-loading",children:(0,p.jsx)(l.Spinner,{})})}):v?(0,p.jsxs)("div",{className:"activitypub-stats-widget",children:[(0,p.jsx)(u,{comparison:v.comparison,userComparison:_?.comparison??null,blogComparison:j?.comparison??null,commentTypes:v.comment_types,canUseUserActor:h,canUseBlogActor:m}),(0,p.jsx)(y,{monthly:v.monthly,commentTypes:v.comment_types}),(0,p.jsx)(g,{multiplicator:v.stats?.top_multiplicator}),(0,p.jsx)(x,{posts:v.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)(_,{}))}}}};const t={};function s(a){const n=t[a];if(void 0!==n)return n.exports;const i=t[a]={exports:{}};return e[a](i,i.exports,s),i.exports}s.m=e,(()=>{const e=[];s.O=(t,a,n,i)=>{if(a){i=i||0;for(var r=e.length;r>0&&e[r-1][2]>i;r--)e[r]=e[r-1];return void(e[r]=[a,n,i])}let o=1/0;for(r=0;r<e.length;r++){let[a,n,i]=e[r],c=!0;for(var l=0;l<a.length;l++)(!1&i||o>=i)&&Object.keys(s.O).every(e=>s.O[e](a[l]))?a.splice(l--,1):(c=!1,i<o&&(o=i));if(c){e.splice(r--,1);const s=n();void 0!==s&&(t=s)}}return t}})(),s.n=e=>{const t=e&&e.__esModule?()=>e.default:()=>e;return s.d(t,{a:t}),t},s.d=(e,t)=>{if(Array.isArray(t))for(var a=0;a<t.length;){var n=t[a++],i=t[a++];s.o(e,n)?0===i&&a++:0===i?Object.defineProperty(e,n,{enumerable:!0,value:t[a++]}):Object.defineProperty(e,n,{enumerable:!0,get:i})}else for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.o=(e,t)=>Object.hasOwn(e,t),(()=>{const e={306:0,598:0};s.O.j=t=>0===e[t];const t=(t,a)=>{let[n,i,r]=a;var o,l,c=0;if(n.some(t=>0!==e[t])){for(o in i)s.o(i,o)&&(s.m[o]=i[o]);if(r)var p=r(s)}for(t&&t(a);c<n.length;c++)l=n[c],s.o(e,l)&&e[l]&&e[l][0](),e[l]=0;return s.O(p)},a=globalThis.webpackChunkwordpress_activitypub||=[];a.forEach(t.bind(null,0)),a.push=t.bind(null,a.push.bind(a))})();let a=s.O(void 0,[598],()=>s(771));a=s.O(a)})();