1 line
3.4 KiB
JavaScript
1 line
3.4 KiB
JavaScript
!function(){"use strict";var e=window.wp.plugins,t=window.wp.element,s=window.wp.editPost,o=window.wp.components,n=window.wp.i18n,i=window.wp.data,p=window.wp.editor;function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var o in s)Object.prototype.hasOwnProperty.call(s,o)&&(e[o]=s[o])}return e},r.apply(this,arguments)}var a=window.wp.url,l=window.wp.compose,c={META_ENABLED:"_sppp_enabled",META_KEY:"_sppp_key",QUERY_PARAM:"_sppp_key"};const{META_KEY:d,QUERY_PARAM:w}=c,m=e=>{let{text:s,onCopy:n,children:i,...p}=e;const a=(0,l.useCopyToClipboard)(s,n);return(0,t.createElement)(o.Button,r({variant:"secondary",ref:a},p),i)};class u extends t.Component{constructor(){super(...arguments),this.state={showCopyConfirmation:!1},this.onCopy=this.onCopy.bind(this),this.onSelectInput=this.onSelectInput.bind(this)}componentWillUnmount(){clearTimeout(this.dismissCopyConfirmation)}onCopy(){this.setState({showCopyConfirmation:!0}),clearTimeout(this.dismissCopyConfirmation),this.dismissCopyConfirmation=setTimeout((()=>{this.setState({showCopyConfirmation:!1})}),4e3)}onSelectInput(e){e.target.select()}render(){const e=(0,a.addQueryArgs)(this.props.postLink,{[w]:this.props.secretKey});return(0,t.createElement)("div",null,(0,t.createElement)("label",{htmlFor:"sppp-link-field",className:"screen-reader-text"},(0,n.__)("Share this URL","sharable-password-protected-posts")),(0,t.createElement)(o.Flex,{className:"sppp__link-copy"},(0,t.createElement)(o.TextControl,{id:"sppp-link-field",className:"sppp__link-field",readOnly:!0,label:(0,n.__)("Secret URL:","sharable-password-protected-posts"),value:(0,a.safeDecodeURIComponent)(e),onFocus:this.onSelectInput}),(0,t.createElement)(m,{text:e,onCopy:this.onCopy,className:"sppp__copy-button"},this.state.showCopyConfirmation?(0,n.__)("Copied!","sharable-password-protected-posts"):(0,n.__)("Copy","sharable-password-protected-posts"))))}}var h=(0,i.withSelect)((e=>{const{getEditedPostAttribute:t,getPermalink:s}=e(p.store);return{postLink:s(),secretKey:t("meta")[d]}}))(u),y=window.wp.coreData,_=e=>{let{children:t}=e;const{isPostTypeVisible:s,postType:o,isPostPrivate:n}=(0,i.useSelect)((e=>{let t=!1;const s=e(p.store).getCurrentPostType(),o=e(y.store).getPostType(s),n=e(p.store).getEditedPostAttribute("link"),i=e(p.store).getEditedPostVisibility();return null!=o&&o.viewable&&(t=!0),n&&(t=!0),e(p.store).getPermalinkParts()&&(t=!0),{isPostTypeVisible:t,postType:s,isPostPrivate:"private"===i||"password"===i}}),[]),r=window.sppp&&window.sppp.settings.postTypes.includes(o);return window.sppp&&window.sppp.settings.hasPermissions&&s&&r&&n?t:null};const{META_ENABLED:E,META_KEY:C}=c;(0,e.registerPlugin)("sharable-password-protected-posts",{render:()=>{const{sharingEnabled:e,existingKey:r}=(0,i.useSelect)((e=>{const{getEditedPostAttribute:t}=e(p.store),s=t("meta");return{sharingEnabled:s[E],existingKey:s[C]}})),{editPost:a}=(0,i.useDispatch)(p.store);return(0,t.createElement)(s.PluginPostStatusInfo,{className:"sppp"},(0,t.createElement)(_,null,(0,t.createElement)("div",{className:"sppp__checkbox"},(0,t.createElement)(o.CheckboxControl,{label:(0,n.__)("Share post via secret URL","sharable-password-protected-posts"),checked:e,onChange:e=>{a(e?{meta:{[E]:!0,[C]:r||window.sppp.newKey||""}}:{meta:{[E]:!1,[C]:""}})}})),e&&(0,t.createElement)("div",{className:"sppp__link"},(0,t.createElement)(h,null))))}})}(); |