From 18da65ff2974b1a036c945f23637658c2c5d56fc Mon Sep 17 00:00:00 2001 From: Matt Wiebe Date: Thu, 19 Sep 2024 15:29:12 -0500 Subject: [PATCH] Follow Me/Followers: add `inherit` mode for dynamic templating (#892) --------- Co-authored-by: Matthias Pfefferle Co-authored-by: Alex Kirk --- build/follow-me/block.json | 4 ++ build/follow-me/index.asset.php | 2 +- build/follow-me/index.js | 3 +- build/follow-me/view.asset.php | 2 +- build/follow-me/view.js | 2 +- build/followers/block.json | 4 ++ build/followers/index.asset.php | 2 +- build/followers/index.js | 7 +-- build/followers/view.asset.php | 2 +- build/followers/view.js | 6 +-- includes/class-blocks.php | 74 +++++++++++++++++++++++++--- src/follow-me/block.json | 1 + src/follow-me/edit.js | 37 ++++++++++++-- src/followers/block.json | 1 + src/followers/edit.js | 34 +++++++++++-- src/shared/inherit-block-fallback.js | 17 +++++++ src/shared/use-user-options.js | 25 +++++++--- 17 files changed, 192 insertions(+), 31 deletions(-) create mode 100644 src/shared/inherit-block-fallback.js diff --git a/build/follow-me/block.json b/build/follow-me/block.json index 6e685671..edeb67c7 100644 --- a/build/follow-me/block.json +++ b/build/follow-me/block.json @@ -38,6 +38,10 @@ "default": "site" } }, + "usesContext": [ + "postType", + "postId" + ], "editorScript": "file:./index.js", "viewScript": "file:./view.js", "style": [ diff --git a/build/follow-me/index.asset.php b/build/follow-me/index.asset.php index 89ab05d1..f559a8a9 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-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'ef5b5c7e3b4b9ceeb7dd'); + 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' => 'f33252a2026002ddb56c'); diff --git a/build/follow-me/index.js b/build/follow-me/index.js index dcd0550d..7b551c71 100644 --- a/build/follow-me/index.js +++ b/build/follow-me/index.js @@ -1 +1,2 @@ -(()=>{"use strict";var e,t={17:(e,t,o)=>{const r=window.wp.blocks,n=window.wp.primitives;var i=o(848);const l=(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"})}),a=window.wp.blockEditor,c=window.wp.i18n,s=window.wp.components,u=window.wp.data,p=window.wp.element,d=window._activityPubOptions?.enabled,v=window.wp.apiFetch;var f=o.n(v);function m(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 m(t)}function b(e,t,o=null,r=""){return o?`${e}${r} { ${t}: ${o}; }\n`:""}function _(e,t,o,r){return b(e,"background-color",t)+b(e,"color",o)+b(e,"background-color",r,":hover")+b(e,"background-color",r,":focus")}function h({selector:e,style:t,backgroundColor:o}){const r=function(e,t,o){const r=`${e} .components-button`,n=("string"==typeof(i=o)?m(i):i?.color?.background||null)||t?.color?.background;var i;return _(r,y(t?.elements?.link?.color?.text),n,y(t?.elements?.link?.[":hover"]?.color?.text))}(e,t,o);return(0,i.jsx)("style",{children:r})}var w=o(609);const g=(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"})}),x=(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"})}),j=(0,p.forwardRef)((function({icon:e,size:t=24,...o},r){return(0,p.cloneElement)(e,{width:t,height:t,...o,ref:r})})),k=window.wp.compose,E="fediverse-remote-user";function S(e){try{return new URL(e),!0}catch(e){return!1}}function O({actionText:e,copyDescription:t,handle:o,resourceUrl:r,myProfile:n=!1,rememberProfile:i=!1}){const a=(0,c.__)("Loading...","activitypub"),u=(0,c.__)("Opening...","activitypub"),d=(0,c.__)("Error","activitypub"),v=(0,c.__)("Invalid","activitypub"),m=n||(0,c.__)("My Profile","activitypub"),[y,b]=(0,p.useState)(e),[_,h]=(0,p.useState)(g),O=(0,k.useCopyToClipboard)(o,(()=>{h(x),setTimeout((()=>h(g)),1e3)})),[C,N]=(0,p.useState)(""),[R,U]=(0,p.useState)(!0),{setRemoteUser:P}=function(){const[e,t]=(0,p.useState)(function(){const e=localStorage.getItem(E);return e?JSON.parse(e):{}}()),o=(0,p.useCallback)((e=>{!function(e){localStorage.setItem(E,JSON.stringify(e))}(e),t(e)}),[]),r=(0,p.useCallback)((()=>{localStorage.removeItem(E),t({})}),[]);return{template:e?.template||!1,profileURL:e?.profileURL||!1,setRemoteUser:o,deleteRemoteUser:r}}(),I=(0,p.useCallback)((()=>{let t;if(!S(C)&&!function(e){const t=e.replace(/^@/,"").split("@");return 2===t.length&&S(`https://${t[1]}`)}(C))return b(v),t=setTimeout((()=>b(e)),2e3),()=>clearTimeout(t);const o=r+C;b(a),f()({path:o}).then((({url:t,template:o})=>{R&&P({profileURL:C,template:o}),b(u),setTimeout((()=>{window.open(t,"_blank"),b(e)}),200)})).catch((()=>{b(d),setTimeout((()=>b(e)),2e3)}))}),[C]);return(0,w.createElement)("div",{className:"activitypub__dialog"},(0,w.createElement)("div",{className:"activitypub-dialog__section"},(0,w.createElement)("h4",null,m),(0,w.createElement)("div",{className:"activitypub-dialog__description"},t),(0,w.createElement)("div",{className:"activitypub-dialog__button-group"},(0,w.createElement)("input",{type:"text",value:o,readOnly:!0}),(0,w.createElement)(s.Button,{ref:O},(0,w.createElement)(j,{icon:_}),(0,c.__)("Copy","activitypub")))),(0,w.createElement)("div",{className:"activitypub-dialog__section"},(0,w.createElement)("h4",null,(0,c.__)("Your Profile","activitypub")),(0,w.createElement)("div",{className:"activitypub-dialog__description"},(0,p.createInterpolateElement)((0,c.__)("Or, if you know your own profile, we can start things that way! (eg yourusername@example.com)","activitypub"),{code:(0,w.createElement)("code",null)})),(0,w.createElement)("div",{className:"activitypub-dialog__button-group"},(0,w.createElement)("input",{type:"text",value:C,onKeyDown:e=>{"Enter"===e?.code&&I()},onChange:e=>N(e.target.value)}),(0,w.createElement)(s.Button,{onClick:I},(0,w.createElement)(j,{icon:l}),y)),i&&(0,w.createElement)("div",{className:"activitypub-dialog__remember"},(0,w.createElement)(s.CheckboxControl,{checked:R,label:(0,c.__)("Remember me for easier comments","activitypub"),onChange:()=>{U(!R)}}))))}const{namespace:C}=window._activityPubOptions,N={avatar:"",webfinger:"@well@hello.dolly",name:(0,c.__)("Hello Dolly Fan Account","activitypub"),url:"#"};function R(e){if(!e)return N;const t={...N,...e};return t.avatar=t?.icon?.url,t}function U({profile:e,popupStyles:t,userId:o}){const{avatar:r,name:n,webfinger:l}=e;return(0,i.jsxs)("div",{className:"activitypub-profile",children:[(0,i.jsx)("img",{className:"activitypub-profile__avatar",src:r,alt:n}),(0,i.jsxs)("div",{className:"activitypub-profile__content",children:[(0,i.jsx)("div",{className:"activitypub-profile__name",children:n}),(0,i.jsx)("div",{className:"activitypub-profile__handle",title:l,children:l})]}),(0,i.jsx)(P,{profile:e,popupStyles:t,userId:o})]})}function P({profile:e,popupStyles:t,userId:o}){const[r,n]=(0,p.useState)(!1),l=(0,c.sprintf)((0,c.__)("Follow %s","activitypub"),e?.name);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.Button,{className:"activitypub-profile__follow",onClick:()=>n(!0),children:(0,c.__)("Follow","activitypub")}),r&&(0,i.jsxs)(s.Modal,{className:"activitypub-profile__confirm activitypub__modal",onRequestClose:()=>n(!1),title:l,children:[(0,i.jsx)(I,{profile:e,userId:o}),(0,i.jsx)("style",{children:t})]})]})}function I({profile:e,userId:t}){const{webfinger:o}=e,r=(0,c.__)("Follow","activitypub"),n=`/${C}/actors/${t}/remote-follow?resource=`,l=(0,c.__)("Copy and paste my profile into the search field of your favorite fediverse app or server.","activitypub");return(0,i.jsx)(O,{actionText:r,copyDescription:l,handle:o,resourceUrl:n})}function $({selectedUser:e,style:t,backgroundColor:o,id:r,useId:n=!1,profileData:l=!1}){const[a,c]=(0,p.useState)(R()),s="site"===e?0:e,u=function(e){return _(".apfmd__button-group .components-button",y(e?.elements?.link?.color?.text)||"#111","#fff",y(e?.elements?.link?.[":hover"]?.color?.text)||"#333")}(t),d=n?{id:r}:{};function v(e){c(R(e))}return(0,p.useEffect)((()=>{if(l)return v(l);(function(e){const t={headers:{Accept:"application/activity+json"},path:`/${C}/actors/${e}`};return f()(t)})(s).then(v)}),[s,l]),(0,i.jsxs)("div",{...d,children:[(0,i.jsx)(h,{selector:`#${r}`,style:t,backgroundColor:o}),(0,i.jsx)(U,{profile:a,userId:s,popupStyles:u})]})}(0,r.registerBlockType)("activitypub/follow-me",{edit:function({attributes:e,setAttributes:t}){const o=(0,a.useBlockProps)({className:"activitypub-follow-me-block-wrapper"}),r=function(){const e=d?.users?(0,u.useSelect)((e=>e("core").getUsers({who:"authors"}))):[];return(0,p.useMemo)((()=>{if(!e)return[];const t=d?.site?[{label:(0,c.__)("Whole Site","activitypub"),value:"site"}]:[];return e.reduce(((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e)),t)}),[e])}(),{selectedUser:n}=e;return(0,p.useEffect)((()=>{r.length&&(r.find((({value:e})=>e===n))||t({selectedUser:r[0].value}))}),[n,r]),(0,i.jsxs)("div",{...o,children:[r.length>1&&(0,i.jsx)(a.InspectorControls,{children:(0,i.jsx)(s.PanelBody,{title:(0,c.__)("Followers Options","activitypub"),children:(0,i.jsx)(s.SelectControl,{label:(0,c.__)("Select User","activitypub"),value:e.selectedUser,options:r,onChange:e=>t({selectedUser:e})})})},"setting"),(0,i.jsx)($,{...e,id:o.id})]})},save:()=>null,icon:l})},20:(e,t,o)=>{var r=o(609),n=Symbol.for("react.element"),i=Symbol.for("react.fragment"),l=Object.prototype.hasOwnProperty,a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function s(e,t,o){var r,i={},s=null,u=null;for(r in void 0!==o&&(s=""+o),void 0!==t.key&&(s=""+t.key),void 0!==t.ref&&(u=t.ref),t)l.call(t,r)&&!c.hasOwnProperty(r)&&(i[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===i[r]&&(i[r]=t[r]);return{$$typeof:n,type:e,key:s,ref:u,props:i,_owner:a.current}}t.Fragment=i,t.jsx=s,t.jsxs=s},848:(e,t,o)=>{e.exports=o(20)},609:e=>{e.exports=window.React}},o={};function r(e){var n=o[e];if(void 0!==n)return n.exports;var i=o[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.m=t,e=[],r.O=(t,o,n,i)=>{if(!o){var l=1/0;for(u=0;u=i)&&Object.keys(r.O).every((e=>r.O[e](o[c])))?o.splice(c--,1):(a=!1,i0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[o,n,i]},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={338:0,301:0};r.O.j=t=>0===e[t];var t=(t,o)=>{var n,i,[l,a,c]=o,s=0;if(l.some((t=>0!==e[t]))){for(n in a)r.o(a,n)&&(r.m[n]=a[n]);if(c)var u=c(r)}for(t&&t(o);sr(17)));n=r.O(n)})(); \ No newline at end of file +(()=>{"use strict";var e,t={399:(e,t,r)=>{const o=window.wp.blocks,n=window.wp.primitives;var l=r(848);const a=(0,l.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,l.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 i=r(609);const c=window.wp.blockEditor,s=window.wp.i18n,u=window.wp.data,p=window.wp.coreData,m=window.wp.components,d=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(l=r)?b(l):l?.color?.background||null)||t?.color?.background;var l;return h(o,_(t?.elements?.link?.color?.text),n,_(t?.elements?.link?.[":hover"]?.color?.text))}(e,t,r);return(0,i.createElement)("style",null,o)}const E=(0,l.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,l.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,l.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,l.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,d.forwardRef)((function({icon:e,size:t=24,...r},o){return(0,d.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 I({actionText:e,copyDescription:t,handle:r,resourceUrl:o,myProfile:n=!1,rememberProfile:l=!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,d.useState)(e),[w,h]=(0,d.useState)(E),g=(0,S.useCopyToClipboard)(r,(()=>{h(k),setTimeout((()=>h(E)),1e3)})),[I,N]=(0,d.useState)(""),[R,U]=(0,d.useState)(!0),{setRemoteUser:P}=function(){const[e,t]=(0,d.useState)(function(){const e=localStorage.getItem(O);return e?JSON.parse(e):{}}()),r=(0,d.useCallback)((e=>{!function(e){localStorage.setItem(O,JSON.stringify(e))}(e),t(e)}),[]),o=(0,d.useCallback)((()=>{localStorage.removeItem(O),t({})}),[]);return{template:e?.template||!1,profileURL:e?.profileURL||!1,setRemoteUser:r,deleteRemoteUser:o}}(),T=(0,d.useCallback)((()=>{let t;if(!C(I)&&!function(e){const t=e.replace(/^@/,"").split("@");return 2===t.length&&C(`https://${t[1]}`)}(I))return _(v),t=setTimeout((()=>_(e)),2e3),()=>clearTimeout(t);const r=o+I;_(c),y()({path:r}).then((({url:t,template:r})=>{R&&P({profileURL:I,template:r}),_(u),setTimeout((()=>{window.open(t,"_blank"),_(e)}),200)})).catch((()=>{_(p),setTimeout((()=>_(e)),2e3)}))}),[I]);return(0,i.createElement)("div",{className:"activitypub__dialog"},(0,i.createElement)("div",{className:"activitypub-dialog__section"},(0,i.createElement)("h4",null,f),(0,i.createElement)("div",{className:"activitypub-dialog__description"},t),(0,i.createElement)("div",{className:"activitypub-dialog__button-group"},(0,i.createElement)("input",{type:"text",value:r,readOnly:!0}),(0,i.createElement)(m.Button,{ref:g},(0,i.createElement)(x,{icon:w}),(0,s.__)("Copy","activitypub")))),(0,i.createElement)("div",{className:"activitypub-dialog__section"},(0,i.createElement)("h4",null,(0,s.__)("Your Profile","activitypub")),(0,i.createElement)("div",{className:"activitypub-dialog__description"},(0,d.createInterpolateElement)((0,s.__)("Or, if you know your own profile, we can start things that way! (eg yourusername@example.com)","activitypub"),{code:(0,i.createElement)("code",null)})),(0,i.createElement)("div",{className:"activitypub-dialog__button-group"},(0,i.createElement)("input",{type:"text",value:I,onKeyDown:e=>{"Enter"===e?.code&&T()},onChange:e=>N(e.target.value)}),(0,i.createElement)(m.Button,{onClick:T},(0,i.createElement)(x,{icon:a}),b)),l&&(0,i.createElement)("div",{className:"activitypub-dialog__remember"},(0,i.createElement)(m.CheckboxControl,{checked:R,label:(0,s.__)("Remember me for easier comments","activitypub"),onChange:()=>{U(!R)}}))))}const{namespace:N}=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{avatar:o,name:n,webfinger:l}=e;return(0,i.createElement)("div",{className:"activitypub-profile"},(0,i.createElement)("img",{className:"activitypub-profile__avatar",src:o,alt:n}),(0,i.createElement)("div",{className:"activitypub-profile__content"},(0,i.createElement)("div",{className:"activitypub-profile__name"},n),(0,i.createElement)("div",{className:"activitypub-profile__handle",title:l},l)),(0,i.createElement)(T,{profile:e,popupStyles:t,userId:r}))}function T({profile:e,popupStyles:t,userId:r}){const[o,n]=(0,d.useState)(!1),l=(0,s.sprintf)((0,s.__)("Follow %s","activitypub"),e?.name);return(0,i.createElement)(i.Fragment,null,(0,i.createElement)(m.Button,{className:"activitypub-profile__follow",onClick:()=>n(!0)},(0,s.__)("Follow","activitypub")),o&&(0,i.createElement)(m.Modal,{className:"activitypub-profile__confirm activitypub__modal",onRequestClose:()=>n(!1),title:l},(0,i.createElement)($,{profile:e,userId:r}),(0,i.createElement)("style",null,t)))}function $({profile:e,userId:t}){const{webfinger:r}=e,o=(0,s.__)("Follow","activitypub"),n=`/${N}/actors/${t}/remote-follow?resource=`,l=(0,s.__)("Copy and paste my profile into the search field of your favorite fediverse app or server.","activitypub");return(0,i.createElement)(I,{actionText:o,copyDescription:l,handle:r,resourceUrl:n})}function j({selectedUser:e,style:t,backgroundColor:r,id:o,useId:n=!1,profileData:l=!1}){const[a,c]=(0,d.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 m(e){c(U(e))}return(0,d.useEffect)((()=>{if(l)return m(l);(function(e){const t={headers:{Accept:"application/activity+json"},path:`/${N}/actors/${e}`};return y()(t)})(s).then(m)}),[s,l]),(0,i.createElement)("div",{...p},(0,i.createElement)(g,{selector:`#${o}`,style:t,backgroundColor:r}),(0,i.createElement)(P,{profile:a,userId:s,popupStyles:u}))}function B({name:e}){const t=(0,s.sprintf)(/* translators: %s: block name */ +"This %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. It will be empty in other non-author contexts.",e);return(0,i.createElement)(m.Card,null,(0,i.createElement)(m.CardBody,null,(0,d.createInterpolateElement)(t,{strong:(0,i.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"}),l=function({withInherit:e=!1}){const t=v?.users?(0,u.useSelect)((e=>e("core").getUsers({who:"authors"}))):[];return(0,d.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,d.useEffect)((()=>{l.length&&(l.find((({value:e})=>e===a))||t({selectedUser:l[0].value}))}),[a,l]),(0,i.createElement)("div",{...n},l.length>1&&(0,i.createElement)(c.InspectorControls,{key:"setting"},(0,i.createElement)(m.PanelBody,{title:(0,s.__)("Followers Options","activitypub")},(0,i.createElement)(m.SelectControl,{label:(0,s.__)("Select User","activitypub"),value:e.selectedUser,options:l,onChange:e=>t({selectedUser:e})}))),f?y?(0,i.createElement)(j,{...e,id:n.id,selectedUser:y}):(0,i.createElement)(B,{name:(0,s.__)("Follow Me","activitypub")}):(0,i.createElement)(j,{...e,id:n.id}))},save:()=>null,icon:a})},20:(e,t,r)=>{var o=r(609),n=Symbol.for("react.element"),l=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),a=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={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)l.call(t,o)&&!i.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 l=r[e]={exports:{}};return t[e](l,l.exports,o),l.exports}o.m=t,e=[],o.O=(t,r,n,l)=>{if(!r){var a=1/0;for(u=0;u=l)&&Object.keys(o.O).every((e=>o.O[e](r[c])))?r.splice(c--,1):(i=!1,l0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[r,n,l]},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,l,[a,i,c]=r,s=0;if(a.some((t=>0!==e[t]))){for(n in i)o.o(i,n)&&(o.m[n]=i[n]);if(c)var u=c(o)}for(t&&t(r);so(399)));n=o.O(n)})(); \ No newline at end of file diff --git a/build/follow-me/view.asset.php b/build/follow-me/view.asset.php index e5556b1f..da6b09c1 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' => 'ec1f2f8a193d8d386abc'); + array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'ab8c0dad126bb0a61ed6'); diff --git a/build/follow-me/view.js b/build/follow-me/view.js index 28b3867f..7fd3cb16 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 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 yourusername@example.com)","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=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={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);so(729)));n=o.O(n)})(); \ No newline at end of file +(()=>{"use strict";var e,t={729:(e,t,r)=>{var o=r(609);const n=window.wp.element,a=window.wp.domReady;var l=r.n(a);const i=window.wp.apiFetch;var c=r.n(i);const s=window.wp.components,u=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 v(e,t,r=null,o=""){return r?`${e}${o} { ${t}: ${r}; }\n`:""}function d(e,t,r,o){return v(e,"background-color",t)+v(e,"color",r)+v(e,"background-color",o,":hover")+v(e,"background-color",o,":focus")}function f({selector:e,style:t,backgroundColor:r}){const n=function(e,t,r){const o=`${e} .components-button`,n=("string"==typeof(a=r)?p(a):a?.color?.background||null)||t?.color?.background;var a;return d(o,m(t?.elements?.link?.color?.text),n,m(t?.elements?.link?.[":hover"]?.color?.text))}(e,t,r);return(0,o.createElement)("style",null,n)}const y=window.wp.primitives;var _=r(848);const b=(0,_.jsx)(y.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,_.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,_.jsx)(y.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,_.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,n.forwardRef)((function({icon:e,size:t=24,...r},o){return(0,n.cloneElement)(e,{width:t,height:t,...r,ref:o})})),g=(0,_.jsx)(y.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,_.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 O({actionText:e,copyDescription:t,handle:r,resourceUrl:a,myProfile:l=!1,rememberProfile:i=!1}){const p=(0,u.__)("Loading...","activitypub"),m=(0,u.__)("Opening...","activitypub"),v=(0,u.__)("Error","activitypub"),d=(0,u.__)("Invalid","activitypub"),f=l||(0,u.__)("My Profile","activitypub"),[y,_]=(0,n.useState)(e),[O,S]=(0,n.useState)(b),C=(0,E.useCopyToClipboard)(r,(()=>{S(w),setTimeout((()=>S(b)),1e3)})),[N,R]=(0,n.useState)(""),[I,P]=(0,n.useState)(!0),{setRemoteUser:$}=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}}(),j=(0,n.useCallback)((()=>{let t;if(!x(N)&&!function(e){const t=e.replace(/^@/,"").split("@");return 2===t.length&&x(`https://${t[1]}`)}(N))return _(d),t=setTimeout((()=>_(e)),2e3),()=>clearTimeout(t);const r=a+N;_(p),c()({path:r}).then((({url:t,template:r})=>{I&&$({profileURL:N,template:r}),_(m),setTimeout((()=>{window.open(t,"_blank"),_(e)}),200)})).catch((()=>{_(v),setTimeout((()=>_(e)),2e3)}))}),[N]);return(0,o.createElement)("div",{className:"activitypub__dialog"},(0,o.createElement)("div",{className:"activitypub-dialog__section"},(0,o.createElement)("h4",null,f),(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:C},(0,o.createElement)(h,{icon:O}),(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 yourusername@example.com)","activitypub"),{code:(0,o.createElement)("code",null)})),(0,o.createElement)("div",{className:"activitypub-dialog__button-group"},(0,o.createElement)("input",{type:"text",value:N,onKeyDown:e=>{"Enter"===e?.code&&j()},onChange:e=>R(e.target.value)}),(0,o.createElement)(s.Button,{onClick:j},(0,o.createElement)(h,{icon:g}),y)),i&&(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:()=>{P(!I)}}))))}const{namespace:S}=window._activityPubOptions,C={avatar:"",webfinger:"@well@hello.dolly",name:(0,u.__)("Hello Dolly Fan Account","activitypub"),url:"#"};function N(e){if(!e)return C;const t={...C,...e};return t.avatar=t?.icon?.url,t}function R({profile:e,popupStyles:t,userId:r}){const{avatar:n,name:a,webfinger:l}=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:l},l)),(0,o.createElement)(I,{profile:e,popupStyles:t,userId:r}))}function I({profile:e,popupStyles:t,userId:r}){const[a,l]=(0,n.useState)(!1),i=(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:()=>l(!0)},(0,u.__)("Follow","activitypub")),a&&(0,o.createElement)(s.Modal,{className:"activitypub-profile__confirm activitypub__modal",onRequestClose:()=>l(!1),title:i},(0,o.createElement)(P,{profile:e,userId:r}),(0,o.createElement)("style",null,t)))}function P({profile:e,userId:t}){const{webfinger:r}=e,n=(0,u.__)("Follow","activitypub"),a=`/${S}/actors/${t}/remote-follow?resource=`,l=(0,u.__)("Copy and paste my profile into the search field of your favorite fediverse app or server.","activitypub");return(0,o.createElement)(O,{actionText:n,copyDescription:l,handle:r,resourceUrl:a})}function $({selectedUser:e,style:t,backgroundColor:r,id:a,useId:l=!1,profileData:i=!1}){const[s,u]=(0,n.useState)(N()),p="site"===e?0:e,v=function(e){return d(".apfmd__button-group .components-button",m(e?.elements?.link?.color?.text)||"#111","#fff",m(e?.elements?.link?.[":hover"]?.color?.text)||"#333")}(t),y=l?{id:a}:{};function _(e){u(N(e))}return(0,n.useEffect)((()=>{if(i)return _(i);(function(e){const t={headers:{Accept:"application/activity+json"},path:`/${S}/actors/${e}`};return c()(t)})(p).then(_)}),[p,i]),(0,o.createElement)("div",{...y},(0,o.createElement)(f,{selector:`#${a}`,style:t,backgroundColor:r}),(0,o.createElement)(R,{profile:s,userId:p,popupStyles:v}))}let j=1;l()((()=>{[].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)($,{...t,id:"activitypub-follow-me-block-"+j++,useId:!0}))}))}))},20:(e,t,r)=>{var o=r(609),n=Symbol.for("react.element"),a=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),l=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={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)a.call(t,o)&&!i.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:l.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 a=r[e]={exports:{}};return t[e](a,a.exports,o),a.exports}o.m=t,e=[],o.O=(t,r,n,a)=>{if(!r){var l=1/0;for(u=0;u=a)&&Object.keys(o.O).every((e=>o.O[e](r[c])))?r.splice(c--,1):(i=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[r,n,a]},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,a,[l,i,c]=r,s=0;if(l.some((t=>0!==e[t]))){for(n in i)o.o(i,n)&&(o.m[n]=i[n]);if(c)var u=c(o)}for(t&&t(r);so(729)));n=o.O(n)})(); \ No newline at end of file diff --git a/build/followers/block.json b/build/followers/block.json index c7015d33..078b82f3 100644 --- a/build/followers/block.json +++ b/build/followers/block.json @@ -33,6 +33,10 @@ ] } }, + "usesContext": [ + "postType", + "postId" + ], "styles": [ { "name": "default", diff --git a/build/followers/index.asset.php b/build/followers/index.asset.php index 94ceb3d4..e147e810 100644 --- a/build/followers/index.asset.php +++ b/build/followers/index.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-url'), 'version' => 'aaa7aa378fccecb81d65'); + array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-url'), 'version' => '28a5bef9295566598f5c'); diff --git a/build/followers/index.js b/build/followers/index.js index da7156c4..2a5e6cf3 100644 --- a/build/followers/index.js +++ b/build/followers/index.js @@ -1,3 +1,4 @@ -(()=>{var e={20:(e,t,a)=>{"use strict";var r=a(609),n=Symbol.for("react.element"),l=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),o=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function s(e,t,a){var r,s={},c=null,p=null;for(r in void 0!==a&&(c=""+a),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(p=t.ref),t)l.call(t,r)&&!i.hasOwnProperty(r)&&(s[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===s[r]&&(s[r]=t[r]);return{$$typeof:n,type:e,key:c,ref:p,props:s,_owner:o.current}}t.jsx=s,t.jsxs=s},848:(e,t,a)=>{"use strict";e.exports=a(20)},609:e=>{"use strict";e.exports=window.React},942:(e,t)=>{var a;!function(){"use strict";var r={}.hasOwnProperty;function n(){for(var e="",t=0;t{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";const e=window.wp.blocks,t=window.wp.primitives;var r=a(848);const n=(0,r.jsx)(t.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,r.jsx)(t.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"})}),l=window.wp.components,o=window.wp.element,i=window.wp.blockEditor,s=window.wp.i18n;var c=a(609);const p=window.wp.apiFetch;var u=a.n(p);const v=window.wp.url;var d=a(942),w=a.n(d);function f({active:e,children:t,page:a,pageClick:r,className:n}){const l=w()("wp-block activitypub-pager",n,{current:e});return(0,c.createElement)("a",{className:l,onClick:t=>{t.preventDefault(),!e&&r(a)}},t)}const b={outlined:"outlined",minimal:"minimal"};function m({compact:e,nextLabel:t,page:a,pageClick:n,perPage:l,prevLabel:o,total:i,variant:s=b.outlined}){const c=((e,t)=>{let a=[1,e-2,e-1,e,e+1,e+2,t];a.sort(((e,t)=>e-t)),a=a.filter(((e,a,r)=>e>=1&&e<=t&&r.lastIndexOf(e)===a));for(let e=a.length-2;e>=0;e--)a[e]===a[e+1]&&a.splice(e+1,1);return a})(a,Math.ceil(i/l)),p=w()("alignwide wp-block-query-pagination is-content-justification-space-between is-layout-flex wp-block-query-pagination-is-layout-flex",`is-${s}`,{"is-compact":e});return(0,r.jsxs)("nav",{className:p,children:[o&&(0,r.jsx)(f,{page:a-1,pageClick:n,active:1===a,"aria-label":o,className:"wp-block-query-pagination-previous block-editor-block-list__block",children:o},"prev"),!e&&(0,r.jsx)("div",{className:"block-editor-block-list__block wp-block wp-block-query-pagination-numbers",children:c.map((e=>(0,r.jsx)(f,{page:e,pageClick:n,active:e===a,className:"page-numbers",children:e},e)))}),t&&(0,r.jsx)(f,{page:a+1,pageClick:n,active:a===Math.ceil(i/l),"aria-label":t,className:"wp-block-query-pagination-next block-editor-block-list__block",children:t},"next")]})}const{namespace:g}=window._activityPubOptions;function y({selectedUser:e,per_page:t,order:a,title:r,page:n,setPage:l,className:i="",followLinks:p=!0,followerData:d=!1}){const w="site"===e?0:e,[f,b]=(0,c.useState)([]),[y,h]=(0,c.useState)(0),[k,x]=(0,c.useState)(0),[E,j]=function(){const[e,t]=(0,c.useState)(1);return[e,t]}(),N=n||E,S=l||j,C=(0,o.createInterpolateElement)(/* translators: arrow for previous followers link */ /* translators: arrow for previous followers link */ -(0,s.__)(" Less","activitypub"),{span:(0,c.createElement)("span",{className:"wp-block-query-pagination-previous-arrow is-arrow-arrow","aria-hidden":"true"})}),O=(0,o.createInterpolateElement)(/* translators: arrow for next followers link */ /* translators: arrow for next followers link */ -(0,s.__)("More ","activitypub"),{span:(0,c.createElement)("span",{className:"wp-block-query-pagination-next-arrow is-arrow-arrow","aria-hidden":"true"})}),P=(e,a)=>{b(e),x(a),h(Math.ceil(a/t))};return(0,c.useEffect)((()=>{if(d&&1===N)return P(d.followers,d.total);const e=function(e,t,a,r){const n=`/${g}/actors/${e}/followers`,l={per_page:t,order:a,page:r,context:"full"};return(0,v.addQueryArgs)(n,l)}(w,t,a,N);u()({path:e}).then((e=>P(e.orderedItems,e.totalItems))).catch((()=>{}))}),[w,t,a,N,d]),(0,c.createElement)("div",{className:"activitypub-follower-block "+i},(0,c.createElement)("h3",null,r),(0,c.createElement)("ul",null,f&&f.map((e=>(0,c.createElement)("li",{key:e.url},(0,c.createElement)(_,{...e,followLinks:p}))))),y>1&&(0,c.createElement)(m,{page:N,perPage:t,total:k,pageClick:S,nextLabel:O,prevLabel:C,compact:"is-style-compact"===i}))}function _({name:e,icon:t,url:a,preferredUsername:r,followLinks:n=!0}){const o=`@${r}`,i={};return n||(i.onClick=e=>e.preventDefault()),(0,c.createElement)(l.ExternalLink,{className:"activitypub-link",href:a,title:o,...i},(0,c.createElement)("img",{width:"40",height:"40",src:t.url,className:"avatar activitypub-avatar",alt:e}),(0,c.createElement)("span",{className:"activitypub-actor"},(0,c.createElement)("strong",{className:"activitypub-name"},e),(0,c.createElement)("span",{className:"sep"},"/"),(0,c.createElement)("span",{className:"activitypub-handle"},o)))}const h=window.wp.data,k=window._activityPubOptions?.enabled;(0,e.registerBlockType)("activitypub/followers",{edit:function({attributes:e,setAttributes:t}){const{order:a,per_page:n,selectedUser:c,title:p}=e,u=(0,i.useBlockProps)(),[v,d]=(0,o.useState)(1),w=[{label:(0,s.__)("New to old","activitypub"),value:"desc"},{label:(0,s.__)("Old to new","activitypub"),value:"asc"}],f=function(){const e=k?.users?(0,h.useSelect)((e=>e("core").getUsers({who:"authors"}))):[];return(0,o.useMemo)((()=>{if(!e)return[];const t=k?.site?[{label:(0,s.__)("Whole Site","activitypub"),value:"site"}]:[];return e.reduce(((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e)),t)}),[e])}(),b=e=>a=>{d(1),t({[e]:a})};return(0,o.useEffect)((()=>{f.length&&(f.find((({value:e})=>e===c))||t({selectedUser:f[0].value}))}),[c,f]),(0,r.jsxs)("div",{...u,children:[(0,r.jsx)(i.InspectorControls,{children:(0,r.jsxs)(l.PanelBody,{title:(0,s.__)("Followers Options","activitypub"),children:[(0,r.jsx)(l.TextControl,{label:(0,s.__)("Title","activitypub"),help:(0,s.__)("Title to display above the list of followers. Blank for none.","activitypub"),value:p,onChange:e=>t({title:e})}),f.length>1&&(0,r.jsx)(l.SelectControl,{label:(0,s.__)("Select User","activitypub"),value:c,options:f,onChange:b("selectedUser")}),(0,r.jsx)(l.SelectControl,{label:(0,s.__)("Sort","activitypub"),value:a,options:w,onChange:b("order")}),(0,r.jsx)(l.RangeControl,{label:(0,s.__)("Number of Followers","activitypub"),value:n,onChange:b("per_page"),min:1,max:10})]})},"setting"),(0,r.jsx)(y,{...e,page:v,setPage:d,followLinks:!1})]})},save:()=>null,icon:n})})()})(); \ No newline at end of file +(()=>{var e={20:(e,t,a)=>{"use strict";var r=a(609),n=Symbol.for("react.element"),l=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),o=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};t.jsx=function(e,t,a){var r,s={},c=null,p=null;for(r in void 0!==a&&(c=""+a),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(p=t.ref),t)l.call(t,r)&&!i.hasOwnProperty(r)&&(s[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===s[r]&&(s[r]=t[r]);return{$$typeof:n,type:e,key:c,ref:p,props:s,_owner:o.current}}},848:(e,t,a)=>{"use strict";e.exports=a(20)},609:e=>{"use strict";e.exports=window.React},942:(e,t)=>{var a;!function(){"use strict";var r={}.hasOwnProperty;function n(){for(var e="",t=0;t{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";const e=window.wp.blocks,t=window.wp.primitives;var r=a(848);const n=(0,r.jsx)(t.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,r.jsx)(t.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=a(609);const o=window.wp.components,i=window.wp.element,s=window.wp.blockEditor,c=window.wp.data,p=window.wp.coreData,u=window.wp.i18n,m=window.wp.apiFetch;var v=a.n(m);const d=window.wp.url;var w=a(942),f=a.n(w);function b({active:e,children:t,page:a,pageClick:r,className:n}){const o=f()("wp-block activitypub-pager",n,{current:e});return(0,l.createElement)("a",{className:o,onClick:t=>{t.preventDefault(),!e&&r(a)}},t)}const y={outlined:"outlined",minimal:"minimal"};function g({compact:e,nextLabel:t,page:a,pageClick:r,perPage:n,prevLabel:o,total:i,variant:s=y.outlined}){const c=((e,t)=>{let a=[1,e-2,e-1,e,e+1,e+2,t];a.sort(((e,t)=>e-t)),a=a.filter(((e,a,r)=>e>=1&&e<=t&&r.lastIndexOf(e)===a));for(let e=a.length-2;e>=0;e--)a[e]===a[e+1]&&a.splice(e+1,1);return a})(a,Math.ceil(i/n)),p=f()("alignwide wp-block-query-pagination is-content-justification-space-between is-layout-flex wp-block-query-pagination-is-layout-flex",`is-${s}`,{"is-compact":e});return(0,l.createElement)("nav",{className:p},o&&(0,l.createElement)(b,{key:"prev",page:a-1,pageClick:r,active:1===a,"aria-label":o,className:"wp-block-query-pagination-previous block-editor-block-list__block"},o),!e&&(0,l.createElement)("div",{className:"block-editor-block-list__block wp-block wp-block-query-pagination-numbers"},c.map((e=>(0,l.createElement)(b,{key:e,page:e,pageClick:r,active:e===a,className:"page-numbers"},e)))),t&&(0,l.createElement)(b,{key:"next",page:a+1,pageClick:r,active:a===Math.ceil(i/n),"aria-label":t,className:"wp-block-query-pagination-next block-editor-block-list__block"},t))}const{namespace:h}=window._activityPubOptions;function _({selectedUser:e,per_page:t,order:a,title:r,page:n,setPage:o,className:s="",followLinks:c=!0,followerData:p=!1}){const m="site"===e?0:e,[w,f]=(0,l.useState)([]),[b,y]=(0,l.useState)(0),[_,E]=(0,l.useState)(0),[x,S]=function(){const[e,t]=(0,l.useState)(1);return[e,t]}(),N=n||x,C=o||S,O=(0,i.createInterpolateElement)(/* translators: arrow for previous followers link */ /* translators: arrow for previous followers link */ +(0,u.__)(" Less","activitypub"),{span:(0,l.createElement)("span",{className:"wp-block-query-pagination-previous-arrow is-arrow-arrow","aria-hidden":"true"})}),P=(0,i.createInterpolateElement)(/* translators: arrow for next followers link */ /* translators: arrow for next followers link */ +(0,u.__)("More ","activitypub"),{span:(0,l.createElement)("span",{className:"wp-block-query-pagination-next-arrow is-arrow-arrow","aria-hidden":"true"})}),I=(e,a)=>{f(e),E(a),y(Math.ceil(a/t))};return(0,l.useEffect)((()=>{if(p&&1===N)return I(p.followers,p.total);const e=function(e,t,a,r){const n=`/${h}/actors/${e}/followers`,l={per_page:t,order:a,page:r,context:"full"};return(0,d.addQueryArgs)(n,l)}(m,t,a,N);v()({path:e}).then((e=>I(e.orderedItems,e.totalItems))).catch((()=>{}))}),[m,t,a,N,p]),(0,l.createElement)("div",{className:"activitypub-follower-block "+s},(0,l.createElement)("h3",null,r),(0,l.createElement)("ul",null,w&&w.map((e=>(0,l.createElement)("li",{key:e.url},(0,l.createElement)(k,{...e,followLinks:c}))))),b>1&&(0,l.createElement)(g,{page:N,perPage:t,total:_,pageClick:C,nextLabel:P,prevLabel:O,compact:"is-style-compact"===s}))}function k({name:e,icon:t,url:a,preferredUsername:r,followLinks:n=!0}){const i=`@${r}`,s={};return n||(s.onClick=e=>e.preventDefault()),(0,l.createElement)(o.ExternalLink,{className:"activitypub-link",href:a,title:i,...s},(0,l.createElement)("img",{width:"40",height:"40",src:t.url,className:"avatar activitypub-avatar",alt:e}),(0,l.createElement)("span",{className:"activitypub-actor"},(0,l.createElement)("strong",{className:"activitypub-name"},e),(0,l.createElement)("span",{className:"sep"},"/"),(0,l.createElement)("span",{className:"activitypub-handle"},i)))}const E=window._activityPubOptions?.enabled;function x({name:e}){const t=(0,u.sprintf)(/* translators: %s: block name */ +"This %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. It will be empty in other non-author contexts.",e);return(0,l.createElement)(o.Card,null,(0,l.createElement)(o.CardBody,null,(0,i.createInterpolateElement)(t,{strong:(0,l.createElement)("strong",null)})))}(0,e.registerBlockType)("activitypub/followers",{edit:function({attributes:e,setAttributes:t,context:{postType:a,postId:r}}){const{order:n,per_page:m,selectedUser:v,title:d}=e,w=(0,s.useBlockProps)(),[f,b]=(0,i.useState)(1),y=[{label:(0,u.__)("New to old","activitypub"),value:"desc"},{label:(0,u.__)("Old to new","activitypub"),value:"asc"}],g=function({withInherit:e=!1}){const t=E?.users?(0,c.useSelect)((e=>e("core").getUsers({who:"authors"}))):[];return(0,i.useMemo)((()=>{if(!t)return[];const a=[];return E?.site&&a.push({label:(0,u.__)("Site","activitypub"),value:"site"}),e&&E?.users&&a.push({label:(0,u.__)("Dynamic User","activitypub"),value:"inherit"}),t.reduce(((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e)),a)}),[t])}({withInherit:!0}),h=e=>a=>{b(1),t({[e]:a})},k=(0,c.useSelect)((e=>{const{getEditedEntityRecord:t}=e(p.store),n=t("postType",a,r)?.author;return null!=n?n:null}),[a,r]);return(0,i.useEffect)((()=>{g.length&&(g.find((({value:e})=>e===v))||t({selectedUser:g[0].value}))}),[v,g]),(0,l.createElement)("div",{...w},(0,l.createElement)(s.InspectorControls,{key:"setting"},(0,l.createElement)(o.PanelBody,{title:(0,u.__)("Followers Options","activitypub")},(0,l.createElement)(o.TextControl,{label:(0,u.__)("Title","activitypub"),help:(0,u.__)("Title to display above the list of followers. Blank for none.","activitypub"),value:d,onChange:e=>t({title:e})}),g.length>1&&(0,l.createElement)(o.SelectControl,{label:(0,u.__)("Select User","activitypub"),value:v,options:g,onChange:h("selectedUser")}),(0,l.createElement)(o.SelectControl,{label:(0,u.__)("Sort","activitypub"),value:n,options:y,onChange:h("order")}),(0,l.createElement)(o.RangeControl,{label:(0,u.__)("Number of Followers","activitypub"),value:m,onChange:h("per_page"),min:1,max:10}))),"inherit"===v?k?(0,l.createElement)(_,{...e,page:f,setPage:b,followLinks:!1,selectedUser:k}):(0,l.createElement)(x,{name:(0,u.__)("Followers","activitypub")}):(0,l.createElement)(_,{...e,page:f,setPage:b,followLinks:!1}))},save:()=>null,icon:n})})()})(); \ No newline at end of file diff --git a/build/followers/view.asset.php b/build/followers/view.asset.php index 0870865c..4e64279d 100644 --- a/build/followers/view.asset.php +++ b/build/followers/view.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => 'fa8a5fc56fc73c38ebad'); + array('react', 'wp-api-fetch', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '111b88843c05346aadbf'); diff --git a/build/followers/view.js b/build/followers/view.js index 9d1fb21e..e9a5792a 100644 --- a/build/followers/view.js +++ b/build/followers/view.js @@ -1,3 +1,3 @@ -(()=>{var e,t={647:(e,t,r)=>{"use strict";var a=r(609);const n=window.wp.apiFetch;var o=r.n(n);const l=window.wp.url,i=window.wp.element,c=window.wp.i18n;var s=r(942),p=r.n(s);function u({active:e,children:t,page:r,pageClick:n,className:o}){const l=p()("wp-block activitypub-pager",o,{current:e});return(0,a.createElement)("a",{className:l,onClick:t=>{t.preventDefault(),!e&&n(r)}},t)}var f=r(848);const m={outlined:"outlined",minimal:"minimal"};function d({compact:e,nextLabel:t,page:r,pageClick:a,perPage:n,prevLabel:o,total:l,variant:i=m.outlined}){const c=((e,t)=>{let r=[1,e-2,e-1,e,e+1,e+2,t];r.sort(((e,t)=>e-t)),r=r.filter(((e,r,a)=>e>=1&&e<=t&&a.lastIndexOf(e)===r));for(let e=r.length-2;e>=0;e--)r[e]===r[e+1]&&r.splice(e+1,1);return r})(r,Math.ceil(l/n)),s=p()("alignwide wp-block-query-pagination is-content-justification-space-between is-layout-flex wp-block-query-pagination-is-layout-flex",`is-${i}`,{"is-compact":e});return(0,f.jsxs)("nav",{className:s,children:[o&&(0,f.jsx)(u,{page:r-1,pageClick:a,active:1===r,"aria-label":o,className:"wp-block-query-pagination-previous block-editor-block-list__block",children:o},"prev"),!e&&(0,f.jsx)("div",{className:"block-editor-block-list__block wp-block wp-block-query-pagination-numbers",children:c.map((e=>(0,f.jsx)(u,{page:e,pageClick:a,active:e===r,className:"page-numbers",children:e},e)))}),t&&(0,f.jsx)(u,{page:r+1,pageClick:a,active:r===Math.ceil(l/n),"aria-label":t,className:"wp-block-query-pagination-next block-editor-block-list__block",children:t},"next")]})}const v=window.wp.components,{namespace:b}=window._activityPubOptions;function w({selectedUser:e,per_page:t,order:r,title:n,page:s,setPage:p,className:u="",followLinks:f=!0,followerData:m=!1}){const v="site"===e?0:e,[w,g]=(0,a.useState)([]),[k,h]=(0,a.useState)(0),[_,E]=(0,a.useState)(0),[x,O]=function(){const[e,t]=(0,a.useState)(1);return[e,t]}(),N=s||x,S=p||O,j=(0,i.createInterpolateElement)(/* translators: arrow for previous followers link */ /* translators: arrow for previous followers link */ -(0,c.__)(" Less","activitypub"),{span:(0,a.createElement)("span",{className:"wp-block-query-pagination-previous-arrow is-arrow-arrow","aria-hidden":"true"})}),C=(0,i.createInterpolateElement)(/* translators: arrow for next followers link */ /* translators: arrow for next followers link */ -(0,c.__)("More ","activitypub"),{span:(0,a.createElement)("span",{className:"wp-block-query-pagination-next-arrow is-arrow-arrow","aria-hidden":"true"})}),L=(e,r)=>{g(e),E(r),h(Math.ceil(r/t))};return(0,a.useEffect)((()=>{if(m&&1===N)return L(m.followers,m.total);const e=function(e,t,r,a){const n=`/${b}/actors/${e}/followers`,o={per_page:t,order:r,page:a,context:"full"};return(0,l.addQueryArgs)(n,o)}(v,t,r,N);o()({path:e}).then((e=>L(e.orderedItems,e.totalItems))).catch((()=>{}))}),[v,t,r,N,m]),(0,a.createElement)("div",{className:"activitypub-follower-block "+u},(0,a.createElement)("h3",null,n),(0,a.createElement)("ul",null,w&&w.map((e=>(0,a.createElement)("li",{key:e.url},(0,a.createElement)(y,{...e,followLinks:f}))))),k>1&&(0,a.createElement)(d,{page:N,perPage:t,total:_,pageClick:S,nextLabel:C,prevLabel:j,compact:"is-style-compact"===u}))}function y({name:e,icon:t,url:r,preferredUsername:n,followLinks:o=!0}){const l=`@${n}`,i={};return o||(i.onClick=e=>e.preventDefault()),(0,a.createElement)(v.ExternalLink,{className:"activitypub-link",href:r,title:l,...i},(0,a.createElement)("img",{width:"40",height:"40",src:t.url,className:"avatar activitypub-avatar",alt:e}),(0,a.createElement)("span",{className:"activitypub-actor"},(0,a.createElement)("strong",{className:"activitypub-name"},e),(0,a.createElement)("span",{className:"sep"},"/"),(0,a.createElement)("span",{className:"activitypub-handle"},l)))}const g=window.wp.domReady;r.n(g)()((()=>{[].forEach.call(document.querySelectorAll(".activitypub-follower-block"),(e=>{const t=JSON.parse(e.dataset.attrs);(0,i.createRoot)(e).render((0,a.createElement)(w,{...t}))}))}))},20:(e,t,r)=>{"use strict";var a=r(609),n=Symbol.for("react.element"),o=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),l=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,r){var a,c={},s=null,p=null;for(a in void 0!==r&&(s=""+r),void 0!==t.key&&(s=""+t.key),void 0!==t.ref&&(p=t.ref),t)o.call(t,a)&&!i.hasOwnProperty(a)&&(c[a]=t[a]);if(e&&e.defaultProps)for(a in t=e.defaultProps)void 0===c[a]&&(c[a]=t[a]);return{$$typeof:n,type:e,key:s,ref:p,props:c,_owner:l.current}}t.jsx=c,t.jsxs=c},848:(e,t,r)=>{"use strict";e.exports=r(20)},609:e=>{"use strict";e.exports=window.React},942:(e,t)=>{var r;!function(){"use strict";var a={}.hasOwnProperty;function n(){for(var e="",t=0;t{if(!r){var l=1/0;for(p=0;p=o)&&Object.keys(a.O).every((e=>a.O[e](r[c])))?r.splice(c--,1):(i=!1,o0&&e[p-1][2]>o;p--)e[p]=e[p-1];e[p]=[r,n,o]},a.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={996:0,528:0};a.O.j=t=>0===e[t];var t=(t,r)=>{var n,o,[l,i,c]=r,s=0;if(l.some((t=>0!==e[t]))){for(n in i)a.o(i,n)&&(a.m[n]=i[n]);if(c)var p=c(a)}for(t&&t(r);sa(647)));n=a.O(n)})(); \ No newline at end of file +(()=>{var e,t={250:(e,t,a)=>{"use strict";const r=window.React,n=window.wp.apiFetch;var l=a.n(n);const o=window.wp.url,i=window.wp.element,c=window.wp.i18n;var s=a(942),p=a.n(s);function u({active:e,children:t,page:a,pageClick:n,className:l}){const o=p()("wp-block activitypub-pager",l,{current:e});return(0,r.createElement)("a",{className:o,onClick:t=>{t.preventDefault(),!e&&n(a)}},t)}const m={outlined:"outlined",minimal:"minimal"};function f({compact:e,nextLabel:t,page:a,pageClick:n,perPage:l,prevLabel:o,total:i,variant:c=m.outlined}){const s=((e,t)=>{let a=[1,e-2,e-1,e,e+1,e+2,t];a.sort(((e,t)=>e-t)),a=a.filter(((e,a,r)=>e>=1&&e<=t&&r.lastIndexOf(e)===a));for(let e=a.length-2;e>=0;e--)a[e]===a[e+1]&&a.splice(e+1,1);return a})(a,Math.ceil(i/l)),f=p()("alignwide wp-block-query-pagination is-content-justification-space-between is-layout-flex wp-block-query-pagination-is-layout-flex",`is-${c}`,{"is-compact":e});return(0,r.createElement)("nav",{className:f},o&&(0,r.createElement)(u,{key:"prev",page:a-1,pageClick:n,active:1===a,"aria-label":o,className:"wp-block-query-pagination-previous block-editor-block-list__block"},o),!e&&(0,r.createElement)("div",{className:"block-editor-block-list__block wp-block wp-block-query-pagination-numbers"},s.map((e=>(0,r.createElement)(u,{key:e,page:e,pageClick:n,active:e===a,className:"page-numbers"},e)))),t&&(0,r.createElement)(u,{key:"next",page:a+1,pageClick:n,active:a===Math.ceil(i/l),"aria-label":t,className:"wp-block-query-pagination-next block-editor-block-list__block"},t))}const v=window.wp.components,{namespace:b}=window._activityPubOptions;function d({selectedUser:e,per_page:t,order:a,title:n,page:s,setPage:p,className:u="",followLinks:m=!0,followerData:v=!1}){const d="site"===e?0:e,[g,y]=(0,r.useState)([]),[k,h]=(0,r.useState)(0),[E,N]=(0,r.useState)(0),[x,_]=function(){const[e,t]=(0,r.useState)(1);return[e,t]}(),O=s||x,S=p||_,C=(0,i.createInterpolateElement)(/* translators: arrow for previous followers link */ /* translators: arrow for previous followers link */ +(0,c.__)(" Less","activitypub"),{span:(0,r.createElement)("span",{className:"wp-block-query-pagination-previous-arrow is-arrow-arrow","aria-hidden":"true"})}),L=(0,i.createInterpolateElement)(/* translators: arrow for next followers link */ /* translators: arrow for next followers link */ +(0,c.__)("More ","activitypub"),{span:(0,r.createElement)("span",{className:"wp-block-query-pagination-next-arrow is-arrow-arrow","aria-hidden":"true"})}),q=(e,a)=>{y(e),N(a),h(Math.ceil(a/t))};return(0,r.useEffect)((()=>{if(v&&1===O)return q(v.followers,v.total);const e=function(e,t,a,r){const n=`/${b}/actors/${e}/followers`,l={per_page:t,order:a,page:r,context:"full"};return(0,o.addQueryArgs)(n,l)}(d,t,a,O);l()({path:e}).then((e=>q(e.orderedItems,e.totalItems))).catch((()=>{}))}),[d,t,a,O,v]),(0,r.createElement)("div",{className:"activitypub-follower-block "+u},(0,r.createElement)("h3",null,n),(0,r.createElement)("ul",null,g&&g.map((e=>(0,r.createElement)("li",{key:e.url},(0,r.createElement)(w,{...e,followLinks:m}))))),k>1&&(0,r.createElement)(f,{page:O,perPage:t,total:E,pageClick:S,nextLabel:L,prevLabel:C,compact:"is-style-compact"===u}))}function w({name:e,icon:t,url:a,preferredUsername:n,followLinks:l=!0}){const o=`@${n}`,i={};return l||(i.onClick=e=>e.preventDefault()),(0,r.createElement)(v.ExternalLink,{className:"activitypub-link",href:a,title:o,...i},(0,r.createElement)("img",{width:"40",height:"40",src:t.url,className:"avatar activitypub-avatar",alt:e}),(0,r.createElement)("span",{className:"activitypub-actor"},(0,r.createElement)("strong",{className:"activitypub-name"},e),(0,r.createElement)("span",{className:"sep"},"/"),(0,r.createElement)("span",{className:"activitypub-handle"},o)))}const g=window.wp.domReady;a.n(g)()((()=>{[].forEach.call(document.querySelectorAll(".activitypub-follower-block"),(e=>{const t=JSON.parse(e.dataset.attrs);(0,i.createRoot)(e).render((0,r.createElement)(d,{...t}))}))}))},942:(e,t)=>{var a;!function(){"use strict";var r={}.hasOwnProperty;function n(){for(var e="",t=0;t{if(!a){var o=1/0;for(p=0;p=l)&&Object.keys(r.O).every((e=>r.O[e](a[c])))?a.splice(c--,1):(i=!1,l0&&e[p-1][2]>l;p--)e[p]=e[p-1];e[p]=[a,n,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 a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={996:0,528:0};r.O.j=t=>0===e[t];var t=(t,a)=>{var n,l,[o,i,c]=a,s=0;if(o.some((t=>0!==e[t]))){for(n in i)r.o(i,n)&&(r.m[n]=i[n]);if(c)var p=c(r)}for(t&&t(a);sr(250)));n=r.O(n)})(); \ No newline at end of file diff --git a/includes/class-blocks.php b/includes/class-blocks.php index 666034f3..5190feb1 100644 --- a/includes/class-blocks.php +++ b/includes/class-blocks.php @@ -67,12 +67,56 @@ class Blocks { ); } + /** + * Get the user ID from a user string. + * + * @param string $user_string The user string. Can be a user ID, 'site', or 'inherit'. + * @return int|null The user ID, or null if the 'inherit' string is not supported in this context. + */ private static function get_user_id( $user_string ) { if ( is_numeric( $user_string ) ) { return absint( $user_string ); } - // any other non-numeric falls back to 0, including the `site` string used in the UI - return 0; + + // if the user string is 'site', return the Blog User ID. + if ( 'site' === $user_string ) { + return User_Collection::BLOG_USER_ID; + } + + // The only other value should be 'inherit', which means to use the query context to determine the User. + if ( 'inherit' !== $user_string ) { + return null; + } + + // For a homepage/front page, if the Blog User is active, use it. + if ( ( is_front_page() || is_home() ) && ! is_user_type_disabled( 'blog' ) ) { + return User_Collection::BLOG_USER_ID; + } + + // If we're in a loop, use the post author + $author_id = get_the_author_meta( 'ID' ); + if ( $author_id ) { + return $author_id; + } + + // For other pages, the queried object will clue us in. + $queried_object = get_queried_object(); + if ( ! $queried_object ) { + return null; + } + + // If we're on a user archive page, use that user's ID. + if ( is_a( $queried_object, 'WP_User' ) ) { + return $queried_object->ID; + } + + // For a single post, use the post author's ID. + if ( is_a( $queried_object, 'WP_Post' ) ) { + return get_the_author_meta( 'ID' ); + } + + // We won't properly account for some conditions, like tag archives. + return null; } /** @@ -93,13 +137,21 @@ class Blocks { public static function render_follow_me_block( $attrs ) { $user_id = self::get_user_id( $attrs['selectedUser'] ); $user = User_Collection::get_by_id( $user_id ); - if ( ! is_wp_error( $user ) ) { - $attrs['profileData'] = self::filter_array_by_keys( - $user->to_array(), - array( 'icon', 'name', 'webfinger' ) - ); + if ( is_wp_error( $user ) ) { + if ( 'inherit' === $attrs['selectedUser'] ) { + // If the user is 'inherit' and we couldn't determine the user, don't render anything. + return ''; + } else { + // If the user is a specific ID and we couldn't find it, render an error message. + return ''; + } } + $attrs['profileData'] = self::filter_array_by_keys( + $user->to_array(), + array( 'icon', 'name', 'webfinger' ) + ); + // add `@` prefix if it's missing if ( '@' !== substr( $attrs['profileData']['webfinger'], 0, 1 ) ) { $attrs['profileData']['webfinger'] = '@' . $attrs['profileData']['webfinger']; @@ -118,6 +170,14 @@ class Blocks { public static function render_follower_block( $attrs ) { $followee_user_id = self::get_user_id( $attrs['selectedUser'] ); + if ( is_null( $followee_user_id ) ) { + return ''; + } + $user = User_Collection::get_by_id( $followee_user_id ); + if ( is_wp_error( $user ) ) { + return ''; + } + $per_page = absint( $attrs['per_page'] ); $follower_data = Followers::get_followers_with_count( $followee_user_id, $per_page ); diff --git a/src/follow-me/block.json b/src/follow-me/block.json index 9e679e07..5c5c9e5d 100644 --- a/src/follow-me/block.json +++ b/src/follow-me/block.json @@ -38,6 +38,7 @@ "default": "site" } }, + "usesContext": [ "postType", "postId" ], "editorScript": "file:./index.js", "viewScript": "file:./view.js", "style": ["file:./style-view.css", "wp-components"] diff --git a/src/follow-me/edit.js b/src/follow-me/edit.js index b1b49eff..be74d288 100644 --- a/src/follow-me/edit.js +++ b/src/follow-me/edit.js @@ -1,16 +1,39 @@ 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 { useUserOptions } from '../shared/use-user-options'; import FollowMe from './follow-me'; import { useEffect } from '@wordpress/element'; +import { InheritModeBlockFallback } from '../shared/inherit-block-fallback'; -export default function Edit( { attributes, setAttributes } ) { + +export default function Edit( { + attributes, + setAttributes, + context: { postType, postId }, +} ) { const blockProps = useBlockProps( { className: 'activitypub-follow-me-block-wrapper', } ); - const usersOptions = useUserOptions(); + const usersOptions = useUserOptions( { withInherit: true } ); const { selectedUser } = attributes; + const isInheritMode = selectedUser === 'inherit'; + + const authorId = useSelect( + ( select ) => { + const { getEditedEntityRecord } = select( coreStore ); + const _authorId = getEditedEntityRecord( + 'postType', + postType, + postId + )?.author; + + return _authorId ?? null; + }, + [ postType, postId ] + ); useEffect( () => { // if there are no users yet, do nothing @@ -37,7 +60,15 @@ export default function Edit( { attributes, setAttributes } ) { ) } - + { isInheritMode ? + authorId ? ( + + ) : ( + + ) + : ( + + ) } ); } diff --git a/src/followers/block.json b/src/followers/block.json index 564032f5..b058c01a 100644 --- a/src/followers/block.json +++ b/src/followers/block.json @@ -30,6 +30,7 @@ "enum": [ "asc", "desc" ] } }, + "usesContext": [ "postType", "postId" ], "styles": [ { "name": "default", "label": "No Lines", "isDefault": true }, { "name": "with-lines", "label": "Lines" }, diff --git a/src/followers/edit.js b/src/followers/edit.js index 2cedadc2..a18c941c 100644 --- a/src/followers/edit.js +++ b/src/followers/edit.js @@ -1,11 +1,18 @@ import { SelectControl, RangeControl, PanelBody, TextControl } from '@wordpress/components'; import { useState, useEffect } from '@wordpress/element'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; +import { useSelect } from '@wordpress/data'; +import { store as coreStore } from '@wordpress/core-data'; import { __ } from '@wordpress/i18n'; import { Followers } from './followers'; import { useUserOptions } from '../shared/use-user-options'; +import { InheritModeBlockFallback } from '../shared/inherit-block-fallback'; -export default function Edit( { attributes, setAttributes } ) { +export default function Edit( { + attributes, + setAttributes, + context: { postType, postId }, +} ) { const { order, per_page, selectedUser, title } = attributes; const blockProps = useBlockProps(); const [ page, setPage ] = useState( 1 ); @@ -13,13 +20,26 @@ export default function Edit( { attributes, setAttributes } ) { { label: __( 'New to old', 'activitypub' ), value: 'desc' }, { label: __( 'Old to new', 'activitypub' ), value: 'asc' }, ]; - const usersOptions = useUserOptions(); + const usersOptions = useUserOptions( { withInherit: true } ); const setAttributestAndResetPage = ( key ) => { return ( value ) => { setPage( 1 ); setAttributes( { [ key ]: value } ); }; } + const authorId = useSelect( + ( select ) => { + const { getEditedEntityRecord } = select( coreStore ); + const _authorId = getEditedEntityRecord( + 'postType', + postType, + postId + )?.author; + + return _authorId ?? null; + }, + [ postType, postId ] + ); useEffect( () => { // if there are no users yet, do nothing @@ -65,7 +85,15 @@ export default function Edit( { attributes, setAttributes } ) { /> - + { selectedUser === 'inherit' ? + authorId ? ( + + ) : ( + + ) + : ( + + ) } ); } \ No newline at end of file diff --git a/src/shared/inherit-block-fallback.js b/src/shared/inherit-block-fallback.js new file mode 100644 index 00000000..a4caca1e --- /dev/null +++ b/src/shared/inherit-block-fallback.js @@ -0,0 +1,17 @@ +import { Card, CardBody } from '@wordpress/components'; +import { sprintf } from '@wordpress/i18n'; +import { createInterpolateElement } from '@wordpress/element'; + +export function InheritModeBlockFallback( { name } ) { + const text = sprintf( + /* translators: %s: block name */ + 'This %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. It will be empty in other non-author contexts.', + name + ); + + return ( + + { createInterpolateElement( text, { strong: } ) } + + ); +} \ No newline at end of file diff --git a/src/shared/use-user-options.js b/src/shared/use-user-options.js index ac6d1c16..e1ac9840 100644 --- a/src/shared/use-user-options.js +++ b/src/shared/use-user-options.js @@ -3,22 +3,35 @@ import { useSelect } from '@wordpress/data'; import { useMemo } from '@wordpress/element'; const enabled = window._activityPubOptions?.enabled; -export function useUserOptions() { +export function useUserOptions( { withInherit = false } ) { const users = enabled?.users ? useSelect( ( select ) => select( 'core' ).getUsers( { who: 'authors' } ) ) : []; return useMemo( () => { if ( ! users ) { return []; } - const withBlogUser = enabled?.site ? [ { - label: __( 'Whole Site', 'activitypub' ), - value: 'site' - } ] : []; + const userKeywords = []; + + if ( enabled?.site ) { + userKeywords.push( { + label: __( 'Site', 'activitypub' ), + value: 'site' + } ); + } + + // Only show inherit option when explicitly asked for and users are enabled. + if ( withInherit && enabled?.users ) { + userKeywords.push( { + label: __( 'Dynamic User', 'activitypub' ), + value: 'inherit' + } ); + } + return users.reduce( ( acc, user ) => { acc.push({ label: user.name, value: `${ user.id }` // casting to string because that's how the attribute is stored by Gutenberg } ); return acc; - }, withBlogUser ); + }, userKeywords ); }, [ users ] ); } \ No newline at end of file