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

2 lines
10 KiB
JavaScript

(()=>{var e,t={3531(e,t,r){"use strict";const s=window.wp.blocks,o=window.wp.primitives,i=window.ReactJSXRuntime;var n=(0,i.jsx)(o.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(o.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"})}),a=r(6942),l=r.n(a);const c=window.wp.blockEditor,u=window.wp.dom,p=window.wp.i18n,d={html:!1,color:{gradients:!0,link:!0,__experimentalDefaultControls:{background:!0,text:!0,link:!0}},__experimentalBorder:{radius:!0,width:!0,color:!0,style:!0},typography:{fontSize:!0,__experimentalDefaultControls:{fontSize:!0}}},f=d;function v({buttonOnly:e=!1,className:t="",...r}){return r.className=l()(t,e?"is-style-button-only":"is-style-default"),r}const b={attributes:{buttonOnly:{type:"boolean",default:!1},buttonText:{type:"string",default:"Follow"},selectedUser:{type:"string",default:"blog"}},supports:d,isEligible:({buttonText:e,buttonOnly:t})=>!!e||!!t,migrate({buttonText:e,...t}){const r=(0,s.createBlock)("core/button",{text:e});return[v(t),[r]]}},h={attributes:{selectedUser:{type:"string",default:"blog"},buttonOnly:{type:"boolean",default:!1}},supports:f,isEligible:({buttonOnly:e})=>!!e,migrate:v,save(){const e=c.useBlockProps.save(),t=c.useInnerBlocksProps.save(e);return(0,i.jsx)("div",{...t})}},y=[{attributes:{selectedUser:{type:"string",default:"blog"}},supports:f,isEligible:(e,t)=>1===t.length&&"button"===t[0].attributes.tagName,migrate(e,t){const{tagName:r,...o}=t[0].attributes,i=(0,u.__unstableStripHTML)(t[0].originalContent)||(0,p.__)("Follow","activitypub");return[e,[(0,s.createBlock)("core/button",{...o,text:i})]]},save(){const e=c.useBlockProps.save(),t=c.useInnerBlocksProps.save(e);return(0,i.jsx)("div",{...t})}},h,b],w=window.wp.apiFetch;var m=r.n(w);const g=window.wp.data,_=window.wp.coreData,x=window.wp.components,j=window.wp.element;function k(){return window._activityPubOptions||{}}function S({name:e}){const{enabled:t}=k(),r=t?.blog?"":(0,p.__)("It will be empty in other non-author contexts.","activitypub"),s=(0,p.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,p.__)("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,r).trim();return(0,i.jsx)(x.Card,{children:(0,i.jsx)(x.CardBody,{children:(0,j.createInterpolateElement)(s,{strong:(0,i.jsx)("strong",{})})})})}const B={avatar:"https://secure.gravatar.com/avatar/default?s=120",webfinger:"@well@hello.dolly",name:(0,p.__)("Hello Dolly Fan Account","activitypub"),url:"#",image:{url:""},summary:""};function O(e){if(!e)return B;const t={...B,...e};return t.avatar=t?.icon?.url,t.webfinger&&!t.webfinger.startsWith("@")&&(t.webfinger="@"+t.webfinger),t}function N({profile:e,className:t,innerBlocksProps:r}){const{webfinger:s,avatar:o,name:n,image:a,summary:l,followersCount:c,postsCount:d}=e,f=t&&t.includes("is-style-button-only"),v={posts:d||0,followers:c||0};return(0,i.jsxs)("div",{className:"activitypub-profile",children:[!f&&a?.url&&(0,i.jsx)("div",{className:"activitypub-profile__header",style:{backgroundImage:`url(${a.url})`}}),(0,i.jsxs)("div",{className:"activitypub-profile__body",children:[!f&&(0,i.jsx)("img",{className:"activitypub-profile__avatar",src:o,alt:n}),(0,i.jsxs)("div",{className:"activitypub-profile__content",children:[!f&&(0,i.jsxs)("div",{className:"activitypub-profile__info",children:[(0,i.jsx)("div",{className:"activitypub-profile__name",children:n}),(0,i.jsx)("div",{className:"activitypub-profile__handle",children:s})]}),(0,i.jsx)("div",{...r}),!f&&(0,i.jsx)("div",{className:"activitypub-profile__bio",dangerouslySetInnerHTML:{__html:(0,u.safeHTML)(l)}}),!f&&(0,i.jsx)("div",{className:"activitypub-profile__stats",children:Object.entries(v).map(([e,t])=>{const r={posts:(0,p._n)("post","posts",t,"activitypub"),followers:(0,p._n)("follower","followers",t,"activitypub"),following:(0,p._n)("following","following",t,"activitypub")};return(0,i.jsxs)("div",{children:[(0,i.jsx)("strong",{children:t})," ",r[e]]},e)})})]})]})]})}const C=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","name":"activitypub/follow-me","apiVersion":3,"version":"8.2.1","title":"Follow me on the Fediverse","category":"widgets","description":"Display your Fediverse profile so that visitors can follow you.","textdomain":"activitypub","icon":"groups","keywords":["fediverse","activitypub","follow","mastodon"],"example":{"attributes":{"className":"is-style-default"}},"supports":{"html":false,"interactivity":true,"color":{"gradients":true,"link":true,"__experimentalDefaultControls":{"background":true,"text":true,"link":true}},"__experimentalBorder":{"radius":true,"width":true,"color":true,"style":true},"shadow":true,"typography":{"fontSize":true,"__experimentalDefaultControls":{"fontSize":true}},"innerBlocks":{"allowedBlocks":["core/button"]}},"styles":[{"name":"default","label":"Default","isDefault":true},{"name":"button-only","label":"Button"},{"name":"profile","label":"Profile"}],"attributes":{"selectedUser":{"type":"string","default":"blog"}},"usesContext":["postType","postId"],"editorScript":"file:./index.js","viewScriptModule":"file:./view.js","viewScript":"wp-api-fetch","style":"file:./style-index.css","render":"file:./render.php"}');(0,s.registerBlockType)(C,{deprecated:y,edit:function({attributes:e,setAttributes:t,context:{postType:r,postId:s}}){const o=(0,c.useBlockProps)({className:"activitypub-follow-me-block-wrapper"}),n=function({withInherit:e=!1}){const{enabled:t,namespace:r}=k(),[s,o]=(0,j.useState)(!1),{fetchedUsers:i,isLoadingUsers:n}=(0,g.useSelect)(e=>{const{getUsers:r,getIsResolving:s}=e("core");return{fetchedUsers:t?.users?r({capabilities:"activitypub"}):null,isLoadingUsers:!!t?.users&&s("getUsers",[{capabilities:"activitypub"}])}},[t?.users]),a=(0,g.useSelect)(e=>i||n?null:e("core").getCurrentUser(),[i,n]);(0,j.useEffect)(()=>{!i&&!n&&a&&r&&m()({path:`/${r}/actors/${a.id}`,method:"HEAD",headers:{Accept:"application/activity+json"},parse:!1}).then(()=>o(!0)).catch(()=>o(!1))},[i,n,a,r]);const l=(0,j.useMemo)(()=>i||(a&&s?[{id:a.id,name:a.name}]:[]),[i,a,s]);return(0,j.useMemo)(()=>{if(!l.length)return[];const r=[];return t?.blog&&i&&r.push({label:(0,p.__)("Blog","activitypub"),value:"blog"}),e&&t?.users&&i&&r.push({label:(0,p.__)("Dynamic User","activitypub"),value:"inherit"}),l.reduce((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e),r)},[l,t?.blog,t?.users,i,e])}({withInherit:!0}),{namespace:a}=k(),{selectedUser:l,className:u="is-style-default"}=e,d="inherit"===l,[f,v]=(0,j.useState)(O(B)),b="blog"===l?0:l,h=[["core/button",{text:(0,p.__)("Follow","activitypub")}]],y=(0,c.useInnerBlocksProps)({},{allowedBlocks:["core/button"],template:h,templateLock:!1,renderAppender:!1}),w=(0,g.useSelect)(e=>{const{getEditedEntityRecord:t}=e(_.store),o=t("postType",r,s)?.author;return o??null},[r,s]);return(0,j.useEffect)(()=>{if(d&&!w)return;const e=d?w:b;(function(e,t){const r={headers:{Accept:"application/activity+json"},path:`/${t}/actors/${e}`};return m()(r)})(e,a).then(t=>{if(v(O(t)),t.followers)try{const{pathname:e}=new URL(t.followers);m()({path:e.replace("wp-json/","")}).then(({totalItems:e=0})=>{v(t=>({...t,followersCount:e}))}).catch(()=>{})}catch(e){}e?m()({path:`/wp/v2/users/${e}/?context=activitypub`}).then(({post_count:e})=>{v(t=>({...t,postsCount:e}))}).catch(()=>{}):m()({path:"/wp/v2/posts",method:"HEAD",parse:!1}).then(e=>{const t=e.headers.get("X-WP-Total");v(e=>({...e,postsCount:t}))}).catch(()=>{})}).catch(()=>{})},[b,w,d,a]),(0,j.useEffect)(()=>{n.length&&(n.find(({value:e})=>e===l)||t({selectedUser:n[0].value}))},[l,n,t]),(0,i.jsxs)("div",{...o,children:[(0,i.jsx)(c.InspectorControls,{children:n.length>1&&(0,i.jsx)(x.PanelBody,{title:(0,p.__)("Follow Me Options","activitypub"),children:(0,i.jsx)(x.SelectControl,{label:(0,p.__)("Select User","activitypub"),value:e.selectedUser,options:n,onChange:e=>t({selectedUser:e}),__next40pxDefaultSize:!0})})},"activitypub-follow-me"),d&&!w?(0,i.jsx)(S,{name:(0,p.__)("Follow Me","activitypub")}):(0,i.jsx)(N,{profile:f,className:u,innerBlocksProps:y})]})},icon:n,save:function(){const e=c.useBlockProps.save(),t=c.useInnerBlocksProps.save(e);return(0,i.jsx)("div",{...t})}})},6942(e,t){var r;!function(){"use strict";var s={}.hasOwnProperty;function o(){for(var e="",t=0;t<arguments.length;t++){var r=arguments[t];r&&(e=n(e,i(r)))}return e}function i(e){if("string"==typeof e||"number"==typeof e)return e;if("object"!=typeof e)return"";if(Array.isArray(e))return o.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var t="";for(var r in e)s.call(e,r)&&e[r]&&(t=n(t,r));return t}function n(e,t){return t?e?e+" "+t:e+t:e}e.exports?(o.default=o,e.exports=o):void 0===(r=function(){return o}.apply(t,[]))||(e.exports=r)}()}},r={};function s(e){var o=r[e];if(void 0!==o)return o.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,s),i.exports}s.m=t,e=[],s.O=(t,r,o,i)=>{if(!r){var n=1/0;for(u=0;u<e.length;u++){for(var[r,o,i]=e[u],a=!0,l=0;l<r.length;l++)(!1&i||n>=i)&&Object.keys(s.O).every(e=>s.O[e](r[l]))?r.splice(l--,1):(a=!1,i<n&&(n=i));if(a){e.splice(u--,1);var c=o();void 0!==c&&(t=c)}}return t}i=i||0;for(var u=e.length;u>0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[r,o,i]},s.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return s.d(t,{a:t}),t},s.d=(e,t)=>{for(var r in t)s.o(t,r)&&!s.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={338:0,870:0};s.O.j=t=>0===e[t];var t=(t,r)=>{var o,i,[n,a,l]=r,c=0;if(n.some(t=>0!==e[t])){for(o in a)s.o(a,o)&&(s.m[o]=a[o]);if(l)var u=l(s)}for(t&&t(r);c<n.length;c++)i=n[c],s.o(e,i)&&e[i]&&e[i][0](),e[i]=0;return s.O(u)},r=globalThis.webpackChunkwordpress_activitypub=globalThis.webpackChunkwordpress_activitypub||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var o=s.O(void 0,[870],()=>s(3531));o=s.O(o)})();