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

1 line
6.8 KiB
JavaScript

(()=>{"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,n.createElement)("input",{type:"text",value:r,readOnly:!0}),(0,n.createElement)(i.Button,{ref:E},(0,n.createElement)(d,{icon:b}),(0,u.__)("Copy","activitypub")))),(0,n.createElement)("div",{className:"apmfd__section"},(0,n.createElement)("h4",null,(0,u.__)("Your Profile","activitypub")),(0,n.createElement)("div",{className:"apfmd-description"},(0,n.createInterpolateElement)((0,u.__)("Or, if you know your own profile, we can start things that way! (eg <code>https://example.com/yourusername</code> or <code>yourusername@example.com</code>)","activitypub"),{code:(0,n.createElement)("code",null)})),(0,n.createElement)("div",{className:"apfmd__button-group"},(0,n.createElement)("input",{type:"text",value:g,onKeyDown:e=>{"Enter"===e?.code&&x()},onChange:e=>k(e.target.value)}),(0,n.createElement)(i.Button,{onClick:x},y))))}function N({selectedUser:e,style:t,backgroundColor:r,id:o,useId:a=!1,profileData:l=!1}){const[i,u]=(0,n.useState)(g()),s="site"===e?0:e,p=function(e){return b(".apfmd__button-group .components-button",y(e?.elements?.link?.color?.text)||"#111","#fff",y(e?.elements?.link?.[":hover"]?.color?.text)||"#333")}(t),m=a?{id:o}:{};function d(e){u(g(e))}return(0,n.useEffect)((()=>{if(l)return d(l);(function(e){const t={headers:{Accept:"application/activity+json"},path:`/${h}/users/${e}`};return c()(t)})(s).then(d)}),[s,l]),(0,n.createElement)("div",{...m},(0,n.createElement)(_,{selector:`#${o}`,style:t,backgroundColor:r}),(0,n.createElement)(k,{profile:i,userId:s,popupStyles:p}))}let S=1;a()((()=>{[].forEach.call(document.querySelectorAll(".activitypub-follow-me-block-wrapper"),(e=>{const t=JSON.parse(e.dataset.attrs);(0,n.render)((0,n.createElement)(N,{...t,id:"activitypub-follow-me-block-"+S++,useId:!0}),e)}))}))}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.m=t,e=[],n.O=(t,r,o,a)=>{if(!r){var l=1/0;for(s=0;s<e.length;s++){r=e[s][0],o=e[s][1],a=e[s][2];for(var c=!0,i=0;i<r.length;i++)(!1&a||l>=a)&&Object.keys(n.O).every((e=>n.O[e](r[i])))?r.splice(i--,1):(c=!1,a<l&&(l=a));if(c){e.splice(s--,1);var u=o();void 0!==u&&(t=u)}}return t}a=a||0;for(var s=e.length;s>0&&e[s-1][2]>a;s--)e[s]=e[s-1];e[s]=[r,o,a]},n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={529:0,740:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var o,a,l=r[0],c=r[1],i=r[2],u=0;if(l.some((t=>0!==e[t]))){for(o in c)n.o(c,o)&&(n.m[o]=c[o]);if(i)var s=i(n)}for(t&&t(r);u<l.length;u++)a=l[u],n.o(e,a)&&e[a]&&e[a][0](),e[a]=0;return n.O(s)},r=self.webpackChunkwordpress_activitypub=self.webpackChunkwordpress_activitypub||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var o=n.O(void 0,[740],(()=>n(703)));o=n.O(o)})();