wordpress-activitypub/build/follow-me/index.js

1 line
5.4 KiB
JavaScript
Raw Normal View History

2023-08-11 04:40:07 +02:00
(()=>{"use strict";var e,t={535:(e,t,o)=>{const n=window.wp.blocks,r=window.wp.element,l=window.wp.primitives,a=(0,r.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(l.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"})),i=window.wp.blockEditor,c=window.wp.i18n,s=window.wp.components,u=window.wp.data,p=window._activityPubOptions?.enabled;function v(e){return`var(--wp--preset--color--${e})`}function d(e){if("string"==typeof e&&e.match(/^#/))return e;const[,,t]=e.split("|");return v(t)}function m(e,t){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return o?`${e}${arguments.length>3&&void 0!==arguments[3]?arguments[3]:""} { ${t}: ${o}; }\n`:""}const f="activitypub-follow-modal-active";function w(e){let{id:t,style:o,backgroundColor:n}=e;const l=function(e,t,o){const n=`#${e} .components-button`,r=("string"==typeof(l=o)?v(l):l?.color?.background||null)||t?.color?.background;var l;const a=d(t?.elements?.link?.color?.text),i=d(t?.elements?.link?.[":hover"]?.color?.text);return m(n,"color",r)+m(n,"background-color",a)+m(n,"background-color",i,":hover")}(t,o,n);return(0,r.createElement)("style",null,l)}const b=window.wp.apiFetch;var h=o.n(b);const{namespace:y}=window._activityPubOptions,_={avatar:"",handle:"@well@hello.dolly",name:(0,c.__)("Hello Dolly Fan Account","fediverse"),url:"#"};function g(e){if(!e)return _;e.handle=function(e){try{var t;const{host:o,pathname:n}=new URL(e.url);return`${null!==(t=e.preferredUsername)&&void 0!==t?t:n.replace(/^\//,"")}@${o}`}catch(e){return"@error@error"}}(e);const t={..._,...e};return t.avatar=t?.icon?.url,t}function k(e){let{profile:t,popupStyles:o}=e;const{handle:n,avatar:l,name:a}=t;return(0,r.createElement)("div",{className:"activitypub-profile"},(0,r.createElement)("img",{className:"activitypub-profile__avatar",src:l}),(0,r.createElement)("div",{className:"activitypub-profile__content"},(0,r.createElement)("div",{className:"activitypub-profile__name"},a),(0,r.createElement)("div",{className:"activitypub-profile__handle"},n)),(0,r.createElement)(E,{profile:t,popupStyles:o}))}function E(e){let{profile:t,popupStyles:o}=e;const[n,l]=(0,r.useState)(!1);function a(e){const t=e?"add":"remove";document.body.classList[t](f),l(e)}return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(s.Button,{className:"activitypub-profile__follow",onClick:()=>a(!0)},(0,c.__)("Follow","fediverse")),(0,r.createElement)(s.__experimentalConfirmDialog,{className:"activitypub-profile__confirm",isOpen:n,onConfirm:()=>a(!1),onCancel:()=>a(!1)},(0,r.createElement)("p",null,"Howdy let's put some dialogs here"),(0,r.createElement)("style",null,o)))}(0,n.registerBlockType)("activitypub/follow-me",{edit:function(e){let{attributes:t,setAttributes:o}=e;const[n,l]=(0,r.useState)(g()),{selectedUser:a}=t,v="site"===a?0:a;function b(e){l(g(e))}(0,r.useEffect)((()=>{(function(e){const t={headers:{Accept:"application/activity+json"},path:`/${y}/users/${e}`};return h()(t)})(v).then(b)}),[v]);const _=(0,i.useBlockProps)(),E=function(){const e=p?.users?(0,u.useSelect)((e=>e("core").getUsers({who:"authors"}))):[];return(0,r.useMemo)((()=>{if(!e)return[];const t=p?.site?[{label:(0,c.__)("Whole Site","activitypub"),value:"site"}]:[];return e.reduce(((e,t)=>(e.push({label:t.name,value:t.id}),e)),t)}),[e])}(),O=function(e){const t=`.${f} .components-modal__content .components-button`,o=`${t}.is-primary`,n=`${t}.is-tertiary`,r=d(e?.elements?.link?.color?.text),l=d(e?.elements?.link?.[":hover"]?.color?.text);return m(o,"background-color",r)+m(o,"background-color",l,":hover")+m(n,"color",r)}(t.style);return(0,r.createElement)("div",_,(0,r.createElement)(i.InspectorControls,{key:"setting"},(0,r.createElement)(s.PanelBody,{title:(0,c.__)("Follow