laipower/wp-content/plugins/activitypub/build/remote-reply/index.js

1 line
5.0 KiB
JavaScript
Raw Normal View History

(()=>{"use strict";var e,t={667:(e,t,n)=>{const o=window.wp.element,r=window.wp.domReady;var a=n.n(r);const i=window.wp.components,c=window.wp.i18n,l=window.wp.apiFetch;var u=n.n(l);const s=window.wp.primitives,p=(0,o.createElement)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(s.Path,{d:"M20.2 8v11c0 .7-.6 1.2-1.2 1.2H6v1.5h13c1.5 0 2.7-1.2 2.7-2.8V8zM18 16.4V4.6c0-.9-.7-1.6-1.6-1.6H4.6C3.7 3 3 3.7 3 4.6v11.8c0 .9.7 1.6 1.6 1.6h11.8c.9 0 1.6-.7 1.6-1.6zm-13.5 0V4.6c0-.1.1-.1.1-.1h11.8c.1 0 .1.1.1.1v11.8c0 .1-.1.1-.1.1H4.6l-.1-.1z"})),m=(0,o.createElement)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(s.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})),d=function({icon:e,size:t=24,...n}){return(0,o.cloneElement)(e,{width:t,height:t,...n})},v=window.wp.compose;function y(e){try{return new URL(e),!0}catch(e){return!1}}function _({actionText:e,copyDescription:t,handle:n,resourceUrl:r}){const a=(0,c.__)("Loading...","activitypub"),l=(0,c.__)("Opening...","activitypub"),s=(0,c.__)("Error","activitypub"),_=(0,c.__)("Invalid","activitypub"),[w,b]=(0,o.useState)(e),[h,f]=(0,o.useState)(p),E=(0,v.useCopyToClipboard)(n,(()=>{f(m),setTimeout((()=>f(p)),1e3)})),[g,C]=(0,o.useState)(""),O=(0,o.useCallback)((()=>{let t;if(!y(g)&&!function(e){const t=e.replace(/^@/,"").split("@");return 2===t.length&&y(`https://${t[1]}`)}(g))return b(_),t=setTimeout((()=>b(e)),2e3),()=>clearTimeout(t);const n=r+g;b(a),u()({path:n}).then((({url:t})=>{b(l),setTimeout((()=>{window.open(t,"_blank"),b(e)}),200)})).catch((()=>{b(s),setTimeout((()=>b(e)),2e3)}))}),[g]);return(0,o.createElement)("div",{className:"activitypub__dialog"},(0,o.createElement)("div",{className:"activitypub-dialog__section"},(0,o.createElement)("h4",null,(0,c.__)("My Profile","activitypub")),(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:n,readOnly:!0}),(0,o.createElement)(i.Button,{ref:E},(0,o.createElement)(d,{icon:h}),(0,c.__)("Copy","activitypub")))),(0,o.createElement)("div",{className:"activitypub-dialog__section"},(0,o.createElement)("h4",null,(0,c.__)("Your Profile","activitypub")),(0,o.createElement)("div",{className:"activitypub-dialog__description"},(0,o.createInterpolateElement)((0,c.__)("Or, if you know your own profile, we can start things that way! (eg <code>https://example.com/yourusername</code> or <code>yourusername@example.com</code>)","activitypub"),{code:(0,o.createElement)("code",null)})),(0,o.createElement)("div",{className:"activitypub-dialog__button-group"},(0,o.createElement)("input",{type:"text",value:g,onKeyDown:e=>{"Enter"===e?.code&&O()},onChange:e=>C(e.target.value)}),(0,o.createElement)(i.Button,{onClick:O},w))))}const{namespace:w}=window._activityPubOptions;function b({selectedComment:e,commentId:t}){const n=(0,c.__)("Reply","activitypub"),r=`/${w}/comments/${t}/remote-reply?resource=`,a=(0,c.__)("Copy and paste the Comment URL into the search field of your favorite fediverse app or server.","activitypub");return(0,o.createElement)(_,{actionText:n,copyDescription:a,handle:e,resourceUrl:r})}function h({selectedComment:e,commentId:t}){const[n,r]=(0,o.useState)(!1),a=(0,c.__)("Remote Reply","activitypub");return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(i.Button,{isLink:!0,className:"comment-reply-link activitypub-remote-reply__button",onClick:()=>r(!0)},(0,c.__)("Reply on the Fediverse","activitypub")),n&&(0,o.createElement)(i.Modal,{className:"activitypub-remote-reply__modal activitypub__modal",onRequestClose:()=>r(!1),title:a},(0,o.createElement)(b,{selectedComment:e,commentId:t})))}let f=1;a()((()=>{[].forEach.call(document.querySelectorAll(".activitypub-remote-reply"),(e=>{const t=JSON.parse(e.dataset.attrs);(0,o.createRoot)(e).render((0,o.createElement)(h,{...t,id:"activitypub-remote-reply-link-"+f++,useId:!0}))}))}))}},n={};function o(e){var r=n[e];if(void 0!==r)return r.exports;var a=n[e]={exports:{}};r