jwtbutler 2.0.9 → 2.1.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.
@@ -358,11 +358,6 @@ var jwtbutler = class {
358
358
  reject(error);
359
359
  });
360
360
  this.captchaRender().then(() => {
361
- let submit = document.querySelector("." + this.config.login_form_class + " form")?.querySelector("button[type=\"submit\"], input[type=\"submit\"]");
362
- if (submit !== null && submit !== void 0) {
363
- submit.disabled = false;
364
- submit.removeAttribute("aria-busy");
365
- }
366
361
  this.triggerLoginFormRenderedEvent();
367
362
  }).catch((error) => {
368
363
  reject(error);
@@ -518,20 +513,23 @@ var jwtbutler = class {
518
513
  sitekey: this.config.captcha.sitekey,
519
514
  theme: this.config.captcha.theme || "light"
520
515
  };
516
+ if (this.captchaProvider() === "turnstile") options.size = "flexible";
517
+ let setSubmitBlocked = (blocked) => {
518
+ let submit = document.querySelector("." + this.config.login_form_class + " form")?.querySelector("button[type=\"submit\"], input[type=\"submit\"]");
519
+ if (submit === null || submit === void 0) return;
520
+ submit.disabled = blocked;
521
+ if (blocked) {
522
+ submit.setAttribute("aria-busy", "true");
523
+ return;
524
+ }
525
+ submit.removeAttribute("aria-busy");
526
+ };
527
+ options.callback = () => setSubmitBlocked(false);
528
+ options["expired-callback"] = () => setSubmitBlocked(true);
529
+ options["error-callback"] = () => setSubmitBlocked(true);
521
530
  if (this.config.language !== "") options[this.captchaVendor().langKey] = this.config.language;
522
- let widgetLoaded = new Promise((resolveWidget) => {
523
- let observer = new MutationObserver(() => {
524
- if (captcha.querySelector("iframe") === null) return;
525
- observer.disconnect();
526
- resolveWidget();
527
- });
528
- observer.observe(captcha, {
529
- childList: true,
530
- subtree: true
531
- });
532
- });
533
531
  captcha.setAttribute("data-widget-id", this.captchaApi().render(captcha, options));
534
- widgetLoaded.then(() => resolve());
532
+ resolve();
535
533
  }).catch((error) => {
536
534
  reject(error);
537
535
  });
@@ -588,6 +586,11 @@ var jwtbutler = class {
588
586
  if (!this.captchaEnabled() || !(this.captchaProvider() in window)) return;
589
587
  let captcha = form.querySelector("." + this.config.login_form_class + "__captcha");
590
588
  if (captcha === null || captcha.getAttribute("data-widget-id") === null) return;
589
+ let submit = form.querySelector("button[type=\"submit\"], input[type=\"submit\"]");
590
+ if (submit !== null) {
591
+ submit.disabled = true;
592
+ submit.setAttribute("aria-busy", "true");
593
+ }
591
594
  this.captchaApi().reset(captcha.getAttribute("data-widget-id"));
592
595
  }
593
596
  bindLoginFormSubmit() {
@@ -615,7 +618,6 @@ var jwtbutler = class {
615
618
  cache: "no-cache"
616
619
  });
617
620
  }).then((res) => res.json()).catch((error) => error).then((response) => {
618
- if (submit !== null) submit.disabled = false;
619
621
  if (response !== void 0 && response !== null && "success" in response && response.success === true) {
620
622
  helpers.remove(document.querySelector("." + this.config.login_form_class));
621
623
  this.setCookies(response.data.access_token).then(() => {
@@ -625,6 +627,7 @@ var jwtbutler = class {
625
627
  reject(error);
626
628
  });
627
629
  } else {
630
+ if (submit !== null && !this.captchaEnabled()) submit.disabled = false;
628
631
  this.removeLoadingStates();
629
632
  this.addLoadingState("login-form-visible");
630
633
  this.captchaReset(form);
package/package.json CHANGED
@@ -65,7 +65,7 @@
65
65
  "uuid": "^11.1.1"
66
66
  },
67
67
  "name": "jwtbutler",
68
- "version": "2.0.9",
68
+ "version": "2.1.0",
69
69
  "description": "",
70
70
  "main": "_js/_build/script.js",
71
71
  "files": [