Plugin Directory

Changeset 3210341


Ignore:
Timestamp:
12/19/2024 09:34:33 AM (16 months ago)
Author:
postcodenl
Message:

Update plugin files for release 2.4.1

Location:
postcode-eu-address-validation/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • postcode-eu-address-validation/trunk/build/shipping-address-autocomplete-intl-frontend.asset.php

    r3197281 r3210341  
    1 <?php return array('dependencies' => array('react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-settings', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '7f123088717075ee9ec5');
     1<?php return array('dependencies' => array('react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-settings', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'c96756a4f17ef2ed5aab');
  • postcode-eu-address-validation/trunk/build/shipping-address-autocomplete-intl-frontend.js

    r3197281 r3210341  
    1 (()=>{"use strict";const e=window.wc.blocksCheckout,t=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"postcode-eu-address-validation/shipping-address-autocomplete-intl","version":"1.0.0","title":"International Address Autocomplete","category":"woocommerce","description":"Autocomplete international addresses using the Postcode.eu API.","example":{},"parent":["woocommerce/checkout-shipping-address-block"],"attributes":{"lock":{"type":"object","default":{"remove":true,"move":true}}},"textdomain":"postcode-eu-address-validation"}'),s=window.React,r=window.wp.data,o=window.wc.wcBlocksData,n=window.wp.element,a=window.wc.wcSettings,d=window.wp.i18n,c=window.wc.blocksComponents;var i,l;const u=(0,a.getSetting)("postcode-eu-address-validation_data"),p=(e,t,s)=>{let r=t,o=s;return u.reverseStreetLineCountries.includes(e)&&([r,o]=[o,r]),`${r} ${o}`.trim()};null!==(l=(i=PostcodeNl).addressDetailsCache)&&void 0!==l||(i.addressDetailsCache=new Map);const m=({id:e,addressType:t,address:a,setAddress:i,setAddressDetails:l})=>{const m=(0,n.useRef)(null),E=(0,n.useRef)(a),h=(0,n.useRef)(""),f=(0,n.useRef)(null),[g,v]=(0,n.useState)(!0),[w,_]=(0,n.useState)(null),[y,A]=(0,n.useState)(!1),[C,D]=(0,n.useState)(""),{setValidationErrors:I,clearValidationError:S}=(0,r.useDispatch)(o.VALIDATION_STORE_KEY),{validationError:b,validationErrorId:k}=(0,r.useSelect)((t=>{const s=t(o.VALIDATION_STORE_KEY);return{validationError:s.getValidationError(e),validationErrorId:s.getValidationErrorId(e)}}));(0,n.useEffect)((()=>{E.current=a}),[a]);const T=(0,n.useCallback)((()=>{i({...E.current,address_1:"",city:"",postcode:""}),l(null)}),[i,l]),R=(0,n.useCallback)(((s=!0)=>{["address_1","city","postcode"].every((e=>void 0===(0,r.select)(o.VALIDATION_STORE_KEY).getValidationError(`${t}_${e}`)))?S(e):I({[e]:{message:(0,d.__)("Please enter an address and select it.","postcode-eu-address-validation"),hidden:s}})}),[e,S,I]),L=(0,n.useCallback)(((e,t)=>{PostcodeNl.addressDetailsCache.has(e)?t(PostcodeNl.addressDetailsCache.get(e)):f.current.getDetails(e,(s=>{t(s),PostcodeNl.addressDetailsCache.set(e,s)}))}),[]),N=(0,n.useCallback)((e=>{_(!0),L(e.context,(e=>{const{locality:t,street:s,postcode:r,building:o}=e.address;i({...E.current,address_1:p(e.country.iso2Code,s,o),city:t,postcode:r}),l(e),R(!1),_(!1)}))}),[_,i,l,R]),O=(0,n.useCallback)((()=>{m.current.addEventListener("autocomplete-response",(e=>{const t=e.detail.matches;1===t.length&&"Address"===t[0].precision?N(t[0]):R(!0)}),{once:!0}),f.current.search(m.current,{term:h.current,showMenu:!1})}),[N,R]);(0,n.useEffect)((()=>{g&&(v(!1),h.current=["postcode","city","address_1","address_2"].map((e=>E.current[e])).join(" ").trim(),D(h.current),m.current.addEventListener("autocomplete-select",(e=>{D(e.detail.value),e.preventDefault(),"Address"===e.detail.precision&&N(e.detail)})),m.current.addEventListener("autocomplete-search",T),m.current.addEventListener("autocomplete-error",(()=>{_(!1),I({[e]:{message:(0,d.__)("An error has occurred while retrieving address data. Please contact us if the problem persists.","postcode-eu-address-validation"),hidden:!1}})})),m.current.addEventListener("autocomplete-open",(()=>A(!0))),m.current.addEventListener("autocomplete-close",(()=>A(!1))))}),[g,v,D,l,T,_,I,A]),(0,n.useEffect)((()=>{var t,s;if(s=a.country,void 0===u.enabledCountries[s])return void S(e);const n=u.enabledCountries[a.country];null===f.current?(f.current=function(e,t){const s=new PostcodeNl.AutocompleteAddress(e,{autocompleteUrl:u.autocomplete,addressDetailsUrl:u.getDetails,context:t});return s.getSuggestions=function(e,t,s){const r=(new TextEncoder).encode(t),o=Array.from(r,(e=>String.fromCodePoint(e))).join(""),n=this.options.autocompleteUrl.replace("${context}",encodeURIComponent(e)).replace("${term}",encodeURIComponent(btoa(o)));return this.xhrGet(`${n}`,s)},s.getDetails=function(e,t){const s=this.options.addressDetailsUrl.replace("${context}",encodeURIComponent(e));return this.xhrGet(s,t)},s}(m.current,n.iso3),h.current.length>0&&O()):(f.current.reset(),f.current.setCountry(n.iso3),T(),D(""));const d=(0,r.select)(o.VALIDATION_STORE_KEY).getValidationError(e);R(null===(t=d?.hidden)||void 0===t||t)}),[a.country,e,S,D,T]),(0,n.useEffect)((()=>()=>S(e)),[S,e]),(0,n.useEffect)((()=>{null!==w&&m.current.classList.toggle(`${f.current.options.cssPrefix}loading`,w)}),[w]);const V=b?.message&&!b?.hidden;return(0,s.createElement)(c.TextInput,{id:e,required:!0,className:{"has-error":V},ref:m,label:(0,d.__)("Start typing your address or zip/postal code","postcode-eu-address-validation"),value:C,onChange:e=>{R(!0),D(e)},onBlur:()=>!y&&R(!1),"aria-invalid":!0===V,ariaDescribedBy:V&&k?k:null,feedback:(0,s.createElement)(c.ValidationInputError,{propertyName:e,elementId:e}),title:""})},E=({forId:e,onClick:t})=>{const n=(0,r.useSelect)((t=>t(o.VALIDATION_STORE_KEY).getValidationError(e))),{clearValidationError:a}=(0,r.useDispatch)(o.VALIDATION_STORE_KEY);return n&&!n.hidden?(0,s.createElement)("a",{className:"postcode-eu-autofill-intl-bypass-link",onClick:()=>{a(e),t()}},(0,d.__)("Enter an address")):null},h=({addressDetails:e})=>e?.mailLines?(0,s.createElement)("address",{className:"postcode-eu-autofill-address"},e.mailLines.join("\n")):null,f=(0,a.getSetting)("postcode-eu-address-validation_data"),g=({addressType:e,address:t,setAddress:r})=>{const o=(0,n.useRef)(null),[a,d]=(0,n.useState)(null),[c,i]=(0,n.useState)(!1),l=`${e}-intl_autocomplete`;return(0,n.useEffect)((()=>{const t=()=>{const t=document.getElementById(`${e}-address_1`)?.parentElement;return t?.before(o.current),t};if(!t()){const e=new MutationObserver((s=>{s.forEach((()=>{t()&&e.disconnect()}))}));return e.observe(o.current.closest(".wc-block-components-checkout-step__content"),{childList:!0}),()=>e.disconnect()}}),[]),(0,n.useEffect)((()=>{i(Boolean(f.enabledCountries[t.country]))}),[i,t.country]),(0,n.useEffect)((()=>{if("showAll"!==f.displayMode)for(const t of["address_1","postcode","city"]){const s=document.getElementById(`${e}-${t}`)?.parentElement;s&&(s.style.display=c?"none":"")}}),[e,c]),(0,s.createElement)("div",{className:"postcode-eu-autofill-container",ref:o,style:c?{}:{display:"none"}},(0,s.createElement)(m,{id:l,addressType:e,address:t,setAddress:r,setAddressDetails:d}),"showAll"!==f.displayMode&&(0,s.createElement)(E,{forId:l,onClick:()=>{i(!1)}}),(0,s.createElement)(h,{addressDetails:a}))};(0,e.registerCheckoutBlock)({metadata:t,component:()=>{const{shippingAddress:e}=(0,r.useSelect)((e=>e(o.CART_STORE_KEY).getCustomerData()),[]),{setShippingAddress:t}=(0,r.useDispatch)(o.CART_STORE_KEY);return(0,s.createElement)(g,{addressType:"shipping",address:e,setAddress:t})}})})();
     1(()=>{"use strict";const e=window.wc.blocksCheckout,t=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"postcode-eu-address-validation/shipping-address-autocomplete-intl","version":"1.0.0","title":"International Address Autocomplete","category":"woocommerce","description":"Autocomplete international addresses using the Postcode.eu API.","example":{},"parent":["woocommerce/checkout-shipping-address-block"],"attributes":{"lock":{"type":"object","default":{"remove":true,"move":true}}},"textdomain":"postcode-eu-address-validation"}'),s=window.React,r=window.wp.data,o=window.wp.element,n=window.wc.wcBlocksData,a=window.wc.wcSettings,d=window.wp.i18n,c=window.wc.blocksComponents;var i,l;const u=(0,a.getSetting)("postcode-eu-address-validation_data"),p=(e,t,s)=>{let r=t,o=s;return u.reverseStreetLineCountries.includes(e)&&([r,o]=[o,r]),`${r} ${o}`.trim()};null!==(l=(i=PostcodeNl).addressDetailsCache)&&void 0!==l||(i.addressDetailsCache=new Map);const m=({id:e,addressType:t,address:a,setAddress:i,setAddressDetails:l})=>{const m=(0,o.useRef)(null),E=(0,o.useRef)(a),h=(0,o.useRef)(""),g=(0,o.useRef)(null),[f,_]=(0,o.useState)(!0),[v,w]=(0,o.useState)(null),[A,y]=(0,o.useState)(!1),[C,S]=(0,o.useState)(""),{setValidationErrors:D,clearValidationError:I}=(0,r.useDispatch)(n.VALIDATION_STORE_KEY),{validationError:b,validationErrorId:k}=(0,r.useSelect)((t=>{const s=t(n.VALIDATION_STORE_KEY);return{validationError:s.getValidationError(e),validationErrorId:s.getValidationErrorId(e)}}));(0,o.useEffect)((()=>{E.current=a}),[a]);const T=(0,o.useCallback)((()=>{i({...E.current,address_1:"",city:"",postcode:""}),l(null)}),[i,l]),R=(0,o.useCallback)(((s=!0)=>{["address_1","city","postcode"].every((e=>void 0===(0,r.select)(n.VALIDATION_STORE_KEY).getValidationError(`${t}_${e}`)))?I(e):D({[e]:{message:(0,d.__)("Please enter an address and select it.","postcode-eu-address-validation"),hidden:s}})}),[e,I,D]),O=(0,o.useCallback)(((e,t)=>{PostcodeNl.addressDetailsCache.has(e)?t(PostcodeNl.addressDetailsCache.get(e)):g.current.getDetails(e,(s=>{t(s),PostcodeNl.addressDetailsCache.set(e,s)}))}),[]),L=(0,o.useCallback)((e=>{w(!0),O(e.context,(e=>{const{locality:t,street:s,postcode:r,building:o}=e.address;i({...E.current,address_1:p(e.country.iso2Code,s,o),city:t,postcode:r}),l(e),R(!1),w(!1)}))}),[w,i,l,R]),N=(0,o.useCallback)((()=>{m.current.addEventListener("autocomplete-response",(e=>{const t=e.detail.matches;1===t.length&&"Address"===t[0].precision?L(t[0]):R(!0)}),{once:!0}),g.current.search(m.current,{term:h.current,showMenu:!1})}),[L,R]);(0,o.useEffect)((()=>{f&&(_(!1),h.current=["postcode","city","address_1","address_2"].map((e=>E.current[e])).join(" ").trim(),S(h.current),m.current.addEventListener("autocomplete-select",(e=>{S(e.detail.value),e.preventDefault(),"Address"===e.detail.precision&&L(e.detail)})),m.current.addEventListener("autocomplete-search",T),m.current.addEventListener("autocomplete-error",(()=>{w(!1),D({[e]:{message:(0,d.__)("An error has occurred while retrieving address data. Please contact us if the problem persists.","postcode-eu-address-validation"),hidden:!1}})})),m.current.addEventListener("autocomplete-open",(()=>y(!0))),m.current.addEventListener("autocomplete-close",(()=>y(!1))))}),[f,_,S,l,T,w,D,y]),(0,o.useEffect)((()=>{var t,s;if(s=a.country,void 0===u.enabledCountries[s])return void I(e);const o=u.enabledCountries[a.country];null===g.current?(g.current=function(e,t){const s=new PostcodeNl.AutocompleteAddress(e,{autocompleteUrl:u.autocomplete,addressDetailsUrl:u.getDetails,context:t});return s.getSuggestions=function(e,t,s){const r=(new TextEncoder).encode(t),o=Array.from(r,(e=>String.fromCodePoint(e))).join(""),n=this.options.autocompleteUrl.replace("${context}",encodeURIComponent(e)).replace("${term}",encodeURIComponent(btoa(o)));return this.xhrGet(`${n}`,s)},s.getDetails=function(e,t){const s=this.options.addressDetailsUrl.replace("${context}",encodeURIComponent(e));return this.xhrGet(s,t)},s}(m.current,o.iso3),h.current.length>0&&N()):(g.current.reset(),g.current.setCountry(o.iso3),T(),S(""));const d=(0,r.select)(n.VALIDATION_STORE_KEY).getValidationError(e);R(null===(t=d?.hidden)||void 0===t||t)}),[a.country,e,I,S,T]),(0,o.useEffect)((()=>()=>I(e)),[I,e]),(0,o.useEffect)((()=>{null!==v&&m.current.classList.toggle(`${g.current.options.cssPrefix}loading`,v)}),[v]);const V=b?.message&&!b?.hidden;return(0,s.createElement)(c.TextInput,{id:e,required:!0,className:{"has-error":V},ref:m,label:(0,d.__)("Start typing your address or zip/postal code","postcode-eu-address-validation"),value:C,onChange:e=>{R(!0),S(e)},onBlur:()=>!A&&R(!1),"aria-invalid":!0===V,ariaDescribedBy:V&&k?k:null,feedback:(0,s.createElement)(c.ValidationInputError,{propertyName:e,elementId:e}),title:""})},E=({forId:e,onClick:t})=>{const o=(0,r.useSelect)((t=>t(n.VALIDATION_STORE_KEY).getValidationError(e))),{clearValidationError:a}=(0,r.useDispatch)(n.VALIDATION_STORE_KEY);return o&&!o.hidden?(0,s.createElement)("a",{className:"postcode-eu-autofill-intl-bypass-link",onClick:()=>{a(e),t()}},(0,d.__)("Enter an address")):null},h=({addressDetails:e})=>e?.mailLines?(0,s.createElement)("address",{className:"postcode-eu-autofill-address"},e.mailLines.join("\n")):null,g=(0,a.getSetting)("postcode-eu-address-validation_data"),f=({addressType:e,address:t,setAddress:r})=>{const n=(0,o.useRef)(null),[a,d]=(0,o.useState)(null),[c,i]=(0,o.useState)(!1),l=`${e}-intl_autocomplete`;return(0,o.useEffect)((()=>{const t=()=>{const t=document.getElementById(`${e}-address_1`)?.parentElement;return t?.before(n.current),t};if(!t()){const e=new MutationObserver((s=>{s.forEach((()=>{t()&&e.disconnect()}))}));return e.observe(n.current.closest(".wc-block-components-checkout-step__content"),{childList:!0}),()=>e.disconnect()}}),[]),(0,o.useEffect)((()=>{i(Boolean(g.enabledCountries[t.country]))}),[i,t.country]),(0,o.useEffect)((()=>{if("showAll"!==g.displayMode)for(const t of["address_1","postcode","city"]){const s=document.getElementById(`${e}-${t}`)?.parentElement;s&&(s.style.display=c?"none":"")}}),[e,c]),(0,s.createElement)("div",{className:"postcode-eu-autofill-container",ref:n,style:c?{}:{display:"none"}},(0,s.createElement)(m,{id:l,addressType:e,address:t,setAddress:r,setAddressDetails:d}),"showAll"!==g.displayMode&&(0,s.createElement)(E,{forId:l,onClick:()=>{i(!1)}}),(0,s.createElement)(h,{addressDetails:a}))};(0,e.registerCheckoutBlock)({metadata:t,component:()=>{const e=(0,r.useSelect)((e=>e(n.CHECKOUT_STORE_KEY).getUseShippingAsBilling),[]),{shippingAddress:t}=(0,r.useSelect)((e=>e(n.CART_STORE_KEY).getCustomerData()),[]),{setShippingAddress:a,setBillingAddress:d}=(0,r.useDispatch)(n.CART_STORE_KEY),c=(0,o.useCallback)((t=>{a(t),e()&&d({...t})}),[e,a,d]);return(0,s.createElement)(f,{addressType:"shipping",address:t,setAddress:c})}})})();
  • postcode-eu-address-validation/trunk/postcode-eu-address-validation.php

    r3197281 r3210341  
    44 * Plugin URI: https://www.postcode.eu/products/address-api/implementation
    55 * Description: Address autocomplete and validation using the Postcode.eu API.
    6  * Version: 2.4.0
     6 * Version: 2.4.1
    77 * Author: Postcode.nl
    88 * Author URI: https://www.postcode.nl
     
    1414 * Requires PHP: 7.4
    1515 * WC requires at least: 4.0
    16  * WC tested up to: 9.4
     16 * WC tested up to: 9.5
    1717 */
    1818
  • postcode-eu-address-validation/trunk/readme.txt

    r3197281 r3210341  
    22Contributors: postcodenl
    33Tags: address validation, address autocomplete, postcode api, address api, postcode check
    4 Stable tag: 2.4.0
     4Stable tag: 2.4.1
    55Tested up to: 6.7
    66License: FreeBSD license
     
    8787== Changelog ==
    8888
     89= 2.4.1 =
     90* Fixed billing address values not synced from shipping address with use-shipping-as-billing option enabled.
     91
    8992= 2.4.0 =
    9093* Add support for blocks checkout. Note that this currently only works with the single address input field. Autocomplete based on Dutch postcode and house number will be supported in a future version.
  • postcode-eu-address-validation/trunk/src/PostcodeNl/AddressAutocomplete/Main.php

    r3197281 r3210341  
    1212{
    1313    /** @var string The version number of the plugin should be equal to the commented version number in ../../../postcode-eu-address-validation.php */
    14     public const VERSION = '2.4.0';
     14    public const VERSION = '2.4.1';
    1515
    1616    /** @var string Path to the plugin directory */
  • postcode-eu-address-validation/trunk/src/blocks/billing-address-autocomplete-intl/block.js

    r3197281 r3210341  
    44
    55const Block = () => {
    6     const useShippingAsBilling = useSelect(select => select(CHECKOUT_STORE_KEY).getUseShippingAsBilling() , []),
     6    const useShippingAsBilling = useSelect(select => select(CHECKOUT_STORE_KEY).getUseShippingAsBilling(), []),
    77        {billingAddress} = useSelect(select => select(CART_STORE_KEY).getCustomerData(), []),
    88        {setBillingAddress} = useDispatch(CART_STORE_KEY);
  • postcode-eu-address-validation/trunk/src/blocks/shipping-address-autocomplete-intl/block.js

    r3197281 r3210341  
    11import { useSelect, useDispatch } from '@wordpress/data';
     2import { useCallback } from '@wordpress/element';
    23import { CART_STORE_KEY } from '@woocommerce/block-data';
     4import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data';
    35import AutocompleteContainer from '../../components/address-autocomplete-intl/container';
    46
    57const Block = () => {
    6     const {shippingAddress} = useSelect(select => select(CART_STORE_KEY).getCustomerData(), []),
    7         {setShippingAddress} = useDispatch(CART_STORE_KEY);
     8    const isUseShippingAsBilling = useSelect(select => select(CHECKOUT_STORE_KEY).getUseShippingAsBilling, []),
     9        {shippingAddress} = useSelect(select => select(CART_STORE_KEY).getCustomerData(), []),
     10        {setShippingAddress, setBillingAddress} = useDispatch(CART_STORE_KEY);
     11
     12    const setAddress = useCallback(
     13        (values) => {
     14            setShippingAddress(values);
     15
     16            if (isUseShippingAsBilling())
     17            {
     18                // Billing address needs to be synced with shipping address after calling `setShippingAddress`.
     19                setBillingAddress({...values});
     20            }
     21        },
     22        [isUseShippingAsBilling, setShippingAddress, setBillingAddress]
     23    );
    824
    925    return (
     
    1127            addressType="shipping"
    1228            address={shippingAddress}
    13             setAddress={setShippingAddress}
     29            setAddress={setAddress}
    1430        />
    1531    )
Note: See TracChangeset for help on using the changeset viewer.