@salesforcedevs/dw-components 1.3.397-canary.5 → 1.3.397-canary.7

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dw-components",
3
- "version": "1.3.397-canary.5",
3
+ "version": "1.3.397-canary.7",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -4,7 +4,7 @@ import { track as trackGtm } from "dxUtils/analytics";
4
4
  import { submitForm, ErrorCode, SignupForm, UserData } from "./submitForm";
5
5
  import { CountryOptions } from "typings/custom";
6
6
  import { stateMap } from "dwUtils/forms";
7
- import Recaptcha from "packages/@salesforcedevs/dw-components/src/modules/dw/recaptcha/recaptcha";
7
+ import Recaptcha from "dw/recaptcha";
8
8
 
9
9
  type SelectOption = { value: string; label: string };
10
10
  type Country = SelectOption & {
@@ -86,7 +86,9 @@ export default class DeSignupForm extends LightningElement {
86
86
  }
87
87
 
88
88
  onSlotChange(e: Event) {
89
- this.recaptchaComponent = e.target as Recaptcha;
89
+ this.recaptchaComponent = (
90
+ e.target as HTMLSlotElement
91
+ )?.assignedElements()[0] as unknown as Recaptcha;
90
92
  }
91
93
 
92
94
  createUUID() {
@@ -1,13 +1,6 @@
1
1
  @import "dxHelpers/reset";
2
2
  @import "dxHelpers/text";
3
3
 
4
- .container {
5
- width: 100%;
6
- display: flex;
7
- justify-content: center;
8
- margin-bottom: var(--dx-g-spacing-lg);
9
- }
10
-
11
4
  .error-message-box {
12
5
  margin-top: var(--dx-g-spacing-xs);
13
6
  display: block;
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div class="container">
3
- <div class="g-recaptcha"></div>
3
+ <slot onslotchange={onSlotChange}></slot>
4
4
  <div
5
5
  if:true={errorMessage}
6
6
  aria-live="assertive"
@@ -7,12 +7,13 @@ type RecaptchaApi = {
7
7
  };
8
8
 
9
9
  export default class Recaptcha extends LightningElement {
10
+ private didRenderRecaptcha = false;
10
11
  private errorMessage = "";
11
- private recaptchaDiv!: HTMLDivElement;
12
+ private recaptchaDiv?: HTMLDivElement;
12
13
  private recaptchaApi?: RecaptchaApi;
13
14
  private recaptchaToken = "";
14
15
 
15
- @api missingErrorMessage = "Complete the captcha";
16
+ @api missingErrorMessage = "Please complete the captcha";
16
17
  @api recaptchaSiteKey = "";
17
18
 
18
19
  @api // read only
@@ -22,7 +23,10 @@ export default class Recaptcha extends LightningElement {
22
23
 
23
24
  @api
24
25
  recaptchaScriptOnLoad = (recaptchaApi: RecaptchaApi) => {
26
+ // store callbacks to be used with recaptcha
25
27
  this.recaptchaApi = recaptchaApi;
28
+
29
+ // and if we have everything needed to render, render
26
30
  if (this.recaptchaDiv) {
27
31
  this.renderRecaptcha();
28
32
  }
@@ -47,30 +51,36 @@ export default class Recaptcha extends LightningElement {
47
51
  return Boolean(this.recaptchaToken);
48
52
  };
49
53
 
50
- renderedCallback() {
51
- if (!this.recaptchaDiv) {
52
- this.recaptchaDiv = this.template.querySelector(
53
- ".g-recaptcha"
54
- ) as HTMLDivElement;
55
- if (this.recaptchaApi) {
56
- this.renderRecaptcha();
57
- }
54
+ private onSlotChange = (e: Event) => {
55
+ this.recaptchaDiv = (
56
+ e.target as HTMLSlotElement
57
+ )?.assignedElements?.()[0] as HTMLDivElement;
58
+
59
+ // if we have everything needed to render, render
60
+ if (this.recaptchaApi) {
61
+ this.renderRecaptcha();
58
62
  }
59
- }
63
+ };
60
64
 
61
65
  private renderRecaptcha = () => {
66
+ if (this.didRenderRecaptcha) {
67
+ return;
68
+ }
69
+
62
70
  const smallMatchMedia = window.matchMedia(
63
71
  "screen and (max-width: 768px)"
64
72
  );
65
73
 
66
74
  // render recaptcha, referencing this component's callbacks for handling events
67
- this.recaptchaApi?.render(this.recaptchaDiv, {
75
+ this.recaptchaApi?.render(this.recaptchaDiv as HTMLDivElement, {
68
76
  sitekey: this.recaptchaSiteKey,
69
77
  callback: this.recaptchaCallback,
70
78
  "expired-callback": this.recaptchaExpiredCallback,
71
79
  "error-callback": this.recaptchaErrorCallback,
72
80
  size: smallMatchMedia.matches ? "compact" : "normal"
73
81
  });
82
+
83
+ this.didRenderRecaptcha = true;
74
84
  };
75
85
 
76
86
  private recaptchaCallback = (token: string) => {