Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mutt/widget-addresslookup

Package Overview
Dependencies
Maintainers
6
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mutt/widget-addresslookup - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

2

dist/widget-address-lookup.es.js

@@ -1,1 +0,1 @@

import MuttVue from"mutt-forms-vue";import Mutt from"mutt-forms";const UK_POSTCODE_PATTERN="^([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})$",REQUIRED_ERROR_MESSAGE="Please enter a valid UK postcode",INVALID_PATTERN_MESSAGE="Please enter a valid UK postcode";class PostcodeValidator extends Mutt.validators.RegexValidator{constructor({pattern:pattern=UK_POSTCODE_PATTERN,requiredErrorMessage:requiredErrorMessage=REQUIRED_ERROR_MESSAGE,invalidPatternErrorMessage:invalidPatternErrorMessage=INVALID_PATTERN_MESSAGE}={}){super(new RegExp(pattern,"i"),{required:requiredErrorMessage,invalidPattern:invalidPatternErrorMessage})}}var script={name:"mutt-address-lookup",mixins:[MuttVue.mixin],data:()=>({errors:null,value:null,manual:!1,addressLookupControl:null,addressLookupFailed:null,addressLookupOptions:{},addressLookupFields:[],postcodeField:null}),mounted(){this.injectCDN()},methods:{init(){if(!this.field.options.hasOwnProperty("addressLookup"))throw new Error("Field missing address lookup options!");if(!this.field.options.addressLookup.key)throw new Error("ADDRESS_LOOKUP_KEY not present!");this.postcodeField=this.field.getFieldByPath("postcode"),this.postcodePlaceholder=this.postcodeField.options.placeholder,this.postcodeField.options.placeholder=this.$t(this.field.options.placeholder||"Enter a postcode"),this.configureValidators({pattern:this.field.options.addressLookup.postcodePattern,requiredErrorMessage:this.field.options.addressLookup.requiredErrorMessage,invalidPatternErrorMessage:this.field.options.addressLookup.invalidPatternErrorMessage}),this.value=this.field.value},initialiseAddressLookup(){const addressLookupOptions={key:this.field.options.addressLookup.key,bar:{visible:!1,showCountry:!1,showLogo:!1},search:{countries:this.field.options.addressLookup.countries||"UK"}};window.pca.ready(()=>{const addressLookupFields=this.field.options.addressLookup.elements.map(el=>(el.mode=window.pca.fieldMode[el.mode],el));this.addressLookupControl=new window.pca.Address(addressLookupFields,addressLookupOptions),this.addressLookupControl.listen("populate",this.select),this.addressLookupControl.load()})},select(data){let result={};for(let element of this.field.options.addressLookup.elements)result[element.element]=data[element.field]||"";this.value=result,this.field.value=this.value,this.postcodeField.validate(),this.$emit("callback",{action:"callback",type:"addressLookupPopulate",addressLookup:data.PostalCode,value:this.value})},configureValidators(options){this.field.getFieldByPath("postcode").validators=[new PostcodeValidator(options)]},toggleManual(state){this.manual=state,this.focus()},focus(){this.$nextTick(()=>{const fieldToFocus=this.$el.querySelector("input[type=text]");fieldToFocus&&fieldToFocus.focus()})},onAddressLookupError(){this.addressLookupFailed=!0,this.manual=!0},injectCDN(){let l=document.createElement("link");l.rel="stylesheet",l.href="https://services.postcodeanywhere.co.uk/css/address-3.70.css",document.head.appendChild(l);let s=document.createElement("script");s.src="https://services.postcodeanywhere.co.uk/js/address-3.70.js",s.onerror=this.onAddressLookupError.bind(this),s.onload=this.initialiseAddressLookup.bind(this),document.head.appendChild(s)}}};const __vue_script__=script;script.__file="/Users/andypattenden/development/mutt-forms/widget-addresslookup/src/AddressLookup.vue";var __vue_render__=function(){var _vm=this,_h=_vm.$createElement,_c=_vm._self._c||_h;return _vm.field?_c("div",{staticClass:"mutt-field-wrapper"},[_c("label-widget",{attrs:{field:_vm.field,"field-id":_vm.getFieldId()}}),_vm._v(" "),_vm.isReadOnly?_c("readonly-widget",{attrs:{value:_vm.field.value}}):_vm._e(),_vm._v(" "),_vm._l(_vm.field.object,function(objectField){return["postcode"===objectField.name||_vm.manual?_c("mutt-widget",{key:objectField.id,ref:objectField.name,refInFor:!0,attrs:{field:objectField}}):_vm._e()]}),_vm._v(" "),_vm.addressLookupControl&&!_vm.isReadOnly?_c("div",{staticClass:"show-manual"},[_vm.manual?_vm._e():_c("button",{staticClass:"btn btn--secondary btn--manual-toggle",attrs:{type:"button"},on:{click:function($event){$event.preventDefault(),_vm.toggleManual(!0)}}},[_vm._v("\n "+_vm._s(_vm.$t("Can't find an address?"))+"\n ")]),_vm._v(" "),_vm.manual?_c("button",{staticClass:"btn btn--secondary btn--search-toggle",attrs:{type:"button"},on:{click:function($event){$event.preventDefault(),_vm.toggleManual(!1)}}},[_c("span",{},[_vm._v(" <")]),_vm._v(" "+_vm._s(_vm.$t("Search for an address"))+"\n ")]):_vm._e()]):_vm._e(),_vm._v(" "),_c("help-widget",{attrs:{field:_vm.field}}),_vm._v(" "),_vm.isReadOnly?_vm._e():_c("error-widget",{attrs:{field:_vm.field,errors:_vm.errors,"error-class":_vm.getErrorClass()}})],2):_vm._e()};__vue_render__._withStripped=!0;export default(function normalizeComponent(compiledTemplate,injectStyle,defaultExport,scopeId,isFunctionalTemplate,moduleIdentifier,isShadowMode,createInjector,createInjectorSSR,createInjectorShadow){"function"==typeof isShadowMode&&(createInjectorSSR=createInjector,createInjector=isShadowMode,isShadowMode=!1);const options="function"==typeof defaultExport?defaultExport.options:defaultExport;let hook;if(compiledTemplate&&compiledTemplate.render&&(options.render=compiledTemplate.render,options.staticRenderFns=compiledTemplate.staticRenderFns,options._compiled=!0,isFunctionalTemplate&&(options.functional=!0)),scopeId&&(options._scopeId=scopeId),moduleIdentifier?(hook=function(context){(context=context||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(context=__VUE_SSR_CONTEXT__),injectStyle&&injectStyle.call(this,createInjectorSSR(context)),context&&context._registeredComponents&&context._registeredComponents.add(moduleIdentifier)},options._ssrRegister=hook):injectStyle&&(hook=isShadowMode?function(){injectStyle.call(this,createInjectorShadow(this.$root.$options.shadowRoot))}:function(context){injectStyle.call(this,createInjector(context))}),hook)if(options.functional){const originalRender=options.render;options.render=function renderWithStyleInjection(h,context){return hook.call(context),originalRender(h,context)}}else{const existing=options.beforeCreate;options.beforeCreate=existing?[].concat(existing,hook):[hook]}return defaultExport}({render:__vue_render__,staticRenderFns:[]},void 0,__vue_script__,void 0,!1,void 0,void 0,void 0));
import MuttVue from"mutt-forms-vue";import Mutt from"mutt-forms";const UK_POSTCODE_PATTERN="^([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})$",REQUIRED_ERROR_MESSAGE="Please enter a valid UK postcode",INVALID_PATTERN_MESSAGE="Please enter a valid UK postcode";class PostcodeValidator extends Mutt.validators.RegexValidator{constructor({pattern:pattern=UK_POSTCODE_PATTERN,requiredErrorMessage:requiredErrorMessage=REQUIRED_ERROR_MESSAGE,invalidPatternErrorMessage:invalidPatternErrorMessage=INVALID_PATTERN_MESSAGE}={}){super(new RegExp(pattern,"i"),{required:requiredErrorMessage,invalidPattern:invalidPatternErrorMessage})}}var script={name:"mutt-address-lookup",mixins:[MuttVue.mixin],data:()=>({errors:null,value:null,manual:!1,addressLookupControl:null,addressLookupFailed:null,addressLookupOptions:{},addressLookupFields:[],postcodeField:null}),mounted(){this.injectCDN()},methods:{init(){if(!this.field.options.hasOwnProperty("addressLookup"))throw new Error("Field missing address lookup options!");if(!this.field.options.addressLookup.key)throw new Error("ADDRESS_LOOKUP_KEY not present!");this.postcodeField=this.field.getFieldByPath("postcode"),this.postcodePlaceholder=this.postcodeField.options.placeholder,this.postcodeField.options.placeholder=this.$t(this.field.options.addressLookup.placeholder||"Enter a postcode"),this.configureValidators({pattern:this.field.options.addressLookup.postcodePattern,requiredErrorMessage:this.field.options.addressLookup.requiredErrorMessage,invalidPatternErrorMessage:this.field.options.addressLookup.invalidPatternErrorMessage}),this.value=this.field.value},initialiseAddressLookup(){const addressLookupOptions={key:this.field.options.addressLookup.key,bar:{visible:!1,showCountry:!1,showLogo:!1},search:{countries:this.field.options.addressLookup.countries||"UK"}};window.pca.ready(()=>{const addressLookupFields=this.field.options.addressLookup.elements.map(el=>(el.mode=window.pca.fieldMode[el.mode],el));this.addressLookupControl=new window.pca.Address(addressLookupFields,addressLookupOptions),this.addressLookupControl.listen("populate",this.select),this.addressLookupControl.load()})},select(data){let result={};for(let element of this.field.options.addressLookup.elements)result[element.element]=data[element.field]||"";this.value=result,this.field.value=this.value,this.postcodeField.validate(),this.$emit("callback",{action:"callback",type:"addressLookupPopulate",addressLookup:data.PostalCode,value:this.value})},configureValidators(options){this.field.getFieldByPath("postcode").validators=[new PostcodeValidator(options)]},toggleManual(state){this.manual=state,this.focus()},focus(){this.$nextTick(()=>{const fieldToFocus=this.$el.querySelector("input[type=text]");fieldToFocus&&fieldToFocus.focus()})},onAddressLookupError(){this.addressLookupFailed=!0,this.manual=!0},injectCDN(){let l=document.createElement("link");l.rel="stylesheet",l.href="https://services.postcodeanywhere.co.uk/css/address-3.70.css",document.head.appendChild(l);let s=document.createElement("script");s.src="https://services.postcodeanywhere.co.uk/js/address-3.70.js",s.onerror=this.onAddressLookupError.bind(this),s.onload=this.initialiseAddressLookup.bind(this),document.head.appendChild(s)}}};const __vue_script__=script;script.__file="/Users/andypattenden/development/mutt-forms/widget-addresslookup/src/AddressLookup.vue";var __vue_render__=function(){var _vm=this,_h=_vm.$createElement,_c=_vm._self._c||_h;return _vm.field?_c("div",{staticClass:"mutt-field-wrapper"},[_c("label-widget",{attrs:{field:_vm.field,"field-id":_vm.getFieldId()}}),_vm._v(" "),_vm.isReadOnly?_c("readonly-widget",{attrs:{value:_vm.field.value}}):_vm._e(),_vm._v(" "),_vm._l(_vm.field.object,function(objectField){return["postcode"===objectField.name||_vm.manual?_c("mutt-widget",{key:objectField.id,ref:objectField.name,refInFor:!0,attrs:{field:objectField}}):_vm._e()]}),_vm._v(" "),_vm.addressLookupControl&&!_vm.isReadOnly?_c("div",{staticClass:"show-manual"},[_vm.manual?_vm._e():_c("button",{staticClass:"btn btn--secondary btn--manual-toggle",attrs:{type:"button"},on:{click:function($event){$event.preventDefault(),_vm.toggleManual(!0)}}},[_vm._v("\n "+_vm._s(_vm.$t("Can't find an address?"))+"\n ")]),_vm._v(" "),_vm.manual?_c("button",{staticClass:"btn btn--secondary btn--search-toggle",attrs:{type:"button"},on:{click:function($event){$event.preventDefault(),_vm.toggleManual(!1)}}},[_c("span",{},[_vm._v(" <")]),_vm._v(" "+_vm._s(_vm.$t("Search for an address"))+"\n ")]):_vm._e()]):_vm._e(),_vm._v(" "),_c("help-widget",{attrs:{field:_vm.field}}),_vm._v(" "),_vm.isReadOnly?_vm._e():_c("error-widget",{attrs:{field:_vm.field,errors:_vm.errors,"error-class":_vm.getErrorClass()}})],2):_vm._e()};__vue_render__._withStripped=!0;export default(function normalizeComponent(compiledTemplate,injectStyle,defaultExport,scopeId,isFunctionalTemplate,moduleIdentifier,isShadowMode,createInjector,createInjectorSSR,createInjectorShadow){"function"==typeof isShadowMode&&(createInjectorSSR=createInjector,createInjector=isShadowMode,isShadowMode=!1);const options="function"==typeof defaultExport?defaultExport.options:defaultExport;let hook;if(compiledTemplate&&compiledTemplate.render&&(options.render=compiledTemplate.render,options.staticRenderFns=compiledTemplate.staticRenderFns,options._compiled=!0,isFunctionalTemplate&&(options.functional=!0)),scopeId&&(options._scopeId=scopeId),moduleIdentifier?(hook=function(context){(context=context||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(context=__VUE_SSR_CONTEXT__),injectStyle&&injectStyle.call(this,createInjectorSSR(context)),context&&context._registeredComponents&&context._registeredComponents.add(moduleIdentifier)},options._ssrRegister=hook):injectStyle&&(hook=isShadowMode?function(){injectStyle.call(this,createInjectorShadow(this.$root.$options.shadowRoot))}:function(context){injectStyle.call(this,createInjector(context))}),hook)if(options.functional){const originalRender=options.render;options.render=function renderWithStyleInjection(h,context){return hook.call(context),originalRender(h,context)}}else{const existing=options.beforeCreate;options.beforeCreate=existing?[].concat(existing,hook):[hook]}return defaultExport}({render:__vue_render__,staticRenderFns:[]},void 0,__vue_script__,void 0,!1,void 0,void 0,void 0));
{
"name": "@mutt/widget-addresslookup",
"version": "0.0.1",
"version": "0.0.2",
"description": "Mutt Forms Widget - Address Lookup",

@@ -8,6 +8,8 @@ "author": "Andy Pattenden <andyp@boughtbymany.com>",

"build": "rollup -c",
"test": "jest",
"lint": "vue-cli-service lint",
"commit": "git-cz",
"test:unit": "vue-cli-service test:unit"
"test:unit": "vue-cli-service test:unit",
"preversion": "npm run lint && npm run test:unit",
"version": "npm run build && git add -A dist",
"postversion": "git push && git push --tags"
},

@@ -14,0 +16,0 @@ "dependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc