@verbb/formie-browser 1.0.0 → 1.0.2
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/CHANGELOG.md +16 -0
- package/dist/chunks/address-finder-CQW81kY0.js +37 -0
- package/dist/chunks/bpoint-D8OjLmsn.js +26 -0
- package/dist/chunks/calculations-BqZsENCq.js +147 -0
- package/dist/chunks/captcha-eu-DIa6aUWz.js +34 -0
- package/dist/chunks/checkbox-radio-BI-UjgMF.js +136 -0
- package/dist/chunks/conditions-BVl6jTYo.js +433 -0
- package/dist/chunks/date-picker-69TgvErA.js +4994 -0
- package/dist/chunks/eway-1GPxH6DU.js +74 -0
- package/dist/chunks/file-upload-BDZZftgL.js +281 -0
- package/dist/chunks/friendly-captcha-v1-DA2QPKA3.js +33 -0
- package/dist/chunks/friendly-captcha-v2-BorOWiz_.js +38 -0
- package/dist/chunks/go-cardless-DwBgERcA.js +24 -0
- package/dist/chunks/google-address-BcTBncyS.js +162 -0
- package/dist/chunks/hcaptcha-BchdVCqq.js +56 -0
- package/dist/chunks/hidden-D8RqSPt7.js +31 -0
- package/dist/chunks/index-BEsfee-D.js +1839 -0
- package/dist/chunks/index-BP7Unm5Y.js +863 -0
- package/dist/chunks/index-C1ZOKiAi.js +4229 -0
- package/dist/chunks/loqate-nXuTX7In.js +55 -0
- package/dist/chunks/mollie-qdCynQCd.js +24 -0
- package/dist/chunks/moneris-BNEA-laO.js +101 -0
- package/dist/chunks/opayo-BJtXOkuK.js +122 -0
- package/dist/chunks/paddle-D72Pa8kr.js +60 -0
- package/dist/chunks/paypal-Cqt2bned.js +100 -0
- package/dist/chunks/payway-BjCqsc0H.js +56 -0
- package/dist/chunks/phone-country-K9pYAlzM.js +3765 -0
- package/dist/chunks/place-kit-Dg6f_UoM.js +42 -0
- package/dist/chunks/placekit-autocomplete.esm-LAwfbPZl.js +1299 -0
- package/dist/chunks/recaptcha-enterprise--VYAeeqz.js +71 -0
- package/dist/chunks/recaptcha-shared-PSIEEEe1.js +15 -0
- package/dist/chunks/recaptcha-v2-checkbox-atBNe5ml.js +41 -0
- package/dist/chunks/recaptcha-v2-invisible-DnBufNPT.js +59 -0
- package/dist/chunks/recaptcha-v3-CF6O8rDj.js +28 -0
- package/dist/chunks/repeater-CB7Yojvx.js +124 -0
- package/dist/chunks/rich-text-nAV_SQZo.js +304 -0
- package/dist/chunks/scripts-BkAAux0i.js +36 -0
- package/dist/chunks/sdk-3SicTWby.js +1559 -0
- package/dist/chunks/shared-DGqeMvcJ.js +80 -0
- package/dist/chunks/signature-BT6CsQ6n.js +550 -0
- package/dist/chunks/snaptcha-C7qQo02f.js +8 -0
- package/dist/chunks/square-C5AH3trb.js +46 -0
- package/dist/chunks/stripe-EJK0RyUv.js +202 -0
- package/dist/chunks/styles-C3aqgtek.js +21 -0
- package/dist/chunks/summary-DC_ipXCU.js +126 -0
- package/dist/chunks/table-BEAI99qo.js +95 -0
- package/dist/chunks/text-limit-Blgq5G-G.js +135 -0
- package/dist/chunks/turnstile-_uCRwnU-.js +59 -0
- package/dist/chunks/utils-BntI3W4S.js +6149 -0
- package/dist/index.js +39 -3205
- package/package.json +5 -5
- package/src/js/modules/fields/file-upload.ts +1 -1
- package/src/js/modules/fields/repeater.ts +1 -1
- package/src/js/modules/fields/rich-text.ts +2 -2
- package/src/js/modules/fields/signature.ts +1 -1
- package/src/js/modules/fields/summary.ts +1 -1
- package/src/js/modules/fields/table.ts +1 -1
- package/src/js/modules/fields/text-limit.ts +1 -1
- package/src/js/modules/payments/paypal.ts +1 -1
- package/src/js/modules/payments/payway.ts +1 -1
- package/src/js/modules/payments/stripe.ts +1 -1
- package/dist/chunks/address-finder-DfMCiW89.js +0 -47
- package/dist/chunks/api-CbqEMQT5.js +0 -181
- package/dist/chunks/api-DE7LfK-R.js +0 -960
- package/dist/chunks/api-DOfDzYC_.js +0 -538
- package/dist/chunks/async-B3DUf1GZ.js +0 -26
- package/dist/chunks/bpoint-Ciy3yY9Q.js +0 -34
- package/dist/chunks/calculations-CkYAqO_-.js +0 -197
- package/dist/chunks/captcha-eu-DnOWhMwr.js +0 -43
- package/dist/chunks/checkbox-radio-0x7Tc0br.js +0 -197
- package/dist/chunks/chunk-K6L4z4UQ.js +0 -24
- package/dist/chunks/conditions-4fXKhEJS.js +0 -609
- package/dist/chunks/date-picker-B6iZkjHS.js +0 -6204
- package/dist/chunks/debug-KnZeKYBI.js +0 -39
- package/dist/chunks/dist-D09GnXMW.js +0 -2663
- package/dist/chunks/event-names-DamGPtXR.js +0 -51
- package/dist/chunks/eway-DEAYcwT0.js +0 -86
- package/dist/chunks/field-references.keys-BpBZ_quS.js +0 -24
- package/dist/chunks/field-references.resolver-Ba6xhiJC.js +0 -183
- package/dist/chunks/file-upload-Bh63PQSE.js +0 -430
- package/dist/chunks/friendly-captcha-v1-CqO4WVre.js +0 -40
- package/dist/chunks/friendly-captcha-v2-CyykcJcM.js +0 -47
- package/dist/chunks/friendly-challenge-Dg8XkStd.js +0 -1101
- package/dist/chunks/go-cardless-CuND59rR.js +0 -26
- package/dist/chunks/google-address--uR8WDSm.js +0 -208
- package/dist/chunks/hcaptcha-CmaFUesv.js +0 -72
- package/dist/chunks/hidden-CYnZYple.js +0 -36
- package/dist/chunks/http-18nn97DZ.js +0 -29
- package/dist/chunks/i18n-vUh-KGiH.js +0 -55
- package/dist/chunks/loqate-BICNJlVK.js +0 -97
- package/dist/chunks/mollie-DwlsgHZ1.js +0 -26
- package/dist/chunks/moneris-B_IFZFTx.js +0 -159
- package/dist/chunks/opayo-U2x_TOII.js +0 -192
- package/dist/chunks/paddle-BqXFrc79.js +0 -75
- package/dist/chunks/paypal-Cn_DYGDb.js +0 -121
- package/dist/chunks/payway-Rnq796eC.js +0 -75
- package/dist/chunks/phone-country-B6Me4lK0.js +0 -3317
- package/dist/chunks/place-kit-ldUl-u9w.js +0 -56
- package/dist/chunks/placekit-autocomplete.esm-D-lGeaZl.js +0 -1771
- package/dist/chunks/recaptcha-enterprise-DPJNyv1X.js +0 -72
- package/dist/chunks/recaptcha-shared-DTI4qWVR.js +0 -22
- package/dist/chunks/recaptcha-v2-checkbox-zFjpvJ5c.js +0 -49
- package/dist/chunks/recaptcha-v2-invisible-CnYtkNvz.js +0 -62
- package/dist/chunks/recaptcha-v3-EAlWhnkX.js +0 -33
- package/dist/chunks/repeater-CXD1eLSn.js +0 -151
- package/dist/chunks/rich-text-DkmZRhGj.js +0 -442
- package/dist/chunks/scripts-BGD_iU_6.js +0 -41
- package/dist/chunks/sdk-B7u9fTlP.js +0 -2103
- package/dist/chunks/shared-DC6_1u8X.js +0 -85
- package/dist/chunks/signature-E9KyYXS1.js +0 -765
- package/dist/chunks/snaptcha-CCDunGeb.js +0 -8
- package/dist/chunks/square-BLqK51rS.js +0 -61
- package/dist/chunks/stripe-B8gHpZNC.js +0 -273
- package/dist/chunks/styles-BIh6g7V_.js +0 -22
- package/dist/chunks/summary-EcNE0cvg.js +0 -191
- package/dist/chunks/table-yxEDL6kA.js +0 -124
- package/dist/chunks/text-limit-D0H_Ca2c.js +0 -179
- package/dist/chunks/theme-classes-vSHpdCUO.js +0 -59
- package/dist/chunks/turnstile-DP0bdR7T.js +0 -68
- package/dist/chunks/utils-ByrEVYrJ.js +0 -49584
|
@@ -1,538 +0,0 @@
|
|
|
1
|
-
import { a as getFormStateEventName } from "./event-names-DamGPtXR.js";
|
|
2
|
-
import { t as createDebug } from "./debug-KnZeKYBI.js";
|
|
3
|
-
import { t as addThemeClasses } from "./theme-classes-vSHpdCUO.js";
|
|
4
|
-
import { i as t } from "./i18n-vUh-KGiH.js";
|
|
5
|
-
import { n as sleep, t as debounce } from "./async-B3DUf1GZ.js";
|
|
6
|
-
//#region src/js/modules/captchas/constants.ts
|
|
7
|
-
var DEFAULT_WAIT_FOR_VALUE_MS = 2e3;
|
|
8
|
-
var CAPTCHA_PROVIDER_LOAD_TIMEOUT_MS = 5e3;
|
|
9
|
-
var CAPTCHA_SUBMIT_WAIT_FOR_VALUE_MS = 5e3;
|
|
10
|
-
var CAPTCHA_EXECUTE_WAIT_FOR_VALUE_MS = 12e4;
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/js/modules/captchas/utils.ts
|
|
13
|
-
function getScriptAttributes(loadingMethod) {
|
|
14
|
-
const normalized = String(loadingMethod || "asyncDefer").toLowerCase();
|
|
15
|
-
return {
|
|
16
|
-
async: normalized.includes("async"),
|
|
17
|
-
defer: normalized.includes("defer")
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function getInputValue(root, name) {
|
|
21
|
-
const inputs = Array.from(root.querySelectorAll(`input[name="${name}"], textarea[name="${name}"]`));
|
|
22
|
-
for (const input of inputs) {
|
|
23
|
-
const value = String(input.value || "").trim();
|
|
24
|
-
if (value !== "") return value;
|
|
25
|
-
}
|
|
26
|
-
return "";
|
|
27
|
-
}
|
|
28
|
-
function hasCaptchaValue(root, names) {
|
|
29
|
-
return names.some((name) => {
|
|
30
|
-
return getInputValue(root, name) !== "";
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
function clearCaptchaValues(root, names) {
|
|
34
|
-
names.forEach((name) => {
|
|
35
|
-
Array.from(root.querySelectorAll(`input[name="${name}"], textarea[name="${name}"]`)).forEach((input) => {
|
|
36
|
-
input.value = "";
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
function ensureCaptchaValueInput(root, name, { value = "", container } = {}) {
|
|
41
|
-
let input = root.querySelector(`input[name="${name}"]`);
|
|
42
|
-
if (!input) {
|
|
43
|
-
input = document.createElement("input");
|
|
44
|
-
input.type = "hidden";
|
|
45
|
-
input.name = name;
|
|
46
|
-
(container || (root instanceof HTMLElement ? root : null))?.appendChild(input);
|
|
47
|
-
}
|
|
48
|
-
input.value = value;
|
|
49
|
-
return input;
|
|
50
|
-
}
|
|
51
|
-
async function waitForCaptchaValue(root, names, waitForValueMs) {
|
|
52
|
-
if (hasCaptchaValue(root, names)) return true;
|
|
53
|
-
const deadline = Date.now() + Math.max(waitForValueMs, 0);
|
|
54
|
-
while (Date.now() < deadline) {
|
|
55
|
-
await sleep(120);
|
|
56
|
-
if (hasCaptchaValue(root, names)) return true;
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/js/modules/captchas/host.ts
|
|
62
|
-
var CAPTCHA_OPTION_KEYS = new Set([
|
|
63
|
-
"handle",
|
|
64
|
-
"placeholderSelector",
|
|
65
|
-
"errorMessage",
|
|
66
|
-
"sessionKey",
|
|
67
|
-
"value"
|
|
68
|
-
]);
|
|
69
|
-
var CAPTCHA_ERROR_SELECTOR = "[data-formie-captcha-error-container]";
|
|
70
|
-
var CAPTCHA_VISIBILITY_EVENTS = [
|
|
71
|
-
"formie:page:navigate",
|
|
72
|
-
"formie:page:navigate:after",
|
|
73
|
-
"formie:submit:result"
|
|
74
|
-
];
|
|
75
|
-
function bindDomEvent(target, eventName, callback) {
|
|
76
|
-
target.addEventListener(eventName, callback);
|
|
77
|
-
return () => {
|
|
78
|
-
target.removeEventListener(eventName, callback);
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function queryCaptchaPlaceholders(root, selector) {
|
|
82
|
-
if (root instanceof HTMLElement && root.matches(selector)) return [root, ...Array.from(root.querySelectorAll(selector))];
|
|
83
|
-
return Array.from(root.querySelectorAll(selector));
|
|
84
|
-
}
|
|
85
|
-
function isElementVisible(target) {
|
|
86
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
87
|
-
if (!target.isConnected) return false;
|
|
88
|
-
if (target.hidden || target.closest("[hidden]")) return false;
|
|
89
|
-
if (target.closest("[data-formie-page-hidden]") || target.closest("[aria-hidden=\"true\"]")) return false;
|
|
90
|
-
const style = window.getComputedStyle(target);
|
|
91
|
-
return style.display !== "none" && style.visibility !== "hidden";
|
|
92
|
-
}
|
|
93
|
-
function getPrimaryPlaceholder(root, selector) {
|
|
94
|
-
const placeholders = queryCaptchaPlaceholders(root, selector);
|
|
95
|
-
return placeholders.find((placeholder) => isElementVisible(placeholder)) || placeholders[0] || null;
|
|
96
|
-
}
|
|
97
|
-
function createCaptchaContainer(placeholder) {
|
|
98
|
-
placeholder.innerHTML = "";
|
|
99
|
-
const container = document.createElement("div");
|
|
100
|
-
placeholder.appendChild(container);
|
|
101
|
-
return container;
|
|
102
|
-
}
|
|
103
|
-
function clearCaptchaError(placeholder) {
|
|
104
|
-
placeholder?.querySelector(CAPTCHA_ERROR_SELECTOR)?.remove();
|
|
105
|
-
}
|
|
106
|
-
function showCaptchaError(placeholder, message, themeSource) {
|
|
107
|
-
if (!placeholder) return;
|
|
108
|
-
clearCaptchaError(placeholder);
|
|
109
|
-
const container = document.createElement("div");
|
|
110
|
-
container.setAttribute("data-formie-captcha-error-container", "");
|
|
111
|
-
container.setAttribute("aria-live", "polite");
|
|
112
|
-
container.setAttribute("aria-atomic", "true");
|
|
113
|
-
addThemeClasses(container, themeSource || placeholder, "fieldErrors");
|
|
114
|
-
const error = document.createElement("div");
|
|
115
|
-
error.setAttribute("data-formie-captcha-error", "");
|
|
116
|
-
error.setAttribute("role", "alert");
|
|
117
|
-
addThemeClasses(error, themeSource || placeholder, "fieldError");
|
|
118
|
-
error.textContent = message;
|
|
119
|
-
container.appendChild(error);
|
|
120
|
-
placeholder.appendChild(container);
|
|
121
|
-
}
|
|
122
|
-
function parseRefreshTokensEvent(event) {
|
|
123
|
-
const detail = event instanceof CustomEvent ? event.detail : null;
|
|
124
|
-
if (!detail || typeof detail !== "object") return null;
|
|
125
|
-
return detail;
|
|
126
|
-
}
|
|
127
|
-
function getCaptchaRefreshEntry(payload, providerHandle) {
|
|
128
|
-
if (!payload?.captchas || typeof payload.captchas !== "object") return null;
|
|
129
|
-
const entry = payload.captchas[providerHandle];
|
|
130
|
-
if (!entry || typeof entry !== "object") return null;
|
|
131
|
-
return entry;
|
|
132
|
-
}
|
|
133
|
-
function observeVisiblePlaceholders(root, selector, onShow, onHide) {
|
|
134
|
-
const visible = /* @__PURE__ */ new Set();
|
|
135
|
-
const reconcileNow = () => {
|
|
136
|
-
const placeholders = queryCaptchaPlaceholders(root, selector);
|
|
137
|
-
const nextVisible = new Set(placeholders.filter((placeholder) => isElementVisible(placeholder)));
|
|
138
|
-
placeholders.forEach((placeholder) => {
|
|
139
|
-
if (nextVisible.has(placeholder) && !visible.has(placeholder)) {
|
|
140
|
-
visible.add(placeholder);
|
|
141
|
-
onShow(placeholder);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
Array.from(visible).forEach((placeholder) => {
|
|
145
|
-
if (nextVisible.has(placeholder)) return;
|
|
146
|
-
visible.delete(placeholder);
|
|
147
|
-
onHide(placeholder);
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
const reconcile = debounce(reconcileNow, 20);
|
|
151
|
-
const mutationObserver = new MutationObserver(() => {
|
|
152
|
-
reconcile();
|
|
153
|
-
});
|
|
154
|
-
mutationObserver.observe(root, {
|
|
155
|
-
childList: true,
|
|
156
|
-
subtree: true,
|
|
157
|
-
attributes: true,
|
|
158
|
-
attributeFilter: [
|
|
159
|
-
"class",
|
|
160
|
-
"style",
|
|
161
|
-
"hidden",
|
|
162
|
-
"aria-hidden",
|
|
163
|
-
"data-formie-page-hidden"
|
|
164
|
-
]
|
|
165
|
-
});
|
|
166
|
-
const cleanups = [bindDomEvent(window, "resize", () => {
|
|
167
|
-
reconcile();
|
|
168
|
-
}), ...CAPTCHA_VISIBILITY_EVENTS.map((eventName) => {
|
|
169
|
-
return bindDomEvent(root, eventName, () => {
|
|
170
|
-
reconcile();
|
|
171
|
-
});
|
|
172
|
-
})];
|
|
173
|
-
reconcileNow();
|
|
174
|
-
return {
|
|
175
|
-
cleanup: () => {
|
|
176
|
-
mutationObserver.disconnect();
|
|
177
|
-
cleanups.forEach((cleanup) => {
|
|
178
|
-
cleanup();
|
|
179
|
-
});
|
|
180
|
-
Array.from(visible).forEach((placeholder) => {
|
|
181
|
-
onHide(placeholder);
|
|
182
|
-
});
|
|
183
|
-
visible.clear();
|
|
184
|
-
},
|
|
185
|
-
reconcile,
|
|
186
|
-
getVisible: () => {
|
|
187
|
-
return queryCaptchaPlaceholders(root, selector).filter((placeholder) => isElementVisible(placeholder));
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
function getCaptchaProviderHandle(id, options) {
|
|
192
|
-
return (typeof options.handle === "string" && options.handle.trim() !== "" ? options.handle.trim() : "") || id;
|
|
193
|
-
}
|
|
194
|
-
function normalizeCaptchaModuleOptions(id, rawOptions, { defaultPlaceholderSelector, defaultTokenFieldNames = [], defaultWaitForValueMs = DEFAULT_WAIT_FOR_VALUE_MS }) {
|
|
195
|
-
const options = rawOptions || {};
|
|
196
|
-
const provider = Object.entries(options).reduce((carry, [key, value]) => {
|
|
197
|
-
if (CAPTCHA_OPTION_KEYS.has(key)) return carry;
|
|
198
|
-
carry[key] = value;
|
|
199
|
-
return carry;
|
|
200
|
-
}, {});
|
|
201
|
-
const tokenFieldNames = defaultTokenFieldNames.map(String).filter(Boolean);
|
|
202
|
-
const waitForValueMs = Number(defaultWaitForValueMs);
|
|
203
|
-
const placeholderSelector = typeof options.placeholderSelector === "string" && options.placeholderSelector.trim() !== "" ? options.placeholderSelector.trim() : defaultPlaceholderSelector;
|
|
204
|
-
const errorMessage = typeof options.errorMessage === "string" && options.errorMessage.trim() !== "" ? options.errorMessage.trim() : t("Captcha challenge must be completed.");
|
|
205
|
-
const sessionKey = typeof options.sessionKey === "string" && options.sessionKey.trim() !== "" ? options.sessionKey.trim() : null;
|
|
206
|
-
const value = typeof options.value === "string" ? options.value : null;
|
|
207
|
-
return {
|
|
208
|
-
handle: getCaptchaProviderHandle(id, options),
|
|
209
|
-
ui: {
|
|
210
|
-
placeholderSelector,
|
|
211
|
-
errorMessage
|
|
212
|
-
},
|
|
213
|
-
transport: {
|
|
214
|
-
tokenFieldNames,
|
|
215
|
-
waitForValueMs: Number.isFinite(waitForValueMs) ? waitForValueMs : defaultWaitForValueMs,
|
|
216
|
-
sessionKey,
|
|
217
|
-
value
|
|
218
|
-
},
|
|
219
|
-
provider
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
function createCaptchaHostServices(ctx, options) {
|
|
223
|
-
const tokenRoot = ctx.form || ctx.root;
|
|
224
|
-
const placeholderSelector = options.ui.placeholderSelector;
|
|
225
|
-
const providerHandle = options.handle;
|
|
226
|
-
return {
|
|
227
|
-
form: ctx.form,
|
|
228
|
-
root: ctx.root,
|
|
229
|
-
placeholder: {
|
|
230
|
-
query: () => queryCaptchaPlaceholders(ctx.root, placeholderSelector),
|
|
231
|
-
getPrimary: () => getPrimaryPlaceholder(ctx.root, placeholderSelector),
|
|
232
|
-
observe: (onShow, onHide) => observeVisiblePlaceholders(ctx.root, placeholderSelector, onShow, onHide),
|
|
233
|
-
createContainer: (placeholder) => createCaptchaContainer(placeholder),
|
|
234
|
-
clear: (placeholder) => {
|
|
235
|
-
if (!placeholder) return;
|
|
236
|
-
clearCaptchaError(placeholder);
|
|
237
|
-
placeholder.innerHTML = "";
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
errors: {
|
|
241
|
-
getDefaultMessage: () => options.ui.errorMessage,
|
|
242
|
-
show: (message, placeholder) => {
|
|
243
|
-
showCaptchaError(placeholder || getPrimaryPlaceholder(ctx.root, placeholderSelector), message || options.ui.errorMessage, ctx.form || ctx.root);
|
|
244
|
-
},
|
|
245
|
-
clear: (placeholder) => {
|
|
246
|
-
clearCaptchaError(placeholder || getPrimaryPlaceholder(ctx.root, placeholderSelector));
|
|
247
|
-
}
|
|
248
|
-
},
|
|
249
|
-
tokens: {
|
|
250
|
-
names: options.transport.tokenFieldNames,
|
|
251
|
-
has: (names = options.transport.tokenFieldNames, root = tokenRoot) => hasCaptchaValue(root, names),
|
|
252
|
-
read: (name = options.transport.tokenFieldNames[0], root = tokenRoot) => name ? getInputValue(root, name) : "",
|
|
253
|
-
write: (value, { names = options.transport.tokenFieldNames, root = tokenRoot, container = ctx.form } = {}) => {
|
|
254
|
-
names.forEach((name) => {
|
|
255
|
-
ensureCaptchaValueInput(root, name, {
|
|
256
|
-
value,
|
|
257
|
-
container
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
},
|
|
261
|
-
clear: (names = options.transport.tokenFieldNames, root = tokenRoot) => {
|
|
262
|
-
clearCaptchaValues(root, names);
|
|
263
|
-
},
|
|
264
|
-
wait: (timeoutMs = options.transport.waitForValueMs, names = options.transport.tokenFieldNames, root = tokenRoot) => {
|
|
265
|
-
return waitForCaptchaValue(root, names, timeoutMs);
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
refresh: {
|
|
269
|
-
providerHandle,
|
|
270
|
-
onTokensRefreshed: (callback) => {
|
|
271
|
-
const handlers = ["formie:refresh-tokens:after", "formie:refresh-tokens:refreshed"].map((eventName) => {
|
|
272
|
-
return bindDomEvent(ctx.root, eventName, (event) => {
|
|
273
|
-
const entry = getCaptchaRefreshEntry(parseRefreshTokensEvent(event), providerHandle);
|
|
274
|
-
if (entry) callback(entry);
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
return () => {
|
|
278
|
-
handlers.forEach((cleanup) => {
|
|
279
|
-
cleanup();
|
|
280
|
-
});
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
},
|
|
284
|
-
events: {
|
|
285
|
-
onRoot: (eventName, callback) => bindDomEvent(ctx.root, eventName, callback),
|
|
286
|
-
onForm: (eventName, callback) => {
|
|
287
|
-
if (!ctx.form) return () => {};
|
|
288
|
-
return bindDomEvent(ctx.form, eventName, callback);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
//#endregion
|
|
294
|
-
//#region src/js/modules/captchas/factories.ts
|
|
295
|
-
var debug = createDebug("captchas");
|
|
296
|
-
function createCaptchaModule({ id, defaultPlaceholderSelector, defaultTokenFieldNames = [], defaultWaitForValueMs = DEFAULT_WAIT_FOR_VALUE_MS, setup }) {
|
|
297
|
-
return {
|
|
298
|
-
id,
|
|
299
|
-
kind: "captcha",
|
|
300
|
-
match: () => true,
|
|
301
|
-
setup: async (ctx) => {
|
|
302
|
-
const options = normalizeCaptchaModuleOptions(id, ctx.options || {}, {
|
|
303
|
-
defaultPlaceholderSelector,
|
|
304
|
-
defaultTokenFieldNames,
|
|
305
|
-
defaultWaitForValueMs
|
|
306
|
-
});
|
|
307
|
-
debug.log("Setup module.", {
|
|
308
|
-
moduleId: id,
|
|
309
|
-
placeholderSelector: options.ui.placeholderSelector,
|
|
310
|
-
tokenFieldNames: options.transport.tokenFieldNames
|
|
311
|
-
});
|
|
312
|
-
const services = createCaptchaHostServices(ctx, options);
|
|
313
|
-
return setup({
|
|
314
|
-
...ctx,
|
|
315
|
-
options,
|
|
316
|
-
services
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
function createPassiveCaptchaModule({ id, defaultPlaceholderSelector, defaultTokenFieldNames = [], defaultWaitForValueMs = DEFAULT_WAIT_FOR_VALUE_MS }) {
|
|
322
|
-
return createCaptchaModule({
|
|
323
|
-
id,
|
|
324
|
-
defaultPlaceholderSelector,
|
|
325
|
-
defaultTokenFieldNames,
|
|
326
|
-
defaultWaitForValueMs,
|
|
327
|
-
setup: async ({ services, options, root }) => {
|
|
328
|
-
const cleanups = [];
|
|
329
|
-
let activePlaceholder = services.placeholder.getPrimary();
|
|
330
|
-
let sessionKey = options.transport.sessionKey;
|
|
331
|
-
let value = options.transport.value || "";
|
|
332
|
-
const renderPlaceholder = (placeholder) => {
|
|
333
|
-
if (!placeholder || !sessionKey) return;
|
|
334
|
-
placeholder.innerHTML = "";
|
|
335
|
-
ensureCaptchaValueInput(placeholder, sessionKey, {
|
|
336
|
-
value,
|
|
337
|
-
container: placeholder
|
|
338
|
-
});
|
|
339
|
-
};
|
|
340
|
-
const visibility = services.placeholder.observe((placeholder) => {
|
|
341
|
-
activePlaceholder = placeholder;
|
|
342
|
-
debug.log("Passive placeholder visible.", { moduleId: id });
|
|
343
|
-
renderPlaceholder(placeholder);
|
|
344
|
-
}, (placeholder) => {
|
|
345
|
-
if (activePlaceholder === placeholder) activePlaceholder = services.placeholder.getPrimary();
|
|
346
|
-
placeholder.innerHTML = "";
|
|
347
|
-
});
|
|
348
|
-
cleanups.push(visibility.cleanup);
|
|
349
|
-
renderPlaceholder(activePlaceholder);
|
|
350
|
-
cleanups.push(services.refresh.onTokensRefreshed((entry) => {
|
|
351
|
-
sessionKey = typeof entry.sessionKey === "string" && entry.sessionKey.trim() !== "" ? entry.sessionKey.trim() : sessionKey;
|
|
352
|
-
value = typeof entry.value === "string" ? entry.value : "";
|
|
353
|
-
const placeholder = services.placeholder.getPrimary() || activePlaceholder;
|
|
354
|
-
activePlaceholder = placeholder;
|
|
355
|
-
renderPlaceholder(placeholder);
|
|
356
|
-
}));
|
|
357
|
-
return {
|
|
358
|
-
destroy: () => {
|
|
359
|
-
cleanups.forEach((cleanup) => {
|
|
360
|
-
cleanup();
|
|
361
|
-
});
|
|
362
|
-
},
|
|
363
|
-
onBeforeStage: async (stageCtx) => {
|
|
364
|
-
if (stageCtx.stage !== "screen" || stageCtx.action !== "submit") return;
|
|
365
|
-
const tokenFieldNames = sessionKey ? [sessionKey] : options.transport.tokenFieldNames;
|
|
366
|
-
if (tokenFieldNames.length === 0) return;
|
|
367
|
-
if (!await waitForCaptchaValue(root, tokenFieldNames, options.transport.waitForValueMs)) {
|
|
368
|
-
const message = services.errors.getDefaultMessage();
|
|
369
|
-
services.errors.show(message, activePlaceholder);
|
|
370
|
-
debug.warn("Passive captcha missing token.", {
|
|
371
|
-
moduleId: id,
|
|
372
|
-
tokenFieldNames
|
|
373
|
-
});
|
|
374
|
-
stageCtx.abort(message);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
function createManagedCaptchaModule(adapter) {
|
|
382
|
-
return createCaptchaModule({
|
|
383
|
-
id: adapter.id,
|
|
384
|
-
defaultPlaceholderSelector: adapter.defaultPlaceholderSelector,
|
|
385
|
-
defaultTokenFieldNames: adapter.defaultTokenFieldNames,
|
|
386
|
-
setup: async (ctx) => {
|
|
387
|
-
const cleanups = [];
|
|
388
|
-
const mountedWidgets = /* @__PURE__ */ new Map();
|
|
389
|
-
const mountPromises = /* @__PURE__ */ new Map();
|
|
390
|
-
let activePlaceholder = ctx.services.placeholder.getPrimary();
|
|
391
|
-
let destroyed = false;
|
|
392
|
-
let apiPromise = null;
|
|
393
|
-
const getApi = async () => {
|
|
394
|
-
if (!apiPromise) {
|
|
395
|
-
debug.log("Loading captcha provider API.", { moduleId: adapter.id });
|
|
396
|
-
apiPromise = adapter.load(ctx);
|
|
397
|
-
}
|
|
398
|
-
return apiPromise;
|
|
399
|
-
};
|
|
400
|
-
const unmountPlaceholder = async (placeholder) => {
|
|
401
|
-
const widget = mountedWidgets.get(placeholder);
|
|
402
|
-
ctx.services.errors.clear(placeholder);
|
|
403
|
-
if (!widget) {
|
|
404
|
-
placeholder.innerHTML = "";
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
const api = await getApi();
|
|
408
|
-
if (adapter.unmount) await adapter.unmount({
|
|
409
|
-
api,
|
|
410
|
-
widget,
|
|
411
|
-
placeholder,
|
|
412
|
-
services: ctx.services,
|
|
413
|
-
options: ctx.options,
|
|
414
|
-
provider: ctx.options.provider
|
|
415
|
-
});
|
|
416
|
-
mountedWidgets.delete(placeholder);
|
|
417
|
-
placeholder.innerHTML = "";
|
|
418
|
-
ctx.services.tokens.clear();
|
|
419
|
-
debug.log("Unmounted captcha placeholder widget.", { moduleId: adapter.id });
|
|
420
|
-
if (activePlaceholder === placeholder) activePlaceholder = ctx.services.placeholder.getPrimary();
|
|
421
|
-
};
|
|
422
|
-
const mountPlaceholder = async (placeholder) => {
|
|
423
|
-
if (destroyed || mountedWidgets.has(placeholder) || mountPromises.has(placeholder)) return;
|
|
424
|
-
const promise = (async () => {
|
|
425
|
-
const api = await getApi();
|
|
426
|
-
if (destroyed || mountedWidgets.has(placeholder)) return;
|
|
427
|
-
const container = ctx.services.placeholder.createContainer(placeholder);
|
|
428
|
-
const widget = await adapter.mount({
|
|
429
|
-
api,
|
|
430
|
-
placeholder,
|
|
431
|
-
container,
|
|
432
|
-
services: ctx.services,
|
|
433
|
-
options: ctx.options,
|
|
434
|
-
provider: ctx.options.provider
|
|
435
|
-
});
|
|
436
|
-
mountedWidgets.set(placeholder, widget);
|
|
437
|
-
activePlaceholder = placeholder;
|
|
438
|
-
debug.log("Mounted captcha placeholder widget.", { moduleId: adapter.id });
|
|
439
|
-
})().finally(() => {
|
|
440
|
-
mountPromises.delete(placeholder);
|
|
441
|
-
});
|
|
442
|
-
mountPromises.set(placeholder, promise);
|
|
443
|
-
await promise;
|
|
444
|
-
};
|
|
445
|
-
const visibility = ctx.services.placeholder.observe((placeholder) => {
|
|
446
|
-
activePlaceholder = placeholder;
|
|
447
|
-
mountPlaceholder(placeholder);
|
|
448
|
-
}, (placeholder) => {
|
|
449
|
-
unmountPlaceholder(placeholder);
|
|
450
|
-
});
|
|
451
|
-
cleanups.push(visibility.cleanup);
|
|
452
|
-
const rerenderVisiblePlaceholders = async (reason) => {
|
|
453
|
-
const placeholdersToMount = visibility.getVisible();
|
|
454
|
-
if (adapter.reset) {
|
|
455
|
-
const api = await getApi();
|
|
456
|
-
for (const placeholder of placeholdersToMount) {
|
|
457
|
-
const widget = mountedWidgets.get(placeholder);
|
|
458
|
-
if (!widget) {
|
|
459
|
-
await mountPlaceholder(placeholder);
|
|
460
|
-
continue;
|
|
461
|
-
}
|
|
462
|
-
await adapter.reset({
|
|
463
|
-
api,
|
|
464
|
-
widget,
|
|
465
|
-
placeholder,
|
|
466
|
-
services: ctx.services,
|
|
467
|
-
options: ctx.options,
|
|
468
|
-
provider: ctx.options.provider,
|
|
469
|
-
reason
|
|
470
|
-
});
|
|
471
|
-
ctx.services.tokens.clear();
|
|
472
|
-
ctx.services.errors.clear(placeholder);
|
|
473
|
-
}
|
|
474
|
-
visibility.reconcile();
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
for (const placeholder of Array.from(mountedWidgets.keys())) await unmountPlaceholder(placeholder);
|
|
478
|
-
for (const placeholder of placeholdersToMount) await mountPlaceholder(placeholder);
|
|
479
|
-
visibility.reconcile();
|
|
480
|
-
};
|
|
481
|
-
cleanups.push(ctx.services.events.onRoot("formie:submit:result", (event) => {
|
|
482
|
-
const detail = event instanceof CustomEvent ? event.detail : null;
|
|
483
|
-
if (detail?.stage === "validate") return;
|
|
484
|
-
if (detail?.ok === false && detail?.stage === "screen") return;
|
|
485
|
-
if (detail?.ok === true) return;
|
|
486
|
-
rerenderVisiblePlaceholders("submit-result");
|
|
487
|
-
}));
|
|
488
|
-
if (ctx.form) cleanups.push(ctx.services.events.onForm(getFormStateEventName("reset"), () => {
|
|
489
|
-
activePlaceholder = ctx.services.placeholder.getPrimary() || activePlaceholder;
|
|
490
|
-
window.setTimeout(() => {
|
|
491
|
-
rerenderVisiblePlaceholders("reset-state");
|
|
492
|
-
}, 0);
|
|
493
|
-
}));
|
|
494
|
-
return {
|
|
495
|
-
destroy: async () => {
|
|
496
|
-
destroyed = true;
|
|
497
|
-
cleanups.forEach((cleanup) => {
|
|
498
|
-
cleanup();
|
|
499
|
-
});
|
|
500
|
-
for (const placeholder of Array.from(mountedWidgets.keys())) await unmountPlaceholder(placeholder);
|
|
501
|
-
},
|
|
502
|
-
onBeforeStage: async (stageCtx) => {
|
|
503
|
-
if (stageCtx.stage !== "screen" || stageCtx.action !== "submit") return;
|
|
504
|
-
const visiblePlaceholders = visibility.getVisible();
|
|
505
|
-
if (visiblePlaceholders.length === 0) return;
|
|
506
|
-
let placeholder = visiblePlaceholders.find((candidate) => candidate === activePlaceholder) || visiblePlaceholders[0];
|
|
507
|
-
await mountPlaceholder(placeholder);
|
|
508
|
-
placeholder = activePlaceholder || placeholder;
|
|
509
|
-
ctx.services.errors.clear(placeholder);
|
|
510
|
-
const widget = mountedWidgets.get(placeholder);
|
|
511
|
-
if (!widget) {
|
|
512
|
-
const message = ctx.services.errors.getDefaultMessage();
|
|
513
|
-
ctx.services.errors.show(message, placeholder);
|
|
514
|
-
debug.warn("Captcha widget unavailable at screen stage.", { moduleId: adapter.id });
|
|
515
|
-
stageCtx.abort(message);
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
const api = await getApi();
|
|
519
|
-
await adapter.screen({
|
|
520
|
-
api,
|
|
521
|
-
widget,
|
|
522
|
-
placeholder,
|
|
523
|
-
services: ctx.services,
|
|
524
|
-
options: ctx.options,
|
|
525
|
-
provider: ctx.options.provider,
|
|
526
|
-
stageCtx
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
//#endregion
|
|
534
|
-
//#region src/js/modules/captchas/api.ts
|
|
535
|
-
var defineCaptchaModule = createManagedCaptchaModule;
|
|
536
|
-
var definePassiveCaptchaModule = createPassiveCaptchaModule;
|
|
537
|
-
//#endregion
|
|
538
|
-
export { CAPTCHA_PROVIDER_LOAD_TIMEOUT_MS as a, CAPTCHA_EXECUTE_WAIT_FOR_VALUE_MS as i, definePassiveCaptchaModule as n, CAPTCHA_SUBMIT_WAIT_FOR_VALUE_MS as o, getScriptAttributes as r, defineCaptchaModule as t };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
//#region src/js/utils/async.ts
|
|
2
|
-
async function sleep(ms) {
|
|
3
|
-
await new Promise((resolve) => {
|
|
4
|
-
window.setTimeout(resolve, Math.max(ms, 0));
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
async function waitFor(callback, { timeoutMs = 5e3, intervalMs = 30 } = {}) {
|
|
8
|
-
const startedAt = Date.now();
|
|
9
|
-
while (Date.now() - startedAt < timeoutMs) {
|
|
10
|
-
const value = callback();
|
|
11
|
-
if (value) return value;
|
|
12
|
-
await sleep(intervalMs);
|
|
13
|
-
}
|
|
14
|
-
throw new Error("Timed out waiting for async condition.");
|
|
15
|
-
}
|
|
16
|
-
function debounce(callback, delayMs) {
|
|
17
|
-
let timeoutId = null;
|
|
18
|
-
return (...args) => {
|
|
19
|
-
if (timeoutId !== null) window.clearTimeout(timeoutId);
|
|
20
|
-
timeoutId = window.setTimeout(() => {
|
|
21
|
-
callback(...args);
|
|
22
|
-
}, Math.max(delayMs, 0));
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
export { sleep as n, waitFor as r, debounce as t };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { t as definePaymentModule } from "./api-DE7LfK-R.js";
|
|
2
|
-
//#region src/js/modules/payments/bpoint.ts
|
|
3
|
-
var bpointModule = definePaymentModule({
|
|
4
|
-
id: "bpoint",
|
|
5
|
-
defaultRequiredInputSuffixes: ["bpointToken"],
|
|
6
|
-
load: async () => {
|
|
7
|
-
return null;
|
|
8
|
-
},
|
|
9
|
-
onBeforeAuthorize: async ({ field, services }) => {
|
|
10
|
-
if ((field.querySelector("input[name$=\"[bpointToken]\"]")?.value || "").trim() !== "") return true;
|
|
11
|
-
const cardholderName = field.querySelector("[data-bpoint-card=\"cardholder-name\"]")?.value?.trim() || "";
|
|
12
|
-
const cardNumber = field.querySelector("[data-bpoint-card=\"card-number\"]")?.value?.replace(/\s+/g, "") || "";
|
|
13
|
-
const expiryRaw = field.querySelector("[data-bpoint-card=\"expiry-date\"]")?.value || "";
|
|
14
|
-
const cvn = field.querySelector("[data-bpoint-card=\"security-code\"]")?.value?.trim() || "";
|
|
15
|
-
const expiryDate = (expiryRaw.match(/\d/g) || []).join("").slice(0, 4);
|
|
16
|
-
if (!cardNumber || expiryDate.length !== 4 || !cvn) {
|
|
17
|
-
services.addError("Please provide valid card details to continue.");
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
const cardData = {
|
|
21
|
-
cardholderName,
|
|
22
|
-
cardNumber,
|
|
23
|
-
expiryDate,
|
|
24
|
-
cvn
|
|
25
|
-
};
|
|
26
|
-
services.updateInputs("bpointToken", JSON.stringify(cardData));
|
|
27
|
-
return true;
|
|
28
|
-
},
|
|
29
|
-
onAfterSubmit: async ({ services }) => {
|
|
30
|
-
services.updateInputs("bpointToken", "");
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
//#endregion
|
|
34
|
-
export { bpointModule };
|