vue-recaptcha
Version:
ReCAPTCHA vue component
34 lines (33 loc) • 1.12 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createPlugin = createPlugin;
var _vueDemi = require("vue-demi");
var _context = require("./composables/context.cjs");
var _proxy = require("./composables/proxy.cjs");
var _common = require("./script-manager/common.cjs");
var _utils = require("./utils.cjs");
function createPlugin(scriptLoaderFactory, {
getRecaptcha = () => window.grecaptcha
} = {}) {
return {
install(app, options) {
const isReady = (0, _vueDemi.ref)(false);
async function waitLoaded() {
await _common.recaptchaLoaded.promise;
isReady.value = true;
}
waitLoaded().catch(error => (0, _utils.warn)("fail to load reCAPTCHA script", error));
(0, _common.checkRecaptchaLoad)();
const opt = (0, _context.normalizeOptions)(options);
app.provide(_context.RecaptchaContextKey, {
isReady,
scriptInjected: false,
proxy: (0, _proxy.createRecaptchaProxy)(isReady, getRecaptcha),
useScriptProvider: scriptLoaderFactory(opt.loaderOptions),
options: opt
});
}
};
}
;