solid-hcaptcha
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -138,5 +138,4 @@ import { effect, setAttribute, template } from 'solid-js/web'; | ||
} = state; | ||
if (!captchaId) return; | ||
if (!isReady()) return; | ||
hcaptcha.setData(captchaId, data); | ||
if (!isReady() || !captchaId) return; | ||
return hcaptcha.setData(captchaId, data); | ||
}; | ||
@@ -205,3 +204,3 @@ | ||
const token = hcaptcha.getResponse(captchaId); // Get current challenge session ID from hCaptcha widget. | ||
const token = hcaptcha.getResponse(captchaId); // Get current challenge session ID from hCaptcha widget. | ||
@@ -276,3 +275,8 @@ const ekey = hcaptcha.getRespKey(captchaId); // Dispatch event to verify user response. | ||
}); | ||
} else handleOnLoad(); | ||
} | ||
/** | ||
* If the API is already ready (`window.hcaptcha` exists) | ||
* render the captcha and trigger `onLoad` prop. | ||
*/ | ||
else handleOnLoad(); | ||
}); | ||
@@ -293,3 +297,3 @@ /** On unmount, reset and remove the hCaptcha widget. */ | ||
* also on cleanup. | ||
* | ||
* | ||
* See here: <https://github.com/solidjs-community/solid-primitives/blob/main/packages/script-loader/src/index.ts>. | ||
@@ -296,0 +300,0 @@ */ |
@@ -49,3 +49,3 @@ import { createScriptLoader } from "@solid-primitives/script-loader"; | ||
"theme": props.theme || "light", | ||
"size": props.size || "normal" | ||
"size": props.size || "normal", | ||
}); | ||
@@ -91,7 +91,5 @@ /** | ||
const { captchaId } = state; | ||
if (!captchaId) | ||
if (!isReady() || !captchaId) | ||
return; | ||
if (!isReady()) | ||
return; | ||
hcaptcha.setData(captchaId, data); | ||
return hcaptcha.setData(captchaId, data); | ||
}; | ||
@@ -147,3 +145,3 @@ const getResponse = () => { | ||
const token = hcaptcha.getResponse(captchaId); | ||
// Get current challenge session ID from hCaptcha widget. | ||
// Get current challenge session ID from hCaptcha widget. | ||
const ekey = hcaptcha.getRespKey(captchaId); | ||
@@ -203,2 +201,6 @@ // Dispatch event to verify user response. | ||
} | ||
/** | ||
* If the API is already ready (`window.hcaptcha` exists) | ||
* render the captcha and trigger `onLoad` prop. | ||
*/ | ||
else | ||
@@ -205,0 +207,0 @@ handleOnLoad(); |
import HCaptcha from "./hcaptcha"; | ||
export default HCaptcha; |
export {}; |
@@ -0,0 +0,0 @@ export const generateScriptUrl = (params, onLoadFunctionName, apihost) => { |
@@ -0,0 +0,0 @@ import type { Component } from "solid-js"; |
import HCaptcha from "./hcaptcha"; | ||
export type { HCaptchaConfig, HCaptchaFunctions, HCaptchaProps } from "./types"; | ||
export type { HCaptchaExecuteResponse, HCaptchaFunctions, HCaptchaConfig, HCaptchaProps } from "./types"; | ||
export default HCaptcha; |
@@ -15,3 +15,3 @@ /// <reference types="@hcaptcha/types" /> | ||
*/ | ||
onError?: (err: string) => any; | ||
onError?: (error: HCaptchaError) => void; | ||
/** | ||
@@ -21,13 +21,13 @@ * When challenge is completed. | ||
*/ | ||
onVerify?: (token: string, eKey: string) => any; | ||
onVerify?: (token: string, eKey: string) => unknown; | ||
/** When the current token expires. */ | ||
onExpire?: () => any; | ||
onExpire?: () => unknown; | ||
/** When the hCaptcha API loads. */ | ||
onLoad?: (hcaptcha: HCaptchaFunctions) => any; | ||
onLoad?: (hcaptcha: HCaptchaFunctions) => unknown; | ||
/** When the user display of a challenge starts. */ | ||
onOpen?: () => any; | ||
onOpen?: () => unknown; | ||
/** When the user dismisses a challenge. */ | ||
onClose?: () => any; | ||
onClose?: () => unknown; | ||
/** When the user display of a challenge times out with no answer. */ | ||
onChallengeExpired?: () => any; | ||
onChallengeExpired?: () => unknown; | ||
/** | ||
@@ -80,5 +80,6 @@ * This is your sitekey, this allows you to load captcha. | ||
* When setting to `auto`, hCaptcha auto-detects language via the user's browser. | ||
* This overrides that to set a default UI language. See [language codes](https://hcaptcha.com/docs/languages). | ||
* This overrides that to set a default UI language. | ||
* | ||
* Defaults to `auto`. The language code should be a ISO 639-2 code. | ||
* @see https://docs.hcaptcha.com/languages/ | ||
* @default "auto" | ||
*/ | ||
@@ -97,4 +98,4 @@ hl?: string; | ||
resetCaptcha(): void; | ||
renderCaptcha(onReady?: () => any): void; | ||
removeCaptcha(callback: () => any): void; | ||
renderCaptcha(onReady?: () => unknown): void; | ||
removeCaptcha(callback: () => unknown): void; | ||
/** | ||
@@ -113,8 +114,9 @@ * Get the associated ekey (challenge ID) for a successful solve. | ||
executeSync(): void; | ||
/** Returns a promise which resolves with `HCaptchaResponse`. */ | ||
execute(): Promise<HCaptchaResponse | undefined>; | ||
/** Returns a promise which resolves with `HCaptchaExecuteResponse`. */ | ||
execute(): Promise<HCaptchaExecuteResponse | undefined>; | ||
} | ||
export interface HCaptchaResponse { | ||
/** Fixes the `String` types from `HCaptchaResponse`. */ | ||
export interface HCaptchaExecuteResponse { | ||
response: string; | ||
key: string; | ||
} |
@@ -0,0 +0,0 @@ export interface HCaptchaUrlParams { |
{ | ||
"name": "solid-hcaptcha", | ||
"description": "Unofficial port of react-hcaptcha for Solid.", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"license": "MIT", | ||
@@ -27,3 +27,3 @@ "source": "./src/index.tsx", | ||
"build": "rollup -c && rimraf ./dist/source ./dist/types && tsc", | ||
"lint": "tsc --noEmit", | ||
"lint": "eslint ./src && tsc --noEmit", | ||
"release": "release-it" | ||
@@ -38,2 +38,5 @@ }, | ||
"@hcaptcha/types": "^1.0.1", | ||
"@typescript-eslint/eslint-plugin": "^5.26.0", | ||
"@typescript-eslint/parser": "^5.26.0", | ||
"eslint": "^8.16.0", | ||
"release-it": "^15.0.0", | ||
@@ -40,0 +43,0 @@ "rimraf": "^3.0.2", |
@@ -0,0 +0,0 @@ # Solid hCaptcha Component Library |
Sorry, the diff of this file is not supported yet
42386
634
10