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

1 line
6.8 KiB
JavaScript
Raw Normal View History

(()=>{"use strict";var e,t={703:(e,t,r)=>{const n=window.wp.element,o=window.wp.domReady;var a=r.n(o);const l=window.wp.apiFetch;var c=r.n(l);const i=window.wp.components,u=window.wp.i18n,s=window.wp.primitives,p=(0,n.createElement)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(s.Path,{d:"M20.2 8v11c0 .7-.6 1.2-1.2 1.2H6v1.5h13c1.5 0 2.7-1.2 2.7-2.8V8zM18 16.4V4.6c0-.9-.7-1.6-1.6-1.6H4.6C3.7 3 3 3.7 3 4.6v11.8c0 .9.7 1.6 1.6 1.6h11.8c.9 0 1.6-.7 1.6-1.6zm-13.5 0V4.6c0-.1.1-.1.1-.1h11.8c.1 0 .1.1.1.1v11.8c0 .1-.1.1-.1.1H4.6l-.1-.1z"})),m=(0,n.createElement)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(s.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})),d=function({icon:e,size:t=24,...r}){return(0,n.cloneElement)(e,{width:t,height:t,...r})},f=window.wp.compose;function v(e){return`var(--wp--preset--color--${e})`}function y(e){if("string"!=typeof e)return null;if(e.match(/^#/))return e.substring(0,7);const[,,t]=e.split("|");return v(t)}function w(e,t,r=null,n=""){return r?`${e}${n} { ${t}: ${r}; }\n`:""}function b(e,t,r,n){return w(e,"background-color",t)+w(e,"color",r)+w(e,"background-color",n,":hover")+w(e,"background-color",n,":focus")}function _({selector:e,style:t,backgroundColor:r}){const o=function(e,t,r){const n=`${e} .components-button`,o=("string"==typeof(a=r)?v(a):a?.color?.background||null)||t?.color?.background;var a;return b(n,y(t?.elements?.link?.color?.text),o,y(t?.elements?.link?.[":hover"]?.color?.text))}(e,t,r);return(0,n.createElement)("style",null,o)}const{namespace:h}=window._activityPubOptions,E={avatar:"",webfinger:"@well@hello.dolly",name:(0,u.__)("Hello Dolly Fan Account","activitypub"),url:"#"};function g(e){if(!e)return E;const t={...E,...e};return t.avatar=t?.icon?.url,t}function k({profile:e,popupStyles:t,userId:r}){const{avatar:o,name:a,webfinger:l}=e;return(0,n.createElement)("div",{className:"activitypub-profile"},(0,n.createElement)("img",{className:"activitypub-profile__avatar",src:o,alt:a}),(0,n.createElement)("div",{className:"activitypub-profile__content"},(0,n.createElement)("div",{className:"activitypub-profile__name"},a),(0,n.createElement)("div",{className:"activitypub-profile__handle",title:l},l)),(0,n.createElement)(x,{profile:e,popupStyles:t,userId:r}))}function x({profile:e,popupStyles:t,userId:r}){const[o,a]=(0,n.useState)(!1),l=(0,u.sprintf)((0,u.__)("Follow %s","activitypub"),e?.name);return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(i.Button,{className:"activitypub-profile__follow",onClick:()=>a(!0)},(0,u.__)("Follow","activitypub")),o&&(0,n.createElement)(i.Modal,{className:"activitypub-profile__confirm",onRequestClose:()=>a(!1),title:l},(0,n.createElement)(C,{profile:e,userId:r}),(0,n.createElement)("style",null,t)))}function O(e){try{return new URL(e),!0}catch(e){return!1}}function C({profile:e,userId:t}){const{webfinger:r}=e,o=(0,u.__)("Follow","activitypub"),a=(0,u.__)("Loading...","activitypub"),l=(0,u.__)("Opening...","activitypub"),s=(0,u.__)("Error","activitypub"),v=(0,u.__)("Invalid","activitypub"),[y,w]=(0,n.useState)(o),[b,_]=(0,n.useState)(p),E=(0,f.useCopyToClipboard)(r,(()=>{_(m),setTimeout((()=>_(p)),1e3)})),[g,k]=(0,n.useState)(""),x=(0,n.useCallback)((()=>{let e;if(!O(g)&&!function(e){const t=e.replace(/^@/,"").split("@");return 2===t.length&&O(`https://${t[1]}`)}(g))return w(v),e=setTimeout((()=>w(o)),2e3),()=>clearTimeout(e);const r=`/${h}/users/${t}/remote-follow?resource=${g}`;w(a),c()({path:r}).then((({url:e})=>{w(l),setTimeout((()=>{window.open(e,"_blank"),w(o)}),200)})).catch((()=>{w(s),setTimeout((()=>w(o)),2e3)}))}),[g]);return(0,n.createElement)("div",{className:"activitypub-follow-me__dialog"},(0,n.createElement)("div",{className:"apmfd__section"},(0,n.createElement)("h4",null,(0,u.__)("My Profile","activitypub")),(0,n.createElement)("div",{className:"apfmd-description"},(0,u.__)("Copy and paste my profile into the search field of your favorite fediverse app or server.","activitypub")),(0,n.createElement)("div",{className:"apfmd__button-group"},(0