base-recaptcha.component.d.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import { AfterViewChecked, AfterViewInit, ElementRef, EventEmitter, Injector, NgZone, OnChanges, Renderer2, SimpleChanges } from "@angular/core";
  2. import { ControlValueAccessor, AbstractControl } from "@angular/forms";
  3. import { ReCaptchaType } from "../models/recaptcha-type.enum";
  4. import { ScriptService } from "../services/script.service";
  5. import * as i0 from "@angular/core";
  6. export declare abstract class BaseReCaptchaComponent implements OnChanges, ControlValueAccessor, AfterViewInit, AfterViewChecked {
  7. protected renderer: Renderer2;
  8. protected zone: NgZone;
  9. protected injector: Injector;
  10. protected scriptService: ScriptService;
  11. /**
  12. * Prefix of the captcha element
  13. */
  14. protected readonly captchaElemPrefix = "ngx_captcha_id_";
  15. private setupCaptcha;
  16. /**
  17. * Google's site key.
  18. * You can find this under https://www.google.com/recaptcha
  19. */
  20. siteKey: string;
  21. /**
  22. * Indicates if global domain 'recaptcha.net' should be used instead of default domain ('google.com')
  23. */
  24. useGlobalDomain: boolean;
  25. /**
  26. * Type
  27. */
  28. type: "audio" | "image";
  29. /**
  30. * Language code. Auto-detects the user's language if unspecified.
  31. */
  32. hl: string;
  33. /**
  34. * Tab index
  35. */
  36. tabIndex: number;
  37. /**
  38. * Called when captcha receives successful response.
  39. * Captcha response token is passed to event.
  40. */
  41. success: EventEmitter<string>;
  42. /**
  43. * Called when captcha is loaded. Event receives id of the captcha
  44. */
  45. load: EventEmitter<void>;
  46. /**
  47. * Called when captcha is reset.
  48. */
  49. reset: EventEmitter<void>;
  50. /**
  51. * Called when captcha is loaded & ready. I.e. when you need to execute captcha on component load.
  52. */
  53. ready: EventEmitter<void>;
  54. /**
  55. * Error callback
  56. */
  57. error: EventEmitter<void>;
  58. /**
  59. * Expired callback
  60. */
  61. expire: EventEmitter<void>;
  62. abstract captchaWrapperElem?: ElementRef;
  63. /**
  64. * Indicates if captcha should be set on load
  65. */
  66. private setupAfterLoad;
  67. /**
  68. * Captcha element
  69. */
  70. protected captchaElem?: HTMLElement;
  71. /**
  72. * Id of the captcha elem
  73. */
  74. protected captchaId?: number;
  75. /**
  76. * Holds last response value
  77. */
  78. protected currentResponse?: string;
  79. /**
  80. * If enabled, captcha will reset after receiving success response. This is useful
  81. * when invisible captcha need to be resolved multiple times on same page
  82. */
  83. protected resetCaptchaAfterSuccess: boolean;
  84. /**
  85. * Captcha type
  86. */
  87. protected abstract recaptchaType: ReCaptchaType;
  88. /**
  89. * Required by ControlValueAccessor
  90. */
  91. protected onChange: (value: string | undefined) => void;
  92. protected onTouched: (value: string | undefined) => void;
  93. /**
  94. * Indicates if captcha is loaded
  95. */
  96. isLoaded: boolean;
  97. /**
  98. * Reference to global reCaptcha API
  99. */
  100. reCaptchaApi?: any;
  101. /**
  102. * Id of the DOM element wrapping captcha
  103. */
  104. captchaElemId?: string;
  105. /**
  106. * Form Control to be enable usage in reactive forms
  107. */
  108. control?: AbstractControl | null;
  109. protected constructor(renderer: Renderer2, zone: NgZone, injector: Injector, scriptService: ScriptService);
  110. ngAfterViewInit(): void;
  111. ngAfterViewChecked(): void;
  112. /**
  113. * Gets reCaptcha properties
  114. */
  115. protected abstract getCaptchaProperties(): any;
  116. /**
  117. * Used for captcha specific setup
  118. */
  119. protected abstract captchaSpecificSetup(): void;
  120. ngOnChanges(changes: SimpleChanges): void;
  121. /**
  122. * Gets captcha response as per reCaptcha docs
  123. */
  124. getResponse(): string;
  125. /**
  126. * Gets Id of captcha widget
  127. */
  128. getCaptchaId(): number | undefined;
  129. /**
  130. * Resets captcha
  131. */
  132. resetCaptcha(): void;
  133. /**
  134. * Gets last submitted captcha response
  135. */
  136. getCurrentResponse(): string | undefined;
  137. /**
  138. * Reload captcha. Useful when properties (i.e. theme) changed and captcha need to reflect them
  139. */
  140. reloadCaptcha(): void;
  141. protected ensureCaptchaElem(captchaElemId: string): void;
  142. /**
  143. * Responsible for instantiating captcha element
  144. */
  145. protected renderReCaptcha(): void;
  146. /**
  147. * Called when captcha receives response
  148. * @param callback Callback
  149. */
  150. protected handleCallback(callback: any): void;
  151. private getPseudoUniqueNumber;
  152. private setupComponent;
  153. /**
  154. * Called when google's recaptcha script is ready
  155. */
  156. private onloadCallback;
  157. private generateNewElemId;
  158. private createAndSetCaptchaElem;
  159. /**
  160. * To be aligned with the ControlValueAccessor interface we need to implement this method
  161. * However as we don't want to update the recaptcha, this doesn't need to be implemented
  162. */
  163. writeValue(obj: any): void;
  164. /**
  165. * This method helps us tie together recaptcha and our formControl values
  166. */
  167. registerOnChange(fn: any): void;
  168. /**
  169. * At some point we might be interested whether the user has touched our component
  170. */
  171. registerOnTouched(fn: any): void;
  172. /**
  173. * Handles error callback
  174. */
  175. protected handleErrorCallback(): void;
  176. /**
  177. * Handles expired callback
  178. */
  179. protected handleExpireCallback(): void;
  180. static ɵfac: i0.ɵɵFactoryDeclaration<BaseReCaptchaComponent, never>;
  181. static ɵdir: i0.ɵɵDirectiveDeclaration<BaseReCaptchaComponent, never, never, { "siteKey": "siteKey"; "useGlobalDomain": "useGlobalDomain"; "type": "type"; "hl": "hl"; "tabIndex": "tabIndex"; }, { "success": "success"; "load": "load"; "reset": "reset"; "ready": "ready"; "error": "error"; "expire": "expire"; }, never>;
  182. }
  183. //# sourceMappingURL=base-recaptcha.component.d.ts.map