@salesforcedevs/dw-components 1.3.397-canary.4 → 1.3.397-canary.5
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,25 +1,33 @@
|
|
|
1
1
|
import { api, LightningElement } from "lwc";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
3
|
+
// NOTE: This component assumes it is the only Recaptcha widget on a page.
|
|
4
|
+
type RecaptchaApi = {
|
|
5
|
+
render(element: HTMLElement | null, recaptchaConfig: any): void;
|
|
6
|
+
reset(): void;
|
|
7
|
+
};
|
|
9
8
|
|
|
10
9
|
export default class Recaptcha extends LightningElement {
|
|
11
|
-
private _recaptchaToken = "";
|
|
12
10
|
private errorMessage = "";
|
|
13
|
-
private
|
|
11
|
+
private recaptchaDiv!: HTMLDivElement;
|
|
12
|
+
private recaptchaApi?: RecaptchaApi;
|
|
13
|
+
private recaptchaToken = "";
|
|
14
14
|
|
|
15
15
|
@api missingErrorMessage = "Complete the captcha";
|
|
16
16
|
@api recaptchaSiteKey = "";
|
|
17
17
|
|
|
18
18
|
@api // read only
|
|
19
19
|
get value() {
|
|
20
|
-
return this.
|
|
20
|
+
return this.recaptchaToken;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
@api
|
|
24
|
+
recaptchaScriptOnLoad = (recaptchaApi: RecaptchaApi) => {
|
|
25
|
+
this.recaptchaApi = recaptchaApi;
|
|
26
|
+
if (this.recaptchaDiv) {
|
|
27
|
+
this.renderRecaptcha();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
23
31
|
@api
|
|
24
32
|
reset = () => this.resetRecaptcha();
|
|
25
33
|
|
|
@@ -36,38 +44,42 @@ export default class Recaptcha extends LightningElement {
|
|
|
36
44
|
|
|
37
45
|
@api
|
|
38
46
|
checkValidity = () => {
|
|
39
|
-
return Boolean(
|
|
40
|
-
(
|
|
41
|
-
this.slottedRecaptchaDiv?.querySelector(
|
|
42
|
-
"#g-recaptcha-response"
|
|
43
|
-
) as HTMLTextAreaElement
|
|
44
|
-
)?.value
|
|
45
|
-
);
|
|
47
|
+
return Boolean(this.recaptchaToken);
|
|
46
48
|
};
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
this.
|
|
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
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private renderRecaptcha = () => {
|
|
50
62
|
const smallMatchMedia = window.matchMedia(
|
|
51
63
|
"screen and (max-width: 768px)"
|
|
52
64
|
);
|
|
53
65
|
|
|
54
66
|
// render recaptcha, referencing this component's callbacks for handling events
|
|
55
|
-
|
|
67
|
+
this.recaptchaApi?.render(this.recaptchaDiv, {
|
|
56
68
|
sitekey: this.recaptchaSiteKey,
|
|
57
69
|
callback: this.recaptchaCallback,
|
|
58
70
|
"expired-callback": this.recaptchaExpiredCallback,
|
|
59
71
|
"error-callback": this.recaptchaErrorCallback,
|
|
60
72
|
size: smallMatchMedia.matches ? "compact" : "normal"
|
|
61
73
|
});
|
|
62
|
-
}
|
|
74
|
+
};
|
|
63
75
|
|
|
64
76
|
private recaptchaCallback = (token: string) => {
|
|
65
|
-
this.
|
|
77
|
+
this.recaptchaToken = token;
|
|
66
78
|
this.errorMessage = "";
|
|
67
79
|
};
|
|
68
80
|
|
|
69
81
|
private recaptchaExpiredCallback = () => {
|
|
70
|
-
this.
|
|
82
|
+
this.recaptchaToken = ""; // note: recaptcha element itself handles showing an "expired" message
|
|
71
83
|
};
|
|
72
84
|
|
|
73
85
|
private recaptchaErrorCallback = () => {
|
|
@@ -76,7 +88,7 @@ export default class Recaptcha extends LightningElement {
|
|
|
76
88
|
};
|
|
77
89
|
|
|
78
90
|
private resetRecaptcha = () => {
|
|
79
|
-
this.
|
|
80
|
-
|
|
91
|
+
this.recaptchaToken = "";
|
|
92
|
+
this.recaptchaApi?.reset();
|
|
81
93
|
};
|
|
82
94
|
}
|