@jarrodmedrano/ui 0.1.3 → 0.1.4
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.
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
var useRecaptcha_exports = {};
|
|
41
|
+
__export(useRecaptcha_exports, {
|
|
42
|
+
useRecaptcha: () => useRecaptcha
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(useRecaptcha_exports);
|
|
45
|
+
var import_react = require("react");
|
|
46
|
+
function useRecaptcha() {
|
|
47
|
+
var _a;
|
|
48
|
+
const siteKey = (_a = process.env.NEXT_PUBLIC_GOOGLE_RECAPTCHA_KEY) != null ? _a : "";
|
|
49
|
+
const loadedRef = (0, import_react.useRef)(false);
|
|
50
|
+
(0, import_react.useEffect)(() => {
|
|
51
|
+
if (!siteKey || loadedRef.current) return;
|
|
52
|
+
if (document.querySelector('script[src*="recaptcha/enterprise.js"]')) {
|
|
53
|
+
loadedRef.current = true;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const script = document.createElement("script");
|
|
57
|
+
script.src = `https://www.google.com/recaptcha/enterprise.js?render=${siteKey}`;
|
|
58
|
+
script.async = true;
|
|
59
|
+
script.onload = () => {
|
|
60
|
+
loadedRef.current = true;
|
|
61
|
+
};
|
|
62
|
+
document.head.appendChild(script);
|
|
63
|
+
}, [siteKey]);
|
|
64
|
+
const executeRecaptcha = (0, import_react.useCallback)(
|
|
65
|
+
(action) => __async(null, null, function* () {
|
|
66
|
+
var _a2;
|
|
67
|
+
if (!siteKey || typeof window === "undefined" || !((_a2 = window.grecaptcha) == null ? void 0 : _a2.enterprise)) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return new Promise((resolve) => {
|
|
71
|
+
window.grecaptcha.enterprise.ready(() => __async(null, null, function* () {
|
|
72
|
+
try {
|
|
73
|
+
const token = yield window.grecaptcha.enterprise.execute(siteKey, {
|
|
74
|
+
action
|
|
75
|
+
});
|
|
76
|
+
resolve(token);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
resolve(null);
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
});
|
|
82
|
+
}),
|
|
83
|
+
[siteKey]
|
|
84
|
+
);
|
|
85
|
+
return { executeRecaptcha };
|
|
86
|
+
}
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
useRecaptcha
|
|
90
|
+
});
|
|
91
|
+
//# sourceMappingURL=useRecaptcha.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../hooks/useRecaptcha.ts"],"sourcesContent":["'use client'\n\nimport { useCallback, useEffect, useRef } from 'react'\n\ndeclare global {\n interface Window {\n grecaptcha: {\n enterprise: {\n ready: (callback: () => void) => void\n execute: (\n siteKey: string,\n options: { action: string },\n ) => Promise<string>\n }\n }\n }\n}\n\nexport function useRecaptcha() {\n const siteKey = process.env.NEXT_PUBLIC_GOOGLE_RECAPTCHA_KEY ?? ''\n const loadedRef = useRef(false)\n\n useEffect(() => {\n if (!siteKey || loadedRef.current) return\n if (document.querySelector('script[src*=\"recaptcha/enterprise.js\"]')) {\n loadedRef.current = true\n return\n }\n\n const script = document.createElement('script')\n script.src = `https://www.google.com/recaptcha/enterprise.js?render=${siteKey}`\n script.async = true\n script.onload = () => {\n loadedRef.current = true\n }\n document.head.appendChild(script)\n }, [siteKey])\n\n const executeRecaptcha = useCallback(\n async (action: string): Promise<string | null> => {\n if (\n !siteKey ||\n typeof window === 'undefined' ||\n !window.grecaptcha?.enterprise\n ) {\n return null\n }\n\n return new Promise((resolve) => {\n window.grecaptcha.enterprise.ready(async () => {\n try {\n const token = await window.grecaptcha.enterprise.execute(siteKey, {\n action,\n })\n resolve(token)\n } catch {\n resolve(null)\n }\n })\n })\n },\n [siteKey],\n )\n\n return { executeRecaptcha }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA+C;AAgBxC,SAAS,eAAe;AAlB/B;AAmBE,QAAM,WAAU,aAAQ,IAAI,qCAAZ,YAAgD;AAChE,QAAM,gBAAY,qBAAO,KAAK;AAE9B,8BAAU,MAAM;AACd,QAAI,CAAC,WAAW,UAAU,QAAS;AACnC,QAAI,SAAS,cAAc,wCAAwC,GAAG;AACpE,gBAAU,UAAU;AACpB;AAAA,IACF;AAEA,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,MAAM,yDAAyD,OAAO;AAC7E,WAAO,QAAQ;AACf,WAAO,SAAS,MAAM;AACpB,gBAAU,UAAU;AAAA,IACtB;AACA,aAAS,KAAK,YAAY,MAAM;AAAA,EAClC,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,uBAAmB;AAAA,IACvB,CAAO,WAA2C;AAvCtD,UAAAA;AAwCM,UACE,CAAC,WACD,OAAO,WAAW,eAClB,GAACA,MAAA,OAAO,eAAP,gBAAAA,IAAmB,aACpB;AACA,eAAO;AAAA,MACT;AAEA,aAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,eAAO,WAAW,WAAW,MAAM,MAAY;AAC7C,cAAI;AACF,kBAAM,QAAQ,MAAM,OAAO,WAAW,WAAW,QAAQ,SAAS;AAAA,cAChE;AAAA,YACF,CAAC;AACD,oBAAQ,KAAK;AAAA,UACf,SAAQ;AACN,oBAAQ,IAAI;AAAA,UACd;AAAA,QACF,EAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAEA,SAAO,EAAE,iBAAiB;AAC5B;","names":["_a"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __async = (__this, __arguments, generator) => {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
var fulfilled = (value) => {
|
|
5
|
+
try {
|
|
6
|
+
step(generator.next(value));
|
|
7
|
+
} catch (e) {
|
|
8
|
+
reject(e);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var rejected = (value) => {
|
|
12
|
+
try {
|
|
13
|
+
step(generator.throw(value));
|
|
14
|
+
} catch (e) {
|
|
15
|
+
reject(e);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
19
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
23
|
+
function useRecaptcha() {
|
|
24
|
+
var _a;
|
|
25
|
+
const siteKey = (_a = process.env.NEXT_PUBLIC_GOOGLE_RECAPTCHA_KEY) != null ? _a : "";
|
|
26
|
+
const loadedRef = useRef(false);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!siteKey || loadedRef.current) return;
|
|
29
|
+
if (document.querySelector('script[src*="recaptcha/enterprise.js"]')) {
|
|
30
|
+
loadedRef.current = true;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const script = document.createElement("script");
|
|
34
|
+
script.src = `https://www.google.com/recaptcha/enterprise.js?render=${siteKey}`;
|
|
35
|
+
script.async = true;
|
|
36
|
+
script.onload = () => {
|
|
37
|
+
loadedRef.current = true;
|
|
38
|
+
};
|
|
39
|
+
document.head.appendChild(script);
|
|
40
|
+
}, [siteKey]);
|
|
41
|
+
const executeRecaptcha = useCallback(
|
|
42
|
+
(action) => __async(null, null, function* () {
|
|
43
|
+
var _a2;
|
|
44
|
+
if (!siteKey || typeof window === "undefined" || !((_a2 = window.grecaptcha) == null ? void 0 : _a2.enterprise)) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return new Promise((resolve) => {
|
|
48
|
+
window.grecaptcha.enterprise.ready(() => __async(null, null, function* () {
|
|
49
|
+
try {
|
|
50
|
+
const token = yield window.grecaptcha.enterprise.execute(siteKey, {
|
|
51
|
+
action
|
|
52
|
+
});
|
|
53
|
+
resolve(token);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
resolve(null);
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
});
|
|
59
|
+
}),
|
|
60
|
+
[siteKey]
|
|
61
|
+
);
|
|
62
|
+
return { executeRecaptcha };
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
useRecaptcha
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=useRecaptcha.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../hooks/useRecaptcha.ts"],"sourcesContent":["'use client'\n\nimport { useCallback, useEffect, useRef } from 'react'\n\ndeclare global {\n interface Window {\n grecaptcha: {\n enterprise: {\n ready: (callback: () => void) => void\n execute: (\n siteKey: string,\n options: { action: string },\n ) => Promise<string>\n }\n }\n }\n}\n\nexport function useRecaptcha() {\n const siteKey = process.env.NEXT_PUBLIC_GOOGLE_RECAPTCHA_KEY ?? ''\n const loadedRef = useRef(false)\n\n useEffect(() => {\n if (!siteKey || loadedRef.current) return\n if (document.querySelector('script[src*=\"recaptcha/enterprise.js\"]')) {\n loadedRef.current = true\n return\n }\n\n const script = document.createElement('script')\n script.src = `https://www.google.com/recaptcha/enterprise.js?render=${siteKey}`\n script.async = true\n script.onload = () => {\n loadedRef.current = true\n }\n document.head.appendChild(script)\n }, [siteKey])\n\n const executeRecaptcha = useCallback(\n async (action: string): Promise<string | null> => {\n if (\n !siteKey ||\n typeof window === 'undefined' ||\n !window.grecaptcha?.enterprise\n ) {\n return null\n }\n\n return new Promise((resolve) => {\n window.grecaptcha.enterprise.ready(async () => {\n try {\n const token = await window.grecaptcha.enterprise.execute(siteKey, {\n action,\n })\n resolve(token)\n } catch {\n resolve(null)\n }\n })\n })\n },\n [siteKey],\n )\n\n return { executeRecaptcha }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,aAAa,WAAW,cAAc;AAgBxC,SAAS,eAAe;AAlB/B;AAmBE,QAAM,WAAU,aAAQ,IAAI,qCAAZ,YAAgD;AAChE,QAAM,YAAY,OAAO,KAAK;AAE9B,YAAU,MAAM;AACd,QAAI,CAAC,WAAW,UAAU,QAAS;AACnC,QAAI,SAAS,cAAc,wCAAwC,GAAG;AACpE,gBAAU,UAAU;AACpB;AAAA,IACF;AAEA,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,MAAM,yDAAyD,OAAO;AAC7E,WAAO,QAAQ;AACf,WAAO,SAAS,MAAM;AACpB,gBAAU,UAAU;AAAA,IACtB;AACA,aAAS,KAAK,YAAY,MAAM;AAAA,EAClC,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,mBAAmB;AAAA,IACvB,CAAO,WAA2C;AAvCtD,UAAAA;AAwCM,UACE,CAAC,WACD,OAAO,WAAW,eAClB,GAACA,MAAA,OAAO,eAAP,gBAAAA,IAAmB,aACpB;AACA,eAAO;AAAA,MACT;AAEA,aAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,eAAO,WAAW,WAAW,MAAM,MAAY;AAC7C,cAAI;AACF,kBAAM,QAAQ,MAAM,OAAO,WAAW,WAAW,QAAQ,SAAS;AAAA,cAChE;AAAA,YACF,CAAC;AACD,oBAAQ,KAAK;AAAA,UACf,SAAQ;AACN,oBAAQ,IAAI;AAAA,UACd;AAAA,QACF,EAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAEA,SAAO,EAAE,iBAAiB;AAC5B;","names":["_a"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jarrodmedrano/ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -11,9 +11,14 @@
|
|
|
11
11
|
],
|
|
12
12
|
"exports": {
|
|
13
13
|
"./components/*": {
|
|
14
|
-
"types": "./dist/components/*.d.ts",
|
|
15
|
-
"import": "./dist/components/*.js",
|
|
16
|
-
"require": "./dist/components/*.cjs"
|
|
14
|
+
"types": ["./dist/components/*.d.ts", "./dist/components/*/index.d.ts"],
|
|
15
|
+
"import": ["./dist/components/*.js", "./dist/components/*/index.js"],
|
|
16
|
+
"require": ["./dist/components/*.cjs", "./dist/components/*/index.cjs"]
|
|
17
|
+
},
|
|
18
|
+
"./hooks/*": {
|
|
19
|
+
"types": "./dist/hooks/*.d.ts",
|
|
20
|
+
"import": "./dist/hooks/*.js",
|
|
21
|
+
"require": "./dist/hooks/*.cjs"
|
|
17
22
|
},
|
|
18
23
|
"./lib/*": {
|
|
19
24
|
"types": "./dist/lib/*.d.ts",
|