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

3 lines
12 KiB
JavaScript

(()=>{"use strict";var e={736(e,t,i){const a=window.wp.blocks,r=window.wp.primitives,s=window.ReactJSXRuntime;var n=(0,s.jsx)(r.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)(r.Path,{fillRule:"evenodd",d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z"})});const o=[{attributes:{title:{type:"string",default:"Fediverse Followers"},selectedUser:{type:"string",default:"blog"},per_page:{type:"number",default:10},order:{type:"string",default:"desc",enum:["asc","desc"]}},supports:{html:!1},isEligible:({title:e})=>!!e,migrate:({title:e,...t})=>[t,[(0,a.createBlock)("core/heading",{content:e,level:3})]]}],l=window.wp.components,c=window.wp.blockEditor,u=window.wp.coreData,p=window.wp.data,d=window.wp.element,h=window.wp.i18n,v=window.wp.apiFetch;var b=i.n(v);function g(){return window._activityPubOptions||{}}function f({name:e}){const{enabled:t}=g(),i=t?.blog?"":(0,h.__)("It will be empty in other non-author contexts.","activitypub"),a=(0,h.sprintf)(/* translators: %1$s: block name, %2$s: extra information for non-author context */ /* translators: %1$s: block name, %2$s: extra information for non-author context */
(0,h.__)("This <strong>%1$s</strong> block will adapt to the page it is on, displaying the user profile associated with a post author (in a loop) or a user archive. %2$s","activitypub"),e,i).trim();return(0,s.jsx)(l.Card,{children:(0,s.jsx)(l.CardBody,{children:(0,d.createInterpolateElement)(a,{strong:(0,s.jsx)("strong",{})})})})}const y=window.wp.url;function w({name:e,icon:t,url:i,webfinger:a}){const r=`@${a}`,{defaultAvatarUrl:n,showAvatars:o}=g(),l=t?.url||n;return(0,s.jsxs)("a",{className:"activitypub-actor-link",href:i,title:r,onClick:e=>e.preventDefault(),children:[o&&(0,s.jsx)("img",{width:"48",height:"48",src:l,className:"activitypub-actor-avatar",alt:e,onError:e=>{e.target.src=n}}),(0,s.jsxs)("div",{className:"activitypub-actor-info",children:[(0,s.jsx)("span",{className:"activitypub-actor-name",children:e}),(0,s.jsx)("span",{className:"activitypub-actor-handle",children:r})]}),(0,s.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",className:"external-link-icon","aria-hidden":"true",focusable:"false",fill:"currentColor",children:(0,s.jsx)("path",{d:"M18.2 17c0 .7-.6 1.2-1.2 1.2H7c-.7 0-1.2-.6-1.2-1.2V7c0-.7.6-1.2 1.2-1.2h3.2V4.2H7C5.5 4.2 4.2 5.5 4.2 7v10c0 1.5 1.2 2.8 2.8 2.8h10c1.5 0 2.8-1.2 2.8-2.8v-3.6h-1.5V17zM14.9 3v1.5h3.7l-6.4 6.4 1.1 1.1 6.4-6.4v3.7h1.5V3h-6.3z"})})]})}function m({page:e,pages:t,setPage:i,navLabel:a=(0,h.__)("Navigation","activitypub")}){if(t<=1)return null;const r=e<=1,n=e>=t;return(0,s.jsxs)("nav",{className:"activitypub-actor-list-pagination",role:"navigation",children:[(0,s.jsx)("h1",{className:"screen-reader-text",children:a}),(0,s.jsx)("a",{role:"button",tabIndex:0,className:"pagination-previous","aria-disabled":r,"aria-label":(0,h.__)("Previous page","activitypub"),onClick:()=>{r||i(e-1)},onKeyDown:t=>{r||"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),i(e-1))},children:(0,h.__)("Previous","activitypub")}),(0,s.jsx)("div",{className:"pagination-info",children:`${e} / ${t}`}),(0,s.jsx)("a",{role:"button",tabIndex:0,className:"pagination-next","aria-disabled":n,"aria-label":(0,h.__)("Next page","activitypub"),onClick:()=>{n||i(e+1)},onKeyDown:t=>{n||"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),i(e+1))},children:(0,h.__)("Next","activitypub")})]})}function _({selectedUser:e,perPage:t,order:i,endpoint:a="followers",page:r,setPage:n,initialData:o=!1,emptyMessage:l=(0,h.__)("No results found.","activitypub"),navLabel:c=(0,h.__)("Navigation","activitypub")}){const{namespace:u}=g(),p="blog"===e?0:e,[v,f]=(0,d.useState)([]),[_,x]=(0,d.useState)(0),[j,k]=(0,d.useState)(1),N=r||j,S=n||k,U=(0,d.useCallback)((e,i)=>{f(e),x(Math.ceil(i/t))},[t]);return(0,d.useEffect)(()=>{if(o&&1===N)return U(o.items,o.total);const e=(0,y.addQueryArgs)(`/${u}/actors/${p}/${a}`,{per_page:t,order:i,page:N,context:"full"});b()({path:e}).then(({orderedItems:e=[],totalItems:t=0})=>U(e,t)).catch(()=>U([],0))},[u,p,t,i,N,a,o,U]),(0,s.jsxs)("div",{className:"activitypub-actor-list-container",children:[v.length?(0,s.jsx)("ul",{className:"activitypub-actor-list",children:v.map(e=>(0,s.jsx)("li",{className:"activitypub-actor-item",children:(0,s.jsx)(w,{...e})},e.url))}):(0,s.jsx)("p",{className:"activitypub-actor-list-placeholder",children:l}),(0,s.jsx)(m,{page:N,pages:_,setPage:S,navLabel:c})]})}function x(e){return!!e&&Object.entries(e).some(([e,t])=>e.endsWith("activitypub_hide_social_graph")&&t)}const j=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","name":"activitypub/followers","apiVersion":3,"version":"9.0.1","title":"Fediverse Followers","category":"widgets","description":"Display your followers from the Fediverse on your website.","textdomain":"activitypub","icon":"groups","keywords":["fediverse","activitypub","followers","mastodon"],"supports":{"html":false,"interactivity":true},"attributes":{"selectedUser":{"type":"string","default":"blog"},"per_page":{"type":"number","default":10},"order":{"type":"string","default":"desc","enum":["asc","desc"]}},"usesContext":["postType","postId"],"styles":[{"name":"default","label":"Default","isDefault":true},{"name":"card","label":"Card"},{"name":"compact","label":"Compact"}],"editorScript":"file:./index.js","editorStyle":"file:./index.css","viewScriptModule":"file:./view.js","viewScript":"wp-api-fetch","style":["file:./style-index.css"],"render":"file:./render.php"}');(0,a.registerBlockType)(j,{deprecated:o,edit:function({attributes:e,setAttributes:t,context:{postType:i,postId:a}}){const{className:r="",order:n,per_page:o,selectedUser:v}=e,y=(0,c.useBlockProps)(),[w,m]=(0,d.useState)(1),j=[{label:(0,h.__)("New to old","activitypub"),value:"desc"},{label:(0,h.__)("Old to new","activitypub"),value:"asc"}],k=function({withInherit:e=!1}){const{enabled:t,namespace:i}=g(),[a,r]=(0,d.useState)(!1),{fetchedUsers:s,isLoadingUsers:n}=(0,p.useSelect)(e=>{const{getUsers:i,getIsResolving:a}=e("core");return{fetchedUsers:t?.users?i({capabilities:"activitypub"}):null,isLoadingUsers:!!t?.users&&a("getUsers",[{capabilities:"activitypub"}])}},[t?.users]),o=(0,p.useSelect)(e=>s||n?null:e("core").getCurrentUser(),[s,n]);(0,d.useEffect)(()=>{!s&&!n&&o&&i&&b()({path:`/${i}/actors/${o.id}`,method:"HEAD",headers:{Accept:"application/activity+json"},parse:!1}).then(()=>r(!0)).catch(()=>r(!1))},[s,n,o,i]);const l=(0,d.useMemo)(()=>s||(o&&a?[{id:o.id,name:o.name}]:[]),[s,o,a]);return(0,d.useMemo)(()=>{if(!l.length)return[];const i=[];return t?.blog&&s&&i.push({label:(0,h.__)("Blog","activitypub"),value:"blog"}),e&&t?.users&&s&&i.push({label:(0,h.__)("Dynamic User","activitypub"),value:"inherit"}),l.reduce((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e),i)},[l,t?.blog,t?.users,s,e])}({withInherit:!0}),N=e=>i=>{m(1),t({[e]:i})},{blogSocialGraphHidden:S,currentUser:U,usersWithMeta:C,siteUrl:M,canManageOptions:O}=(0,p.useSelect)(e=>{const{getCurrentUser:t,getUsers:i,getEntityRecord:a,canUser:r}=e(u.store),s=a("root","site"),n=a("root","__unstableBase");return{blogSocialGraphHidden:!!s?.activitypub_hide_social_graph,currentUser:t(),usersWithMeta:i({capabilities:"activitypub",context:"edit"}),siteUrl:n?.home,canManageOptions:r("update",{kind:"root",name:"site"})}},[]),P=(0,p.useSelect)(e=>{const{getEditedEntityRecord:t}=e(u.store),r=t("postType",i,a)?.author;return r??null},[i,a]),D=(0,d.useMemo)(()=>k.length&&C?k.filter(({value:e})=>{if("inherit"===e)return!0;if("blog"===e)return!S;const t=C?.find(t=>String(t.id)===e);return!x(t?.meta)}):[],[k,S,C]),E=(0,d.useMemo)(()=>{if(!C)return!1;if("blog"===v)return S;if("inherit"===v){if(!P)return!1;const e=C.find(e=>e.id===P);return!!e&&x(e.meta)}return!1},[v,P,C,S]),F=(0,d.useMemo)(()=>!(!E||!U)&&("blog"===v?O:U.id===P),[E,U,v,P,O]),I=(0,d.useMemo)(()=>F&&M?"blog"===v?M+"/wp-admin/options-general.php?page=activitypub&tab=blog-profile":M+"/wp-admin/profile.php#activitypub":null,[F,M,v]);(0,d.useEffect)(()=>{D.length&&("blog"===v||"inherit"===v||D.find(({value:e})=>e===v)||t({selectedUser:D[0].value}))},[v,D,t]);const B=[["core/heading",{level:3,placeholder:(0,h.__)("Fediverse Followers","activitypub"),content:(0,h.__)("Fediverse Followers","activitypub")}]];return(0,s.jsxs)("div",{...y,children:[(0,s.jsx)(c.InspectorControls,{children:(0,s.jsxs)(l.PanelBody,{title:(0,h.__)("Followers Options","activitypub"),children:[D.length>1&&(0,s.jsx)(l.SelectControl,{label:(0,h.__)("Select User","activitypub"),value:v,options:D,onChange:N("selectedUser"),__next40pxDefaultSize:!0}),(0,s.jsx)(l.SelectControl,{label:(0,h.__)("Sort","activitypub"),value:n,options:j,onChange:N("order"),__next40pxDefaultSize:!0}),(0,s.jsx)(l.RangeControl,{label:(0,h.__)("Number of Followers","activitypub"),value:o,onChange:N("per_page"),min:1,max:10,__next40pxDefaultSize:!0})]})},"setting"),(0,s.jsxs)("div",{className:"wp-block-activitypub-followers "+r,children:[(0,s.jsx)(c.InnerBlocks,{template:B,allowedBlocks:["core/heading"],templateLock:"all",renderAppender:!1}),E&&(0,s.jsx)(l.Notice,{status:"warning",isDismissible:!1,children:I?(0,d.createInterpolateElement)(/* translators: <a> is a link to the profile settings page. */ /* translators: <a> is a link to the profile settings page. */
(0,h.__)("The selected user has their social graph hidden. This block will not display followers on the frontend. <a>Edit privacy settings</a>","activitypub"),{a:(0,s.jsx)("a",{href:I,target:"_blank",rel:"noopener noreferrer"})}):(0,h.__)("The selected user has their social graph hidden. This block will not display followers on the frontend.","activitypub")}),!E&&"inherit"===v&&P&&(0,s.jsx)(_,{selectedUser:P,perPage:o,order:n,endpoint:"followers",page:w,setPage:m,emptyMessage:(0,h.__)("No followers found.","activitypub"),navLabel:(0,h.__)("Follower navigation","activitypub")}),!E&&"inherit"===v&&!P&&(0,s.jsx)(f,{name:(0,h.__)("Followers","activitypub")}),!E&&"inherit"!==v&&(0,s.jsx)(_,{selectedUser:v,perPage:o,order:n,endpoint:"followers",page:w,setPage:m,emptyMessage:(0,h.__)("No followers found.","activitypub"),navLabel:(0,h.__)("Follower navigation","activitypub")})]})]})},save:function(){const e=c.useBlockProps.save(),t=c.useInnerBlocksProps.save(e);return(0,s.jsx)("div",{...t})},icon:n})}};const t={};function i(a){const r=t[a];if(void 0!==r)return r.exports;const s=t[a]={exports:{}};return e[a](s,s.exports,i),s.exports}i.m=e,(()=>{const e=[];i.O=(t,a,r,s)=>{if(a){s=s||0;for(var n=e.length;n>0&&e[n-1][2]>s;n--)e[n]=e[n-1];return void(e[n]=[a,r,s])}let o=1/0;for(n=0;n<e.length;n++){let[a,r,s]=e[n],c=!0;for(var l=0;l<a.length;l++)(!1&s||o>=s)&&Object.keys(i.O).every(e=>i.O[e](a[l]))?a.splice(l--,1):(c=!1,s<o&&(o=s));if(c){e.splice(n--,1);const i=r();void 0!==i&&(t=i)}}return t}})(),i.n=e=>{const t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{if(Array.isArray(t))for(var a=0;a<t.length;){var r=t[a++],s=t[a++];i.o(e,r)?0===s&&a++:0===s?Object.defineProperty(e,r,{enumerable:!0,value:t[a++]}):Object.defineProperty(e,r,{enumerable:!0,get:s})}else for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=(e,t)=>Object.hasOwn(e,t),(()=>{const e={149:0,17:0};i.O.j=t=>0===e[t];const t=(t,a)=>{let[r,s,n]=a;var o,l,c=0;if(r.some(t=>0!==e[t])){for(o in s)i.o(s,o)&&(i.m[o]=s[o]);if(n)var u=n(i)}for(t&&t(a);c<r.length;c++)l=r[c],i.o(e,l)&&e[l]&&e[l][0](),e[l]=0;return i.O(u)},a=globalThis.webpackChunkwordpress_activitypub||=[];a.forEach(t.bind(null,0)),a.push=t.bind(null,a.push.bind(a))})();let a=i.O(void 0,[17],()=>i(736));a=i.O(a)})();