2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
(()=>{"use strict";var e={n:t=>{var o=t&&t.__esModule?()=>t.default:()=>t;return e.d(o,{a:o}),o},d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function o(e){var t,r,p="";if("string"==typeof e||"number"==typeof e)p+=e;else if("object"==typeof e)if(Array.isArray(e)){var n=e.length;for(t=0;t<n;t++)e[t]&&(r=o(e[t]))&&(p&&(p+=" "),p+=r)}else for(r in e)e[r]&&(p&&(p+=" "),p+=r);return p}e.r(t),e.d(t,{TriggerEdit:()=>F,name:()=>O,settings:()=>M});const r=function(){for(var e,t,r=0,p="",n=arguments.length;r<n;r++)(e=arguments[r])&&(t=o(e))&&(p&&(p+=" "),p+=t);return p},p=window.popupMaker.i18n,n=window.wp.hooks,i=window.wp.blockEditor,a=window.wp.components,s=window.wp.compose,l=window.popupMaker.components,u=window.popupMaker.icons,c=window.ReactJSXRuntime,{popupTriggerExcludedBlocks:d}=window.popupMakerBlockEditor,g=[],m=d||["core/nextpage","popup-maker/call-to-action","popup-maker/call-to-actions"];function h(e){return!g.length&&!m.length||(g.length?g.includes(e):!m.length||!m.includes(e))}const k=(0,s.createHigherOrderComponent)(e=>t=>{const{name:o,attributes:r,setAttributes:n,isSelected:s}=t,{openPopupId:d}=r;return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(e,{...t}),s&&h(o)&&(0,c.jsx)(i.InspectorControls,{children:(0,c.jsx)(a.Panel,{className:"pum-block-inspector-popup-controls",children:(0,c.jsxs)(a.PanelBody,{title:(0,p.__)("Popup Controls","popup-maker"),icon:u.Mark,initialOpen:!1,children:[(0,c.jsx)(a.PanelRow,{children:(0,p.__)("These settings allow you to control popups with this block.","popup-maker")}),(0,c.jsx)(a.PanelRow,{children:(0,c.jsx)(l.PopupSelectControl,{label:(0,c.jsxs)(c.Fragment,{children:[(0,p.__)("Open Popup","popup-maker"),(0,c.jsx)(a.Tooltip,{placement:"top",text:(0,p.__)("This method does not work well with all block types.","popup-maker"),children:(0,c.jsx)("a",{href:"https://wppopupmaker.com/docs/triggering-popups/trigger-click-open-overview-methods/",target:"_blank",rel:"noopener noreferrer",children:(0,c.jsx)(a.Icon,{size:16,icon:"editor-help",title:(0,p.__)("Open documentation","popup-maker"),style:{verticalAlign:"middle"}})})})]}),value:d,onChange:e=>n({openPopupId:e}),help:(0,p.__)("Open a popup when clicking this block","popup-maker")})})]})})})]})},"withAdvancedControls");(0,n.addFilter)("blocks.registerBlockType","popup-maker/popup-trigger-attributes",function(e){return void 0!==e.attributes&&h(e.name)&&(e.attributes=Object.assign(e.attributes,{openPopupId:{type:"string",default:""}})),e}),(0,n.addFilter)("editor.BlockEdit","popup-maker/popup-trigger-advanced-control",k),(0,n.addFilter)("blocks.getSaveContent.extraProps","popup-maker/applyTriggerClass",function(e,t,o){const{openPopupId:p}=o;return void 0!==p&&p>0&&h(t.name)&&(e.className=r(e.className,"popmake-"+p)),e});const _=window.wp.richText,w=window.wp.a11y,v=window.wp.element,b=window.wp.data,f=window.wp.keycodes,x=({className:e,onChangeInputValue:t,value:o,...n})=>(0,c.jsx)("form",{className:r("block-editor-popup-trigger-popover__popup-editor",e),role:"dialog","aria-label":(0,p.__)("Popup Trigger Editor","popup-maker"),...n,children:(0,c.jsxs)("div",{className:"block-editor-popup-select-input",role:"group","aria-label":(0,p.__)("Popup Selection Controls","popup-maker"),children:[(0,c.jsx)(l.PopupSelectControl,{emptyValueLabel:(0,p.__)("Which popup should open?","popup-maker"),hideLabelFromVision:!0,value:String(o),onChange:t,required:!0}),(0,c.jsx)(a.Button,{icon:"editor-break",label:(0,p.__)("Apply","popup-maker"),type:"submit"})]})}),y=window.wp.htmlEntities,{popups:S=[]}=window.popupMakerBlockEditor;function T({popupId:e,className:t}){const o=r(t,"block-editor-popup-trigger-popover__popup-viewer-text"),n=((e=0)=>{e=parseInt(String(e))||0;const t=S.filter(({id:t})=>e===t);return 1===t.length&&t[0]})(e),i=n?/* translators: %s = popup title */ /* translators: %s = popup title */
|
|
(0,p.sprintf)((0,p.__)('Open "%s" popup',"popup-maker"),(0,y.decodeEntities)(n.title.rendered)):"";return(0,c.jsx)("span",{className:o,role:"button","aria-label":i,children:i})}function C({className:e="",spanClassName:t="",onEditTriggerClick:o,popupId:n,...i}){return(0,c.jsxs)("div",{className:r("block-editor-popup-trigger-popover__popup-viewer",e),role:"region","aria-label":(0,p.__)("Popup Trigger Preview","popup-maker"),...i,children:[(0,c.jsx)(T,{popupId:n,className:t}),o&&(0,c.jsx)(a.Button,{icon:"edit",label:(0,p.__)("Edit","popup-maker"),onClick:o})]})}function j(e,t,o,r,p){let n=t;const i={forwards:1,backwards:-1}[p]||1,a=-1*i;for(;e[n]&&e[n][r]===o;)n+=i;return n+=a,n}const P=(e,...t)=>(...o)=>e(...o,...t),I=(P(j,"backwards"),P(j,"forwards"),e=>e.stopPropagation()),E=e=>{[f.LEFT,f.DOWN,f.RIGHT,f.UP,f.BACKSPACE,f.ENTER].indexOf(parseInt(e.key))>-1&&e.stopPropagation()},N=({isActive:e,activeAttributes:t,value:o,onChange:r,onFocusOutside:n,stopAddingTrigger:s,contentRef:l,focusOnMount:u})=>{const{selectionChange:d}=(0,b.useDispatch)(i.store),{selectionStart:g}=(0,b.useSelect)(e=>{const{getSelectionStart:t}=e(i.store);return{selectionStart:t()}},[]),m=(0,v.useMemo)(()=>{return e=t,{popupId:parseInt(e.popupId??"0"),doDefault:"1"===e.doDefault};var e},[t]),[h,k]=(0,v.useState)(!t||!t.popupId),f=(0,_.useAnchor)({editableContentElement:l.current,settings:{...M,isActive:e}}),y=(0,v.useCallback)(()=>{const e=(0,_.removeFormat)(o,O);r(e),s(),(0,w.speak)((0,p.__)("Trigger removed.","popup-maker"),"assertive")},[r,s,o]),[S,T]=(0,v.useState)(!1),j=(0,v.useCallback)(()=>{T(e=>!e)},[]),P=(0,v.useCallback)(t=>{const n=m?.popupId,i=!n,a={...m,...t};if(!i&&!a?.popupId)return void y();const s=(({popupId:e=0,doDefault:t=!1})=>({type:O,attributes:{class:`popmake-${e} ${t?"pum-do-default":""}`,popupId:e.toString(),doDefault:t?"1":"0"}}))(a),l=(0,p.__)("Open Popup","popup-maker");let u;(0,_.isCollapsed)(o)&&!e?(u=function(e,t,o,r){const p=(0,_.insert)(e,t,r);return(0,_.applyFormat)(p,o,r,r+t.length)}(o,l,s,o.start),r(u),d({clientId:g.clientId,identifier:g.attributeKey,start:o.start+l.length+1})):(u=(0,_.applyFormat)(o,s),r(u)),e?(0,w.speak)((0,p.__)("Trigger edited.","popup-maker"),"assertive"):(0,w.speak)((0,p.__)("Trigger inserted.","popup-maker"),"assertive")},[m,o,e,r,y,d,g]),N=h||!m.popupId,{popupId:A,doDefault:F}=m,D=(0,v.useRef)(null);return(0,v.useEffect)(()=>{const t=l.current;D.current=e&&t?.ownerDocument?.activeElement!==t?.ownerDocument?.body?t?.ownerDocument?.activeElement:t;const o=e=>{"Escape"===e.key&&s()};return document.addEventListener("keydown",o),()=>{D.current&&"focus"in D.current&&D.current.focus(),document.removeEventListener("keydown",o)}},[l,e,s]),(0,v.useEffect)(()=>()=>{},[]),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(a.Popover,{className:"block-editor-popup-trigger__inline-popover editor-popup-trigger-popover block-editor-popup-trigger-popover",anchor:f,animate:!1,onClose:()=>{e||s()},onFocusOutside:n,position:"bottom center",offset:8,shift:!0,focusOnMount:u,constrainTabbing:!0,children:(0,c.jsxs)("div",{className:"block-editor-popup-trigger-popover__input-container",children:[(0,c.jsxs)("div",{className:"editor-popup-trigger-popover__row block-editor-popup-trigger-popover__row",children:[N?(0,c.jsx)(x,{className:"editor-format-toolbar__trigger-container-content block-editor-format-toolbar__trigger-container-content",value:A??"",onChangeInputValue:e=>{P({popupId:Number(e)})},onKeyDown:E,onKeyPress:I,onSubmit:s}):(0,c.jsx)(C,{className:"editor-format-toolbar__trigger-container-content block-editor-format-toolbar__trigger-container-content",onKeyPress:I,popupId:A??0,onEditTriggerClick:e=>{k(!0),e.preventDefault()}}),(0,c.jsx)(a.Button,{className:"editor-popup-trigger-popover__settings-toggle block-editor-popup-trigger-popover__settings-toggle",icon:S?"arrow-up-alt2":"arrow-down-alt2",label:(0,p.__)("Trigger settings","popup-maker"),onClick:j,"aria-expanded":S})]}),S&&(0,c.jsx)("div",{className:"editor-popup-trigger-popover__row block-editor-popup-trigger-popover__row editor-popup-trigger-popover__settings block-editor-popup-trigger-popover__settings",children:(0,c.jsx)(a.ToggleControl,{label:(0,p.__)("Do not prevent default click behavior","popup-maker"),checked:!!F,onChange:e=>P({doDefault:e}),__nextHasNoMarginBottom:!0})})]})})})},A=(0,p.__)("Popup Trigger","popup-maker"),O="popup-maker/popup-trigger",F=(0,a.withSpokenMessages)(({isActive:e,activeAttributes:t,value:o,onChange:r,onFocus:n,contentRef:a})=>{const[s,l]=(0,v.useState)(!1),[d,g]=(0,v.useState)(null);(0,v.useEffect)(()=>{e||l(!1)},[e]),(0,v.useLayoutEffect)(()=>{const t=a?.current;if(t)return t.addEventListener("click",o),()=>{t.removeEventListener("click",o)};function o(t){const o=t.target,r=o?.closest("[contenteditable] span.popup-trigger");r&&e&&(l(!0),g({el:r,action:"click"}))}},[a,e]);const m=()=>{l(!0)},h=()=>{r((0,_.removeFormat)(o,O)),(0,w.speak)((0,p.__)("Trigger removed.","popup-maker"),"assertive")},k=!("SPAN"===d?.el?.tagName&&"click"===d?.action),b=!(0,_.isCollapsed)(o);return(0,c.jsxs)(c.Fragment,{children:[b&&(0,c.jsx)(i.RichTextShortcut,{type:"primary",character:"p",onUse:m}),(0,c.jsx)(i.RichTextShortcut,{type:"primaryShift",character:"p",onUse:h}),e?(0,c.jsx)(i.RichTextToolbarButton,{icon:u.MarkWhite,iconSize:16,title:(0,p.__)("Remove Trigger","popup-maker"),onClick:h,isActive:e,shortcutType:"primaryShift",shortcutCharacter:"p","aria-haspopup":"true","aria-expanded":s}):(0,c.jsx)(i.RichTextToolbarButton,{icon:u.Mark,iconSize:16,title:A,onClick:m,isActive:e,shortcutType:"primary",shortcutCharacter:"p","aria-haspopup":"true","aria-expanded":s}),s&&(0,c.jsx)(N,{stopAddingTrigger:()=>{l(!1),d?.el?d.el.focus():n(),g(null)},onFocusOutside:()=>{l(!1),g(null)},isActive:e,activeAttributes:t,value:o,onChange:r,contentRef:a,focusOnMount:!!k&&"firstElement"})]})}),M={name:O,title:A,tagName:"span",className:"popup-trigger",object:!1,attributes:{popupId:"data-popup-id",doDefault:"data-do-default"},interactive:!1,edit:F};[t].forEach(({name:e,settings:t})=>(0,_.registerFormatType)(e,t));const D=window.wp.i18n,R=window.wp.editPost,B=window.wp.plugins,L=window.wp.apiFetch;var K=e.n(L);const V={postId:null,title:"",hasChanges:!1};let z=!1;(0,B.registerPlugin)("popup-maker-title-panel",{render:()=>{const[e,t]=(0,v.useState)(""),[o,r]=(0,v.useState)(!1),{postType:p,postId:n,popupTitle:i}=(0,b.useSelect)(e=>{const t=e("core/editor");return{postType:t.getCurrentPostType(),postId:t.getCurrentPostId(),popupTitle:t.getEditedPostAttribute("popup_title")??""}},[]);return(0,v.useEffect)(()=>{if("popup"===p&&!o&&n){const e=i||"";t(e),r(!0),V.postId=n,V.title=e,V.hasChanges=!1,function(){if(z)return;z=!0;let e=!1;(0,b.subscribe)(()=>{const t=(0,b.select)("core/editor"),o=t.isSavingPost(),r=t.isAutosavingPost(),p=t.didPostSaveRequestSucceed(),n=e&&!o&&!r;e=o&&!r,n&&p&&V.hasChanges&&V.postId&&K()({path:`/popup-maker/v2/popups/${V.postId}`,method:"POST",data:{popup_title:V.title}}).then(()=>{V.hasChanges=!1}).catch(e=>{console.error("Failed to save popup title:",e),(0,b.dispatch)("core/notices").createErrorNotice((0,D.__)("Failed to save popup title.","popup-maker"),{type:"snackbar"})})})}()}},[p,n,i,o]),"popup"!==p?null:(0,c.jsx)(R.PluginDocumentSettingPanel,{name:"popup-title-panel",title:(0,D.__)("Popup Title","popup-maker"),className:"popup-maker-title-panel",children:(0,c.jsx)(a.TextControl,{label:(0,D.__)("Title","popup-maker"),value:e,onChange:e=>{t(e),V.title=e,V.hasChanges=!0},help:(0,D.__)("Shown as headline inside the popup.","popup-maker")})})},icon:null});const H=window.popupMaker.coreData;(0,b.register)(H.callToActionStore),(0,b.register)(H.licenseStore),(0,b.register)(H.settingsStore),(0,b.register)(H.popupStore),(0,b.register)(H.urlSearchStore),(window.popupMaker=window.popupMaker||{}).blockEditor={}})(); |