@descope/web-components-ui 3.2.1 → 3.3.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.
@@ -25119,7 +25119,7 @@ const darkTheme = merge({}, defaultTheme, {
25119
25119
 
25120
25120
  const componentName$2 = getComponentName$1('recaptcha');
25121
25121
 
25122
- const observedAttributes = ['enabled', 'site-key', 'action', 'enterprise'];
25122
+ const observedAttributes = ['enabled', 'site-key', 'action', 'enterprise', 'variant'];
25123
25123
 
25124
25124
  const BaseClass$1 = createBaseClass({
25125
25125
  componentName: componentName$2,
@@ -25136,6 +25136,10 @@ class RawRecaptcha extends BaseClass$1 {
25136
25136
  if (attrName === 'enabled') {
25137
25137
  this.#toggleRecaptcha(newValue === 'true');
25138
25138
  }
25139
+
25140
+ if (attrName === 'variant') {
25141
+ this.updatePreview();
25142
+ }
25139
25143
  }
25140
25144
  }
25141
25145
 
@@ -25148,13 +25152,37 @@ class RawRecaptcha extends BaseClass$1 {
25148
25152
  this.toggleRecaptchaEles(enabled);
25149
25153
  }
25150
25154
 
25155
+ displayRecaptcha() {
25156
+ if (this.isWidget) {
25157
+ this.displayWidget();
25158
+ } else {
25159
+ this.displayDeprecated();
25160
+ }
25161
+ }
25162
+
25163
+ displayWidget() {
25164
+ this.mockRecaptchaEle.style.display = 'none';
25165
+ this.recaptchaWidgetEle.style.display = '';
25166
+ this.depercatedRecaptchaEle.style.display = 'none';
25167
+ }
25168
+
25169
+ hideRecaptcha() {
25170
+ this.recaptchaWidgetEle.style.display = 'none';
25171
+ this.depercatedRecaptchaEle.style.display = 'none';
25172
+ this.mockRecaptchaEle.style.display = '';
25173
+ }
25174
+
25175
+ displayDeprecated() {
25176
+ this.mockRecaptchaEle.style.display = 'none';
25177
+ this.recaptchaWidgetEle.style.display = 'none';
25178
+ this.depercatedRecaptchaEle.style.display = '';
25179
+ }
25180
+
25151
25181
  toggleRecaptchaEles(enabled) {
25152
25182
  if (enabled) {
25153
- this.recaptchaEle.style.display = '';
25154
- this.mockRecaptchaEle.style.display = 'none';
25183
+ this.displayRecaptcha();
25155
25184
  } else {
25156
- this.recaptchaEle.style.display = 'none';
25157
- this.mockRecaptchaEle.style.display = '';
25185
+ this.hideRecaptcha();
25158
25186
  }
25159
25187
  }
25160
25188
 
@@ -25164,6 +25192,8 @@ class RawRecaptcha extends BaseClass$1 {
25164
25192
  this.attachShadow({ mode: 'open' }).innerHTML = `
25165
25193
  <div class="badge">
25166
25194
  <span id="recaptcha"></span>
25195
+ <span id="recaptcha-widget"></span>
25196
+ <input id="recaptcha-widget-input" type="hidden" name="recaptcha-widget" required />
25167
25197
  <img src="https://imgs.descope.com/connectors/templates/recaptcha/recaptcha-big.png" alt="recaptcha"/>
25168
25198
  </div>
25169
25199
  <slot></slot>
@@ -25187,6 +25217,13 @@ class RawRecaptcha extends BaseClass$1 {
25187
25217
  width: 100%;
25188
25218
  height: 100%;
25189
25219
  }
25220
+ :host #recaptcha-widget {
25221
+ width: 100%;
25222
+ height: 100%;
25223
+ }
25224
+ :host #recaptcha-widget-input {
25225
+ display: none;
25226
+ }
25190
25227
  :host img {
25191
25228
  width: 256px;
25192
25229
  }
@@ -25200,7 +25237,9 @@ class RawRecaptcha extends BaseClass$1 {
25200
25237
  this
25201
25238
  );
25202
25239
 
25203
- this.recaptchaEle = this.baseElement.querySelector('#recaptcha');
25240
+ this.depercatedRecaptchaEle = this.baseElement.querySelector('#recaptcha');
25241
+ this.recaptchaWidgetEle = this.baseElement.querySelector('#recaptcha-widget');
25242
+ this.recaptchaWidgetInputEle = this.baseElement.querySelector('#recaptcha-widget-input');
25204
25243
  this.mockRecaptchaEle = this.baseElement.querySelector('img');
25205
25244
  this.badge = this.shadowRoot.querySelector('.badge');
25206
25245
  }
@@ -25213,7 +25252,8 @@ class RawRecaptcha extends BaseClass$1 {
25213
25252
 
25214
25253
  updatePreview() {
25215
25254
  if (this.children.length) {
25216
- this.recaptchaEle.style.display = 'none';
25255
+ this.depercatedRecaptchaEle.style.display = 'none';
25256
+ this.recaptchaWidgetEle.style.display = 'none';
25217
25257
  this.mockRecaptchaEle.style.display = 'none';
25218
25258
  this.badge.classList.add('hidden');
25219
25259
  } else {
@@ -25222,6 +25262,26 @@ class RawRecaptcha extends BaseClass$1 {
25222
25262
  }
25223
25263
  }
25224
25264
 
25265
+ getValidity() {
25266
+ if (!this.isWidget) {
25267
+ return {};
25268
+ }
25269
+
25270
+ if (!this.recaptchaWidgetInputEle.value) {
25271
+ return { valueMissing: true };
25272
+ }
25273
+
25274
+ return {};
25275
+ }
25276
+
25277
+ checkValidity() {
25278
+ if (!this.isWidget) {
25279
+ return true;
25280
+ }
25281
+
25282
+ return !!this.recaptchaWidgetInputEle.value;
25283
+ }
25284
+
25225
25285
  get enterprise() {
25226
25286
  return this.getAttribute('enterprise') === 'true';
25227
25287
  }
@@ -25238,6 +25298,14 @@ class RawRecaptcha extends BaseClass$1 {
25238
25298
  return this.getAttribute('enabled') === 'true';
25239
25299
  }
25240
25300
 
25301
+ get variant() {
25302
+ return this.getAttribute('variant') || 'text';
25303
+ }
25304
+
25305
+ get isWidget() {
25306
+ return this.variant === 'widget';
25307
+ }
25308
+
25241
25309
  get scriptURL() {
25242
25310
  const url = new URL('https://www.google.com/recaptcha/');
25243
25311
  url.pathname += `${this.enterprise ? 'enterprise' : 'api'}.js`;
@@ -25248,6 +25316,11 @@ class RawRecaptcha extends BaseClass$1 {
25248
25316
 
25249
25317
  #toggleRecaptcha(enabled) {
25250
25318
  this.renderRecaptcha(enabled);
25319
+ if (this.isWidget) {
25320
+ // For the v2 checkbox flow, scripts are loaded/executed by the runtime (grecaptcha-v2).
25321
+ // This legacy v3/invisible path must be fully skipped.
25322
+ return;
25323
+ }
25251
25324
  if (enabled) {
25252
25325
  this.#createOnLoadScript();
25253
25326
  if (!document.getElementById('recaptcha-script')) {
@@ -25320,7 +25393,7 @@ class RawRecaptcha extends BaseClass$1 {
25320
25393
 
25321
25394
  #createOnLoadScript() {
25322
25395
  window.onRecaptchaLoadCallback = () => {
25323
- const currentNode = this.recaptchaEle;
25396
+ const currentNode = this.depercatedRecaptchaEle;
25324
25397
 
25325
25398
  // if there are child nodes, it means that the recaptcha was already rendered
25326
25399
  if (currentNode.hasChildNodes()) {