Edit file File name : subscribe.js Content :(()=>{"use strict";const e=window.wp.blocks;function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function a(e){var a=function(e,a){if("object"!=t(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var l=n.call(e,"string");if("object"!=t(l))return l;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(a)?a:a+""}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var a=0,n=new Array(t);a<t;a++)n[a]=e[a];return n}function l(e,t){if(e){if("string"==typeof e)return n(e,t);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?n(e,t):void 0}}function i(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var n,l,i,c,s=[],r=!0,o=!1;try{if(i=(a=a.call(e)).next,0===t){if(Object(a)!==a)return;r=!1}else for(;!(r=(n=i.call(a)).done)&&(s.push(n.value),s.length!==t);r=!0);}catch(e){o=!0,l=e}finally{try{if(!r&&null!=a.return&&(c=a.return(),Object(c)!==c))return}finally{if(o)throw l}}return s}}(e,t)||l(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}const c=window.wp.element,s=window.wp.i18n,r=window.wp.blockEditor,o=window.wp.components;function m(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function u(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?m(Object(n),!0).forEach((function(t){var l,i,c;l=e,i=t,c=n[t],(i=a(i))in l?Object.defineProperty(l,i,{value:c,enumerable:!0,configurable:!0,writable:!0}):l[i]=c})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):m(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var p="notshow",d="optional",b="required",y="summary",N="message",f="redirect",h=function(e,t){var a=i(React.useState([]),2),n=a[0],l=a[1],c=i(React.useState(!1),2),s=c[0],r=c[1],o=i(React.useState(!1),2),m=o[0],u=o[1];return React.useEffect((function(){var a;s||m||(r(!0),jQuery.post(null===(a=ce4wp_form_submit_data)||void 0===a?void 0:a.url,{action:e,nonce:t}).done((function(e){r(!1),u(!0),null!=(null==e?void 0:e.data)&&l(e.data)})))}),[s,m,n]),{data:n,loading:s,hasLoaded:m}};(0,e.registerBlockType)("ce4wp/subscribe",{edit:function(e){var t=this,a=e.attributes,i=e.setAttributes,m=e.className,E=e.clientId;a.blockId||i({blockId:E});var v,g,w,_=function(){var e,t=h("ce4wp_get_all_custom_lists",null===(e=ce4wp_form_submit_data)||void 0===e?void 0:e.listNonce),a=t.data,n=t.loading,l=t.hasLoaded,i=[];return null!=a&&null!=a.length&&(i=a.map((function(e){return{label:e.name,value:e.id}}))),{customLists:i,loading:n,hasLoaded:l}}().customLists,k=[(g=h("ce4wp_creative_email_activated",null===(v=ce4wp_form_submit_data)||void 0===v?void 0:v.activatedNonce)).data,g.loading,g.hasLoaded][0];return(0,c.createElement)("div",{className:"wp-block-ce4wp-subscribe ".concat(m||"")},(0,c.createElement)(r.BlockControls,{key:"setting"},(0,c.createElement)(r.InspectorControls,{key:"setting"},(0,c.createElement)(o.Panel,{header:"Settings"},(0,c.createElement)(o.PanelBody,{title:"Contact Segmentation",initialOpen:!0},(0,c.createElement)(o.PanelRow,{className:"no-flex"},(0,c.createElement)("fieldset",null,(0,c.createElement)("i",{className:"subTitle sub-header"},(0,s.__)("Automatically assign a new contact to a list when they subscribe","ce4wp"),(0,c.createElement)("br",null),(0,c.createElement)(o.ExternalLink,{onClick:function(){return ce4wpNavigateToDashboard(t,"fbcd9606-288a-4d82-be7c-449eaf5a3792",{source:"ce4wp_form_menu"},ce4wpDashboardStartCallback,ce4wpDashboardFinishCallback)}},(0,c.createElement)("span",{id:"ce4wp-manage-lists","data-link_reference":"836b20fc-9ff1-41b2-912b-a8646caf05a4"},(0,s.__)("Manage your lists","ce4wp")))),(0,c.createElement)("br",null),(0,c.createElement)("br",null),(0,c.createElement)(o.SelectControl,{label:"list",value:a.customList,options:[{label:(0,s.__)("Don't assign to a list","cewp4"),value:""}].concat((w=_,function(e){if(Array.isArray(e))return n(e)}(w)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(w)||l(w)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}())),onChange:function(e){return i({customList:e})}})))),(0,c.createElement)(o.PanelBody,{title:"On submission",initialOpen:!0},(0,c.createElement)(o.PanelRow,null,(0,c.createElement)("fieldset",null,(0,c.createElement)(o.SelectControl,{label:"On submission",value:a.onSubmissionSetting,options:[{label:"Show a custom text message",value:N},{label:"Show a summary of submitted fields",value:y},{label:"Redirect",value:f}],onChange:function(e){return i({onSubmissionSetting:e})}}))),a.onSubmissionSetting===N&&(0,c.createElement)(o.PanelRow,null,(0,c.createElement)("fieldset",null,(0,c.createElement)(o.TextareaControl,{label:"Message text",value:a.onSubmission,onChange:function(e){return i({onSubmission:e})}}))),a.onSubmissionSetting===f&&(0,c.createElement)(o.PanelRow,null,(0,c.createElement)("fieldset",null,(0,c.createElement)(o.TextControl,{label:"Redirect link",value:a.redirectLink,onChange:function(e){return i({redirectLink:e})}})))),(0,c.createElement)(o.PanelBody,{title:"Disclaimer settings",initialOpen:!0},(0,c.createElement)(o.PanelRow,{className:"no-flex"},(0,c.createElement)("fieldset",null,(0,c.createElement)(o.SelectControl,{label:"Permission to mail",value:a.emailPermission,options:[{label:"message",value:"message"},{label:"checkbox",value:"checkbox"}],onChange:function(e){return i(u(u({},a),{},{emailPermission:e}))}})))),(0,c.createElement)(o.PanelBody,{title:"Field settings",initialOpen:!0},(0,c.createElement)(o.PanelRow,{className:"no-flex"},(0,c.createElement)("fieldset",null,(0,c.createElement)(o.SelectControl,{label:"First name field",value:a.displayFirstName,options:[{label:"Do not show",value:p},{label:"Optional",value:d},{label:"Required",value:b}],onChange:function(e){return i({displayFirstName:e})}}))),(0,c.createElement)(o.PanelRow,{className:"no-flex"},(0,c.createElement)("fieldset",null,(0,c.createElement)(o.SelectControl,{label:"Last name field",value:a.displayLastName,options:[{label:"Do not show",value:p},{label:"Optional",value:d},{label:"Required",value:b}],onChange:function(e){return i({displayLastName:e})}}))),(0,c.createElement)(o.PanelRow,{className:"no-flex"},(0,c.createElement)("fieldset",null,(0,c.createElement)(o.SelectControl,{label:"Telephone field",value:a.displayTelephone,options:[{label:"Do not show",value:p},{label:"Optional",value:d},{label:"Required",value:b}],onChange:function(e){return i({displayTelephone:e})}}))))))),(0,c.createElement)("form",{name:"contact-form"},(0,c.createElement)(r.RichText,{tagName:"h2",onChange:function(e){i({title:e})},value:a.title}),(0,c.createElement)(r.RichText,{tagName:"p",className:"subTitle",onChange:function(e){i({subTitle:e})},value:a.subTitle}),!1===k&&(0,c.createElement)("div",{className:"ce4wp-inline-notification ce4wp-inline-warning ce4wp-banner-clickable",onClick:function(){return ce4wpNavigateToDashboard(t,"d25f690a-217a-4d68-9c58-8693965d4673",{source:"ce4wp_form_menu"},ce4wpDashboardStartCallback,ce4wpDashboardFinishCallback)}},(0,c.createElement)(o.Dashicon,{className:"ce4wp-inline-warning-icon",icon:"warning"}),(0,c.createElement)("div",{className:"ce4wp-inline-warning-text"},(0,s.__)("Set up Creative Mail before you use this form on your website.")),(0,c.createElement)(o.Dashicon,{className:"ce4wp-inline-warning-arrow",icon:"arrow-right-alt2"})),a.displayFirstName!==p&&(0,c.createElement)("div",{className:"inputBlock"},(0,c.createElement)(r.RichText,{tagName:"label",className:"firstNameLabel",onChange:function(e){i({firstNameLabel:e})},value:a.firstNameLabel}),a.displayFirstName===b&&(0,c.createElement)("p",{className:"required-text subTitle",style:{color:"#ee0000"}},"*"),(0,c.createElement)("input",{name:"first_name",type:"text"})),a.displayLastName!==p&&(0,c.createElement)("div",{className:"inputBlock"},(0,c.createElement)(r.RichText,{tagName:"label",className:"lastNameLabel",onChange:function(e){i({lastNameLabel:e})},value:a.lastNameLabel}),a.displayLastName===b&&(0,c.createElement)("p",{className:"required-text subTitle",style:{color:"#ee0000"}},"*"),(0,c.createElement)("input",{name:"last_name",type:"text"})),a.displayTelephone!==p&&(0,c.createElement)("div",{class:"inputBlock"},(0,c.createElement)(r.RichText,{tagName:"label",className:"lastNameLabel",onChange:function(e){i({telephoneLabel:e})},value:a.telephoneLabel}),a.displayTelephone===b&&(0,c.createElement)("p",{className:"required-text subTitle",style:{color:"#ee0000"}},"*"),(0,c.createElement)("input",{name:"telephone",type:"text"})),(0,c.createElement)("div",{className:"inputBlock"},(0,c.createElement)(r.RichText,{tagName:"label",className:"emailLabel",onChange:function(e){i({emailLabel:e})},value:a.emailLabel}),(0,c.createElement)("p",{className:"required-text subTitle",style:{color:"#ee0000"}},"*"),(0,c.createElement)("input",{className:"textwidget",name:"email",type:"text"})),"message"==a.emailPermission&&(0,c.createElement)("div",{className:"disclaimer"},(0,c.createElement)(r.RichText,{tagName:"label",className:"disclaimer-text",onChange:function(e){i({disclaimer:e})},value:a.disclaimer})),"checkbox"==a.emailPermission&&(0,c.createElement)("div",{className:"disclaimer"},(0,c.createElement)("input",{type:"checkbox",name:"consent_check_".concat(E),id:"consent_check_".concat(E)}),(0,c.createElement)(r.RichText,{htmlFor:"consent_check_".concat(E),tagName:"label",className:"consentLabel disclaimer-label",onChange:function(e){i({consentLabel:e})},value:a.consentLabel})),(0,c.createElement)("button",{className:"wp-block-button__link submit-button",type:"button"},(0,s.__)("Subscribe","cewp4"))))},save:function(e){var t=e.attributes,a=e.className;return(0,c.createElement)("div",{className:"wp-block-ce4wp-subscribe ".concat(a||"")},(0,c.createElement)("div",{className:"onSubmission",style:{display:"none"}},(0,c.createElement)("input",{className:"onSubmissionSetting",name:"onSubmissionSetting",type:"hidden",value:t.onSubmissionSetting}),t.onSubmissionSetting!==N&&(0,c.createElement)("div",null,(0,c.createElement)(r.RichText.Content,{className:"title",tagName:"h2",value:t.title})),t.onSubmissionSetting===N&&(0,c.createElement)("div",null,(0,c.createElement)(r.RichText.Content,{className:"title",tagName:"h2",value:t.title}),(0,c.createElement)("p",{className:"subTitle"},t.onSubmission)),t.onSubmissionSetting===y&&(0,c.createElement)("div",null,(0,c.createElement)("h3",null,"You have subscribed"),(0,c.createElement)("br",null),(t.displayFirstName!==p||t.displayLastName!==p)&&(0,c.createElement)("p",null,(0,c.createElement)("span",null,"Name: "),(0,c.createElement)("span",{className:"firstNameSummary"}),(0,c.createElement)("span",{className:"lastNameSummary"})),t.displayTelephone!==p&&(0,c.createElement)("p",null,(0,c.createElement)("span",null,"Telephone: "),(0,c.createElement)("span",{className:"telephoneSummary"})),(0,c.createElement)("p",null,(0,c.createElement)("span",null,"Email: "),(0,c.createElement)("span",{className:"emailSummary"}))),t.onSubmissionSetting===f&&(0,c.createElement)("input",{className:"redirect",name:"redirect",type:"hidden",value:t.redirectLink})),(0,c.createElement)("form",{className:"cm-contact-form",name:"contact-form"},(0,c.createElement)("input",{className:"list_id",name:"list_id",type:"hidden",value:t.customList}),(0,c.createElement)(r.RichText.Content,{className:"title",tagName:"h2",value:t.title})," ",(0,c.createElement)(r.RichText.Content,{className:"subTitle",tagName:"p",value:t.subTitle}),t.displayFirstName!==p&&(0,c.createElement)("div",{className:"inputBlock"},(0,c.createElement)(r.RichText.Content,{tagName:"label",value:t.firstNameLabel}),t.displayFirstName===b&&(0,c.createElement)("span",{className:"wp-caption-text required-text",style:{color:"#ee0000"}},"*"),(0,c.createElement)("input",{className:"firstName",name:"first_name",type:"text",required:t.displayFirstName===b})),t.displayLastName!==p&&(0,c.createElement)("div",{className:"inputBlock"},(0,c.createElement)(r.RichText.Content,{tagName:"label",value:t.lastNameLabel}),t.displayLastName===b&&(0,c.createElement)("span",{className:"wp-caption-text required-text",style:{color:"#ee0000"}},"*"),(0,c.createElement)("input",{className:"lastName",name:"last_name",type:"text",required:t.displayLastName===b})),t.displayTelephone!==p&&(0,c.createElement)("div",{className:"inputBlock"},(0,c.createElement)(r.RichText.Content,{tagName:"label",value:t.telephoneLabel}),t.displayTelephone===b&&(0,c.createElement)("span",{className:"wp-caption-text required-text",style:{color:"#ee0000"}},"*"),(0,c.createElement)("input",{className:"telephone",name:"telephone",type:"tel",pattern:"[+]?[0-9\\(\\)\\s+-]{5,20}",oninvalid:"setCustomValidity('".concat((0,s.__)("Please enter a valid phone number","creative-mail-by-constant-contact"),"')"),oninput:"setCustomValidity('')",required:t.displayTelephone===b})),(0,c.createElement)("div",{className:"inputBlock"},(0,c.createElement)(r.RichText.Content,{tagName:"label",value:t.emailLabel}),(0,c.createElement)("span",{className:"wp-caption-text required-text",style:{color:"#ee0000"}},"*"),(0,c.createElement)("input",{className:"email",name:"email",type:"email",oninvalid:"setCustomValidity('".concat((0,s.__)("Please enter a valid email address","creative-mail-by-constant-contact"),"')"),oninput:"setCustomValidity('')",required:!0})),"message"==t.emailPermission&&(0,c.createElement)("div",{className:"disclaimer"},(0,c.createElement)("input",{className:"consent_check",name:"consent",type:"hidden",checked:!0}),(0,c.createElement)(r.RichText.Content,{tagName:"label",value:t.disclaimer})),"checkbox"==t.emailPermission&&(0,c.createElement)("div",{className:"disclaimer"},(0,c.createElement)("input",{className:"consent_check",name:"consent_check_".concat(t.blockId),id:"consent_check_".concat(t.blockId),type:"checkbox"}),(0,c.createElement)(r.RichText.Content,{htmlFor:"consent_check_".concat(t.blockId),tagName:"label",value:t.consentLabel,className:"disclaimer-label"})),(0,c.createElement)("button",{className:"wp-block-button__link submit-button",type:"submit"},(0,s.__)("Subscribe","creative-mail-by-constant-contact"))))},supports:{alignWide:!1},keywords:[(0,s.__)("contact","creative-mail-by-constant-contact"),(0,s.__)("form","creative-mail-by-constant-contact"),(0,s.__)("email","creative-mail-by-constant-contact"),(0,s.__)("mail","creative-mail-by-constant-contact")],deprecated:[{attributes:{blockId:{type:"string"},title:{type:"string",default:"Subscribe"},subTitle:{type:"string",default:"Sign up for our newsletter and stay up to date"},firstNameLabel:{type:"string",default:"First name"},lastNameLabel:{type:"string",default:"Last name"},emailLabel:{type:"string",default:"Email"},telephoneLabel:{type:"string",default:"Telephone"},emailPermission:{type:"string",default:"checkbox"},displayTelephone:{type:"string",default:"notshow"},displayFirstName:{type:"string",default:"optional"},displayLastName:{type:"string",default:"optional"},onSubmission:{type:"string",selector:"div",default:"Thank you for subscribing!"},customList:{type:"string",default:null}},save:function(e){var t=e.attributes,a=e.className;return(0,c.createElement)("div",{className:"wp-block-ce4wp-subscribe ".concat(a||"")},(0,c.createElement)("div",{className:"onSubmission",style:{display:"none"}},(0,c.createElement)(r.RichText.Content,{className:"title",tagName:"h2",value:t.title}),(0,c.createElement)("p",{className:"subTitle"},t.onSubmission)),(0,c.createElement)("form",{className:"cm-contact-form",name:"contact-form"},(0,c.createElement)("input",{className:"list_id",name:"list_id",type:"hidden",value:t.customList}),(0,c.createElement)(r.RichText.Content,{className:"title",tagName:"h2",value:t.title})," ",(0,c.createElement)(r.RichText.Content,{className:"subTitle",tagName:"p",value:t.subTitle}),t.displayFirstName!==p&&(0,c.createElement)("div",{className:"inputBlock"},(0,c.createElement)(r.RichText.Content,{tagName:"label",value:t.firstNameLabel}),t.displayFirstName===b&&(0,c.createElement)("span",{className:"wp-caption-text required-text",style:{color:"#ee0000"}},"*"),(0,c.createElement)("input",{className:"firstName",name:"first_name",type:"text",required:t.displayFirstName===b})),t.displayLastName!==p&&(0,c.createElement)("div",{className:"inputBlock"},(0,c.createElement)(r.RichText.Content,{tagName:"label",value:t.lastNameLabel}),t.displayLastName===b&&(0,c.createElement)("span",{className:"wp-caption-text required-text",style:{color:"#ee0000"}},"*"),(0,c.createElement)("input",{className:"lastName",name:"last_name",type:"text",required:t.displayFirstName===b})),t.displayTelephone!==p&&(0,c.createElement)("div",{className:"inputBlock"},(0,c.createElement)(r.RichText.Content,{tagName:"label",value:t.telephoneLabel}),t.displayTelephone===b&&(0,c.createElement)("span",{className:"wp-caption-text required-text",style:{color:"#ee0000"}},"*"),(0,c.createElement)("input",{className:"telephone",name:"telephone",type:"tel",pattern:"[+]?[0-9\\(\\)\\s+-]{5,20}",oninvalid:"setCustomValidity('".concat((0,s.__)("Please enter a valid phone number","creative-mail-by-constant-contact"),"')"),oninput:"setCustomValidity('')",required:t.displayFirstName===b})),(0,c.createElement)("div",{className:"inputBlock"},(0,c.createElement)(r.RichText.Content,{tagName:"label",value:t.emailLabel}),(0,c.createElement)("span",{className:"wp-caption-text required-text",style:{color:"#ee0000"}},"*"),(0,c.createElement)("input",{className:"email",name:"email",type:"email",oninvalid:"setCustomValidity('".concat((0,s.__)("Please enter a valid email address","creative-mail-by-constant-contact"),"')"),oninput:"setCustomValidity('')",required:!0})),"message"==t.emailPermission&&(0,c.createElement)("span",{className:"disclaimer"},(0,c.createElement)("input",{className:"consent_check",name:"consent",type:"hidden",checked:!0}),(0,s.__)("By submitting your information, you are granting us permission to email you. You may unsubscribe at any time.","creative-mail-by-constant-contact")),"checkbox"==t.emailPermission&&(0,c.createElement)("span",null,(0,c.createElement)("input",{className:"consent_check",name:"consent_check_".concat(t.blockId),id:"consent_check_".concat(t.blockId),type:"checkbox"}),(0,c.createElement)("label",{htmlFor:"consent_check_".concat(t.blockId),className:"disclaimer"},(0,s.__)("Can we send you an email from time to time?","creative-mail-by-constant-contact"))),(0,c.createElement)("button",{className:"wp-block-button__link submit-button",type:"submit"},(0,s.__)("Subscribe","creative-mail-by-constant-contact"))))}}]})})(); Save