@automattic/newspack-blocks 4.26.4 → 4.26.5-epic-editor-refactor.1
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/.prettierrc.js +1 -1
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +14 -0
- package/composer.json +3 -16
- package/dist/carousel/view-rtl.css +1 -1
- package/dist/carousel/view.asset.php +1 -1
- package/dist/carousel/view.css +1 -1
- package/dist/carousel/view.js +1 -1
- package/dist/editor-rtl.css +4 -4
- package/dist/editor.asset.php +1 -1
- package/dist/editor.css +4 -4
- package/dist/editor.js +11 -11
- package/dist/modal.asset.php +1 -1
- package/dist/modal.js +1 -1
- package/includes/class-modal-checkout.php +1 -2
- package/includes/modal-checkout/class-checkout-data.php +1 -1
- package/languages/newspack-blocks-de_DE.po +1 -1
- package/languages/newspack-blocks-es_ES.po +1 -1
- package/languages/newspack-blocks-fr_BE.po +1 -1
- package/languages/newspack-blocks-nb_NO.po +1 -1
- package/languages/newspack-blocks-pt_PT.po +1 -1
- package/languages/newspack-blocks.pot +2 -2
- package/newspack-blocks.php +2 -2
- package/package.json +4 -4
- package/src/blocks/checkout-button/view.php +6 -1
- package/src/components/query-controls.js +8 -9
- package/src/modal-checkout/checkout-button-trigger.js +190 -0
- package/src/modal-checkout/checkout-button-trigger.test.js +266 -0
- package/src/modal-checkout/modal.js +37 -36
- package/vendor/composer/installed.php +2 -2
- package/phpcs.xml +0 -38
package/dist/modal.asset.php
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<?php return array('dependencies' => array(), 'version' => '
|
|
1
|
+
<?php return array('dependencies' => array(), 'version' => 'a7965e06cb0f7958a0ba');
|
package/dist/modal.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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","prompt_title","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}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",p=`${l}__modal`,m="newspack-blocks__modal-variation",_=`${l}__processing-payment-text`,h=newspackBlocksModal.processing_payment_messages;let y=!1,k=newspackBlocksModal.labels.checkout_modal_title,w=null;const f=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(`.${p}-container`).forEach(e=>f(e)))};const v=new CustomEvent("checkout-closed");var g;window.newspackRAS=window.newspackRAS||[],g=()=>{const t=document.querySelector("#newspack_modal_checkout");if(!t)return;const o=t.querySelector(`.${p}__content`),n=a("modal_checkout","1"),g=o.querySelector(`.${l}__spinner`);let b=document.querySelector(".newspack-reader__account-link")?.[0];const S="600px",E=document.createElement("iframe");E.name=d,E.style.height=S,E.style.visibility="hidden";const A=e=>{M.observe(e),"none"!==g.style.display&&(g.style.display="none"),"visible"!==E.style.visibility&&(E.style.visibility="visible"),E._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()}(E,function(){const o=E.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=E?.contentDocument?.querySelector(`#${u}`);if(!n)return;const c=n.querySelector("#modal-checkout-product-details"),a=s(c),r=document.createElement("p");r.classList.add(_);let i=[];const l=()=>{i.forEach(e=>clearTimeout(e)),i=[]},d=()=>{g.style.display="none",l(),g.querySelectorAll(`.${_}`).forEach(e=>e.remove())};!function(e,t){e.checkoutCancel?t():e.addEventListener("checkout-cancel",t)}(n,()=>{C()}),function(e,t){e.checkoutPlaceOrderStart?t():e.addEventListener("checkout-place-order-start",t)}(n,e=>{g.querySelectorAll(`.${_}`).forEach(e=>e.remove()),g.style.display="flex",l(),r.textContent=h[0]?.text??"",h.slice(1).forEach(({text:t,delay:o})=>{const n=setTimeout(()=>{e.target.dispatchEvent(new CustomEvent("checkout-place-order-processing")),r.textContent=t},o);i.push(n)}),g.appendChild(r)}),function(e,t){e.checkoutPlaceOrderError?t():e.addEventListener("checkout-place-order-error",t)}(n,d),function(e,t){e.checkoutReady?t():e.addEventListener("checkout-ready",t)}(n,()=>{const e=c?.querySelector("strong");if(e&&(e.textContent=a.price_summary),t.initialErrors){const e=document.createElement("div");e.classList.add("woocommerce-error"),e.textContent=t.initialErrors,n.prepend(e),delete t.initialErrors}P(),O(k),E.contentWindow?.newspackBlocksModalCheckout?.checkout_nonce&&(t.checkout_nonce=E.contentWindow.newspackBlocksModalCheckout.checkout_nonce),A(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),P("small"),O(newspackBlocksModal.labels.thankyou_modal_title),A(n),e(t.querySelector(`.${p}`)),d()}),function(e,t){e.checkoutPlaceOrderCriticalError?t():e.addEventListener("checkout-place-order-critical-error",t)}(n,()=>{var e;(e=w)&&(C(),g.style.display="none",t.initialErrors=newspackBlocksModal.labels.critical_error,e.requestSubmit(e.querySelector('button[type="submit"]')),d())})},()=>{g.style.display="flex"});const q=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)}),L=()=>"undefined"!=typeof newspack_ras_config&&!newspack_ras_config?.is_logged_in&&!window?.newspackReaderActivation?.getReader?.()?.authenticated&&newspackBlocksModal?.is_registration_required&&window?.newspackReaderActivation?.openAuthModal,$=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||(b=t.submitter);const p=document.querySelectorAll(`.${m}`);if(p.forEach(e=>{(L()||o)&&f(e)}),u.is_grouped||u.is_variable&&!u.variation_id){const o=[...p].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","gate_post_id","newspack_popup_id","prompt_title"].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"),B(o),e(o,!1),y||c(u),void document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u))}if(o||L()){if(n.classList.remove("modal-processing"),y||c(u),y=!0,L()){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=q(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(R(e)):q(u).then(window.location.href=e)}).catch(e=>{console.warn("Unable to generate cart:",e),C()})},onError:()=>{C()},onDismiss:()=>{i(u),y=!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 x(),document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u));w=n}else q(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>"})},R=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",$),t},M=new ResizeObserver(e=>{if(!e||!e.length)return;if(!E.contentDocument)return;const n=e[0].contentRect;if(n){const e=.01*Math.max(document.documentElement.clientHeight,window.innerHeight||0)*90-(t.querySelector(`.${p}__header`)?.offsetHeight||0),c=n.top+n.bottom,a=Math.min(c,e);if(0===a)return void(E.style.visibility="hidden");o.style.height=a+"px",E.style.height=a+"px"}}),C=()=>{const e=E?.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=!(E.contentDocument&&n&&c&&e?.checkoutComplete);if((l||a)&&(g.style.display="flex",E&&o.contains(E)&&(E._ready=!1,E.src="about:blank",E.style.height=S,E.style.visibility="hidden",o.style.height=S,o.removeChild(E)),M&&M.disconnect(),document.querySelectorAll(`.${p}-container`).forEach(e=>f(e)),b&&b.focus(),document.dispatchEvent(v)),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?.(),y=!1};"subscription_switch"!==r.action_type&&window?.newspackReaderActivation?.openNewslettersSignupModal?window.newspackReaderActivation.openNewslettersSignupModal({onSuccess:e,onError:e,closeOnSuccess:l}):e(),l&&(k=newspackBlocksModal.labels.checkout_modal_title,P(),O(k))}else window?.newspackReaderActivation?.setPendingCheckout?.(),i(),y=!1,document.getElementById("newspack_modal_checkout").removeAttribute("data-checkout");document.removeEventListener("keydown",D)},x=n=>{n&&(E.src=n),g.style.display="flex",B(t),o.appendChild(E),t.addEventListener("click",e=>{e.target===t&&C()}),e(t,E),document.addEventListener("keydown",D)},B=e=>{window.newspackReaderActivation?.overlays&&(e.overlayId=window.newspackReaderActivation?.overlays.add()),e.setAttribute("data-state","open"),document.body.style.overflow="hidden"},O=e=>{const o=t.querySelector(`.${p}__header h2`);o&&(o.innerText=e)},P=(e="default")=>{const o=t.querySelector(`.${p}`);o&&("small"===e?o.classList.add(`${p}--small`):o.classList.remove(`${p}--small`))};t.querySelectorAll(`.${p}__close`).forEach(e=>{e.addEventListener("click",e=>{e.preventDefault(),C()})}),document.querySelectorAll(".newspack-blocks__modal-variation").forEach(e=>{e.addEventListener("click",t=>{t.target===e&&C()}),e.querySelectorAll(`.${p}__close`).forEach(e=>{e.addEventListener("click",e=>{e.preventDefault(),C()})})});const D=e=>{"Escape"===e.key&&C()};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",$)})}),(()=>{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(`.${m}`)].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(R(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(k=t||newspackBlocksModal.labels.checkout_modal_title,O(k),(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)}x(e.toString())},window.newspackCloseModalCheckout=C},"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",g):g())})();
|
|
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","prompt_title","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:i="",variation_id:s=""}=e,l={...e};(c||i)&&(l.amount=c||i),a&&!s&&(n="opened_variations"),r&&(n="opened_grouped");const u=t(n,l);o(u)};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 i(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}const s=e=>{if("function"!=typeof window.gtag)return;e=e||i("newspack_modal_checkout");const n=t("dismissed",e);o(n)};function l(e){const t=e&&e.dataset?e.dataset.checkout:null;if(!t)return null;try{return JSON.parse(t)}catch(e){return null}}function u(e,t,n=null){const o=e.querySelectorAll(".wp-block-newspack-blocks-checkout-button"),c=null!=n&&""!==String(n);let a=null;return o.forEach(e=>{if(a)return;const o=e.querySelector("form"),r=l(o);r&&String(r.product_id)===String(t)&&(c&&String(r.variation_id)!==String(n)||(a=o))}),a}const d=["after_success_behavior","after_success_url","after_success_button_label","gate_post_id","newspack_popup_id","prompt_title"];const p=newspackBlocksModal.newspack_class_prefix,m="newspack_modal_checkout_iframe",_="newspack_modal_checkout_container",h=`${p}__modal`,k="newspack-blocks__modal-variation",y=`${p}__processing-payment-text`,w=newspackBlocksModal.processing_payment_messages;let f=!1,v=newspackBlocksModal.labels.checkout_modal_title,g=null;const b=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(`.${h}-container`).forEach(e=>b(e)))};const S=new CustomEvent("checkout-closed");var E;window.newspackRAS=window.newspackRAS||[],E=()=>{const t=document.querySelector("#newspack_modal_checkout");if(!t)return;const n=t.querySelector(`.${h}__content`),o=a("modal_checkout","1"),E=n.querySelector(`.${p}__spinner`);let A=document.querySelector(".newspack-reader__account-link")?.[0];const q="600px",L=document.createElement("iframe");L.name=m,L.style.height=q,L.style.visibility="hidden";const $=e=>{B.observe(e),"none"!==E.style.display&&(E.style.display="none"),"visible"!==L.style.visibility&&(L.style.visibility="visible"),L._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 i(){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 s(){if(e._ready)return void i();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(s,10)}e._observer||(e._observer=new MutationObserver(e=>{e.forEach(e=>{"attributes"===e.type&&"src"===e.attributeName&&(o=!1,i(),s())})}),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,i(),s())},50)),s()}(L,function(){const n=L.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=L?.contentDocument?.querySelector(`#${_}`);if(!o)return;const c=o.querySelector("#modal-checkout-product-details"),a=i(c),r=document.createElement("p");r.classList.add(y);let s=[];const l=()=>{s.forEach(e=>clearTimeout(e)),s=[]},u=()=>{E.style.display="none",l(),E.querySelectorAll(`.${y}`).forEach(e=>e.remove())};!function(e,t){e.checkoutCancel?t():e.addEventListener("checkout-cancel",t)}(o,()=>{P()}),function(e,t){e.checkoutPlaceOrderStart?t():e.addEventListener("checkout-place-order-start",t)}(o,e=>{E.querySelectorAll(`.${y}`).forEach(e=>e.remove()),E.style.display="flex",l(),r.textContent=w[0]?.text??"",w.slice(1).forEach(({text:t,delay:n})=>{const o=setTimeout(()=>{e.target.dispatchEvent(new CustomEvent("checkout-place-order-processing")),r.textContent=t},n);s.push(o)}),E.appendChild(r)}),function(e,t){e.checkoutPlaceOrderError?t():e.addEventListener("checkout-place-order-error",t)}(o,u),function(e,t){e.checkoutReady?t():e.addEventListener("checkout-ready",t)}(o,()=>{const e=c?.querySelector("strong");if(e&&(e.textContent=a.price_summary),t.initialErrors){const e=document.createElement("div");e.classList.add("woocommerce-error"),e.textContent=t.initialErrors,o.prepend(e),delete t.initialErrors}N(),T(v),L.contentWindow?.newspackBlocksModalCheckout?.checkout_nonce&&(t.checkout_nonce=L.contentWindow.newspackBlocksModalCheckout.checkout_nonce),$(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),N("small"),T(newspackBlocksModal.labels.thankyou_modal_title),$(o),e(t.querySelector(`.${h}`)),u()}),function(e,t){e.checkoutPlaceOrderCriticalError?t():e.addEventListener("checkout-place-order-critical-error",t)}(o,()=>{var e;(e=g)&&(P(),E.style.display="none",t.initialErrors=newspackBlocksModal.labels.critical_error,e.requestSubmit(e.querySelector('button[type="submit"]')),u())})},()=>{E.style.display="flex"});const R=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)}),M=()=>"undefined"!=typeof newspack_ras_config&&!newspack_ras_config?.is_logged_in&&!window?.newspackReaderActivation?.getReader?.()?.authenticated&&newspackBlocksModal?.is_registration_required&&window?.newspackReaderActivation?.openAuthModal,C=t=>{const n=!newspackBlocksModal.has_unsupported_payment_gateway;n||t.preventDefault();const o=t.target;o.classList.add("modal-processing");const u=i(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=i(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||(A=t.submitter);const d=document.querySelectorAll(`.${k}`);if(d.forEach(e=>{(M()||n)&&b(e)}),u.is_grouped||u.is_variable&&!u.variation_id){const n=[...d].find(e=>e.dataset.productId===u.product_id);if(n)return n.querySelectorAll(`form[target="${m}"]`).forEach(e=>{["after_success_behavior","after_success_url","after_success_button_label","gate_post_id","newspack_popup_id","prompt_title"].forEach(t=>{0===e.querySelectorAll('input[name="'+t+'"]').length&&e.prepend(a(t,u[t]))});const t=l(e);t&&Object.keys(t).forEach(n=>{0===e.querySelectorAll('input[name="'+n+'"]').length&&e.prepend(a(n,t[n]))})}),t.preventDefault(),o.classList.remove("modal-processing"),O(n),e(n,!1),f||c(u),void document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u))}if(n||M()){if(o.classList.remove("modal-processing"),f||c(u),f=!0,M()){t.preventDefault();const e=u.price_summary,o=e?`<div class="order-details-summary ${p}__box ${p}__box--text-center"><p><strong>${e}</strong></p></div>`:"",c=R(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(x(e)):R(u).then(window.location.href=e)}).catch(e=>{console.warn("Unable to generate cart:",e),P()})},onError:()=>{P()},onDismiss:()=>{s(u),f=!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 D(),document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u));g=o}else R(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>"})},x=e=>{const t=document.createElement("form");t.method="POST",t.action=e,t.target=m,t.style.display="none";const n=document.createElement("button");return n.setAttribute("type","submit"),t.appendChild(n),document.body.appendChild(t),t.addEventListener("submit",C),t},B=new ResizeObserver(e=>{if(!e||!e.length)return;if(!L.contentDocument)return;const o=e[0].contentRect;if(o){const e=.01*Math.max(document.documentElement.clientHeight,window.innerHeight||0)*90-(t.querySelector(`.${h}__header`)?.offsetHeight||0),c=o.top+o.bottom,a=Math.min(c,e);if(0===a)return void(L.style.visibility="hidden");n.style.height=a+"px",L.style.height=a+"px"}}),P=()=>{const e=L?.contentDocument?.querySelector(`#${_}`),o=e?.querySelector('input[name="after_success_url"]'),c=e?.querySelector('input[name="after_success_behavior"]'),a=document?.querySelector(".newspack-newsletters-signup-modal"),r=i(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=!(L.contentDocument&&o&&c&&e?.checkoutComplete);if((l||a)&&(E.style.display="flex",L&&n.contains(L)&&(L._ready=!1,L.src="about:blank",L.style.height=q,L.style.visibility="hidden",n.style.height=q,n.removeChild(L)),B&&B.disconnect(),document.querySelectorAll(`.${h}-container`).forEach(e=>b(e)),A&&A.focus(),document.dispatchEvent(S)),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?.(),f=!1};"subscription_switch"!==r.action_type&&window?.newspackReaderActivation?.openNewslettersSignupModal?window.newspackReaderActivation.openNewslettersSignupModal({onSuccess:e,onError:e,closeOnSuccess:l}):e(),l&&(v=newspackBlocksModal.labels.checkout_modal_title,N(),T(v))}else window?.newspackReaderActivation?.setPendingCheckout?.(),s(),f=!1,document.getElementById("newspack_modal_checkout").removeAttribute("data-checkout");document.removeEventListener("keydown",I)},D=o=>{o&&(L.src=o),E.style.display="flex",O(t),n.appendChild(L),t.addEventListener("click",e=>{e.target===t&&P()}),e(t,L),document.addEventListener("keydown",I)},O=e=>{window.newspackReaderActivation?.overlays&&(e.overlayId=window.newspackReaderActivation?.overlays.add()),e.setAttribute("data-state","open"),document.body.style.overflow="hidden"},T=e=>{const n=t.querySelector(`.${h}__header h2`);n&&(n.innerText=e)},N=(e="default")=>{const n=t.querySelector(`.${h}`);n&&("small"===e?n.classList.add(`${h}--small`):n.classList.remove(`${h}--small`))};t.querySelectorAll(`.${h}__close`).forEach(e=>{e.addEventListener("click",e=>{e.preventDefault(),P()})}),document.querySelectorAll(".newspack-blocks__modal-variation").forEach(e=>{e.addEventListener("click",t=>{t.target===e&&P()}),e.querySelectorAll(`.${h}__close`).forEach(e=>{e.addEventListener("click",e=>{e.preventDefault(),P()})})});const I=e=>{"Escape"===e.key&&P()};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=m,e.addEventListener("submit",C)})}),(()=>{const e=new URLSearchParams(window.location.search);if(!e.has("checkout"))return;let t=!0;const n=e.get("type");if("donate"===n){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 i="untiered"===e?a.querySelector(`input[name="donation_value_${t}_untiered"]`):a.querySelector(`input[name="donation_value_${t}"][value="${n}"]`);if(r&&i){if(r.checked=!0,"untiered"===e)i.value=n;else if("other"===n){i.click();const e=a.querySelector(`input[name="donation_value_${t}_other"]`);e&&o&&(e.value=o)}else i.checked=!0;c=a}}}),c&&r(c)})(t,n,o,c)}else if("checkout_button"===n){const n=e.get("product_id"),o=e.get("variation_id");n?t=((e,t=null)=>{const n=function(e,t,n,o={}){const{allowProductOnlyFallback:c=!1}=o;if(null==n||""===String(n))return u(e,t,null);const a=u(e,t,n);if(a)return a;const r=function(e,t,n,o={}){const{variationModalClassPrefix:c,iframeName:a}=o,r=[...e.querySelectorAll(`.${c}`)].find(e=>String(e.dataset.productId)===String(t));if(!r)return null;const i=r.querySelectorAll("form"),s=a?[...i].find(e=>e.getAttribute("target")===a):i[0];if(!s)return null;const l=[...s.querySelectorAll('input[type="radio"][name="product_id"]')].find(e=>String(e.value)===String(n));return l?(l.checked=!0,s):null}(e,t,n,o);return r?(function(e,t,n=d){if(!e||!t)return;const o=t.ownerDocument,c=new FormData(e);n.forEach(e=>{if(t.querySelector(`input[name="${e}"]`))return;const n=c.getAll(e).filter(e=>"string"==typeof e&&e);if(!n.length)return;const a=o.createElement("input");a.type="hidden",a.name=e,a.value=n[n.length-1],t.prepend(a)})}(u(e,t,null),r),r):c?u(e,t,null):null}(document,e,t,{variationModalClassPrefix:k,iframeName:m});if(n)return r(n),!0;const o=`Newspack modal checkout: no checkout form found for product_id "${e}"`+(t?` and variation_id "${t}"`:"")+". The checkout was not triggered.";return console.warn(o),!1})(n,o):(t=!1,console.warn("Newspack modal checkout: checkout_button trigger is missing product_id. The checkout was not triggered."))}else{const e=window.newspackReaderActivation?.getPendingCheckout?.();e&&r(x(e))}t&&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(v=t||newspackBlocksModal.labels.checkout_modal_title,T(v),(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)}D(e.toString())},window.newspackCloseModalCheckout=P},"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",E):E())})();
|
|
@@ -777,10 +777,9 @@ final class Modal_Checkout {
|
|
|
777
777
|
$products = array_keys( self::$products );
|
|
778
778
|
$class_prefix = self::get_class_prefix();
|
|
779
779
|
|
|
780
|
-
$products = array_keys( self::$products );
|
|
781
780
|
foreach ( $products as $product_id ) {
|
|
782
781
|
$product = wc_get_product( $product_id );
|
|
783
|
-
if ( ! $product || ( ! $product->is_type( 'variable' ) && ! $product->is_type( 'grouped' ) ) ) {
|
|
782
|
+
if ( ! $product || ( ! $product->is_type( 'variable' ) && ! $product->is_type( 'variable-subscription' ) && ! $product->is_type( 'grouped' ) ) ) {
|
|
784
783
|
continue;
|
|
785
784
|
}
|
|
786
785
|
?>
|
|
@@ -256,7 +256,7 @@ final class Checkout_Data {
|
|
|
256
256
|
$is_grouped = true;
|
|
257
257
|
$product_id = $source->get_id();
|
|
258
258
|
$children = self::get_children( $source );
|
|
259
|
-
} elseif ( $source->is_type( 'variable' ) ) {
|
|
259
|
+
} elseif ( $source->is_type( 'variable' ) || $source->is_type( 'variable-subscription' ) ) {
|
|
260
260
|
$is_variable = true;
|
|
261
261
|
$product_id = $source->get_id();
|
|
262
262
|
$children = self::get_children( $source );
|
|
@@ -2,7 +2,7 @@ msgid ""
|
|
|
2
2
|
msgstr ""
|
|
3
3
|
"Project-Id-Version: Newspack Blocks\n"
|
|
4
4
|
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/newspack-blocks\n"
|
|
5
|
-
"POT-Creation-Date: 2026-05-
|
|
5
|
+
"POT-Creation-Date: 2026-05-27T09:15:53+00:00\n"
|
|
6
6
|
"PO-Revision-Date: 2024-08-30 08:45-0700\n"
|
|
7
7
|
"Last-Translator: \n"
|
|
8
8
|
"Language-Team: \n"
|
|
@@ -2,7 +2,7 @@ msgid ""
|
|
|
2
2
|
msgstr ""
|
|
3
3
|
"Project-Id-Version: Newspack Blocks 1.0.0-alpha.20\n"
|
|
4
4
|
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/newspack-blocks\n"
|
|
5
|
-
"POT-Creation-Date: 2026-05-
|
|
5
|
+
"POT-Creation-Date: 2026-05-27T09:15:53+00:00\n"
|
|
6
6
|
"PO-Revision-Date: 2025-08-12T14:56:45+00:00\n"
|
|
7
7
|
"Last-Translator: \n"
|
|
8
8
|
"Language-Team: \n"
|
|
@@ -2,7 +2,7 @@ msgid ""
|
|
|
2
2
|
msgstr ""
|
|
3
3
|
"Project-Id-Version: Newspack Blocks 1.0.0-alpha.25\n"
|
|
4
4
|
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/newspack-blocks\n"
|
|
5
|
-
"POT-Creation-Date: 2026-05-
|
|
5
|
+
"POT-Creation-Date: 2026-05-27T09:15:53+00:00\n"
|
|
6
6
|
"PO-Revision-Date: 2024-08-30 08:46-0700\n"
|
|
7
7
|
"Last-Translator: \n"
|
|
8
8
|
"Language-Team: \n"
|
|
@@ -2,7 +2,7 @@ msgid ""
|
|
|
2
2
|
msgstr ""
|
|
3
3
|
"Project-Id-Version: Newspack Blocks 1.0.0-alpha.20\n"
|
|
4
4
|
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/newspack-blocks\n"
|
|
5
|
-
"POT-Creation-Date: 2026-05-
|
|
5
|
+
"POT-Creation-Date: 2026-05-27T09:15:53+00:00\n"
|
|
6
6
|
"PO-Revision-Date: 2024-08-30 08:46-0700\n"
|
|
7
7
|
"Last-Translator: \n"
|
|
8
8
|
"Language-Team: \n"
|
|
@@ -2,7 +2,7 @@ msgid ""
|
|
|
2
2
|
msgstr ""
|
|
3
3
|
"Project-Id-Version: Newspack Blocks 1.0.0-alpha.25\n"
|
|
4
4
|
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/newspack-blocks\n"
|
|
5
|
-
"POT-Creation-Date: 2026-05-
|
|
5
|
+
"POT-Creation-Date: 2026-05-27T09:15:53+00:00\n"
|
|
6
6
|
"PO-Revision-Date: 2024-08-30 08:46-0700\n"
|
|
7
7
|
"Last-Translator: \n"
|
|
8
8
|
"Language-Team: \n"
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
# This file is distributed under the same license as the Newspack Blocks plugin.
|
|
3
3
|
msgid ""
|
|
4
4
|
msgstr ""
|
|
5
|
-
"Project-Id-Version: Newspack Blocks 4.26.
|
|
5
|
+
"Project-Id-Version: Newspack Blocks 4.26.3\n"
|
|
6
6
|
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/newspack-blocks\n"
|
|
7
7
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
|
8
8
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
|
9
9
|
"MIME-Version: 1.0\n"
|
|
10
10
|
"Content-Type: text/plain; charset=UTF-8\n"
|
|
11
11
|
"Content-Transfer-Encoding: 8bit\n"
|
|
12
|
-
"POT-Creation-Date: 2026-05-
|
|
12
|
+
"POT-Creation-Date: 2026-05-27T09:15:53+00:00\n"
|
|
13
13
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
|
14
14
|
"X-Generator: WP-CLI 2.12.0\n"
|
|
15
15
|
"X-Domain: newspack-blocks\n"
|
package/newspack-blocks.php
CHANGED
|
@@ -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.26.
|
|
10
|
+
* Version: 4.26.5-epic-editor-refactor.1
|
|
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.26.
|
|
18
|
+
define( 'NEWSPACK_BLOCKS__VERSION', '4.26.5-epic-editor-refactor.1' );
|
|
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.26.
|
|
3
|
+
"version": "4.26.5-epic-editor-refactor.1",
|
|
4
4
|
"author": "Automattic",
|
|
5
5
|
"description": "=== Newspack Blocks === Contributors: (this should be a list of wordpress.org userid's) Donate link: https://example.com/ Tags: comments, spam Requires at least: 4.5 Tested up to: 5.1.1 Stable tag: 0.1.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html",
|
|
6
6
|
"repository": {
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"newspack-colors": "1.1.0",
|
|
50
50
|
"newspack-icons": "1.0.8",
|
|
51
51
|
"redux": "^5.0.0",
|
|
52
|
-
"redux-saga": "^1.
|
|
52
|
+
"redux-saga": "^1.5.0",
|
|
53
53
|
"regenerator-runtime": "^0.14.1",
|
|
54
|
-
"swiper": "12.0
|
|
54
|
+
"swiper": "12.2.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/lodash": "^4.17.23",
|
|
58
|
-
"newspack-components": "4.
|
|
58
|
+
"newspack-components": "4.4.0-epic-editor-refactor.1",
|
|
59
59
|
"newspack-scripts": "5.9.8"
|
|
60
60
|
},
|
|
61
61
|
"overrides": {
|
|
@@ -43,7 +43,12 @@ function render_callback( $attributes ) {
|
|
|
43
43
|
if ( $attributes['is_variable'] && ! empty( $attributes['variation'] ) ) {
|
|
44
44
|
$product_id = $attributes['variation'];
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
// Register the parent for variable buttons so the picker is rendered.
|
|
47
|
+
// The form still carries any locked variation for direct clicks.
|
|
48
|
+
$modal_product_id = ! empty( $attributes['is_variable'] ) && ! empty( $attributes['product'] )
|
|
49
|
+
? $attributes['product']
|
|
50
|
+
: $product_id;
|
|
51
|
+
\Newspack_Blocks\Modal_Checkout::enqueue_modal( $modal_product_id );
|
|
47
52
|
\Newspack_Blocks::enqueue_view_assets( 'checkout-button' );
|
|
48
53
|
|
|
49
54
|
$background_color = $attributes['backgroundColor'] ?? '';
|
|
@@ -420,17 +420,16 @@ class QueryControls extends Component {
|
|
|
420
420
|
tokens={ getTermsOfCustomTaxonomy( customTaxonomyExclusions, slug ) }
|
|
421
421
|
/>
|
|
422
422
|
) ) }
|
|
423
|
-
|
|
424
|
-
{ onAllowDedupeChange && (
|
|
425
|
-
<ToggleControl
|
|
426
|
-
label={ __( 'Allow duplicate content', 'newspack-blocks' ) }
|
|
427
|
-
help={ __( "Exclude this block from the page's deduplication logic.", 'newspack-blocks' ) }
|
|
428
|
-
checked={ allowDedupeCurrentValue }
|
|
429
|
-
onChange={ value => onAllowDedupeChange( value ) }
|
|
430
|
-
/>
|
|
431
|
-
) }
|
|
432
423
|
</>
|
|
433
424
|
) }
|
|
425
|
+
{ onAllowDedupeChange && (
|
|
426
|
+
<ToggleControl
|
|
427
|
+
label={ __( 'Allow duplicate content', 'newspack-blocks' ) }
|
|
428
|
+
help={ __( "Exclude this block from the page's deduplication logic.", 'newspack-blocks' ) }
|
|
429
|
+
checked={ allowDedupeCurrentValue }
|
|
430
|
+
onChange={ value => onAllowDedupeChange( value ) }
|
|
431
|
+
/>
|
|
432
|
+
) }
|
|
434
433
|
</>
|
|
435
434
|
);
|
|
436
435
|
};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the form submitted by a modal checkout `checkout_button` URL trigger.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parse a form's `data-checkout` attribute without throwing.
|
|
7
|
+
* Picker forms do not carry `data-checkout`.
|
|
8
|
+
*
|
|
9
|
+
* @param {HTMLElement|null} form The form element.
|
|
10
|
+
*
|
|
11
|
+
* @return {Object|null} The parsed checkout data, or null.
|
|
12
|
+
*/
|
|
13
|
+
export function readCheckoutData( form ) {
|
|
14
|
+
const raw = form && form.dataset ? form.dataset.checkout : null;
|
|
15
|
+
if ( ! raw ) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse( raw );
|
|
20
|
+
} catch ( e ) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Find a checkout button form matching the requested product.
|
|
27
|
+
*
|
|
28
|
+
* Variation requests are never served by a button locked to a different
|
|
29
|
+
* variation.
|
|
30
|
+
*
|
|
31
|
+
* @param {Document|HTMLElement} root The DOM root to search.
|
|
32
|
+
* @param {string} productId The requested product ID.
|
|
33
|
+
* @param {string|null} variationId Optional. The requested variation ID.
|
|
34
|
+
*
|
|
35
|
+
* @return {HTMLFormElement|null} The matching form, or null.
|
|
36
|
+
*/
|
|
37
|
+
export function findCheckoutButtonForm( root, productId, variationId = null ) {
|
|
38
|
+
const buttons = root.querySelectorAll( '.wp-block-newspack-blocks-checkout-button' );
|
|
39
|
+
const hasVariation = variationId !== null && variationId !== undefined && String( variationId ) !== '';
|
|
40
|
+
let match = null;
|
|
41
|
+
buttons.forEach( button => {
|
|
42
|
+
if ( match ) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const form = button.querySelector( 'form' );
|
|
46
|
+
const data = readCheckoutData( form );
|
|
47
|
+
if ( ! data ) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if ( String( data.product_id ) !== String( productId ) ) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if ( hasVariation && String( data.variation_id ) !== String( variationId ) ) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
match = form;
|
|
57
|
+
} );
|
|
58
|
+
return match;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Select the requested variation in a product picker.
|
|
63
|
+
* Picker forms use the selected radio value instead of `data-checkout`.
|
|
64
|
+
*
|
|
65
|
+
* Side effect: when a matching radio is found it is checked (mutating the DOM)
|
|
66
|
+
* before the form is returned, so the form submits the requested variation.
|
|
67
|
+
*
|
|
68
|
+
* @param {Document|HTMLElement} root The DOM root to search.
|
|
69
|
+
* @param {string} productId The parent product ID of the picker.
|
|
70
|
+
* @param {string} variationId The requested variation ID.
|
|
71
|
+
* @param {Object} options Options.
|
|
72
|
+
* @param {string} options.variationModalClassPrefix Class of the picker container.
|
|
73
|
+
* @param {string} options.iframeName The checkout iframe name (form target).
|
|
74
|
+
*
|
|
75
|
+
* @return {HTMLFormElement|null} The picker form, or null.
|
|
76
|
+
*/
|
|
77
|
+
export function selectPickerForm( root, productId, variationId, options = {} ) {
|
|
78
|
+
const { variationModalClassPrefix, iframeName } = options;
|
|
79
|
+
const modals = root.querySelectorAll( `.${ variationModalClassPrefix }` );
|
|
80
|
+
const modal = [ ...modals ].find( el => String( el.dataset.productId ) === String( productId ) );
|
|
81
|
+
if ( ! modal ) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const forms = modal.querySelectorAll( 'form' );
|
|
85
|
+
const form = iframeName ? [ ...forms ].find( el => el.getAttribute( 'target' ) === iframeName ) : forms[ 0 ];
|
|
86
|
+
if ( ! form ) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const radios = form.querySelectorAll( 'input[type="radio"][name="product_id"]' );
|
|
90
|
+
const radio = [ ...radios ].find( input => String( input.value ) === String( variationId ) );
|
|
91
|
+
if ( ! radio ) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
radio.checked = true;
|
|
95
|
+
return form;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Hidden fields copied from a source checkout button to a picker submission.
|
|
100
|
+
*
|
|
101
|
+
* @type {string[]}
|
|
102
|
+
*/
|
|
103
|
+
export const PICKER_CONTEXT_FIELDS = [
|
|
104
|
+
'after_success_behavior',
|
|
105
|
+
'after_success_url',
|
|
106
|
+
'after_success_button_label',
|
|
107
|
+
'gate_post_id',
|
|
108
|
+
'newspack_popup_id',
|
|
109
|
+
'prompt_title',
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Copy context fields. Target values are preserved, empty source values are
|
|
114
|
+
* skipped, and null forms are ignored.
|
|
115
|
+
*
|
|
116
|
+
* @param {HTMLFormElement|null} sourceForm Checkout button form to read from.
|
|
117
|
+
* @param {HTMLFormElement|null} targetForm Picker form to copy into.
|
|
118
|
+
* @param {string[]} fields Field names to copy.
|
|
119
|
+
*
|
|
120
|
+
* @return {void}
|
|
121
|
+
*/
|
|
122
|
+
export function copyContextFields( sourceForm, targetForm, fields = PICKER_CONTEXT_FIELDS ) {
|
|
123
|
+
if ( ! sourceForm || ! targetForm ) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const doc = targetForm.ownerDocument;
|
|
127
|
+
const sourceData = new FormData( sourceForm );
|
|
128
|
+
fields.forEach( name => {
|
|
129
|
+
if ( targetForm.querySelector( `input[name="${ name }"]` ) ) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const values = sourceData.getAll( name ).filter( value => typeof value === 'string' && value );
|
|
133
|
+
if ( ! values.length ) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const input = doc.createElement( 'input' );
|
|
137
|
+
input.type = 'hidden';
|
|
138
|
+
input.name = name;
|
|
139
|
+
input.value = values[ values.length - 1 ];
|
|
140
|
+
targetForm.prepend( input );
|
|
141
|
+
} );
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Resolve which form a `checkout_button` URL trigger should submit.
|
|
146
|
+
*
|
|
147
|
+
* Strict order: exact button, picker, then explicit product-only fallback.
|
|
148
|
+
* Returning null prevents silent substitution.
|
|
149
|
+
*
|
|
150
|
+
* @param {Document|HTMLElement} root The DOM root to search.
|
|
151
|
+
* @param {string} productId The requested product ID.
|
|
152
|
+
* @param {string|null} variationId Optional. The requested variation ID.
|
|
153
|
+
* @param {Object} options Options (see selectPickerForm) plus
|
|
154
|
+
* `allowProductOnlyFallback` (default false).
|
|
155
|
+
*
|
|
156
|
+
* @return {HTMLFormElement|null} The form to submit, or null.
|
|
157
|
+
*/
|
|
158
|
+
export function resolveCheckoutButtonForm( root, productId, variationId, options = {} ) {
|
|
159
|
+
const { allowProductOnlyFallback = false } = options;
|
|
160
|
+
const hasVariation = variationId !== null && variationId !== undefined && String( variationId ) !== '';
|
|
161
|
+
|
|
162
|
+
if ( ! hasVariation ) {
|
|
163
|
+
// No variation requested. If several buttons on the page share this
|
|
164
|
+
// parent product, the first in DOM order is used (along with its
|
|
165
|
+
// context); the URL gives no signal to prefer one over another.
|
|
166
|
+
return findCheckoutButtonForm( root, productId, null );
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const exact = findCheckoutButtonForm( root, productId, variationId );
|
|
170
|
+
if ( exact ) {
|
|
171
|
+
return exact;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const picker = selectPickerForm( root, productId, variationId, options );
|
|
175
|
+
if ( picker ) {
|
|
176
|
+
// The source button may be locked to another variation. Use it only
|
|
177
|
+
// for block context, then submit the picker. The picker is only reached
|
|
178
|
+
// because no button matches the requested variation, so when several
|
|
179
|
+
// buttons share this parent product there is no single correct one to
|
|
180
|
+
// prefer: the first in DOM order supplies the context.
|
|
181
|
+
copyContextFields( findCheckoutButtonForm( root, productId, null ), picker );
|
|
182
|
+
return picker;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if ( allowProductOnlyFallback ) {
|
|
186
|
+
return findCheckoutButtonForm( root, productId, null );
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return null;
|
|
190
|
+
}
|