@automattic/newspack-blocks 4.17.0-alpha.1 → 4.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- # [4.17.0-alpha.1](https://github.com/Automattic/newspack-blocks/compare/v4.16.0...v4.17.0-alpha.1) (2025-10-17)
1
+ # [4.17.0](https://github.com/Automattic/newspack-blocks/compare/v4.16.1...v4.17.0) (2025-10-30)
2
2
 
3
3
 
4
4
  ### Bug Fixes
@@ -6,6 +6,7 @@
6
6
  * correct RTL styles for the Content Loop ([#2215](https://github.com/Automattic/newspack-blocks/issues/2215)) ([a8e2f42](https://github.com/Automattic/newspack-blocks/commit/a8e2f42655c63dbea3a6a8cf3fd0c497ae038365))
7
7
  * ga4 events for tiered modal ([#2218](https://github.com/Automattic/newspack-blocks/issues/2218)) ([a08981d](https://github.com/Automattic/newspack-blocks/commit/a08981dd7c7ea168825a12bddc74840493560d3e))
8
8
  * handle invalid file errors when processing archive ([#2221](https://github.com/Automattic/newspack-blocks/issues/2221)) ([2ba3d26](https://github.com/Automattic/newspack-blocks/commit/2ba3d26fc2864f8f28705d26866deb136d32a7e8))
9
+ * **modal-checkout:** skip newsletter signup on subscription switch ([#2235](https://github.com/Automattic/newspack-blocks/issues/2235)) ([e6feccc](https://github.com/Automattic/newspack-blocks/commit/e6feccc5277dfdfcf909603e134a1f21d64fc938))
9
10
  * **modal-checkout:** style improvements to single-gateway ([#2223](https://github.com/Automattic/newspack-blocks/issues/2223)) ([3c0014a](https://github.com/Automattic/newspack-blocks/commit/3c0014a463649545a3d5680c4ca16eca2c23de5e))
10
11
 
11
12
 
@@ -13,6 +14,13 @@
13
14
 
14
15
  * add newspack-colors and newspack-icons packages ([#2222](https://github.com/Automattic/newspack-blocks/issues/2222)) ([f6bdf20](https://github.com/Automattic/newspack-blocks/commit/f6bdf20434f34e813b13856266372ad355f31f19))
15
16
 
17
+ ## [4.16.1](https://github.com/Automattic/newspack-blocks/compare/v4.16.0...v4.16.1) (2025-10-27)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * update subscriptions gifting method ([#2232](https://github.com/Automattic/newspack-blocks/issues/2232)) ([6b5e665](https://github.com/Automattic/newspack-blocks/commit/6b5e665c6797cb26228613fb7cdc96c8889455c5))
23
+
16
24
  # [4.16.0](https://github.com/Automattic/newspack-blocks/compare/v4.15.4...v4.16.0) (2025-10-06)
17
25
 
18
26
 
@@ -1 +1 @@
1
- <?php return array('dependencies' => array(), 'version' => '94f4e19994c46c789430');
1
+ <?php return array('dependencies' => array(), 'version' => '4da23ff508a2c8e9fb3f');
package/dist/modal.js CHANGED
@@ -1 +1 @@
1
- (()=>{"use strict";function e(e,t=!1){const n=e.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])');if(0===n.length)return!1;const o=n?.[0];let c;o.focus(),t?(document.addEventListener("keydown",(function(e){if(("Tab"===e.key||9===e.keyCode)&&e.shiftKey&&document.activeElement===o){const n=t.contentWindow.document,o=n.getElementById("checkout-after-success");c=null!==o?o:n.getElementById("checkout_cancel"),c.focus(),e.preventDefault()}})),document.getElementById("newspack-a11y-last-element").addEventListener("focus",(()=>{o.focus()}))):(c=n[n.length-1],document.addEventListener("keydown",(function(e){("Tab"===e.key||9===e.keyCode)&&(e.shiftKey?document.activeElement===o&&(c.focus(),e.preventDefault()):document.activeElement===c&&(o.focus(),e.preventDefault()))})))}const t=(e,t={})=>({...t,action:e}),n=["action","action_type","amount","currency","product_id","product_type","variation_id","variation_ids","is_variable","is_grouped","child_ids","price_summary","newspack_popup_id","gate_post_id","recurrence","referrer"],o=(e,t="np_modal_checkout_interaction")=>{if("function"==typeof window.gtag&&e){const o={};for(const t of n)e[t]&&("boolean"==typeof e[t]?e[t]=e[t]?"yes":"no":"true"===e[t]?e[t]="yes":"false"===e[t]&&(e[t]="no"),o[t]=e[t].toString());window.gtag("event",t,o)}},c=e=>{if("function"!=typeof window.gtag)return;let n="opened";const{amount:c="",is_variable:a="",is_grouped:r="",price:s="",variation_id:i=""}=e,l={...e};(c||s)&&(l.amount=c||s),a&&!i&&(n="opened_variations"),r&&(n="opened_grouped");const d=t(n,l);o(d)};function a(e,t=null){const n=document.createElement("input");return n.type="hidden",n.name=e,t&&(n.value=t),n}function r(e){e.requestSubmit(e.querySelector('button[type="submit"]'))}function s(e){const t="string"==typeof e?document.getElementById(e):e;if(!t)return console.warn("No container found for checkout data"),{};let n={};if("FORM"===t.tagName){const e=new FormData(t);n=Object.fromEntries(e)}const o=t.dataset.checkout;if(!o)return console.warn("No checkout data found"),n;try{n={...n,...JSON.parse(o)}}catch(e){console.warn("Error parsing checkout data")}const c=new URL(t.ownerDocument.defaultView.location.href);return c.searchParams.get("action_type")&&(n.action_type=c.searchParams.get("action_type")),n.memberships_content_gate&&(n.gate_post_id=n.memberships_content_gate,delete n.memberships_content_gate),n}const i=e=>{if("function"!=typeof window.gtag)return;e=e||s("newspack_modal_checkout");const n=t("dismissed",e);o(n)},l=newspackBlocksModal.newspack_class_prefix,d="newspack_modal_checkout_iframe",u="newspack_modal_checkout_container",m=`${l}__modal`,p="newspack-blocks__modal-variation";let _=!1,h=newspackBlocksModal.labels.checkout_modal_title;const w=e=>{e.overlayId&&window.newspackReaderActivation?.overlays&&window.newspackReaderActivation?.overlays.remove(e.overlayId),e.setAttribute("data-state","closed"),document.body.style.overflow="auto"};window.onpageshow=e=>{e.persisted&&(document.querySelectorAll(".modal-processing").forEach((e=>e.classList.remove("modal-processing"))),document.querySelectorAll(".non-modal-checkout-loading").forEach((e=>e.classList.remove("non-modal-checkout-loading"))),document.querySelectorAll(`.${m}-container`).forEach((e=>w(e))))};const y=new CustomEvent("checkout-closed");var k;window.newspackRAS=window.newspackRAS||[],k=()=>{const t=document.querySelector("#newspack_modal_checkout");if(!t)return;const n=t.querySelector(`.${m}__content`),o=a("modal_checkout","1"),k=n.querySelector(`.${l}__spinner`);let f=document.querySelector(".newspack-reader__account-link")?.[0];const v="600px",g=document.createElement("iframe");g.name=d,g.style.height=v,g.style.visibility="hidden";const b=e=>{L.observe(e),"none"!==k.style.display&&(k.style.display="none"),"visible"!==g.style.visibility&&(g.style.visibility="visible"),g._ready=!0};!function(e,t,n){e._ready=!1,e._readyTimer&&clearTimeout(e._readyTimer);let o=!1,c="";function a(){o||(o=!0,clearTimeout(e._readyTimer),t.call(this))}function r(){"complete"===this.readyState&&a.call(this)}function s(){e._ready=!1,n&&n(),e._readyTimer&&clearTimeout(e._readyTimer);const t=e.contentDocument||e.contentWindow?.document;t&&(t.removeEventListener("DOMContentLoaded",a),t.removeEventListener("readystatechange",r))}function i(){if(e._ready)return void s();const t=e.contentDocument||e.contentWindow?.document;t&&0!==t.URL.indexOf("about:")?"complete"===t?.readyState?a.call(t):(t.addEventListener("DOMContentLoaded",a),t.addEventListener("readystatechange",r)):e._readyTimer=setTimeout(i,10)}e._observer||(e._observer=new MutationObserver((e=>{e.forEach((e=>{"attributes"===e.type&&"src"===e.attributeName&&(o=!1,s(),i())}))})),e._observer.observe(e,{attributes:!0})),e._locationObserver||(e._locationObserver=setInterval((function(){const t=e.contentDocument||e.contentWindow?.document;t&&t.URL!==c&&(c=t.URL,o=!1,s(),i())}),50)),i()}(g,(function(){const n=g.contentWindow?.location;if(window.newspackReaderActivation&&n?.href?.includes("order-received")){const e=window.newspackReaderActivation,t=new Proxy(new URLSearchParams(n.search),{get:(e,t)=>e.get(t)});t.email&&(e.setReaderEmail(t.email),e.setAuthenticated(!0))}const o=g?.contentDocument?.querySelector(`#${u}`);if(!o)return;const c=o.querySelector("#modal-checkout-product-details"),a=s(c);o.addEventListener("checkout-cancel",(()=>{R()})),function(e,t){e.checkoutReady?t():e.addEventListener("checkout-ready",t)}(o,(()=>{const e=c?.querySelector("strong");e&&(e.textContent=a.price_summary),B(),C(h),g.contentWindow?.newspackBlocksModalCheckout?.checkout_nonce&&(t.checkout_nonce=g.contentWindow.newspackBlocksModalCheckout.checkout_nonce),b(o)})),function(e,t){e.checkoutComplete?t():e.addEventListener("checkout-complete",t)}(o,(()=>{window.newspackRAS.push(["checkout_completed",a]),window?.newspackReaderActivation?.refreshNewslettersSignupModal&&window?.newspackReaderActivation?.getReader()?.email&&window.newspackReaderActivation.refreshNewslettersSignupModal(window.newspackReaderActivation.getReader().email),B("small"),C(newspackBlocksModal.labels.thankyou_modal_title),b(o),e(t.querySelector(`.${m}`))}))}),(()=>{k.style.display="flex"}));const S=e=>new Promise(((t,n)=>{const o=new URLSearchParams(e);o.append("action","modal_checkout_request"),fetch(newspackBlocksModal.ajax_url+"?"+o.toString()).then((e=>{e.ok||n(e),e.json().then((e=>{t(e.url)})).catch(n)})).catch(n)})),E=()=>"undefined"!=typeof newspack_ras_config&&!newspack_ras_config?.is_logged_in&&!window?.newspackReaderActivation?.getReader?.()?.authenticated&&newspackBlocksModal?.is_registration_required&&window?.newspackReaderActivation?.openAuthModal,A=t=>{const n=!newspackBlocksModal.has_unsupported_payment_gateway;n||t.preventDefault();const o=t.target;o.classList.add("modal-processing");const u=s(o);if(u.newspack_donate){const e=u.donation_frequency,t=[...o.querySelectorAll(`.donation-tier__${e}, .donation-frequency__${e}`)],n=u.donation_tier_index;let c,a;n?(c=t[n],a=u[`donation_value_${e}`]):(c=t[0],u[`donation_value_${e}_untiered`]?a=u[`donation_value_${e}_untiered`]:(a=u[`donation_value_${e}`],"other"===a&&(a=u[`donation_value_${e}_other`])));const r=s(c);for(const e in r)u[e]=r[e];u.amount=a,u.price_summary=u.summary_template.replace("{{PRICE}}",function(e,t="USD"){return parseFloat(e).toLocaleString(document.documentElement.lang,{style:"currency",currency:t,currencyDisplay:"narrowSymbol"})}(u.amount,u.currency))}u&&Object.keys(u).forEach((e=>{0===o.querySelectorAll('input[name="'+e+'"]').length&&o.prepend(a(e,u[e]))})),u.variation_id||(f=t.submitter);const m=document.querySelectorAll(`.${p}`);if(m.forEach((e=>{(E()||n)&&w(e)})),u.is_grouped||u.is_variable&&!u.variation_id){const n=[...m].find((e=>e.dataset.productId===u.product_id));if(n)return n.querySelectorAll(`form[target="${d}"]`).forEach((e=>{["after_success_behavior","after_success_url","after_success_button_label"].forEach((t=>{0===e.querySelectorAll('input[name="'+t+'"]').length&&e.prepend(a(t,u[t]))}));const t=e.dataset.checkout;if(t){const n=JSON.parse(t);Object.keys(n).forEach((t=>{0===e.querySelectorAll('input[name="'+t+'"]').length&&e.prepend(a(t,n[t]))}))}})),t.preventDefault(),o.classList.remove("modal-processing"),M(n),e(n,!1),_||c(u),void document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u))}if(n||E())if(o.classList.remove("modal-processing"),_||c(u),_=!0,E()){t.preventDefault();const e=u.price_summary,o=e?`<div class="order-details-summary ${l}__box ${l}__box--text-center"><p><strong>${e}</strong></p></div>`:"",c=S(u);c.then((e=>{window.newspackReaderActivation?.setPendingCheckout?.(e)})),window.newspackReaderActivation.openAuthModal({title:newspackBlocksModal.labels.auth_modal_title,onSuccess:(e,t)=>{c.then((e=>{t?.registered&&n&&(e+=`&${newspackBlocksModal.checkout_registration_flag}=1`),n?r(q(e)):S(u).then(window.location.href=e)})).catch((e=>{console.warn("Unable to generate cart:",e),R()}))},onError:()=>{R()},onDismiss:()=>{i(u),_=!1,document.getElementById("newspack_modal_checkout").removeAttribute("data-checkout")},skipSuccess:!0,skipNewslettersSignup:!0,labels:{signin:{title:newspackBlocksModal.labels.signin_modal_title},register:{title:newspackBlocksModal.labels.register_modal_title}},content:o,trigger:t.submitter,closeOnSuccess:n})}else $(),document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u));else S(u).then((e=>{window.location.href=e})),(!u.is_variable||u.variation_id)&&o.querySelectorAll("button[type=submit]:focus").forEach((e=>{e.classList.add("non-modal-checkout-loading");const t=e.innerHTML;e.innerHTML="<span>"+t+"</span>"}))},q=e=>{const t=document.createElement("form");t.method="POST",t.action=e,t.target=d,t.style.display="none";const n=document.createElement("button");return n.setAttribute("type","submit"),t.appendChild(n),document.body.appendChild(t),t.addEventListener("submit",A),t},L=new ResizeObserver((e=>{if(!e||!e.length)return;if(!g.contentDocument)return;const o=e[0].contentRect;if(o){const e=.01*Math.max(document.documentElement.clientHeight,window.innerHeight||0)*90-(t.querySelector(`.${m}__header`)?.offsetHeight||0),c=o.top+o.bottom,a=Math.min(c,e);if(0===a)return void(g.style.visibility="hidden");n.style.height=a+"px",g.style.height=a+"px"}})),R=()=>{const e=g?.contentDocument?.querySelector(`#${u}`),o=e?.querySelector('input[name="after_success_url"]'),c=e?.querySelector('input[name="after_success_behavior"]'),a=document?.querySelector(".newspack-newsletters-signup-modal");e?.checkoutComplete||(async()=>{const e=new FormData;newspackBlocksModal.has_unsupported_payment_gateway||e.append("modal_checkout","1"),e.append("action","abandon_modal_checkout"),e.append("_wpnonce",t.checkout_nonce),t.checkout_nonce=null;try{await fetch(newspackBlocksModal.ajax_url,{method:"POST",body:e})}catch(e){console.warn("Unable to empty cart:",e)}})();const r=!(g.contentDocument&&o&&c&&e?.checkoutComplete);if((r||a)&&(k.style.display="flex",g&&n.contains(g)&&(g._ready=!1,g.src="about:blank",g.style.height=v,g.style.visibility="hidden",n.style.height=v,n.removeChild(g)),L&&L.disconnect(),document.querySelectorAll(`.${m}-container`).forEach((e=>w(e))),f&&f.focus(),document.dispatchEvent(y)),e?.checkoutComplete){const e=()=>{if(o&&c){const e=o.getAttribute("value"),t=c.getAttribute("value");"custom"===t?window.location.href=e:"referrer"===t&&window.history.back()}window?.newspackReaderActivation?.setPendingCheckout?.(),_=!1};window?.newspackReaderActivation?.openNewslettersSignupModal?window.newspackReaderActivation.openNewslettersSignupModal({onSuccess:e,onError:e,closeOnSuccess:r}):e(),r&&(h=newspackBlocksModal.labels.checkout_modal_title,B(),C(h))}else window?.newspackReaderActivation?.setPendingCheckout?.(),i(),_=!1,document.getElementById("newspack_modal_checkout").removeAttribute("data-checkout");document.removeEventListener("keydown",D)},$=o=>{o&&(g.src=o),k.style.display="flex",M(t),n.appendChild(g),t.addEventListener("click",(e=>{e.target===t&&R()})),e(t,g),document.addEventListener("keydown",D)},M=e=>{window.newspackReaderActivation?.overlays&&(e.overlayId=window.newspackReaderActivation?.overlays.add()),e.setAttribute("data-state","open"),document.body.style.overflow="hidden"},C=e=>{const n=t.querySelector(`.${m}__header h2`);n&&(n.innerText=e)},B=(e="default")=>{const n=t.querySelector(`.${m}`);n&&("small"===e?n.classList.add(`${m}--small`):n.classList.remove(`${m}--small`))};t.querySelectorAll(`.${m}__close`).forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),R()}))})),document.querySelectorAll(".newspack-blocks__modal-variation").forEach((e=>{e.addEventListener("click",(t=>{t.target===e&&R()})),e.querySelectorAll(`.${m}__close`).forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),R()}))}))}));const D=e=>{"Escape"===e.key&&R()};document.querySelectorAll(".wpbnbd.wpbnbd--platform-wc, .wp-block-newspack-blocks-checkout-button, .newspack-blocks__modal-variation").forEach((e=>{e.querySelectorAll("form").forEach((e=>{newspackBlocksModal.has_unsupported_payment_gateway||e.prepend(o.cloneNode()),e.target=d,e.addEventListener("submit",A)}))})),(()=>{const e=new URLSearchParams(window.location.search);if(!e.has("checkout"))return;const t=e.get("type");if("donate"===t){const t=e.get("layout"),n=e.get("frequency"),o=e.get("amount"),c=e.get("other");t&&n&&o&&((e,t,n,o=null)=>{let c;document.querySelectorAll(".wpbnbd.wpbnbd--platform-wc form").forEach((a=>{const r=a.querySelector(`input[name="donation_frequency"][value="${t}"]`);if(r)if("tiered"===e){const e=document.querySelector(`button[data-frequency-slug="${t}"]`);if(!e)return;e.click();const o=a.querySelector(`button[type="submit"][name="donation_value_${t}"][value="${n}"]`);if(!o)return;o.click()}else{const s="untiered"===e?a.querySelector(`input[name="donation_value_${t}_untiered"]`):a.querySelector(`input[name="donation_value_${t}"][value="${n}"]`);if(r&&s){if(r.checked=!0,"untiered"===e)s.value=n;else if("other"===n){s.click();const e=a.querySelector(`input[name="donation_value_${t}_other"]`);e&&o&&(e.value=o)}else s.checked=!0;c=a}}})),c&&r(c)})(t,n,o,c)}else if("checkout_button"===t){const t=e.get("product_id"),n=e.get("variation_id");t&&((e,t=null)=>{let n;if(t&&t!==e){const o=[...document.querySelectorAll(`.${p}`)].find((t=>t.dataset.productId===e));o&&o.querySelectorAll(`form[target="${d}"]`).forEach((e=>{const o=JSON.parse(e.dataset.checkout);o?.variation_id===Number(t)&&(n=e)}))}else document.querySelectorAll(".wp-block-newspack-blocks-checkout-button").forEach((t=>{const o=t.querySelector("form");if(!o)return;const c=JSON.parse(o.dataset.checkout);c?.product_id===e&&(n=o)}));n&&r(n)})(t,n)}else{const e=window.newspackReaderActivation?.getPendingCheckout?.();e&&r(q(e))}window.history.replaceState(null,null,window.location.pathname)})(),window.newspackOpenModalCheckout=({url:e=null,title:t=null,actionType:n=null,afterSuccess:o={},onCheckoutComplete:c=null,onClose:a=null})=>{if(h=t||newspackBlocksModal.labels.checkout_modal_title,C(h),(e=new URL(e||newspackBlocksModal.checkout_url)).searchParams.has("my_account_checkout")&&e.searchParams.delete("my_account_checkout"),e.searchParams.has("modal_checkout")||e.searchParams.set("modal_checkout","1"),n&&e.searchParams.set("action_type",n),o?.url&&e.searchParams.set("after_success_url",o.url),(o?.behavior||o?.url)&&e.searchParams.set("after_success_behavior",o.behavior||"custom"),o?.buttonLabel&&e.searchParams.set("after_success_button_label",o.buttonLabel),c){const e=({detail:{action:e,data:t}})=>{"checkout_completed"===e&&c(t)};window.newspackRAS.push((t=>{t.on("activity",e);const n=()=>{t.off("activity",e),document.removeEventListener("checkout-closed",n)};document.addEventListener("checkout-closed",n)}))}if(a){const e=()=>{a(),document.removeEventListener("checkout-closed",e)};document.addEventListener("checkout-closed",e)}$(e.toString())},window.newspackCloseModalCheckout=R},"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",k):k())})();
1
+ (()=>{"use strict";function e(e,t=!1){const o=e.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])');if(0===o.length)return!1;const n=o?.[0];let c;n.focus(),t?(document.addEventListener("keydown",(function(e){if(("Tab"===e.key||9===e.keyCode)&&e.shiftKey&&document.activeElement===n){const o=t.contentWindow.document,n=o.getElementById("checkout-after-success");c=null!==n?n:o.getElementById("checkout_cancel"),c.focus(),e.preventDefault()}})),document.getElementById("newspack-a11y-last-element").addEventListener("focus",(()=>{n.focus()}))):(c=o[o.length-1],document.addEventListener("keydown",(function(e){("Tab"===e.key||9===e.keyCode)&&(e.shiftKey?document.activeElement===n&&(c.focus(),e.preventDefault()):document.activeElement===c&&(n.focus(),e.preventDefault()))})))}const t=(e,t={})=>({...t,action:e}),o=["action","action_type","amount","currency","product_id","product_type","variation_id","variation_ids","is_variable","is_grouped","child_ids","price_summary","newspack_popup_id","gate_post_id","recurrence","referrer"],n=(e,t="np_modal_checkout_interaction")=>{if("function"==typeof window.gtag&&e){const n={};for(const t of o)e[t]&&("boolean"==typeof e[t]?e[t]=e[t]?"yes":"no":"true"===e[t]?e[t]="yes":"false"===e[t]&&(e[t]="no"),n[t]=e[t].toString());window.gtag("event",t,n)}},c=e=>{if("function"!=typeof window.gtag)return;let o="opened";const{amount:c="",is_variable:a="",is_grouped:r="",price:s="",variation_id:i=""}=e,l={...e};(c||s)&&(l.amount=c||s),a&&!i&&(o="opened_variations"),r&&(o="opened_grouped");const d=t(o,l);n(d)};function a(e,t=null){const o=document.createElement("input");return o.type="hidden",o.name=e,t&&(o.value=t),o}function r(e){e.requestSubmit(e.querySelector('button[type="submit"]'))}function s(e){const t="string"==typeof e?document.getElementById(e):e;if(!t)return console.warn("No container found for checkout data"),{};let o={};if("FORM"===t.tagName){const e=new FormData(t);o=Object.fromEntries(e)}const n=t.dataset.checkout;if(!n)return console.warn("No checkout data found"),o;try{o={...o,...JSON.parse(n)}}catch(e){console.warn("Error parsing checkout data")}const c=new URL(t.ownerDocument.defaultView.location.href);return c.searchParams.get("action_type")&&(o.action_type=c.searchParams.get("action_type")),o.memberships_content_gate&&(o.gate_post_id=o.memberships_content_gate,delete o.memberships_content_gate),o}const i=e=>{if("function"!=typeof window.gtag)return;e=e||s("newspack_modal_checkout");const o=t("dismissed",e);n(o)},l=newspackBlocksModal.newspack_class_prefix,d="newspack_modal_checkout_iframe",u="newspack_modal_checkout_container",m=`${l}__modal`,p="newspack-blocks__modal-variation";let _=!1,h=newspackBlocksModal.labels.checkout_modal_title;const w=e=>{e.overlayId&&window.newspackReaderActivation?.overlays&&window.newspackReaderActivation?.overlays.remove(e.overlayId),e.setAttribute("data-state","closed"),document.body.style.overflow="auto"};window.onpageshow=e=>{e.persisted&&(document.querySelectorAll(".modal-processing").forEach((e=>e.classList.remove("modal-processing"))),document.querySelectorAll(".non-modal-checkout-loading").forEach((e=>e.classList.remove("non-modal-checkout-loading"))),document.querySelectorAll(`.${m}-container`).forEach((e=>w(e))))};const y=new CustomEvent("checkout-closed");var k;window.newspackRAS=window.newspackRAS||[],k=()=>{const t=document.querySelector("#newspack_modal_checkout");if(!t)return;const o=t.querySelector(`.${m}__content`),n=a("modal_checkout","1"),k=o.querySelector(`.${l}__spinner`);let f=document.querySelector(".newspack-reader__account-link")?.[0];const v="600px",g=document.createElement("iframe");g.name=d,g.style.height=v,g.style.visibility="hidden";const b=e=>{L.observe(e),"none"!==k.style.display&&(k.style.display="none"),"visible"!==g.style.visibility&&(g.style.visibility="visible"),g._ready=!0};!function(e,t,o){e._ready=!1,e._readyTimer&&clearTimeout(e._readyTimer);let n=!1,c="";function a(){n||(n=!0,clearTimeout(e._readyTimer),t.call(this))}function r(){"complete"===this.readyState&&a.call(this)}function s(){e._ready=!1,o&&o(),e._readyTimer&&clearTimeout(e._readyTimer);const t=e.contentDocument||e.contentWindow?.document;t&&(t.removeEventListener("DOMContentLoaded",a),t.removeEventListener("readystatechange",r))}function i(){if(e._ready)return void s();const t=e.contentDocument||e.contentWindow?.document;t&&0!==t.URL.indexOf("about:")?"complete"===t?.readyState?a.call(t):(t.addEventListener("DOMContentLoaded",a),t.addEventListener("readystatechange",r)):e._readyTimer=setTimeout(i,10)}e._observer||(e._observer=new MutationObserver((e=>{e.forEach((e=>{"attributes"===e.type&&"src"===e.attributeName&&(n=!1,s(),i())}))})),e._observer.observe(e,{attributes:!0})),e._locationObserver||(e._locationObserver=setInterval((function(){const t=e.contentDocument||e.contentWindow?.document;t&&t.URL!==c&&(c=t.URL,n=!1,s(),i())}),50)),i()}(g,(function(){const o=g.contentWindow?.location;if(window.newspackReaderActivation&&o?.href?.includes("order-received")){const e=window.newspackReaderActivation,t=new Proxy(new URLSearchParams(o.search),{get:(e,t)=>e.get(t)});t.email&&(e.setReaderEmail(t.email),e.setAuthenticated(!0))}const n=g?.contentDocument?.querySelector(`#${u}`);if(!n)return;const c=n.querySelector("#modal-checkout-product-details"),a=s(c);n.addEventListener("checkout-cancel",(()=>{R()})),function(e,t){e.checkoutReady?t():e.addEventListener("checkout-ready",t)}(n,(()=>{const e=c?.querySelector("strong");e&&(e.textContent=a.price_summary),B(),C(h),g.contentWindow?.newspackBlocksModalCheckout?.checkout_nonce&&(t.checkout_nonce=g.contentWindow.newspackBlocksModalCheckout.checkout_nonce),b(n)})),function(e,t){e.checkoutComplete?t():e.addEventListener("checkout-complete",t)}(n,(()=>{window.newspackRAS.push(["checkout_completed",a]),window?.newspackReaderActivation?.refreshNewslettersSignupModal&&window?.newspackReaderActivation?.getReader()?.email&&window.newspackReaderActivation.refreshNewslettersSignupModal(window.newspackReaderActivation.getReader().email),B("small"),C(newspackBlocksModal.labels.thankyou_modal_title),b(n),e(t.querySelector(`.${m}`))}))}),(()=>{k.style.display="flex"}));const S=e=>new Promise(((t,o)=>{const n=new URLSearchParams(e);n.append("action","modal_checkout_request"),fetch(newspackBlocksModal.ajax_url+"?"+n.toString()).then((e=>{e.ok||o(e),e.json().then((e=>{t(e.url)})).catch(o)})).catch(o)})),E=()=>"undefined"!=typeof newspack_ras_config&&!newspack_ras_config?.is_logged_in&&!window?.newspackReaderActivation?.getReader?.()?.authenticated&&newspackBlocksModal?.is_registration_required&&window?.newspackReaderActivation?.openAuthModal,A=t=>{const o=!newspackBlocksModal.has_unsupported_payment_gateway;o||t.preventDefault();const n=t.target;n.classList.add("modal-processing");const u=s(n);if(u.newspack_donate){const e=u.donation_frequency,t=[...n.querySelectorAll(`.donation-tier__${e}, .donation-frequency__${e}`)],o=u.donation_tier_index;let c,a;o?(c=t[o],a=u[`donation_value_${e}`]):(c=t[0],u[`donation_value_${e}_untiered`]?a=u[`donation_value_${e}_untiered`]:(a=u[`donation_value_${e}`],"other"===a&&(a=u[`donation_value_${e}_other`])));const r=s(c);for(const e in r)u[e]=r[e];u.amount=a,u.price_summary=u.summary_template.replace("{{PRICE}}",function(e,t="USD"){return parseFloat(e).toLocaleString(document.documentElement.lang,{style:"currency",currency:t,currencyDisplay:"narrowSymbol"})}(u.amount,u.currency))}u&&Object.keys(u).forEach((e=>{0===n.querySelectorAll('input[name="'+e+'"]').length&&n.prepend(a(e,u[e]))})),u.variation_id||(f=t.submitter);const m=document.querySelectorAll(`.${p}`);if(m.forEach((e=>{(E()||o)&&w(e)})),u.is_grouped||u.is_variable&&!u.variation_id){const o=[...m].find((e=>e.dataset.productId===u.product_id));if(o)return o.querySelectorAll(`form[target="${d}"]`).forEach((e=>{["after_success_behavior","after_success_url","after_success_button_label"].forEach((t=>{0===e.querySelectorAll('input[name="'+t+'"]').length&&e.prepend(a(t,u[t]))}));const t=e.dataset.checkout;if(t){const o=JSON.parse(t);Object.keys(o).forEach((t=>{0===e.querySelectorAll('input[name="'+t+'"]').length&&e.prepend(a(t,o[t]))}))}})),t.preventDefault(),n.classList.remove("modal-processing"),M(o),e(o,!1),_||c(u),void document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u))}if(o||E())if(n.classList.remove("modal-processing"),_||c(u),_=!0,E()){t.preventDefault();const e=u.price_summary,n=e?`<div class="order-details-summary ${l}__box ${l}__box--text-center"><p><strong>${e}</strong></p></div>`:"",c=S(u);c.then((e=>{window.newspackReaderActivation?.setPendingCheckout?.(e)})),window.newspackReaderActivation.openAuthModal({title:newspackBlocksModal.labels.auth_modal_title,onSuccess:(e,t)=>{c.then((e=>{t?.registered&&o&&(e+=`&${newspackBlocksModal.checkout_registration_flag}=1`),o?r(q(e)):S(u).then(window.location.href=e)})).catch((e=>{console.warn("Unable to generate cart:",e),R()}))},onError:()=>{R()},onDismiss:()=>{i(u),_=!1,document.getElementById("newspack_modal_checkout").removeAttribute("data-checkout")},skipSuccess:!0,skipNewslettersSignup:!0,labels:{signin:{title:newspackBlocksModal.labels.signin_modal_title},register:{title:newspackBlocksModal.labels.register_modal_title}},content:n,trigger:t.submitter,closeOnSuccess:o})}else $(),document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u));else S(u).then((e=>{window.location.href=e})),(!u.is_variable||u.variation_id)&&n.querySelectorAll("button[type=submit]:focus").forEach((e=>{e.classList.add("non-modal-checkout-loading");const t=e.innerHTML;e.innerHTML="<span>"+t+"</span>"}))},q=e=>{const t=document.createElement("form");t.method="POST",t.action=e,t.target=d,t.style.display="none";const o=document.createElement("button");return o.setAttribute("type","submit"),t.appendChild(o),document.body.appendChild(t),t.addEventListener("submit",A),t},L=new ResizeObserver((e=>{if(!e||!e.length)return;if(!g.contentDocument)return;const n=e[0].contentRect;if(n){const e=.01*Math.max(document.documentElement.clientHeight,window.innerHeight||0)*90-(t.querySelector(`.${m}__header`)?.offsetHeight||0),c=n.top+n.bottom,a=Math.min(c,e);if(0===a)return void(g.style.visibility="hidden");o.style.height=a+"px",g.style.height=a+"px"}})),R=()=>{const e=g?.contentDocument?.querySelector(`#${u}`),n=e?.querySelector('input[name="after_success_url"]'),c=e?.querySelector('input[name="after_success_behavior"]'),a=document?.querySelector(".newspack-newsletters-signup-modal"),r=s(e?.querySelector("#modal-checkout-product-details"));e?.checkoutComplete||(async()=>{const e=new FormData;newspackBlocksModal.has_unsupported_payment_gateway||e.append("modal_checkout","1"),e.append("action","abandon_modal_checkout"),e.append("_wpnonce",t.checkout_nonce),t.checkout_nonce=null;try{await fetch(newspackBlocksModal.ajax_url,{method:"POST",body:e})}catch(e){console.warn("Unable to empty cart:",e)}})();const l=!(g.contentDocument&&n&&c&&e?.checkoutComplete);if((l||a)&&(k.style.display="flex",g&&o.contains(g)&&(g._ready=!1,g.src="about:blank",g.style.height=v,g.style.visibility="hidden",o.style.height=v,o.removeChild(g)),L&&L.disconnect(),document.querySelectorAll(`.${m}-container`).forEach((e=>w(e))),f&&f.focus(),document.dispatchEvent(y)),e?.checkoutComplete){const e=()=>{if(n&&c){const e=n.getAttribute("value"),t=c.getAttribute("value");"custom"===t?window.location.href=e:"referrer"===t&&window.history.back()}window?.newspackReaderActivation?.setPendingCheckout?.(),_=!1};"subscription_switch"!==r.action_type&&window?.newspackReaderActivation?.openNewslettersSignupModal?window.newspackReaderActivation.openNewslettersSignupModal({onSuccess:e,onError:e,closeOnSuccess:l}):e(),l&&(h=newspackBlocksModal.labels.checkout_modal_title,B(),C(h))}else window?.newspackReaderActivation?.setPendingCheckout?.(),i(),_=!1,document.getElementById("newspack_modal_checkout").removeAttribute("data-checkout");document.removeEventListener("keydown",D)},$=n=>{n&&(g.src=n),k.style.display="flex",M(t),o.appendChild(g),t.addEventListener("click",(e=>{e.target===t&&R()})),e(t,g),document.addEventListener("keydown",D)},M=e=>{window.newspackReaderActivation?.overlays&&(e.overlayId=window.newspackReaderActivation?.overlays.add()),e.setAttribute("data-state","open"),document.body.style.overflow="hidden"},C=e=>{const o=t.querySelector(`.${m}__header h2`);o&&(o.innerText=e)},B=(e="default")=>{const o=t.querySelector(`.${m}`);o&&("small"===e?o.classList.add(`${m}--small`):o.classList.remove(`${m}--small`))};t.querySelectorAll(`.${m}__close`).forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),R()}))})),document.querySelectorAll(".newspack-blocks__modal-variation").forEach((e=>{e.addEventListener("click",(t=>{t.target===e&&R()})),e.querySelectorAll(`.${m}__close`).forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),R()}))}))}));const D=e=>{"Escape"===e.key&&R()};document.querySelectorAll(".wpbnbd.wpbnbd--platform-wc, .wp-block-newspack-blocks-checkout-button, .newspack-blocks__modal-variation").forEach((e=>{e.querySelectorAll("form").forEach((e=>{newspackBlocksModal.has_unsupported_payment_gateway||e.prepend(n.cloneNode()),e.target=d,e.addEventListener("submit",A)}))})),(()=>{const e=new URLSearchParams(window.location.search);if(!e.has("checkout"))return;const t=e.get("type");if("donate"===t){const t=e.get("layout"),o=e.get("frequency"),n=e.get("amount"),c=e.get("other");t&&o&&n&&((e,t,o,n=null)=>{let c;document.querySelectorAll(".wpbnbd.wpbnbd--platform-wc form").forEach((a=>{const r=a.querySelector(`input[name="donation_frequency"][value="${t}"]`);if(r)if("tiered"===e){const e=document.querySelector(`button[data-frequency-slug="${t}"]`);if(!e)return;e.click();const n=a.querySelector(`button[type="submit"][name="donation_value_${t}"][value="${o}"]`);if(!n)return;n.click()}else{const s="untiered"===e?a.querySelector(`input[name="donation_value_${t}_untiered"]`):a.querySelector(`input[name="donation_value_${t}"][value="${o}"]`);if(r&&s){if(r.checked=!0,"untiered"===e)s.value=o;else if("other"===o){s.click();const e=a.querySelector(`input[name="donation_value_${t}_other"]`);e&&n&&(e.value=n)}else s.checked=!0;c=a}}})),c&&r(c)})(t,o,n,c)}else if("checkout_button"===t){const t=e.get("product_id"),o=e.get("variation_id");t&&((e,t=null)=>{let o;if(t&&t!==e){const n=[...document.querySelectorAll(`.${p}`)].find((t=>t.dataset.productId===e));n&&n.querySelectorAll(`form[target="${d}"]`).forEach((e=>{const n=JSON.parse(e.dataset.checkout);n?.variation_id===Number(t)&&(o=e)}))}else document.querySelectorAll(".wp-block-newspack-blocks-checkout-button").forEach((t=>{const n=t.querySelector("form");if(!n)return;const c=JSON.parse(n.dataset.checkout);c?.product_id===e&&(o=n)}));o&&r(o)})(t,o)}else{const e=window.newspackReaderActivation?.getPendingCheckout?.();e&&r(q(e))}window.history.replaceState(null,null,window.location.pathname)})(),window.newspackOpenModalCheckout=({url:e=null,title:t=null,actionType:o=null,afterSuccess:n={},onCheckoutComplete:c=null,onClose:a=null})=>{if(h=t||newspackBlocksModal.labels.checkout_modal_title,C(h),(e=new URL(e||newspackBlocksModal.checkout_url)).searchParams.has("my_account_checkout")&&e.searchParams.delete("my_account_checkout"),e.searchParams.has("modal_checkout")||e.searchParams.set("modal_checkout","1"),o&&e.searchParams.set("action_type",o),n?.url&&e.searchParams.set("after_success_url",n.url),(n?.behavior||n?.url)&&e.searchParams.set("after_success_behavior",n.behavior||"custom"),n?.buttonLabel&&e.searchParams.set("after_success_button_label",n.buttonLabel),c){const e=({detail:{action:e,data:t}})=>{"checkout_completed"===e&&c(t)};window.newspackRAS.push((t=>{t.on("activity",e);const o=()=>{t.off("activity",e),document.removeEventListener("checkout-closed",o)};document.addEventListener("checkout-closed",o)}))}if(a){const e=()=>{a(),document.removeEventListener("checkout-closed",e)};document.addEventListener("checkout-closed",e)}$(e.toString())},window.newspackCloseModalCheckout=R},"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",k):k())})();
@@ -1294,7 +1294,7 @@ final class Modal_Checkout {
1294
1294
  if (
1295
1295
  1 === count( array_values( $cart_items ) ) &&
1296
1296
  method_exists( 'WCS_Gifting', 'email_belongs_to_current_user' ) &&
1297
- method_exists( 'WCS_Gifting', 'update_cart_item_key' ) &&
1297
+ method_exists( 'WCS_Gifting', 'update_cart_item_recipient' ) &&
1298
1298
  method_exists( 'WCSG_Cart', 'is_giftable_item' )
1299
1299
  ) {
1300
1300
  $is_gift = ! empty( filter_input( INPUT_POST, 'newspack_wcsg_is_gift', FILTER_SANITIZE_SPECIAL_CHARS ) );
@@ -1307,7 +1307,7 @@ final class Modal_Checkout {
1307
1307
 
1308
1308
  // If no errors, attach the recipient's email address to the subscription item.
1309
1309
  if ( $is_valid_email ) {
1310
- \WCS_Gifting::update_cart_item_key( $cart_item, $cart_item_key, $recipient_email );
1310
+ \WCS_Gifting::update_cart_item_recipient( $cart_item, $cart_item_key, $recipient_email );
1311
1311
  } else {
1312
1312
  $notice = $self_gifting
1313
1313
  ? __( 'Please enter someone else\' email address to receive this gift.', 'newspack-blocks' )
@@ -145,23 +145,33 @@ final class Checkout_Data {
145
145
  /**
146
146
  * Returns the action type: checkout_button or donation.
147
147
  *
148
- * @param string $product_id Product's ID.
148
+ * @param string $product_id Product's ID.
149
+ * @param \WC_Order $order Optional order to check if it's a subscription switch.
149
150
  */
150
- public static function get_action_type( $product_id ) {
151
+ public static function get_action_type( $product_id, $order = null ) {
151
152
  $action_type = 'checkout_button';
153
+
152
154
  // Check if it's a donation product, and update action_type, product_type.
153
155
  if ( method_exists( 'Newspack\Donations', 'is_donation_product' ) ) {
154
156
  if ( \Newspack\Donations::is_donation_product( $product_id ) ) {
155
157
  $action_type = 'donation';
156
158
  }
157
159
  }
160
+
158
161
  // Check if it's a subscription switch.
159
- if ( method_exists( 'WC_Subscriptions_Switcher', 'cart_contains_switches' ) && \WC_Subscriptions_Switcher::cart_contains_switches( 'any' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
162
+ if ( $order ) {
163
+ if ( function_exists( 'wcs_order_contains_switch' ) && wcs_order_contains_switch( $order ) ) {
164
+ $action_type = 'subscription_switch';
165
+ }
166
+ } elseif ( method_exists( 'WC_Subscriptions_Switcher', 'cart_contains_switches' ) && \WC_Subscriptions_Switcher::cart_contains_switches( 'any' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
160
167
  $action_type = 'subscription_switch';
161
168
  }
169
+
170
+ // Check if the action type is set in the URL.
162
171
  if ( isset( $_GET['action_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
163
172
  $action_type = sanitize_text_field( wp_unslash( $_GET['action_type'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
164
173
  }
174
+
165
175
  return $action_type;
166
176
  }
167
177
 
@@ -298,7 +308,7 @@ final class Checkout_Data {
298
308
  }
299
309
 
300
310
  $data = [
301
- 'action_type' => self::get_action_type( $product_id ),
311
+ 'action_type' => self::get_action_type( $product_id, $order ),
302
312
  'currency' => function_exists( 'get_woocommerce_currency' ) ? \get_woocommerce_currency() : 'USD',
303
313
  'product_id' => strval( $product_id ? $product_id : '' ),
304
314
  'product_type' => $product_type,
@@ -7,7 +7,7 @@
7
7
  * Author URI: https://newspack.com/
8
8
  * Text Domain: newspack-blocks
9
9
  * Domain Path: /languages
10
- * Version: 4.17.0-alpha.1
10
+ * Version: 4.17.0
11
11
  *
12
12
  * @package Newspack_Blocks
13
13
  */
@@ -15,7 +15,7 @@
15
15
  define( 'NEWSPACK_BLOCKS__PLUGIN_FILE', __FILE__ );
16
16
  define( 'NEWSPACK_BLOCKS__BLOCKS_DIRECTORY', 'dist/' );
17
17
  define( 'NEWSPACK_BLOCKS__PLUGIN_DIR', plugin_dir_path( NEWSPACK_BLOCKS__PLUGIN_FILE ) );
18
- define( 'NEWSPACK_BLOCKS__VERSION', '4.17.0-alpha.1' );
18
+ define( 'NEWSPACK_BLOCKS__VERSION', '4.17.0' );
19
19
 
20
20
  require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks.php';
21
21
  require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks-api.php';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/newspack-blocks",
3
- "version": "4.17.0-alpha.1",
3
+ "version": "4.17.0",
4
4
  "author": "Automattic",
5
5
  "devDependencies": {
6
6
  "@rushstack/eslint-patch": "^1.12.0",
@@ -498,6 +498,8 @@ domReady( () => {
498
498
  );
499
499
  const hasNewsletterPopup = document?.querySelector( '.newspack-newsletters-signup-modal' );
500
500
 
501
+ const checkoutData = getCheckoutData( container?.querySelector( '#modal-checkout-product-details' ) );
502
+
501
503
  // Empty cart if checkout is not complete.
502
504
  if ( ! container?.checkoutComplete ) {
503
505
  emptyCart();
@@ -546,7 +548,7 @@ domReady( () => {
546
548
  inCheckoutIntent = false;
547
549
  };
548
550
 
549
- if ( window?.newspackReaderActivation?.openNewslettersSignupModal ) {
551
+ if ( checkoutData.action_type !== 'subscription_switch' && window?.newspackReaderActivation?.openNewslettersSignupModal ) {
550
552
  window.newspackReaderActivation.openNewslettersSignupModal( {
551
553
  onSuccess: handleCheckoutComplete,
552
554
  onError: handleCheckoutComplete,
@@ -3,7 +3,7 @@
3
3
  'name' => 'automattic/newspack-blocks',
4
4
  'pretty_version' => 'dev-trunk',
5
5
  'version' => 'dev-trunk',
6
- 'reference' => '203c08a3372bf750a13bf4ec1fcf932be795ede6',
6
+ 'reference' => '4dbe8b35a7331849d7a5b33ac75b1e862a4ff1b3',
7
7
  'type' => 'wordpress-plugin',
8
8
  'install_path' => __DIR__ . '/../../',
9
9
  'aliases' => array(),
@@ -13,7 +13,7 @@
13
13
  'automattic/newspack-blocks' => array(
14
14
  'pretty_version' => 'dev-trunk',
15
15
  'version' => 'dev-trunk',
16
- 'reference' => '203c08a3372bf750a13bf4ec1fcf932be795ede6',
16
+ 'reference' => '4dbe8b35a7331849d7a5b33ac75b1e862a4ff1b3',
17
17
  'type' => 'wordpress-plugin',
18
18
  'install_path' => __DIR__ . '/../../',
19
19
  'aliases' => array(),