@hcaptcha/vue3-hcaptcha
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -121,3 +121,4 @@ import { openBlock, createElementBlock } from "vue"; | ||
widgetId: null, | ||
hcaptcha: null | ||
hcaptcha: null, | ||
renderedCb: null | ||
}; | ||
@@ -129,10 +130,14 @@ }, | ||
unmounted() { | ||
if (this.widgetId) { | ||
this.hcaptcha.then(() => { | ||
this.teardown(); | ||
}, | ||
destroyed() { | ||
this.teardown(); | ||
}, | ||
methods: { | ||
teardown() { | ||
if (this.widgetId) { | ||
this.hcaptcha.reset(this.widgetId); | ||
this.hcaptcha.remove(this.widgetId); | ||
}); | ||
} | ||
}, | ||
methods: { | ||
} | ||
}, | ||
onApiLoaded() { | ||
@@ -166,3 +171,6 @@ this.hcaptcha = window.hcaptcha; | ||
} else { | ||
this.$on("rendered", this.execute); | ||
this.renderedCb = () => { | ||
this.renderedCb = null; | ||
this.execute(); | ||
}; | ||
} | ||
@@ -180,2 +188,3 @@ }, | ||
this.$emit("rendered"); | ||
this.renderedCb && this.renderedCb(); | ||
}, | ||
@@ -182,0 +191,0 @@ onExecuted() { |
@@ -1,1 +0,1 @@ | ||
(function(d,r){typeof exports=="object"&&typeof module!="undefined"?module.exports=r(require("vue")):typeof define=="function"&&define.amd?define(["vue"],r):(d=typeof globalThis!="undefined"?globalThis:d||self,d.VueHcaptcha=r(d.Vue))})(this,function(d){"use strict";const r="hcaptcha-api-script-id",h="_hcaptchaOnLoad";let s,c;const o=new Promise((t,e)=>{s=t,c=e});function p(t){if(window.hcaptcha)return s(),o;if(document.getElementById(r))return o;window[h]=s;const e=l(t),i=document.createElement("script");return i.id=r,i.src=e,i.async=!0,i.defer=!0,i.onerror=a=>{console.error("Failed to load api: "+e,a),c("Failed to load api.js")},document.head.appendChild(i),o}function l(t){let e=t.apiEndpoint;return e=n(e,"render","explicit"),e=n(e,"onload",h),e=n(e,"recaptchacompat",t.reCaptchaCompat===!1?"off":null),e=n(e,"hl",t.language),e=n(e,"sentry",t.sentry),e=n(e,"endpoint",t.endpoint),e=n(e,"assethost",t.assethost),e=n(e,"imghost",t.imghost),e=n(e,"reportapi",t.reportapi),e}function n(t,e,i){if(i!=null){const a=t.includes("?")?"&":"?";return t+a+e+"="+encodeURIComponent(i)}return t}var u=(t,e)=>{for(const[i,a]of e)t[i]=a;return t};const f={name:"VueHcaptcha",props:{sitekey:{type:String,required:!0},theme:{type:String,default:void 0},size:{type:String,default:void 0},tabindex:{type:String,default:void 0},language:{type:String,default:void 0},reCaptchaCompat:{type:Boolean,default:!0},challengeContainer:{type:String,default:void 0},rqdata:{type:String,default:void 0},sentry:{type:Boolean,default:!0},apiEndpoint:{type:String,default:"https://hcaptcha.com/1/api.js"},endpoint:{type:String,default:void 0},reportapi:{type:String,default:void 0},assethost:{type:String,default:void 0},imghost:{type:String,default:void 0}},data:()=>({widgetId:null,hcaptcha:null}),mounted(){return p(this.$props).then(this.onApiLoaded).catch(this.onError)},unmounted(){this.widgetId&&this.hcaptcha.then(()=>{this.hcaptcha.reset(this.widgetId),this.hcaptcha.remove(this.widgetId)})},methods:{onApiLoaded(){this.hcaptcha=window.hcaptcha;const t={sitekey:this.sitekey,theme:this.theme,size:this.size,tabindex:this.tabindex,callback:this.onVerify,"expired-callback":this.onExpired,"chalexpired-callback":this.onChallengeExpired,"error-callback":this.onError,"open-callback":this.onOpen,"close-callback":this.onClose};this.challengeContainer&&(t["challenge-container"]=this.challengeContainer),this.widgetId=this.hcaptcha.render(this.$el,t),this.rqdata&&this.hcaptcha.setData(this.widgetId,{rqdata:this.rqdata}),this.onRendered()},execute(){this.widgetId?(this.hcaptcha.execute(this.widgetId),this.onExecuted()):this.$on("rendered",this.execute)},reset(){this.widgetId?(this.hcaptcha.reset(this.widgetId),this.onReset()):this.$emit("error","Element is not rendered yet and thus cannot reset it. Wait for `rendered` event to safely call reset.")},onRendered(){this.$emit("rendered")},onExecuted(){this.$emit("executed")},onReset(){this.$emit("reset")},onError(t){this.$emit("error",t),this.reset()},onVerify(){const t=this.hcaptcha.getResponse(this.widgetId),e=this.hcaptcha.getRespKey(this.widgetId);this.$emit("verify",t,e)},onExpired(){this.$emit("expired")},onChallengeExpired(){this.$emit("challengeExpired")},onOpen(){this.$emit("opened")},onClose(){this.$emit("closed")}}},m={id:"hcap-script"};function g(t,e,i,a,x,w){return d.openBlock(),d.createElementBlock("div",m)}var y=u(f,[["render",g]]);return y}); | ||
(function(d,r){typeof exports=="object"&&typeof module!="undefined"?module.exports=r(require("vue")):typeof define=="function"&&define.amd?define(["vue"],r):(d=typeof globalThis!="undefined"?globalThis:d||self,d.VueHcaptcha=r(d.Vue))})(this,function(d){"use strict";const r="hcaptcha-api-script-id",h="_hcaptchaOnLoad";let a,c;const o=new Promise((t,e)=>{a=t,c=e});function p(t){if(window.hcaptcha)return a(),o;if(document.getElementById(r))return o;window[h]=a;const e=l(t),i=document.createElement("script");return i.id=r,i.src=e,i.async=!0,i.defer=!0,i.onerror=s=>{console.error("Failed to load api: "+e,s),c("Failed to load api.js")},document.head.appendChild(i),o}function l(t){let e=t.apiEndpoint;return e=n(e,"render","explicit"),e=n(e,"onload",h),e=n(e,"recaptchacompat",t.reCaptchaCompat===!1?"off":null),e=n(e,"hl",t.language),e=n(e,"sentry",t.sentry),e=n(e,"endpoint",t.endpoint),e=n(e,"assethost",t.assethost),e=n(e,"imghost",t.imghost),e=n(e,"reportapi",t.reportapi),e}function n(t,e,i){if(i!=null){const s=t.includes("?")?"&":"?";return t+s+e+"="+encodeURIComponent(i)}return t}var u=(t,e)=>{for(const[i,s]of e)t[i]=s;return t};const f={name:"VueHcaptcha",props:{sitekey:{type:String,required:!0},theme:{type:String,default:void 0},size:{type:String,default:void 0},tabindex:{type:String,default:void 0},language:{type:String,default:void 0},reCaptchaCompat:{type:Boolean,default:!0},challengeContainer:{type:String,default:void 0},rqdata:{type:String,default:void 0},sentry:{type:Boolean,default:!0},apiEndpoint:{type:String,default:"https://hcaptcha.com/1/api.js"},endpoint:{type:String,default:void 0},reportapi:{type:String,default:void 0},assethost:{type:String,default:void 0},imghost:{type:String,default:void 0}},data:()=>({widgetId:null,hcaptcha:null,renderedCb:null}),mounted(){return p(this.$props).then(this.onApiLoaded).catch(this.onError)},unmounted(){this.teardown()},destroyed(){this.teardown()},methods:{teardown(){this.widgetId&&(this.hcaptcha.reset(this.widgetId),this.hcaptcha.remove(this.widgetId))},onApiLoaded(){this.hcaptcha=window.hcaptcha;const t={sitekey:this.sitekey,theme:this.theme,size:this.size,tabindex:this.tabindex,callback:this.onVerify,"expired-callback":this.onExpired,"chalexpired-callback":this.onChallengeExpired,"error-callback":this.onError,"open-callback":this.onOpen,"close-callback":this.onClose};this.challengeContainer&&(t["challenge-container"]=this.challengeContainer),this.widgetId=this.hcaptcha.render(this.$el,t),this.rqdata&&this.hcaptcha.setData(this.widgetId,{rqdata:this.rqdata}),this.onRendered()},execute(){this.widgetId?(this.hcaptcha.execute(this.widgetId),this.onExecuted()):this.renderedCb=()=>{this.renderedCb=null,this.execute()}},reset(){this.widgetId?(this.hcaptcha.reset(this.widgetId),this.onReset()):this.$emit("error","Element is not rendered yet and thus cannot reset it. Wait for `rendered` event to safely call reset.")},onRendered(){this.$emit("rendered"),this.renderedCb&&this.renderedCb()},onExecuted(){this.$emit("executed")},onReset(){this.$emit("reset")},onError(t){this.$emit("error",t),this.reset()},onVerify(){const t=this.hcaptcha.getResponse(this.widgetId),e=this.hcaptcha.getRespKey(this.widgetId);this.$emit("verify",t,e)},onExpired(){this.$emit("expired")},onChallengeExpired(){this.$emit("challengeExpired")},onOpen(){this.$emit("opened")},onClose(){this.$emit("closed")}}},m={id:"hcap-script"};function g(t,e,i,s,w,x){return d.openBlock(),d.createElementBlock("div",m)}var y=u(f,[["render",g]]);return y}); |
{ | ||
"name": "@hcaptcha/vue3-hcaptcha", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"author": "hCaptcha team and contributors", | ||
@@ -42,3 +42,3 @@ "homepage": "https://github.com/hCaptcha/vue-hcaptcha", | ||
"@vitejs/plugin-vue": "^1.9.3", | ||
"@vue/test-utils": "^1.2.2", | ||
"@vue/test-utils": "^2.0.0-rc.16", | ||
"babel-core": "^7.0.0-bridge.0", | ||
@@ -56,3 +56,3 @@ "babel-jest": "^26.6.3", | ||
}, | ||
"gitHead": "74c1f6d54004dce39e03b6be29e7cff358b1441a" | ||
"gitHead": "23213787f03d24c65b871540c1936db914e3eac2" | ||
} |
@@ -145,1 +145,12 @@ # Vue.js hCaptcha Component Library | ||
* CI/CD pipeline will publish the new version(s) to: [@hcaptcha/vue-hcaptcha](https://www.npmjs.com/package/@hcaptcha/vue-hcaptcha) or [@hcaptcha/vue3-hcaptcha](https://www.npmjs.com/package/@hcaptcha/vue3-hcaptcha). | ||
### Contributing + Notable Contributors | ||
`vue-hcaptcha` is developed and maintained through the collective efforts of the hCaptcha community. | ||
This includes developers like you! We welcome your issues, suggestions, and PRs. | ||
Notable contributors for larger changes: | ||
- Vue2 support: hCaptcha team | ||
- Vue3 support: JDinABox and DSergiu |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17359
235
156