← Back
Editing: cta-editor.js
(()=>{"use strict";const e={n:t=>{const r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{if(Array.isArray(r))for(var o=0;o<r.length;){var i=r[o++],s=r[o++];e.o(t,i)?0===s&&o++:0===s?Object.defineProperty(t,i,{enumerable:!0,value:r[o++]}):Object.defineProperty(t,i,{enumerable:!0,get:s})}else for(var i in r)e.o(r,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:r[i]})},o:(e,t)=>Object.hasOwn(e,t),r:e=>{Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}};let t={};e.r(t),e.d(t,{BaseEditor:()=>ce,DEBUG_MODE:()=>xe,Editor:()=>be,EditorHeaderActionsRegistry:()=>d,EditorHeaderOptionsRegistry:()=>g,getEditorHeaderActions:()=>m,getEditorHeaderOptions:()=>x,registerEditorHeaderAction:()=>p,registerEditorHeaderActionGroup:()=>h,registerEditorHeaderOption:()=>f,registerEditorHeaderOptionGroup:()=>b,useAllFieldErrors:()=>Z,useEditor:()=>X,useEditorHeaderActions:()=>u,useEditorHeaderOptions:()=>v,useFieldError:()=>L,useFields:()=>z,useTabErrors:()=>U,useTabHasError:()=>q,withDataStore:()=>ge,withModal:()=>ve,withQueryParams:()=>fe});var r={};e.r(r),e.d(r,{historyEditorHeaderAction:()=>S,statusEditorHeaderAction:()=>y});var o={};e.r(o),e.d(o,{deleteBulkAction:()=>B});var i={};e.r(i),e.d(i,{Component:()=>ie,default:()=>se,getCallToActionTypeOptions:()=>oe,name:()=>te,title:()=>re});var s={};e.r(s),e.d(s,{generalTab:()=>i});const a=window.wp.domReady;var n=e.n(a);const l=window.wp.hooks,c=window.popupMaker.registry,d=(0,c.createRegistry)({name:"cta-editor/editor-header-actions",groups:{general:{priority:10}},defaultGroup:"general"}),u=()=>d.useItems(),p=d.register,h=d.registerGroup,m=()=>d.getItems(),g=(0,c.createRegistry)({name:"cta-editor/editor-header-options",groups:{general:{priority:10}}}),v=()=>g.useItems(),f=g.register,b=g.registerGroup,x=()=>g.getItems(),E=window.popupMaker.i18n,w=window.popupMaker.coreData,C=window.wp.components,T=window.wp.data,j=window.ReactJSXRuntime,S={id:"history",priority:99,render:({values:e})=>{const t=(0,T.useSelect)(e=>e(w.callToActionStore).isResolving("updateCallToAction"),[]),{hasUndo:r,hasRedo:o,hasEdits:i}=(0,T.useSelect)(t=>{if("number"!=typeof e.id)return{hasUndo:!1,hasRedo:!1,hasEdits:!1};const r=t(w.callToActionStore);return{hasUndo:r.hasUndo(e.id),hasRedo:r.hasRedo(e.id),hasEdits:r.hasEdits(e.id)}},[e,t]),{undo:s,redo:a}=(0,T.useDispatch)(w.callToActionStore);return(0,j.jsx)(j.Fragment,{children:i&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(C.Button,{disabled:t||!r,variant:"tertiary",icon:"undo","aria-label":(0,E.__)("Undo","popup-maker"),onClick:()=>s(e.id)}),(0,j.jsx)(C.Button,{disabled:t||!o,variant:"tertiary",icon:"redo","aria-label":(0,E.__)("Redo","popup-maker"),onClick:()=>a(e.id)})]})})}};function _(e){var t,r,o="";if("string"==typeof e||"number"==typeof e)o+=e;else if("object"==typeof e)if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(r=_(e[t]))&&(o&&(o+=" "),o+=r)}else for(r in e)e[r]&&(o&&(o+=" "),o+=r);return o}const k=function(){for(var e,t,r=0,o="",i=arguments.length;r<i;r++)(e=arguments[r])&&(t=_(e))&&(o&&(o+=" "),o+=t);return o},y={id:"status",priority:100,render:({values:e})=>{const t=(0,T.useSelect)(e=>e(w.callToActionStore).isResolving("updateCallToAction"),[]),{updateEditorValues:r}=(0,T.useDispatch)(w.callToActionStore);return(0,j.jsx)("div",{className:k(["call-to-action-enabled-toggle","publish"===e?.status?"enabled":"disabled"]),style:{minWidth:"11.5ch"},children:(0,j.jsx)(C.ToggleControl,{disabled:t,label:"publish"===e?.status?(0,E.__)("Enabled","popup-maker"):(0,E.__)("Disabled","popup-maker"),checked:"publish"===e?.status,onChange:t=>r({id:e.id,status:t?"publish":"draft"}),__nextHasNoMarginBottom:!0})})}},A=window.popupMaker.components,N=window.wp.element;(0,N.forwardRef)(({icon:e,size:t=24,...r},o)=>(0,N.cloneElement)(e,{width:t,height:t,...r,ref:o}));const O=window.wp.primitives;var M=(0,j.jsx)(O.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,j.jsx)(O.Path,{d:"M12 4c-4.4 0-8 3.6-8 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8Zm3.8 10.7-1.1 1.1-2.7-2.7-2.7 2.7-1.1-1.1 2.7-2.7-2.7-2.7 1.1-1.1 2.7 2.7 2.7-2.7 1.1 1.1-2.7 2.7 2.7 2.7Z"})}),R=(0,j.jsx)(O.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,j.jsx)(O.Path,{d:"m13.06 12 6.47-6.47-1.06-1.06L12 10.94 5.53 4.47 4.47 5.53 10.94 12l-6.47 6.47 1.06 1.06L12 13.06l6.47 6.47 1.06-1.06L13.06 12Z"})}),F=(0,j.jsx)(O.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,j.jsx)(O.Path,{d:"M10 17.389H8.444A5.194 5.194 0 1 1 8.444 7H10v1.5H8.444a3.694 3.694 0 0 0 0 7.389H10v1.5ZM14 7h1.556a5.194 5.194 0 0 1 0 10.39H14v-1.5h1.556a3.694 3.694 0 0 0 0-7.39H14V7Zm-4.5 6h5v-1.5h-5V13Z"})}),D=(0,j.jsx)(O.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,j.jsx)(O.Path,{d:"M11 13h2v-2h-2v2zm-6 0h2v-2H5v2zm12-2v2h2v-2h-2z"})}),I=(0,j.jsx)(O.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,j.jsx)(O.Path,{d:"M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z"})});const B={id:"delete",group:"trash",priority:6,render:({values:e,closeModal:t})=>{const[r,o]=(0,N.useState)(!1),i=(0,N.useRef)(r),[s,a]=(0,N.useState)();(0,N.useEffect)(()=>{i.current=r},[r]);const{deleteCallToAction:n,resetRecordEdits:l}=(0,T.useDispatch)(w.callToActionStore),c=(0,N.useCallback)(()=>{e.id>0?n(e.id,i.current):l(e.id),t()},[n,l,e.id,t]);return(0,j.jsxs)(j.Fragment,{children:[s&&(0,j.jsxs)(A.ConfirmDialogue,{...s,onClose:()=>{a(void 0)},children:[(0,j.jsx)("p",{children:(0,E.__)("Are you sure you want to delete this call to action?","popup-maker")}),(0,j.jsx)(C.ToggleControl,{label:(0,E.__)("Permanently delete all associated content","popup-maker"),checked:r,onChange:o})]}),(0,j.jsx)(C.Button,{text:(0,E.__)("Delete","popup-maker"),icon:M,isDestructive:!0,onClick:()=>{a({isDestructive:!0,callback:c})}})]})}},P=window.popupMaker.utils,H=window.wp.url,V=window.popupMaker.useQueryParams;let $=!1;const X=()=>{const{isEditorActive:e,editorId:t}=(0,T.useSelect)(e=>{const t=e(w.callToActionStore);return{editorId:t.getEditorId(),isEditorActive:t.isEditorActive()}},[]),{changeEditorId:r}=(0,T.useDispatch)(w.callToActionStore),[o,i]=(0,V.useQueryParams)({edit:V.NumberParam,add:V.BooleanParam,tab:V.StringParam}),{edit:s,add:a,tab:n}=o;return(0,N.useEffect)(()=>{if($)return;let e;$=!0,s&&s>0?e=s:a&&(e="new"),e&&!t&&r(e)},[]),{tab:null===n?void 0:n,setTab:e=>i({tab:e}),setEditorId:(0,N.useCallback)(e=>{r(e),i({edit:"number"==typeof e?e:void 0,add:"new"===e||void 0})},[r,i]),clearEditorParams:()=>{r(void 0),i({add:void 0,edit:void 0,tab:void 0})},editorId:t,isEditorActive:e}},z=()=>{const{updateEditorValues:e}=(0,T.useDispatch)(w.callToActionStore),{values:t}=(0,T.useSelect)(e=>{const t=e(w.callToActionStore);return{values:t.getCurrentEditorValues(),isEditorActive:t.isEditorActive()}},[]),r=(0,N.useMemo)(()=>t??w.defaultCtaValues,[t]),{settings:o}=r,i=(0,N.useCallback)(t=>{e({...r,settings:{...r.settings,...t}})},[e,r]),s=(e,t)=>{const r=(0,l.applyFilters)("popupMaker.callToActionEditor.fieldIsVisible",void 0,e,o,t);return void 0===r||r},a=(0,N.useMemo)(()=>(0,l.applyFilters)("popupMaker.callToActionEditor.tabFields",{},o,i),[o,i]);return{values:t,fieldIsVisible:s,getTabFields:e=>(0,l.applyFilters)(`popupMaker.callToActionEditor.tabFields.${e}`,a[e]??[],o,i).sort((e,t)=>e.priority-t.priority).filter(t=>s(t.id,e)).map(t=>{const r=(0,l.applyFilters)("popupMaker.callToActionEditor.renderField",t.component,t.id,e);return{...t,component:r}}),updateSettings:i,updateField:(e,t)=>{i({[e]:t})}}},G=window.wp.notices,L=e=>{const t=(0,T.useSelect)(e=>e(w.callToActionStore).getEditorId(),[]),{removeNotice:r}=(0,T.useDispatch)(G.store);return{error:(0,T.useSelect)(r=>{const o=r(G.store).getNotices(w.NOTICE_CONTEXT).find(r=>r.id===`field-error-${t||"new"}-${e}`);return o?.content||null},[t,e]),clearError:(0,N.useCallback)(()=>{void 0!==t&&r(`field-error-${t||"new"}-${e}`,w.NOTICE_CONTEXT)},[t,e,r])}},U=e=>{const t=(0,T.useSelect)(e=>e(w.callToActionStore).getEditorId(),[]),{removeNotice:r}=(0,T.useDispatch)(G.store),{getTabFields:o}=z(),i=(0,T.useSelect)(r=>{const i=r(G.store).getNotices(w.NOTICE_CONTEXT),s=o(e),a=new Set(s.map(e=>e.id));return i.filter(e=>{if(!e.id?.startsWith(`field-error-${t||"new"}-`))return!1;const r=e.id.match(/field-error-(?:\d+|new)-(.+)$/),o=r?.[1];return o&&a.has(o)})},[t,e]),s=i.length>0,a=i.length,n=i.map(e=>e.id);return{hasErrors:s,errorCount:a,clearTabErrors:(0,N.useCallback)(()=>{n.forEach(e=>r(e,w.NOTICE_CONTEXT))},[n,r])}},q=e=>{const{hasErrors:t}=U(e);return t},Z=()=>{const e=(0,T.useSelect)(e=>e(w.callToActionStore).getEditorId(),[]),{removeNotice:t}=(0,T.useDispatch)(G.store),r=(0,T.useSelect)(t=>{const r=t(G.store).getNotices(w.NOTICE_CONTEXT),o={};return r.forEach(t=>{const r=t.id?.match(new RegExp(`^field-error-${e||"new"}-(.+)$`));r&&(o[r[1]]=t.content)}),o},[e]),o=(0,T.useSelect)(t=>{const r=t(G.store).getNotices(w.NOTICE_CONTEXT),o=[];return r.forEach(t=>{const r=t.id?.match(new RegExp(`^field-error-${e||"new"}-(.+)$`));r&&o.push(t.id)}),o},[e]),i=(0,N.useCallback)(()=>{o.forEach(e=>t(e,w.NOTICE_CONTEXT))},[o,t]),s=(0,N.useCallback)(r=>{void 0!==e&&t(`field-error-${e||"new"}-${r}`,w.NOTICE_CONTEXT)},[e,t]);return{errors:r,hasAnyError:Object.keys(r).length>0,clearAllErrors:i,clearFieldError:s}},Q=window.React,W=({fieldId:e,title:t,error:r,className:o,children:i})=>{const s=null!=r&&""!==r;return(0,j.jsx)(C.Panel,{header:t,className:k("components-field-panel","cta-field-wrapper",`cta-field-wrapper--${e}`,{"cta-field-wrapper--has-error":s},o),children:(0,j.jsxs)(C.PanelBody,{opened:!0,children:[i,s&&(0,j.jsx)("div",{className:"cta-field-error",children:r})]})})},J=()=>{const e=(0,T.useSelect)(e=>e(G.store).getNotices(w.NOTICE_CONTEXT),[]);return xe?0===e.length?(0,j.jsx)("div",{style:{padding:"10px",background:"#f0f0f0",margin:"10px 0",fontSize:"12px",fontFamily:"monospace"},children:(0,j.jsx)("strong",{children:`Debug: No notices found in context "${w.NOTICE_CONTEXT}"`})}):(0,j.jsxs)("div",{style:{padding:"10px",background:"#ffeeee",margin:"10px 0",fontSize:"12px",fontFamily:"monospace",border:"1px solid #cc1818"},children:[(0,j.jsx)("strong",{children:`Debug: Notices in context "${w.NOTICE_CONTEXT}":`}),(0,j.jsx)("ul",{style:{margin:"5px 0 0 20px",padding:0},children:e.map(e=>(0,j.jsxs)("li",{style:{marginBottom:"3px"},children:[(0,j.jsx)("strong",{children:e.id}),": ",e.content," ","(status: ",e.status,")"]},e.id))})]}):null},K=window.popupMaker.fields,Y=({fieldId:e,field:t,value:r,onChange:o})=>{const{error:i,clearError:s}=L(e),a=e=>{i&&s(),o(e)};return(0,j.jsx)(W,{fieldId:e,title:t.label??"",error:i,children:"url"===t.type?(0,j.jsx)(A.URLControl,{...t,value:r,onChange:e=>a(e.url)}):(0,j.jsx)(K.Field,{...t,value:r,onChange:a})})},ee=({tabName:e,message:t=(0,E.__)("Please fix the errors below.","popup-maker")})=>{const{hasErrors:r}=U(e),[o,i]=(0,Q.useState)(!1),s=(0,Q.useRef)(null),a=(0,Q.useRef)(!1),n=(0,Q.useRef)(!1),l=(0,T.useSelect)(e=>e(w.callToActionStore).isResolving("updateCallToAction"),[]);return(0,Q.useEffect)(()=>{s.current&&(clearTimeout(s.current),s.current=null);const e=r&&!a.current,t=n.current&&!l;return r&&(e||t)?(i(!0),xe||(s.current=setTimeout(()=>{i(!1)},3e3))):r||i(!1),a.current=r,n.current=l,()=>{s.current&&clearTimeout(s.current)}},[r,l]),o?(0,j.jsx)(C.Notice,{status:"error",isDismissible:!1,children:t}):null},te="general",re=(0,E.__)("General","popup-maker"),oe=()=>{const{cta_types:e={}}=window.popupMakerCtaEditor||{},t=Object.values(e).map(e=>({value:e.key,label:e.label}));return(0,l.applyFilters)("popupMaker.callToActionEditor.typeOptions",[{value:"",label:(0,E.__)("Select a type","popup-maker")},...t])},ie=({callToAction:e,updateFields:t,updateSettings:r})=>{const{getTabFields:o}=z(),{clearAllErrors:i}=Z(),{settings:s}=e,[a,n]=(0,N.useState)(null),l=(e.excerpt??"").length/80,c=(0,P.clamp)(l,1,5),{cta_types:d={}}=window.popupMakerCtaEditor||{},u=oe();return(0,j.jsxs)("div",{className:"general-tab",children:[(0,j.jsx)(ee,{tabName:"general"}),(0,j.jsx)(C.TextControl,{label:(0,E.__)("Name","popup-maker"),placeholder:(0,E.__)("Name…","popup-maker"),className:"title-field",value:e.title??"",onChange:e=>t({title:e,slug:(0,H.cleanForSlug)(e)}),__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0}),(e.title??"").length<=0&&(0,j.jsx)(C.Notice,{status:"warning",isDismissible:!1,className:"title-field-notice",children:(0,E.__)("Enter a name for this call to action.","popup-maker")}),(0,j.jsx)(C.TextareaControl,{rows:c,scrolling:c>5?"auto":"no",label:(0,E.__)("Description","popup-maker"),placeholder:(0,E.__)("Add description…","popup-maker"),className:"description-field",value:e.excerpt??"",onChange:e=>t({excerpt:e}),__nextHasNoMarginBottom:!0}),o("general").filter(e=>e.priority<3).map(e=>(0,j.jsx)(N.Fragment,{children:e.component},e.id)),u.length>1&&(0,j.jsx)(C.SelectControl,{label:(0,E.__)("Action Type","popup-maker"),options:u,value:s.type??"",onChange:e=>{const t=d[e];if(t?.pro_required)return n(e),i(),void r({type:"link"});n(null),i(),r({type:e})},__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0}),a&&d?.[a]&&(0,j.jsxs)(C.Notice,{status:"warning",isDismissible:!0,onDismiss:()=>n(null),className:"pro-cta-type-notice",children:[(0,j.jsx)("strong",{children:d[a]?.label})," — ",d[a]?.pro_description||"This action type requires Popup Maker Pro."," ",(0,j.jsxs)("a",{href:d[a]?.upgrade_url||"#",target:"_blank",rel:"noopener noreferrer",children:[d[a]?.pro_cta||"Upgrade Now"," →"]})]}),o("general").filter(e=>e.priority>=3).map(e=>(0,j.jsx)(N.Fragment,{children:e.component},e.id))]})},se=ie,{cta_types:ae}=window.popupMakerCtaEditor,ne=()=>{(0,l.addFilter)("popupMaker.callToActionEditor.tabFields","popup-maker",(e,t,r)=>{const o=(i=t.type,Object.values(ae).find(e=>e.key===i)?.fields??{});var i;return 0===Object.keys(o).length?e:Object.entries(o).reduce((e,[o,i])=>(e[o]||(e[o]=[]),e[o]=[...e[o],...Object.entries(i).map(([e,o])=>o&&o.type?{...o,id:e,priority:o?.priority??0,component:(0,j.jsx)(N.Fragment,{children:!(()=>{if(!o.dependencies)return!1;const e=o.dependencies;return!Object.entries(e).every(([e,r])=>{const o=t[e];return"string"==typeof r?void 0===o?""===r:r===o:"boolean"==typeof r?void 0===o?!1===r:r===o:"number"==typeof r&&(void 0===o?0===r:r===o)})})()&&(0,j.jsx)(Y,{fieldId:e,field:o,value:t[e],onChange:t=>r({[e]:t})})},e)}:null).filter(e=>null!==e)],e),{...e})})};let le=!1;const ce=({afterTabs:e,beforeTabs:t,className:r,...o})=>{const[i,s]=(0,A.useControlledState)(o.tab,"general",o.setTab),[a,n]=(0,A.useControlledState)(o.values,w.defaultCtaValues,o.onChange??P.noop),c=(0,N.useMemo)(()=>({callToAction:a,onChange:n,updateFields:e=>{n({...a,...e})},updateSettings:e=>{n({...a,settings:{...a.settings,...e}})},updateSetting:(e,t)=>{n({...a,settings:{...a.settings,[e]:t}})}}),[a,n]),{tabsFilter:d}=o,u=(0,N.useMemo)(()=>{const e=(0,l.applyFilters)("popupMaker.callToActionEditor.tabs",[]);return d?d(e):e},[d]),p=u.length>1;return(0,j.jsxs)("div",{className:k("call-to-action-editor",r),children:[t&&(0,j.jsx)("div",{className:"editor-tabs-before",children:t}),(0,j.jsx)("div",{className:"editor-tabs-container",children:p?(0,j.jsx)(C.TabPanel,{orientation:"vertical",initialTabName:i??"general",onSelect:s,tabs:u,className:"editor-tabs",children:({Component:e})=>(0,j.jsx)(e,{...c})}):(0,j.jsx)("div",{className:"editor-tab-content",children:(()=>{const e=(()=>{if(0===u.length)return null;const e=u.find(e=>e.name===i)||u[0];return e?.Component})();return e?(0,j.jsx)(e,{...c}):(0,j.jsx)("div",{className:"no-content-available",children:"No content available"})})()})}),e&&(0,j.jsx)("div",{className:"editor-tabs-after",children:e})]})},de=({values:e,closeModal:t})=>{const r=(0,N.useRef)(void 0),o=u(),i={values:e,closeModal:t},s=({group:e})=>{if(!e||e===r.current)return null;const t=r.current;return r.current=e,t?(0,j.jsx)("span",{children:"|"}):null};return(0,j.jsx)(j.Fragment,{children:(r.current=void 0,(0,j.jsx)(j.Fragment,{children:o.map(({id:e,group:t,render:r})=>(0,j.jsxs)(N.Fragment,{children:[(0,j.jsx)(s,{group:t}),(0,j.jsx)(r,{...i})]},e))}))})},ue=window.lodash,pe=({values:e,closeModal:t})=>{const r=(0,N.useRef)(void 0),o=(0,N.useRef)(),i=(0,N.useRef)(null),[s,a]=(0,N.useState)(!1),n=(0,ue.debounce)(()=>{a(!s)},100),l=v(),c={values:e,closeModal:t},d=({group:e})=>{if(!e||e===r.current)return null;const t=r.current;return r.current=e,t?(0,j.jsx)("hr",{}):null};return(0,j.jsx)(j.Fragment,{children:(0,j.jsx)(C.Dropdown,{className:"editor-header-options",contentClassName:"editor-header-options__popover",focusOnMount:"firstElement",open:s,popoverProps:{noArrow:!1,placement:"bottom",anchor:{getBoundingClientRect:()=>o.current?.getBoundingClientRect()||new DOMRect},onClose:()=>{n()},onFocusOutside:()=>{n(),i.current=setTimeout(()=>{clearTimeout(i.current??void 0),i.current=null},300)}},renderToggle:()=>(0,j.jsx)(C.Button,{className:"popover-toggle",ref:e=>{o.current=e},"aria-label":(0,E.__)("Options","popup-maker"),variant:"link",onClick:()=>{s||i.current||a(!0)},icon:s?I:D,iconSize:20}),renderContent:()=>(r.current=void 0,(0,j.jsx)(C.NavigableMenu,{orientation:"vertical",children:l.map(({id:e,group:t,render:r})=>(0,j.jsxs)(N.Fragment,{children:[(0,j.jsx)(d,{group:t}),(0,j.jsx)(r,{...c})]},e))}))})})},he=window.popupMaker.skeleton,me=()=>{const e=(0,l.applyFilters)("popupMaker.callToActionEditor.tabs",[]).length>1,t=(0,j.jsxs)("div",{className:"editor-tabs__content-skeleton",children:[(0,j.jsxs)("div",{className:"editor-tabs__field-skeleton",children:[(0,j.jsx)(he.SkeletonBar,{width:"15%",height:13}),(0,j.jsx)(he.SkeletonBar,{width:"100%",height:48})]}),(0,j.jsxs)("div",{className:"editor-tabs__field-skeleton",children:[(0,j.jsx)(he.SkeletonBar,{width:"20%",height:13}),(0,j.jsx)(he.SkeletonBar,{width:"100%",height:36})]}),[1,2,3].map(e=>(0,j.jsxs)("div",{className:"editor-tabs__field-skeleton",children:[(0,j.jsx)(he.SkeletonBar,{width:"30%",height:13}),(0,j.jsx)(he.SkeletonBar,{width:"100%",height:36})]},e))]});return(0,j.jsx)("div",{className:"call-to-action-editor call-to-action-editor--loading","aria-busy":"true","aria-label":(0,E.__)("Loading call to action…","popup-maker"),children:(0,j.jsx)("div",{className:"editor-tabs-container",children:e?(0,j.jsxs)("div",{className:"editor-tabs editor-tabs--skeleton",children:[(0,j.jsx)("div",{className:"editor-tabs__sidebar-skeleton",children:[90,70,80].map((e,t)=>(0,j.jsx)(he.SkeletonBar,{width:`${e}%`,height:20},t))}),t]}):t})})},ge=e=>function({id:t,defaultValues:r=w.defaultCtaValues,onSave:o,...i}){const[s,a]=(0,N.useState)(!1),n=(0,N.useRef)(!1),l=(0,N.useRef)(void 0),c=(0,w.editorRecordKey)(t),d=(0,N.useMemo)(()=>({...w.defaultCtaValues,...r,id:c}),[r,c]),{values:u=d,isEditorActive:p,isSaving:h,savingAction:m,createSavedSuccessfully:g,updateSavedSuccessfully:v,getEditorValues:f,isLoadingEntity:b,fetchError:x}=(0,T.useSelect)(e=>{const r=e(w.callToActionStore),o=r.isResolving("updateCallToAction"),i=r.isResolving("createCallToAction");let s;return o?s="updateCallToAction":i&&(s="createCallToAction"),{values:r.getEditedCallToAction(c),isEditorActive:r.isEditorActive(),isSaving:o||i,savingAction:s,getEditorValues:r.getEditedCallToAction,createSavedSuccessfully:r.getResolutionState("createCallToAction").status===w.DispatchStatus.Success,updateSavedSuccessfully:r.getResolutionState("updateCallToAction").status===w.DispatchStatus.Success,isLoadingEntity:"number"==typeof t&&!r.hasEditedEntity(t)&&!r.getCallToAction(t),fetchError:"number"==typeof t?r.getFetchError(t):void 0}},[t,c]),{id:S}=u,{editRecord:_,resetRecordEdits:k,changeEditorId:y}=(0,T.useDispatch)(w.callToActionStore),A=(0,T.useSelect)(e=>e(G.store).getNotices(w.NOTICE_CONTEXT).filter(e=>!e.id?.startsWith("field-error-")),[]),{removeNotice:O}=(0,T.useDispatch)(G.store),{clearAllErrors:M}=Z(),R=(0,N.useRef)(M);R.current=M,(0,N.useEffect)(()=>{!p&&t&&y(t)},[t]),(0,N.useEffect)(()=>()=>{R.current()},[t]),(0,N.useEffect)(()=>{let e=!1;if("createCallToAction"===l.current?e=g:"updateCallToAction"===l.current&&(e=v),s){if(e&&!n.current){n.current=!0,l.current=void 0,a(!1);const e=f(u.id);o?.(e||u)}}else h&&(a(!0),n.current=!1,l.current=m)},[o,s,g,v,f,u,h,m]);const F=(0,T.useSelect)(e=>e(w.callToActionStore).hasEdits(S),[S]);if((0,N.useEffect)(()=>{const e=e=>{if(F){if(!window.confirm((0,E.__)("Changes you made may not be saved.","popup-maker")))return e.preventDefault(),!1;k(S)}return!0};return window.addEventListener("beforeunload",e),()=>{window.removeEventListener("beforeunload",e)}},[F,S]),!u)return(0,j.jsx)(j.Fragment,{children:(0,E.__)("Editor requires a valid call to action.","popup-maker")});if(!p)return null;if(b)return x?(0,j.jsx)(C.Notice,{status:"error",isDismissible:!1,className:"call-to-action-editor-error",children:x}):(0,j.jsx)(me,{});const D=()=>(0,j.jsx)(j.Fragment,{children:A.map(e=>(0,j.jsx)(C.Notice,{status:e.status||"error",className:"call-to-action-editor-error",onDismiss:!1!==e.isDismissible?()=>{O(e.id,w.NOTICE_CONTEXT)}:void 0,children:e.content},e.id))}),I=u;return(0,j.jsx)(e,{...i,values:I,onChange:e=>{_(u.id,e)},beforeTabs:(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(J,{}),(0,j.jsx)(D,{}),i.beforeTabs]})})},ve=e=>function({closeOnSave:t=!0,showDocumentationLink:r=!0,showActions:o=!0,onClose:i,onRequestClose:s,modalProps:a,...n}){const[l,c]=(0,N.useState)(),d=(0,T.useSelect)(e=>{const t=e(w.callToActionStore),r=t.getCurrentEditorValues();if(r)return r;const o=t.getEditorId();return{...t.getDefaultValues(),id:"number"==typeof o?o:0}},[]),u=(0,T.useSelect)(e=>e(w.callToActionStore),[]),p=(0,T.useSelect)(e=>e(w.callToActionStore).isResolving("updateCallToAction")||e(w.callToActionStore).isResolving("createCallToAction"),[]),{saveEditorValues:h,resetRecordEdits:m}=(0,T.useDispatch)(w.callToActionStore),{hasAnyError:g}=Z(),v=(0,T.useSelect)(e=>"number"==typeof d.id&&e(w.callToActionStore).hasEdits(d.id),[d.id]),f=(0,N.useMemo)(()=>a?.title?a.title:d?.id>0?`${(0,E.__)("Edit Call to Action","popup-maker")} #${d.id}${d?.title?` - ${d.title}`:""}`:(0,E.__)("New Call to Action","popup-maker"),[a?.title,d?.id,d?.title]),b=(0,N.useCallback)(()=>{u.isResolving("updateCallToAction")||u.isResolving("createCallToAction")||("number"==typeof d.id&&u.hasEdits(d.id)?c({message:(0,E.__)("Changes you made may not be saved.","popup-maker"),callback:()=>{m(d.id),i?.()},isDestructive:!0}):(m(d.id),i?.()))},[u,i,d.id]),x=(0,N.useCallback)(async()=>{if(!g)try{if(!await h())return;n?.onSave?.(d),!u.hasEdits(d.id)&&t&&b()}catch(e){console.error("Save failed:",e)}},[t,b,u,g,d]);return(0,j.jsxs)(j.Fragment,{children:[l&&(0,j.jsx)(A.ConfirmDialogue,{...l,onClose:()=>c(void 0)}),(0,j.jsxs)(C.Modal,{...a,title:f,className:k("call-to-action-editor-modal",a?.className),onRequestClose:b,shouldCloseOnClickOutside:!0,isDismissible:!1,headerActions:(0,j.jsxs)("div",{className:"editor-header-actions",children:[(0,j.jsx)(de,{values:d,closeModal:b}),(0,j.jsx)(pe,{values:d,closeModal:b}),(0,j.jsx)(C.Button,{className:"close-button",variant:"link",icon:R,"aria-label":(0,E.__)("Close","popup-maker"),onClick:b,style:{color:"currentColor"}})]}),children:[(0,j.jsx)(e,{...n}),o&&(0,j.jsxs)("div",{className:"editor-actions",children:[(0,j.jsx)(C.Button,{text:(0,E.__)("Cancel","popup-maker"),disabled:p,variant:"tertiary",isDestructive:!0,onClick:b,className:"cancel-button"}),(0,j.jsxs)(C.Button,{variant:"primary",disabled:p||!v||g,onClick:e=>{e.preventDefault(),x()},children:[p&&(0,j.jsx)(C.Spinner,{}),"number"==typeof d.id&&d.id>0?(0,E.__)("Save Call to Action","popup-maker"):(0,E.__)("Add Call to Action","popup-maker")]}),r&&(0,j.jsx)(C.Button,{text:(0,E.__)("Documentation","popup-maker"),href:"https://wppopupmaker.com/docs/?utm_campaign=documentation&utm_source=call-to-action-editor&utm_medium=plugin-ui&utm_content=footer-documentation-link",target:"_blank",icon:F,iconSize:20})]})]})]})},fe=e=>function({onSave:t,onClose:r,...o}){const{tab:i,setTab:s,clearEditorParams:a,editorId:n}=X(),{isEditorActive:l,isSaving:c}=(0,T.useSelect)(e=>{const t=e(w.callToActionStore);return{isEditorActive:t.isEditorActive(),isSaving:t.isResolving("updateCallToAction")||t.isResolving("createCallToAction")}},[]),d=(0,N.useCallback)(e=>{a(),t?.(e)},[t,!0,a]),u=(0,N.useCallback)(()=>{c||(a(),r?.())},[c,a,r]);return l?n?(0,j.jsx)(e,{...o,id:n,tab:i,setTab:s,onSave:d,onClose:u}):(0,j.jsx)(j.Fragment,{children:(0,E.__)("Editor requires a valid id","popup-maker")}):null},be=ge(ce),xe=!1;n()(()=>{le||((0,l.addFilter)("popupMaker.callToActionEditor.tabs","popup-maker/cta-editor/tabs",e=>[...e,...Object.values(s)]),ne(),Object.values(r).forEach(e=>{p(e)}),Object.values(o).forEach(e=>{f(e)}),le=!0),(0,l.doAction)("popupMaker.ctaEditor.init")}),(window.popupMaker=window.popupMaker||{}).ctaEditor=t})();
Save File
Cancel