@descope/web-components-ui 1.0.406 → 1.0.407
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.
@@ -1 +1 @@
|
|
1
|
-
"use strict";(self.webpackChunk_descope_web_components_ui=self.webpackChunk_descope_web_components_ui||[]).push([[3847],{19552:(e,t,a)=>{a.r(t),a.d(t,{RecaptchaClass:()=>
|
1
|
+
"use strict";(self.webpackChunk_descope_web_components_ui=self.webpackChunk_descope_web_components_ui||[]).push([[3847],{19552:(e,t,a)=>{a.r(t),a.d(t,{RecaptchaClass:()=>p});var n=a(94619),s=a(70263),c=a(7138),i=a(14944);const r=(0,i.xE)("recaptcha"),h=["enabled","site-key","action","enterprise"],o=(0,s.q)({componentName:r,baseSelector:":host > div"}),p=(0,c.Zz)(n.VO)(class extends o{static get observedAttributes(){return h.concat(o.observedAttributes||[])}attributeChangedCallback(e,t,a){super.attributeChangedCallback?.(e,t,a),t!==a&&"enabled"===e&&this.#e("true"===a)}renderRecaptcha(e){this.children.length?this.updatePreview():e?(this.recaptchaEle.style.display="",this.mockRecaptchaEle.style.display="none"):(this.recaptchaEle.style.display="none",this.mockRecaptchaEle.style.display="")}constructor(){super(),this.attachShadow({mode:"open"}).innerHTML='\n\t\t<style>\n :host {\n display: inline-flex;\n }\n :host > div:not(.hidden) {\n display: flex;\n }\n :host #recaptcha .grecaptcha-badge {\n box-shadow: none !important;\n }\n :host #recaptcha .grecaptcha-logo {\n height: 100%;\n }\n :host #recaptcha {\n\t\t\t\twidth: 100%;\n height: 100%;\n\t\t\t}\n :host img {\n width: 256px;\n }\n :host([full-width="true"]) {\n width: 100%;\n }\n .hidden {\n display: none;\n }\n\t\t</style>\n <div class="badge">\n <span id="recaptcha"></span>\n <img src="https://imgs.descope.com/connectors/templates/recaptcha/recaptcha-big.png" alt="recaptcha"/>\n </div>\n <slot></slot>\n\t',this.recaptchaEle=this.baseElement.querySelector("#recaptcha"),this.mockRecaptchaEle=this.baseElement.querySelector("img"),this.badge=this.shadowRoot.querySelector(".badge")}init(){super.init?.(),(0,i.Ge)(this,this.updatePreview.bind(this))}updatePreview(){this.children.length?(this.recaptchaEle.style.display="none",this.mockRecaptchaEle.style.display="none",this.badge.classList.add("hidden")):this.badge.classList.remove("hidden")}get enterprise(){return"true"===this.getAttribute("enterprise")}get siteKey(){return this.getAttribute("site-key")}get action(){return this.getAttribute("action")||"load"}get enabled(){return"true"===this.getAttribute("enabled")}get scriptURL(){const e=new URL("https://www.google.com/recaptcha/");return e.pathname+=(this.enterprise?"enterprise":"api")+".js",e.searchParams.append("onload","onRecaptchaLoadCallback"),e.searchParams.append("render","explicit"),e.toString()}#e(e){this.renderRecaptcha(e),e&&(this.#t(),document.getElementById("recaptcha-script")?window.onRecaptchaLoadCallback():this.#a())}#a(){const e=document.createElement("script");e.src=this.scriptURL,e.async=!0,e.id="recaptcha-script",e.defer=!0,document.body.appendChild(e)}get grecaptchaInstance(){return this.enterprise?window.grecaptcha?.enterprise:window.grecaptcha}#n(e,t,a){this.isConnected&&e.ready((()=>{const n=t.querySelector('textarea[name^="g-recaptcha-response"]')?.cloneNode();if(n&&(n.style.display="none",document.body.appendChild(n)),!this.siteKey)return;const s=e?.execute(a,{action:this.action});s.then(((s,c)=>{c?console.warn("could not execute recaptcha",c):(this.updateComponentsContext({risktoken:s,riskaction:this.action}),this.isConnected&&setTimeout((()=>{this.#n(e,t,a)}),11e4)),n.remove()}))}))}#t(){window.onRecaptchaLoadCallback=()=>{const e=this.recaptchaEle;if(e.hasChildNodes())return;const{grecaptchaInstance:t}=this;t&&setTimeout((()=>{const a=t.render(e,{sitekey:this.siteKey,badge:"inline",size:"invisible"});this.#n(t,e,a)}),0)}}});customElements.define(r,p)}}]);
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { draggableMixin } from '../../mixins';
|
2
2
|
import { createBaseClass } from '../../baseClasses/createBaseClass';
|
3
3
|
import { compose } from '../../helpers';
|
4
|
-
import { getComponentName } from '../../helpers/componentHelpers';
|
4
|
+
import { getComponentName, observeChildren } from '../../helpers/componentHelpers';
|
5
5
|
|
6
6
|
export const componentName = getComponentName('recaptcha');
|
7
7
|
|
@@ -26,6 +26,11 @@ class RawRecaptcha extends BaseClass {
|
|
26
26
|
}
|
27
27
|
|
28
28
|
renderRecaptcha(enabled) {
|
29
|
+
if (this.children.length) {
|
30
|
+
this.updatePreview();
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
|
29
34
|
if (enabled) {
|
30
35
|
this.recaptchaEle.style.display = '';
|
31
36
|
this.mockRecaptchaEle.style.display = 'none';
|
@@ -43,7 +48,7 @@ class RawRecaptcha extends BaseClass {
|
|
43
48
|
:host {
|
44
49
|
display: inline-flex;
|
45
50
|
}
|
46
|
-
:host > div {
|
51
|
+
:host > div:not(.hidden) {
|
47
52
|
display: flex;
|
48
53
|
}
|
49
54
|
:host #recaptcha .grecaptcha-badge {
|
@@ -58,16 +63,40 @@ class RawRecaptcha extends BaseClass {
|
|
58
63
|
}
|
59
64
|
:host img {
|
60
65
|
width: 256px;
|
66
|
+
}
|
67
|
+
:host([full-width="true"]) {
|
68
|
+
width: 100%;
|
69
|
+
}
|
70
|
+
.hidden {
|
71
|
+
display: none;
|
61
72
|
}
|
62
73
|
</style>
|
63
|
-
<div>
|
74
|
+
<div class="badge">
|
64
75
|
<span id="recaptcha"></span>
|
65
76
|
<img src="https://imgs.descope.com/connectors/templates/recaptcha/recaptcha-big.png" alt="recaptcha"/>
|
66
77
|
</div>
|
78
|
+
<slot></slot>
|
67
79
|
`;
|
68
80
|
|
69
81
|
this.recaptchaEle = this.baseElement.querySelector('#recaptcha');
|
70
82
|
this.mockRecaptchaEle = this.baseElement.querySelector('img');
|
83
|
+
this.badge = this.shadowRoot.querySelector('.badge');
|
84
|
+
}
|
85
|
+
|
86
|
+
init() {
|
87
|
+
super.init?.();
|
88
|
+
|
89
|
+
observeChildren(this, this.updatePreview.bind(this));
|
90
|
+
}
|
91
|
+
|
92
|
+
updatePreview() {
|
93
|
+
if (this.children.length) {
|
94
|
+
this.recaptchaEle.style.display = 'none';
|
95
|
+
this.mockRecaptchaEle.style.display = 'none';
|
96
|
+
this.badge.classList.add('hidden');
|
97
|
+
} else {
|
98
|
+
this.badge.classList.remove('hidden');
|
99
|
+
}
|
71
100
|
}
|
72
101
|
|
73
102
|
get enterprise() {
|