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

1 line
8.1 KiB
JavaScript

(()=>{"use strict";var e,t={454:(e,t,n)=>{const r=window.wp.blocks,o=window.wp.element,l=window.wp.primitives,a=(0,o.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.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"})),c=window.wp.blockEditor,i=window.wp.i18n,s=window.wp.components,u=window.wp.data,p=window._activityPubOptions?.enabled,m=window.wp.apiFetch;var d=n.n(m);const v=(0,o.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(l.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"})),f=(0,o.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(l.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})),w=function({icon:e,size:t=24,...n}){return(0,o.cloneElement)(e,{width:t,height:t,...n})},b=window.wp.compose;function y(e){return`var(--wp--preset--color--${e})`}function _(e){if("string"!=typeof e)return null;if(e.match(/^#/))return e.substring(0,7);const[,,t]=e.split("|");return y(t)}function h(e,t,n=null,r=""){return n?`${e}${r} { ${t}: ${n}; }\n`:""}function E(e,t,n,r){return h(e,"background-color",t)+h(e,"color",n)+h(e,"background-color",r,":hover")+h(e,"background-color",r,":focus")}function g({selector:e,style:t,backgroundColor:n}){const r=function(e,t,n){const r=`${e} .components-button`,o=("string"==typeof(l=n)?y(l):l?.color?.background||null)||t?.color?.background;var l;return E(r,_(t?.elements?.link?.color?.text),o,_(t?.elements?.link?.[":hover"]?.color?.text))}(e,t,n);return(0,o.createElement)("style",null,r)}const{namespace:k}=window._activityPubOptions,x={avatar:"",webfinger:"@well@hello.dolly",name:(0,i.__)("Hello Dolly Fan Account","activitypub"),url:"#"};function C(e){if(!e)return x;const t={...x,...e};return t.avatar=t?.icon?.url,t}function O({profile:e,popupStyles:t,userId:n}){const{avatar:r,name:l,webfinger:a}=e;return(0,o.createElement)("div",{className:"activitypub-profile"},(0,o.createElement)("img",{className:"activitypub-profile__avatar",src:r,alt:l}),(0,o.createElement)("div",{className:"activitypub-profile__content"},(0,o.createElement)("div",{className:"activitypub-profile__name"},l),(0,o.createElement)("div",{className:"activitypub-profile__handle",title:a},a)),(0,o.createElement)(S,{profile:e,popupStyles:t,userId:n}))}function S({profile:e,popupStyles:t,userId:n}){const[r,l]=(0,o.useState)(!1),a=(0,i.sprintf)((0,i.__)("Follow %s","activitypub"),e?.name);return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(s.Button,{className:"activitypub-profile__follow",onClick:()=>l(!0)},(0,i.__)("Follow","activitypub")),r&&(0,o.createElement)(s.Modal,{className:"activitypub-profile__confirm",onRequestClose:()=>l(!1),title:a},(0,o.createElement)($,{profile:e,userId:n}),(0,o.createElement)("style",null,t)))}function N(e){try{return new URL(e),!0}catch(e){return!1}}function $({profile:e,userId:t}){const{webfinger:n}=e,r=(0,i.__)("Follow","activitypub"),l=(0,i.__)("Loading...","activitypub"),a=(0,i.__)("Opening...","activitypub"),c=(0,i.__)("Error","activitypub"),u=(0,i.__)("Invalid","activitypub"),[p,m]=(0,o.useState)(r),[y,_]=(0,o.useState)(v),h=(0,b.useCopyToClipboard)(n,(()=>{_(f),setTimeout((()=>_(v)),1e3)})),[E,g]=(0,o.useState)(""),x=(0,o.useCallback)((()=>{let e;if(!N(E)&&!function(e){const t=e.replace(/^@/,"").split("@");return 2===t.length&&N(`https://${t[1]}`)}(E))return m(u),e=setTimeout((()=>m(r)),2e3),()=>clearTimeout(e);const n=`/${k}/users/${t}/remote-follow?resource=${E}`;m(l),d()({path:n}).then((({url:e})=>{m(a),setTimeout((()=>{window.open(e,"_blank"),m(r)}),200)})).catch((()=>{m(c),setTimeout((()=>m(r)),2e3)}))}),[E]);return(0,o.createElement)("div",{className:"activitypub-follow-me__dialog"},(0,o.createElement)("div",{className:"apmfd__section"},(0,o.createElement)("h4",null,(0,i.__)("My Profile","activitypub")),(0,o.createElement)("div",{className:"apfmd-description"},(0,i.__)("Copy and paste my profile into the search field of your favorite fediverse app or server.","activitypub")),(0,o.createElement)("div",{className:"apfmd__button-group"},(0,o.createElement)("input",{type:"text",value:n,readOnly:!0}),(0,o.createElement)(s.Button,{ref:h},(0,o.createElement)(w,{icon:y}),(0,i.__)("Copy","activitypub")))),(0,o.createElement)("div",{className:"apmfd__section"},(0,o.createElement)("h4",null,(0,i.__)("Your Profile","activitypub")),(0,o.createElement)("div",{className:"apfmd-description"},(0,o.createInterpolateElement)((0,i.__)("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,o.createElement)("code",null)})),(0,o.createElement)("div",{className:"apfmd__button-group"},(0,o.createElement)("input",{type:"text",value:E,onKeyDown:e=>{"Enter"===e?.code&&x()},onChange:e=>g(e.target.value)}),(0,o.createElement)(s.Button,{onClick:x},p))))}function z({selectedUser:e,style:t,backgroundColor:n,id:r,useId:l=!1,profileData:a=!1}){const[c,i]=(0,o.useState)(C()),s="site"===e?0:e,u=function(e){return E(".apfmd__button-group .components-button",_(e?.elements?.link?.color?.text)||"#111","#fff",_(e?.elements?.link?.[":hover"]?.color?.text)||"#333")}(t),p=l?{id:r}:{};function m(e){i(C(e))}return(0,o.useEffect)((()=>{if(a)return m(a);(function(e){const t={headers:{Accept:"application/activity+json"},path:`/${k}/users/${e}`};return d()(t)})(s).then(m)}),[s,a]),(0,o.createElement)("div",{...p},(0,o.createElement)(g,{selector:`#${r}`,style:t,backgroundColor:n}),(0,o.createElement)(O,{profile:c,userId:s,popupStyles:u}))}(0,r.registerBlockType)("activitypub/follow-me",{edit:function({attributes:e,setAttributes:t}){const n=(0,c.useBlockProps)({className:"activitypub-follow-me-block-wrapper"}),r=function(){const e=p?.users?(0,u.useSelect)((e=>e("core").getUsers({who:"authors"}))):[];return(0,o.useMemo)((()=>{if(!e)return[];const t=p?.site?[{label:(0,i.__)("Whole Site","activitypub"),value:"site"}]:[];return e.reduce(((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e)),t)}),[e])}(),{selectedUser:l}=e;return(0,o.useEffect)((()=>{r.length&&(r.find((({value:e})=>e===l))||t({selectedUser:r[0].value}))}),[l,r]),(0,o.createElement)("div",{...n},r.length>1&&(0,o.createElement)(c.InspectorControls,{key:"setting"},(0,o.createElement)(s.PanelBody,{title:(0,i.__)("Followers Options","activitypub")},(0,o.createElement)(s.SelectControl,{label:(0,i.__)("Select User","activitypub"),value:e.selectedUser,options:r,onChange:e=>t({selectedUser:e})}))),(0,o.createElement)(z,{...e,id:n.id}))},save:()=>null,icon:a})}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var l=n[e]={exports:{}};return t[e](l,l.exports,r),l.exports}r.m=t,e=[],r.O=(t,n,o,l)=>{if(!n){var a=1/0;for(u=0;u<e.length;u++){n=e[u][0],o=e[u][1],l=e[u][2];for(var c=!0,i=0;i<n.length;i++)(!1&l||a>=l)&&Object.keys(r.O).every((e=>r.O[e](n[i])))?n.splice(i--,1):(c=!1,l<a&&(a=l));if(c){e.splice(u--,1);var s=o();void 0!==s&&(t=s)}}return t}l=l||0;for(var u=e.length;u>0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[n,o,l]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={127:0,740:0};r.O.j=t=>0===e[t];var t=(t,n)=>{var o,l,a=n[0],c=n[1],i=n[2],s=0;if(a.some((t=>0!==e[t]))){for(o in c)r.o(c,o)&&(r.m[o]=c[o]);if(i)var u=i(r)}for(t&&t(n);s<a.length;s++)l=a[s],r.o(e,l)&&e[l]&&e[l][0](),e[l]=0;return r.O(u)},n=self.webpackChunkwordpress_activitypub=self.webpackChunkwordpress_activitypub||[];n.forEach(t.bind(null,0)),n.push=t.bind(null,n.push.bind(n))})();var o=r.O(void 0,[740],(()=>r(454)));o=r.O(o)})();