@automattic/newspack-blocks 4.18.0-alpha.1 → 4.18.0-alpha.2
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 +5 -6
- package/dist/editor.asset.php +1 -1
- package/dist/editor.js +2 -2
- package/newspack-blocks.php +2 -2
- package/package.json +1 -1
- package/src/blocks/donate/edit/TierBasedLayout.tsx +3 -3
- package/src/blocks/donate/edit/index.tsx +9 -11
- package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-tiers-based.php +5 -1
- package/src/modal-checkout/modal.js +7 -5
- package/vendor/composer/installed.php +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
# [4.18.0-alpha.
|
|
1
|
+
# [4.18.0-alpha.2](https://github.com/Automattic/newspack-blocks/compare/v4.18.0-alpha.1...v4.18.0-alpha.2) (2025-11-17)
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
###
|
|
4
|
+
### Bug Fixes
|
|
5
5
|
|
|
6
|
-
*
|
|
7
|
-
* **modal-checkout:** processing payment screen ([#2247](https://github.com/Automattic/newspack-blocks/issues/2247)) ([8beea1e](https://github.com/Automattic/newspack-blocks/commit/8beea1e4fc67b150fc06b5a3b46c827a7d908f1c))
|
|
6
|
+
* linting issues ([#2254](https://github.com/Automattic/newspack-blocks/issues/2254)) ([ae580a3](https://github.com/Automattic/newspack-blocks/commit/ae580a3a5eb864c20e99c0fc692d19c2c3fec55f))
|
|
8
7
|
|
|
9
8
|
|
|
10
|
-
###
|
|
9
|
+
### Features
|
|
11
10
|
|
|
12
|
-
*
|
|
11
|
+
* **donate-block:** default frequency for tiered layout ([#2248](https://github.com/Automattic/newspack-blocks/issues/2248)) ([2d07c11](https://github.com/Automattic/newspack-blocks/commit/2d07c111cd678138ad09cec2b768fc7c98e1d35b))
|
|
13
12
|
|
|
14
13
|
## [4.17.4](https://github.com/Automattic/newspack-blocks/compare/v4.17.3...v4.17.4) (2025-11-13)
|
|
15
14
|
|
package/dist/editor.asset.php
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<?php return array('dependencies' => array('lodash', 'react', 'react-jsx-runtime', 'wp-a11y', 'wp-api-fetch', 'wp-autop', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-element', 'wp-escape-html', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-keycodes', 'wp-primitives', 'wp-url'), 'version' => '
|
|
1
|
+
<?php return array('dependencies' => array('lodash', 'react', 'react-jsx-runtime', 'wp-a11y', 'wp-api-fetch', 'wp-autop', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-element', 'wp-escape-html', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-keycodes', 'wp-primitives', 'wp-url'), 'version' => '6c59c4c42fdc6eb965e0');
|
package/dist/editor.js
CHANGED
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
(0,o._x)("per %s","per `Frequency`","newspack-blocks"),e),k=(e,t=!1)=>{const s={minimumFractionDigits:0==e%1?0:2};return t&&(s.style="currency",s.currency=window.newspack_blocks_data?.currency||"USD"),new Intl.NumberFormat(navigator?.language||"en-US",s).format(e)},S=(e,t,s=!1)=>{const n=window.newspack_blocks_data?.tier_amounts_template;if(!n)try{const s="once"===t?t:(0,o.sprintf)(
|
|
33
33
|
// Translators: %s is the %s is the frequency.
|
|
34
34
|
// Translators: %s is the %s is the frequency.
|
|
35
|
-
(0,o.__)("per %s","newspack-blocks"),t);return('<span class="price-amount">'+k(e,!0)+'</span> <span class="tier-frequency">'+s+"</span>").replace(".00","")}catch(t){return'<span class="price-amount">'+e+"</span>"}const a=_(t,s);return n.replace("AMOUNT_PLACEHOLDER",k(e)).replace("FREQUENCY_PLACEHOLDER",a)},C={once:(0,o.__)("One-time","newspack-blocks"),month:(0,o.__)("Monthly","newspack-blocks"),year:(0,o.__)("Annually","newspack-blocks")},E=Object.keys(C),T=[{label:(0,o.__)("Frequency","newspack-blocks"),key:"frequency"},{label:(0,o.__)("Tiers","newspack-blocks"),key:"tiers"}],j=e=>{const{amounts:t,availableFrequencies:s,attributes:n}=e,[r,i]=(0,h.useState)(s[0]),l=t[r].slice(0,3);(0,h.useEffect)(()=>{i(s[0])},[s.length]);const d=(t,s)=>a=>{const r=[...n.tiersBasedOptions];r[t]={...r[t],[s]:a},e.setAttributes({tiersBasedOptions:r})},u=n.tiersBasedOptions.some(e=>Boolean(e.recommendLabel));return(0,a.jsxs)("form",{className:"wpbnbd__tiers",onSubmit:e=>e.preventDefault(),children:[s.length>1&&(0,a.jsx)("div",{className:"wpbnbd__tiers__selection",children:s.map(e=>{const t=r===e;return(0,a.jsx)("button",{className:c()("wpbnbd__button",{"wpbnbd__button--active":t}),onClick:()=>i(e),children:C[e]},e)})}),(0,a.jsx)("div",{className:"wpbnbd__tiers__options",children:l.map((e,t)=>{const s=n.tiersBasedOptions[t].recommendLabel||"";return(0,a.jsxs)("div",{className:c()("wpbnbd__tiers__tier",{"wpbnbd__tiers__tier--recommended":s.length}),children:[(0,a.jsxs)("div",{className:"wpbnbd__tiers__top",children:[(0,a.jsx)("h2",{className:"wpbnbd__tiers__heading",children:(0,a.jsx)(f.RichText,{onChange:d(t,"heading"),placeholder:(0,o.__)("Heading…","newspack-blocks"),value:n.tiersBasedOptions[t].heading,tagName:"span"})}),(0,a.jsx)("h3",{className:"wpbnbd__tiers__recommend-label",style:{opacity:s?1:.5},children:(0,a.jsx)(f.RichText,{onChange:d(t,"recommendLabel"),placeholder:(0,o.__)("…","newspack-blocks"),value:s,tagName:"span"})})]}),(0,a.jsx)("div",{className:"wpbnbd__tiers__amount",children:(0,a.jsx)("div",{dangerouslySetInnerHTML:{__html:S(e,r)}})}),(0,a.jsx)("div",{className:"submit-button",style:{appearance:"button",borderColor:n.buttonColor,...u&&!s?{backgroundColor:"transparent",color:n.buttonColor}:{backgroundColor:n.buttonColor,color:y(n.buttonColor)}},children:(0,a.jsx)(f.RichText,{onChange:d(t,"buttonText"),placeholder:(0,o.__)("Button text…","newspack-blocks"),value:n.tiersBasedOptions[t].buttonText,tagName:"span"})}),(0,a.jsx)("div",{className:"wpbnbd__tiers__description",children:(0,a.jsx)(f.RichText,{onChange:d(t,"description"),placeholder:(0,o.__)("Description…","newspack-blocks"),value:n.tiersBasedOptions[t].description,tagName:"span"})})]},t)})})]})},M=({frequencySlug:e,tierIndex:t,id:s,label:n,attributes:r,settings:i,amounts:o,setAttributes:l,setSettings:c,disabled:d,ignoreMinimumAmount:u})=>{const p=o[e][t],h=i.minimumDonation&&!u?Math.max(p,i.minimumDonation):p;return(0,a.jsxs)("span",{children:[n&&(0,a.jsx)("label",{htmlFor:s,children:n}),(0,a.jsx)("input",{type:"number",min:u?void 0:r.minimumDonation,onChange:s=>(({value:e,frequency:s})=>{const n=r.manual?r:i;n.amounts[s][t]=parseFloat(e);const a={amounts:{[s]:n.amounts[s],...n.amounts}};r.manual?l(a):c(a)})({value:s.target.value,frequency:e}),value:h,id:s,disabled:d})]},`${e}-${t}`)};var P=s(6588);const A=e=>{const t=(0,h.useMemo)(()=>Math.random().toString(16).slice(2),[]),{attributes:s,settings:n,amounts:r,availableFrequencies:i,setAttributes:l}=e,d=(0,h.useRef)(null);(0,h.useEffect)(()=>{if(null!==d.current){const e=d.current.closest(".wpbnbd");e&&(0,P.C)(e,(0,P.t)(d.current)),d.current.addEventListener("change",()=>{null!==d.current&&e&&(0,P.C)(e,(0,P.t)(d.current))})}},[]),(0,h.useEffect)(()=>{if(d.current&&!(0,P.t)(d.current).donation_frequency&&d.current.elements){const e=d.current.elements[0];e instanceof HTMLInputElement&&e.click()}-1===i.indexOf(s.defaultFrequency)&&l({defaultFrequency:i[0]})},[s.disabledFrequencies]),(0,h.useEffect)(()=>{if(d.current){const e=d.current.querySelector(`[name="donation_frequency"][value="${s.defaultFrequency}"]`);e instanceof HTMLInputElement&&e.click()}},[s.defaultFrequency]);const[u,p]=(0,h.useState)(s.defaultFrequency),m=window.newspack_blocks_data?.can_use_name_your_price,g=e=>(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("input",{type:"radio",value:e,id:`newspack-donate-${e}-${t}`,name:"donation_frequency",checked:e===u,onChange:e=>p(e.target.value)}),(0,a.jsx)("label",{htmlFor:"newspack-donate-"+e+"-"+t,children:C[e]})]}),v=e=>(0,a.jsx)("button",{role:"tab",className:c()("wpbnbd__button freq-label",{"wpbnbd__button--active":e===u}),id:`tab-newspack-donate-${e}-${t}`,onClick:t=>{t.preventDefault(),p(e)},children:C[e]},e),b=()=>!w&&(0,a.jsx)("div",{className:"tab-container",children:i.map(v)}),w=1===i.length;return(0,a.jsxs)("form",{ref:d,children:[e.isTiered?(0,a.jsx)("div",{className:"wp-block-newspack-blocks-donate__options",children:(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__frequencies frequencies",children:[b(),i.map(e=>(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__frequency frequency",children:[g(e),(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__tiers tiers",children:[r[e].map((s,r)=>{const i=3===r,l=`newspack-tier-${e}-${t}-${i?"other":r}`,d=i?(0,o.__)("Other","newspack-blocks"):k(s,!0);return(0,a.jsxs)("div",{className:c()("wp-block-newspack-blocks-donate__tier","wp-block-newspack-blocks-donate__tier--"+(i?"other":"frequency")),children:[(0,a.jsx)("input",{type:"radio",value:i?"other":s,className:i?"other-input":"frequency-input",id:l,name:`donation_value_${e}`,defaultChecked:1===r}),(0,a.jsx)("label",{className:"tier-select-label tier-label",htmlFor:l,children:d}),i?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"odl",htmlFor:l+"-other-input",children:[(0,o.__)("Donation amount","newspack-blocks"),_(e,!0)]}),(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__money-input money-input",children:[(0,a.jsx)("span",{className:"currency",children:n.currencySymbol}),(0,a.jsx)("input",{type:"number",readOnly:!0})]})]}):null]},r)}),w?(0,a.jsx)("div",{className:"wp-block-newspack-blocks-donate__frequency-label",children:_(e,!0)}):null]})]},e))]})}):(0,a.jsx)("div",{className:"wp-block-newspack-blocks-donate__options",children:(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__frequencies frequencies",children:[b(),i.map(s=>{const i=r[s][3];return(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__frequency frequency",children:[g(s),(0,a.jsx)("div",{className:"input-container",children:m?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"donate-label",htmlFor:"newspack-"+s+"-"+t+"-untiered-input",children:[(0,o.__)("Donation amount","newspack-blocks"),_(s,!0)]}),(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__money-input money-input",children:[(0,a.jsx)("span",{className:"currency",children:n.currencySymbol}),(0,a.jsx)(M,{...e,frequencySlug:s,tierIndex:3,id:`newspack-${s}-${t}-untiered-input`})]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("input",{type:"radio",value:i,className:"frequency-input",id:`newspack-${s}-${t}-untiered-input`,name:`donation_value_${s}`,defaultChecked:!0}),(0,a.jsx)("label",{className:"tier-select-label tier-label",htmlFor:`newspack-${s}-${t}-untiered-input`,children:(0,a.jsx)("div",{dangerouslySetInnerHTML:{__html:S(i,s)}})})]})})]},s)})]})}),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{className:"wp-block-newspack-blocks-donate__thanks thanks",children:(0,a.jsx)(f.RichText,{onChange:e=>l({thanksText:e}),placeholder:(0,o.__)("Thank you text…","newspack-blocks"),value:s.thanksText,tagName:"span"})}),(0,a.jsx)("div",{className:"submit-button",style:{backgroundColor:s.buttonColor,color:y(s.buttonColor)},children:(0,a.jsx)(f.RichText,{onChange:e=>l({buttonText:e}),placeholder:(0,o.__)("Button text…","newspack-blocks"),value:s.buttonText,tagName:"span"})})]})]})};var L=s(8614),I=s(1609);const O=[(0,o.__)("Low-tier","newspack-blocks"),(0,o.__)("Mid-tier","newspack-blocks"),(0,o.__)("High-tier","newspack-blocks")],N=JSON.parse('{"UU":"donate","L1":"newspack","uK":{"className":{"type":"string"},"manual":{"type":"boolean"},"tiered":{"type":"boolean","default":true},"amounts":{"type":"object","default":{}},"disabledFrequencies":{"type":"object","default":{}},"thanksText":{"type":"string","default":"Your contribution is appreciated."},"buttonText":{"type":"string","default":"Donate Now"},"defaultFrequency":{"type":"string","default":"month"},"campaign":{"type":"string"},"buttonColor":{"type":"string","default":"#dd3333"},"suggestedAmounts":{"type":"array"},"suggestedAmountUntiered":{"type":"number"},"minimumDonation":{"type":"number"},"layoutOption":{"type":"string","default":"frequency"},"tierStyle":{"type":"string","default":"grid"},"useModalCheckout":{"type":"boolean","default":true},"tiersBasedOptions":{"type":"array","default":[{"heading":"Small","description":"","buttonText":"Select","recommendLabel":""},{"heading":"Medium","description":"","buttonText":"Select","recommendLabel":"BEST VALUE"},{"heading":"Large","description":"","buttonText":"Select","recommendLabel":""}]},"afterSuccessBehavior":{"type":"string"},"afterSuccessButtonLabel":{"type":"string","default":"Continue"},"afterSuccessURL":{"type":"string"}},"xY":{"html":false,"align":false}}'),{UU:z,uK:D,L1:$,xY:B}=N,R={title:(0,o.__)("Donate","newspack-blocks"),icon:{src:r,foreground:t.A["primary-400"]},category:$,keywords:[(0,o.__)("donate","newspack-blocks"),(0,o.__)("memberships","newspack-blocks"),(0,o.__)("subscriptions","newspack-blocks")],description:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:(0,o.__)("Manually place a donation block on any post or page on your site.","newspack-blocks")}),(0,a.jsx)(i.ExternalLink,{href:"https://help.newspack.com/publishing-and-appearance/blocks/donate-block/",children:(0,o.__)("Support reference","newspack-blocks")})]}),attributes:D,supports:B,edit:({attributes:e,setAttributes:t,className:s})=>{const[n,r]=(0,h.useState)(!0),[l,u]=(0,h.useState)(""),[w,y]=d.JL.useObjectState({amounts:{},currencySymbol:"$",tiered:!1,disabledFrequencies:{},minimumDonation:5,platform:""});if((0,h.useEffect)(()=>{p()({path:"/newspack/v1/wizard/newspack-audience-donations"}).then(({donation_data:s})=>{if(y({amounts:s.amounts,currencySymbol:s.currencySymbol,tiered:s.tiered,disabledFrequencies:s.disabledFrequencies,minimumDonation:s.minimumDonation,platform:s.platform}),(0,m.isEmpty)(e.disabledFrequencies)&&t({disabledFrequencies:s.disabledFrequencies}),(0,m.isEmpty)(e.minimumDonation)&&t({minimumDonation:s.minimumDonation}),(0,m.isEmpty)(e.amounts)&&e.suggestedAmounts&&e.suggestedAmounts.length){const n=e.suggestedAmountUntiered||s.amounts.month[3];t({suggestedAmounts:void 0,suggestedAmountUntiered:void 0,amounts:{once:x("once",e.suggestedAmounts,n),month:x("month",e.suggestedAmounts,n),year:x("year",e.suggestedAmounts,n)}})}else t({amounts:{...s.amounts,...e.amounts}})}).catch(u).finally(()=>r(!1))},[]),l.length)return(0,a.jsx)(i.Placeholder,{icon:"warning",label:(0,o.__)("Error","newspack-blocks"),instructions:l,children:(0,a.jsx)(i.ExternalLink,{href:"/wp-admin/admin.php?page=newspack-audience#/payment",children:(0,o.__)("Go to checkout & payment settings to troubleshoot.","newspack-blocks")})});if("other"===w.platform)return(0,a.jsx)(i.Placeholder,{icon:"warning",label:(0,o.__)("The Donate block will not be rendered.","newspack-blocks"),instructions:(0,o.__)('The Reader Revenue platform is set to "other".',"newspack-blocks"),children:(0,a.jsx)(i.ExternalLink,{href:"/wp-admin/admin.php?page=newspack-audience#/payment",children:(0,o.__)("Go to checkout & payment settings to update the platform.","newspack-blocks")})});if(n)return(0,a.jsx)(i.Placeholder,{icon:(0,a.jsx)(i.Spinner,{}),className:"component-placeholder__align-center"});const _=window.newspack_blocks_data?.can_use_name_your_price,k=e.manual&&_,S=k?e.tiered:w.tiered,P=S&&"tiers"===e.layoutOption,N=e.tierStyle,z=k?e.amounts:w.amounts,D=E.filter(t=>k?!e.disabledFrequencies[t]:!w.disabledFrequencies[t]);-1===s.indexOf("is-style")&&(s+=" is-style-default"),_||(s+=" wpbnbd--nyp-disabled");const $=(e=[])=>c()(e,s,"wpbnbd","wpbnbd--"+(P?"tiers-based":"frequency-based"),`wpbnbd--platform-${w.platform}`,`wpbnbd-frequencies--${D.length}`,P&&`wpbnbd--tier-style-${N}`),B=[{icon:(0,a.jsx)(g.A,{icon:v.A}),title:(0,o.__)("Grid View","newspack-blocks"),onClick:()=>t({tierStyle:"grid"}),isActive:"grid"===e.tierStyle},{icon:(0,a.jsx)(g.A,{icon:b}),title:(0,o.__)("List View","newspack-blocks"),onClick:()=>t({tierStyle:"list"}),isActive:"list"===e.tierStyle}],R=k?e.minimumDonation:w.minimumDonation,F={...z};Object.keys(z).forEach(e=>{const t=z[e].map(e=>Math.max(e,R));F[e]=t});const H={attributes:e,amounts:z,availableFrequencies:D,settings:w,setAttributes:t,setSettings:y},V=()=>(0,a.jsx)("p",{className:"components-frequency-donations__error",children:(0,o.sprintf)(
|
|
35
|
+
(0,o.__)("per %s","newspack-blocks"),t);return('<span class="price-amount">'+k(e,!0)+'</span> <span class="tier-frequency">'+s+"</span>").replace(".00","")}catch(t){return'<span class="price-amount">'+e+"</span>"}const a=_(t,s);return n.replace("AMOUNT_PLACEHOLDER",k(e)).replace("FREQUENCY_PLACEHOLDER",a)},C={once:(0,o.__)("One-time","newspack-blocks"),month:(0,o.__)("Monthly","newspack-blocks"),year:(0,o.__)("Annually","newspack-blocks")},E=Object.keys(C),T=[{label:(0,o.__)("Frequency","newspack-blocks"),key:"frequency"},{label:(0,o.__)("Tiers","newspack-blocks"),key:"tiers"}],j=e=>{const{amounts:t,availableFrequencies:s,attributes:n}=e,[r,i]=(0,h.useState)(n.defaultFrequency||s[0]),l=t[r].slice(0,3);(0,h.useEffect)(()=>{i(n.defaultFrequency||s[0])},[s.length,n.defaultFrequency]);const d=(t,s)=>a=>{const r=[...n.tiersBasedOptions];r[t]={...r[t],[s]:a},e.setAttributes({tiersBasedOptions:r})},u=n.tiersBasedOptions.some(e=>Boolean(e.recommendLabel));return(0,a.jsxs)("form",{className:"wpbnbd__tiers",onSubmit:e=>e.preventDefault(),children:[s.length>1&&(0,a.jsx)("div",{className:"wpbnbd__tiers__selection",children:s.map(e=>{const t=r===e;return(0,a.jsx)("button",{className:c()("wpbnbd__button",{"wpbnbd__button--active":t}),onClick:()=>i(e),children:C[e]},e)})}),(0,a.jsx)("div",{className:"wpbnbd__tiers__options",children:l.map((e,t)=>{const s=n.tiersBasedOptions[t].recommendLabel||"";return(0,a.jsxs)("div",{className:c()("wpbnbd__tiers__tier",{"wpbnbd__tiers__tier--recommended":s.length}),children:[(0,a.jsxs)("div",{className:"wpbnbd__tiers__top",children:[(0,a.jsx)("h2",{className:"wpbnbd__tiers__heading",children:(0,a.jsx)(f.RichText,{onChange:d(t,"heading"),placeholder:(0,o.__)("Heading…","newspack-blocks"),value:n.tiersBasedOptions[t].heading,tagName:"span"})}),(0,a.jsx)("h3",{className:"wpbnbd__tiers__recommend-label",style:{opacity:s?1:.5},children:(0,a.jsx)(f.RichText,{onChange:d(t,"recommendLabel"),placeholder:(0,o.__)("…","newspack-blocks"),value:s,tagName:"span"})})]}),(0,a.jsx)("div",{className:"wpbnbd__tiers__amount",children:(0,a.jsx)("div",{dangerouslySetInnerHTML:{__html:S(e,r)}})}),(0,a.jsx)("div",{className:"submit-button",style:{appearance:"button",borderColor:n.buttonColor,...u&&!s?{backgroundColor:"transparent",color:n.buttonColor}:{backgroundColor:n.buttonColor,color:y(n.buttonColor)}},children:(0,a.jsx)(f.RichText,{onChange:d(t,"buttonText"),placeholder:(0,o.__)("Button text…","newspack-blocks"),value:n.tiersBasedOptions[t].buttonText,tagName:"span"})}),(0,a.jsx)("div",{className:"wpbnbd__tiers__description",children:(0,a.jsx)(f.RichText,{onChange:d(t,"description"),placeholder:(0,o.__)("Description…","newspack-blocks"),value:n.tiersBasedOptions[t].description,tagName:"span"})})]},t)})})]})},M=({frequencySlug:e,tierIndex:t,id:s,label:n,attributes:r,settings:i,amounts:o,setAttributes:l,setSettings:c,disabled:d,ignoreMinimumAmount:u})=>{const p=o[e][t],h=i.minimumDonation&&!u?Math.max(p,i.minimumDonation):p;return(0,a.jsxs)("span",{children:[n&&(0,a.jsx)("label",{htmlFor:s,children:n}),(0,a.jsx)("input",{type:"number",min:u?void 0:r.minimumDonation,onChange:s=>(({value:e,frequency:s})=>{const n=r.manual?r:i;n.amounts[s][t]=parseFloat(e);const a={amounts:{[s]:n.amounts[s],...n.amounts}};r.manual?l(a):c(a)})({value:s.target.value,frequency:e}),value:h,id:s,disabled:d})]},`${e}-${t}`)};var P=s(6588);const A=e=>{const t=(0,h.useMemo)(()=>Math.random().toString(16).slice(2),[]),{attributes:s,settings:n,amounts:r,availableFrequencies:i,setAttributes:l}=e,d=(0,h.useRef)(null);(0,h.useEffect)(()=>{if(null!==d.current){const e=d.current.closest(".wpbnbd");e&&(0,P.C)(e,(0,P.t)(d.current)),d.current.addEventListener("change",()=>{null!==d.current&&e&&(0,P.C)(e,(0,P.t)(d.current))})}},[]),(0,h.useEffect)(()=>{if(d.current&&!(0,P.t)(d.current).donation_frequency&&d.current.elements){const e=d.current.elements[0];e instanceof HTMLInputElement&&e.click()}-1===i.indexOf(s.defaultFrequency)&&l({defaultFrequency:i[0]})},[s.disabledFrequencies]),(0,h.useEffect)(()=>{if(d.current){const e=d.current.querySelector(`[name="donation_frequency"][value="${s.defaultFrequency}"]`);e instanceof HTMLInputElement&&e.click()}},[s.defaultFrequency]);const[u,p]=(0,h.useState)(s.defaultFrequency),m=window.newspack_blocks_data?.can_use_name_your_price,g=e=>(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("input",{type:"radio",value:e,id:`newspack-donate-${e}-${t}`,name:"donation_frequency",checked:e===u,onChange:e=>p(e.target.value)}),(0,a.jsx)("label",{htmlFor:"newspack-donate-"+e+"-"+t,children:C[e]})]}),v=e=>(0,a.jsx)("button",{role:"tab",className:c()("wpbnbd__button freq-label",{"wpbnbd__button--active":e===u}),id:`tab-newspack-donate-${e}-${t}`,onClick:t=>{t.preventDefault(),p(e)},children:C[e]},e),b=()=>!w&&(0,a.jsx)("div",{className:"tab-container",children:i.map(v)}),w=1===i.length;return(0,a.jsxs)("form",{ref:d,children:[e.isTiered?(0,a.jsx)("div",{className:"wp-block-newspack-blocks-donate__options",children:(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__frequencies frequencies",children:[b(),i.map(e=>(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__frequency frequency",children:[g(e),(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__tiers tiers",children:[r[e].map((s,r)=>{const i=3===r,l=`newspack-tier-${e}-${t}-${i?"other":r}`,d=i?(0,o.__)("Other","newspack-blocks"):k(s,!0);return(0,a.jsxs)("div",{className:c()("wp-block-newspack-blocks-donate__tier","wp-block-newspack-blocks-donate__tier--"+(i?"other":"frequency")),children:[(0,a.jsx)("input",{type:"radio",value:i?"other":s,className:i?"other-input":"frequency-input",id:l,name:`donation_value_${e}`,defaultChecked:1===r}),(0,a.jsx)("label",{className:"tier-select-label tier-label",htmlFor:l,children:d}),i?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"odl",htmlFor:l+"-other-input",children:[(0,o.__)("Donation amount","newspack-blocks"),_(e,!0)]}),(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__money-input money-input",children:[(0,a.jsx)("span",{className:"currency",children:n.currencySymbol}),(0,a.jsx)("input",{type:"number",readOnly:!0})]})]}):null]},r)}),w?(0,a.jsx)("div",{className:"wp-block-newspack-blocks-donate__frequency-label",children:_(e,!0)}):null]})]},e))]})}):(0,a.jsx)("div",{className:"wp-block-newspack-blocks-donate__options",children:(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__frequencies frequencies",children:[b(),i.map(s=>{const i=r[s][3];return(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__frequency frequency",children:[g(s),(0,a.jsx)("div",{className:"input-container",children:m?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"donate-label",htmlFor:"newspack-"+s+"-"+t+"-untiered-input",children:[(0,o.__)("Donation amount","newspack-blocks"),_(s,!0)]}),(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__money-input money-input",children:[(0,a.jsx)("span",{className:"currency",children:n.currencySymbol}),(0,a.jsx)(M,{...e,frequencySlug:s,tierIndex:3,id:`newspack-${s}-${t}-untiered-input`})]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("input",{type:"radio",value:i,className:"frequency-input",id:`newspack-${s}-${t}-untiered-input`,name:`donation_value_${s}`,defaultChecked:!0}),(0,a.jsx)("label",{className:"tier-select-label tier-label",htmlFor:`newspack-${s}-${t}-untiered-input`,children:(0,a.jsx)("div",{dangerouslySetInnerHTML:{__html:S(i,s)}})})]})})]},s)})]})}),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{className:"wp-block-newspack-blocks-donate__thanks thanks",children:(0,a.jsx)(f.RichText,{onChange:e=>l({thanksText:e}),placeholder:(0,o.__)("Thank you text…","newspack-blocks"),value:s.thanksText,tagName:"span"})}),(0,a.jsx)("div",{className:"submit-button",style:{backgroundColor:s.buttonColor,color:y(s.buttonColor)},children:(0,a.jsx)(f.RichText,{onChange:e=>l({buttonText:e}),placeholder:(0,o.__)("Button text…","newspack-blocks"),value:s.buttonText,tagName:"span"})})]})]})};var L=s(8614),I=s(1609);const O=[(0,o.__)("Low-tier","newspack-blocks"),(0,o.__)("Mid-tier","newspack-blocks"),(0,o.__)("High-tier","newspack-blocks")],N=JSON.parse('{"UU":"donate","L1":"newspack","uK":{"className":{"type":"string"},"manual":{"type":"boolean"},"tiered":{"type":"boolean","default":true},"amounts":{"type":"object","default":{}},"disabledFrequencies":{"type":"object","default":{}},"thanksText":{"type":"string","default":"Your contribution is appreciated."},"buttonText":{"type":"string","default":"Donate Now"},"defaultFrequency":{"type":"string","default":"month"},"campaign":{"type":"string"},"buttonColor":{"type":"string","default":"#dd3333"},"suggestedAmounts":{"type":"array"},"suggestedAmountUntiered":{"type":"number"},"minimumDonation":{"type":"number"},"layoutOption":{"type":"string","default":"frequency"},"tierStyle":{"type":"string","default":"grid"},"useModalCheckout":{"type":"boolean","default":true},"tiersBasedOptions":{"type":"array","default":[{"heading":"Small","description":"","buttonText":"Select","recommendLabel":""},{"heading":"Medium","description":"","buttonText":"Select","recommendLabel":"BEST VALUE"},{"heading":"Large","description":"","buttonText":"Select","recommendLabel":""}]},"afterSuccessBehavior":{"type":"string"},"afterSuccessButtonLabel":{"type":"string","default":"Continue"},"afterSuccessURL":{"type":"string"}},"xY":{"html":false,"align":false}}'),{UU:z,uK:D,L1:$,xY:B}=N,R={title:(0,o.__)("Donate","newspack-blocks"),icon:{src:r,foreground:t.A["primary-400"]},category:$,keywords:[(0,o.__)("donate","newspack-blocks"),(0,o.__)("memberships","newspack-blocks"),(0,o.__)("subscriptions","newspack-blocks")],description:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:(0,o.__)("Manually place a donation block on any post or page on your site.","newspack-blocks")}),(0,a.jsx)(i.ExternalLink,{href:"https://help.newspack.com/publishing-and-appearance/blocks/donate-block/",children:(0,o.__)("Support reference","newspack-blocks")})]}),attributes:D,supports:B,edit:({attributes:e,setAttributes:t,className:s})=>{const[n,r]=(0,h.useState)(!0),[l,u]=(0,h.useState)(""),[w,y]=d.JL.useObjectState({amounts:{},currencySymbol:"$",tiered:!1,disabledFrequencies:{},minimumDonation:5,platform:""});if((0,h.useEffect)(()=>{p()({path:"/newspack/v1/wizard/newspack-audience-donations"}).then(({donation_data:s})=>{if(y({amounts:s.amounts,currencySymbol:s.currencySymbol,tiered:s.tiered,disabledFrequencies:s.disabledFrequencies,minimumDonation:s.minimumDonation,platform:s.platform}),(0,m.isEmpty)(e.disabledFrequencies)&&t({disabledFrequencies:s.disabledFrequencies}),(0,m.isEmpty)(e.minimumDonation)&&t({minimumDonation:s.minimumDonation}),(0,m.isEmpty)(e.amounts)&&e.suggestedAmounts&&e.suggestedAmounts.length){const n=e.suggestedAmountUntiered||s.amounts.month[3];t({suggestedAmounts:void 0,suggestedAmountUntiered:void 0,amounts:{once:x("once",e.suggestedAmounts,n),month:x("month",e.suggestedAmounts,n),year:x("year",e.suggestedAmounts,n)}})}else t({amounts:{...s.amounts,...e.amounts}})}).catch(u).finally(()=>r(!1))},[]),l.length)return(0,a.jsx)(i.Placeholder,{icon:"warning",label:(0,o.__)("Error","newspack-blocks"),instructions:l,children:(0,a.jsx)(i.ExternalLink,{href:"/wp-admin/admin.php?page=newspack-audience#/payment",children:(0,o.__)("Go to checkout & payment settings to troubleshoot.","newspack-blocks")})});if("other"===w.platform)return(0,a.jsx)(i.Placeholder,{icon:"warning",label:(0,o.__)("The Donate block will not be rendered.","newspack-blocks"),instructions:(0,o.__)('The Reader Revenue platform is set to "other".',"newspack-blocks"),children:(0,a.jsx)(i.ExternalLink,{href:"/wp-admin/admin.php?page=newspack-audience#/payment",children:(0,o.__)("Go to checkout & payment settings to update the platform.","newspack-blocks")})});if(n)return(0,a.jsx)(i.Placeholder,{icon:(0,a.jsx)(i.Spinner,{}),className:"component-placeholder__align-center"});const _=window.newspack_blocks_data?.can_use_name_your_price,k=e.manual&&_,S=k?e.tiered:w.tiered,P=S&&"tiers"===e.layoutOption,N=e.tierStyle,z=k?e.amounts:w.amounts,D=E.filter(t=>k?!e.disabledFrequencies[t]:!w.disabledFrequencies[t]);-1===s.indexOf("is-style")&&(s+=" is-style-default"),_||(s+=" wpbnbd--nyp-disabled");const $=(e=[])=>c()(e,s,"wpbnbd","wpbnbd--"+(P?"tiers-based":"frequency-based"),`wpbnbd--platform-${w.platform}`,`wpbnbd-frequencies--${D.length}`,P&&`wpbnbd--tier-style-${N}`),B=[{icon:(0,a.jsx)(g.A,{icon:v.A}),title:(0,o.__)("Grid View","newspack-blocks"),onClick:()=>t({tierStyle:"grid"}),isActive:"grid"===e.tierStyle},{icon:(0,a.jsx)(g.A,{icon:b}),title:(0,o.__)("List View","newspack-blocks"),onClick:()=>t({tierStyle:"list"}),isActive:"list"===e.tierStyle}],R=k?e.minimumDonation:w.minimumDonation,F={...z};Object.keys(z).forEach(e=>{const t=z[e].map(e=>Math.max(e,R));F[e]=t});const H={attributes:e,amounts:z,availableFrequencies:D,settings:w,setAttributes:t,setSettings:y},V=()=>(0,a.jsx)("p",{className:"components-frequency-donations__error",children:(0,o.sprintf)(
|
|
36
36
|
// translators: %1$s: currency symbol, %2$d: minimum donation amount.
|
|
37
37
|
// translators: %1$s: currency symbol, %2$d: minimum donation amount.
|
|
38
|
-
(0,o.__)("Warning: suggested donations should be at least the minimum donation amount (%1$s%2$d).","newspack-blocks"),w.currencySymbol,R)});return(0,a.jsxs)(a.Fragment,{children:[P?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:$(),children:(0,a.jsx)(j,{...H,amounts:F})}),(0,a.jsx)(f.BlockControls,{children:(0,a.jsx)(i.Toolbar,{controls:B})})]}):(0,a.jsx)("div",{className:$([S?"tiered":"untiered"]),children:(0,a.jsx)(A,{isTiered:S,...H,amounts:F})}),(0,a.jsxs)(f.InspectorControls,{children:[(0,a.jsxs)(i.PanelBody,{title:(0,o.__)("Layout","newspack-blocks"),children:[_&&(0,a.jsx)("div",{className:"newspack-blocks-donate__layout-selector",children:T.map(({label:e,key:s})=>{const n="tiers"===s?P:!P;return(0,a.jsx)(i.Button,{variant:n?"primary":"secondary",isPressed:n,onClick:()=>t({layoutOption:s}),"aria-current":n,disabled:"tiers"===s&&!S,children:e},s)})}),_&&!S&&(0,a.jsx)(i.Notice,{isDismissible:!1,className:"newspack-blocks-donate__notice",children:(0,o.__)("Tiers layout is disabled if the block is set to render untiered.","newspack-blocks")})
|
|
38
|
+
(0,o.__)("Warning: suggested donations should be at least the minimum donation amount (%1$s%2$d).","newspack-blocks"),w.currencySymbol,R)});return(0,a.jsxs)(a.Fragment,{children:[P?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:$(),children:(0,a.jsx)(j,{...H,amounts:F})}),(0,a.jsx)(f.BlockControls,{children:(0,a.jsx)(i.Toolbar,{controls:B})})]}):(0,a.jsx)("div",{className:$([S?"tiered":"untiered"]),children:(0,a.jsx)(A,{isTiered:S,...H,amounts:F})}),(0,a.jsxs)(f.InspectorControls,{children:[(0,a.jsxs)(i.PanelBody,{title:(0,o.__)("Layout","newspack-blocks"),children:[_&&(0,a.jsx)("div",{className:"newspack-blocks-donate__layout-selector",children:T.map(({label:e,key:s})=>{const n="tiers"===s?P:!P;return(0,a.jsx)(i.Button,{variant:n?"primary":"secondary",isPressed:n,onClick:()=>t({layoutOption:s}),"aria-current":n,disabled:"tiers"===s&&!S,children:e},s)})}),_&&!S&&(0,a.jsx)(i.Notice,{isDismissible:!1,className:"newspack-blocks-donate__notice",children:(0,o.__)("Tiers layout is disabled if the block is set to render untiered.","newspack-blocks")}),(0,a.jsx)(i.SelectControl,{label:(0,o.__)("Default Tab","newspack-blocks"),value:e.defaultFrequency,options:D.map(e=>({label:C[e],value:e})),onChange:e=>t({defaultFrequency:e})})]}),_&&(0,a.jsxs)(i.PanelBody,{title:(0,o.__)("Suggested Donations","newspack-blocks"),children:[(0,a.jsx)(i.ToggleControl,{checked:Boolean(k),onChange:()=>t({manual:!e.manual}),label:(0,o.__)("Configure manually","newspack-blocks")}),k?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(i.ToggleControl,{checked:Boolean(S),onChange:()=>t({tiered:!e.tiered}),label:(0,o.__)("Tiered","newspack-blocks")}),S?(0,a.jsx)(a.Fragment,{children:(0,a.jsx)("div",{className:"components-frequency-donations",children:E.map(s=>{const n=e.disabledFrequencies[s],r=Object.values((0,m.pick)(e.disabledFrequencies,E)).filter(Boolean).length,o=E.length-r===1;return(0,a.jsxs)(h.Fragment,{children:[(0,a.jsx)(i.CheckboxControl,{label:C[s],checked:!n,disabled:!n&&o,onChange:()=>{t({disabledFrequencies:{...e.disabledFrequencies,[s]:!n}})}}),!n&&(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__panel-inputs",children:[z[s].reduce((e,t)=>!t||t<R||e,!1)&&V(),z[s].map((e,t)=>3===t?null:(0,I.createElement)(M,{ignoreMinimumAmount:!0,...H,key:`amount-${s}-${t}`,frequencySlug:s,tierIndex:t,label:O[t],id:`${s}-${t}-amount`,disabled:P&&3===t}))]})]},s)})})}):(0,a.jsx)("div",{className:"components-frequency-donations",children:(0,a.jsxs)("div",{className:"wp-block-newspack-blocks-donate__panel-inputs",children:[E.reduce((t,s)=>!z[s][3]||z[s][3]<e.minimumDonation||t,!1)&&V(),E.map(e=>(0,I.createElement)(M,{ignoreMinimumAmount:!0,...H,key:e,frequencySlug:e,tierIndex:3,label:C[e],id:`${e}-3-amount`}))]})}),(0,a.jsx)(i.TextControl,{className:"components-frequency-donations__minimum-donation",type:"number",label:(0,o.__)("Minimum donation","newspack-blocks"),min:1,onChange:e=>t({minimumDonation:e}),value:e.minimumDonation})]}):(0,a.jsxs)("p",{children:[(0,o.__)("The Donate Block allows you to collect donations from readers. The fields are automatically defined based on your donation settings.","newspack-blocks"),(0,a.jsx)("br",{}),(0,a.jsx)("br",{}),(0,a.jsx)(i.ExternalLink,{href:"/wp-admin/admin.php?page=newspack-audience-donations",children:(0,o.__)("Edit donation settings","newspack-blocks")})]})]}),(0,a.jsx)(i.PanelBody,{title:(0,o.__)("Styling","newspack-blocks"),initialOpen:!1,children:(0,a.jsx)(f.ColorPaletteControl,{value:e.buttonColor,onChange:e=>t({buttonColor:e}),label:(0,o.__)("Button Color","newspack-blocks")})}),"nrh"===w.platform&&(0,a.jsx)(i.PanelBody,{title:(0,o.__)("News Revenue Hub Settings","newspack-blocks"),initialOpen:!1,children:(0,a.jsx)(i.TextControl,{label:(0,o.__)("Campaign ID","newspack-blocks"),value:e.campaign||"",onChange:e=>t({campaign:e})})}),window.newspack_blocks_data.supports_recaptcha&&(0,a.jsxs)(i.PanelBody,{title:(0,o.__)("Spam protection","newspack"),children:[(0,a.jsx)("p",{children:(0,o.sprintf)(
|
|
39
39
|
// translators: %s is either 'enabled' or 'disabled'.
|
|
40
40
|
// translators: %s is either 'enabled' or 'disabled'.
|
|
41
41
|
(0,o.__)("reCAPTCHA is currently %s.","newspack"),window.newspack_blocks_data.has_recaptcha?(0,o.__)("enabled","newspack"):(0,o.__)("disabled","newspack"))}),!window.newspack_blocks_data.has_recaptcha&&(0,a.jsx)("p",{children:(0,o.__)("It's highly recommended that you enable reCAPTCHA protection to prevent spambots from using this form!","newspack")}),(0,a.jsx)("p",{children:(0,a.jsx)("a",{href:window.newspack_blocks_data.recaptcha_url,children:(0,o.__)("Configure your reCAPTCHA settings.","newspack")})})]}),(0,a.jsx)(i.PanelBody,{title:(0,o.__)("After purchase","newspack-blocks"),children:(0,a.jsx)(L.A,{setAttributes:t,attributes:e})})]})]})},save:()=>null};(0,e.registerBlockStyle)("newspack-blocks/donate",{name:"alternate",label:(0,o.__)("Alternate","newspack-blocks")}),(0,e.registerBlockStyle)("newspack-blocks/donate",{name:"minimal",label:(0,o.__)("Minimal","newspack-blocks")}),(0,e.registerBlockStyle)("newspack-blocks/donate",{name:"modern",label:(0,o.__)("Modern","newspack-blocks")}),(0,e.registerBlockType)(`newspack-blocks/${z}`,R)})(),(()=>{"use strict";var e=s(4997),t=s(4727),n=s(5573),a=s(790);const r=(0,a.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,a.jsx)(n.Path,{d:"M6.5 12.75H11V14.25H6.5V12.75ZM6.5 11.25H14.5V9.75H6.5V11.25ZM6.5 8.25H14.5V6.75H6.5V8.25ZM16.375 18H4.625C4.19402 18 3.7807 17.8288 3.47595 17.524C3.1712 17.2193 3 16.806 3 16.375V4.625C3 3.728 3.728 3 4.625 3H16.375C17.273 3 18 3.728 18 4.625V16.375C18 17.273 17.273 18 16.375 18ZM4.625 16.5H16.375C16.4082 16.5 16.4399 16.4868 16.4634 16.4634C16.4868 16.4399 16.5 16.4082 16.5 16.375V4.625C16.5 4.59185 16.4868 4.56005 16.4634 4.53661C16.4399 4.51317 16.4082 4.5 16.375 4.5H4.625C4.59185 4.5 4.56005 4.51317 4.53661 4.53661C4.51317 4.56005 4.5 4.59185 4.5 4.625V16.375C4.5 16.444 4.556 16.5 4.625 16.5ZM20.25 19C20.25 19.69 19.69 20.25 19.001 20.25H6V21.75H19.001C19.3621 21.75 19.7196 21.6789 20.0532 21.5406C20.3868 21.4024 20.6899 21.1999 20.9452 20.9445C21.2005 20.6891 21.4029 20.3859 21.541 20.0523C21.6791 19.7187 21.7501 19.3611 21.75 19V8H20.25V19Z"})});var i=s(2619),o=s(7723),l=s(1225),c=s(2859),d=s(6175),u=s(766),p=s(6942),h=s.n(p);const f=(0,a.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,a.jsx)(n.Path,{d:"M18.714 6H5.286C4.67971 6 4.09826 6.24085 3.66955 6.66955C3.24085 7.09826 3 7.67972 3 8.286V15.714C3 16.0142 3.05913 16.3115 3.17401 16.5888C3.28889 16.8662 3.45728 17.1182 3.66955 17.3304C3.88183 17.5427 4.13384 17.7111 4.41119 17.826C4.68854 17.9409 4.9858 18 5.286 18H18.714C19.3203 18 19.9017 17.7592 20.3304 17.3304C20.7592 16.9017 21 16.3203 21 15.714V8.286C21 7.67972 20.7592 7.09826 20.3304 6.66955C19.9017 6.24085 19.3203 6 18.714 6ZM19.5 15.714C19.5 15.9225 19.4172 16.1224 19.2698 16.2698C19.1224 16.4172 18.9225 16.5 18.714 16.5H5.286C5.07754 16.5 4.87762 16.4172 4.73021 16.2698C4.58281 16.1224 4.5 15.9225 4.5 15.714V8.286C4.5 7.852 4.852 7.5 5.286 7.5H18.714C19.148 7.5 19.5 7.852 19.5 8.286V15.714Z"})}),m=(0,a.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,a.jsx)(n.Path,{d:"M15.714 3H8.286C7.67972 3 7.09826 3.24085 6.66955 3.66955C6.24085 4.09826 6 4.67971 6 5.286V18.714C6 19.3203 6.24085 19.9017 6.66955 20.3304C7.09826 20.7592 7.67972 21 8.286 21H15.714C16.0142 21 16.3115 20.9409 16.5888 20.826C16.8662 20.7111 17.1182 20.5427 17.3304 20.3304C17.5427 20.1182 17.7111 19.8662 17.826 19.5888C17.9409 19.3115 18 19.0142 18 18.714V5.286C18 4.67971 17.7592 4.09826 17.3304 3.66955C16.9017 3.24085 16.3203 3 15.714 3ZM16.5 18.714C16.5 18.9225 16.4172 19.1224 16.2698 19.2698C16.1224 19.4172 15.9225 19.5 15.714 19.5H8.286C8.07754 19.5 7.87762 19.4172 7.73021 19.2698C7.58281 19.1224 7.5 18.9225 7.5 18.714V5.286C7.5 4.852 7.852 4.5 8.286 4.5H15.714C16.148 4.5 16.5 4.852 16.5 5.286V18.714Z"})}),g=(0,a.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,a.jsx)(n.Path,{d:"M18.714 3H5.286C4.67971 3 4.09826 3.24085 3.66955 3.66955C3.24085 4.09826 3 4.67971 3 5.286V18.714C3 19.3203 3.24085 19.9017 3.66955 20.3304C4.09826 20.7592 4.67971 21 5.286 21H18.714C19.3203 21 19.9017 20.7592 20.3304 20.3304C20.7592 19.9017 21 19.3203 21 18.714V5.286C21 4.67971 20.7592 4.09826 20.3304 3.66955C19.9017 3.24085 19.3203 3 18.714 3ZM19.5 18.714C19.5 18.9225 19.4172 19.1224 19.2698 19.2698C19.1224 19.4172 18.9225 19.5 18.714 19.5H5.286C5.07754 19.5 4.87762 19.4172 4.73021 19.2698C4.58281 19.1224 4.5 18.9225 4.5 18.714V5.286C4.5 4.852 4.852 4.5 5.286 4.5H18.714C19.148 4.5 19.5 4.852 19.5 5.286V18.714Z"})});var v=s(6087),b=s(4715),w=s(6427),y=s(7143),x=s(9491),_=s(8537),k=(0,a.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,a.jsx)(n.Path,{d:"M12.9 6h-2l-4 11h1.9l1.1-3h4.2l1.1 3h1.9L12.9 6zm-2.5 6.5l1.5-4.9 1.7 4.9h-3.2z"})}),S=(0,a.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,a.jsx)(n.Path,{d:"m7.5 6h9v-1.5h-9zm0 13.5h9v-1.5h-9zm-3-3h1.5v-9h-1.5zm13.5-9v9h1.5v-9z"})}),C=(0,a.jsx)(n.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,a.jsx)(n.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})}),E=s(9936),T=(0,a.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,a.jsx)(n.Path,{d:"M19 3H5c-.6 0-1 .4-1 1v7c0 .5.4 1 1 1h14c.5 0 1-.4 1-1V4c0-.6-.4-1-1-1zM5.5 10.5v-.4l1.8-1.3 1.3.8c.3.2.7.2.9-.1L11 8.1l2.4 2.4H5.5zm13 0h-2.9l-4-4c-.3-.3-.8-.3-1.1 0L8.9 8l-1.2-.8c-.3-.2-.6-.2-.9 0l-1.3 1V4.5h13v6zM4 20h9v-1.5H4V20zm0-4h16v-1.5H4V16z"})}),j=s(1417),M=s(3216),P=(0,a.jsx)(n.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,a.jsx)(n.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5 4.5h14c.3 0 .5.2.5.5v8.4l-3-2.9c-.3-.3-.8-.3-1 0L11.9 14 9 12c-.3-.2-.6-.2-.8 0l-3.6 2.6V5c-.1-.3.1-.5.4-.5zm14 15H5c-.3 0-.5-.2-.5-.5v-2.4l4.1-3 3 1.9c.3.2.7.2.9-.1L16 12l3.5 3.4V19c0 .3-.2.5-.5.5z"})}),A=(0,a.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,a.jsx)(n.Path,{d:"M6 4a2 2 0 0 0-2 2v3h1.5V6a.5.5 0 0 1 .5-.5h3V4H6Zm3 14.5H6a.5.5 0 0 1-.5-.5v-3H4v3a2 2 0 0 0 2 2h3v-1.5Zm6 1.5v-1.5h3a.5.5 0 0 0 .5-.5v-3H20v3a2 2 0 0 1-2 2h-3Zm3-16a2 2 0 0 1 2 2v3h-1.5V6a.5.5 0 0 0-.5-.5h-3V4h3Z"})});let L;"object"==typeof window&&window.newspack_blocks_data&&window.newspack_blocks_data.post_subtitle&&(L=!0);class I extends v.Component{renderPost=e=>{const{attributes:t,isUIDisabled:s}=this.props,{showImage:n,imageShape:r,mediaPosition:i,minHeight:o,showCaption:l,showCredit:c,showExcerpt:u,showFullContent:p,showReadMore:f,readMoreLabel:m,showSubtitle:g,showAuthor:w,showAvatar:y,showDate:x,showCategory:k,sectionHeader:S}=t,C={minHeight:"behind"===i&&n&&e.newspack_featured_image_src&&o+"vh"||void 0,paddingTop:"behind"===i&&n&&e.newspack_featured_image_src&&o/5+"vh"||void 0},E=h()({"post-has-image":e.newspack_featured_image_src,"newspack-block--disabled":s},e.newspack_article_classes),T=this.titleForPost(e);return(0,a.jsxs)("article",{className:E,style:C,children:[(0,d.X8)(e),n&&e.newspack_featured_image_src&&(0,a.jsxs)("figure",{className:"post-thumbnail",children:[(0,a.jsxs)("a",{href:"#",children:["landscape"===r&&(0,a.jsx)("img",{src:e.newspack_featured_image_src.landscape,alt:""}),"portrait"===r&&(0,a.jsx)("img",{src:e.newspack_featured_image_src.portrait,alt:""}),"square"===r&&(0,a.jsx)("img",{src:e.newspack_featured_image_src.square,alt:""}),"uncropped"===r&&(0,a.jsx)("img",{src:e.newspack_featured_image_src.uncropped,alt:""})]}),(l||c)&&(0,a.jsx)("div",{dangerouslySetInnerHTML:{__html:e.newspack_featured_image_caption}})]},"thumbnail"),(0,a.jsxs)("div",{className:"entry-wrapper",children:[(e.newspack_post_sponsors||k&&0<e.newspack_category_info.length)&&(0,a.jsxs)("div",{className:"cat-links"+(e.newspack_post_sponsors?" sponsor-label":""),children:[e.newspack_post_sponsors&&(0,a.jsx)("span",{className:"flag",children:e.newspack_post_sponsors[0].flag}),k&&(!e.newspack_post_sponsors||e.newspack_sponsors_show_categories)&&(0,a.jsx)(v.RawHTML,{children:(0,_.decodeEntities)(e.newspack_category_info)})]}),b.RichText.isEmpty(S)?(0,a.jsx)("h2",{className:"entry-title",children:(0,a.jsx)("a",{href:"#",children:T})},"title"):(0,a.jsx)("h3",{className:"entry-title",children:(0,a.jsx)("a",{href:"#",children:T})},"title"),L&&g&&(0,a.jsx)(v.RawHTML,{className:"newspack-post-subtitle newspack-post-subtitle--in-homepage-block",children:e.meta.newspack_post_subtitle||""},"subtitle"),u&&!p&&(0,a.jsx)(v.RawHTML,{className:"excerpt-contain",children:e.excerpt.rendered},"excerpt"),!u&&p&&(0,a.jsx)(v.RawHTML,{className:"excerpt-contain",children:e.full_content},"full-content"),f&&e.post_link&&(0,a.jsx)("a",{href:"#",className:"more-link",children:m},"readmore"),(0,a.jsxs)("div",{className:"entry-meta",children:[e.newspack_post_sponsors&&(0,a.jsxs)("span",{className:"entry-sponsors "+(e.newspack_sponsors_show_author?"plus-author":""),children:[(0,d.__)(e.newspack_post_sponsors),(0,d.vQ)(e.newspack_post_sponsors)]}),w&&!e.newspack_listings_hide_author&&(!e.newspack_post_sponsors||e.newspack_sponsors_show_author)&&(0,a.jsx)(v.RawHTML,{className:"byline-container",children:(0,d.pO)(e,y)}),x&&!e.newspack_listings_hide_publish_date&&(0,a.jsx)("time",{className:"entry-date published",children:e.date_formatted},"pub-date"),e.article_meta_footer?(0,a.jsx)(v.RawHTML,{children:e.article_meta_footer}):null]})]})]},e.id)};titleForPost=e=>e.title?"object"==typeof e.title&&e.title.rendered?(0,_.decodeEntities)(e.title.rendered.trim()):void 0:"";renderInspectorControls=()=>{const{attributes:e,setAttributes:t}=this.props,{authors:s,specificPosts:n,postsToShow:r,categories:i,includeSubcategories:d,categoryJoinType:p,customTaxonomies:h,columns:f,postType:m,showImage:g,showCaption:b,showCredit:y,imageScale:x,mobileStack:_,minHeight:k,moreButton:S,infiniteScroll:C,showExcerpt:E,showFullContent:T,showReadMore:j,readMoreLabel:M,excerptLength:P,showSubtitle:A,showDate:I,showAuthor:O,showAvatar:N,showCategory:z,postLayout:D,mediaPosition:$,specificMode:B,tags:R,tagExclusions:F,categoryExclusions:H,customTaxonomyExclusions:V}=e,G=[{value:1,label:/* translators: label for small size option */ /* translators: label for small size option */(0,o.__)("Small","newspack-blocks"),shortName:/* translators: abbreviation for small size */ /* translators: abbreviation for small size */(0,o.__)("S","newspack-blocks")},{value:2,label:/* translators: label for medium size option */ /* translators: label for medium size option */(0,o.__)("Medium","newspack-blocks"),shortName:/* translators: abbreviation for medium size */ /* translators: abbreviation for medium size */(0,o.__)("M","newspack-blocks")},{value:3,label:/* translators: label for large size option */ /* translators: label for large size option */(0,o.__)("Large","newspack-blocks"),shortName:/* translators: abbreviation for large size */ /* translators: abbreviation for large size */(0,o.__)("L","newspack-blocks")},{value:4,label:/* translators: label for extra large size option */ /* translators: label for extra large size option */(0,o.__)("Extra Large","newspack-blocks"),shortName:/* translators: abbreviation for extra large size */ /* translators: abbreviation for extra large size */(0,o.__)("XL","newspack-blocks")}],q=e=>s=>t({[e]:s});return(0,a.jsxs)(v.Fragment,{children:["grid"===D&&(0,a.jsx)(w.PanelBody,{title:(0,o.__)("Grid","newspack-blocks"),children:(0,a.jsx)(w.RangeControl,{label:(0,o.__)("Columns","newspack-blocks"),value:f,onChange:q("columns"),min:2,max:6,required:!0,__next40pxDefaultSize:!0})}),(0,a.jsxs)(w.PanelBody,{title:(0,o.__)("Settings","newspack-blocks"),className:"newspack-block__panel is-content",children:[(0,a.jsx)(l.A,{numberOfItems:r,onNumberOfItemsChange:e=>t({postsToShow:e||1}),specificMode:B,onSpecificModeChange:()=>t({specificMode:!0}),onLoopModeChange:()=>t({specificMode:!1}),specificPosts:n,onSpecificPostsChange:q("specificPosts"),authors:s,onAuthorsChange:q("authors"),categories:i,onCategoriesChange:q("categories"),includeSubcategories:d,onIncludeSubcategoriesChange:q("includeSubcategories"),categoryJoinType:p,onCategoryJoinTypeChange:q("categoryJoinType"),tags:R,onTagsChange:q("tags"),onCustomTaxonomiesChange:q("customTaxonomies"),customTaxonomies:h,tagExclusions:F,onTagExclusionsChange:q("tagExclusions"),categoryExclusions:H,onCategoryExclusionsChange:q("categoryExclusions"),customTaxonomyExclusions:V,onCustomTaxonomyExclusionsChange:q("customTaxonomyExclusions"),postType:m}),(0,a.jsx)(w.ToggleControl,{label:(0,o.__)("Allow duplicate content","newspack-blocks"),help:(0,o.__)("Exclude this block from the page's deduplication logic.","newspack-blocks"),checked:!e.deduplicate,onChange:e=>t({deduplicate:!e})}),!B&&(0,c.Wu)()?(0,a.jsx)(w.ToggleControl,{label:(0,o.__)('Show "Load more posts" button',"newspack-blocks"),help:(0,o.__)("This site is private, therefore this feature is not active.","newspack-blocks"),disabled:!0}):!B&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(w.ToggleControl,{label:(0,o.__)('Show "Load more posts" button',"newspack-blocks"),checked:S,onChange:()=>t({moreButton:!S})}),(0,a.jsx)(w.ToggleControl,{label:(0,o.__)("Infinite scroll","newspack-blocks"),checked:C,disabled:!S,onChange:()=>t({infiniteScroll:!C})})]})]}),(0,a.jsxs)(w.PanelBody,{title:(0,o.__)("Display","newspack-blocks"),className:"newspack-block__panel",children:[(0,a.jsxs)(w.__experimentalToggleGroupControl,{label:(0,o.__)("Text","newspack-blocks"),value:T?"full":E?"excerpt":"none",onChange:e=>{t({showExcerpt:"excerpt"===e,showFullContent:"full"===e})},isBlock:!0,__next40pxDefaultSize:!0,children:[(0,a.jsx)(w.__experimentalToggleGroupControlOption,{label:(0,o.__)("None","newspack-blocks"),value:"none"}),(0,a.jsx)(w.__experimentalToggleGroupControlOption,{label:(0,o.__)("Excerpt","newspack-blocks"),value:"excerpt"}),(0,a.jsx)(w.__experimentalToggleGroupControlOption,{label:(0,o.__)("Full Post","newspack-blocks"),value:"full"})]}),E&&(0,a.jsx)(w.RangeControl,{label:(0,o.__)("Max number of words in excerpt","newspack-blocks"),value:P,onChange:e=>t({excerptLength:e}),min:10,max:100,__next40pxDefaultSize:!0}),!T&&(0,a.jsx)(w.ToggleControl,{label:(0,o.sprintf)(
|
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.18.0-alpha.
|
|
10
|
+
* Version: 4.18.0-alpha.2
|
|
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.18.0-alpha.
|
|
18
|
+
define( 'NEWSPACK_BLOCKS__VERSION', '4.18.0-alpha.2' );
|
|
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.18.0-alpha.
|
|
3
|
+
"version": "4.18.0-alpha.2",
|
|
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": {
|
|
@@ -15,13 +15,13 @@ import { FREQUENCIES, DISABLED_IN_TIERS_BASED_LAYOUT_TIER_INDEX } from '../const
|
|
|
15
15
|
|
|
16
16
|
const TierBasedLayout = ( props: ComponentProps ) => {
|
|
17
17
|
const { amounts, availableFrequencies, attributes } = props;
|
|
18
|
-
const [ currentFrequency, setCurrencyFrequency ] = useState( availableFrequencies[ 0 ] );
|
|
18
|
+
const [ currentFrequency, setCurrencyFrequency ] = useState( attributes.defaultFrequency || availableFrequencies[ 0 ] );
|
|
19
19
|
|
|
20
20
|
const displayedAmounts = amounts[ currentFrequency ].slice( 0, DISABLED_IN_TIERS_BASED_LAYOUT_TIER_INDEX );
|
|
21
21
|
|
|
22
22
|
useEffect( () => {
|
|
23
|
-
setCurrencyFrequency( availableFrequencies[ 0 ] );
|
|
24
|
-
}, [ availableFrequencies.length ] );
|
|
23
|
+
setCurrencyFrequency( attributes.defaultFrequency || availableFrequencies[ 0 ] );
|
|
24
|
+
}, [ availableFrequencies.length, attributes.defaultFrequency ] );
|
|
25
25
|
|
|
26
26
|
const handleTierOptionChange = ( tierIndex: number, optionKey: keyof TierBasedOptionValue ) => ( value: string ) => {
|
|
27
27
|
const tiersBasedOptions: DonateBlockAttributes[ 'tiersBasedOptions' ] = [
|
|
@@ -242,17 +242,15 @@ const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
|
|
|
242
242
|
{ __( 'Tiers layout is disabled if the block is set to render untiered.', 'newspack-blocks' ) }
|
|
243
243
|
</Notice>
|
|
244
244
|
) }
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
/>
|
|
255
|
-
) }
|
|
245
|
+
<SelectControl
|
|
246
|
+
label={ __( 'Default Tab', 'newspack-blocks' ) }
|
|
247
|
+
value={ attributes.defaultFrequency }
|
|
248
|
+
options={ availableFrequencies.map( key => ( {
|
|
249
|
+
label: FREQUENCIES[ key ],
|
|
250
|
+
value: key,
|
|
251
|
+
} ) ) }
|
|
252
|
+
onChange={ ( defaultFrequency: DonationFrequencySlug ) => setAttributes( { defaultFrequency } ) }
|
|
253
|
+
/>
|
|
256
254
|
</PanelBody>
|
|
257
255
|
{ canUseNameYourPrice && (
|
|
258
256
|
<PanelBody title={ __( 'Suggested Donations', 'newspack-blocks' ) }>
|
|
@@ -99,7 +99,11 @@ class Newspack_Blocks_Donate_Renderer_Tiers_Based extends Newspack_Blocks_Donate
|
|
|
99
99
|
public static function render( $attributes ) {
|
|
100
100
|
$configuration = self::get_configuration( $attributes );
|
|
101
101
|
$displayed_frequencies = array_keys( $configuration['frequencies'] );
|
|
102
|
-
$
|
|
102
|
+
if ( isset( $attributes['defaultFrequency'] ) && in_array( $attributes['defaultFrequency'], $displayed_frequencies, true ) ) {
|
|
103
|
+
$intial_selected_frequency = $attributes['defaultFrequency'];
|
|
104
|
+
} else {
|
|
105
|
+
$intial_selected_frequency = $displayed_frequencies[0];
|
|
106
|
+
}
|
|
103
107
|
|
|
104
108
|
$displayed_amounts = self::get_displayed_amounts( $configuration['amounts'][ $intial_selected_frequency ] );
|
|
105
109
|
$config_related_attributes = array_map(
|
|
@@ -333,12 +333,14 @@ domReady( () => {
|
|
|
333
333
|
if ( variationModal ) {
|
|
334
334
|
variationModal.querySelectorAll( `form[target="${ IFRAME_NAME }"]` ).forEach( singleVariationForm => {
|
|
335
335
|
// Fill in the hidden params in the variation modal.
|
|
336
|
-
[ 'after_success_behavior', 'after_success_url', 'after_success_button_label', 'gate_post_id', 'newspack_popup_id' ].forEach(
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
336
|
+
[ 'after_success_behavior', 'after_success_url', 'after_success_button_label', 'gate_post_id', 'newspack_popup_id' ].forEach(
|
|
337
|
+
hiddenParam => {
|
|
338
|
+
const existingInputs = singleVariationForm.querySelectorAll( 'input[name="' + hiddenParam + '"]' );
|
|
339
|
+
if ( 0 === existingInputs.length ) {
|
|
340
|
+
singleVariationForm.prepend( createHiddenInput( hiddenParam, checkoutData[ hiddenParam ] ) );
|
|
341
|
+
}
|
|
340
342
|
}
|
|
341
|
-
|
|
343
|
+
);
|
|
342
344
|
|
|
343
345
|
// Append the product data hidden inputs.
|
|
344
346
|
const variationData = singleVariationForm.dataset.checkout;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
'name' => 'automattic/newspack-blocks',
|
|
4
4
|
'pretty_version' => 'dev-trunk',
|
|
5
5
|
'version' => 'dev-trunk',
|
|
6
|
-
'reference' => '
|
|
6
|
+
'reference' => '2d07c111cd678138ad09cec2b768fc7c98e1d35b',
|
|
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' => '
|
|
16
|
+
'reference' => '2d07c111cd678138ad09cec2b768fc7c98e1d35b',
|
|
17
17
|
'type' => 'wordpress-plugin',
|
|
18
18
|
'install_path' => __DIR__ . '/../../',
|
|
19
19
|
'aliases' => array(),
|