diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a9a7f9b9..d54c439ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +* Button only mode for the "Follow Me" Block * Support for WPML post locale ### Removed @@ -32,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Hide ActivityPub post meta keys from the custom Fields UI * Bumped minimum required PHP version to 7.2 +* Print `_activityPubOptions` in the `wp_footer` action on the frontend. ### Fixed @@ -40,9 +42,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fetching replies from the same instance for Enable Mastodon Apps * Image captions not being included in the ActivityPub representation when the image is attached to the post -### Changed -* Print `_activityPubOptions` in the `wp_footer` action on the frontend. - ## [4.6.0] - 2024-12-20 ### Added diff --git a/build/follow-me/block.json b/build/follow-me/block.json index edeb67c73..e799fbb58 100644 --- a/build/follow-me/block.json +++ b/build/follow-me/block.json @@ -36,6 +36,23 @@ "selectedUser": { "type": "string", "default": "site" + }, + "buttonOnly": { + "type": "boolean", + "default": false + }, + "buttonText": { + "type": "string", + "default": "Follow" + }, + "buttonSize": { + "type": "string", + "default": "default", + "enum": [ + "small", + "default", + "compact" + ] } }, "usesContext": [ diff --git a/build/follow-me/index.asset.php b/build/follow-me/index.asset.php index d5face1ed..34c7e34b8 100644 --- a/build/follow-me/index.asset.php +++ b/build/follow-me/index.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '62610556ba8e5f129fdf'); + array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '6074e38f927a0105218a'); diff --git a/build/follow-me/index.js b/build/follow-me/index.js index cd4eff04e..4f053f7aa 100644 --- a/build/follow-me/index.js +++ b/build/follow-me/index.js @@ -1,2 +1,2 @@ -(()=>{"use strict";var e,t={399:(e,t,r)=>{const o=window.wp.blocks,n=window.wp.primitives;var i=r(848);const a=(0,i.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(n.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"})});var l=r(609);const c=window.wp.blockEditor,s=window.wp.i18n,u=window.wp.data,p=window.wp.coreData,d=window.wp.components,m=window.wp.element,v=window._activityPubOptions?.enabled,f=window.wp.apiFetch;var y=r.n(f);function b(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 b(t)}function w(e,t,r=null,o=""){return r?`${e}${o} { ${t}: ${r}; }\n`:""}function h(e,t,r,o){return w(e,"background-color",t)+w(e,"color",r)+w(e,"background-color",o,":hover")+w(e,"background-color",o,":focus")}function g({selector:e,style:t,backgroundColor:r}){const o=function(e,t,r){const o=`${e} .components-button`,n=("string"==typeof(i=r)?b(i):i?.color?.background||null)||t?.color?.background;var i;return h(o,_(t?.elements?.link?.color?.text),n,_(t?.elements?.link?.[":hover"]?.color?.text))}(e,t,r);return(0,l.createElement)("style",null,o)}const E=(0,i.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(n.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"})}),k=(0,i.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(n.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})}),x=(0,m.forwardRef)((function({icon:e,size:t=24,...r},o){return(0,m.cloneElement)(e,{width:t,height:t,...r,ref:o})})),S=window.wp.compose,O="fediverse-remote-user";function C(e){try{return new URL(e),!0}catch(e){return!1}}function N({actionText:e,copyDescription:t,handle:r,resourceUrl:o,myProfile:n=!1,rememberProfile:i=!1}){const c=(0,s.__)("Loading...","activitypub"),u=(0,s.__)("Opening...","activitypub"),p=(0,s.__)("Error","activitypub"),v=(0,s.__)("Invalid","activitypub"),f=n||(0,s.__)("My Profile","activitypub"),[b,_]=(0,m.useState)(e),[w,h]=(0,m.useState)(E),g=(0,S.useCopyToClipboard)(r,(()=>{h(k),setTimeout((()=>h(E)),1e3)})),[N,I]=(0,m.useState)(""),[R,U]=(0,m.useState)(!0),{setRemoteUser:P}=function(){const[e,t]=(0,m.useState)(function(){const e=localStorage.getItem(O);return e?JSON.parse(e):{}}()),r=(0,m.useCallback)((e=>{!function(e){localStorage.setItem(O,JSON.stringify(e))}(e),t(e)}),[]),o=(0,m.useCallback)((()=>{localStorage.removeItem(O),t({})}),[]);return{template:e?.template||!1,profileURL:e?.profileURL||!1,setRemoteUser:r,deleteRemoteUser:o}}(),$=(0,m.useCallback)((()=>{let t;if(!C(N)&&!function(e){const t=e.replace(/^@/,"").split("@");return 2===t.length&&C(`https://${t[1]}`)}(N))return _(v),t=setTimeout((()=>_(e)),2e3),()=>clearTimeout(t);const r=o+N;_(c),y()({path:r}).then((({url:t,template:r})=>{R&&P({profileURL:N,template:r}),_(u),setTimeout((()=>{window.open(t,"_blank"),_(e)}),200)})).catch((()=>{_(p),setTimeout((()=>_(e)),2e3)}))}),[N]);return(0,l.createElement)("div",{className:"activitypub__dialog",role:"dialog","aria-labelledby":"dialog-title"},(0,l.createElement)("div",{className:"activitypub-dialog__section"},(0,l.createElement)("h4",{id:"dialog-title"},f),(0,l.createElement)("div",{className:"activitypub-dialog__description",id:"copy-description"},t),(0,l.createElement)("div",{className:"activitypub-dialog__button-group"},(0,l.createElement)("label",{htmlFor:"profile-handle",className:"screen-reader-text"},t),(0,l.createElement)("input",{type:"text",id:"profile-handle",value:r,readOnly:!0}),(0,l.createElement)(d.Button,{ref:g,"aria-label":(0,s.__)("Copy handle to clipboard","activitypub")},(0,l.createElement)(x,{icon:w}),(0,s.__)("Copy","activitypub")))),(0,l.createElement)("div",{className:"activitypub-dialog__section"},(0,l.createElement)("h4",{id:"remote-profile-title"},(0,s.__)("Your Profile","activitypub")),(0,l.createElement)("div",{className:"activitypub-dialog__description",id:"remote-profile-description"},(0,m.createInterpolateElement)((0,s.__)("Or, if you know your own profile, we can start things that way! (eg @yourusername@example.com)","activitypub"),{code:(0,l.createElement)("code",null)})),(0,l.createElement)("div",{className:"activitypub-dialog__button-group"},(0,l.createElement)("label",{htmlFor:"remote-profile",className:"screen-reader-text"},(0,s.__)("Enter your ActivityPub profile","activitypub")),(0,l.createElement)("input",{type:"text",id:"remote-profile",value:N,onKeyDown:e=>{"Enter"===e?.code&&$()},onChange:e=>I(e.target.value),"aria-invalid":b===v}),(0,l.createElement)(d.Button,{onClick:$,"aria-label":(0,s.__)("Submit profile","activitypub")},(0,l.createElement)(x,{icon:a}),b)),i&&(0,l.createElement)("div",{className:"activitypub-dialog__remember"},(0,l.createElement)(d.CheckboxControl,{checked:R,label:(0,s.__)("Remember me for easier comments","activitypub"),onChange:()=>{U(!R)}}))))}const{namespace:I}=window._activityPubOptions,R={avatar:"",webfinger:"@well@hello.dolly",name:(0,s.__)("Hello Dolly Fan Account","activitypub"),url:"#"};function U(e){if(!e)return R;const t={...R,...e};return t.avatar=t?.icon?.url,t}function P({profile:e,popupStyles:t,userId:r}){const{webfinger:o,avatar:n,name:i}=e,a=o.startsWith("@")?o:`@${o}`;return(0,l.createElement)("div",{className:"activitypub-profile"},(0,l.createElement)("img",{className:"activitypub-profile__avatar",src:n,alt:i}),(0,l.createElement)("div",{className:"activitypub-profile__content"},(0,l.createElement)("div",{className:"activitypub-profile__name"},i),(0,l.createElement)("div",{className:"activitypub-profile__handle",title:a},a)),(0,l.createElement)($,{profile:e,popupStyles:t,userId:r}))}function $({profile:e,popupStyles:t,userId:r}){const[o,n]=(0,m.useState)(!1),i=(0,s.sprintf)((0,s.__)("Follow %s","activitypub"),e?.name);return(0,l.createElement)(l.Fragment,null,(0,l.createElement)(d.Button,{className:"activitypub-profile__follow",onClick:()=>n(!0),"aria-haspopup":"dialog","aria-expanded":o,"aria-label":(0,s.__)("Follow me on the Fediverse","activitypub")},(0,s.__)("Follow","activitypub")),o&&(0,l.createElement)(d.Modal,{className:"activitypub-profile__confirm activitypub__modal",onRequestClose:()=>n(!1),title:i,"aria-label":i,role:"dialog"},(0,l.createElement)(T,{profile:e,userId:r}),(0,l.createElement)("style",null,t)))}function T({profile:e,userId:t}){const{webfinger:r}=e,o=(0,s.__)("Follow","activitypub"),n=`/${I}/actors/${t}/remote-follow?resource=`,i=(0,s.__)("Copy and paste my profile into the search field of your favorite fediverse app or server.","activitypub"),a=r.startsWith("@")?r:`@${r}`;return(0,l.createElement)(N,{actionText:o,copyDescription:i,handle:a,resourceUrl:n})}function j({selectedUser:e,style:t,backgroundColor:r,id:o,useId:n=!1,profileData:i=!1}){const[a,c]=(0,m.useState)(U()),s="site"===e?0:e,u=function(e){return h(".apfmd__button-group .components-button",_(e?.elements?.link?.color?.text)||"#111","#fff",_(e?.elements?.link?.[":hover"]?.color?.text)||"#333")}(t),p=n?{id:o}:{};function d(e){c(U(e))}return(0,m.useEffect)((()=>{if(i)return d(i);(function(e){const t={headers:{Accept:"application/activity+json"},path:`/${I}/actors/${e}`};return y()(t)})(s).then(d)}),[s,i]),(0,l.createElement)("div",{...p},(0,l.createElement)(g,{selector:`#${o}`,style:t,backgroundColor:r}),(0,l.createElement)(P,{profile:a,userId:s,popupStyles:u}))}const F=window._activityPubOptions?.enabled;function B({name:e}){const t=F?.site?"":(0,s.__)("It will be empty in other non-author contexts.","activitypub"),r=(0,s.sprintf)(/* translators: %1$s: block name, %2$s: extra information for non-author context */ /* translators: %1$s: block name, %2$s: extra information for non-author context */ -(0,s.__)("This %1$s block will adapt to the page it is on, displaying the user profile associated with a post author (in a loop) or a user archive. %2$s","activitypub"),e,t).trim();return(0,l.createElement)(d.Card,null,(0,l.createElement)(d.CardBody,null,(0,m.createInterpolateElement)(r,{strong:(0,l.createElement)("strong",null)})))}(0,o.registerBlockType)("activitypub/follow-me",{edit:function({attributes:e,setAttributes:t,context:{postType:r,postId:o}}){const n=(0,c.useBlockProps)({className:"activitypub-follow-me-block-wrapper"}),i=function({withInherit:e=!1}){const t=v?.users?(0,u.useSelect)((e=>e("core").getUsers({who:"authors"}))):[];return(0,m.useMemo)((()=>{if(!t)return[];const r=[];return v?.site&&r.push({label:(0,s.__)("Site","activitypub"),value:"site"}),e&&v?.users&&r.push({label:(0,s.__)("Dynamic User","activitypub"),value:"inherit"}),t.reduce(((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e)),r)}),[t])}({withInherit:!0}),{selectedUser:a}=e,f="inherit"===a,y=(0,u.useSelect)((e=>{const{getEditedEntityRecord:t}=e(p.store),n=t("postType",r,o)?.author;return null!=n?n:null}),[r,o]);return(0,m.useEffect)((()=>{i.length&&(i.find((({value:e})=>e===a))||t({selectedUser:i[0].value}))}),[a,i]),(0,l.createElement)("div",{...n},i.length>1&&(0,l.createElement)(c.InspectorControls,{key:"setting"},(0,l.createElement)(d.PanelBody,{title:(0,s.__)("Followers Options","activitypub")},(0,l.createElement)(d.SelectControl,{label:(0,s.__)("Select User","activitypub"),value:e.selectedUser,options:i,onChange:e=>t({selectedUser:e})}))),f?y?(0,l.createElement)(j,{...e,id:n.id,selectedUser:y}):(0,l.createElement)(B,{name:(0,s.__)("Follow Me","activitypub")}):(0,l.createElement)(j,{...e,id:n.id}))},save:()=>null,icon:a})},20:(e,t,r)=>{var o=r(609),n=Symbol.for("react.element"),i=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),a=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};t.jsx=function(e,t,r){var o,c={},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)i.call(t,o)&&!l.hasOwnProperty(o)&&(c[o]=t[o]);if(e&&e.defaultProps)for(o in t=e.defaultProps)void 0===c[o]&&(c[o]=t[o]);return{$$typeof:n,type:e,key:s,ref:u,props:c,_owner:a.current}}},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=i)&&Object.keys(o.O).every((e=>o.O[e](r[c])))?r.splice(c--,1):(l=!1,i0&&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={338:0,301:0};o.O.j=t=>0===e[t];var t=(t,r)=>{var n,i,a=r[0],l=r[1],c=r[2],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);so(399)));n=o.O(n)})(); \ No newline at end of file +(()=>{"use strict";var e,t={420:(e,t,o)=>{const l=window.wp.blocks,a=window.React,n=window.wp.primitives,i=(0,a.createElement)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,a.createElement)(n.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"})),r=window.wp.blockEditor,c=window.wp.i18n,u=window.wp.data,s=window.wp.coreData,p=window.wp.components,m=window.wp.element,d=window._activityPubOptions?.enabled,b=window.wp.apiFetch;var v=o.n(b);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 _(e,t,o=null,l=""){return o?`${e}${l} { ${t}: ${o}; }\n`:""}function h(e,t,o,l){return _(e,"background-color",t)+_(e,"color",o)+_(e,"background-color",l,":hover")+_(e,"background-color",l,":focus")}function w({selector:e,style:t,backgroundColor:o}){const l=function(e,t,o){const l=`${e} .components-button`,a=("string"==typeof(n=o)?f(n):n?.color?.background||null)||t?.color?.background;var n;return h(l,y(t?.elements?.link?.color?.text),a,y(t?.elements?.link?.[":hover"]?.color?.text))}(e,t,o);return(0,a.createElement)("style",null,l)}const g=(0,a.createElement)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,a.createElement)(n.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"})),E=(0,a.createElement)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,a.createElement)(n.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})),S=(0,m.forwardRef)((function({icon:e,size:t=24,...o},l){return(0,m.cloneElement)(e,{width:t,height:t,...o,ref:l})})),k=window.wp.compose,x="fediverse-remote-user";function C(e){try{return new URL(e),!0}catch(e){return!1}}function O({actionText:e,copyDescription:t,handle:o,resourceUrl:l,myProfile:n=!1,rememberProfile:r=!1}){const u=(0,c.__)("Loading...","activitypub"),s=(0,c.__)("Opening...","activitypub"),d=(0,c.__)("Error","activitypub"),b=(0,c.__)("Invalid","activitypub"),f=n||(0,c.__)("My Profile","activitypub"),[y,_]=(0,m.useState)(e),[h,w]=(0,m.useState)(g),O=(0,k.useCopyToClipboard)(o,(()=>{w(E),setTimeout((()=>w(g)),1e3)})),[T,N]=(0,m.useState)(""),[z,I]=(0,m.useState)(!0),{setRemoteUser:U}=function(){const[e,t]=(0,m.useState)(function(){const e=localStorage.getItem(x);return e?JSON.parse(e):{}}()),o=(0,m.useCallback)((e=>{!function(e){localStorage.setItem(x,JSON.stringify(e))}(e),t(e)}),[]),l=(0,m.useCallback)((()=>{localStorage.removeItem(x),t({})}),[]);return{template:e?.template||!1,profileURL:e?.profileURL||!1,setRemoteUser:o,deleteRemoteUser:l}}(),$=(0,m.useCallback)((()=>{let t;if(!C(T)&&!function(e){const t=e.replace(/^@/,"").split("@");return 2===t.length&&C(`https://${t[1]}`)}(T))return _(b),t=setTimeout((()=>_(e)),2e3),()=>clearTimeout(t);const o=l+T;_(u),v()({path:o}).then((({url:t,template:o})=>{z&&U({profileURL:T,template:o}),_(s),setTimeout((()=>{window.open(t,"_blank"),_(e)}),200)})).catch((()=>{_(d),setTimeout((()=>_(e)),2e3)}))}),[T]);return(0,a.createElement)("div",{className:"activitypub__dialog",role:"dialog","aria-labelledby":"dialog-title"},(0,a.createElement)("div",{className:"activitypub-dialog__section"},(0,a.createElement)("h4",{id:"dialog-title"},f),(0,a.createElement)("div",{className:"activitypub-dialog__description",id:"copy-description"},t),(0,a.createElement)("div",{className:"activitypub-dialog__button-group"},(0,a.createElement)("label",{htmlFor:"profile-handle",className:"screen-reader-text"},t),(0,a.createElement)("input",{type:"text",id:"profile-handle",value:o,readOnly:!0}),(0,a.createElement)(p.Button,{ref:O,"aria-label":(0,c.__)("Copy handle to clipboard","activitypub")},(0,a.createElement)(S,{icon:h}),(0,c.__)("Copy","activitypub")))),(0,a.createElement)("div",{className:"activitypub-dialog__section"},(0,a.createElement)("h4",{id:"remote-profile-title"},(0,c.__)("Your Profile","activitypub")),(0,a.createElement)("div",{className:"activitypub-dialog__description",id:"remote-profile-description"},(0,m.createInterpolateElement)((0,c.__)("Or, if you know your own profile, we can start things that way! (eg @yourusername@example.com)","activitypub"),{code:(0,a.createElement)("code",null)})),(0,a.createElement)("div",{className:"activitypub-dialog__button-group"},(0,a.createElement)("label",{htmlFor:"remote-profile",className:"screen-reader-text"},(0,c.__)("Enter your ActivityPub profile","activitypub")),(0,a.createElement)("input",{type:"text",id:"remote-profile",value:T,onKeyDown:e=>{"Enter"===e?.code&&$()},onChange:e=>N(e.target.value),"aria-invalid":y===b}),(0,a.createElement)(p.Button,{onClick:$,"aria-label":(0,c.__)("Submit profile","activitypub")},(0,a.createElement)(S,{icon:i}),y)),r&&(0,a.createElement)("div",{className:"activitypub-dialog__remember"},(0,a.createElement)(p.CheckboxControl,{checked:z,label:(0,c.__)("Remember me for easier comments","activitypub"),onChange:()=>{I(!z)}}))))}const{namespace:T}=window._activityPubOptions,N={avatar:"",webfinger:"@well@hello.dolly",name:(0,c.__)("Hello Dolly Fan Account","activitypub"),url:"#"};function z(e){if(!e)return N;const t={...N,...e};return t.avatar=t?.icon?.url,t}function I({profile:e,popupStyles:t,userId:o,buttonText:l,buttonOnly:n,buttonSize:i}){const{webfinger:r,avatar:c,name:u}=e,s=r.startsWith("@")?r:`@${r}`;return n?(0,a.createElement)("div",{className:"activitypub-profile"},(0,a.createElement)(U,{profile:e,popupStyles:t,userId:o,buttonText:l,buttonSize:i})):(0,a.createElement)("div",{className:"activitypub-profile"},(0,a.createElement)("img",{className:"activitypub-profile__avatar",src:c,alt:u}),(0,a.createElement)("div",{className:"activitypub-profile__content"},(0,a.createElement)("div",{className:"activitypub-profile__name"},u),(0,a.createElement)("div",{className:"activitypub-profile__handle",title:s},s)),(0,a.createElement)(U,{profile:e,popupStyles:t,userId:o,buttonText:l,buttonSize:i}))}function U({profile:e,popupStyles:t,userId:o,buttonText:l,buttonSize:n}){const[i,r]=(0,m.useState)(!1),u=(0,c.sprintf)((0,c.__)("Follow %s","activitypub"),e?.name);return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(p.Button,{className:"activitypub-profile__follow",onClick:()=>r(!0),"aria-haspopup":"dialog","aria-expanded":i,"aria-label":(0,c.__)("Follow me on the Fediverse","activitypub"),size:n},l),i&&(0,a.createElement)(p.Modal,{className:"activitypub-profile__confirm activitypub__modal",onRequestClose:()=>r(!1),title:u,"aria-label":u,role:"dialog"},(0,a.createElement)($,{profile:e,userId:o}),(0,a.createElement)("style",null,t)))}function $({profile:e,userId:t}){const{webfinger:o}=e,l=(0,c.__)("Follow","activitypub"),n=`/${T}/actors/${t}/remote-follow?resource=`,i=(0,c.__)("Copy and paste my profile into the search field of your favorite fediverse app or server.","activitypub"),r=o.startsWith("@")?o:`@${o}`;return(0,a.createElement)(O,{actionText:l,copyDescription:i,handle:r,resourceUrl:n})}function P({selectedUser:e,style:t,backgroundColor:o,id:l,useId:n=!1,profileData:i=!1,buttonOnly:r=!1,buttonText:u=(0,c.__)("Follow","activitypub"),buttonSize:s="default"}){const[p,d]=(0,m.useState)(z()),b="site"===e?0:e,f=function(e){return h(".apfmd__button-group .components-button",y(e?.elements?.link?.color?.text)||"#111","#fff",y(e?.elements?.link?.[":hover"]?.color?.text)||"#333")}(t),_=n?{id:l}:{};return(0,m.useEffect)((()=>{i?d(z(i)):function(e){const t={headers:{Accept:"application/activity+json"},path:`/${T}/actors/${e}`};return v()(t)}(b).then((e=>{d(z(e))}))}),[b,i]),(0,a.createElement)("div",{..._,className:"activitypub-follow-me-block-wrapper"},(0,a.createElement)(w,{selector:`#${l}`,style:t,backgroundColor:o}),(0,a.createElement)(I,{profile:p,userId:b,popupStyles:f,buttonText:u,buttonOnly:r,buttonSize:s}))}const R=window._activityPubOptions?.enabled;function B({name:e}){const t=R?.site?"":(0,c.__)("It will be empty in other non-author contexts.","activitypub"),o=(0,c.sprintf)(/* translators: %1$s: block name, %2$s: extra information for non-author context */ /* translators: %1$s: block name, %2$s: extra information for non-author context */ +(0,c.__)("This %1$s block will adapt to the page it is on, displaying the user profile associated with a post author (in a loop) or a user archive. %2$s","activitypub"),e,t).trim();return(0,a.createElement)(p.Card,null,(0,a.createElement)(p.CardBody,null,(0,m.createInterpolateElement)(o,{strong:(0,a.createElement)("strong",null)})))}(0,l.registerBlockType)("activitypub/follow-me",{edit:function({attributes:e,setAttributes:t,context:{postType:o,postId:l}}){const n=(0,r.useBlockProps)({className:"activitypub-follow-me-block-wrapper"}),i=function({withInherit:e=!1}){const t=d?.users?(0,u.useSelect)((e=>e("core").getUsers({who:"authors"}))):[];return(0,m.useMemo)((()=>{if(!t)return[];const o=[];return d?.site&&o.push({label:(0,c.__)("Site","activitypub"),value:"site"}),e&&d?.users&&o.push({label:(0,c.__)("Dynamic User","activitypub"),value:"inherit"}),t.reduce(((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e)),o)}),[t])}({withInherit:!0}),{selectedUser:b,buttonOnly:v,buttonText:f,buttonSize:y}=e,_="inherit"===b,h=(0,u.useSelect)((e=>{const{getEditedEntityRecord:t}=e(s.store),a=t("postType",o,l)?.author;return null!=a?a:null}),[o,l]);return(0,m.useEffect)((()=>{i.length&&(i.find((({value:e})=>e===b))||t({selectedUser:i[0].value}))}),[b,i]),(0,a.createElement)("div",{...n},(0,a.createElement)(r.InspectorControls,{key:"activitypub-follow-me"},(0,a.createElement)(p.PanelBody,{title:(0,c.__)("Follow Me Options","activitypub")},i.length>1&&(0,a.createElement)(p.SelectControl,{label:(0,c.__)("Select User","activitypub"),value:e.selectedUser,options:i,onChange:e=>t({selectedUser:e})}),(0,a.createElement)(p.ToggleControl,{label:(0,c.__)("Button Only Mode","activitypub"),checked:v,onChange:e=>t({buttonOnly:e}),help:(0,c.__)("Only show the follow button without profile information","activitypub")}),(0,a.createElement)(p.TextControl,{label:(0,c.__)("Button Text","activitypub"),value:f,onChange:e=>t({buttonText:e})}),(0,a.createElement)(p.SelectControl,{label:(0,c.__)("Button Size","activitypub"),value:y,options:[{label:(0,c.__)("Default","activitypub"),value:"default"},{label:(0,c.__)("Compact","activitypub"),value:"compact"},{label:(0,c.__)("Small","activitypub"),value:"small"}],onChange:e=>t({buttonSize:e}),help:(0,c.__)("Choose the size of the follow button","activitypub")}))),_?h?(0,a.createElement)(P,{...e,id:n.id,selectedUser:h}):(0,a.createElement)(B,{name:(0,c.__)("Follow Me","activitypub")}):(0,a.createElement)(P,{...e,id:n.id}))},save:()=>null,icon:i})}},o={};function l(e){var a=o[e];if(void 0!==a)return a.exports;var n=o[e]={exports:{}};return t[e](n,n.exports,l),n.exports}l.m=t,e=[],l.O=(t,o,a,n)=>{if(!o){var i=1/0;for(s=0;s=n)&&Object.keys(l.O).every((e=>l.O[e](o[c])))?o.splice(c--,1):(r=!1,n0&&e[s-1][2]>n;s--)e[s]=e[s-1];e[s]=[o,a,n]},l.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return l.d(t,{a:t}),t},l.d=(e,t)=>{for(var o in t)l.o(t,o)&&!l.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},l.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={338:0,301:0};l.O.j=t=>0===e[t];var t=(t,o)=>{var a,n,[i,r,c]=o,u=0;if(i.some((t=>0!==e[t]))){for(a in r)l.o(r,a)&&(l.m[a]=r[a]);if(c)var s=c(l)}for(t&&t(o);ul(420)));a=l.O(a)})(); \ No newline at end of file diff --git a/build/follow-me/view.asset.php b/build/follow-me/view.asset.php index 5068f4ba1..450e6729c 100644 --- a/build/follow-me/view.asset.php +++ b/build/follow-me/view.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '8008189b4c59111938ec'); + array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'ad9482bcf1d2f9d080b3'); diff --git a/build/follow-me/view.js b/build/follow-me/view.js index 72946cd37..b202309c8 100644 --- a/build/follow-me/view.js +++ b/build/follow-me/view.js @@ -1 +1 @@ -(()=>{"use strict";var e,t={729:(e,t,r)=>{var o=r(609);const a=window.wp.element,n=window.wp.domReady;var i=r.n(n);const l=window.wp.apiFetch;var c=r.n(l);const s=window.wp.components,u=window.wp.i18n;function p(e){return`var(--wp--preset--color--${e})`}function d(e){if("string"!=typeof e)return null;if(e.match(/^#/))return e.substring(0,7);const[,,t]=e.split("|");return p(t)}function m(e,t,r=null,o=""){return r?`${e}${o} { ${t}: ${r}; }\n`:""}function v(e,t,r,o){return m(e,"background-color",t)+m(e,"color",r)+m(e,"background-color",o,":hover")+m(e,"background-color",o,":focus")}function f({selector:e,style:t,backgroundColor:r}){const a=function(e,t,r){const o=`${e} .components-button`,a=("string"==typeof(n=r)?p(n):n?.color?.background||null)||t?.color?.background;var n;return v(o,d(t?.elements?.link?.color?.text),a,d(t?.elements?.link?.[":hover"]?.color?.text))}(e,t,r);return(0,o.createElement)("style",null,a)}const y=window.wp.primitives;var b=r(848);const _=(0,b.jsx)(y.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,b.jsx)(y.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"})}),w=(0,b.jsx)(y.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,b.jsx)(y.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})}),h=(0,a.forwardRef)((function({icon:e,size:t=24,...r},o){return(0,a.cloneElement)(e,{width:t,height:t,...r,ref:o})})),g=(0,b.jsx)(y.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,b.jsx)(y.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"})}),E=window.wp.compose,k="fediverse-remote-user";function x(e){try{return new URL(e),!0}catch(e){return!1}}function S({actionText:e,copyDescription:t,handle:r,resourceUrl:n,myProfile:i=!1,rememberProfile:l=!1}){const p=(0,u.__)("Loading...","activitypub"),d=(0,u.__)("Opening...","activitypub"),m=(0,u.__)("Error","activitypub"),v=(0,u.__)("Invalid","activitypub"),f=i||(0,u.__)("My Profile","activitypub"),[y,b]=(0,a.useState)(e),[S,O]=(0,a.useState)(_),N=(0,E.useCopyToClipboard)(r,(()=>{O(w),setTimeout((()=>O(_)),1e3)})),[C,R]=(0,a.useState)(""),[I,$]=(0,a.useState)(!0),{setRemoteUser:P}=function(){const[e,t]=(0,a.useState)(function(){const e=localStorage.getItem(k);return e?JSON.parse(e):{}}()),r=(0,a.useCallback)((e=>{!function(e){localStorage.setItem(k,JSON.stringify(e))}(e),t(e)}),[]),o=(0,a.useCallback)((()=>{localStorage.removeItem(k),t({})}),[]);return{template:e?.template||!1,profileURL:e?.profileURL||!1,setRemoteUser:r,deleteRemoteUser:o}}(),j=(0,a.useCallback)((()=>{let t;if(!x(C)&&!function(e){const t=e.replace(/^@/,"").split("@");return 2===t.length&&x(`https://${t[1]}`)}(C))return b(v),t=setTimeout((()=>b(e)),2e3),()=>clearTimeout(t);const r=n+C;b(p),c()({path:r}).then((({url:t,template:r})=>{I&&P({profileURL:C,template:r}),b(d),setTimeout((()=>{window.open(t,"_blank"),b(e)}),200)})).catch((()=>{b(m),setTimeout((()=>b(e)),2e3)}))}),[C]);return(0,o.createElement)("div",{className:"activitypub__dialog",role:"dialog","aria-labelledby":"dialog-title"},(0,o.createElement)("div",{className:"activitypub-dialog__section"},(0,o.createElement)("h4",{id:"dialog-title"},f),(0,o.createElement)("div",{className:"activitypub-dialog__description",id:"copy-description"},t),(0,o.createElement)("div",{className:"activitypub-dialog__button-group"},(0,o.createElement)("label",{htmlFor:"profile-handle",className:"screen-reader-text"},t),(0,o.createElement)("input",{type:"text",id:"profile-handle",value:r,readOnly:!0}),(0,o.createElement)(s.Button,{ref:N,"aria-label":(0,u.__)("Copy handle to clipboard","activitypub")},(0,o.createElement)(h,{icon:S}),(0,u.__)("Copy","activitypub")))),(0,o.createElement)("div",{className:"activitypub-dialog__section"},(0,o.createElement)("h4",{id:"remote-profile-title"},(0,u.__)("Your Profile","activitypub")),(0,o.createElement)("div",{className:"activitypub-dialog__description",id:"remote-profile-description"},(0,a.createInterpolateElement)((0,u.__)("Or, if you know your own profile, we can start things that way! (eg @yourusername@example.com)","activitypub"),{code:(0,o.createElement)("code",null)})),(0,o.createElement)("div",{className:"activitypub-dialog__button-group"},(0,o.createElement)("label",{htmlFor:"remote-profile",className:"screen-reader-text"},(0,u.__)("Enter your ActivityPub profile","activitypub")),(0,o.createElement)("input",{type:"text",id:"remote-profile",value:C,onKeyDown:e=>{"Enter"===e?.code&&j()},onChange:e=>R(e.target.value),"aria-invalid":y===v}),(0,o.createElement)(s.Button,{onClick:j,"aria-label":(0,u.__)("Submit profile","activitypub")},(0,o.createElement)(h,{icon:g}),y)),l&&(0,o.createElement)("div",{className:"activitypub-dialog__remember"},(0,o.createElement)(s.CheckboxControl,{checked:I,label:(0,u.__)("Remember me for easier comments","activitypub"),onChange:()=>{$(!I)}}))))}const{namespace:O}=window._activityPubOptions,N={avatar:"",webfinger:"@well@hello.dolly",name:(0,u.__)("Hello Dolly Fan Account","activitypub"),url:"#"};function C(e){if(!e)return N;const t={...N,...e};return t.avatar=t?.icon?.url,t}function R({profile:e,popupStyles:t,userId:r}){const{webfinger:a,avatar:n,name:i}=e,l=a.startsWith("@")?a:`@${a}`;return(0,o.createElement)("div",{className:"activitypub-profile"},(0,o.createElement)("img",{className:"activitypub-profile__avatar",src:n,alt:i}),(0,o.createElement)("div",{className:"activitypub-profile__content"},(0,o.createElement)("div",{className:"activitypub-profile__name"},i),(0,o.createElement)("div",{className:"activitypub-profile__handle",title:l},l)),(0,o.createElement)(I,{profile:e,popupStyles:t,userId:r}))}function I({profile:e,popupStyles:t,userId:r}){const[n,i]=(0,a.useState)(!1),l=(0,u.sprintf)((0,u.__)("Follow %s","activitypub"),e?.name);return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(s.Button,{className:"activitypub-profile__follow",onClick:()=>i(!0),"aria-haspopup":"dialog","aria-expanded":n,"aria-label":(0,u.__)("Follow me on the Fediverse","activitypub")},(0,u.__)("Follow","activitypub")),n&&(0,o.createElement)(s.Modal,{className:"activitypub-profile__confirm activitypub__modal",onRequestClose:()=>i(!1),title:l,"aria-label":l,role:"dialog"},(0,o.createElement)($,{profile:e,userId:r}),(0,o.createElement)("style",null,t)))}function $({profile:e,userId:t}){const{webfinger:r}=e,a=(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"),l=r.startsWith("@")?r:`@${r}`;return(0,o.createElement)(S,{actionText:a,copyDescription:i,handle:l,resourceUrl:n})}function P({selectedUser:e,style:t,backgroundColor:r,id:n,useId:i=!1,profileData:l=!1}){const[s,u]=(0,a.useState)(C()),p="site"===e?0:e,m=function(e){return v(".apfmd__button-group .components-button",d(e?.elements?.link?.color?.text)||"#111","#fff",d(e?.elements?.link?.[":hover"]?.color?.text)||"#333")}(t),y=i?{id:n}:{};function b(e){u(C(e))}return(0,a.useEffect)((()=>{if(l)return b(l);(function(e){const t={headers:{Accept:"application/activity+json"},path:`/${O}/actors/${e}`};return c()(t)})(p).then(b)}),[p,l]),(0,o.createElement)("div",{...y},(0,o.createElement)(f,{selector:`#${n}`,style:t,backgroundColor:r}),(0,o.createElement)(R,{profile:s,userId:p,popupStyles:m}))}let j=1;i()((()=>{[].forEach.call(document.querySelectorAll(".activitypub-follow-me-block-wrapper"),(e=>{const t=JSON.parse(e.dataset.attrs);(0,a.createRoot)(e).render((0,o.createElement)(P,{...t,id:"activitypub-follow-me-block-"+j++,useId:!0}))}))}))},20:(e,t,r)=>{var o=r(609),a=Symbol.for("react.element"),n=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),i=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};t.jsx=function(e,t,r){var o,c={},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)n.call(t,o)&&!l.hasOwnProperty(o)&&(c[o]=t[o]);if(e&&e.defaultProps)for(o in t=e.defaultProps)void 0===c[o]&&(c[o]=t[o]);return{$$typeof:a,type:e,key:s,ref:u,props:c,_owner:i.current}}},848:(e,t,r)=>{e.exports=r(20)},609:e=>{e.exports=window.React}},r={};function o(e){var a=r[e];if(void 0!==a)return a.exports;var n=r[e]={exports:{}};return t[e](n,n.exports,o),n.exports}o.m=t,e=[],o.O=(t,r,a,n)=>{if(!r){var i=1/0;for(u=0;u=n)&&Object.keys(o.O).every((e=>o.O[e](r[c])))?r.splice(c--,1):(l=!1,n0&&e[u-1][2]>n;u--)e[u]=e[u-1];e[u]=[r,a,n]},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 a,n,i=r[0],l=r[1],c=r[2],s=0;if(i.some((t=>0!==e[t]))){for(a in l)o.o(l,a)&&(o.m[a]=l[a]);if(c)var u=c(o)}for(t&&t(r);so(729)));a=o.O(a)})(); \ No newline at end of file +(()=>{"use strict";var e,t={804:(e,t,o)=>{const r=window.React,a=window.wp.element,l=window.wp.domReady;var n=o.n(l);const i=window.wp.apiFetch;var c=o.n(i);const u=window.wp.components,s=window.wp.i18n;function p(e){return`var(--wp--preset--color--${e})`}function m(e){if("string"!=typeof e)return null;if(e.match(/^#/))return e.substring(0,7);const[,,t]=e.split("|");return p(t)}function d(e,t,o=null,r=""){return o?`${e}${r} { ${t}: ${o}; }\n`:""}function v(e,t,o,r){return d(e,"background-color",t)+d(e,"color",o)+d(e,"background-color",r,":hover")+d(e,"background-color",r,":focus")}function b({selector:e,style:t,backgroundColor:o}){const a=function(e,t,o){const r=`${e} .components-button`,a=("string"==typeof(l=o)?p(l):l?.color?.background||null)||t?.color?.background;var l;return v(r,m(t?.elements?.link?.color?.text),a,m(t?.elements?.link?.[":hover"]?.color?.text))}(e,t,o);return(0,r.createElement)("style",null,a)}const f=window.wp.primitives,y=(0,r.createElement)(f.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(f.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"})),_=(0,r.createElement)(f.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(f.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,a.forwardRef)((function({icon:e,size:t=24,...o},r){return(0,a.cloneElement)(e,{width:t,height:t,...o,ref:r})})),h=(0,r.createElement)(f.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(f.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"})),g=window.wp.compose,E="fediverse-remote-user";function k(e){try{return new URL(e),!0}catch(e){return!1}}function x({actionText:e,copyDescription:t,handle:o,resourceUrl:l,myProfile:n=!1,rememberProfile:i=!1}){const p=(0,s.__)("Loading...","activitypub"),m=(0,s.__)("Opening...","activitypub"),d=(0,s.__)("Error","activitypub"),v=(0,s.__)("Invalid","activitypub"),b=n||(0,s.__)("My Profile","activitypub"),[f,x]=(0,a.useState)(e),[S,N]=(0,a.useState)(y),O=(0,g.useCopyToClipboard)(o,(()=>{N(_),setTimeout((()=>N(y)),1e3)})),[C,R]=(0,a.useState)(""),[T,z]=(0,a.useState)(!0),{setRemoteUser:I}=function(){const[e,t]=(0,a.useState)(function(){const e=localStorage.getItem(E);return e?JSON.parse(e):{}}()),o=(0,a.useCallback)((e=>{!function(e){localStorage.setItem(E,JSON.stringify(e))}(e),t(e)}),[]),r=(0,a.useCallback)((()=>{localStorage.removeItem(E),t({})}),[]);return{template:e?.template||!1,profileURL:e?.profileURL||!1,setRemoteUser:o,deleteRemoteUser:r}}(),$=(0,a.useCallback)((()=>{let t;if(!k(C)&&!function(e){const t=e.replace(/^@/,"").split("@");return 2===t.length&&k(`https://${t[1]}`)}(C))return x(v),t=setTimeout((()=>x(e)),2e3),()=>clearTimeout(t);const o=l+C;x(p),c()({path:o}).then((({url:t,template:o})=>{T&&I({profileURL:C,template:o}),x(m),setTimeout((()=>{window.open(t,"_blank"),x(e)}),200)})).catch((()=>{x(d),setTimeout((()=>x(e)),2e3)}))}),[C]);return(0,r.createElement)("div",{className:"activitypub__dialog",role:"dialog","aria-labelledby":"dialog-title"},(0,r.createElement)("div",{className:"activitypub-dialog__section"},(0,r.createElement)("h4",{id:"dialog-title"},b),(0,r.createElement)("div",{className:"activitypub-dialog__description",id:"copy-description"},t),(0,r.createElement)("div",{className:"activitypub-dialog__button-group"},(0,r.createElement)("label",{htmlFor:"profile-handle",className:"screen-reader-text"},t),(0,r.createElement)("input",{type:"text",id:"profile-handle",value:o,readOnly:!0}),(0,r.createElement)(u.Button,{ref:O,"aria-label":(0,s.__)("Copy handle to clipboard","activitypub")},(0,r.createElement)(w,{icon:S}),(0,s.__)("Copy","activitypub")))),(0,r.createElement)("div",{className:"activitypub-dialog__section"},(0,r.createElement)("h4",{id:"remote-profile-title"},(0,s.__)("Your Profile","activitypub")),(0,r.createElement)("div",{className:"activitypub-dialog__description",id:"remote-profile-description"},(0,a.createInterpolateElement)((0,s.__)("Or, if you know your own profile, we can start things that way! (eg @yourusername@example.com)","activitypub"),{code:(0,r.createElement)("code",null)})),(0,r.createElement)("div",{className:"activitypub-dialog__button-group"},(0,r.createElement)("label",{htmlFor:"remote-profile",className:"screen-reader-text"},(0,s.__)("Enter your ActivityPub profile","activitypub")),(0,r.createElement)("input",{type:"text",id:"remote-profile",value:C,onKeyDown:e=>{"Enter"===e?.code&&$()},onChange:e=>R(e.target.value),"aria-invalid":f===v}),(0,r.createElement)(u.Button,{onClick:$,"aria-label":(0,s.__)("Submit profile","activitypub")},(0,r.createElement)(w,{icon:h}),f)),i&&(0,r.createElement)("div",{className:"activitypub-dialog__remember"},(0,r.createElement)(u.CheckboxControl,{checked:T,label:(0,s.__)("Remember me for easier comments","activitypub"),onChange:()=>{z(!T)}}))))}const{namespace:S}=window._activityPubOptions,N={avatar:"",webfinger:"@well@hello.dolly",name:(0,s.__)("Hello Dolly Fan Account","activitypub"),url:"#"};function O(e){if(!e)return N;const t={...N,...e};return t.avatar=t?.icon?.url,t}function C({profile:e,popupStyles:t,userId:o,buttonText:a,buttonOnly:l,buttonSize:n}){const{webfinger:i,avatar:c,name:u}=e,s=i.startsWith("@")?i:`@${i}`;return l?(0,r.createElement)("div",{className:"activitypub-profile"},(0,r.createElement)(R,{profile:e,popupStyles:t,userId:o,buttonText:a,buttonSize:n})):(0,r.createElement)("div",{className:"activitypub-profile"},(0,r.createElement)("img",{className:"activitypub-profile__avatar",src:c,alt:u}),(0,r.createElement)("div",{className:"activitypub-profile__content"},(0,r.createElement)("div",{className:"activitypub-profile__name"},u),(0,r.createElement)("div",{className:"activitypub-profile__handle",title:s},s)),(0,r.createElement)(R,{profile:e,popupStyles:t,userId:o,buttonText:a,buttonSize:n}))}function R({profile:e,popupStyles:t,userId:o,buttonText:l,buttonSize:n}){const[i,c]=(0,a.useState)(!1),p=(0,s.sprintf)((0,s.__)("Follow %s","activitypub"),e?.name);return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(u.Button,{className:"activitypub-profile__follow",onClick:()=>c(!0),"aria-haspopup":"dialog","aria-expanded":i,"aria-label":(0,s.__)("Follow me on the Fediverse","activitypub"),size:n},l),i&&(0,r.createElement)(u.Modal,{className:"activitypub-profile__confirm activitypub__modal",onRequestClose:()=>c(!1),title:p,"aria-label":p,role:"dialog"},(0,r.createElement)(T,{profile:e,userId:o}),(0,r.createElement)("style",null,t)))}function T({profile:e,userId:t}){const{webfinger:o}=e,a=(0,s.__)("Follow","activitypub"),l=`/${S}/actors/${t}/remote-follow?resource=`,n=(0,s.__)("Copy and paste my profile into the search field of your favorite fediverse app or server.","activitypub"),i=o.startsWith("@")?o:`@${o}`;return(0,r.createElement)(x,{actionText:a,copyDescription:n,handle:i,resourceUrl:l})}function z({selectedUser:e,style:t,backgroundColor:o,id:l,useId:n=!1,profileData:i=!1,buttonOnly:u=!1,buttonText:p=(0,s.__)("Follow","activitypub"),buttonSize:d="default"}){const[f,y]=(0,a.useState)(O()),_="site"===e?0:e,w=function(e){return v(".apfmd__button-group .components-button",m(e?.elements?.link?.color?.text)||"#111","#fff",m(e?.elements?.link?.[":hover"]?.color?.text)||"#333")}(t),h=n?{id:l}:{};return(0,a.useEffect)((()=>{i?y(O(i)):function(e){const t={headers:{Accept:"application/activity+json"},path:`/${S}/actors/${e}`};return c()(t)}(_).then((e=>{y(O(e))}))}),[_,i]),(0,r.createElement)("div",{...h,className:"activitypub-follow-me-block-wrapper"},(0,r.createElement)(b,{selector:`#${l}`,style:t,backgroundColor:o}),(0,r.createElement)(C,{profile:f,userId:_,popupStyles:w,buttonText:p,buttonOnly:u,buttonSize:d}))}let I=1;n()((()=>{[].forEach.call(document.querySelectorAll(".activitypub-follow-me-block-wrapper"),(e=>{const t=JSON.parse(e.dataset.attrs);(0,a.createRoot)(e).render((0,r.createElement)(z,{...t,id:"activitypub-follow-me-block-"+I++,useId:!0}))}))}))}},o={};function r(e){var a=o[e];if(void 0!==a)return a.exports;var l=o[e]={exports:{}};return t[e](l,l.exports,r),l.exports}r.m=t,e=[],r.O=(t,o,a,l)=>{if(!o){var n=1/0;for(s=0;s=l)&&Object.keys(r.O).every((e=>r.O[e](o[c])))?o.splice(c--,1):(i=!1,l0&&e[s-1][2]>l;s--)e[s]=e[s-1];e[s]=[o,a,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 o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={41:0,301:0};r.O.j=t=>0===e[t];var t=(t,o)=>{var a,l,[n,i,c]=o,u=0;if(n.some((t=>0!==e[t]))){for(a in i)r.o(i,a)&&(r.m[a]=i[a]);if(c)var s=c(r)}for(t&&t(o);ur(804)));a=r.O(a)})(); \ No newline at end of file diff --git a/readme.txt b/readme.txt index de59312d5..21f7f5066 100644 --- a/readme.txt +++ b/readme.txt @@ -134,6 +134,7 @@ For reasons of data protection, it is not possible to see the followers of other = Unreleased = +* Added: Button only mode for the "Follow Me" Block * Added: Support for WPML post locale * Removed: Built-in support for nodeinfo2. Use the [NodeInfo plugin](https://wordpress.org/plugins/nodeinfo/) instead. @@ -147,11 +148,11 @@ For reasons of data protection, it is not possible to see the followers of other * Added: A filter to make custom comment types manageable in WP.com Calypso * Changed: Hide ActivityPub post meta keys from the custom Fields UI * Changed: Bumped minimum required PHP version to 7.2 +* Changed: Print `_activityPubOptions` in the `wp_footer` action on the frontend. * Fixed: Undefined array key warnings in various places * Fixed: @-mentions in federated comments being displayed with a line break * Fixed: Fetching replies from the same instance for Enable Mastodon Apps * Fixed: Image captions not being included in the ActivityPub representation when the image is attached to the post -* Changed: Print `_activityPubOptions` in the `wp_footer` action on the frontend. = 4.6.0 = diff --git a/src/follow-me/block.json b/src/follow-me/block.json index 5c5c9e5d2..2abe9de5d 100644 --- a/src/follow-me/block.json +++ b/src/follow-me/block.json @@ -36,6 +36,19 @@ "selectedUser": { "type": "string", "default": "site" + }, + "buttonOnly": { + "type": "boolean", + "default": false + }, + "buttonText": { + "type": "string", + "default": "Follow" + }, + "buttonSize": { + "type": "string", + "default": "default", + "enum": ["small", "default", "compact"] } }, "usesContext": [ "postType", "postId" ], diff --git a/src/follow-me/edit.js b/src/follow-me/edit.js index be74d288e..b41d0f0fb 100644 --- a/src/follow-me/edit.js +++ b/src/follow-me/edit.js @@ -2,23 +2,36 @@ import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; -import { SelectControl, PanelBody } from '@wordpress/components'; +import { SelectControl, PanelBody, ToggleControl, TextControl } from '@wordpress/components'; import { useUserOptions } from '../shared/use-user-options'; import FollowMe from './follow-me'; import { useEffect } from '@wordpress/element'; import { InheritModeBlockFallback } from '../shared/inherit-block-fallback'; - +/** + * Edit component. + * + * @param {Object} props Component props. + * @param {Object} props.attributes Block attributes. + * @param {Function} props.setAttributes Set block attributes. + * @param {Object} props.context Block context. + * @param {string} props.context.postType Post type. + * @param {number} props.context.postId Post ID. + * @return {JSX.Element} Edit component. + */ export default function Edit( { attributes, setAttributes, - context: { postType, postId }, + context: { + postType, + postId, + }, } ) { const blockProps = useBlockProps( { className: 'activitypub-follow-me-block-wrapper', } ); const usersOptions = useUserOptions( { withInherit: true } ); - const { selectedUser } = attributes; + const { selectedUser, buttonOnly, buttonText, buttonSize } = attributes; const isInheritMode = selectedUser === 'inherit'; const authorId = useSelect( @@ -48,27 +61,49 @@ export default function Edit( { return (
- { usersOptions.length > 1 && ( - - + + + { usersOptions.length > 1 && ( setAttributes( { selectedUser: value } ) } /> - - - ) } + ) } + setAttributes( { buttonOnly: value } ) } + help={ __( 'Only show the follow button without profile information', 'activitypub' ) } + /> + setAttributes( { buttonText: value } ) } + /> + setAttributes( { buttonSize: value } ) } + help={ __( 'Choose the size of the follow button', 'activitypub' ) } + /> + + { isInheritMode ? - authorId ? ( - - ) : ( - - ) - : ( - - ) } + authorId ? ( + + ) : ( + + ) + : ( + + ) }
); } diff --git a/src/follow-me/follow-me.js b/src/follow-me/follow-me.js index 8020e1507..7b7cf0e73 100644 --- a/src/follow-me/follow-me.js +++ b/src/follow-me/follow-me.js @@ -1,4 +1,3 @@ - import apiFetch from '@wordpress/api-fetch'; import { useEffect, useState } from '@wordpress/element'; import { Button, Modal } from '@wordpress/components'; @@ -6,8 +5,14 @@ import { __, sprintf } from '@wordpress/i18n'; import { ButtonStyle, getPopupStyles } from './button-style'; import { Dialog } from '../shared/dialog'; import './style.scss'; + const { namespace } = window._activityPubOptions; +/** + * Default profile data. + * + * @type {Object} + */ const DEFAULT_PROFILE_DATA = { avatar: '', webfinger: '@well@hello.dolly', @@ -15,6 +20,12 @@ const DEFAULT_PROFILE_DATA = { url: '#', }; +/** + * Get normalized profile data. + * + * @param {Object} profile Profile data. + * @return {Object} Normalized profile data. + */ function getNormalizedProfile( profile ) { if ( ! profile ) { return DEFAULT_PROFILE_DATA; @@ -24,6 +35,12 @@ function getNormalizedProfile( profile ) { return data; } +/** + * Fetch profile data. + * + * @param {number} userId User ID. + * @return {Promise} Promise resolving with profile data. + */ function fetchProfile( userId ) { const fetchOptions = { headers: { Accept: 'application/activity+json' }, @@ -32,10 +49,44 @@ function fetchProfile( userId ) { return apiFetch( fetchOptions ); } -function Profile( { profile, popupStyles, userId } ) { +/** + * Profile component. + * + * @param {Object} props Component props. + * @param {Object} props.profile Profile data. + * @param {string} props.popupStyles Popup styles. + * @param {number} props.userId User ID. + * @param {string} props.buttonText Button text. + * @param {boolean} props.buttonOnly Whether to render only the button. + * @param {string} props.buttonSize Button size. + * @return {JSX.Element} Profile component. + */ +function Profile( { + profile, + popupStyles, + userId, + buttonText, + buttonOnly, + buttonSize, +} ) { const { webfinger, avatar, name } = profile; // check if webfinger starts with @ and add it if it doesn't const webfingerWithAt = webfinger.startsWith( '@' ) ? webfinger : `@${ webfinger }`; + + if ( buttonOnly ) { + return ( +
+ +
+ ); + } + return (
{ @@ -43,12 +94,35 @@ function Profile( { profile, popupStyles, userId } ) {
{ name }
{ webfingerWithAt }
- + ); } -function Follow( { profile, popupStyles, userId } ) { +/** + * Follow component. + * + * @param {Object} props Component props. + * @param {Object} props.profile Profile data. + * @param {string} props.popupStyles Popup styles. + * @param {number} props.userId User ID. + * @param {string} props.buttonText Button text. + * @param {string} props.buttonSize Button size. + * @return {JSX.Element} Follow component. + */ +function Follow( { + profile, + popupStyles, + userId, + buttonText, + buttonSize, +} ) { const [ isOpen, setIsOpen ] = useState( false ); const title = sprintf( __( 'Follow %s', 'activitypub' ), profile?.name ); @@ -59,60 +133,105 @@ function Follow( { profile, popupStyles, userId } ) { onClick={ () => setIsOpen( true ) } aria-haspopup="dialog" aria-expanded={ isOpen } - aria-label={ __( 'Follow me on the Fediverse', 'activitypub' ) } + aria-label={ __( 'Follow me on the Fediverse', 'activitypub' ) } + size={ buttonSize } > - { __( 'Follow', 'activitypub' ) } + { buttonText } { isOpen && ( setIsOpen( false ) } - title={ title } - aria-label={ title } - role="dialog" + className="activitypub-profile__confirm activitypub__modal" + onRequestClose={ () => setIsOpen( false ) } + title={ title } + aria-label={ title } + role="dialog" > - + ) } ); } +/** + * Dialog follow component. + * + * @param {Object} props Component props. + * @param {Object} props.profile Profile data. + * @param {number} props.userId User ID. + * @return {JSX.Element} Dialog follow component. + */ function DialogFollow( { profile, userId } ) { const { webfinger } = profile; const actionText = __( 'Follow', 'activitypub' ); - const resourceUrl = `/${ namespace }/actors/${userId}/remote-follow?resource=`; + const resourceUrl = `/${ namespace }/actors/${ userId }/remote-follow?resource=`; const copyDescription = __( 'Copy and paste my profile into the search field of your favorite fediverse app or server.', 'activitypub' ); const webfingerWithAt = webfinger.startsWith( '@' ) ? webfinger : `@${ webfinger }`; - return ; + return ( + + ); } -export default function FollowMe( { selectedUser, style, backgroundColor, id, useId = false, profileData = false } ) { +/** + * Follow me component. + * + * @param {Object} props Component props. + * @param {number|string} props.selectedUser Selected user ID or 'site'. + * @param {Object} props.style Style object. + * @param {string} props.backgroundColor Background color. + * @param {string} props.id Component ID. + * @param {boolean} props.useId Whether to use the ID. + * @param {Object} props.profileData Profile data. + * @param {boolean} props.buttonOnly Whether to render only the button. + * @param {string} props.buttonText Button text. + * @param {string} props.buttonSize Button size. + * @return {JSX.Element} Follow me component. + */ +export default function FollowMe( { + selectedUser, + style, + backgroundColor, + id, + useId = false, + profileData = false, + buttonOnly = false, + buttonText = __( 'Follow', 'activitypub' ), + buttonSize = 'default', +} ) { const [ profile, setProfile ] = useState( getNormalizedProfile() ); const userId = selectedUser === 'site' ? 0 : selectedUser; const popupStyles = getPopupStyles( style ); const wrapperProps = useId ? { id } : {}; - function setProfileData( profile ) { - setProfile( getNormalizedProfile( profile ) ); - } + useEffect( () => { if ( profileData ) { - return setProfileData( profileData ); + setProfile( getNormalizedProfile( profileData ) ); + return; } - fetchProfile( userId ).then( setProfileData ); + + fetchProfile( userId ).then( ( data ) => { + setProfile( getNormalizedProfile( data ) ); + } ); }, [ userId, profileData ] ); - return( -
+ return ( +
- +
- ) + ); }