3 lines
12 KiB
JavaScript
3 lines
12 KiB
JavaScript
(()=>{"use strict";var e,t={4736(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",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,p=window.wp.coreData,u=window.wp.data,d=window.wp.element,v=window.wp.i18n,h=window.wp.apiFetch;var b=i.n(h);function g(){return window._activityPubOptions||{}}function f({name:e}){const{enabled:t}=g(),i=t?.blog?"":(0,v.__)("It will be empty in other non-author contexts.","activitypub"),a=(0,v.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,v.__)("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 w=window.wp.url;function y({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,v.__)("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,v.__)("Previous page","activitypub"),onClick:()=>{r||i(e-1)},onKeyDown:t=>{r||"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),i(e-1))},children:(0,v.__)("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,v.__)("Next page","activitypub"),onClick:()=>{n||i(e+1)},onKeyDown:t=>{n||"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),i(e+1))},children:(0,v.__)("Next","activitypub")})]})}function _({selectedUser:e,perPage:t,order:i,endpoint:a="followers",page:r,setPage:n,initialData:o=!1,emptyMessage:l=(0,v.__)("No results found.","activitypub"),navLabel:c=(0,v.__)("Navigation","activitypub")}){const{namespace:p}=g(),u="blog"===e?0:e,[h,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,w.addQueryArgs)(`/${p}/actors/${u}/${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))},[p,u,t,i,N,a,o,U]),(0,s.jsxs)("div",{className:"activitypub-actor-list-container",children:[h.length?(0,s.jsx)("ul",{className:"activitypub-actor-list",children:h.map(e=>(0,s.jsx)("li",{className:"activitypub-actor-item",children:(0,s.jsx)(y,{...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":"8.2.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:h}=e,w=(0,c.useBlockProps)(),[y,m]=(0,d.useState)(1),j=[{label:(0,v.__)("New to old","activitypub"),value:"desc"},{label:(0,v.__)("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,u.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,u.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,v.__)("Blog","activitypub"),value:"blog"}),e&&t?.users&&s&&i.push({label:(0,v.__)("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,u.useSelect)(e=>{const{getCurrentUser:t,getUsers:i,getEntityRecord:a,canUser:r}=e(p.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,u.useSelect)(e=>{const{getEditedEntityRecord:t}=e(p.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"===h)return S;if("inherit"===h){if(!P)return!1;const e=C.find(e=>e.id===P);return!!e&&x(e.meta)}return!1},[h,P,C,S]),F=(0,d.useMemo)(()=>!(!E||!U)&&("blog"===h?O:U.id===P),[E,U,h,P,O]),I=(0,d.useMemo)(()=>F&&M?"blog"===h?M+"/wp-admin/options-general.php?page=activitypub&tab=blog-profile":M+"/wp-admin/profile.php#activitypub":null,[F,M,h]);(0,d.useEffect)(()=>{D.length&&("blog"===h||"inherit"===h||D.find(({value:e})=>e===h)||t({selectedUser:D[0].value}))},[h,D,t]);const B=[["core/heading",{level:3,placeholder:(0,v.__)("Fediverse Followers","activitypub"),content:(0,v.__)("Fediverse Followers","activitypub")}]];return(0,s.jsxs)("div",{...w,children:[(0,s.jsx)(c.InspectorControls,{children:(0,s.jsxs)(l.PanelBody,{title:(0,v.__)("Followers Options","activitypub"),children:[D.length>1&&(0,s.jsx)(l.SelectControl,{label:(0,v.__)("Select User","activitypub"),value:h,options:D,onChange:N("selectedUser"),__next40pxDefaultSize:!0}),(0,s.jsx)(l.SelectControl,{label:(0,v.__)("Sort","activitypub"),value:n,options:j,onChange:N("order"),__next40pxDefaultSize:!0}),(0,s.jsx)(l.RangeControl,{label:(0,v.__)("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,v.__)("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,v.__)("The selected user has their social graph hidden. This block will not display followers on the frontend.","activitypub")}),!E&&"inherit"===h&&P&&(0,s.jsx)(_,{selectedUser:P,perPage:o,order:n,endpoint:"followers",page:y,setPage:m,emptyMessage:(0,v.__)("No followers found.","activitypub"),navLabel:(0,v.__)("Follower navigation","activitypub")}),!E&&"inherit"===h&&!P&&(0,s.jsx)(f,{name:(0,v.__)("Followers","activitypub")}),!E&&"inherit"!==h&&(0,s.jsx)(_,{selectedUser:h,perPage:o,order:n,endpoint:"followers",page:y,setPage:m,emptyMessage:(0,v.__)("No followers found.","activitypub"),navLabel:(0,v.__)("Follower navigation","activitypub")})]})]})},save:function(){const e=c.useBlockProps.save(),t=c.useInnerBlocksProps.save(e);return(0,s.jsx)("div",{...t})},icon:n})}},i={};function a(e){var r=i[e];if(void 0!==r)return r.exports;var s=i[e]={exports:{}};return t[e](s,s.exports,a),s.exports}a.m=t,e=[],a.O=(t,i,r,s)=>{if(!i){var n=1/0;for(p=0;p<e.length;p++){for(var[i,r,s]=e[p],o=!0,l=0;l<i.length;l++)(!1&s||n>=s)&&Object.keys(a.O).every(e=>a.O[e](i[l]))?i.splice(l--,1):(o=!1,s<n&&(n=s));if(o){e.splice(p--,1);var c=r();void 0!==c&&(t=c)}}return t}s=s||0;for(var p=e.length;p>0&&e[p-1][2]>s;p--)e[p]=e[p-1];e[p]=[i,r,s]},a.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var i in t)a.o(t,i)&&!a.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={149:0,17:0};a.O.j=t=>0===e[t];var t=(t,i)=>{var r,s,[n,o,l]=i,c=0;if(n.some(t=>0!==e[t])){for(r in o)a.o(o,r)&&(a.m[r]=o[r]);if(l)var p=l(a)}for(t&&t(i);c<n.length;c++)s=n[c],a.o(e,s)&&e[s]&&e[s][0](),e[s]=0;return a.O(p)},i=globalThis.webpackChunkwordpress_activitypub=globalThis.webpackChunkwordpress_activitypub||[];i.forEach(t.bind(null,0)),i.push=t.bind(null,i.push.bind(i))})();var r=a.O(void 0,[17],()=>a(4736));r=a.O(r)})(); |