wordpress-activitypub/build/followers/index.js

3 lines
7.4 KiB
JavaScript
Raw Normal View History

(()=>{var e={20:(e,t,a)=>{"use strict";var r=a(609),n=Symbol.for("react.element"),l=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),o=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function s(e,t,a){var r,s={},c=null,p=null;for(r in void 0!==a&&(c=""+a),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(p=t.ref),t)l.call(t,r)&&!i.hasOwnProperty(r)&&(s[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===s[r]&&(s[r]=t[r]);return{$$typeof:n,type:e,key:c,ref:p,props:s,_owner:o.current}}t.jsx=s,t.jsxs=s},848:(e,t,a)=>{"use strict";e.exports=a(20)},609:e=>{"use strict";e.exports=window.React},942:(e,t)=>{var a;!function(){"use strict";var r={}.hasOwnProperty;function n(){for(var e="",t=0;t<arguments.length;t++){var a=arguments[t];a&&(e=o(e,l(a)))}return e}function l(e){if("string"==typeof e||"number"==typeof e)return e;if("object"!=typeof e)return"";if(Array.isArray(e))return n.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var t="";for(var a in e)r.call(e,a)&&e[a]&&(t=o(t,a));return t}function o(e,t){return t?e?e+" "+t:e+t:e}e.exports?(n.default=n,e.exports=n):void 0===(a=function(){return n}.apply(t,[]))||(e.exports=a)}()}},t={};function a(r){var n=t[r];if(void 0!==n)return n.exports;var l=t[r]={exports:{}};return e[r](l,l.exports,a),l.exports}a.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";const e=window.wp.blocks,t=window.wp.primitives;var r=a(848);const n=(0,r.jsx)(t.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,r.jsx)(t.Path,{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",fillRule:"evenodd"})}),l=window.wp.components,o=window.wp.element,i=window.wp.blockEditor,s=window.wp.i18n;var c=a(609);const p=window.wp.apiFetch;var u=a.n(p);const v=window.wp.url;var d=a(942),w=a.n(d);function f({active:e,children:t,page:a,pageClick:r,className:n}){const l=w()("wp-block activitypub-pager",n,{current:e});return(0,c.createElement)("a",{className:l,onClick:t=>{t.preventDefault(),!e&&r(a)}},t)}const b={outlined:"outlined",minimal:"minimal"};function m({compact:e,nextLabel:t,page:a,pageClick:n,perPage:l,prevLabel:o,total:i,variant:s=b.outlined}){const c=((e,t)=>{let a=[1,e-2,e-1,e,e+1,e+2,t];a.sort(((e,t)=>e-t)),a=a.filter(((e,a,r)=>e>=1&&e<=t&&r.lastIndexOf(e)===a));for(let e=a.length-2;e>=0;e--)a[e]===a[e+1]&&a.splice(e+1,1);return a})(a,Math.ceil(i/l)),p=w()("alignwide wp-block-query-pagination is-content-justification-space-between is-layout-flex wp-block-query-pagination-is-layout-flex",`is-${s}`,{"is-compact":e});return(0,r.jsxs)("nav",{className:p,children:[o&&(0,r.jsx)(f,{page:a-1,pageClick:n,active:1===a,"aria-label":o,className:"wp-block-query-pagination-previous block-editor-block-list__block",children:o},"prev"),!e&&(0,r.jsx)("div",{className:"block-editor-block-list__block wp-block wp-block-query-pagination-numbers",children:c.map((e=>(0,r.jsx)(f,{page:e,pageClick:n,active:e===a,className:"page-numbers",children:e},e)))}),t&&(0,r.jsx)(f,{page:a+1,pageClick:n,active:a===Math.ceil(i/l),"aria-label":t,className:"wp-block-query-pagination-next block-editor-block-list__block",children:t},"next")]})}const{namespace:g}=window._activityPubOptions;function y({selectedUser:e,per_page:t,order:a,title:r,page:n,setPage:l,className:i="",followLinks:p=!0,followerData:d=!1}){const w="site"===e?0:e,[f,b]=(0,c.useState)([]),[y,h]=(0,c.useState)(0),[k,x]=(0,c.useState)(0),[E,j]=function(){const[e,t]=(0,c.useState)(1);return[e,t]}(),N=n||E,S=l||j,C=(0,o.createI
(0,s.__)("<span>←</span> Less","activitypub"),{span:(0,c.createElement)("span",{className:"wp-block-query-pagination-previous-arrow is-arrow-arrow","aria-hidden":"true"})}),O=(0,o.createInterpolateElement)(/* translators: arrow for next followers link */ /* translators: arrow for next followers link */
(0,s.__)("More <span>→</span>","activitypub"),{span:(0,c.createElement)("span",{className:"wp-block-query-pagination-next-arrow is-arrow-arrow","aria-hidden":"true"})}),P=(e,a)=>{b(e),x(a),h(Math.ceil(a/t))};return(0,c.useEffect)((()=>{if(d&&1===N)return P(d.followers,d.total);const e=function(e,t,a,r){const n=`/${g}/actors/${e}/followers`,l={per_page:t,order:a,page:r,context:"full"};return(0,v.addQueryArgs)(n,l)}(w,t,a,N);u()({path:e}).then((e=>P(e.orderedItems,e.totalItems))).catch((()=>{}))}),[w,t,a,N,d]),(0,c.createElement)("div",{className:"activitypub-follower-block "+i},(0,c.createElement)("h3",null,r),(0,c.createElement)("ul",null,f&&f.map((e=>(0,c.createElement)("li",{key:e.url},(0,c.createElement)(_,{...e,followLinks:p}))))),y>1&&(0,c.createElement)(m,{page:N,perPage:t,total:k,pageClick:S,nextLabel:O,prevLabel:C,compact:"is-style-compact"===i}))}function _({name:e,icon:t,url:a,preferredUsername:r,followLinks:n=!0}){const o=`@${r}`,i={};return n||(i.onClick=e=>e.preventDefault()),(0,c.createElement)(l.ExternalLink,{className:"activitypub-link",href:a,title:o,...i},(0,c.createElement)("img",{width:"40",height:"40",src:t.url,className:"avatar activitypub-avatar",alt:e}),(0,c.createElement)("span",{className:"activitypub-actor"},(0,c.createElement)("strong",{className:"activitypub-name"},e),(0,c.createElement)("span",{className:"sep"},"/"),(0,c.createElement)("span",{className:"activitypub-handle"},o)))}const h=window.wp.data,k=window._activityPubOptions?.enabled;(0,e.registerBlockType)("activitypub/followers",{edit:function({attributes:e,setAttributes:t}){const{order:a,per_page:n,selectedUser:c,title:p}=e,u=(0,i.useBlockProps)(),[v,d]=(0,o.useState)(1),w=[{label:(0,s.__)("New to old","activitypub"),value:"desc"},{label:(0,s.__)("Old to new","activitypub"),value:"asc"}],f=function(){const e=k?.users?(0,h.useSelect)((e=>e("core").getUsers({who:"authors"}))):[];return(0,o.useMemo)((()=>{if(!e)return[];const t=k?.site?[{label:(0,s.__)("Whole Site","activitypub"),value:"site"}]:[];return e.reduce(((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e)),t)}),[e])}(),b=e=>a=>{d(1),t({[e]:a})};return(0,o.useEffect)((()=>{f.length&&(f.find((({value:e})=>e===c))||t({selectedUser:f[0].value}))}),[c,f]),(0,r.jsxs)("div",{...u,children:[(0,r.jsx)(i.InspectorControls,{children:(0,r.jsxs)(l.PanelBody,{title:(0,s.__)("Followers Options","activitypub"),children:[(0,r.jsx)(l.TextControl,{label:(0,s.__)("Title","activitypub"),help:(0,s.__)("Title to display above the list of followers. Blank for none.","activitypub"),value:p,onChange:e=>t({title:e})}),f.length>1&&(0,r.jsx)(l.SelectControl,{label:(0,s.__)("Select User","activitypub"),value:c,options:f,onChange:b("selectedUser")}),(0,r.jsx)(l.SelectControl,{label:(0,s.__)("Sort","activitypub"),value:a,options:w,onChange:b("order")}),(0,r.jsx)(l.RangeControl,{label:(0,s.__)("Number of Followers","activitypub"),value:n,onChange:b("per_page"),min:1,max:10})]})},"setting"),(0,r.jsx)(y,{...e,page:v,setPage:d,followLinks:!1})]})},save:()=>null,icon:n})})()})();