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

1 line
6.9 KiB
JavaScript
Raw Normal View History

(()=>{"use strict";var e,t={703:(e,t,r)=>{const o=window.wp.element,n=window.wp.domReady;var a=r.n(n);const i=window.wp.apiFetch;var l=r.n(i);const c=window.wp.components,u=window.wp.i18n,s=window.wp.primitives,p=(0,o.createElement)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.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,o.createElement)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.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,o.cloneElement)(e,{width:t,height:t,...r})},v=window.wp.compose;function f(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 f(t)}function b(e,t,r=null,o=""){return r?`${e}${o} { ${t}: ${r}; }\n`:""}function w(e,t,r,o){return b(e,"background-color",t)+b(e,"color",r)+b(e,"background-color",o,":hover")+b(e,"background-color",o,":focus")}function _({selector:e,style:t,backgroundColor:r}){const n=function(e,t,r){const o=`${e} .components-button`,n=("string"==typeof(a=r)?f(a):a?.color?.background||null)||t?.color?.background;var a;return w(o,y(t?.elements?.link?.color?.text),n,y(t?.elements?.link?.[":hover"]?.color?.text))}(e,t,r);return(0,o.createElement)("style",null,n)}const{namespace:h}=window._activityPubOptions,g={avatar:"",webfinger:"@well@hello.dolly",name:(0,u.__)("Hello Dolly Fan Account","activitypub"),url:"#"};function E(e){if(!e)return g;const t={...g,...e};return t.avatar=t?.icon?.url,t}function k({profile:e,popupStyles:t,userId:r}){const{avatar:n,name:a,webfinger:i}=e;return(0,o.createElement)("div",{className:"activitypub-profile"},(0,o.createElement)("img",{className:"activitypub-profile__avatar",src:n,alt:a}),(0,o.createElement)("div",{className:"activitypub-profile__content"},(0,o.createElement)("div",{className:"activitypub-profile__name"},a),(0,o.createElement)("div",{className:"activitypub-profile__handle",title:i},i)),(0,o.createElement)(x,{profile:e,popupStyles:t,userId:r}))}function x({profile:e,popupStyles:t,userId:r}){const[n,a]=(0,o.useState)(!1),i=(0,u.sprintf)((0,u.__)("Follow %s","activitypub"),e?.name);return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(c.Button,{className:"activitypub-profile__follow",onClick:()=>a(!0)},(0,u.__)("Follow","activitypub")),n&&(0,o.createElement)(c.Modal,{className:"activitypub-profile__confirm activitypub__modal",onRequestClose:()=>a(!1),title:i},(0,o.createElement)(C,{profile:e,userId:r}),(0,o.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,n=(0,u.__)("Follow","activitypub"),a=(0,u.__)("Loading...","activitypub"),i=(0,u.__)("Opening...","activitypub"),s=(0,u.__)("Error","activitypub"),f=(0,u.__)("Invalid","activitypub"),[y,b]=(0,o.useState)(n),[w,_]=(0,o.useState)(p),g=(0,v.useCopyToClipboard)(r,(()=>{_(m),setTimeout((()=>_(p)),1e3)})),[E,k]=(0,o.useState)(""),x=(0,o.useCallback)((()=>{let e;if(!O(E)&&!function(e){const t=e.replace(/^@/,"").split("@");return 2===t.length&&O(`https://${t[1]}`)}(E))return b(f),e=setTimeout((()=>b(n)),2e3),()=>clearTimeout(e);const r=`/${h}/users/${t}/remote-follow?resource=${E}`;b(a),l()({path:r}).then((({url:e})=>{b(i),setTimeout((()=>{window.open(e,"_blank"),b(n)}),200)})).catch((()=>{b(s),setTimeout((()=>b(n)),2e3)}))}),[E]);return(0,o.createElement)("div",{className:"activitypub__dialog"},(0,o.createElement)("div",{className:"activitypub-dialog__section"},(0,o.createElement)("h4",null,(0,u.__)("My Profile","activitypub")),(0,o.createElement)("div",{className:"activitypub-dialog-description"},(0,u.__)("Copy and paste my profile into the search field of your favorite fediverse app or server.","activitypub")),(0,o.createElement)("div",{