wordpress-activitypub/build/follow-me/view.js
Matthias Pfefferle b240589e78
Add "reply context" support (#819)
* add basic reply context support

* UX improvements

* remove unused style file

* built

* Add bookmarklet!

* add build

* small UX tweaks

* add toolbox box

* improved text

* optimized block filter

* add in-reply-to to activity

* refactor to add inboxes using filters

and retrieve/add inboxes of `in-reply-to` links

* renamings

* plugins do not like slashed IDs

* rename to match new get param

---------

Co-authored-by: Matt Wiebe <wiebe@automattic.com>
2024-07-24 23:44:01 +02:00

1 line
No EOL
8.9 KiB
JavaScript

(()=>{"use strict";var e,t={729:(e,t,r)=>{var o=r(609);const n=window.wp.element,i=window.wp.domReady;var a=r.n(i);const l=window.wp.apiFetch;var c=r.n(l);const s=window.wp.components,u=window.wp.i18n;var p=r(848);function d(e){return`var(--wp--preset--color--${e})`}function v(e){if("string"!=typeof e)return null;if(e.match(/^#/))return e.substring(0,7);const[,,t]=e.split("|");return d(t)}function f(e,t,r=null,o=""){return r?`${e}${o} { ${t}: ${r}; }\n`:""}function m(e,t,r,o){return f(e,"background-color",t)+f(e,"color",r)+f(e,"background-color",o,":hover")+f(e,"background-color",o,":focus")}function y({selector:e,style:t,backgroundColor:r}){const o=function(e,t,r){const o=`${e} .components-button`,n=("string"==typeof(i=r)?d(i):i?.color?.background||null)||t?.color?.background;var i;return m(o,v(t?.elements?.link?.color?.text),n,v(t?.elements?.link?.[":hover"]?.color?.text))}(e,t,r);return(0,p.jsx)("style",{children:o})}const _=window.wp.primitives,b=(0,p.jsx)(_.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,p.jsx)(_.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M5 4.5h11a.5.5 0 0 1 .5.5v11a.5.5 0 0 1-.5.5H5a.5.5 0 0 1-.5-.5V5a.5.5 0 0 1 .5-.5ZM3 5a2 2 0 0 1 2-2h11a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5Zm17 3v10.75c0 .69-.56 1.25-1.25 1.25H6v1.5h12.75a2.75 2.75 0 0 0 2.75-2.75V8H20Z"})}),h=(0,p.jsx)(_.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,p.jsx)(_.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})}),w=(0,n.forwardRef)((function({icon:e,size:t=24,...r},o){return(0,n.cloneElement)(e,{width:t,height:t,...r,ref:o})})),g=(0,p.jsx)(_.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,p.jsx)(_.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"})}),x=window.wp.compose,k="fediverse-remote-user";function E(e){try{return new URL(e),!0}catch(e){return!1}}function j({actionText:e,copyDescription:t,handle:r,resourceUrl:i,myProfile:a=!1,rememberProfile:l=!1}){const p=(0,u.__)("Loading...","activitypub"),d=(0,u.__)("Opening...","activitypub"),v=(0,u.__)("Error","activitypub"),f=(0,u.__)("Invalid","activitypub"),m=a||(0,u.__)("My Profile","activitypub"),[y,_]=(0,n.useState)(e),[j,O]=(0,n.useState)(b),S=(0,x.useCopyToClipboard)(r,(()=>{O(h),setTimeout((()=>O(b)),1e3)})),[C,N]=(0,n.useState)(""),[R,I]=(0,n.useState)(!0),{setRemoteUser:P}=function(){const[e,t]=(0,n.useState)(function(){const e=localStorage.getItem(k);return e?JSON.parse(e):{}}()),r=(0,n.useCallback)((e=>{!function(e){localStorage.setItem(k,JSON.stringify(e))}(e),t(e)}),[]),o=(0,n.useCallback)((()=>{localStorage.removeItem(k),t({})}),[]);return{template:e?.template||!1,profileURL:e?.profileURL||!1,setRemoteUser:r,deleteRemoteUser:o}}(),$=(0,n.useCallback)((()=>{let t;if(!E(C)&&!function(e){const t=e.replace(/^@/,"").split("@");return 2===t.length&&E(`https://${t[1]}`)}(C))return _(f),t=setTimeout((()=>_(e)),2e3),()=>clearTimeout(t);const r=i+C;_(p),c()({path:r}).then((({url:t,template:r})=>{R&&P({profileURL:C,template:r}),_(d),setTimeout((()=>{window.open(t,"_blank"),_(e)}),200)})).catch((()=>{_(v),setTimeout((()=>_(e)),2e3)}))}),[C]);return(0,o.createElement)("div",{className:"activitypub__dialog"},(0,o.createElement)("div",{className:"activitypub-dialog__section"},(0,o.createElement)("h4",null,m),(0,o.createElement)("div",{className:"activitypub-dialog__description"},t),(0,o.createElement)("div",{className:"activitypub-dialog__button-group"},(0,o.createElement)("input",{type:"text",value:r,readOnly:!0}),(0,o.createElement)(s.Button,{ref:S},(0,o.createElement)(w,{icon:j}),(0,u.__)("Copy","activitypub")))),(0,o.createElement)("div",{className:"activitypub-dialog__section"},(0,o.createElement)("h4",null,(0,u.__)("Your Profile","activitypub")),(0,o.createElement)("div",{className:"activitypub-dialog__description"},(0,n.createInterpolateElement)((0,u.__)("Or, if you know your own profile, we can start things that way! (eg <code>yourusername@example.com</code>)","activitypub"),{code:(0,o.createElement)("code",null)})),(0,o.createElement)("div",{className:"activitypub-dialog__button-group"},(0,o.createElement)("input",{type:"text",value:C,onKeyDown:e=>{"Enter"===e?.code&&$()},onChange:e=>N(e.target.value)}),(0,o.createElement)(s.Button,{onClick:$},(0,o.createElement)(w,{icon:g}),y)),l&&(0,o.createElement)("div",{className:"activitypub-dialog__remember"},(0,o.createElement)(s.CheckboxControl,{checked:R,label:(0,u.__)("Remember me for easier comments","activitypub"),onChange:()=>{I(!R)}}))))}const{namespace:O}=window._activityPubOptions,S={avatar:"",webfinger:"@well@hello.dolly",name:(0,u.__)("Hello Dolly Fan Account","activitypub"),url:"#"};function C(e){if(!e)return S;const t={...S,...e};return t.avatar=t?.icon?.url,t}function N({profile:e,popupStyles:t,userId:r}){const{avatar:o,name:n,webfinger:i}=e;return(0,p.jsxs)("div",{className:"activitypub-profile",children:[(0,p.jsx)("img",{className:"activitypub-profile__avatar",src:o,alt:n}),(0,p.jsxs)("div",{className:"activitypub-profile__content",children:[(0,p.jsx)("div",{className:"activitypub-profile__name",children:n}),(0,p.jsx)("div",{className:"activitypub-profile__handle",title:i,children:i})]}),(0,p.jsx)(R,{profile:e,popupStyles:t,userId:r})]})}function R({profile:e,popupStyles:t,userId:r}){const[o,i]=(0,n.useState)(!1),a=(0,u.sprintf)((0,u.__)("Follow %s","activitypub"),e?.name);return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(s.Button,{className:"activitypub-profile__follow",onClick:()=>i(!0),children:(0,u.__)("Follow","activitypub")}),o&&(0,p.jsxs)(s.Modal,{className:"activitypub-profile__confirm activitypub__modal",onRequestClose:()=>i(!1),title:a,children:[(0,p.jsx)(I,{profile:e,userId:r}),(0,p.jsx)("style",{children:t})]})]})}function I({profile:e,userId:t}){const{webfinger:r}=e,o=(0,u.__)("Follow","activitypub"),n=`/${O}/actors/${t}/remote-follow?resource=`,i=(0,u.__)("Copy and paste my profile into the search field of your favorite fediverse app or server.","activitypub");return(0,p.jsx)(j,{actionText:o,copyDescription:i,handle:r,resourceUrl:n})}function P({selectedUser:e,style:t,backgroundColor:r,id:o,useId:i=!1,profileData:a=!1}){const[l,s]=(0,n.useState)(C()),u="site"===e?0:e,d=function(e){return m(".apfmd__button-group .components-button",v(e?.elements?.link?.color?.text)||"#111","#fff",v(e?.elements?.link?.[":hover"]?.color?.text)||"#333")}(t),f=i?{id:o}:{};function _(e){s(C(e))}return(0,n.useEffect)((()=>{if(a)return _(a);(function(e){const t={headers:{Accept:"application/activity+json"},path:`/${O}/actors/${e}`};return c()(t)})(u).then(_)}),[u,a]),(0,p.jsxs)("div",{...f,children:[(0,p.jsx)(y,{selector:`#${o}`,style:t,backgroundColor:r}),(0,p.jsx)(N,{profile:l,userId:u,popupStyles:d})]})}let $=1;a()((()=>{[].forEach.call(document.querySelectorAll(".activitypub-follow-me-block-wrapper"),(e=>{const t=JSON.parse(e.dataset.attrs);(0,n.createRoot)(e).render((0,o.createElement)(P,{...t,id:"activitypub-follow-me-block-"+$++,useId:!0}))}))}))},20:(e,t,r)=>{var o=r(609),n=Symbol.for("react.element"),i=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,l=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function s(e,t,r){var o,i={},s=null,u=null;for(o in void 0!==r&&(s=""+r),void 0!==t.key&&(s=""+t.key),void 0!==t.ref&&(u=t.ref),t)a.call(t,o)&&!c.hasOwnProperty(o)&&(i[o]=t[o]);if(e&&e.defaultProps)for(o in t=e.defaultProps)void 0===i[o]&&(i[o]=t[o]);return{$$typeof:n,type:e,key:s,ref:u,props:i,_owner:l.current}}t.Fragment=i,t.jsx=s,t.jsxs=s},848:(e,t,r)=>{e.exports=r(20)},609:e=>{e.exports=window.React}},r={};function o(e){var n=r[e];if(void 0!==n)return n.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,o),i.exports}o.m=t,e=[],o.O=(t,r,n,i)=>{if(!r){var a=1/0;for(u=0;u<e.length;u++){for(var[r,n,i]=e[u],l=!0,c=0;c<r.length;c++)(!1&i||a>=i)&&Object.keys(o.O).every((e=>o.O[e](r[c])))?r.splice(c--,1):(l=!1,i<a&&(a=i));if(l){e.splice(u--,1);var s=n();void 0!==s&&(t=s)}}return t}i=i||0;for(var u=e.length;u>0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[r,n,i]},o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={41:0,301:0};o.O.j=t=>0===e[t];var t=(t,r)=>{var n,i,[a,l,c]=r,s=0;if(a.some((t=>0!==e[t]))){for(n in l)o.o(l,n)&&(o.m[n]=l[n]);if(c)var u=c(o)}for(t&&t(r);s<a.length;s++)i=a[s],o.o(e,i)&&e[i]&&e[i][0](),e[i]=0;return o.O(u)},r=globalThis.webpackChunkwordpress_activitypub=globalThis.webpackChunkwordpress_activitypub||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var n=o.O(void 0,[301],(()=>o(729)));n=o.O(n)})();