woocommerce-subscriptions/build/index.js

36 lines
14 KiB
JavaScript

(()=>{"use strict";var e={20:(e,s,i)=>{var n=i(609),t=Symbol.for("react.element"),r=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,c=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function l(e,s,i){var n,r={},l=null,p=null;for(n in void 0!==i&&(l=""+i),void 0!==s.key&&(l=""+s.key),void 0!==s.ref&&(p=s.ref),s)o.call(s,n)&&!a.hasOwnProperty(n)&&(r[n]=s[n]);if(e&&e.defaultProps)for(n in s=e.defaultProps)void 0===r[n]&&(r[n]=s[n]);return{$$typeof:t,type:e,key:l,ref:p,props:r,_owner:c.current}}s.Fragment=r,s.jsx=l,s.jsxs=l},609:e=>{e.exports=window.React},848:(e,s,i)=>{e.exports=i(20)}},s={};const i=window.wp.plugins,n=window.wc.blocksCheckout,t=window.wp.i18n,r=window.wc.priceFormat,o=window.wc.wcSettings,c=window.wp.data,a=window.wc.wcBlocksData;function l(e){return{day:(0,t._nx)("day","days",e,"Used in recurring totals section in Cart. 2+ will need plural, 1 will need singular.","woocommerce-subscriptions"),week:(0,t._nx)("week","weeks",e,"Used in recurring totals section in Cart. 2+ will need plural, 1 will need singular.","woocommerce-subscriptions"),month:(0,t._nx)("month","months",e,"Used in recurring totals section in Cart. 2+ will need plural, 1 will need singular.","woocommerce-subscriptions"),year:(0,t._nx)("year","years",e,"Used in recurring totals section in Cart. 2+ will need plural, 1 will need singular.","woocommerce-subscriptions")}}function p({billing_interval:e,billing_period:s},i,n){const r=l(e)[s];return i=i.trim(),1===e?`${n} ${i} ${r}`:(0,t.sprintf)(
/*
* translators: %1$s is the price of the product. %2$s is the separator used e.g "every" or "/",
* %3$d is the length, %4$s is week, month, year
*/
/*
* translators: %1$s is the price of the product. %2$s is the separator used e.g "every" or "/",
* %3$d is the length, %4$s is week, month, year
*/
(0,t.__)("%1$s %2$s %3$d %4$s","woocommerce-subscriptions"),n,i,e,r)}function u({subscriptionLength:e,billingInterval:s}){return e===s}const d=(0,o.getSetting)("countryData",{}),g=(0,o.getSetting)("countries",{}),m={...Object.fromEntries(Object.keys(d).filter((e=>!0===d[e].allowBilling)).map((e=>[e,g[e]||""]))),...Object.fromEntries(Object.keys(d).filter((e=>!0===d[e].allowShipping)).map((e=>[e,g[e]||""])))},_=Object.fromEntries(Object.keys(m).map((e=>[e,d[e].locale||{}]))),b={address:["first_name","last_name","company","address_1","address_2","city","postcode","country","state","phone"],contact:["email"],order:[]},h=Object.entries(_).reduce(((e,[s,i])=>(e[s]=Object.entries(i).reduce(((e,[s,i])=>(e[s]=(e=>{const s={};return void 0!==e.label&&(s.label=e.label),void 0!==e.required&&(s.required=e.required),void 0!==e.hidden&&(s.hidden=e.hidden),void 0===e.label||e.optionalLabel||(s.optionalLabel=(0,t.sprintf)(/* translators: %s Field label. */ /* translators: %s Field label. */
(0,t.__)("%s (optional)","woocommerce-subscriptions"),e.label)),void 0!==e.optionalLabel&&(s.optionalLabel=e.optionalLabel),e.index&&("number"==typeof e.index&&(s.index=e.index),"string"==typeof e.index&&(s.index=parseInt(e.index,10))),e.hidden&&(s.required=!1),s})(i),e)),{}),e)),{}),w=["state","country","postcode","city"],y=e=>e.some((e=>!!e.shipping_rates.length)),f=(0,o.getSetting)("collectableMethodIds",[]),v=(0,o.getSetting)("localPickupEnabled",!1);var x=function i(n){var t=s[n];if(void 0!==t)return t.exports;var r=s[n]={exports:{}};return e[n](r,r.exports,i),r.exports}(848);const k=(0,o.getSetting)("displayCartPricesIncludingTax",!1),S=({currency:e,values:s,isLoading:i})=>{const{total_discount:r,total_discount_tax:o}=s,c=parseInt(r,10);if(!c)return null;const a=parseInt(o,10),l=k?c+a:c;return(0,x.jsx)(n.TotalsItem,{className:"wc-block-components-totals-discount",currency:e,label:(0,t.__)("Discount","woocommerce-subscriptions"),value:-1*l,showSkeleton:i})},j=({values:e,currency:s,shippingRatePackages:i,isLoading:n,needsShipping:r,calculatedShipping:l,shippingAddress:p})=>{const u=(0,c.useSelect)((e=>e(a.checkoutStore).prefersCollection()));if(!r||!l)return null;const d=(_=((e,s)=>e.map((e=>({...e,shipping_rates:e.shipping_rates.filter((e=>{const i=(n=e.method_id,!!v&&(Array.isArray(n)?!!n.find((e=>f.includes(e))):f.includes(n)));var n;return s?i:!i}))}))))(i,null!=u&&u),!!y(_)&&_.every((e=>e.shipping_rates.every((e=>!e.selected||(e=>f.includes(e.method_id))(e)))))),g=!!(m=p).country&&((e,s,i="")=>{const n=i&&void 0!==h[i]?h[i]:{};return e.map((e=>({key:e,...s&&e in s?s[e]:{},...n&&e in n?n[e]:{}}))).sort(((e,s)=>e.index-s.index))})((0,o.getSetting)("addressFieldsLocations",b).address,o.defaultFields,m.country).filter((({key:e})=>w.includes(e))).every((({key:e,hidden:s,required:i})=>!0===s||!1===i||e in m&&""!==m[e]));var m,_;return(0,x.jsx)(I,{label:d?(0,t.__)("Pickup","woocommerce-subscriptions"):(0,t.__)("Delivery","woocommerce-subscriptions"),placeholder:(0,x.jsx)("span",{className:"wc-block-components-shipping-placeholder__value",children:g?(0,t.__)("No available delivery option","woocommerce-subscriptions"):(0,t.__)("Enter address to calculate","woocommerce-subscriptions")}),isLoading:n,shippingRatePackages:i,currency:s,values:e})},I=({values:e,currency:s,shippingRatePackages:i,label:r,placeholder:c,isLoading:a})=>{const l=i?.flatMap((e=>e.shipping_rates)).find((({selected:e})=>e))?.name,p=!!y(u=i)&&u.some((e=>e.shipping_rates.some((e=>e.selected))));var u;const d=!p||i?.length>1?r:(0,t.__)("Shipping","woocommerce-subscriptions"),g=k?parseInt(e.total_shipping,10)+parseInt(e.total_shipping_tax,10):parseInt(e.total_shipping,10),m=0===g&&(0,o.isWcVersion)("9.0",">=")?(0,x.jsx)("strong",{children:(0,t.__)("Free","woocommerce-subscriptions")}):g;return(0,x.jsx)(n.TotalsItem,{value:p?m:c,label:d,currency:s,showSkeleton:a,description:!!l&&(0,t.sprintf)(
// translators: %s selected shipping rate (ex: flat rate)
// translators: %s selected shipping rate (ex: flat rate)
(0,t.__)("via %s","woocommerce-subscriptions"),l)})},L=({nextPaymentDate:e,subscriptionLength:s,billingPeriod:i,billingInterval:n})=>{const r=function({subscriptionLength:e,billingPeriod:s}){const i=l(e);return(0,t.sprintf)("For %1$d %2$s",e,i[s],"woocommerce-subscriptions")}({subscriptionLength:s,billingPeriod:i}),o=u({subscriptionLength:s,billingInterval:n})?(0,t.sprintf)(/* Translators: %1$s is a date. */ /* Translators: %1$s is a date. */
(0,t.__)("Due: %1$s","woocommerce-subscriptions"),e):(0,t.sprintf)(/* Translators: %1$s is a date. */ /* Translators: %1$s is a date. */
(0,t.__)("Starting: %1$s","woocommerce-subscriptions"),e);return(0,x.jsxs)("span",{children:[!!e&&o," ",!!s&&s>=n&&(0,x.jsx)("span",{className:"wcs-recurring-totals__subscription-length",children:r})]})},P=({currency:e,billingInterval:s,billingPeriod:i,nextPaymentDate:r,subscriptionLength:o,totals:c,isLoading:a})=>{const l=u({billingInterval:s,subscriptionLength:o})?(0,t.__)("Total","woocommerce-subscriptions"):function({billingInterval:e,billingPeriod:s}){switch(e){case 1:if("day"===s)return(0,t.__)("Daily recurring total","woocommerce-subscriptions");if("week"===s)return(0,t.__)("Weekly recurring total","woocommerce-subscriptions");if("month"===s)return(0,t.__)("Monthly recurring total","woocommerce-subscriptions");if("year"===s)return(0,t.__)("Yearly recurring total","woocommerce-subscriptions");break;case 2:return(0,t.sprintf)(/* translators: %1$s is week, month, year */ /* translators: %1$s is week, month, year */
(0,t.__)("Recurring total every 2nd %1$s","woocommerce-subscriptions"),s);case 3:return(0,t.sprintf)(/* Translators: %1$s is week, month, year */ /* Translators: %1$s is week, month, year */
(0,t.__)("Recurring total every 3rd %1$s","woocommerce-subscriptions"),s);default:return(0,t.sprintf)(/* Translators: %1$d is number of weeks, months, days, years. %2$s is week, month, year */ /* Translators: %1$d is number of weeks, months, days, years. %2$s is week, month, year */
(0,t.__)("Recurring total every %1$dth %2$s","woocommerce-subscriptions"),e,s)}}({billingInterval:s,billingPeriod:i});return(0,x.jsx)(n.TotalsItem,{className:"wcs-recurring-totals-panel__title",currency:e,label:l,value:c,showSkeleton:a,description:(0,x.jsx)(L,{nextPaymentDate:r,subscriptionLength:o,billingInterval:s,billingPeriod:i})})},O=({subscription:e,needsShipping:s,calculatedShipping:i,shippingAddress:o})=>{const{isLoading:l}=(()=>{const{cartIsLoading:e,isLoadingRates:s,hasPendingItemsOperations:i,isApplyingCoupon:n,isRemovingCoupon:t}=(0,c.useSelect)((e=>{const s=e(a.cartStore);return{cartIsLoading:!s.hasFinishedResolution("getCartData",[]),isLoadingRates:s.isAddressFieldsForShippingRatesUpdating(),hasPendingItemsOperations:s.hasPendingItemsOperations(),isApplyingCoupon:s.isApplyingCoupon(),isRemovingCoupon:s.isRemovingCoupon()}}),[]),r=(0,c.useSelect)((e=>e(a.checkoutStore).isCalculating()),[]);return{isLoading:e||s||n||t||r||i}})(),{totals:p,billing_interval:u,billing_period:d,next_payment_date:g,subscription_length:m,shipping_rates:_}=e;if(!g)return null;const b=(0,r.getCurrencyFromPriceResponse)(p);return(0,x.jsxs)("div",{className:"wcs-recurring-totals-panel",children:[(0,x.jsx)(P,{billingInterval:u,billingPeriod:d,nextPaymentDate:g,subscriptionLength:m,totals:parseInt(p.total_price,10),currency:b,isLoading:l}),(0,x.jsxs)(n.Panel,{className:"wcs-recurring-totals-panel__details",initialOpen:!1,title:(0,t.__)("Details","woocommerce-subscriptions"),children:[(0,x.jsxs)(n.TotalsWrapper,{children:[(0,x.jsx)(n.Subtotal,{currency:b,values:p,showSkeleton:l}),(0,x.jsx)(S,{currency:b,values:p,isLoading:l})]}),(0,x.jsx)(n.TotalsWrapper,{className:"wc-block-components-totals-shipping",children:(0,x.jsx)(j,{currency:b,needsShipping:s,calculatedShipping:i,values:p,shippingAddress:o,shippingRatePackages:_,isLoading:l})}),!k&&(0,x.jsx)(n.TotalsWrapper,{children:(0,x.jsx)(n.TotalsTaxes,{currency:b,values:p})}),(0,x.jsx)(n.TotalsWrapper,{children:(0,x.jsx)(n.TotalsItem,{className:"wcs-recurring-totals-panel__details-total",currency:b,label:(0,t.__)("Total","woocommerce-subscriptions"),value:parseInt(p.total_price,10),showSkeleton:l})})]})]})},R=({extensions:e,cart:s})=>{const{subscriptions:i}=e,{cartNeedsShipping:n,cartHasCalculatedShipping:t,shippingAddress:r}=s;return i&&0!==i.length?i.map((({key:e,...s})=>(0,x.jsx)(O,{subscription:s,needsShipping:n,calculatedShipping:t,shippingAddress:r},e))):null},C=window.wp.element,$=({extensions:e,collapsible:s,collapse:i,showItems:n,noResultsMessage:t,renderOption:r,components:o,context:c})=>{const{subscriptions:a=[]}=e,{ShippingRatesControlPackage:l}=o,p=(0,C.useMemo)((()=>Object.values(a).map((e=>e.shipping_rates)).filter(Boolean).flat()),[a]),u=(0,C.useMemo)((()=>p.length>1||i),[p.length,i]),d=(0,C.useMemo)((()=>p.length>1||n),[p.length,n]);return p.filter((e=>!e.match_initial_rates&&e.needs_shipping)).map((({package_id:e,...i})=>(0,x.jsx)(l,{packageId:e,packageData:i,collapsible:s,collapse:u,showItems:d,noResultsMessage:t,renderOption:r,highlightChecked:"woocommerce/checkout"===c},e)))};(0,i.registerPlugin)("woocommerce-subscriptions",{render:()=>(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(n.ExperimentalOrderShippingPackages,{children:(0,x.jsx)($,{})}),(0,x.jsx)(n.ExperimentalOrderMeta,{children:(0,x.jsx)(R,{})})]}),scope:"woocommerce-checkout"}),(0,n.registerCheckoutFilters)("woocommerce-subscriptions",{totalLabel:(e,{subscriptions:s})=>s?.length>0?(0,t.__)("Total due today","woocommerce-subscriptions"):e,subtotalPriceFormat:(e,{subscriptions:s})=>{if(s?.billing_period&&s?.billing_interval){const{billing_interval:i,subscription_length:n}=s;return u({subscriptionLength:n,billingInterval:i})?p(s,1===n?
// translators: the word used to describe billing frequency, e.g. "for" 1 day or "for" 1 month.
// translators: the word used to describe billing frequency, e.g. "for" 1 day or "for" 1 month.
(0,t.__)("for 1","woocommerce-subscriptions"):
// translators: the word used to describe billing frequency, e.g. "for" 6 days or "for" 2 weeks.
// translators: the word used to describe billing frequency, e.g. "for" 6 days or "for" 2 weeks.
(0,t.__)("for","woocommerce-subscriptions"),e):p(s,
// translators: the word used to describe billing frequency, e.g. "every" 6 days or "every" 2 weeks.
// translators: the word used to describe billing frequency, e.g. "every" 6 days or "every" 2 weeks.
(0,t.__)("every","woocommerce-subscriptions"),e)}return e},saleBadgePriceFormat:(e,{subscriptions:s})=>s?.billing_period&&s?.billing_interval?p(s,"/",e):e,itemName:(e,{subscriptions:s})=>s?.is_resubscribe?(0,t.sprintf)(
// translators: %s Product name.
// translators: %s Product name.
(0,t.__)("%s (resubscription)","woocommerce-subscriptions"),e):s?.switch_type?(0,t.sprintf)(
// translators: %1$s Product name, %2$s Switch type (upgraded, downgraded, or crossgraded).
// translators: %1$s Product name, %2$s Switch type (upgraded, downgraded, or crossgraded).
(0,t.__)("%1$s (%2$s)","woocommerce-subscriptions"),e,function(e){switch(e){case"upgraded":return(0,t.__)("Upgrade","woocommerce-subscriptions");case"downgraded":return(0,t.__)("Downgrade","woocommerce-subscriptions");case"crossgraded":return(0,t.__)("Crossgrade","woocommerce-subscriptions");default:return""}}(s.switch_type)):e,cartItemPrice:(e,{subscriptions:s},{context:i})=>s?.sign_up_fees?"cart"===i?(0,t.sprintf)(/* translators: %s is the subscription price to pay immediately (ie: $10). */ /* translators: %s is the subscription price to pay immediately (ie: $10). */
(0,t.__)("Due today %s","woocommerce-subscriptions"),e):(0,t.sprintf)(/* translators: %s is the subscription price to pay immediately (ie: $10). */ /* translators: %s is the subscription price to pay immediately (ie: $10). */
(0,t.__)("%s due today","woocommerce-subscriptions"),e):e,placeOrderButtonLabel:e=>{const s=(0,o.getSetting)("subscriptions_data");return s?.place_order_override?s?.place_order_override:e}})})();