Files
php_assessment_2/wp-content/plugins/woocommerce/assets/client/blocks/wc-blocks-data.js
T

5 lines
74 KiB
JavaScript
Raw Normal View History

2025-02-05 23:15:46 +01:00
(()=>{"use strict";var e={136:e=>{var t,r=function(){function e(e,t){if("function"!=typeof e)throw new TypeError("DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but got: "+e+".");this._batchLoadFn=e,this._maxBatchSize=function(e){if(!(!e||!1!==e.batch))return 1;var t=e&&e.maxBatchSize;if(void 0===t)return 1/0;if("number"!=typeof t||t<1)throw new TypeError("maxBatchSize must be a positive number: "+t);return t}(t),this._batchScheduleFn=function(e){var t=e&&e.batchScheduleFn;if(void 0===t)return a;if("function"!=typeof t)throw new TypeError("batchScheduleFn must be a function: "+t);return t}(t),this._cacheKeyFn=function(e){var t=e&&e.cacheKeyFn;if(void 0===t)return function(e){return e};if("function"!=typeof t)throw new TypeError("cacheKeyFn must be a function: "+t);return t}(t),this._cacheMap=function(e){if(!(!e||!1!==e.cache))return null;var t=e&&e.cacheMap;if(void 0===t)return new Map;if(null!==t){var r=["get","set","delete","clear"].filter((function(e){return t&&"function"!=typeof t[e]}));if(0!==r.length)throw new TypeError("Custom cacheMap missing methods: "+r.join(", "))}return t}(t),this._batch=null,this.name=function(e){return e&&e.name?e.name:null}(t)}var t=e.prototype;return t.load=function(e){if(null==e)throw new TypeError("The loader.load() function must be called with a value, but got: "+String(e)+".");var t=function(e){var t=e._batch;if(null!==t&&!t.hasDispatched&&t.keys.length<e._maxBatchSize)return t;var r={hasDispatched:!1,keys:[],callbacks:[]};return e._batch=r,e._batchScheduleFn((function(){!function(e,t){if(t.hasDispatched=!0,0!==t.keys.length){var r;try{r=e._batchLoadFn(t.keys)}catch(r){return s(e,t,new TypeError("DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function errored synchronously: "+String(r)+"."))}if(!r||"function"!=typeof r.then)return s(e,t,new TypeError("DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise: "+String(r)+"."));r.then((function(e){if(!o(e))throw new TypeError("DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise of an Array: "+String(e)+".");if(e.length!==t.keys.length)throw new TypeError("DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise of an Array of the same length as the Array of keys.\n\nKeys:\n"+String(t.keys)+"\n\nValues:\n"+String(e));i(t);for(var r=0;r<t.callbacks.length;r++){var a=e[r];a instanceof Error?t.callbacks[r].reject(a):t.callbacks[r].resolve(a)}})).catch((function(r){s(e,t,r)}))}else i(t)}(e,r)})),r}(this),r=this._cacheMap,a=this._cacheKeyFn(e);if(r){var n=r.get(a);if(n){var c=t.cacheHits||(t.cacheHits=[]);return new Promise((function(e){c.push((function(){e(n)}))}))}}t.keys.push(e);var l=new Promise((function(e,r){t.callbacks.push({resolve:e,reject:r})}));return r&&r.set(a,l),l},t.loadMany=function(e){if(!o(e))throw new TypeError("The loader.loadMany() function must be called with Array<key> but got: "+e+".");for(var t=[],r=0;r<e.length;r++)t.push(this.load(e[r]).catch((function(e){return e})));return Promise.all(t)},t.clear=function(e){var t=this._cacheMap;if(t){var r=this._cacheKeyFn(e);t.delete(r)}return this},t.clearAll=function(){var e=this._cacheMap;return e&&e.clear(),this},t.prime=function(e,t){var r=this._cacheMap;if(r){var a,s=this._cacheKeyFn(e);void 0===r.get(s)&&(t instanceof Error?(a=Promise.reject(t)).catch((function(){})):a=Promise.resolve(t),r.set(s,a))}return this},e}(),a="object"==typeof process&&"function"==typeof process.nextTick?function(e){t||(t=Promise.resolve()),t.then((function(){process.nextTick(e)}))}:"function"==typeof setImmediate?function(e){setImmediate(e)}:function(e){setTimeout(e)};function s(e,t,r){i(t);for(var a=0;a<t.keys.length;a++)e.clear(t.keys[a]),t.callbacks[a].reject(r)}function i(e){if(e.cacheHits
(0,v.__)('"%s" was removed from your cart.',"woocommerce"),ve(e.name)),{context:"wc/cart",speak:!0,type:"snackbar",id:`${e.key}-removed`})}))})(e,t,a),((e,t,r)=>{t.items.forEach((t=>{if(r.includes(t.key))return;const a=e.items.find((e=>e&&e.key===t.key));return a&&t.key===a.key?(t.quantity!==a.quantity&&(e=>e.quantity>=e.quantity_limits.minimum&&e.quantity<=e.quantity_limits.maximum&&e.quantity%e.quantity_limits.multiple_of==0)(t)&&(0,Pe.applyFilters)("woocommerce_show_cart_item_quantity_changed_notice",!0,t)&&(0,P.dispatch)("core/notices").createInfoNotice((0,v.sprintf)(/* translators: %1$s is the name of the item, %2$d is the quantity of the item. */ /* translators: %1$s is the name of the item, %2$d is the quantity of the item. */
(0,v.__)('The quantity of "%1$s" was changed to %2$d.',"woocommerce"),ve(t.name),t.quantity),{context:"wc/cart",speak:!0,type:"snackbar",id:`${t.key}-quantity-update`}),t):void 0}))})(e,t,r))})({oldCart:s,newCart:a,cartItemsPendingQuantity:r.getItemsPendingQuantityUpdate(),cartItemsPendingDelete:r.getItemsPendingDelete()}),t.setCartData(a),t.setErrorData(null)},ct=e=>({dispatch:t})=>{const{shipping_address:r,billing_address:a,...s}=e;t.receiveCart(s)},lt=(e=null)=>({dispatch:t})=>{var r,a;(0,de.isApiErrorResponse)(e)&&(null!==(r=e.data)&&void 0!==r&&r.cart&&t.receiveCart(null==e||null===(a=e.data)||void 0===a?void 0:a.cart),t.setErrorData(e))},dt=e=>async({dispatch:t})=>{try{const{response:r}=await Je({path:"/wc/store/v1/cart/extensions",method:"POST",data:{namespace:e.namespace,data:e.data},cache:"no-store"});if(!0===e.overwriteDirtyCustomerData)return t.receiveCart(r),r;if("true"===window.localStorage.getItem("WOOCOMMERCE_CHECKOUT_IS_CUSTOMER_DATA_DIRTY")){const{shipping_address:e,billing_address:__,...a}=r;return t.receiveCart(a),r}t.receiveCart(r)}catch(e){return t.receiveError((0,de.isApiErrorResponse)(e)?e:null),Promise.reject(e)}},pt=e=>async({dispatch:t})=>{try{t.receiveApplyingCoupon(e);const{response:r}=await Je({path:"/wc/store/v1/cart/apply-coupon",method:"POST",data:{code:e},cache:"no-store"});return t.receiveCart(r),r}catch(e){return t.receiveError((0,de.isApiErrorResponse)(e)?e:null),Promise.reject(e)}finally{t.receiveApplyingCoupon("")}},_t=e=>async({dispatch:t})=>{try{t.receiveRemovingCoupon(e);const{response:r}=await Je({path:"/wc/store/v1/cart/remove-coupon",method:"POST",data:{code:e},cache:"no-store"});return t.receiveCart(r),r}catch(e){return t.receiveError((0,de.isApiErrorResponse)(e)?e:null),Promise.reject(e)}finally{t.receiveRemovingCoupon("")}},ut=(e,t=1)=>async({dispatch:r})=>{try{Te("wc-blocks_adding_to_cart",{bubbles:!0,cancelable:!0});const{response:a}=await Je({path:"/wc/store/v1/cart/add-item",method:"POST",data:{id:e,quantity:t},cache:"no-store"});return r.receiveCart(a),(({preserveCartData:e=!1})=>{Te("wc-blocks_added_to_cart",{bubbles:!0,cancelable:!0,detail:{preserveCartData:e}})})({preserveCartData:!0}),a}catch(e){return r.receiveError((0,de.isApiErrorResponse)(e)?e:null),Promise.reject(e)}},mt=e=>async({dispatch:t})=>{try{t.itemIsPendingDelete(e);const{response:r}=await Je({path:"/wc/store/v1/cart/remove-item",data:{key:e},method:"POST",cache:"no-store"});return t.receiveCart(r),r}catch(e){return t.receiveError((0,de.isApiErrorResponse)(e)?e:null),Promise.reject(e)}finally{t.itemIsPendingDelete(e,!1)}},Et=(e,t)=>async({dispatch:r,select:a})=>{const s=a.getCartItem(e);if((null==s?void 0:s.quantity)!==t)try{r.itemIsPendingQuantity(e);const{response:a}=await Je({path:"/wc/store/v1/cart/update-item",method:"POST",data:{key:e,quantity:t},cache:"no-store"});return r.receiveCart(a),a}catch(e){return r.receiveError((0,de.isApiErrorResponse)(e)?e:null),Promise.reject(e)}finally{r.itemIsPendingQuantity(e,!1)}};let ht=null;const gt=(e,t=null)=>async({dispatch:r,select:a})=>{var s;const i=null===(s=a.getShippingRates().find((e=>e.package_id===t)))||void 0===s?void 0:s.shipping_rates.find((e=>!0===e.selected));if((null==i?void 0:i.rate_id)!==e)try{var o;r.shippingRatesBeingSelected(!0),ht&&ht.abort(),ht="undefined"==typeof AbortController?null:new AbortController;const{response:a}=await Je({path:"/wc/store/v1/cart/select-shipping-rate",method:"POST",data:{package_id:t,rate_id:e},cache:"no-store",signal:(null===(o=ht)||void 0===o?void 0:o.signal)||null}),{shipping_address:s,billing_address:i,...n}=a;return r.receiveCart(n),r.shippingRatesBeingSelected(!1),a}catch(e){return r.receiveError((0,de.isApiErrorResponse)(e)?e:null),r.shippingRatesBeingSelected(!1),Promise.reject(e)}},yt=(e,t=!0)=>async({dispatch:r})=>{try{r.updatingCustomerData(!0);const{response:a}=await Je({path:"/wc/store/v1/cart/update-customer",method:"POST",data:e,cache:"no-store"});return t?r.receiveCartContents(a):r.receiveCart(a),ot(!1),a}catch(e){return r.receiveError((0,de.isApiErrorResponse)(e)?e:null),ot(!0),Promise.reject(e
(0,v.__)("%s (optional)","woocommerce"),e.label)),e.priority&&((0,de.isNumber)(e.priority)&&(t.index=e.priority),(0,de.isString)(e.priority)&&(t.index=parseInt(e.priority,10))),e.hidden&&(t.required=!1),t},Ia=Object.entries(lr).map((([e,t])=>[e,Object.entries(t).map((([e,t])=>[e,va(t)])).reduce(((e,[t,r])=>(e[t]=r,e)),{})])).reduce(((e,[t,r])=>(e[t]=r,e)),{}),Ca=e=>{const t=((e,t,r="")=>{const a=r&&void 0!==Ia[r]?Ia[r]:{};return e.map((e=>({key:e,...t[e]||{},...a[e]||{}}))).sort(((e,t)=>e.index-t.index))})(pr,b.defaultFields,e.country),r=Object.assign({},e);return t.forEach((({key:t="",hidden:a=!1})=>{a&&((e,t)=>e in t)(t,e)&&(r[t]="")})),r},ba=!(!Kt.billing_address.address_1||!Kt.billing_address.first_name&&!Kt.billing_address.last_name),fa=!(!Kt.shipping_address.address_1||!Kt.shipping_address.first_name&&!Kt.shipping_address.last_name),wa=(Da=Kt.billing_address,Oa=Kt.shipping_address,pr.every((e=>Da[e]===Oa[e])));var Da,Oa;const Ma={additionalFields:Kt.additional_fields||{},calculatingCount:0,customerId:Kt.customer_id,customerPassword:"",extensionData:{},hasError:!1,orderId:Kt.order_id,orderNotes:"",prefersCollection:void 0,redirectUrl:"",shouldCreateAccount:!1,status:zt.IDLE,useShippingAsBilling:wa,editingBillingAddress:!ba,editingShippingAddress:!fa},Na={reducer:(e=Ma,t)=>{var r;let a=e;switch(t.type){case Br:a=e.status!==zt.IDLE?{...e,status:zt.IDLE}:e;break;case Qr:a=void 0!==t.redirectUrl&&t.redirectUrl!==e.redirectUrl?{...e,redirectUrl:t.redirectUrl}:e;break;case Hr:a={...e,status:zt.COMPLETE,redirectUrl:"string"==typeof(null===(r=t.data)||void 0===r?void 0:r.redirectUrl)?t.data.redirectUrl:e.redirectUrl};break;case Kr:a={...e,status:zt.PROCESSING,hasError:!1};break;case Yr:a={...e,status:zt.BEFORE_PROCESSING,hasError:!1};break;case Ur:a={...e,status:zt.AFTER_PROCESSING};break;case Fr:a={...e,hasError:t.hasError,status:e.status===zt.PROCESSING||e.status===zt.BEFORE_PROCESSING?zt.IDLE:e.status};break;case Lr:a={...e,calculatingCount:e.calculatingCount+1};break;case kr:a={...e,calculatingCount:Math.max(0,e.calculatingCount-1)};break;case jr:void 0!==t.customerId&&(a={...e,customerId:t.customerId});break;case Vr:void 0!==t.customerPassword&&(a={...e,customerPassword:t.customerPassword});break;case xr:void 0!==t.additionalFields&&(a={...e,additionalFields:{...e.additionalFields,...t.additionalFields}});break;case Wr:void 0!==t.useShippingAsBilling&&t.useShippingAsBilling!==e.useShippingAsBilling&&(a={...e,useShippingAsBilling:t.useShippingAsBilling});break;case $r:a={...e,editingBillingAddress:t.isEditing};break;case Zr:a={...e,editingShippingAddress:t.isEditing};break;case Xr:void 0!==t.shouldCreateAccount&&t.shouldCreateAccount!==e.shouldCreateAccount&&(a={...e,shouldCreateAccount:t.shouldCreateAccount});break;case zr:void 0!==t.prefersCollection&&t.prefersCollection!==e.prefersCollection&&(a={...e,prefersCollection:t.prefersCollection});break;case qr:void 0!==t.orderNotes&&e.orderNotes!==t.orderNotes&&(a={...e,orderNotes:t.orderNotes});break;case Gr:void 0!==t.extensionData&&void 0!==t.namespace&&(a={...e,extensionData:{...e.extensionData,[t.namespace]:t.replace?t.extensionData:{...e.extensionData[t.namespace],...t.extensionData}}})}return a},selectors:i,actions:o,__experimentalUseThunks:!0},ka=(0,P.createReduxStore)(qt,Na);(0,P.register)(ka);const La=qt,xa="wc/store/collections",Ua=[],Ya=(e,t)=>!!t&&!!t.reduce(((e,t)=>"object"==typeof e&&null!==e?e[t]:void 0),e);function Ha(e,t){return Ya(e,t)}const ja=({state:e,namespace:t,resourceName:r,query:a,ids:s,type:i="items",fallback:o=Ua})=>Ha(e,[t,r,s=JSON.stringify(s),a=null!==a?(0,rt.addQueryArgs)("",a):"",i])?e[t][r][s][a][i]:o,Va=(e,t,r,a=null,s=Ua)=>ja({state:e,namespace:t,resourceName:r,query:a,ids:s}),Ga=(e,t,r,a=null,s=Ua)=>ja({state:e,namespace:t,resourceName:r,query:a,ids:s,type:"error",fallback:null}),Fa=(e,t,r,a,s=null,i=Ua)=>{const o=((e,t,r,a=null,s=Ua)=>ja({state:e,namespace:t,resourceName:r,query:a,ids:s,type:"headers",fallback:void 0}))(e,r,a,s,i);return o&&o.get?o.has(t)?o.get(t):void 0:null},Ba=e=>e.lastModified||0,qa={RECEIVE_COLLECTION:"RECEIVE_C
(0,v.__)("There was an error registering the payment method with id '%s': ","woocommerce"),e.paymentMethodId)} ${t}`,{context:s,id:`wc-${e.paymentMethodId}-registration-error`})},us=async(e=!1)=>{let t={};const r=e?(0,os.getExpressPaymentMethods)():(0,os.getPaymentMethods)(),a=r=>{if(e){const{name:e,title:a,description:s,gatewayId:i,supports:o}=r;t={...t,[r.name]:{name:e,title:a,description:s,gatewayId:i,supportsStyle:null==o?void 0:o.style}}}else{const{name:e}=r;t={...t,[r.name]:{name:e}}}},s=e?Object.keys(r):Array.from(new Set([...(0,b.getSetting)("paymentMethodSortOrder",[]),...Object.keys(r)])),i=(()=>{let e;if((0,P.select)("core/editor")){const t={cartCoupons:ps.coupons,cartItems:ps.items,crossSellsProducts:ps.cross_sells,cartFees:ps.fees,cartItemsCount:ps.items_count,cartItemsWeight:ps.items_weight,cartNeedsPayment:ps.needs_payment,cartNeedsShipping:ps.needs_shipping,cartItemErrors:N,cartTotals:ps.totals,cartIsLoading:!1,cartErrors:k,billingData:G.cartData.billingAddress,billingAddress:G.cartData.billingAddress,shippingAddress:G.cartData.shippingAddress,extensions:Y,shippingRates:ps.shipping_rates,isLoadingRates:!1,cartHasCalculatedShipping:ps.has_calculated_shipping,paymentRequirements:ps.payment_requirements,receiveCart:()=>{}};e={cart:t,cartTotals:t.cartTotals,cartNeedsShipping:t.cartNeedsShipping,billingData:t.billingAddress,billingAddress:t.billingAddress,shippingAddress:t.shippingAddress,selectedShippingMethods:is(t.shippingRates),paymentMethods:ps.payment_methods,paymentRequirements:t.paymentRequirements}}else{const t=(0,P.select)(I),r=t.getCartData(),a=t.getCartErrors(),s=t.getCartTotals(),i=!t.hasFinishedResolution("getCartData"),o=t.isCustomerDataUpdating(),n=is(r.shippingRates);e={cart:{cartCoupons:r.coupons,cartItems:r.items,crossSellsProducts:r.crossSells,cartFees:r.fees,cartItemsCount:r.itemsCount,cartItemsWeight:r.itemsWeight,cartNeedsPayment:r.needsPayment,cartNeedsShipping:r.needsShipping,cartItemErrors:r.errors,cartTotals:s,cartIsLoading:i,cartErrors:a,billingData:Ca(r.billingAddress),billingAddress:Ca(r.billingAddress),shippingAddress:Ca(r.shippingAddress),extensions:r.extensions,shippingRates:r.shippingRates,isLoadingRates:o,cartHasCalculatedShipping:r.hasCalculatedShipping,paymentRequirements:r.paymentRequirements,receiveCart:(0,P.dispatch)(I).receiveCart},cartTotals:r.totals,cartNeedsShipping:r.needsShipping,billingData:r.billingAddress,billingAddress:r.billingAddress,shippingAddress:r.shippingAddress,selectedShippingMethods:n,paymentMethods:r.paymentMethods,paymentRequirements:r.paymentRequirements}}return e})(),o=i.paymentMethods,n=!!(0,P.select)("core/editor");for(let t=0;t<s.length;t++){const c=s[t],l=r[c];if(l)try{const t=!(!n&&!e)||o.includes(c),r=!!n||t&&await Promise.resolve(l.canMakePayment(i));if(r){if("object"==typeof r&&r.error)throw new Error(r.error.message);a(l)}}catch(t){(b.CURRENT_USER_IS_ADMIN||n)&&_s(l,t,e)}}const c=Object.keys(t),l=e?(0,P.select)(Yt).getAvailableExpressPaymentMethods():(0,P.select)(Yt).getAvailablePaymentMethods();if(Object.keys(l).length===c.length&&Object.keys(l).every((e=>c.includes(e))))return!0;const{__internalSetAvailablePaymentMethods:d,__internalSetAvailableExpressPaymentMethods:p}=(0,P.dispatch)(Yt);return(e?p:d)(t),!0},ms=async e=>{const t=Object.keys(e),r=Object.keys((0,P.select)(Yt).getAvailableExpressPaymentMethods()),a=[...t,...r],s=(0,P.select)(Yt).getSavedPaymentMethods(),i=Object.keys(s).flatMap((e=>s[e])),o=i.find((e=>e.is_default))||i[0]||void 0;if(o){const e=o.tokenId.toString(),t=o.method.gateway,r=`wc-${t}-payment-token`;return void(0,P.dispatch)(Yt).__internalSetActivePaymentMethod(t,{token:e,payment_method:t,[r]:e,isSavedToken:!0})}const n=(0,P.select)(Yt).getActivePaymentMethod();n&&a.includes(n)||((0,P.dispatch)(Yt).__internalSetPaymentIdle(),(0,P.dispatch)(Yt).__internalSetActivePaymentMethod(t[0]))},Es=window.wp.deprecated;var hs=r.n(Es);const gs=e=>["first_name","last_name","company","address_1","address_2","city","state","postcode","country","phone"].every((t=>(0,de.objectHasProp)(e,t))),ys=e=>gs(e)&&(0,de.objectHasProp)(e,"em