| 1 |
(()=>{"use strict";const e=window.wp.hooks,t=window.wp.compose,o=window.wp.i18n,n=window.wp.blockEditor,s=window.wp.components,l=window.React,r=window.wp.htmlEntities,i=window.ReactJSXRuntime;function a(e){const{name:t,attributes:n,setAttributes:a}=e;if(!("wppbContentRestriction"in n))return null;const{wppbContentRestriction:p}=n,_=JSON.parse(wppbBlockEditorData.userRoles);if(!JSON.parse(wppbBlockEditorData.content_restriction_activated))return null;let c=!1;["wppb/content-restriction-start","wppb/content-restriction-end"].includes(t)&&(c=!0);let d=function(e,t){let n="",s=!1;switch(e.display_to){case"all":n=(0,o.__)("This content is not restricted and can be seen by all users.","profile-builder");break;case"":n=(0,o.__)("This content is restricted and can only be seen by logged in users","profile-builder"),e.user_roles&&0!==e.user_roles.length&&(s=!0,n+=(0,o.__)(" that have the following user roles: ","profile-builder"),e.user_roles.map(e=>{t.map(t=>{t.slug===e&&(n+=t.name+", ")})}),n=n.slice(0,-2)),e.users_ids&&0!==e.users_ids.length&&(s&&(n+=(0,o.__)(" and","profile-builder")),n+=(0,o.__)(" that have the following user IDs: ","profile-builder"),n+=e.users_ids),n+=".";break;case"not_logged_in":n=(0,o.__)("This content is restricted and can only be seen by logged out users.","profile-builder");break;default:n=(0,o.__)("Please select an option.","profile-builder")}return n}(p,_);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("p",{children:d}),(0,i.jsx)("br",{}),(0,i.jsxs)(s.__experimentalToggleGroupControl,{isBlock:!0,label:(0,o.__)("Show content to","profile-builder"),value:p.display_to,onChange:e=>a({wppbContentRestriction:{...p,display_to:e}}),children:[!c&&(0,i.jsx)(s.__experimentalToggleGroupControlOption,{label:(0,o.__)("All Users","profile-builder"),value:"all"}),(0,i.jsx)(s.__experimentalToggleGroupControlOption,{label:(0,o.__)("Logged In Users","profile-builder"),value:""}),(0,i.jsx)(s.__experimentalToggleGroupControlOption,{label:(0,o.__)("Logged Out Users","profile-builder"),value:"not_logged_in"})]}),"all"==p.display_to&&(0,i.jsx)("p",{}),""==p.display_to&&(0,i.jsxs)("div",{children:[(0,i.jsx)(s.BaseControl,{label:(0,o.__)("User Roles","profile-builder"),help:(0,o.__)("The desired valid user roles. Select none for all roles to be valid.","profile-builder"),children:(0,i.jsxs)("div",{style:{maxHeight:"380px",overflowY:"auto",border:"1px solid #8c8f94",padding:"8px 12px",borderRadius:"2px",marginBottom:"16px",backgroundColor:"#fff"},children:[(0,i.jsx)("style",{children:"\n .wppb-user-role-checkbox {\n margin-bottom: 4px !important;\n }\n .wppb-user-role-checkbox:last-child {\n margin-bottom: 0 !important;\n }\n .wppb-user-role-checkbox .components-checkbox-control__label {\n font-size: 13px !important;\n line-height: 1.4 !important;\n }\n .wppb-user-role-checkbox .components-checkbox-control__input-container {\n margin-right: 8px !important;\n }\n "}),_?.map(e=>{const t=!!p.user_roles&&p.user_roles.includes(e.slug);return(0,i.jsx)(s.CheckboxControl,{label:(0,r.decodeEntities)(e.name),checked:t,className:"wppb-user-role-checkbox",onChange:t=>{const o=p.user_roles?[...p.user_roles]:[];let n;n=t?[...o,e.slug]:o.filter(t=>t!==e.slug),a({wppbContentRestriction:{...p,user_roles:n}})}},e.slug)})]})}),(0,i.jsx)(s.BaseControl,{label:(0,o.__)("User IDs","profile-builder"),children:(0,i.jsx)(s.__experimentalInputControl,{help:(0,o.__)("A comma-separated list of user IDs.","profile-builder"),value:p.users_ids,onChange:e=>a({wppbContentRestriction:{...p,users_ids:e}}),className:"components-input-control__input"})}),(0,i.jsxs)(l.Fragment,{children:[(0,i.jsx)(s.ToggleControl,{label:(0,o.__)("Enable Custom Message","profile-builder"),checked:!!p.enable_message_logged_in&&p.enable_message_logged_in,onChange:()=>a({wppbContentRestriction:{...p,enable_message_logged_in:!p.enable_message_logged_in}})}),p.enable_message_logged_in&&(0,i.jsx)(s.TextareaControl,{help:(0,o.__)("Custom message for logged-in users.","profile-builder"),value:p.message_logged_in,onChange:e=>a({wppbContentRestriction:{...p,message_logged_in:e}})})]})]}),"not_logged_in"==p.display_to&&(0,i.jsxs)(l.Fragment,{children:[(0,i.jsx)(s.ToggleControl,{label:(0,o.__)("Enable Custom Message","profile-builder"),checked:!!p.enable_message_logged_out&&p.enable_message_logged_out,onChange:()=>a({wppbContentRestriction:{...p,enable_message_logged_out:!p.enable_message_logged_out}})}),p.enable_message_logged_out&&(0,i.jsx)(s.TextareaControl,{help:(0,o.__)("Custom message for logged-out users","profile-builder"),value:p.message_logged_out,onChange:e=>a({wppbContentRestriction:{...p,message_logged_out:e}})})]})]})}function p(e){const{name:t,attributes:l,setAttributes:r}=e,{wppbContentRestriction:p}=l;return JSON.parse(wppbBlockEditorData.content_restriction_activated)&&"wppbContentRestriction"in l&&!["wppb/content-restriction-start","wppb/content-restriction-end","wppb/content-restriction-start","wppb/content-restriction-start"].includes(t)?(0,i.jsx)(n.InspectorControls,{children:(0,i.jsx)(s.PanelBody,{title:(0,o.__)("Profile Builder Content Restriction","profile-builder"),className:"profile-builder-content-restriction-settings",initialOpen:p.panel_open,onToggle:e=>r({wppbContentRestriction:{...p,panel_open:!p.panel_open}}),children:(0,i.jsx)(a,{...e})})}):null}(0,e.addFilter)("blocks.registerBlockType","profile-builder/attributes",function(e){let t={wppbContentRestriction:{type:"object",properties:{user_roles:{type:"array"},users_ids:{type:"string"},display_to:{type:"string"},enable_message_logged_in:{type:"boolean"},enable_message_logged_out:{type:"boolean"},message_logged_in:{type:"string"},message_logged_out:{type:"string"},panel_open:{type:"boolean"}},default:{user_roles:[],users_ids:"",display_to:"all",enable_message_logged_in:!1,enable_message_logged_out:!1,message_logged_in:"",message_logged_out:"",panel_open:!1}}};return e.attributes.wppb_content_restriction_block_start&&(t.wppbContentRestriction.default.display_to=""),e.attributes.wppb_content_restriction_block_end||e.attributes.pms_content_restriction_block_start||e.attributes.pms_content_restriction_block_end||(e.attributes={...e.attributes,...t}),e});const _=(0,t.createHigherOrderComponent)(e=>t=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(e,{...t}),(0,i.jsx)(p,{...t})]}),"blockWPPBContentRestrictionControls");(0,e.addFilter)("editor.BlockEdit","profile-builder/inspector-controls",_,100)})(); |