2 lines
10 KiB
JavaScript
2 lines
10 KiB
JavaScript
(()=>{var e={531(e,t,o){"use strict";const r=window.wp.blocks,s=window.wp.primitives,n=window.ReactJSXRuntime;var i=(0,n.jsx)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)(s.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"})}),l=o(942),a=o.n(l);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 b({buttonOnly:e=!1,className:t="",...o}){return o.className=a()(t,e?"is-style-button-only":"is-style-default"),o}const v={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 o=(0,r.createBlock)("core/button",{text:e});return[b(t),[o]]}},h={attributes:{selectedUser:{type:"string",default:"blog"},buttonOnly:{type:"boolean",default:!1}},supports:f,isEligible:({buttonOnly:e})=>!!e,migrate:b,save(){const e=c.useBlockProps.save(),t=c.useInnerBlocksProps.save(e);return(0,n.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:o,...s}=t[0].attributes,n=(0,u.__unstableStripHTML)(t[0].originalContent)||(0,p.__)("Follow","activitypub");return[e,[(0,r.createBlock)("core/button",{...s,text:n})]]},save(){const e=c.useBlockProps.save(),t=c.useInnerBlocksProps.save(e);return(0,n.jsx)("div",{...t})}},h,v],w=window.wp.apiFetch;var m=o.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(),o=t?.blog?"":(0,p.__)("It will be empty in other non-author contexts.","activitypub"),r=(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,o).trim();return(0,n.jsx)(x.Card,{children:(0,n.jsx)(x.CardBody,{children:(0,j.createInterpolateElement)(r,{strong:(0,n.jsx)("strong",{})})})})}const O={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 B(e){if(!e)return O;const t={...O,...e};return t.avatar=t?.icon?.url,t.webfinger&&!t.webfinger.startsWith("@")&&(t.webfinger="@"+t.webfinger),t}function N({profile:e,className:t,innerBlocksProps:o}){const{webfinger:r,avatar:s,name:i,image:l,summary:a,followersCount:c,postsCount:d}=e,f=t&&t.includes("is-style-button-only"),b={posts:d||0,followers:c||0};return(0,n.jsxs)("div",{className:"activitypub-profile",children:[!f&&l?.url&&(0,n.jsx)("div",{className:"activitypub-profile__header",style:{backgroundImage:`url(${l.url})`}}),(0,n.jsxs)("div",{className:"activitypub-profile__body",children:[!f&&(0,n.jsx)("img",{className:"activitypub-profile__avatar",src:s,alt:i}),(0,n.jsxs)("div",{className:"activitypub-profile__content",children:[!f&&(0,n.jsxs)("div",{className:"activitypub-profile__info",children:[(0,n.jsx)("div",{className:"activitypub-profile__name",children:i}),(0,n.jsx)("div",{className:"activitypub-profile__handle",children:r})]}),(0,n.jsx)("div",{...o}),!f&&(0,n.jsx)("div",{className:"activitypub-profile__bio",dangerouslySetInnerHTML:{__html:(0,u.safeHTML)(a)}}),!f&&(0,n.jsx)("div",{className:"activitypub-profile__stats",children:Object.entries(b).map(([e,t])=>{const o={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,n.jsxs)("div",{children:[(0,n.jsx)("strong",{children:t})," ",o[e]]},e)})})]})]})]})}const C=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","name":"activitypub/follow-me","apiVersion":3,"version":"9.0.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,r.registerBlockType)(C,{deprecated:y,edit:function({attributes:e,setAttributes:t,context:{postType:o,postId:r}}){const s=(0,c.useBlockProps)({className:"activitypub-follow-me-block-wrapper"}),i=function({withInherit:e=!1}){const{enabled:t,namespace:o}=k(),[r,s]=(0,j.useState)(!1),{fetchedUsers:n,isLoadingUsers:i}=(0,g.useSelect)(e=>{const{getUsers:o,getIsResolving:r}=e("core");return{fetchedUsers:t?.users?o({capabilities:"activitypub"}):null,isLoadingUsers:!!t?.users&&r("getUsers",[{capabilities:"activitypub"}])}},[t?.users]),l=(0,g.useSelect)(e=>n||i?null:e("core").getCurrentUser(),[n,i]);(0,j.useEffect)(()=>{!n&&!i&&l&&o&&m()({path:`/${o}/actors/${l.id}`,method:"HEAD",headers:{Accept:"application/activity+json"},parse:!1}).then(()=>s(!0)).catch(()=>s(!1))},[n,i,l,o]);const a=(0,j.useMemo)(()=>n||(l&&r?[{id:l.id,name:l.name}]:[]),[n,l,r]);return(0,j.useMemo)(()=>{if(!a.length)return[];const o=[];return t?.blog&&n&&o.push({label:(0,p.__)("Blog","activitypub"),value:"blog"}),e&&t?.users&&n&&o.push({label:(0,p.__)("Dynamic User","activitypub"),value:"inherit"}),a.reduce((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e),o)},[a,t?.blog,t?.users,n,e])}({withInherit:!0}),{namespace:l}=k(),{selectedUser:a,className:u="is-style-default"}=e,d="inherit"===a,[f,b]=(0,j.useState)(B(O)),v="blog"===a?0:a,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),s=t("postType",o,r)?.author;return s??null},[o,r]);return(0,j.useEffect)(()=>{if(d&&!w)return;const e=d?w:v;(function(e,t){const o={headers:{Accept:"application/activity+json"},path:`/${t}/actors/${e}`};return m()(o)})(e,l).then(t=>{if(b(B(t)),t.followers)try{const{pathname:e}=new URL(t.followers);m()({path:e.replace("wp-json/","")}).then(({totalItems:e=0})=>{b(t=>({...t,followersCount:e}))}).catch(()=>{})}catch(e){}e?m()({path:`/wp/v2/users/${e}/?context=activitypub`}).then(({post_count:e})=>{b(t=>({...t,postsCount:e}))}).catch(()=>{}):m()({path:"/wp/v2/posts",method:"HEAD",parse:!1}).then(e=>{const t=e.headers.get("X-WP-Total");b(e=>({...e,postsCount:t}))}).catch(()=>{})}).catch(()=>{})},[v,w,d,l]),(0,j.useEffect)(()=>{i.length&&(i.find(({value:e})=>e===a)||t({selectedUser:i[0].value}))},[a,i,t]),(0,n.jsxs)("div",{...s,children:[(0,n.jsx)(c.InspectorControls,{children:i.length>1&&(0,n.jsx)(x.PanelBody,{title:(0,p.__)("Follow Me Options","activitypub"),children:(0,n.jsx)(x.SelectControl,{label:(0,p.__)("Select User","activitypub"),value:e.selectedUser,options:i,onChange:e=>t({selectedUser:e}),__next40pxDefaultSize:!0})})},"activitypub-follow-me"),d&&!w?(0,n.jsx)(S,{name:(0,p.__)("Follow Me","activitypub")}):(0,n.jsx)(N,{profile:f,className:u,innerBlocksProps:y})]})},icon:i,save:function(){const e=c.useBlockProps.save(),t=c.useInnerBlocksProps.save(e);return(0,n.jsx)("div",{...t})}})},942(e,t){var o;!function(){"use strict";var r={}.hasOwnProperty;function s(){for(var e="",t=0;t<arguments.length;t++){var o=arguments[t];o&&(e=i(e,n(o)))}return e}function n(e){if("string"==typeof e||"number"==typeof e)return e;if("object"!=typeof e)return"";if(Array.isArray(e))return s.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var t="";for(var o in e)r.call(e,o)&&e[o]&&(t=i(t,o));return t}function i(e,t){return t?e?e+" "+t:e+t:e}e.exports?(s.default=s,e.exports=s):void 0===(o=function(){return s}.apply(t,[]))||(e.exports=o)}()}};const t={};function o(r){const s=t[r];if(void 0!==s)return s.exports;const n=t[r]={exports:{}};return e[r](n,n.exports,o),n.exports}o.m=e,(()=>{const e=[];o.O=(t,r,s,n)=>{if(r){n=n||0;for(var i=e.length;i>0&&e[i-1][2]>n;i--)e[i]=e[i-1];return void(e[i]=[r,s,n])}let l=1/0;for(i=0;i<e.length;i++){let[r,s,n]=e[i],c=!0;for(var a=0;a<r.length;a++)(!1&n||l>=n)&&Object.keys(o.O).every(e=>o.O[e](r[a]))?r.splice(a--,1):(c=!1,n<l&&(l=n));if(c){e.splice(i--,1);const o=s();void 0!==o&&(t=o)}}return t}})(),o.n=e=>{const t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{if(Array.isArray(t))for(var r=0;r<t.length;){var s=t[r++],n=t[r++];o.o(e,s)?0===n&&r++:0===n?Object.defineProperty(e,s,{enumerable:!0,value:t[r++]}):Object.defineProperty(e,s,{enumerable:!0,get:n})}else for(var s in t)o.o(t,s)&&!o.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},o.o=(e,t)=>Object.hasOwn(e,t),(()=>{const e={338:0,870:0};o.O.j=t=>0===e[t];const t=(t,r)=>{let[s,n,i]=r;var l,a,c=0;if(s.some(t=>0!==e[t])){for(l in n)o.o(n,l)&&(o.m[l]=n[l]);if(i)var u=i(o)}for(t&&t(r);c<s.length;c++)a=s[c],o.o(e,a)&&e[a]&&e[a][0](),e[a]=0;return o.O(u)},r=globalThis.webpackChunkwordpress_activitypub||=[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();let r=o.O(void 0,[870],()=>o(531));r=o.O(r)})(); |