← Back
Editing: admin-notifications.js
(()=>{"use strict";const e={n:t=>{const n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{if(Array.isArray(n))for(var i=0;i<n.length;){var o=n[i++],a=n[i++];e.o(t,o)?0===a&&i++:0===a?Object.defineProperty(t,o,{enumerable:!0,value:n[i++]}):Object.defineProperty(t,o,{enumerable:!0,get:a})}else for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},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,{NotificationItem:()=>N,NotificationPanel:()=>R,STORE_NAME:()=>c,init:()=>P,store:()=>d});const n=window.wp.domReady;var i=e.n(n);const o=window.wp.element,a=window.wp.data,r=window.wp.apiFetch;var s=e.n(r);const c="popup-maker/admin-notifications",l={items:[],isLoading:!1,hasLoaded:!1,error:null},u={fetchStart:()=>({type:"FETCH_START"}),fetchSuccess:e=>({type:"FETCH_SUCCESS",items:e}),fetchError:e=>({type:"FETCH_ERROR",error:e}),dismissLocal:e=>({type:"DISMISS_LOCAL",code:e}),fetchNotifications:()=>async({dispatch:e})=>{e.fetchStart();try{const t=await s()({path:"/popup-maker/v2/notifications"});e.fetchSuccess(Array.isArray(t)?t:[])}catch(t){const n=t instanceof Error?t.message:"Unknown error";e.fetchError(n)}},dismiss:(e,t="")=>async({dispatch:n})=>{n.dismissLocal(e);try{await s()({path:"/popup-maker/v2/notifications/dismiss",method:"POST",data:{code:e,action:t}})}catch(e){console.warn("[PM] dismiss failed",e),n.fetchNotifications()}}},d=(0,a.createReduxStore)(c,{reducer:(e=l,t)=>{switch(t.type){case"FETCH_START":return{...e,isLoading:!0,error:null};case"FETCH_SUCCESS":return{...e,items:t.items,isLoading:!1,hasLoaded:!0};case"FETCH_ERROR":return{...e,isLoading:!1,hasLoaded:!0,error:t.error};case"DISMISS_LOCAL":return{...e,items:e.items.filter(e=>e.code!==t.code)};default:return e}},actions:u,selectors:{getNotifications:e=>e.items,getCount:e=>e.items.length,isLoading:e=>e.isLoading,hasLoaded:e=>e.hasLoaded,getError:e=>e.error}}),p=window.wp.components,m=window.popupMaker.i18n;function f(e){var t,n,i="";if("string"==typeof e||"number"==typeof e)i+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(n=f(e[t]))&&(i&&(i+=" "),i+=n)}else for(n in e)e[n]&&(i&&(i+=" "),i+=n);return i}const _=function(){for(var e,t,n=0,i="",o=arguments.length;n<o;n++)(e=arguments[n])&&(t=f(e))&&(i&&(i+=" "),i+=t);return i},h="pum-notifications",w="pumOpenNotifications",y=()=>{if("undefined"!=typeof window&&window.history?.replaceState)try{const e=new URL(window.location.href);if(!e.searchParams.has(h))return;e.searchParams.delete(h),window.history.replaceState({},"",e.toString())}catch{}},g=window.ReactJSXRuntime,v={feature:(0,m.__)("What’s New","popup-maker"),recommendation:(0,m.__)("Tip for you","popup-maker"),announcement:(0,m.__)("Announcement","popup-maker"),offer:(0,m.__)("Offer","popup-maker"),warning:(0,m.__)("Heads up","popup-maker")},b={feature:"lightbulb",recommendation:"chart-line",announcement:"megaphone",offer:"tickets-alt",warning:"warning"},k=e=>({__html:e}),x="pumReviewRequestDismissed",S=()=>{document.dispatchEvent(new CustomEvent(x))},j=(e,t)=>{if("review_request"!==e.code||void 0===window.pum_review_api_url)return;const n=new window.URLSearchParams({trigger_group:window.pum_review_trigger?.group||"",trigger_code:window.pum_review_trigger?.code||"",reason:t&&"dismiss"!==t?t:"maybe_later",product:window.pum_review_context?.product||"core",attempt:String(window.pum_review_context?.attempt||0),uuid:window.pum_review_uuid||""});window.fetch(window.pum_review_api_url,{method:"POST",body:n,keepalive:!0,credentials:"omit"}).catch(()=>{})},N=({notification:e,isVisible:t=!0})=>{const{dismiss:n,dismissLocal:i}=(0,a.useDispatch)(c),[r,s]=(0,o.useState)(!1),[l,u]=(0,o.useState)(null),[d,f]=(0,o.useState)(""),h=(0,o.useRef)(null);(0,o.useEffect)(()=>()=>{null!==h.current&&window.clearTimeout(h.current)},[]),(0,o.useEffect)(()=>{if("review_request"!==e.code)return;const t=()=>{i(e.code)};return document.addEventListener(x,t),()=>{document.removeEventListener(x,t)}},[i,e.code]),(0,o.useEffect)(()=>{const n=window.pum_review_context;if("review_request"!==e.code||!t||!n?.needsImpression)return;const i=`shown_${n.product||"core"}`;n.needsImpression=!1,(e=>{if(!(window.pum_review_ajax_url&&window.pum_review_nonce&&window.pum_review_trigger?.group&&window.pum_review_trigger?.code))return Promise.resolve();const t=new window.URLSearchParams({action:"pum_review_action",nonce:window.pum_review_nonce,group:window.pum_review_trigger.group,code:window.pum_review_trigger.code,reason:e});return window.fetch(window.pum_review_ajax_url,{method:"POST",body:t,keepalive:!0,credentials:"same-origin"}).then(()=>{})})(i).then(()=>j(e,i)).catch(()=>{})},[t,e]);const w=t=>{const i=t.target,o=i?.closest?.("a");if(!o)return;const a=o.classList.contains("pum-dismiss"),r=o.getAttribute("href")||"";if(a){const i=o.dataset.reason||"maybe_later";"review_request"===e.code&&j(e,i),r&&"#"!==r||t.preventDefault(),n(e.code,i),"review_request"===e.code&&S()}};(0,o.useRef)(null),(0,o.useEffect)(()=>{document.querySelectorAll(`[data-code="${CSS.escape(e.code)}"] .pum-notification-item__body a`).forEach(e=>{const t=e.getAttribute("href")||"",n=/^https?:\/\//i.test(t);n&&!e.hasAttribute("target")&&e.setAttribute("target","_blank"),n&&!e.hasAttribute("rel")&&e.setAttribute("rel","noopener noreferrer")})},[e.code,e.message,e.html]);const N=e.icon||b[e.category]||"admin-generic",E=v[e.category]||e.category,L=t=>t.primary?"offer"===e.category?"pum-notification-cta pum-notification-cta--chip":"pum-notification-cta pum-notification-cta--link":"pum-notification-cta pum-notification-cta--muted";return(0,g.jsxs)("article",{className:_("pum-notification-item",`pum-notification-item--${e.category}`,{"is-dismissing":r}),"data-code":e.code,"data-category":e.category,children:[(0,g.jsx)("span",{className:"pum-notification-item__icon","aria-hidden":"true",children:(0,g.jsx)("span",{className:`dashicons dashicons-${N}`})}),(0,g.jsxs)("div",{className:"pum-notification-item__head",children:[(0,g.jsx)("span",{className:"pum-notification-item__category",children:E}),e.subtitle&&(0,g.jsx)("span",{className:"pum-notification-item__time",children:e.subtitle})]}),e.dismissible&&(0,g.jsx)("button",{type:"button",className:"pum-notification-item__dismiss","aria-label":(0,m.__)("Dismiss","popup-maker"),onClick:()=>{s(!0),"review_request"===e.code&&j(e,"maybe_later"),h.current=window.setTimeout(()=>{n(e.code,""),"review_request"===e.code&&S()},260)},children:(0,g.jsx)("span",{className:"dashicons dashicons-no-alt"})}),e.title&&(0,g.jsx)("h3",{className:"pum-notification-item__title",dangerouslySetInnerHTML:k(e.title)}),e.message&&(0,g.jsx)("div",{className:"pum-notification-item__body",onClick:w,dangerouslySetInnerHTML:k(e.message)}),e.html&&(0,g.jsx)("div",{className:"pum-notification-item__body pum-notification-item__body--legacy",onClick:w,dangerouslySetInnerHTML:k(e.html)}),e.actions.length>0&&(0,g.jsx)("div",{className:"pum-notification-item__actions",children:e.actions.map((t,i)=>{const o=`${e.code}-a-${i}`;if("link"===t.type&&t.href){const e=!0===t.external||"_blank"===t.target,n=e?void 0:()=>y();return(0,g.jsx)("a",{href:t.href,target:e?"_blank":void 0,rel:e?"noopener noreferrer":void 0,className:L(t),onClick:n,children:t.text},o)}return(0,g.jsx)("button",{type:"button",className:L(t),onClick:i=>((t,i)=>{if("iframe"===i.type&&i.href)return t.preventDefault(),u(i.href),void f(i.text);"link"===i.type&&i.href||(t.preventDefault(),n(e.code,i.action||"dismiss"))})(i,t),children:t.text},o)})}),l&&(0,g.jsxs)(p.Modal,{className:"pum-notification-item__iframe-modal",__experimentalHideHeader:!0,contentLabel:d||(0,m.__)("Details","popup-maker"),onRequestClose:()=>u(null),shouldCloseOnClickOutside:!0,shouldCloseOnEsc:!0,children:[(0,g.jsx)("button",{type:"button",className:"pum-notification-item__iframe-close","aria-label":(0,m.__)("Close","popup-maker"),onClick:()=>u(null),children:(0,g.jsx)("span",{className:"dashicons dashicons-no-alt"})}),(0,g.jsx)("iframe",{title:d||(0,m.__)("Details","popup-maker"),src:l,className:"pum-notification-item__iframe",sandbox:"allow-scripts allow-same-origin allow-popups allow-forms"})]})]})},E=window.popupMaker.icons,L=({count:e,showCount:t,onClose:n})=>{const i=(0,m.sprintf)(/* translators: %d: number of unread notifications. */ /* translators: %d: number of unread notifications. */ (0,m._n)("%d unread notification","%d unread notifications",e,"popup-maker"),e);return(0,g.jsxs)("header",{className:"pum-notification-panel__header",children:[(0,g.jsxs)("div",{className:"pum-notification-panel__brand",children:[(0,g.jsx)(p.Icon,{icon:E.MarkColored,size:28,className:"pum-notification-panel__mark"}),(0,g.jsxs)("div",{className:"pum-notification-panel__brand-text",children:[(0,g.jsx)("span",{className:"pum-notification-panel__brand-label",children:(0,m.__)("Popup Maker","popup-maker")}),(0,g.jsxs)("h2",{className:"pum-notification-panel__title",children:[(0,m.__)("Notifications","popup-maker"),t&&(0,g.jsx)("span",{className:"pum-notification-panel__count","aria-label":i,children:e})]})]})]}),(0,g.jsx)(p.Button,{icon:"no-alt",label:(0,m.__)("Close","popup-maker"),showTooltip:!0,onClick:n})]})},C=[{key:"all",label:(0,m.__)("All","popup-maker")},{key:"feature",label:(0,m.__)("What’s New","popup-maker")},{key:"recommendation",label:(0,m.__)("Tips","popup-maker")},{key:"announcement",label:(0,m.__)("News","popup-maker")},{key:"offer",label:(0,m.__)("Offers","popup-maker")}],A=({counts:e,active:t,onChange:n})=>(0,g.jsx)("div",{className:"pum-notification-filters",children:C.map(i=>{const o=e[i.key]||0;return"all"!==i.key&&0===o?null:(0,g.jsxs)("button",{type:"button","data-filter":i.key,className:_("pum-notification-chip",{"is-active":t===i.key}),"aria-pressed":t===i.key,onClick:()=>n(i.key),children:["all"!==i.key&&(0,g.jsx)("span",{className:"pum-notification-chip__dot"}),i.label,(0,g.jsx)("span",{className:"pum-notification-chip__count",children:o})]},i.key)})}),O=["a[href]","button:not([disabled])",'input:not([disabled]):not([type="hidden"])',"select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(","),R=({initiallyOpen:e=!1})=>{const{isOpen:t,setIsOpen:n}=(({initiallyOpen:e=!1}={})=>{const[t,n]=(0,o.useState)(e),i=(0,o.useCallback)(e=>{n(e),e?(()=>{if("undefined"!=typeof window&&window.history?.pushState)try{const e=new URL(window.location.href);if("open"===e.searchParams.get(h))return;e.searchParams.set(h,"open"),window.history.pushState({},"",e.toString())}catch{}})():y()},[]);return(0,o.useEffect)(()=>{if(!t)return;const e=e=>{"Escape"===e.key&&i(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,i]),(0,o.useEffect)(()=>{const e=e=>{if(e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;const t=e.target;if(!t)return;const n=null!==t.closest("[data-pum-notifications-trigger]"),o=null!==t.closest("#wp-admin-bar-pum-notifications");(n||o)&&(e.preventDefault(),i(!0))};return document.addEventListener("click",e),()=>document.removeEventListener("click",e)},[i]),(0,o.useEffect)(()=>{const e=()=>{try{const e="open"===new URL(window.location.href).searchParams.get(h);n(e)}catch{}};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[]),{isOpen:t,setIsOpen:i}})({initiallyOpen:e}),i=(0,o.useRef)(null);((e,t)=>{const n=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!e)return;n.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const i=t.current;let o=!1;if(i){const e=i.querySelectorAll(O)[0];e?e.focus():(i.hasAttribute("tabindex")||(i.setAttribute("tabindex","-1"),o=!0),i.focus())}const a=e=>{if("Tab"!==e.key||!i)return;const t=Array.from(i.querySelectorAll(O)).filter(e=>!e.hasAttribute("data-pum-trap-skip"));if(0===t.length)return void e.preventDefault();const n=t[0],o=t[t.length-1],a=document.activeElement;e.shiftKey&&a===n?(e.preventDefault(),o.focus()):e.shiftKey||a!==o||(e.preventDefault(),n.focus())};return document.addEventListener("keydown",a),()=>{document.removeEventListener("keydown",a),i&&o&&i.removeAttribute("tabindex");const e=n.current;e&&document.contains(e)&&e.focus(),n.current=null}},[e,t])})(t,i);const{items:r,isLoading:s,hasLoaded:l,counts:u,activeFilter:d,setActiveFilter:f,visibleItems:w}=(()=>{const[e,t]=(0,o.useState)("all"),{fetchNotifications:n}=(0,a.useDispatch)(c),{items:i,isLoading:r,hasLoaded:s}=(0,a.useSelect)(e=>{const t=e(c);return{items:t.getNotifications(),isLoading:t.isLoading(),hasLoaded:t.hasLoaded()}},[]);(0,o.useEffect)(()=>{n()},[n]);const l=(0,o.useMemo)(()=>{const e={all:i.length,feature:0,recommendation:0,announcement:0,offer:0,warning:0};return i.forEach(t=>{e[t.category]=(e[t.category]||0)+1}),e},[i]),u=(0,o.useMemo)(()=>"all"===e?i:i.filter(t=>t.category===e),[i,e]);return{items:i,isLoading:r,hasLoaded:s,counts:l,activeFilter:e,setActiveFilter:t,visibleItems:u}})();((e,t)=>{(0,o.useEffect)(()=>{if(!e)return;const n=document.querySelectorAll(".pum-notifications-marker"),i=document.getElementById("wp-admin-bar-pum-notifications");if(0===t)return n.forEach(e=>{e.style.display="none"}),void(i&&(i.style.display="none"));const o=(0,m.sprintf)(/* translators: %d: notification count. */ /* translators: %d: notification count. */ (0,m._n)("%d Popup Maker notification","%d Popup Maker notifications",t,"popup-maker"),t);if(n.forEach(e=>{e.style.display="",e.dataset.count=String(t),e.setAttribute("aria-label",o)}),i){i.style.display="";const e=i.querySelector(".pum-notifications-count");e&&(e.textContent=String(t))}},[e,t])})(l,r.length);const v=r.length>0;return(0,g.jsxs)(g.Fragment,{children:[t&&(0,g.jsx)("div",{className:"pum-notification-panel__backdrop",onClick:()=>n(!1),"aria-hidden":"true"}),(0,g.jsxs)("aside",{ref:i,className:_("pum-notification-panel",{"is-open":t}),role:"dialog","aria-modal":t?"true":"false","aria-hidden":t?void 0:"true","aria-label":(0,m.__)("Popup Maker notifications","popup-maker"),...t?{}:{inert:""},children:[(0,g.jsx)(L,{count:r.length,showCount:l&&v,onClose:()=>n(!1)}),l&&v&&(0,g.jsx)(A,{counts:u,active:d,onChange:f}),(0,g.jsxs)("div",{className:"pum-notification-panel__body",children:[s&&!l&&(0,g.jsx)("div",{className:"pum-notification-panel__loading",children:(0,g.jsx)(p.Spinner,{})}),l&&!v&&(0,g.jsx)("p",{className:"pum-notification-panel__empty",children:(0,m.__)("You’re all caught up. No notifications right now.","popup-maker")}),l&&v&&0===w.length&&(0,g.jsx)("p",{className:"pum-notification-panel__empty",children:(0,m.__)("Nothing in this category right now.","popup-maker")}),w.map(e=>(0,g.jsx)(N,{notification:e,isVisible:t},e.code))]}),l&&v&&(0,g.jsx)("footer",{className:"pum-notification-panel__footer",children:(0,g.jsx)("span",{className:"pum-notification-panel__footer-note",children:(0,m.__)("Dismiss items you’re not interested in — we’ll remember.","popup-maker")})})]})]})},T="pum-notifications-panel-root",P=()=>{(0,a.register)(d);const e=(()=>{let e=document.getElementById(T);return e||(e=document.createElement("div"),e.id=T,document.body.appendChild(e)),e})();(0,o.createRoot)(e).render((0,g.jsx)(R,{initiallyOpen:(()=>{try{return"open"===new URL(window.location.href).searchParams.get(h)}catch{return!1}})()||(()=>{if("undefined"==typeof window||!window.localStorage)return!1;try{const e=window.localStorage.getItem(w);if(!e)return!1;window.localStorage.removeItem(w);const t=JSON.parse(e);return"number"==typeof t?.exp&&t.exp>Date.now()}catch{try{window.localStorage.removeItem(w)}catch{}return!1}})()}))};i()(P),(window.popupMaker=window.popupMaker||{}).adminNotifications=t})();
Save File
Cancel