@opensystemslab/map 0.4.7 → 0.5.0

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.
@@ -6519,10 +6519,32 @@ x:-moz-any-link {
6519
6519
  width: 25% !important;
6520
6520
  }
6521
6521
  }
6522
- ul,
6523
- li {
6524
- font-family: Inter, Helvetica, sans-serif;
6525
- }`,by=Object.freeze,xy=Object.defineProperty,ky=Object.getOwnPropertyDescriptor,wy=(t,e,i,o)=>{for(var n,r=o>1?void 0:o?ky(e,i):e,a=t.length-1;a>=0;a--)(n=t[a])&&(r=(o?n(e,i,r):n(r))||r);return o&&r&&xy(e,i,r),r},Sy=(t,e)=>by(xy(t,"raw",{value:by(e||t.slice())}));let Cy=class extends ht{constructor(){super(...arguments),this.id="autocomplete",this.postcode="SE5 0HU",this.label="Select an address",this.osPlacesApiKey="",this._totalAddresses=void 0,this._addressesInPostcode=[],this._options=[],this._selectedAddress=null,this._osError=void 0,this.dispatch=(t,e)=>this.dispatchEvent(new CustomEvent(t,{detail:e}))}connectedCallback(){super.connectedCallback(),this._fetchData()}disconnectedCallback(){super.disconnectedCallback()}firstUpdated(){yy({element:this.renderRoot.querySelector(`#${this.id}-container`),id:this.id,required:!0,source:this._options,showAllValues:!0,tNoResults:()=>"No addresses found",onConfirm:t=>{this._selectedAddress=this._addressesInPostcode.filter((e=>e.LPI.ADDRESS.split(`, ${e.LPI.ADMINISTRATIVE_AREA}`)[0]===t))[0],this._selectedAddress&&this.dispatch("addressSelection",{address:this._selectedAddress})}})}async _fetchData(t=0,e=[]){const i={postcode:this.postcode,dataset:"LPI",maxResults:"100",output_srs:"EPSG:4326",lr:"EN",key:this.osPlacesApiKey},o=`https://api.os.uk/search/places/v1/postcode?${new URLSearchParams(i).toString()}`;await fetch(o+`&offset=${t}`).then((t=>t.json())).then((t=>{var i;t.error&&(this._osError=t.error.message),this._totalAddresses=null==(i=t.header)?void 0:i.totalresults;const o=e.concat(t.results||[]);this._addressesInPostcode=o,this.dispatch("ready",{postcode:this.postcode,addresses:`fetched ${this._addressesInPostcode.length}/${this._totalAddresses}`}),t.results&&(t.results.filter((t=>"APPROVED"===t.LPI.LPI_LOGICAL_STATUS_CODE_DESCRIPTION)).map((t=>{this._options.push(t.LPI.ADDRESS.split(`, ${t.LPI.ADMINISTRATIVE_AREA}`)[0])})),this._options.sort(((t,e)=>t.localeCompare(e)))),this._totalAddresses&&this._totalAddresses>this._addressesInPostcode.length&&this._fetchData(this._addressesInPostcode.length,this._addressesInPostcode)})).catch((t=>console.log(t)))}render(){let t;return t=this.osPlacesApiKey?this._osError?this._osError:0===this._totalAddresses?`No addresses found in postcode ${this.postcode}`:"Something went wrong":"Missing OS Places API key",!this.osPlacesApiKey||this._osError||0===this._totalAddresses?U(my||(my=Sy(['<script src="https://cdn.polyfill.io/v2/polyfill.min.js"><\/script>\n <div class="govuk-warning-text" role="status">\n <span class="govuk-warning-text__icon" aria-hidden="true">!</span>\n <strong class="govuk-warning-text__text">\n <span class="govuk-warning-text__assistive">Warning</span>\n ',"\n </strong>\n </div>"])),t):U(vy||(vy=Sy(['<script src="https://cdn.polyfill.io/v2/polyfill.min.js"><\/script>\n <link\n rel="stylesheet"\n href="https://cdn.jsdelivr.net/npm/accessible-autocomplete@2.0.4/dist/accessible-autocomplete.min.css"\n />\n <label class="govuk-label" htmlFor=',"> ",' </label>\n <div id="','-container" role="status"></div>'])),this.id,this.label,this.id)}};Cy.styles=f(_y),wy([gt({type:String})],Cy.prototype,"id",2),wy([gt({type:String})],Cy.prototype,"postcode",2),wy([gt({type:String})],Cy.prototype,"label",2),wy([gt({type:String})],Cy.prototype,"osPlacesApiKey",2),wy([mt()],Cy.prototype,"_totalAddresses",2),wy([mt()],Cy.prototype,"_addressesInPostcode",2),wy([mt()],Cy.prototype,"_options",2),wy([mt()],Cy.prototype,"_selectedAddress",2),wy([mt()],Cy.prototype,"_osError",2),Cy=wy([ct("address-autocomplete")],Cy);var zy,Ty=function(){return(Ty=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)},Ey=/^([a-z]{1,2}\d)([a-z])$/i,Oy=/[a-z]{2}$/i,Py=/\d[a-z]{2}$/i,jy=/^[a-z]{1,2}\d[a-z\d]?\s*\d[a-z]{2}$/i,Ry=/^[a-z]{1,2}/i,Iy={valid:!1,postcode:null,incode:null,outcode:null,area:null,district:null,subDistrict:null,sector:null,unit:null},Fy=function(t){return null===t?null:t[0]},My=/\s+/gi,Ay=function(t){return t.replace(My,"").toUpperCase()},Dy=function(t,e){return Ay(t).match(e)},Ly=function(t){return null!==t.match(jy)},Gy=function(t){var e=Ny(t);if(null===e)return null;var i=By(t);return null===i?null:e+" "+i},Ny=function(t){return Ly(t)?Ay(t).replace(Py,""):null},By=function(t){if(!Ly(t))return null;var e=Dy(t,Py);return Fy(e)},qy=function(t){if(!Ly(t))return null;var e=Dy(t,Ry);return Fy(e)},Wy=function(t){var e=Ny(t);if(null===e)return null;var i=By(t);return null===i?null:e+" "+i[0]},Vy=function(t){if(!Ly(t))return null;var e=Dy(t,Oy);return Fy(e)},Uy=function(t){var e=Ny(t);if(null===e)return null;var i=e.match(Ey);return null===i?e:i[1]},Xy=function(t){var e=Ny(t);return null===e||null===e.match(Ey)?null:e},Ky=g`@charset "UTF-8";
6522
+ :host .govuk-label {
6523
+ font-family: var(--autocomplete__font-family, "GDS Transport", arial, sans-serif);
6524
+ }
6525
+ :host .autocomplete__input {
6526
+ font-family: var(--autocomplete__font-family, "GDS Transport", arial, sans-serif);
6527
+ font-size: var(--autocomplete__input__font-size, 19px);
6528
+ height: var(--autocomplete__input__height, 35px);
6529
+ padding: var(--autocomplete__input__padding, 5px 34px 5px 5px);
6530
+ }
6531
+ :host .autocomplete__dropdown-arrow-down {
6532
+ z-index: var(--autocomplete__dropdown-arrow-down__z-index, -1);
6533
+ top: calc((var(--autocomplete__input__height, 35px) - 17px) / 2);
6534
+ }
6535
+ :host .autocomplete__option {
6536
+ font-family: var(--autocomplete__font-family, "GDS Transport", arial, sans-serif);
6537
+ font-size: var(--autocomplete__input__font-size, 19px);
6538
+ padding: var(--autocomplete__option__padding, 5px);
6539
+ border-bottom: var(--autocomplete__option__border-bottom, solid 1px #b1b4b6);
6540
+ }
6541
+ :host .autocomplete__option:hover, :host .autocomplete__option:focus {
6542
+ border-color: var(--autocomplete__option__hover-border-color, #1d70b8);
6543
+ background-color: var(--autocomplete__option__hover-background-color, #1d70b8);
6544
+ }
6545
+ :host .autocomplete__menu {
6546
+ max-height: var(--autocomplete__menu__max-height, 342px);
6547
+ }`,by=Object.freeze,xy=Object.defineProperty,ky=Object.getOwnPropertyDescriptor,wy=(t,e,i,o)=>{for(var n,r=o>1?void 0:o?ky(e,i):e,a=t.length-1;a>=0;a--)(n=t[a])&&(r=(o?n(e,i,r):n(r))||r);return o&&r&&xy(e,i,r),r},Sy=(t,e)=>by(xy(t,"raw",{value:by(e||t.slice())}));let Cy=class extends ht{constructor(){super(...arguments),this.id="autocomplete",this.postcode="SE5 0HU",this.label="Select an address",this.initialAddress="",this.osPlacesApiKey="",this._totalAddresses=void 0,this._addressesInPostcode=[],this._options=[],this._selectedAddress=null,this._osError=void 0,this.dispatch=(t,e)=>this.dispatchEvent(new CustomEvent(t,{detail:e}))}connectedCallback(){super.connectedCallback(),this._fetchData()}disconnectedCallback(){super.disconnectedCallback()}firstUpdated(){yy({element:this.renderRoot.querySelector(`#${this.id}-container`),id:this.id,required:!0,source:this._options,defaultValue:this.initialAddress,showAllValues:!0,displayMenu:"overlay",tNoResults:()=>"No addresses found",onConfirm:t=>{this._selectedAddress=this._addressesInPostcode.filter((e=>e.LPI.ADDRESS.split(`, ${e.LPI.ADMINISTRATIVE_AREA}`)[0]===t))[0],this._selectedAddress&&this.dispatch("addressSelection",{address:this._selectedAddress})}})}async _fetchData(t=0,e=[]){const i={postcode:this.postcode,dataset:"LPI",maxResults:"100",output_srs:"EPSG:4326",lr:"EN",key:this.osPlacesApiKey},o=`https://api.os.uk/search/places/v1/postcode?${new URLSearchParams(i)}`;await fetch(o+`&offset=${t}`).then((t=>t.json())).then((t=>{var i,o,n;(t.error||t.fault)&&(this._osError=(null==(i=t.error)?void 0:i.message)||(null==(o=t.fault)?void 0:o.faultstring)||"Something went wrong"),this._totalAddresses=null==(n=t.header)?void 0:n.totalresults;const r=e.concat(t.results||[]);if(this._addressesInPostcode=r,this.dispatch("ready",{postcode:this.postcode,status:`fetched ${this._addressesInPostcode.length}/${this._totalAddresses} addresses`}),t.results){t.results.filter((t=>"APPROVED"===t.LPI.LPI_LOGICAL_STATUS_CODE_DESCRIPTION)).map((t=>{this._options.push(t.LPI.ADDRESS.split(`, ${t.LPI.ADMINISTRATIVE_AREA}`)[0])}));const e=new Intl.Collator([],{numeric:!0});this._options.sort(((t,i)=>e.compare(t,i)))}this._totalAddresses&&this._totalAddresses>this._addressesInPostcode.length&&this._fetchData(this._addressesInPostcode.length,this._addressesInPostcode)})).catch((t=>console.log(t)))}render(){let t;return this.osPlacesApiKey?this._osError?t=this._osError:0===this._totalAddresses&&(t=`No addresses found in postcode ${this.postcode}`):t="Missing OS Places API key",t?U(my||(my=Sy(['<script src="https://cdn.polyfill.io/v2/polyfill.min.js"><\/script>\n <div class="govuk-warning-text" role="status">\n <span class="govuk-warning-text__icon" aria-hidden="true">!</span>\n <strong class="govuk-warning-text__text">\n <span class="govuk-warning-text__assistive">Warning</span>\n ',"\n </strong>\n </div>"])),t):U(vy||(vy=Sy(['<script src="https://cdn.polyfill.io/v2/polyfill.min.js"><\/script>\n <link\n rel="stylesheet"\n href="https://cdn.jsdelivr.net/npm/accessible-autocomplete@2.0.4/dist/accessible-autocomplete.min.css"\n />\n <label class="govuk-label" htmlFor=',">",'</label>\n <div\n id="','-container"\n role="status"\n spellcheck="false"\n ></div>'])),this.id,this.label,this.id)}};Cy.styles=f(_y),wy([gt({type:String})],Cy.prototype,"id",2),wy([gt({type:String})],Cy.prototype,"postcode",2),wy([gt({type:String})],Cy.prototype,"label",2),wy([gt({type:String})],Cy.prototype,"initialAddress",2),wy([gt({type:String})],Cy.prototype,"osPlacesApiKey",2),wy([mt()],Cy.prototype,"_totalAddresses",2),wy([mt()],Cy.prototype,"_addressesInPostcode",2),wy([mt()],Cy.prototype,"_options",2),wy([mt()],Cy.prototype,"_selectedAddress",2),wy([mt()],Cy.prototype,"_osError",2),Cy=wy([ct("address-autocomplete")],Cy);var zy,Ty=function(){return(Ty=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)},Ey=/^([a-z]{1,2}\d)([a-z])$/i,Oy=/[a-z]{2}$/i,Py=/\d[a-z]{2}$/i,jy=/^[a-z]{1,2}\d[a-z\d]?\s*\d[a-z]{2}$/i,Ry=/^[a-z]{1,2}/i,Iy={valid:!1,postcode:null,incode:null,outcode:null,area:null,district:null,subDistrict:null,sector:null,unit:null},Fy=function(t){return null===t?null:t[0]},My=/\s+/gi,Ay=function(t){return t.replace(My,"").toUpperCase()},Dy=function(t,e){return Ay(t).match(e)},Ly=function(t){return null!==t.match(jy)},Gy=function(t){var e=Ny(t);if(null===e)return null;var i=By(t);return null===i?null:e+" "+i},Ny=function(t){return Ly(t)?Ay(t).replace(Py,""):null},By=function(t){if(!Ly(t))return null;var e=Dy(t,Py);return Fy(e)},qy=function(t){if(!Ly(t))return null;var e=Dy(t,Ry);return Fy(e)},Wy=function(t){var e=Ny(t);if(null===e)return null;var i=By(t);return null===i?null:e+" "+i[0]},Vy=function(t){if(!Ly(t))return null;var e=Dy(t,Oy);return Fy(e)},Uy=function(t){var e=Ny(t);if(null===e)return null;var i=e.match(Ey);return null===i?e:i[1]},Xy=function(t){var e=Ny(t);return null===e||null===e.match(Ey)?null:e},Ky=g`@charset "UTF-8";
6526
6548
  .govuk-link {
6527
6549
  font-family: "GDS Transport", arial, sans-serif;
6528
6550
  -webkit-font-smoothing: antialiased;
@@ -12679,4 +12701,4 @@ x:-moz-any-link {
12679
12701
  </label>
12680
12702
  </h1>`:U`<label class="govuk-label" htmlFor=${this.id}
12681
12703
  >${this.label}</label
12682
- >`}render(){return U(zy||(zy=Yy(Zy(t=['<script src="https://cdn.polyfill.io/v2/polyfill.min.js"><\/script>\n <div class="govuk-form-group">\n ','\n <div id="postcode-hint" class="govuk-hint">',"</div>\n <span\n id=",'\n class="govuk-error-message"\n style="display:none"\n role="status"\n >\n <span class="govuk-visually-hidden">Error:</span>','\n </span>\n <input\n class="govuk-input govuk-input--width-10"\n id=','\n name="postcode"\n type="text"\n autocomplete="postal-code"\n spellcheck="false"\n aria-describedby="postcode-hint ','"\n .value=',"\n @input=","\n @blur=","\n @keyup=","\n />\n </div>"],"raw",{value:Yy(e||t.slice())}))),this._makeLabel(),this.hintText,this.errorId,this.errorMessage,this.id,this.errorId,this._postcode,this._onInputChange,this._onBlur,this._onKeyUp);var t,e}};Jy.styles=f(Ky),$y([gt({type:String})],Jy.prototype,"id",2),$y([gt({type:String})],Jy.prototype,"errorId",2),$y([gt({type:String})],Jy.prototype,"label",2),$y([gt({type:String})],Jy.prototype,"hintText",2),$y([gt({type:String})],Jy.prototype,"errorMessage",2),$y([gt({type:Boolean})],Jy.prototype,"onlyQuestionOnPage",2),$y([mt()],Jy.prototype,"_postcode",2),$y([mt()],Jy.prototype,"_sanitizedPostcode",2),$y([mt()],Jy.prototype,"_showPostcodeError",2),Jy=$y([ct("postcode-search")],Jy);export{Cy as AddressAutocomplete,cy as MyMap,Jy as PostcodeSearch};
12704
+ >`}render(){return U(zy||(zy=Yy(Zy(t=['<script src="https://cdn.polyfill.io/v2/polyfill.min.js"><\/script>\n <div class="govuk-form-group">\n ','\n <div id="postcode-hint" class="govuk-hint">',"</div>\n <span\n id=",'\n class="govuk-error-message"\n style="display:none"\n role="status"\n >\n <span class="govuk-visually-hidden">Error:</span>','\n </span>\n <input\n class="govuk-input govuk-input--width-10"\n id=','\n name="postcode"\n type="text"\n autocomplete="postal-code"\n spellcheck="false"\n aria-describedby="postcode-hint ','"\n .value=',"\n @input=","\n @blur=","\n @keyup=",'\n tabindex="0"\n />\n </div>'],"raw",{value:Yy(e||t.slice())}))),this._makeLabel(),this.hintText,this.errorId,this.errorMessage,this.id,this.errorId,this._postcode,this._onInputChange,this._onBlur,this._onKeyUp);var t,e}};Jy.styles=f(Ky),$y([gt({type:String})],Jy.prototype,"id",2),$y([gt({type:String})],Jy.prototype,"errorId",2),$y([gt({type:String})],Jy.prototype,"label",2),$y([gt({type:String})],Jy.prototype,"hintText",2),$y([gt({type:String})],Jy.prototype,"errorMessage",2),$y([gt({type:Boolean})],Jy.prototype,"onlyQuestionOnPage",2),$y([mt()],Jy.prototype,"_postcode",2),$y([mt()],Jy.prototype,"_sanitizedPostcode",2),$y([mt()],Jy.prototype,"_showPostcodeError",2),Jy=$y([ct("postcode-search")],Jy);export{Cy as AddressAutocomplete,cy as MyMap,Jy as PostcodeSearch};