@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,8 +0,0 @@
|
|
|
1
|
-
import { n as definePassiveCaptchaModule } from "./api-DOfDzYC_.js";
|
|
2
|
-
//#region src/js/modules/captchas/snaptcha.ts
|
|
3
|
-
var snaptchaModule = definePassiveCaptchaModule({
|
|
4
|
-
id: "snaptcha",
|
|
5
|
-
defaultPlaceholderSelector: "[data-snaptcha-captcha-placeholder]"
|
|
6
|
-
});
|
|
7
|
-
//#endregion
|
|
8
|
-
export { snaptchaModule };
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { t as definePaymentModule } from "./api-DE7LfK-R.js";
|
|
2
|
-
import { r as loadScriptAndEnsureGlobal } from "./scripts-BGD_iU_6.js";
|
|
3
|
-
//#region src/js/modules/payments/square.ts
|
|
4
|
-
var SCRIPT_ID = "FORMIE_SQUARE_SCRIPT";
|
|
5
|
-
var squareModule = definePaymentModule({
|
|
6
|
-
id: "square",
|
|
7
|
-
defaultRequiredInputSuffixes: ["squarePaymentId"],
|
|
8
|
-
load: async (ctx) => {
|
|
9
|
-
const { provider } = ctx.options;
|
|
10
|
-
const applicationId = provider.applicationId;
|
|
11
|
-
const locationId = provider.locationId;
|
|
12
|
-
if (!applicationId?.trim() || !locationId?.trim()) {
|
|
13
|
-
console.error("[formie] Missing applicationId or locationId for Square.");
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
await loadScriptAndEnsureGlobal("Square", {
|
|
17
|
-
id: SCRIPT_ID,
|
|
18
|
-
src: provider.environment === "sandbox" ? "https://sandbox.web.squarecdn.com/v1/square.js" : "https://web.squarecdn.com/v1/square.js"
|
|
19
|
-
});
|
|
20
|
-
return window.Square;
|
|
21
|
-
},
|
|
22
|
-
mount: async (args) => {
|
|
23
|
-
const { api, field, services, options } = args;
|
|
24
|
-
const provider = options.provider;
|
|
25
|
-
const placeholder = field.querySelector("[data-formie-square-button]");
|
|
26
|
-
if (!placeholder || !api) return null;
|
|
27
|
-
try {
|
|
28
|
-
const card = await api.payments(provider.applicationId || "", provider.locationId || "").card();
|
|
29
|
-
await card.attach(placeholder);
|
|
30
|
-
return card;
|
|
31
|
-
} catch (error) {
|
|
32
|
-
services.addError(error instanceof Error ? error.message : "Unable to initialize payment.");
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
unmount: async () => {},
|
|
37
|
-
onBeforeAuthorize: async (args) => {
|
|
38
|
-
const { widget, services } = args;
|
|
39
|
-
if (!widget) {
|
|
40
|
-
services.addError("Square card is not ready.");
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
const result = await widget.tokenize();
|
|
45
|
-
if (result.status === "OK" && result.token) {
|
|
46
|
-
services.updateInputs("squarePaymentId", result.token);
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
services.addError(result.errors?.[0]?.message || "Tokenization failed.");
|
|
50
|
-
return false;
|
|
51
|
-
} catch {
|
|
52
|
-
services.addError("Payment tokenization failed. Please try again.");
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
onAfterSubmit: async ({ services }) => {
|
|
57
|
-
services.updateInputs("squarePaymentId", "");
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
//#endregion
|
|
61
|
-
export { squareModule };
|
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
import { s as getPaymentProviderActionEventName } from "./event-names-DamGPtXR.js";
|
|
2
|
-
import { t as definePaymentModule } from "./api-DE7LfK-R.js";
|
|
3
|
-
import { r as removeThemeClasses, t as addThemeClasses } from "./theme-classes-vSHpdCUO.js";
|
|
4
|
-
import { r as loadScriptAndEnsureGlobal } from "./scripts-BGD_iU_6.js";
|
|
5
|
-
import { t as ensureModuleStyles } from "./styles-BIh6g7V_.js";
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/js/modules/payments/stripe.ts
|
|
8
|
-
ensureModuleStyles("stripe", ["@layer formie-theme{.formie-stripe-placeholder{justify-content:center;align-items:center;gap:var(--formie-space-2);width:100%;min-height:12rem;padding:var(--formie-space-4);border:var(--formie-border-width) solid var(--formie-color-border);border-radius:var(--formie-radius-sm);background:var(--formie-color-surface);color:var(--formie-color-text-muted);text-align:center;box-sizing:border-box;flex-direction:column;display:flex}.formie-stripe-placeholder[hidden]{display:none}}"]);
|
|
9
|
-
var SCRIPT_ID = "FORMIE_STRIPE_SCRIPT";
|
|
10
|
-
var CONFIRM_EVENT = getPaymentProviderActionEventName("stripe", "confirm");
|
|
11
|
-
var PLACEHOLDER_SELECTOR = "[data-formie-stripe-elements-placeholder]";
|
|
12
|
-
var ZERO_DECIMAL_CURRENCIES = new Set([
|
|
13
|
-
"BIF",
|
|
14
|
-
"CLP",
|
|
15
|
-
"DJF",
|
|
16
|
-
"GNF",
|
|
17
|
-
"JPY",
|
|
18
|
-
"KMF",
|
|
19
|
-
"KRW",
|
|
20
|
-
"MGA",
|
|
21
|
-
"PYG",
|
|
22
|
-
"RWF",
|
|
23
|
-
"UGX",
|
|
24
|
-
"VND",
|
|
25
|
-
"VUV",
|
|
26
|
-
"XAF",
|
|
27
|
-
"XOF",
|
|
28
|
-
"XPF"
|
|
29
|
-
]);
|
|
30
|
-
function toStripeSubunitAmount(amount, currency) {
|
|
31
|
-
if (ZERO_DECIMAL_CURRENCIES.has(currency.toUpperCase())) return Math.ceil(amount);
|
|
32
|
-
return Math.ceil(amount * 100);
|
|
33
|
-
}
|
|
34
|
-
function clearPlaceholderError(placeholder, themeSource) {
|
|
35
|
-
if (!placeholder) return;
|
|
36
|
-
removeThemeClasses(placeholder, themeSource, "fieldErrors", "fieldError");
|
|
37
|
-
placeholder.querySelectorAll("[data-payment-placeholder-error]").forEach((el) => {
|
|
38
|
-
removeThemeClasses(el, themeSource, "fieldError");
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function renderPlaceholderLoading(placeholder, themeSource, message = "Loading payment options...") {
|
|
42
|
-
if (!placeholder) return;
|
|
43
|
-
clearPlaceholderError(placeholder, themeSource);
|
|
44
|
-
placeholder.removeAttribute("hidden");
|
|
45
|
-
placeholder.innerHTML = "";
|
|
46
|
-
const spinner = document.createElement("div");
|
|
47
|
-
spinner.className = "formie-loading";
|
|
48
|
-
const text = document.createElement("div");
|
|
49
|
-
text.textContent = message;
|
|
50
|
-
placeholder.append(spinner, text);
|
|
51
|
-
}
|
|
52
|
-
function showPlaceholderMessage(placeholder, themeSource, message) {
|
|
53
|
-
if (!placeholder) return;
|
|
54
|
-
clearPlaceholderError(placeholder, themeSource);
|
|
55
|
-
placeholder.removeAttribute("hidden");
|
|
56
|
-
addThemeClasses(placeholder, themeSource, "fieldErrors");
|
|
57
|
-
placeholder.innerHTML = "";
|
|
58
|
-
const error = document.createElement("div");
|
|
59
|
-
error.setAttribute("data-payment-placeholder-error", "");
|
|
60
|
-
error.textContent = message;
|
|
61
|
-
addThemeClasses(error, themeSource, "fieldError");
|
|
62
|
-
placeholder.appendChild(error);
|
|
63
|
-
}
|
|
64
|
-
var stripeModule = definePaymentModule({
|
|
65
|
-
id: "stripe",
|
|
66
|
-
defaultRequiredInputSuffixes: ["stripePaymentIntentId"],
|
|
67
|
-
load: async (ctx) => {
|
|
68
|
-
const { provider } = ctx.options;
|
|
69
|
-
const publishableKey = provider.publishableKey;
|
|
70
|
-
if (!publishableKey?.trim()) {
|
|
71
|
-
console.error("[formie] Missing publishableKey for Stripe.");
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
return (await loadScriptAndEnsureGlobal("Stripe", {
|
|
75
|
-
id: SCRIPT_ID,
|
|
76
|
-
src: "https://js.stripe.com/v3"
|
|
77
|
-
}))(publishableKey);
|
|
78
|
-
},
|
|
79
|
-
mount: async (args) => {
|
|
80
|
-
const { api, field, services, provider } = args;
|
|
81
|
-
const placeholder = field.querySelector("[data-formie-stripe-elements]");
|
|
82
|
-
const loadingPlaceholder = field.querySelector(PLACEHOLDER_SELECTOR);
|
|
83
|
-
const stripeField = field;
|
|
84
|
-
const themeSource = services.form || services.root;
|
|
85
|
-
if (!placeholder || !api) return null;
|
|
86
|
-
const initial = provider.initialPaymentInformation || {};
|
|
87
|
-
const dynamicHandles = [initial.amount, initial.currency].map((value) => String(value ?? "").trim()).filter((value, index) => {
|
|
88
|
-
return (index === 0 ? provider.amountType : provider.currencyType) === "dynamic" && value !== "";
|
|
89
|
-
});
|
|
90
|
-
const getResolvedPaymentInfo = () => {
|
|
91
|
-
const amountResult = services.resolveAmount({ value: initial.amount });
|
|
92
|
-
if (!amountResult.ok) return {
|
|
93
|
-
ok: false,
|
|
94
|
-
error: "error" in amountResult ? amountResult.error : "Provide a payment amount to proceed."
|
|
95
|
-
};
|
|
96
|
-
const currencyResult = services.resolveCurrency({ value: initial.currency });
|
|
97
|
-
if (!currencyResult.ok) return {
|
|
98
|
-
ok: false,
|
|
99
|
-
error: "error" in currencyResult ? currencyResult.error : "Provide a payment currency to proceed."
|
|
100
|
-
};
|
|
101
|
-
const currencyCode = currencyResult.value.toLowerCase();
|
|
102
|
-
const amountValue = provider.amountType === "dynamic" ? toStripeSubunitAmount(amountResult.value, currencyCode) : amountResult.value;
|
|
103
|
-
return {
|
|
104
|
-
ok: true,
|
|
105
|
-
value: {
|
|
106
|
-
...initial,
|
|
107
|
-
capture_method: "automatic",
|
|
108
|
-
mode: provider.paymentType === "subscription" ? "subscription" : "payment",
|
|
109
|
-
appearance: {},
|
|
110
|
-
amount: amountValue,
|
|
111
|
-
currency: currencyCode
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
const destroyWidget = () => {
|
|
116
|
-
try {
|
|
117
|
-
stripeField.__formieStripeWidget?.paymentElement?.destroy?.();
|
|
118
|
-
} catch (error) {}
|
|
119
|
-
stripeField.__formieStripeWidget = null;
|
|
120
|
-
stripeField.__formieStripeElements = void 0;
|
|
121
|
-
placeholder.innerHTML = "";
|
|
122
|
-
};
|
|
123
|
-
const evaluateAndRender = () => {
|
|
124
|
-
const resolved = getResolvedPaymentInfo();
|
|
125
|
-
if (!resolved.ok) {
|
|
126
|
-
destroyWidget();
|
|
127
|
-
showPlaceholderMessage(loadingPlaceholder, themeSource, "error" in resolved ? resolved.error : "Unable to resolve payment details.");
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
if (stripeField.__formieStripeWidget && stripeField.__formieStripeElements) {
|
|
132
|
-
stripeField.__formieStripeElements.update(resolved.value);
|
|
133
|
-
clearPlaceholderError(loadingPlaceholder, themeSource);
|
|
134
|
-
loadingPlaceholder?.setAttribute("hidden", "hidden");
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
renderPlaceholderLoading(loadingPlaceholder, themeSource);
|
|
138
|
-
const elements = api.elements(resolved.value);
|
|
139
|
-
const paymentElement = elements.create("payment", {});
|
|
140
|
-
paymentElement.mount(placeholder);
|
|
141
|
-
paymentElement.on?.("loaderror", (event) => {
|
|
142
|
-
const message = event?.error?.message || "Unable to load payment options.";
|
|
143
|
-
destroyWidget();
|
|
144
|
-
showPlaceholderMessage(loadingPlaceholder, themeSource, message);
|
|
145
|
-
});
|
|
146
|
-
paymentElement.on?.("ready", () => {
|
|
147
|
-
clearPlaceholderError(loadingPlaceholder, themeSource);
|
|
148
|
-
loadingPlaceholder?.setAttribute("hidden", "hidden");
|
|
149
|
-
});
|
|
150
|
-
stripeField.__formieStripeElements = elements;
|
|
151
|
-
stripeField.__formieStripeInstance = api;
|
|
152
|
-
stripeField.__formieStripeWidget = {
|
|
153
|
-
elements,
|
|
154
|
-
paymentElement
|
|
155
|
-
};
|
|
156
|
-
if (!paymentElement.on) {
|
|
157
|
-
clearPlaceholderError(loadingPlaceholder, themeSource);
|
|
158
|
-
loadingPlaceholder?.setAttribute("hidden", "hidden");
|
|
159
|
-
}
|
|
160
|
-
} catch (error) {
|
|
161
|
-
destroyWidget();
|
|
162
|
-
showPlaceholderMessage(loadingPlaceholder, themeSource, error instanceof Error ? error.message : "Unable to initialize Stripe payment element.");
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
stripeField.__formieStripeEvaluateAndRender = evaluateAndRender;
|
|
166
|
-
stripeField.__formieStripeDynamicUnbind?.();
|
|
167
|
-
if (dynamicHandles.length > 0) stripeField.__formieStripeDynamicUnbind = services.watchFieldValueChanges(dynamicHandles, () => {
|
|
168
|
-
evaluateAndRender();
|
|
169
|
-
}, 600);
|
|
170
|
-
evaluateAndRender();
|
|
171
|
-
return stripeField.__formieStripeWidget || null;
|
|
172
|
-
},
|
|
173
|
-
unmount: async (args) => {
|
|
174
|
-
args.widget?.paymentElement?.destroy();
|
|
175
|
-
const stripeField = args.field;
|
|
176
|
-
stripeField.__formieStripeWidget = null;
|
|
177
|
-
stripeField.__formieStripeElements = void 0;
|
|
178
|
-
stripeField.__formieStripeInstance = null;
|
|
179
|
-
stripeField.__formieStripeLastClientSecret = void 0;
|
|
180
|
-
stripeField.__formieStripeEvaluateAndRender = null;
|
|
181
|
-
stripeField.__formieStripeDynamicUnbind?.();
|
|
182
|
-
stripeField.__formieStripeDynamicUnbind = null;
|
|
183
|
-
},
|
|
184
|
-
onBeforeAuthorize: async (args) => {
|
|
185
|
-
const { widget, services, field } = args;
|
|
186
|
-
const stripeField = field;
|
|
187
|
-
let activeWidget = widget;
|
|
188
|
-
if (!activeWidget?.elements) {
|
|
189
|
-
stripeField.__formieStripeEvaluateAndRender?.();
|
|
190
|
-
activeWidget = stripeField.__formieStripeWidget || null;
|
|
191
|
-
}
|
|
192
|
-
if (!activeWidget?.elements) return false;
|
|
193
|
-
const result = await activeWidget.elements.submit();
|
|
194
|
-
if (result?.error) {
|
|
195
|
-
services.addError(result.error.message);
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
return true;
|
|
199
|
-
},
|
|
200
|
-
setup: async (ctx) => {
|
|
201
|
-
const { services, options } = ctx;
|
|
202
|
-
const provider = options.provider;
|
|
203
|
-
const field = ctx.target;
|
|
204
|
-
const handler = async (event) => {
|
|
205
|
-
try {
|
|
206
|
-
const data = event.detail?.data;
|
|
207
|
-
if (!data?.clientSecret) return;
|
|
208
|
-
if (field.__formieStripeConfirming) return;
|
|
209
|
-
if (field.__formieStripeLastClientSecret === data.clientSecret) return;
|
|
210
|
-
const elements = field.__formieStripeElements;
|
|
211
|
-
if (!elements) {
|
|
212
|
-
services.addError("Stripe elements not ready for 3DS.");
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
const instance = field.__formieStripeInstance;
|
|
216
|
-
const publishableKey = provider.publishableKey;
|
|
217
|
-
if (!instance || !publishableKey) {
|
|
218
|
-
services.addError("Stripe is not initialized.");
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
field.__formieStripeConfirming = true;
|
|
222
|
-
const returnUrl = new URL(data.returnUrl || window.location.href);
|
|
223
|
-
returnUrl.searchParams.set("origin", window.location.href);
|
|
224
|
-
const result = await (data.type === "setup" ? instance.confirmSetup : instance.confirmPayment)({
|
|
225
|
-
elements,
|
|
226
|
-
clientSecret: data.clientSecret,
|
|
227
|
-
redirect: "if_required",
|
|
228
|
-
confirmParams: { return_url: returnUrl.toString() }
|
|
229
|
-
});
|
|
230
|
-
if (result?.error) {
|
|
231
|
-
services.releaseSubmitLoading();
|
|
232
|
-
services.addError(result.error.message);
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
if (data.subscriptionId) services.updateInputs("stripeSubscriptionId", data.subscriptionId);
|
|
236
|
-
const pi = result && "paymentIntent" in result ? result.paymentIntent : null;
|
|
237
|
-
const si = result && "setupIntent" in result ? result.setupIntent : null;
|
|
238
|
-
if (pi?.id) services.updateInputs("stripePaymentIntentId", pi.id);
|
|
239
|
-
else if (si?.id) services.updateInputs("stripePaymentIntentId", si.id);
|
|
240
|
-
else {
|
|
241
|
-
services.releaseSubmitLoading();
|
|
242
|
-
services.addError("Stripe confirmation did not return an intent ID.");
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
field.__formieStripeLastClientSecret = data.clientSecret;
|
|
246
|
-
services.triggerSubmit();
|
|
247
|
-
} catch (error) {
|
|
248
|
-
services.releaseSubmitLoading();
|
|
249
|
-
services.addError(error instanceof Error ? error.message : "Unable to confirm Stripe payment.");
|
|
250
|
-
} finally {
|
|
251
|
-
field.__formieStripeConfirming = false;
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
field.__formieStripeConfirmUnbind?.();
|
|
255
|
-
field.__formieStripeConfirmUnbind = services.events.onForm(CONFIRM_EVENT, handler);
|
|
256
|
-
return { destroy: () => {
|
|
257
|
-
field.__formieStripeConfirmUnbind?.();
|
|
258
|
-
field.__formieStripeConfirmUnbind = null;
|
|
259
|
-
} };
|
|
260
|
-
},
|
|
261
|
-
onAfterSubmit: async (args) => {
|
|
262
|
-
const stripeField = args.field;
|
|
263
|
-
if (args.result?.ok && !args.result?.nextPage) {
|
|
264
|
-
stripeField.__formieStripeWidget?.paymentElement?.destroy?.();
|
|
265
|
-
stripeField.__formieStripeWidget = null;
|
|
266
|
-
stripeField.__formieStripeElements = void 0;
|
|
267
|
-
args.services.updateInputs(["stripePaymentIntentId", "stripeSubscriptionId"], "");
|
|
268
|
-
stripeField.__formieStripeLastClientSecret = void 0;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
//#endregion
|
|
273
|
-
export { stripeModule };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//#region src/js/modules/styles.ts
|
|
2
|
-
var injectedModuleStyles = /* @__PURE__ */ new Set();
|
|
3
|
-
function ensureModuleStyles(moduleId, styles) {
|
|
4
|
-
if (typeof document === "undefined") return;
|
|
5
|
-
const styleId = `formie-module-style:${moduleId}`;
|
|
6
|
-
if (injectedModuleStyles.has(styleId) || document.querySelector(`style[data-formie-module-style="${moduleId}"]`)) {
|
|
7
|
-
injectedModuleStyles.add(styleId);
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
const cssText = styles.filter((style) => typeof style === "string" && style.trim().length > 0).join("\n");
|
|
11
|
-
if (!cssText) {
|
|
12
|
-
injectedModuleStyles.add(styleId);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const style = document.createElement("style");
|
|
16
|
-
style.setAttribute("data-formie-module-style", moduleId);
|
|
17
|
-
style.textContent = cssText;
|
|
18
|
-
document.head.appendChild(style);
|
|
19
|
-
injectedModuleStyles.add(styleId);
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
export { ensureModuleStyles as t };
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { t as createDebug } from "./debug-KnZeKYBI.js";
|
|
2
|
-
import { i as toggleThemeClasses } from "./theme-classes-vSHpdCUO.js";
|
|
3
|
-
import { n as requestText } from "./http-18nn97DZ.js";
|
|
4
|
-
import { t as debounce } from "./async-B3DUf1GZ.js";
|
|
5
|
-
import { t as ensureModuleStyles } from "./styles-BIh6g7V_.js";
|
|
6
|
-
import { r as getModuleFieldContainers, t as dispatchFieldEvent } from "./shared-DC6_1u8X.js";
|
|
7
|
-
//#region src/css/theme/fields/_summary.css?inline
|
|
8
|
-
var _summary_default = "@layer formie-theme{.formie-summary-container{padding:var(--formie-summary-padding);border:var(--formie-border-width) solid var(--formie-color-border);border-radius:var(--formie-radius-sm)}.formie-summary-heading{color:var(--formie-color-heading)}.formie-summary-blocks{gap:var(--formie-gap-summary);display:grid}.formie-summary-blocks[data-formie-loading=true]{min-height:calc(var(--formie-loading-size) + var(--formie-space-4));position:relative}.formie-summary-blocks[data-formie-loading=true]>*{opacity:0;pointer-events:none}.formie-summary-blocks[data-formie-loading=true]:before{content:\"\";background:var(--formie-color-bg);border-radius:inherit;z-index:1;display:block;position:absolute;inset:0}.formie-summary-blocks[data-formie-loading=true]:after{width:var(--formie-loading-size);height:var(--formie-loading-size);content:\"\";border:var(--formie-loading-border-width) solid var(--formie-loading-color);border-radius:var(--formie-radius-full);z-index:2;animation:formie-loading-spin var(--formie-loading-speed) linear infinite;border-top-color:#0000;border-right-color:#0000;display:block;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}}";
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/js/modules/fields/summary.ts
|
|
11
|
-
var BLOCKS_SELECTOR = "[data-formie-summary-blocks]";
|
|
12
|
-
var CONTAINER_SELECTOR = "[data-formie-summary-container]";
|
|
13
|
-
var SUMMARY_ACTION = "formie/fields/get-summary-html";
|
|
14
|
-
var MODULE_ID = "summary";
|
|
15
|
-
var debug = createDebug("fields", "summary");
|
|
16
|
-
ensureModuleStyles(MODULE_ID, [_summary_default]);
|
|
17
|
-
function getSummaryRequestUrl() {
|
|
18
|
-
const url = new URL(window.location.href);
|
|
19
|
-
url.hash = "";
|
|
20
|
-
return url.toString();
|
|
21
|
-
}
|
|
22
|
-
function getSummaryRequestState(field) {
|
|
23
|
-
return { accessToken: field.querySelector("[data-formie-summary-token]")?.value?.trim() || null };
|
|
24
|
-
}
|
|
25
|
-
async function requestSummaryHtml(form, state, signal) {
|
|
26
|
-
if (!state.accessToken) throw new Error("Summary field requires an access token.");
|
|
27
|
-
const formData = new FormData(form);
|
|
28
|
-
formData.set("action", SUMMARY_ACTION);
|
|
29
|
-
formData.set("accessToken", state.accessToken);
|
|
30
|
-
return requestText(getSummaryRequestUrl(), {
|
|
31
|
-
method: "POST",
|
|
32
|
-
body: formData,
|
|
33
|
-
signal,
|
|
34
|
-
headers: { Accept: "text/html" }
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
function initSummaryField(field, root) {
|
|
38
|
-
const form = field.closest("form");
|
|
39
|
-
if (!(form instanceof HTMLFormElement)) {
|
|
40
|
-
debug.warn("Missing form ancestor; skipping field.");
|
|
41
|
-
return () => {};
|
|
42
|
-
}
|
|
43
|
-
let hasFetched = false;
|
|
44
|
-
let isDirty = true;
|
|
45
|
-
let isVisible = false;
|
|
46
|
-
let dirtyVersion = 0;
|
|
47
|
-
let requestVersion = 0;
|
|
48
|
-
let activeRequest = null;
|
|
49
|
-
const getBlocks = () => {
|
|
50
|
-
const blocks = field.querySelector(BLOCKS_SELECTOR);
|
|
51
|
-
return blocks instanceof HTMLElement ? blocks : null;
|
|
52
|
-
};
|
|
53
|
-
const getContainer = () => {
|
|
54
|
-
const container = field.querySelector(CONTAINER_SELECTOR);
|
|
55
|
-
return container instanceof HTMLElement ? container : null;
|
|
56
|
-
};
|
|
57
|
-
const setLoadingState = (isLoading) => {
|
|
58
|
-
const blocks = getBlocks();
|
|
59
|
-
if (!blocks) return;
|
|
60
|
-
if (isLoading) {
|
|
61
|
-
blocks.setAttribute("data-formie-loading", "true");
|
|
62
|
-
blocks.setAttribute("aria-busy", "true");
|
|
63
|
-
toggleThemeClasses(blocks, form, "loading", true);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
blocks.removeAttribute("data-formie-loading");
|
|
67
|
-
blocks.removeAttribute("aria-busy");
|
|
68
|
-
toggleThemeClasses(blocks, form, "loading", false);
|
|
69
|
-
};
|
|
70
|
-
setLoadingState(!!getSummaryRequestState(field).accessToken);
|
|
71
|
-
const queueFetch = () => {
|
|
72
|
-
if (!isVisible || hasFetched && !isDirty) return;
|
|
73
|
-
debug.log("Queueing fetch.");
|
|
74
|
-
fetchSummary();
|
|
75
|
-
};
|
|
76
|
-
const fetchSummary = debounce(async () => {
|
|
77
|
-
const state = getSummaryRequestState(field);
|
|
78
|
-
if (!getBlocks() || !state.accessToken) {
|
|
79
|
-
debug.warn("Missing state for fetch.", state);
|
|
80
|
-
setLoadingState(false);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
requestVersion += 1;
|
|
84
|
-
const currentRequestVersion = requestVersion;
|
|
85
|
-
const requestDirtyVersion = dirtyVersion;
|
|
86
|
-
activeRequest?.abort();
|
|
87
|
-
activeRequest = new AbortController();
|
|
88
|
-
setLoadingState(true);
|
|
89
|
-
try {
|
|
90
|
-
const html = await requestSummaryHtml(form, state, activeRequest.signal);
|
|
91
|
-
if (currentRequestVersion !== requestVersion) return;
|
|
92
|
-
const container = getContainer();
|
|
93
|
-
const nextMarkup = document.createElement("template");
|
|
94
|
-
nextMarkup.innerHTML = html.trim();
|
|
95
|
-
const nextContainer = nextMarkup.content.querySelector(CONTAINER_SELECTOR);
|
|
96
|
-
if (container && nextContainer instanceof HTMLElement) container.replaceWith(nextContainer);
|
|
97
|
-
else if (container) container.innerHTML = html;
|
|
98
|
-
hasFetched = true;
|
|
99
|
-
isDirty = dirtyVersion !== requestDirtyVersion;
|
|
100
|
-
debug.log("Fetch complete.", {
|
|
101
|
-
isDirty,
|
|
102
|
-
dirtyVersion,
|
|
103
|
-
requestVersion: currentRequestVersion
|
|
104
|
-
});
|
|
105
|
-
dispatchFieldEvent(field, MODULE_ID, "fetch-summary", {
|
|
106
|
-
summary: field,
|
|
107
|
-
html
|
|
108
|
-
});
|
|
109
|
-
} catch (error) {
|
|
110
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
111
|
-
debug.log("Fetch aborted.");
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
console.error("[formie] Failed to load summary field HTML.", error);
|
|
115
|
-
} finally {
|
|
116
|
-
if (currentRequestVersion === requestVersion) {
|
|
117
|
-
setLoadingState(false);
|
|
118
|
-
activeRequest = null;
|
|
119
|
-
if (isDirty) queueFetch();
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}, 300);
|
|
123
|
-
const markDirty = (event) => {
|
|
124
|
-
const target = event?.target;
|
|
125
|
-
if (target instanceof Node && field.contains(target)) return;
|
|
126
|
-
isDirty = true;
|
|
127
|
-
dirtyVersion += 1;
|
|
128
|
-
debug.log("Marked dirty.", { dirtyVersion });
|
|
129
|
-
};
|
|
130
|
-
const handleFieldMutation = (event) => {
|
|
131
|
-
markDirty(event);
|
|
132
|
-
queueFetch();
|
|
133
|
-
};
|
|
134
|
-
const handleSubmitResult = () => {
|
|
135
|
-
isDirty = true;
|
|
136
|
-
debug.log("Submit result received; refreshing.");
|
|
137
|
-
queueFetch();
|
|
138
|
-
};
|
|
139
|
-
const handlePageNavigate = () => {
|
|
140
|
-
isDirty = true;
|
|
141
|
-
debug.log("Page navigation received; refreshing.");
|
|
142
|
-
queueFetch();
|
|
143
|
-
};
|
|
144
|
-
const observer = new IntersectionObserver((entries) => {
|
|
145
|
-
isVisible = !!entries[0]?.isIntersecting;
|
|
146
|
-
if (!isVisible) return;
|
|
147
|
-
debug.log("Field became visible.");
|
|
148
|
-
dispatchFieldEvent(field, MODULE_ID, "field-visible", { summary: field });
|
|
149
|
-
queueFetch();
|
|
150
|
-
}, {
|
|
151
|
-
root: form,
|
|
152
|
-
rootMargin: "50px"
|
|
153
|
-
});
|
|
154
|
-
observer.observe(field);
|
|
155
|
-
form.addEventListener("input", handleFieldMutation);
|
|
156
|
-
form.addEventListener("change", handleFieldMutation);
|
|
157
|
-
root.addEventListener("formie:page:navigate:after", handlePageNavigate);
|
|
158
|
-
root.addEventListener("formie:submit:result", handleSubmitResult);
|
|
159
|
-
return () => {
|
|
160
|
-
activeRequest?.abort();
|
|
161
|
-
observer.disconnect();
|
|
162
|
-
form.removeEventListener("input", handleFieldMutation);
|
|
163
|
-
form.removeEventListener("change", handleFieldMutation);
|
|
164
|
-
root.removeEventListener("formie:page:navigate:after", handlePageNavigate);
|
|
165
|
-
root.removeEventListener("formie:submit:result", handleSubmitResult);
|
|
166
|
-
debug.log("Field destroyed.");
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
var summaryModule = {
|
|
170
|
-
id: MODULE_ID,
|
|
171
|
-
kind: "field",
|
|
172
|
-
match: (ctx) => {
|
|
173
|
-
return !!ctx.target.querySelector(BLOCKS_SELECTOR);
|
|
174
|
-
},
|
|
175
|
-
setup: async (ctx) => {
|
|
176
|
-
const cleanups = getModuleFieldContainers(ctx).map((field) => {
|
|
177
|
-
return initSummaryField(field, ctx.root);
|
|
178
|
-
});
|
|
179
|
-
debug.log("Module setup.", { fieldCount: cleanups.length });
|
|
180
|
-
await ctx.emit("formie:module:summary:init", { count: cleanups.length });
|
|
181
|
-
return { destroy: () => {
|
|
182
|
-
cleanups.forEach((cleanup) => {
|
|
183
|
-
cleanup();
|
|
184
|
-
});
|
|
185
|
-
debug.log("Module destroy.", { fieldCount: cleanups.length });
|
|
186
|
-
ctx.emit("formie:module:summary:destroy", {});
|
|
187
|
-
} };
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
//#endregion
|
|
191
|
-
export { summaryModule };
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { n as sleep } from "./async-B3DUf1GZ.js";
|
|
2
|
-
import { t as ensureModuleStyles } from "./styles-BIh6g7V_.js";
|
|
3
|
-
import { a as getTemplateSource, o as getTemplateSourceHtml, t as dispatchFieldEvent } from "./shared-DC6_1u8X.js";
|
|
4
|
-
//#region src/css/theme/fields/_table.css?inline
|
|
5
|
-
var _table_default = "@layer formie-theme{.formie-table-wrapper{-webkit-overflow-scrolling:touch;max-width:100%;overflow:auto hidden}.formie-table{width:var(--formie-table-width);margin-bottom:var(--formie-table-margin-bottom);border-collapse:var(--formie-table-border-collapse)}.formie-table th{text-align:var(--formie-table-th-text-align);font-size:var(--formie-table-th-font-size);font-weight:var(--formie-table-th-font-weight);color:var(--formie-table-th-color,var(--formie-gray-500))}.formie-table th,.formie-table td{padding:var(--formie-table-row-padding);vertical-align:top}.formie-table th:first-child,.formie-table td:first-child{padding-left:0}.formie-table th:last-child,.formie-table td:last-child{padding-right:0}.formie-table [data-col-remove]{width:calc(var(--formie-button-icon-button-size) + (var(--formie-table-row-padding) * 2));min-width:calc(var(--formie-button-icon-button-size) + (var(--formie-table-row-padding) * 2));white-space:nowrap;text-align:center;vertical-align:middle}.formie-table [data-formie-table-column-type=checkbox]{text-align:center;vertical-align:middle}.formie-table [data-formie-table-column-type=checkbox] .formie-checkbox-option{width:100%;min-height:var(--formie-check-size);justify-content:center;align-items:center;margin:0;display:flex}.formie-table [data-formie-table-column-type=checkbox] .formie-checkbox-option-label{width:var(--formie-check-size);min-width:var(--formie-check-size);height:var(--formie-check-size);margin:0 auto;padding-left:0;font-size:0;line-height:0;display:block}.formie-table [data-formie-table-column-type=checkbox] .formie-checkbox-option-label:before{position:static}.formie-table-color-input{min-width:4rem;padding:var(--formie-space-1)}.formie-table-multiline-input{min-height:calc(var(--formie-control-height) + var(--formie-space-2))}.formie-table-remove-button{vertical-align:middle;display:inline-flex}.formie-button.formie-table-add-button{width:auto;max-width:100%;padding-left:var(--formie-table-add-button-padding-left);justify-content:center;justify-self:start;align-items:center;display:inline-flex;position:relative}.formie-button.formie-table-add-button:before{content:\"\";width:var(--formie-table-add-button-width);height:var(--formie-table-add-button-height);left:var(--formie-table-add-button-left);-webkit-mask-image:var(--formie-table-add-button-icon-mask);-webkit-mask-image:var(--formie-table-add-button-icon-mask);mask-image:var(--formie-table-add-button-icon-mask);background-color:currentColor;display:block;position:absolute;top:50%;transform:translateY(-50%);-webkit-mask-position:50%;mask-position:50%;-webkit-mask-size:contain;mask-size:contain;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat}}";
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/js/modules/fields/table.ts
|
|
8
|
-
var FIELD_SELECTOR = "[data-formie-table-field-layout]";
|
|
9
|
-
var TABLE_SELECTOR = "[data-formie-table]";
|
|
10
|
-
var TABLE_BODY_SELECTOR = "[data-formie-table-body]";
|
|
11
|
-
var ROW_SELECTOR = "[data-formie-table-row]";
|
|
12
|
-
var ADD_SELECTOR = "[data-formie-table-add]";
|
|
13
|
-
var REMOVE_SELECTOR = "[data-formie-table-remove]";
|
|
14
|
-
var TEMPLATE_ID_ATTR = "data-formie-template-id";
|
|
15
|
-
var ROW_ID_ATTR = "data-formie-table-row-id";
|
|
16
|
-
var MODULE_ID = "table";
|
|
17
|
-
ensureModuleStyles(MODULE_ID, [_table_default]);
|
|
18
|
-
function getTemplate(field, templateId) {
|
|
19
|
-
return getTemplateSource(field, templateId);
|
|
20
|
-
}
|
|
21
|
-
function getRowCount(field) {
|
|
22
|
-
return field.querySelectorAll(ROW_SELECTOR).length;
|
|
23
|
-
}
|
|
24
|
-
function getNextRowId(field) {
|
|
25
|
-
return Array.from(field.querySelectorAll(ROW_SELECTOR)).reduce((max, row) => {
|
|
26
|
-
const current = parseInt(row.getAttribute(ROW_ID_ATTR) || "", 10);
|
|
27
|
-
return Number.isNaN(current) ? max : Math.max(max, current + 1);
|
|
28
|
-
}, 0);
|
|
29
|
-
}
|
|
30
|
-
function syncAddButton(addButton, rowCount) {
|
|
31
|
-
if (!addButton) return;
|
|
32
|
-
const maxRows = parseInt(addButton.getAttribute("data-formie-max-rows") || "", 10);
|
|
33
|
-
addButton.disabled = maxRows > 0 && rowCount >= maxRows;
|
|
34
|
-
}
|
|
35
|
-
function bindTableField(field, options) {
|
|
36
|
-
const table = field.querySelector(TABLE_SELECTOR);
|
|
37
|
-
const tbody = field.querySelector(TABLE_BODY_SELECTOR);
|
|
38
|
-
const addButton = field.querySelector(ADD_SELECTOR);
|
|
39
|
-
if (!(table instanceof HTMLElement) || !(tbody instanceof HTMLElement)) return () => {};
|
|
40
|
-
const removeHandlers = /* @__PURE__ */ new Map();
|
|
41
|
-
let rowCounter = getNextRowId(field);
|
|
42
|
-
const bindRemoveButtons = () => {
|
|
43
|
-
field.querySelectorAll(REMOVE_SELECTOR).forEach((button) => {
|
|
44
|
-
if (!(button instanceof HTMLElement) || removeHandlers.has(button)) return;
|
|
45
|
-
const handler = (event) => {
|
|
46
|
-
event.preventDefault();
|
|
47
|
-
const row = button.closest(ROW_SELECTOR);
|
|
48
|
-
if (!(row instanceof HTMLElement)) return;
|
|
49
|
-
const minRows = parseInt((addButton instanceof HTMLButtonElement ? addButton.getAttribute("data-formie-min-rows") : "") || "", 10);
|
|
50
|
-
if (minRows > 0 && getRowCount(field) <= minRows) return;
|
|
51
|
-
row.remove();
|
|
52
|
-
syncAddButton(addButton instanceof HTMLButtonElement ? addButton : null, getRowCount(field));
|
|
53
|
-
dispatchFieldEvent(field, MODULE_ID, "remove", {
|
|
54
|
-
table: field,
|
|
55
|
-
row
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
button.addEventListener("click", handler);
|
|
59
|
-
removeHandlers.set(button, handler);
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
const addRow = async () => {
|
|
63
|
-
if (options.static || !(addButton instanceof HTMLButtonElement)) return;
|
|
64
|
-
if (!addButton.getAttribute("data-formie-table-add")) return;
|
|
65
|
-
const templateId = addButton.getAttribute(TEMPLATE_ID_ATTR) || field.getAttribute(TEMPLATE_ID_ATTR);
|
|
66
|
-
const maxRows = parseInt(addButton.getAttribute("data-formie-max-rows") || "", 10);
|
|
67
|
-
if (maxRows > 0 && getRowCount(field) >= maxRows) return;
|
|
68
|
-
const template = getTemplate(field, templateId);
|
|
69
|
-
if (!template) return;
|
|
70
|
-
const html = getTemplateSourceHtml(template).replaceAll("__ROW__", String(rowCounter++));
|
|
71
|
-
const row = document.createElement("tr");
|
|
72
|
-
row.setAttribute("data-formie-table-row", "true");
|
|
73
|
-
row.setAttribute(ROW_ID_ATTR, String(rowCounter - 1));
|
|
74
|
-
row.innerHTML = html;
|
|
75
|
-
tbody.appendChild(row);
|
|
76
|
-
await sleep(50);
|
|
77
|
-
bindRemoveButtons();
|
|
78
|
-
syncAddButton(addButton, getRowCount(field));
|
|
79
|
-
dispatchFieldEvent(field, MODULE_ID, "append", {
|
|
80
|
-
table: field,
|
|
81
|
-
row
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
const addHandler = (event) => {
|
|
85
|
-
event.preventDefault();
|
|
86
|
-
addRow();
|
|
87
|
-
};
|
|
88
|
-
if (addButton instanceof HTMLButtonElement && !options.static) addButton.addEventListener("click", addHandler);
|
|
89
|
-
bindRemoveButtons();
|
|
90
|
-
syncAddButton(addButton instanceof HTMLButtonElement ? addButton : null, getRowCount(field));
|
|
91
|
-
dispatchFieldEvent(field, MODULE_ID, "init", { table: field });
|
|
92
|
-
return () => {
|
|
93
|
-
if (addButton instanceof HTMLButtonElement) addButton.removeEventListener("click", addHandler);
|
|
94
|
-
removeHandlers.forEach((handler, button) => {
|
|
95
|
-
button.removeEventListener("click", handler);
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
var tableModule = {
|
|
100
|
-
id: MODULE_ID,
|
|
101
|
-
kind: "field",
|
|
102
|
-
match: (ctx) => {
|
|
103
|
-
return ctx.target instanceof HTMLElement && (ctx.target.matches(FIELD_SELECTOR) || !!ctx.target.querySelector(FIELD_SELECTOR));
|
|
104
|
-
},
|
|
105
|
-
setup: async (ctx) => {
|
|
106
|
-
const options = ctx.options || {};
|
|
107
|
-
if (!(ctx.target instanceof HTMLElement)) return;
|
|
108
|
-
const fields = ctx.target.matches(FIELD_SELECTOR) ? [ctx.target] : Array.from(ctx.target.querySelectorAll(FIELD_SELECTOR)).filter((field) => {
|
|
109
|
-
return field instanceof HTMLElement;
|
|
110
|
-
});
|
|
111
|
-
const destroyBindings = fields.map((field) => {
|
|
112
|
-
return bindTableField(field, options);
|
|
113
|
-
});
|
|
114
|
-
await ctx.emit("formie:module:table:init", { count: fields.length });
|
|
115
|
-
return { destroy: () => {
|
|
116
|
-
destroyBindings.forEach((destroyBinding) => {
|
|
117
|
-
destroyBinding();
|
|
118
|
-
});
|
|
119
|
-
ctx.emit("formie:module:table:destroy", {});
|
|
120
|
-
} };
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
//#endregion
|
|
124
|
-
export { tableModule };
|