@verbb/formie-browser 1.0.4 → 1.0.5

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.
Files changed (182) hide show
  1. package/CHANGELOG.md +62 -22
  2. package/dist/chunks/address-country-Rx6GQTND.js +68 -0
  3. package/dist/chunks/address-finder-yXU5yMjG.js +30 -0
  4. package/dist/chunks/address-state-BQ0xGV9n.js +344 -0
  5. package/dist/chunks/api-CmwLRq_n.js +780 -0
  6. package/dist/chunks/api-DMK8NSUI.js +407 -0
  7. package/dist/chunks/api-sPqGbOww.js +125 -0
  8. package/dist/chunks/async-nPFRNQ06.js +25 -0
  9. package/dist/chunks/bpoint-DSjqRv63.js +24 -0
  10. package/dist/chunks/calculations-CgVJcQ2P.js +299 -0
  11. package/dist/chunks/captcha-eu-CWJb64_j.js +31 -0
  12. package/dist/chunks/checkbox-radio-DQ0H67Tj.js +125 -0
  13. package/dist/chunks/chunk-3b4jIN3o.js +13 -0
  14. package/dist/chunks/combobox-D-2b42wn.js +1954 -0
  15. package/dist/chunks/conditions-CZ3FU5QO.js +412 -0
  16. package/dist/chunks/constants-DVcJAvc5.js +38 -0
  17. package/dist/chunks/country-from-ip-BwxKaBuJ.js +26 -0
  18. package/dist/chunks/custom-google-maps-BsaSirEZ.js +194 -0
  19. package/dist/chunks/custom-link-CJ1-FjEM.js +46 -0
  20. package/dist/chunks/custom-maps-DYW_pBid.js +161 -0
  21. package/dist/chunks/date-picker-5CA_-zGb.js +5311 -0
  22. package/dist/chunks/debug-BV0DvdHx.js +41 -0
  23. package/dist/chunks/dist-BF5GU3_9.js +2674 -0
  24. package/dist/chunks/event-names-BCI2FLD8.js +51 -0
  25. package/dist/chunks/eway-D3ctTbEk.js +70 -0
  26. package/dist/chunks/field-references.keys-58ZSTrCW.js +21 -0
  27. package/dist/chunks/field-references.resolver-CHwn0G0L.js +145 -0
  28. package/dist/chunks/file-upload-D49m8-DR.js +287 -0
  29. package/dist/chunks/friendly-captcha-v1-ByXzENYZ.js +31 -0
  30. package/dist/chunks/friendly-captcha-v2-BPdlmhQu.js +36 -0
  31. package/dist/chunks/friendly-challenge-8uPatWqk.js +832 -0
  32. package/dist/chunks/go-cardless-BwASSYSK.js +23 -0
  33. package/dist/chunks/google-address-OhKilPWE.js +161 -0
  34. package/dist/chunks/hcaptcha-CdCd9oEi.js +54 -0
  35. package/dist/chunks/hidden-D7_Ch-QN.js +26 -0
  36. package/dist/chunks/http-D-JExro7.js +27 -0
  37. package/dist/chunks/i18n-BY1ds1BL.js +121 -0
  38. package/dist/chunks/leaflet-src-j-lHNmhR.js +4585 -0
  39. package/dist/chunks/loqate-Cp2zvwpE.js +76 -0
  40. package/dist/chunks/mollie-COG-ko2D.js +23 -0
  41. package/dist/chunks/moneris-CMH8PlRc.js +117 -0
  42. package/dist/chunks/opayo-D2jsR5vh.js +113 -0
  43. package/dist/chunks/paddle-DxF88RfC.js +55 -0
  44. package/dist/chunks/paypal-b5pnwrA2.js +95 -0
  45. package/dist/chunks/payway-BJYu9DIR.js +55 -0
  46. package/dist/chunks/phone-country-D3ayr60L.js +2645 -0
  47. package/dist/chunks/place-kit-BGHklIZ-.js +48 -0
  48. package/dist/chunks/placekit-autocomplete.esm-DWVabQlq.js +1236 -0
  49. package/dist/chunks/recaptcha-enterprise-BSwi8IVX.js +65 -0
  50. package/dist/chunks/recaptcha-shared-B4zAescW.js +15 -0
  51. package/dist/chunks/recaptcha-v2-checkbox-CnDQmsKa.js +40 -0
  52. package/dist/chunks/recaptcha-v2-invisible-Cz5uIlp-.js +53 -0
  53. package/dist/chunks/recaptcha-v3-BtbbP111.js +27 -0
  54. package/dist/chunks/repeater-B5leVxZU.js +102 -0
  55. package/dist/chunks/rich-text-Cv8ADyk-.js +349 -0
  56. package/dist/chunks/scripts-6CYSUGKQ.js +24 -0
  57. package/dist/chunks/sdk-BhHAYgga.js +1397 -0
  58. package/dist/chunks/shared-Bx9s0i0P.js +100 -0
  59. package/dist/chunks/signature-CpgqHCEx.js +463 -0
  60. package/dist/chunks/snaptcha-vz1RnZ15.js +8 -0
  61. package/dist/chunks/square-BP8RWAKB.js +40 -0
  62. package/dist/chunks/stripe-MihN63uC.js +184 -0
  63. package/dist/chunks/styles-BfoIZwJp.js +19 -0
  64. package/dist/chunks/summary-D3AjxpYN.js +114 -0
  65. package/dist/chunks/table-C-lkQN6I.js +78 -0
  66. package/dist/chunks/text-limit-B09elPDB.js +125 -0
  67. package/dist/chunks/theme-classes-Tv7q7ToE.js +44 -0
  68. package/dist/chunks/turnstile-D_Pi1CKM.js +58 -0
  69. package/dist/chunks/utils-Vqp8i_RM.js +49401 -0
  70. package/dist/css/formie-theme.css +2 -0
  71. package/dist/css/theme/fields/_address-state.css +94 -0
  72. package/dist/css/theme/fields/_combobox.css +246 -0
  73. package/dist/css/theme/fields/_select.css +13 -0
  74. package/dist/index.js +2447 -39
  75. package/dist/js/core/create-formie-client.d.ts.map +1 -1
  76. package/dist/js/core/submit-result-ui.d.ts.map +1 -1
  77. package/dist/js/core/validation-focus.d.ts +4 -0
  78. package/dist/js/core/validation-focus.d.ts.map +1 -0
  79. package/dist/js/modules/address/api.d.ts +1 -0
  80. package/dist/js/modules/address/api.d.ts.map +1 -1
  81. package/dist/js/modules/address/constants.d.ts +22 -1
  82. package/dist/js/modules/address/constants.d.ts.map +1 -1
  83. package/dist/js/modules/address/host.d.ts +2 -2
  84. package/dist/js/modules/address/host.d.ts.map +1 -1
  85. package/dist/js/modules/address/loqate.d.ts.map +1 -1
  86. package/dist/js/modules/fields/address-country.d.ts +3 -0
  87. package/dist/js/modules/fields/address-country.d.ts.map +1 -0
  88. package/dist/js/modules/fields/address-state.d.ts +3 -0
  89. package/dist/js/modules/fields/address-state.d.ts.map +1 -0
  90. package/dist/js/modules/fields/calculations.d.ts.map +1 -1
  91. package/dist/js/modules/fields/combobox.d.ts +17 -0
  92. package/dist/js/modules/fields/combobox.d.ts.map +1 -0
  93. package/dist/js/modules/fields/custom-google-maps.d.ts +64 -0
  94. package/dist/js/modules/fields/custom-google-maps.d.ts.map +1 -0
  95. package/dist/js/modules/fields/custom-link.d.ts +3 -0
  96. package/dist/js/modules/fields/custom-link.d.ts.map +1 -0
  97. package/dist/js/modules/fields/custom-maps.d.ts +3 -0
  98. package/dist/js/modules/fields/custom-maps.d.ts.map +1 -0
  99. package/dist/js/modules/fields/date-picker.d.ts.map +1 -1
  100. package/dist/js/modules/fields/index.d.ts.map +1 -1
  101. package/dist/js/modules/fields/phone-country.d.ts.map +1 -1
  102. package/dist/js/submit/pipeline.d.ts.map +1 -1
  103. package/dist/js/utils/country-from-ip.d.ts +7 -0
  104. package/dist/js/utils/country-from-ip.d.ts.map +1 -0
  105. package/dist/js/utils/field-references.d.ts +1 -0
  106. package/dist/js/utils/field-references.d.ts.map +1 -1
  107. package/dist/js/utils/field-references.row-scope.d.ts +11 -0
  108. package/dist/js/utils/field-references.row-scope.d.ts.map +1 -0
  109. package/package.json +6 -3
  110. package/src/css/formie-theme.css +2 -0
  111. package/src/css/theme/fields/_address-state.css +94 -0
  112. package/src/css/theme/fields/_combobox.css +246 -0
  113. package/src/css/theme/fields/_select.css +13 -0
  114. package/src/js/core/create-formie-client.ts +27 -0
  115. package/src/js/core/submit-result-ui.ts +4 -4
  116. package/src/js/core/validation-focus.ts +117 -0
  117. package/src/js/modules/address/api.ts +7 -0
  118. package/src/js/modules/address/constants.ts +82 -2
  119. package/src/js/modules/address/host.ts +16 -6
  120. package/src/js/modules/address/loqate.ts +3 -17
  121. package/src/js/modules/fields/address-country.ts +156 -0
  122. package/src/js/modules/fields/address-state.ts +946 -0
  123. package/src/js/modules/fields/calculations.ts +32 -0
  124. package/src/js/modules/fields/combobox.ts +188 -0
  125. package/src/js/modules/fields/custom-google-maps.ts +416 -0
  126. package/src/js/modules/fields/custom-link.ts +95 -0
  127. package/src/js/modules/fields/custom-maps.ts +339 -0
  128. package/src/js/modules/fields/date-picker.ts +96 -3
  129. package/src/js/modules/fields/index.ts +6 -0
  130. package/src/js/modules/fields/phone-country.ts +6 -0
  131. package/src/js/submit/pipeline.ts +11 -1
  132. package/src/js/utils/country-from-ip.ts +54 -0
  133. package/src/js/utils/field-references.row-scope.ts +303 -0
  134. package/src/js/utils/field-references.ts +1 -0
  135. package/dist/chunks/address-finder-BU4roxT6.js +0 -37
  136. package/dist/chunks/bpoint-uNg5j6rt.js +0 -26
  137. package/dist/chunks/calculations-C9t6Zop9.js +0 -147
  138. package/dist/chunks/captcha-eu-BAPzHNts.js +0 -34
  139. package/dist/chunks/checkbox-radio-CHeLNVIK.js +0 -141
  140. package/dist/chunks/conditions-DKxVCsjD.js +0 -459
  141. package/dist/chunks/date-picker-B3iQ797Z.js +0 -4994
  142. package/dist/chunks/eway-DCielIML.js +0 -74
  143. package/dist/chunks/file-upload-DP2TOUYV.js +0 -316
  144. package/dist/chunks/friendly-captcha-v1-DdlcGiFY.js +0 -33
  145. package/dist/chunks/friendly-captcha-v2-76w-YnFm.js +0 -38
  146. package/dist/chunks/go-cardless-rwCkzbNK.js +0 -24
  147. package/dist/chunks/google-address-BD8IZ86V.js +0 -181
  148. package/dist/chunks/hcaptcha-BNNTL6uf.js +0 -56
  149. package/dist/chunks/hidden-CW6Rcf1N.js +0 -31
  150. package/dist/chunks/index-BEsfee-D.js +0 -1839
  151. package/dist/chunks/index-BP7Unm5Y.js +0 -863
  152. package/dist/chunks/index-D6npYxvr.js +0 -4423
  153. package/dist/chunks/loqate-B-ZNS65B.js +0 -55
  154. package/dist/chunks/mollie-BDAZ-1X4.js +0 -24
  155. package/dist/chunks/moneris-B1b0uEtY.js +0 -101
  156. package/dist/chunks/opayo-CC5hraHo.js +0 -122
  157. package/dist/chunks/paddle-B4GmrDsq.js +0 -60
  158. package/dist/chunks/paypal-BFS6XsIS.js +0 -100
  159. package/dist/chunks/payway-DekoJead.js +0 -56
  160. package/dist/chunks/phone-country-Cm5YUeXI.js +0 -3765
  161. package/dist/chunks/place-kit-DizZWV_e.js +0 -42
  162. package/dist/chunks/placekit-autocomplete.esm-LAwfbPZl.js +0 -1299
  163. package/dist/chunks/recaptcha-enterprise-BbOvO7JZ.js +0 -71
  164. package/dist/chunks/recaptcha-shared-Dwg1eVFS.js +0 -15
  165. package/dist/chunks/recaptcha-v2-checkbox-SY3ti5iQ.js +0 -41
  166. package/dist/chunks/recaptcha-v2-invisible-DSmQnn6c.js +0 -59
  167. package/dist/chunks/recaptcha-v3-DNh7YCnR.js +0 -28
  168. package/dist/chunks/repeater-DM0vuFNQ.js +0 -124
  169. package/dist/chunks/rich-text-C8aGYp70.js +0 -304
  170. package/dist/chunks/scripts-CKTFtxPO.js +0 -36
  171. package/dist/chunks/sdk-3SicTWby.js +0 -1559
  172. package/dist/chunks/shared--BU5CFoL.js +0 -80
  173. package/dist/chunks/signature-pFhZfH7d.js +0 -550
  174. package/dist/chunks/snaptcha-VuOUOaLj.js +0 -8
  175. package/dist/chunks/square-BR9pvToy.js +0 -46
  176. package/dist/chunks/stripe-OHUwoV9g.js +0 -202
  177. package/dist/chunks/styles-C3aqgtek.js +0 -21
  178. package/dist/chunks/summary-Da7Ktg3N.js +0 -126
  179. package/dist/chunks/table-C0PmR9bI.js +0 -95
  180. package/dist/chunks/text-limit-mLEwZDIa.js +0 -144
  181. package/dist/chunks/turnstile-9tM7q_LK.js +0 -59
  182. package/dist/chunks/utils-BntI3W4S.js +0 -6149
@@ -1,4423 +0,0 @@
1
- const Dr = [
2
- { legacyEvent: "onFormieLoaded", canonicalEvent: "formie:mount:after", disposition: "approximate", target: "document" },
3
- { legacyEvent: "onFormieInit", canonicalEvent: "formie:mount:after", disposition: "approximate", target: "document" },
4
- { legacyEvent: "onFormieReady", canonicalEvent: "formie:mount:after", disposition: "safe" },
5
- { legacyEvent: "onAfterFormieSubmit", canonicalEvent: "formie:submit:result", disposition: "safe" },
6
- { legacyEvent: "onFormieSubmitError", canonicalEvent: "formie:submit:result", disposition: "safe" },
7
- { legacyEvent: "onFormiePageToggle", canonicalEvent: "formie:page:navigate:after", disposition: "safe" },
8
- { legacyEvent: "onBeforeFormieSubmit", canonicalEvent: "formie:submit:before", disposition: "approximate" },
9
- { legacyEvent: "onFormieValidate", canonicalEvent: "formie:stage:validate:before", disposition: "approximate" },
10
- { legacyEvent: "onAfterFormieValidate", canonicalEvent: "formie:stage:validate:after", disposition: "approximate" },
11
- { legacyEvent: "onFormieSubmit", canonicalEvent: "formie:submit:after", disposition: "approximate" }
12
- ], oa = [
13
- { legacyEvent: "formieValidatorInitialized", canonicalEvent: "formie:validator:ready", disposition: "safe" },
14
- { legacyEvent: "formieValidatorDestroyed", canonicalEvent: "formie:validator:destroy", disposition: "safe" },
15
- { legacyEvent: "formieValidatorShowError", canonicalEvent: "formie:validator:show-error", disposition: "safe" },
16
- { legacyEvent: "formieValidatorClearError", canonicalEvent: "formie:validator:clear-error", disposition: "safe" }
17
- ];
18
- function xr(e) {
19
- if (!e)
20
- return {
21
- enabled: !1,
22
- legacyDomEvents: !1,
23
- legacyValidatorEvents: !1
24
- };
25
- if (e === !0)
26
- return {
27
- enabled: !0,
28
- legacyDomEvents: !0,
29
- legacyValidatorEvents: !0
30
- };
31
- const t = e.legacyDomEvents ?? !0, r = e.legacyValidatorEvents ?? !0;
32
- return {
33
- enabled: t || r,
34
- legacyDomEvents: t,
35
- legacyValidatorEvents: r
36
- };
37
- }
38
- const Nr = [
39
- "formie:mount:after",
40
- "formie:unmount:before",
41
- "formie:unmount:after",
42
- "formie:validator:ready",
43
- "formie:theme:applied",
44
- "formie:page:navigate",
45
- "formie:page:navigate:after",
46
- "formie:page:navigate:error",
47
- "formie:submit:before",
48
- "formie:submit:after",
49
- "formie:submit:final:before",
50
- "formie:submit:final:after",
51
- "formie:submit:result",
52
- "formie:client-event",
53
- "formie:refresh-tokens:after",
54
- "formie:refresh-tokens:refreshed"
55
- ];
56
- function Be(e) {
57
- return e;
58
- }
59
- function aa(e) {
60
- return e;
61
- }
62
- function sa(e, t) {
63
- return `formie:field:${e}:${t}`;
64
- }
65
- function pe(e) {
66
- return `formie:validator:${e}`;
67
- }
68
- function la(e, t) {
69
- return `formie:address:${e}:${t}`;
70
- }
71
- function ua(e) {
72
- return `formie:file-upload:${e}`;
73
- }
74
- function ca(e, t) {
75
- return `formie:payment:${e}:${t}`;
76
- }
77
- function je(e) {
78
- return `formie:state:${e}`;
79
- }
80
- function Ur(e, t) {
81
- return `formie:module:${e}:${t}`;
82
- }
83
- function Br(e) {
84
- return `formie:module:${e}`;
85
- }
86
- function jr(e, t, r) {
87
- e.dispatchEvent(new CustomEvent(t, {
88
- bubbles: !0,
89
- detail: r
90
- }));
91
- }
92
- function zr(e, t) {
93
- if (e.canonicalEvent !== "formie:submit:result")
94
- return !0;
95
- const r = t;
96
- return e.legacyEvent === "onAfterFormieSubmit" ? !!r?.ok : e.legacyEvent === "onFormieSubmitError" ? r?.ok === !1 : !0;
97
- }
98
- function Wr(e, t) {
99
- const r = t && typeof t == "object" ? t : {}, n = typeof r.pageId == "string" ? r.pageId : "", i = Array.from(e.querySelectorAll("[data-formie-page-id]")), o = i.findIndex((a) => a.getAttribute("data-formie-page-id") === n);
100
- return {
101
- data: {
102
- nextPageId: n,
103
- nextPageIndex: o,
104
- totalPages: i.length
105
- }
106
- };
107
- }
108
- function Kr(e, t, r, n, i) {
109
- const o = globalThis.Formie || i;
110
- return e.legacyEvent === "onFormieLoaded" ? {
111
- formie: o
112
- } : e.legacyEvent === "onFormieInit" ? {
113
- formie: o,
114
- form: i,
115
- $form: n,
116
- formId: i.id
117
- } : e.legacyEvent === "onFormieReady" ? {
118
- ...t && typeof t == "object" ? t : {},
119
- form: n,
120
- target: r,
121
- instance: i
122
- } : e.legacyEvent === "onFormiePageToggle" ? Wr(n, t) : t;
123
- }
124
- function Gr({
125
- target: e,
126
- form: t,
127
- instance: r,
128
- options: n,
129
- unbinds: i
130
- }) {
131
- n.legacyDomEvents && Dr.forEach((o) => {
132
- const a = (s) => {
133
- if (!(s instanceof CustomEvent) || !zr(o, s.detail))
134
- return;
135
- const l = o.target === "document" ? document : t;
136
- jr(l, o.legacyEvent, Kr(o, s.detail, e, t, r));
137
- };
138
- e.addEventListener(Be(o.canonicalEvent), a), i.push(() => {
139
- e.removeEventListener(Be(o.canonicalEvent), a);
140
- });
141
- });
142
- }
143
- function ge(e, t, r) {
144
- e.dispatchEvent(new CustomEvent(t, {
145
- bubbles: !0,
146
- detail: r
147
- }));
148
- }
149
- function Oe(e, t) {
150
- return !!e && typeof e == "object" && e.validator === t;
151
- }
152
- function Jr({
153
- target: e,
154
- form: t,
155
- validatorDetail: r,
156
- options: n,
157
- unbinds: i
158
- }) {
159
- if (!n.legacyValidatorEvents || !r)
160
- return;
161
- const { validator: o, addValidator: a, removeValidator: s } = r, l = {
162
- ...r,
163
- form: t,
164
- target: e
165
- };
166
- ge(document, "formieValidatorInitialized", l);
167
- const d = (u) => {
168
- !(u instanceof CustomEvent) || !Oe(u.detail, o) || ge(document, "formieValidatorDestroyed", {
169
- ...l,
170
- ...u.detail
171
- });
172
- }, p = (u) => {
173
- !(u instanceof CustomEvent) || !Oe(u.detail, o) || !(u.target instanceof Element) || t.contains(u.target) && ge(u.target, "formieValidatorShowError", {
174
- ...u.detail,
175
- addValidator: a,
176
- removeValidator: s,
177
- form: t,
178
- target: e
179
- });
180
- }, h = (u) => {
181
- !(u instanceof CustomEvent) || !Oe(u.detail, o) || !(u.target instanceof Element) || t.contains(u.target) && ge(u.target, "formieValidatorClearError", {
182
- ...u.detail,
183
- addValidator: a,
184
- removeValidator: s,
185
- form: t,
186
- target: e
187
- });
188
- };
189
- document.addEventListener("formie:validator:destroy", d), document.addEventListener("formie:validator:show-error", p), document.addEventListener("formie:validator:clear-error", h), i.push(() => {
190
- document.removeEventListener("formie:validator:destroy", d), document.removeEventListener("formie:validator:show-error", p), document.removeEventListener("formie:validator:clear-error", h);
191
- });
192
- }
193
- function I(e, t, r) {
194
- e.dispatchEvent(new CustomEvent(Be(t), {
195
- bubbles: !0,
196
- detail: r
197
- }));
198
- }
199
- function zt() {
200
- return globalThis;
201
- }
202
- function Wt() {
203
- return zt().__FORMIE_DEBUG__ === !0;
204
- }
205
- function da(e) {
206
- zt().__FORMIE_DEBUG__ = e;
207
- }
208
- function Yr(e, t, r) {
209
- if (Wt()) {
210
- if (typeof r > "u") {
211
- console.log(`[formie:${e}] ${t}`);
212
- return;
213
- }
214
- console.log(`[formie:${e}] ${t}`, r);
215
- }
216
- }
217
- function Zr(e, t, r) {
218
- if (Wt()) {
219
- if (typeof r > "u") {
220
- console.warn(`[formie:${e}] ${t}`);
221
- return;
222
- }
223
- console.warn(`[formie:${e}] ${t}`, r);
224
- }
225
- }
226
- function _(e, t) {
227
- const r = t ? `${e}:${t}` : e;
228
- return {
229
- log: (n, i) => {
230
- Yr(r, n, i);
231
- },
232
- warn: (n, i) => {
233
- Zr(r, n, i);
234
- }
235
- };
236
- }
237
- const Ee = _("general", "page-client-event"), Qr = "data-formie-client-event";
238
- function Xr(e) {
239
- return typeof window < "u" && window.CSS?.escape ? window.CSS.escape(e) : e.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
240
- }
241
- function en(e) {
242
- const r = e.querySelector('input[name="pageId"]')?.value?.trim();
243
- if (r)
244
- return r;
245
- const i = e.querySelector("[data-formie-page]:not([data-formie-page-hidden])")?.getAttribute("data-formie-page-id")?.trim();
246
- return i || e.querySelector("[data-formie-page]")?.getAttribute("data-formie-page-id")?.trim() || null;
247
- }
248
- function tn(e) {
249
- if (!e?.trim())
250
- return null;
251
- try {
252
- const t = JSON.parse(e);
253
- return t && typeof t == "object" ? t : null;
254
- } catch {
255
- return Ee.warn("Invalid data-formie-client-event JSON.", {
256
- rawPreview: e.slice(0, 80)
257
- }), null;
258
- }
259
- }
260
- function rn(e) {
261
- const t = {};
262
- return e.forEach((r) => {
263
- const n = typeof r.label == "string" ? r.label.trim() : "";
264
- n && (t[n] = typeof r.value == "string" ? r.value : "");
265
- }), t;
266
- }
267
- function Kt(e, t) {
268
- if (t !== "submit")
269
- return;
270
- const r = en(e);
271
- if (!r) {
272
- Ee.log("No submitted page id; skipping client event.");
273
- return;
274
- }
275
- const n = e.querySelector(
276
- `[data-formie-page][data-formie-page-id="${Xr(r)}"]`
277
- );
278
- if (!n) {
279
- Ee.log("No page section for id; skipping client event.", { pageId: r });
280
- return;
281
- }
282
- const i = n.getAttribute(Qr);
283
- if (i === null)
284
- return;
285
- const o = tn(i);
286
- if (!o || !Array.isArray(o.fields))
287
- return;
288
- const a = rn(o.fields), s = window;
289
- s.dataLayer = s.dataLayer || [], s.dataLayer.push(a), e.dispatchEvent(new CustomEvent("formie:client-event", {
290
- bubbles: !0,
291
- detail: { payload: a }
292
- })), Ee.log("Dispatched page client event.", {
293
- pageId: r,
294
- keys: Object.keys(a)
295
- });
296
- }
297
- const we = /* @__PURE__ */ new WeakMap(), nn = "[data-formie-form], [data-formie], form";
298
- function on(e) {
299
- return e ? (Array.isArray(e) ? e : [e]).flatMap((r) => String(r).split(/\s+/)).map((r) => r.trim()).filter(Boolean) : [];
300
- }
301
- function tt(e) {
302
- return Array.from(new Set(e));
303
- }
304
- function an(e) {
305
- if (!e)
306
- return {};
307
- const t = we.get(e);
308
- if (t)
309
- return t;
310
- const r = e.closest(nn);
311
- return r ? we.get(r) || {} : {};
312
- }
313
- function sn(e) {
314
- const t = {};
315
- return Object.entries(e || {}).forEach(([r, n]) => {
316
- const i = tt(on(n));
317
- i.length && (t[r] = i);
318
- }), t;
319
- }
320
- function yt(e, t, r) {
321
- const n = sn(t), i = r || (e instanceof HTMLFormElement ? e : e.querySelector("form"));
322
- return we.set(e, n), i && we.set(i, n), n;
323
- }
324
- function rt(e, t) {
325
- return an(e)[t] || [];
326
- }
327
- function O(e, t, ...r) {
328
- const n = tt(r.flatMap((i) => rt(t, i)));
329
- n.length && e.classList.add(...n);
330
- }
331
- function le(e, t, ...r) {
332
- const n = tt(r.flatMap((i) => rt(t, i)));
333
- n.length && e.classList.remove(...n);
334
- }
335
- function ue(e, t, r, n) {
336
- rt(t, r).forEach((i) => {
337
- e.classList.toggle(i, n);
338
- });
339
- }
340
- function ln(e, t) {
341
- if (ue(e, e, "tabError", t), t) {
342
- e.setAttribute("data-formie-tab-error", "true");
343
- return;
344
- }
345
- e.removeAttribute("data-formie-tab-error");
346
- }
347
- function J(e) {
348
- const t = /* @__PURE__ */ new Set();
349
- e.querySelectorAll("[data-formie-page]").forEach((r) => {
350
- const n = r, i = n.getAttribute("data-formie-page-id");
351
- i && n.querySelector("[data-formie-field-has-error]") && t.add(i);
352
- }), e.querySelectorAll("[data-formie-tab]").forEach((r) => {
353
- const n = r, i = n.getAttribute("data-formie-page-id");
354
- ln(n, !!i && t.has(i));
355
- });
356
- }
357
- class Gt {
358
- constructor() {
359
- this.listeners = /* @__PURE__ */ new Map();
360
- }
361
- on(t, r) {
362
- return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t)?.add(r), () => {
363
- this.listeners.get(t)?.delete(r);
364
- };
365
- }
366
- async emit(t, r) {
367
- const n = this.listeners.get(t);
368
- if (!(!n || n.size === 0))
369
- for (const i of n)
370
- await i(r);
371
- }
372
- async emitSafe(t, r) {
373
- const n = this.listeners.get(t), i = {
374
- eventName: t,
375
- total: n?.size || 0,
376
- succeeded: 0,
377
- failed: []
378
- };
379
- if (!n || n.size === 0)
380
- return i;
381
- let o = 0;
382
- for (const a of n) {
383
- try {
384
- await a(r), i.succeeded += 1;
385
- } catch (s) {
386
- i.failed.push({
387
- index: o,
388
- error: s
389
- });
390
- }
391
- o += 1;
392
- }
393
- return i;
394
- }
395
- async emitParallelSafe(t, r) {
396
- const n = this.listeners.get(t), i = {
397
- eventName: t,
398
- total: n?.size || 0,
399
- succeeded: 0,
400
- failed: []
401
- };
402
- return !n || n.size === 0 || (await Promise.allSettled(Array.from(n).map(async (a) => a(r)))).forEach((a, s) => {
403
- if (a.status === "fulfilled") {
404
- i.succeeded += 1;
405
- return;
406
- }
407
- i.failed.push({
408
- index: s,
409
- error: a.reason
410
- });
411
- }), i;
412
- }
413
- clear() {
414
- this.listeners.clear();
415
- }
416
- }
417
- async function Jt(e, t = {}) {
418
- const r = {
419
- Accept: "application/json",
420
- ...t.headers || {}
421
- };
422
- return delete r["X-Requested-With"], delete r["x-requested-with"], fetch(String(e), {
423
- method: t.method || "GET",
424
- body: t.body ?? null,
425
- signal: t.signal,
426
- // Avoid sending `Cache-Control`: not CORS-safelisted; use fetch cache mode instead.
427
- cache: "no-store",
428
- headers: r,
429
- // `include` + `Access-Control-Allow-Origin: *` is invalid; many Craft GraphQL setups use `*`.
430
- // `same-origin` keeps cookies for same-host deployments and avoids credentialed cross-origin
431
- // fetches (e.g. Vite on localhost → ddev HTTPS) so wildcard CORS can succeed.
432
- credentials: "same-origin"
433
- });
434
- }
435
- async function Re(e, t = {}) {
436
- const r = await Jt(e, t);
437
- if (!r.ok)
438
- throw new Error(`Request failed (${r.status}) for ${String(e)}`);
439
- return r.json();
440
- }
441
- async function fa(e, t = {}) {
442
- const r = await Jt(e, t);
443
- if (!r.ok)
444
- throw new Error(`Request failed (${r.status}) for ${String(e)}`);
445
- return r.text();
446
- }
447
- const H = _("general", "transport");
448
- function un(e) {
449
- const t = {};
450
- return ["theme", "themeConfig", "locale", "siteId"].forEach((r) => {
451
- e[r] !== void 0 && (t[r] = e[r]);
452
- }), t;
453
- }
454
- function Yt(e, t = "", r = {}) {
455
- if (Array.isArray(e)) {
456
- const n = e.map((i) => typeof i == "string" ? i : String(i ?? "")).filter((i) => i.trim() !== "");
457
- return t && n.length && (r[t] = (r[t] || []).concat(n)), r;
458
- }
459
- return e && typeof e == "object" && Object.entries(e).forEach(([n, i]) => {
460
- const o = t ? `${t}.${n}` : n;
461
- Yt(i, o, r);
462
- }), r;
463
- }
464
- function cn(e, t) {
465
- const r = e.success === !0, n = e.keepSubmitLoading === !0, i = e.errors, o = Yt(i || {}), a = o.form || [], s = {};
466
- Object.entries(o).forEach(([h, u]) => {
467
- if (h === "form")
468
- return;
469
- const c = h.split(".")[0];
470
- s[c] = (s[c] || []).concat(u);
471
- });
472
- const l = !r && a.length === 0 && Object.keys(s).length > 0 ? [t || "Submission failed."] : a, d = !r && n && l.length === 0 && Object.keys(s).length === 0;
473
- return {
474
- ok: r,
475
- action: e.submitAction === "back" || e.submitAction === "save" || e.submitAction === "submit" ? e.submitAction : void 0,
476
- message: e.submitActionMessage || (r ? "Submission completed." : d ? "" : l[0] || "Submission failed."),
477
- code: r ? void 0 : String(e.code || "SUBMIT_ERROR"),
478
- keepSubmitLoading: n,
479
- fieldErrors: Object.keys(s).length ? s : void 0,
480
- formErrors: l.length ? l : void 0,
481
- nextPage: e.nextPageId ? {
482
- id: String(e.nextPageId)
483
- } : null,
484
- redirect: e.redirectUrl ? {
485
- url: String(e.redirectUrl),
486
- target: e.submitActionTab === "new-tab" ? "new-tab" : "same-tab"
487
- } : null,
488
- submitData: Array.isArray(e.submitData) ? e.submitData : void 0,
489
- meta: e
490
- };
491
- }
492
- async function dn(e, t, r = {}) {
493
- const n = JSON.stringify({
494
- handle: t,
495
- renderOptions: r
496
- });
497
- H.log("requestRender start.", { endpoint: e, handle: t });
498
- const i = await Re(e, {
499
- method: "POST",
500
- body: n,
501
- headers: {
502
- "Content-Type": "application/json"
503
- }
504
- });
505
- return H.log("requestRender complete.", {
506
- hasHtml: !!i.html
507
- }), i;
508
- }
509
- async function fn(e, t, r = {}) {
510
- const i = JSON.stringify({
511
- query: `
512
- query FormieHtmlForm($handle: String!, $input: ServerRenderPayloadInput) {
513
- formieHtmlForm(handle: $handle, input: $input) {
514
- html
515
- }
516
- }`,
517
- variables: {
518
- handle: t,
519
- input: un(r)
520
- }
521
- });
522
- H.log("requestGraphqlRender start.", { endpoint: e, handle: t });
523
- const o = await Re(e, {
524
- method: "POST",
525
- body: i,
526
- headers: {
527
- "Content-Type": "application/json"
528
- }
529
- });
530
- if (Array.isArray(o.errors) && o.errors.length > 0)
531
- throw new Error(o.errors.map((s) => s.message || "Unknown GraphQL error").join("; "));
532
- if (!o.data?.formieHtmlForm)
533
- throw new Error(`Form not found for handle "${t}".`);
534
- const a = o.data.formieHtmlForm;
535
- return H.log("requestGraphqlRender complete.", {
536
- hasHtml: !!a.html
537
- }), a;
538
- }
539
- async function nt(e, t, r) {
540
- const n = new URL(e, window.location.origin);
541
- n.searchParams.set("handle", t), r && n.searchParams.set("renderId", r), H.log("requestRefreshTokens start.", {
542
- endpoint: n.toString(),
543
- handle: t,
544
- hasRenderId: !!r
545
- });
546
- const i = await Re(n.toString());
547
- return H.log("requestRefreshTokens complete.", {
548
- hasRefreshTokens: !!i.refreshTokens
549
- }), i.refreshTokens || i;
550
- }
551
- async function mn(e, t, r) {
552
- const n = new URL(e, window.location.origin), i = new FormData();
553
- if (r && i.append("pageId", r), t) {
554
- ["handle", "renderId", "draftContextToken", "draftContext", "continuationToken"].forEach((d) => {
555
- const h = t.querySelector(`input[name="${d}"]`)?.value?.trim();
556
- h && i.append(d, h);
557
- });
558
- const l = t.querySelector('input[name="CRAFT_CSRF_TOKEN"]')?.value?.trim();
559
- l && i.append("CRAFT_CSRF_TOKEN", l);
560
- }
561
- H.log("requestSetPage start.", {
562
- requestUrl: n.toString(),
563
- pageId: r || null
564
- });
565
- const o = await Re(n.toString(), {
566
- method: "POST",
567
- body: i
568
- });
569
- return H.log("requestSetPage complete.", o), o;
570
- }
571
- function pn(e, t) {
572
- const r = new URL(e, window.location.origin), n = new FormData();
573
- ["handle", "renderId", "draftContextToken", "draftContext"].forEach((s) => {
574
- const d = t.querySelector(`input[name="${s}"]`)?.value?.trim();
575
- d && n.append(s, d);
576
- });
577
- const a = t.querySelector('input[name="CRAFT_CSRF_TOKEN"]')?.value?.trim();
578
- a && n.append("CRAFT_CSRF_TOKEN", a), H.log("clearSubmissionOnUnload start.", {
579
- requestUrl: r.toString()
580
- });
581
- try {
582
- if (typeof navigator.sendBeacon == "function" && navigator.sendBeacon(r.toString(), n))
583
- return;
584
- } catch {
585
- }
586
- fetch(r.toString(), {
587
- method: "POST",
588
- body: n,
589
- credentials: "include",
590
- keepalive: !0,
591
- headers: {
592
- Accept: "application/json"
593
- }
594
- });
595
- }
596
- async function gn(e, t) {
597
- const r = (e.getAttribute("method") || "POST").toUpperCase(), n = e.getAttribute("action") || window.location.href, i = e.dataset.formieErrorMessage?.trim() || "Submission failed.";
598
- H.log("submitForm start.", {
599
- method: r,
600
- action: n,
601
- submitAction: t.get("submitAction")
602
- });
603
- const o = await fetch(n, {
604
- method: r,
605
- body: t,
606
- credentials: "include",
607
- headers: {
608
- Accept: "application/json"
609
- }
610
- }), a = o.headers.get("content-type") || "";
611
- if (!a.includes("application/json"))
612
- return o.ok ? (H.log("submitForm non-JSON success response.", {
613
- status: o.status,
614
- contentType: a
615
- }), {
616
- ok: !0,
617
- message: "Submission completed."
618
- }) : (H.warn("submitForm non-JSON HTTP error.", {
619
- status: o.status,
620
- contentType: a
621
- }), {
622
- ok: !1,
623
- code: "HTTP_ERROR",
624
- message: `Request failed (${o.status}).`,
625
- formErrors: [`Request failed (${o.status}).`]
626
- });
627
- const s = await o.json(), l = cn(s, i);
628
- return H.log("submitForm JSON response normalized.", {
629
- ok: l.ok,
630
- code: l.code,
631
- hasRedirect: !!l.redirect?.url,
632
- hasSubmitData: Array.isArray(l.submitData) && l.submitData.length > 0
633
- }), l;
634
- }
635
- function it(e) {
636
- return Array.from(e.querySelectorAll("[data-formie-page]"));
637
- }
638
- function Zt(e) {
639
- const t = it(e);
640
- if (!t.length)
641
- return {
642
- scope: e,
643
- final: !0
644
- };
645
- const r = t.find((n) => !n.hasAttribute("data-formie-page-hidden")) || t[t.length - 1];
646
- return {
647
- scope: r,
648
- final: r === t[t.length - 1]
649
- };
650
- }
651
- const hn = ["prepare", "normalize", "validate", "screen", "authorize", "dispatch", "finalize"], bn = ["prepare", "normalize", "validate", "screen", "authorize"], F = _("general", "pipeline");
652
- function $e(e, t) {
653
- return {
654
- ok: !1,
655
- stage: e,
656
- code: "ABORTED",
657
- message: t || "Submission aborted.",
658
- formErrors: [t || "Submission aborted."]
659
- };
660
- }
661
- function Qt(e) {
662
- return e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement;
663
- }
664
- function Xt(e) {
665
- return !(!e.name || e.disabled || e instanceof HTMLInputElement && (e.type === "submit" || e.type === "button" || e.type === "reset" || e.type === "image" || (e.type === "checkbox" || e.type === "radio") && !e.checked || e.type === "file" && (!e.files || e.files.length === 0)));
666
- }
667
- function er(e, t) {
668
- if (t instanceof HTMLInputElement) {
669
- if (t.type === "file") {
670
- Array.from(t.files || []).forEach((r) => {
671
- e.append(t.name, r);
672
- });
673
- return;
674
- }
675
- e.append(t.name, t.value);
676
- return;
677
- }
678
- if (t instanceof HTMLSelectElement && t.multiple) {
679
- Array.from(t.selectedOptions).forEach((r) => {
680
- e.append(t.name, r.value);
681
- });
682
- return;
683
- }
684
- e.append(t.name, t.value);
685
- }
686
- function yn(e, t) {
687
- t.querySelectorAll("input, select, textarea").forEach((r) => {
688
- const n = Qt(r) ? r : null;
689
- !n || n.closest("[data-formie-page]") || Xt(n) && er(e, n);
690
- });
691
- }
692
- function vn(e, t) {
693
- const r = /* @__PURE__ */ new Set();
694
- return t.querySelectorAll("input, select, textarea").forEach((n) => {
695
- const i = Qt(n) ? n : null;
696
- !i || !i.name || i.disabled || i instanceof HTMLInputElement && (i.type === "submit" || i.type === "button" || i.type === "reset" || i.type === "image") || (i.name.startsWith("fields[") && r.add(i.name), Xt(i) && er(e, i));
697
- }), r;
698
- }
699
- function En(e, t) {
700
- t.forEach((r) => {
701
- e.has(r) || e.append(r, "");
702
- });
703
- }
704
- function vt(e, t) {
705
- const r = it(e), n = r.find((a) => !a.hasAttribute("data-formie-page-hidden")) || null;
706
- if (!r.length || !n) {
707
- const a = new FormData(e);
708
- return a.set("submitAction", t), a;
709
- }
710
- const i = new FormData();
711
- yn(i, e);
712
- const o = vn(i, n);
713
- return En(i, o), i.set("submitAction", t), i;
714
- }
715
- function Sn(e, t) {
716
- if (t !== "submit")
717
- return !1;
718
- const r = it(e);
719
- return r.length ? (r.find((i) => !i.hasAttribute("data-formie-page-hidden")) || r[r.length - 1]) === r[r.length - 1] : !0;
720
- }
721
- async function tr(e, t, r, n = {}) {
722
- F.log("Starting submit pipeline.", {
723
- action: t,
724
- preflightOnly: n.preflightOnly === !0
725
- });
726
- let i = !1, o, a = null;
727
- const s = Sn(e, t), l = {
728
- form: e,
729
- action: t,
730
- formData: vt(e, t),
731
- abort: (u) => {
732
- i = !0, o = u, F.warn("Pipeline aborted.", { reason: u });
733
- },
734
- isAborted: () => i,
735
- abortReason: () => o
736
- }, d = {
737
- prepare: async (u) => {
738
- const c = u.form.querySelector('input[name="submitAction"]');
739
- return c && (c.value = u.action), u.formData.set("submitAction", u.action), null;
740
- },
741
- normalize: async () => null,
742
- validate: async (u) => {
743
- if (u.action !== "submit" || n.validateOnSubmit === !1)
744
- return null;
745
- if (n.validator) {
746
- const { scope: c, final: b } = Zt(u.form), A = n.validator.submit(b ? u.form : c, { final: b });
747
- return A.length > 0 ? (A[0]?.input.focus(), {
748
- ok: !1,
749
- stage: "validate",
750
- code: "VALIDATION_FAILED",
751
- message: n.validator.config.errorMessage || "Validation failed.",
752
- fieldErrors: n.validator.getFieldErrors(A),
753
- formErrors: [n.validator.config.errorMessage || "Validation failed."]
754
- }) : null;
755
- }
756
- return u.form.checkValidity() ? null : (u.form.querySelector(":invalid")?.focus(), {
757
- ok: !1,
758
- stage: "validate",
759
- code: "VALIDATION_FAILED",
760
- message: "Validation failed.",
761
- formErrors: ["Validation failed."]
762
- });
763
- },
764
- screen: async () => null,
765
- authorize: async () => null,
766
- dispatch: async (u) => {
767
- u.formData = vt(u.form, u.action);
768
- const c = await gn(u.form, u.formData);
769
- return a = c, c;
770
- },
771
- finalize: async (u) => (a && a.ok && a.redirect?.url && (a.redirect.target === "new-tab" ? window.open(a.redirect.url, "_blank") : window.location.href = a.redirect.url), null)
772
- };
773
- {
774
- const u = await r.emitSafe("formie:submit:before", l);
775
- u.failed.length > 0 && F.warn("Submit before listeners failed.", {
776
- eventName: u.eventName,
777
- failed: u.failed.length
778
- });
779
- }
780
- if (s) {
781
- const u = await r.emitSafe("formie:submit:final:before", l);
782
- u.failed.length > 0 && F.warn("Final submit before listeners failed.", {
783
- eventName: u.eventName,
784
- failed: u.failed.length
785
- });
786
- }
787
- const p = n.preflightOnly ? bn : hn;
788
- for (const u of p) {
789
- if (F.log("Stage start.", { stage: u, action: t }), i)
790
- return F.warn("Stage skipped due to abort.", { stage: u, reason: o }), $e(u, o);
791
- {
792
- const b = await r.emitSafe(`formie:stage:${u}:before`, {
793
- ...l,
794
- stage: u
795
- });
796
- b.failed.length > 0 && F.warn("Stage before listeners failed.", {
797
- stage: u,
798
- failed: b.failed.length
799
- });
800
- }
801
- if (i) {
802
- const b = $e(u, o);
803
- {
804
- const A = await r.emitSafe("formie:submit:after", b);
805
- A.failed.length > 0 && F.warn("Submit after listeners failed (abort before stage).", {
806
- stage: u,
807
- failed: A.failed.length
808
- });
809
- }
810
- if (s) {
811
- const A = await r.emitSafe("formie:submit:final:after", b);
812
- A.failed.length > 0 && F.warn("Final submit after listeners failed (abort before stage).", {
813
- stage: u,
814
- failed: A.failed.length
815
- });
816
- }
817
- return F.warn("Aborted after stage before-hooks.", { stage: u, reason: o }), b;
818
- }
819
- const c = await d[u](l);
820
- F.log("Stage runner complete.", {
821
- stage: u,
822
- hasResult: !!c,
823
- ok: c ? c.ok : void 0,
824
- code: c?.code
825
- });
826
- {
827
- const b = await r.emitSafe(`formie:stage:${u}:after`, {
828
- ...l,
829
- stage: u,
830
- result: c
831
- });
832
- b.failed.length > 0 && F.warn("Stage after listeners failed.", {
833
- stage: u,
834
- failed: b.failed.length
835
- });
836
- }
837
- if (i) {
838
- const b = $e(u, o);
839
- {
840
- const A = await r.emitSafe("formie:submit:after", b);
841
- A.failed.length > 0 && F.warn("Submit after listeners failed (abort after stage).", {
842
- stage: u,
843
- failed: A.failed.length
844
- });
845
- }
846
- if (s) {
847
- const A = await r.emitSafe("formie:submit:final:after", b);
848
- A.failed.length > 0 && F.warn("Final submit after listeners failed (abort after stage).", {
849
- stage: u,
850
- failed: A.failed.length
851
- });
852
- }
853
- return F.warn("Aborted after stage after-hooks.", { stage: u, reason: o }), b;
854
- }
855
- if (c && !c.ok) {
856
- {
857
- const b = await r.emitSafe("formie:submit:after", c);
858
- b.failed.length > 0 && F.warn("Submit after listeners failed (failed stage).", {
859
- stage: u,
860
- failed: b.failed.length
861
- });
862
- }
863
- if (s) {
864
- const b = await r.emitSafe("formie:submit:final:after", c);
865
- b.failed.length > 0 && F.warn("Final submit after listeners failed (failed stage).", {
866
- stage: u,
867
- failed: b.failed.length
868
- });
869
- }
870
- return F.warn("Pipeline short-circuited by failed stage.", {
871
- stage: u,
872
- code: c.code,
873
- message: c.message
874
- }), c;
875
- }
876
- }
877
- const h = a || {
878
- ok: !0,
879
- stage: n.preflightOnly ? "authorize" : "finalize",
880
- message: n.preflightOnly ? "Submission preflight completed." : "Submission completed."
881
- };
882
- {
883
- const u = await r.emitSafe("formie:submit:after", h);
884
- u.failed.length > 0 && F.warn("Submit after listeners failed (success).", {
885
- failed: u.failed.length
886
- });
887
- }
888
- if (s) {
889
- const u = await r.emitSafe("formie:submit:final:after", h);
890
- u.failed.length > 0 && F.warn("Final submit after listeners failed (success).", {
891
- failed: u.failed.length
892
- });
893
- }
894
- return F.log("Pipeline completed.", {
895
- ok: h.ok,
896
- stage: h.stage,
897
- code: h.code
898
- }), h;
899
- }
900
- function An(e) {
901
- return e.querySelector("[data-formie-field-layout]")?.getAttribute("data-formie-error-position")?.trim() === "above" ? "above" : "below";
902
- }
903
- function rr(e, t) {
904
- const r = e.querySelector("[data-formie-field-errors]");
905
- if (r)
906
- return r;
907
- const n = e.querySelector("[data-formie-field-content]"), i = e.querySelector("[data-formie-field-control]"), o = An(e), a = document.createElement("div");
908
- return a.setAttribute("data-formie-field-errors", "true"), t?.(a), n && i ? o === "above" ? n.insertBefore(a, i) : n.appendChild(a) : e.appendChild(a), a;
909
- }
910
- const wn = {
911
- rule: ({ input: e, getRule: t }) => !t("email") || !e.value || e.value.length < 1 ? !0 : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.value),
912
- message: ({ input: e, label: t, t: r }) => e.getAttribute("data-formie-validation-email-message") ?? e.getAttribute("data-formie-pattern-email-message") ?? e.getAttribute("data-pattern-email-message") ?? r("{label} is not a valid email address.", { label: t })
913
- };
914
- function Tn(e) {
915
- return e?.querySelector("[data-formie-field-label]")?.childNodes[0]?.textContent?.trim() || "";
916
- }
917
- function Et(e) {
918
- const t = e.getRule("match");
919
- if (!t || t === !0 || typeof t != "object" || !e.field)
920
- return null;
921
- const r = typeof t.fieldHandle == "string" ? t.fieldHandle.trim() : "";
922
- if (!r)
923
- return null;
924
- const n = e.form.querySelector(`[data-formie-field-handle="${r}"]`);
925
- return n ? n.querySelector(e.config.fieldsSelector) : null;
926
- }
927
- const Mn = {
928
- rule: (e) => {
929
- const t = Et(e);
930
- return t ? t.value === e.input.value : !0;
931
- },
932
- message: (e) => {
933
- const r = Et(e)?.closest("[data-formie-field-handle]"), n = Tn(r);
934
- return e.t("{label} must match {value}.", {
935
- label: e.label,
936
- value: n
937
- });
938
- }
939
- }, Cn = {
940
- rule: ({ input: e, getRule: t }) => {
941
- const r = t("number");
942
- if (!r || !e.value || e.value.trim() === "")
943
- return !0;
944
- const n = parseFloat(e.value);
945
- if (Number.isNaN(n))
946
- return !1;
947
- if (r !== !0 && typeof r == "object") {
948
- const i = typeof r.min == "number" ? r.min : null, o = typeof r.max == "number" ? r.max : null;
949
- if (i !== null && n < i || o !== null && n > o)
950
- return !1;
951
- }
952
- return !0;
953
- },
954
- message: ({ input: e, label: t, getRule: r, t: n }) => {
955
- const i = r("number"), o = i !== !0 && i && typeof i == "object" && typeof i.min == "number" ? i.min : null, a = i !== !0 && i && typeof i == "object" && typeof i.max == "number" ? i.max : null;
956
- return o !== null && a !== null ? e.getAttribute("data-formie-validation-number-min-message") ?? n("{label} must be between {min} and {max}.", { label: t, min: o, max: a }) : o !== null ? e.getAttribute("data-formie-validation-number-min-message") ?? n("{label} must be no less than {min}.", { label: t, min: o }) : a !== null ? e.getAttribute("data-formie-validation-number-max-message") ?? n("{label} must be no greater than {max}.", { label: t, max: a }) : e.getAttribute("data-formie-validation-number-message") ?? e.getAttribute("data-formie-pattern-number-message") ?? e.getAttribute("data-pattern-number-message") ?? n("{label} is not a valid number.", { label: t });
957
- }
958
- }, Ln = {
959
- rule: ({ input: e, getRule: t }) => {
960
- if (!t("required") || e.type === "hidden")
961
- return !0;
962
- if (e.type === "checkbox" || e.type === "radio") {
963
- const r = e.form?.querySelectorAll(`[name="${e.name}"]:not([type="hidden"]):not([disabled])`) || [];
964
- return r.length ? Array.from(r).some((n) => n instanceof HTMLInputElement && n.checked) : e instanceof HTMLInputElement ? e.checked : !0;
965
- }
966
- return e.value.trim() !== "";
967
- },
968
- message: ({ input: e, label: t, t: r }) => e.getAttribute("data-formie-required-message") ?? e.getAttribute("data-required-message") ?? r("{label} cannot be blank.", { label: t })
969
- }, In = {
970
- rule: ({ input: e, getRule: t }) => {
971
- if (!t("url") || !e.value || e.value.length < 1)
972
- return !0;
973
- try {
974
- return new URL(e.value), !0;
975
- } catch {
976
- return !1;
977
- }
978
- },
979
- message: ({ input: e, label: t, t: r }) => e.getAttribute("data-formie-pattern-url-message") ?? e.getAttribute("data-pattern-url-message") ?? r("{label} is not a valid URL.", { label: t })
980
- }, Rn = {
981
- // Keep the core validator registry centralized so FormieValidator can extend
982
- // it at runtime while still shipping one predictable builtin rule surface.
983
- required: Ln,
984
- email: wn,
985
- url: In,
986
- number: Cn,
987
- match: Mn
988
- };
989
- function nr() {
990
- return window.FormieTranslations || {};
991
- }
992
- function Fn() {
993
- if (typeof document > "u")
994
- return;
995
- const e = Array.from(document.querySelectorAll('script[type="application/json"][data-formie-translations]:not([data-formie-translations-loaded="true"])'));
996
- if (e.length === 0)
997
- return;
998
- let t = null;
999
- for (const r of e) {
1000
- r.dataset.formieTranslationsLoaded = "true";
1001
- const n = r.textContent?.trim();
1002
- if (n)
1003
- try {
1004
- const i = JSON.parse(n);
1005
- if (!i || Array.isArray(i) || typeof i != "object")
1006
- continue;
1007
- t = {
1008
- ...t ?? nr(),
1009
- ...i
1010
- };
1011
- } catch {
1012
- continue;
1013
- }
1014
- }
1015
- t && (window.FormieTranslations = t);
1016
- }
1017
- function ot() {
1018
- return Fn(), nr();
1019
- }
1020
- function ir() {
1021
- return { ...ot() };
1022
- }
1023
- function ma(e) {
1024
- return window.FormieTranslations = { ...e }, ir();
1025
- }
1026
- function pa(e) {
1027
- return window.FormieTranslations = {
1028
- ...ot(),
1029
- ...e
1030
- }, ir();
1031
- }
1032
- function kn(e) {
1033
- const t = {};
1034
- let r = 0;
1035
- for (; r < e.length; ) {
1036
- for (; r < e.length && /\s/.test(e[r]); )
1037
- r++;
1038
- if (r >= e.length)
1039
- break;
1040
- const n = e.slice(r).match(/^(\w+|=\d+)\{/);
1041
- if (!n)
1042
- break;
1043
- const i = n[1];
1044
- r += n[0].length;
1045
- let o = 1;
1046
- const a = r;
1047
- for (; r < e.length && o > 0; )
1048
- e[r] === "{" ? o++ : e[r] === "}" && o--, o > 0 && r++;
1049
- t[i] = e.slice(a, r), r++;
1050
- }
1051
- return t;
1052
- }
1053
- function Pn(e, t) {
1054
- const r = `=${e}`;
1055
- if (Object.prototype.hasOwnProperty.call(t, r))
1056
- return t[r];
1057
- if (typeof Intl < "u" && typeof Intl.PluralRules == "function") {
1058
- const i = new Intl.PluralRules().select(e);
1059
- if (Object.prototype.hasOwnProperty.call(t, i))
1060
- return t[i];
1061
- }
1062
- if (e === 1 && Object.prototype.hasOwnProperty.call(t, "one"))
1063
- return t.one;
1064
- if (Object.prototype.hasOwnProperty.call(t, "other"))
1065
- return t.other;
1066
- const n = Object.keys(t)[0];
1067
- return n ? t[n] : "";
1068
- }
1069
- function qn(e, t) {
1070
- const r = e.slice(t).match(/^\{(\w+),\s*plural,\s*/);
1071
- if (!r)
1072
- return null;
1073
- const n = r[1], i = t + r[0].length;
1074
- let o = i;
1075
- for (; o < e.length; ) {
1076
- for (; o < e.length && /\s/.test(e[o]); )
1077
- o++;
1078
- if (o >= e.length || e[o] === "}")
1079
- break;
1080
- const a = e.slice(o).match(/^(\w+|=\d+)\{/);
1081
- if (!a)
1082
- return null;
1083
- o += a[0].length;
1084
- let s = 1;
1085
- for (; o < e.length && s > 0; )
1086
- e[o] === "{" ? s++ : e[o] === "}" && s--, s > 0 && o++;
1087
- o++;
1088
- }
1089
- return o >= e.length || e[o] !== "}" ? null : {
1090
- param: n,
1091
- body: e.slice(i, o),
1092
- endIndex: o
1093
- };
1094
- }
1095
- function Vn(e, t) {
1096
- let r = "", n = 0;
1097
- for (; n < e.length; ) {
1098
- if (e[n] !== "{") {
1099
- r += e[n], n++;
1100
- continue;
1101
- }
1102
- const i = qn(e, n);
1103
- if (!i) {
1104
- r += e[n], n++;
1105
- continue;
1106
- }
1107
- const o = t[i.param], a = typeof o == "number" ? o : Number.parseInt(String(o ?? ""), 10) || 0, s = kn(i.body);
1108
- let l = Pn(a, s);
1109
- l = l.replace(/#/g, String(a)), r += l, n = i.endIndex + 1;
1110
- }
1111
- return r;
1112
- }
1113
- function On(e, t) {
1114
- return e.replace(/\{(\w+),\s*number\}/g, (r, n) => {
1115
- if (!Object.prototype.hasOwnProperty.call(t, n))
1116
- return r;
1117
- const i = t[n];
1118
- return typeof i == "number" ? i.toLocaleString() : String(i);
1119
- });
1120
- }
1121
- function $n(e, t) {
1122
- return e.replace(/\{(\w+)\}/g, (r, n) => Object.prototype.hasOwnProperty.call(t, n) ? String(t[n]) : r);
1123
- }
1124
- function x(e, t = {}) {
1125
- let r = ot()[e] || e;
1126
- return r = Vn(r, t), r = On(r, t), r = $n(r, t), r;
1127
- }
1128
- const ga = x, Hn = {
1129
- // eslint-disable-next-line
1130
- email: /^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*(\.\w{2,})+$/,
1131
- url: /^(?:(?:https?|HTTPS?|ftp|FTP):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)(?:\.(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)*(?:\.(?:[a-zA-Z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/,
1132
- number: /^(?:[-+]?[0-9]*[.,]?[0-9]+)$/,
1133
- color: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,
1134
- date: /(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))/,
1135
- time: /^(?:(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9]))$/,
1136
- month: /^(?:(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])))$/
1137
- }, K = _("general", "validator");
1138
- function oe(e) {
1139
- return !!e && (e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement);
1140
- }
1141
- function _n(e, t) {
1142
- const r = (e.getAttribute("aria-describedby") || "").trim();
1143
- if (!r)
1144
- return;
1145
- const n = r.split(/\s+/).filter((i) => i !== t);
1146
- if (n.length) {
1147
- e.setAttribute("aria-describedby", n.join(" "));
1148
- return;
1149
- }
1150
- e.removeAttribute("aria-describedby");
1151
- }
1152
- function Dn(e, t) {
1153
- const r = (e.getAttribute("aria-describedby") || "").trim(), n = r ? r.split(/\s+/) : [];
1154
- n.includes(t) || n.push(t), e.setAttribute("aria-describedby", n.join(" ").trim());
1155
- }
1156
- function xn(e, t) {
1157
- e.setAttribute("aria-errormessage", t);
1158
- }
1159
- function Nn(e, t) {
1160
- e.getAttribute("aria-errormessage") === t && e.removeAttribute("aria-errormessage");
1161
- }
1162
- class Un {
1163
- constructor(t, r = {}) {
1164
- this.errors = [], this.validators = {}, this.boundListeners = !1, this.activated = /* @__PURE__ */ new WeakSet(), this.submitted = !1, this.initialValues = /* @__PURE__ */ new WeakMap(), this.form = t, this.onBlur = this.blurHandler.bind(this), this.onChange = this.changeHandler.bind(this), this.onInput = this.inputHandler.bind(this), this.config = {
1165
- live: !1,
1166
- errorMessage: "",
1167
- fieldContainerErrorClass: [],
1168
- inputErrorClass: [],
1169
- messagesClass: [],
1170
- messageClass: [],
1171
- fieldsSelector: 'input:not([type="hidden"]):not([type="submit"]):not([type="button"]):not([disabled]), select:not([disabled]), textarea:not([disabled])',
1172
- patterns: Hn,
1173
- ...r
1174
- }, Object.entries(Rn).forEach(([n, i]) => {
1175
- this.addValidator(n, i.rule, i.message);
1176
- }), this.init();
1177
- }
1178
- init() {
1179
- K.log("Initializing validator.", {
1180
- formId: this.form.id || null,
1181
- live: this.config.live
1182
- }), this.form.setAttribute("novalidate", "true"), this.inputs().forEach((t) => {
1183
- this.initialValues.set(t, this.getInputValue(t));
1184
- }), this.config.live && this.addEventListeners(), this.emitEvent(document, pe("ready"), {
1185
- validator: this
1186
- });
1187
- }
1188
- inputs(t = null) {
1189
- if (oe(t))
1190
- return [t];
1191
- const r = t || this.form;
1192
- return Array.from(r.querySelectorAll(this.config.fieldsSelector)).filter((n) => oe(n));
1193
- }
1194
- getInputValue(t) {
1195
- return t instanceof HTMLInputElement && (t.type === "checkbox" || t.type === "radio") ? t.checked : t instanceof HTMLInputElement && t.type === "file" ? t.files?.length ? Array.from(t.files).map((r) => r.name).join("|") : "" : t.value ?? "";
1196
- }
1197
- isDirty(t) {
1198
- return this.initialValues.has(t) ? this.getInputValue(t) !== this.initialValues.get(t) : (this.initialValues.set(t, this.getInputValue(t)), !1);
1199
- }
1200
- shouldShowError(t) {
1201
- return this.submitted || this.activated.has(t);
1202
- }
1203
- isValid(t = null, r = {}) {
1204
- return this.validate(t, r).length === 0;
1205
- }
1206
- validate(t = null, r = {}) {
1207
- this.errors = [];
1208
- const n = /* @__PURE__ */ new Set();
1209
- return this.inputs(t).forEach((i) => {
1210
- let o = !1;
1211
- if (!this.isVisible(i, r))
1212
- return;
1213
- const a = i.closest("[data-formie-field-handle]"), s = i instanceof HTMLInputElement && (i.type === "checkbox" || i.type === "radio") ? `${a?.getAttribute("data-formie-field-handle") || ""}:${i.name}` : null;
1214
- if (s) {
1215
- if (n.has(s))
1216
- return;
1217
- n.add(s);
1218
- }
1219
- this.shouldShowError(i) && this.removeError(i);
1220
- const l = this.getValidatorCallbackOptions(i);
1221
- Object.entries(this.validators).forEach(([d, p]) => {
1222
- if (!p.validate(l)) {
1223
- const u = this.getErrorMessage(i, d, p, l);
1224
- this.shouldShowError(i) && !o && this.showError(i, d, u), this.errors.push({
1225
- input: i,
1226
- field: l.field,
1227
- validator: d,
1228
- message: u,
1229
- handle: l.field?.getAttribute("data-formie-field-handle") || null,
1230
- result: !1
1231
- }), o = !0;
1232
- }
1233
- }), !o && this.shouldShowError(i) && this.removeError(i);
1234
- }), K.log("Validation pass complete.", {
1235
- errorCount: this.errors.length,
1236
- includeHiddenPages: r.includeHiddenPages === !0
1237
- }), this.errors;
1238
- }
1239
- removeAllErrors() {
1240
- this.inputs().forEach((t) => {
1241
- this.removeError(t);
1242
- });
1243
- }
1244
- removeError(t) {
1245
- const r = t.closest("[data-formie-field-handle]");
1246
- if (!r) {
1247
- t.removeAttribute("aria-invalid");
1248
- return;
1249
- }
1250
- const n = r.querySelector("[data-formie-field-errors]"), i = n?.id || "";
1251
- r.querySelectorAll("[data-formie-field-error]").forEach((o) => {
1252
- o.remove();
1253
- }), n && (n.innerHTML = ""), r.querySelectorAll("input, select, textarea").forEach((o) => {
1254
- const a = o;
1255
- a.removeAttribute("aria-invalid"), this.config.inputErrorClass.length && a.classList.remove(...this.config.inputErrorClass), a.removeAttribute("data-formie-input-has-error"), i && _n(a, i), r.querySelectorAll("[data-formie-field-error]").forEach((s) => {
1256
- const l = s.id;
1257
- l && Nn(a, l);
1258
- });
1259
- });
1260
- for (let o = r; o; o = o.parentElement?.closest("[data-formie-field-handle]"))
1261
- this.config.fieldContainerErrorClass.length && o.classList.remove(...this.config.fieldContainerErrorClass), o.removeAttribute("data-formie-field-has-error");
1262
- this.emitEvent(t, pe("clear-error"), {
1263
- validator: this
1264
- }), J(this.form);
1265
- }
1266
- showError(t, r, n) {
1267
- const i = t.closest("[data-formie-field-handle]");
1268
- if (!i)
1269
- return;
1270
- let o = i.querySelector("[data-formie-field-errors]");
1271
- o || (o = rr(i, (d) => {
1272
- this.config.messagesClass.length && d.classList.add(...this.config.messagesClass);
1273
- })), this.config.messagesClass.length && o.classList.add(...this.config.messagesClass), o.innerHTML = "";
1274
- const a = i.getAttribute("data-formie-field-handle") || "field", s = `${a}-error`;
1275
- o.id = o.id || `${a}-errors`, o.setAttribute("aria-live", "polite"), o.setAttribute("aria-atomic", "true");
1276
- const l = document.createElement("div");
1277
- l.setAttribute("data-formie-field-error", "true"), l.setAttribute(`data-formie-field-error-${r}`, "true"), l.setAttribute("id", s), l.setAttribute("role", "alert"), this.config.messageClass.length && l.classList.add(...this.config.messageClass), l.textContent = n, o.appendChild(l), i.setAttribute("data-formie-field-has-error", "true"), i.querySelectorAll("input, select, textarea").forEach((d) => {
1278
- const p = d;
1279
- p.setAttribute("aria-invalid", "true"), this.config.inputErrorClass.length && p.classList.add(...this.config.inputErrorClass), p.setAttribute("data-formie-input-has-error", "true"), Dn(p, o.id), xn(p, s);
1280
- });
1281
- for (let d = i; d; d = d.parentElement?.closest("[data-formie-field-handle]"))
1282
- this.config.fieldContainerErrorClass.length && d.classList.add(...this.config.fieldContainerErrorClass), d.setAttribute("data-formie-field-has-error", "true");
1283
- this.emitEvent(t, pe("show-error"), {
1284
- validator: this,
1285
- validatorName: r,
1286
- errorMessage: n
1287
- }), J(this.form);
1288
- }
1289
- getValidatorCallbackOptions(t) {
1290
- const r = t.closest("[data-formie-field-handle]"), n = r?.querySelector("[data-formie-field-label]")?.childNodes[0]?.textContent?.trim() ?? "", i = this.parseValidationRules(r?.getAttribute("data-formie-validation"));
1291
- return {
1292
- t: x,
1293
- input: t,
1294
- label: n,
1295
- field: r,
1296
- form: this.form,
1297
- config: this.config,
1298
- rules: i,
1299
- getRule: (o) => this.getRule(r, o)
1300
- };
1301
- }
1302
- getErrorMessage(t, r, n, i) {
1303
- return (typeof n.errorMessage == "function" ? n.errorMessage(i) : n.errorMessage) ?? x("{label} is invalid.", { label: i.label });
1304
- }
1305
- getErrors() {
1306
- return this.errors;
1307
- }
1308
- getFieldErrors(t = this.errors) {
1309
- const r = {};
1310
- return t.forEach((n) => {
1311
- !n.handle || r[n.handle]?.length || (r[n.handle] = [n.message]);
1312
- }), r;
1313
- }
1314
- getRule(t, r) {
1315
- if (!t)
1316
- return !1;
1317
- const n = this.parseValidationRules(t.getAttribute("data-formie-validation"));
1318
- return Object.prototype.hasOwnProperty.call(n, r) ? n[r] : !1;
1319
- }
1320
- parseValidationRules(t) {
1321
- const r = {};
1322
- if (!t)
1323
- return r;
1324
- let n = null;
1325
- try {
1326
- n = JSON.parse(t);
1327
- } catch {
1328
- return K.warn("Invalid validation rules payload.", {
1329
- formId: this.form.id || null
1330
- }), r;
1331
- }
1332
- return Array.isArray(n) && n.forEach((i) => {
1333
- if (!i || typeof i != "object" || Array.isArray(i))
1334
- return;
1335
- const o = i, a = typeof o.type == "string" ? o.type.trim() : "";
1336
- a && (r[a] = o);
1337
- }), r;
1338
- }
1339
- destroy() {
1340
- K.log("Destroying validator.", {
1341
- formId: this.form.id || null
1342
- }), this.removeEventListeners(), this.form.removeAttribute("novalidate"), this.emitEvent(document, pe("destroy"), {
1343
- validator: this
1344
- });
1345
- }
1346
- isVisible(t, r = {}) {
1347
- return t.closest("[data-formie-conditionally-hidden]") ? !1 : t.closest("[data-formie-page-hidden]") ? !!r.includeHiddenPages : !!(t.offsetWidth || t.offsetHeight || t.getClientRects().length);
1348
- }
1349
- blurHandler(t) {
1350
- !(t.target instanceof HTMLElement) || !oe(t.target) || !t.target.form?.isSameNode(this.form) || t instanceof CustomEvent || t.target instanceof HTMLInputElement && t.target.type === "file" || t.target instanceof HTMLInputElement && (t.target.type === "checkbox" || t.target.type === "radio") || (this.isDirty(t.target) && this.activated.add(t.target), this.shouldShowError(t.target) && this.validate(t.target));
1351
- }
1352
- changeHandler(t) {
1353
- if (!(!(t.target instanceof HTMLElement) || !oe(t.target) || !t.target.form?.isSameNode(this.form)) && !(t instanceof CustomEvent)) {
1354
- if (t.target instanceof HTMLSelectElement) {
1355
- this.activated.add(t.target), this.validate(t.target);
1356
- return;
1357
- }
1358
- t.target instanceof HTMLInputElement && (t.target.type !== "file" && t.target.type !== "checkbox" && t.target.type !== "radio" || (this.activated.add(t.target), this.validate(t.target)));
1359
- }
1360
- }
1361
- inputHandler(t) {
1362
- !(t.target instanceof HTMLElement) || !oe(t.target) || !t.target.form?.isSameNode(this.form) || t instanceof CustomEvent || t.target instanceof HTMLInputElement && (t.target.type === "checkbox" || t.target.type === "radio") || this.shouldShowError(t.target) && this.validate(t.target);
1363
- }
1364
- submit(t = null, { final: r = !1 } = {}) {
1365
- return this.submitted = !0, K.log("Submit validation requested.", {
1366
- final: r
1367
- }), this.boundListeners || this.addEventListeners(), this.removeAllErrors(), this.validate(t, {
1368
- includeHiddenPages: r
1369
- });
1370
- }
1371
- resetLiveState() {
1372
- this.submitted = !1, this.activated = /* @__PURE__ */ new WeakSet(), this.errors = [], this.removeAllErrors();
1373
- }
1374
- addEventListeners() {
1375
- this.boundListeners || (this.form.addEventListener("blur", this.onBlur, !0), this.form.addEventListener("change", this.onChange, !1), this.form.addEventListener("input", this.onInput, !1), this.boundListeners = !0, K.log("Event listeners attached."));
1376
- }
1377
- removeEventListeners() {
1378
- this.form.removeEventListener("blur", this.onBlur, !0), this.form.removeEventListener("change", this.onChange, !1), this.form.removeEventListener("input", this.onInput, !1), this.boundListeners = !1, K.log("Event listeners removed.");
1379
- }
1380
- emitEvent(t, r, n = {}) {
1381
- t.dispatchEvent(new CustomEvent(r, {
1382
- bubbles: !0,
1383
- detail: n
1384
- }));
1385
- }
1386
- addValidator(t, r, n) {
1387
- this.validators[t] = {
1388
- validate: r,
1389
- errorMessage: n
1390
- };
1391
- }
1392
- removeValidator(t) {
1393
- delete this.validators[t];
1394
- }
1395
- }
1396
- const he = "data-formie-submit-validation-disabled", He = "data-formie-preserve-disabled", Bn = "data-formie-submit-ready";
1397
- function or(e) {
1398
- return e.dataset.formieDisableSubmitUntilValid === "true";
1399
- }
1400
- function jn(e) {
1401
- return Array.from(e.querySelectorAll('button[data-formie-action="submit"]')).filter((t) => t instanceof HTMLButtonElement);
1402
- }
1403
- function zn(e) {
1404
- return !e.hasAttribute("data-formie-conditionally-hidden") && !e.closest("[data-formie-conditionally-hidden]");
1405
- }
1406
- function at(e, t) {
1407
- if (!or(e) || e.getAttribute("data-formie-loading") === "true")
1408
- return;
1409
- const { scope: r, final: n } = Zt(e), i = t.isValid(r, {
1410
- includeHiddenPages: n
1411
- });
1412
- e.setAttribute(Bn, i ? "true" : "false"), jn(e).forEach((o) => {
1413
- if (zn(o)) {
1414
- if (i) {
1415
- if (!o.hasAttribute(he))
1416
- return;
1417
- o.hasAttribute(He) ? (o.disabled = !0, o.removeAttribute(He)) : o.disabled = !1, o.removeAttribute(he);
1418
- return;
1419
- }
1420
- o.hasAttribute(he) || (o.disabled && o.setAttribute(He, "true"), o.setAttribute(he, "true")), o.disabled = !0;
1421
- }
1422
- });
1423
- }
1424
- function Wn(e, t, r) {
1425
- if (!or(e))
1426
- return () => {
1427
- };
1428
- let n = !1;
1429
- const i = () => {
1430
- n || (n = !0, queueMicrotask(() => {
1431
- n = !1, at(e, t);
1432
- }));
1433
- };
1434
- i();
1435
- const o = () => {
1436
- i();
1437
- };
1438
- e.addEventListener("input", o, !0), e.addEventListener("change", o, !0);
1439
- const a = () => {
1440
- window.setTimeout(() => {
1441
- i();
1442
- }, 0);
1443
- };
1444
- e.addEventListener("reset", a);
1445
- const s = () => {
1446
- i();
1447
- };
1448
- r.addEventListener("formie:conditions:evaluated", s);
1449
- const l = new MutationObserver((d) => {
1450
- d.some((h) => {
1451
- if (h.type === "attributes") {
1452
- const u = h.attributeName || "";
1453
- return u === "data-formie-page-hidden" || u === "data-formie-conditionally-hidden" || u === "data-formie-loading" || u === "disabled";
1454
- }
1455
- return h.type === "childList";
1456
- }) && i();
1457
- });
1458
- return l.observe(e, {
1459
- childList: !0,
1460
- subtree: !0,
1461
- attributes: !0,
1462
- attributeFilter: [
1463
- "data-formie-page-hidden",
1464
- "data-formie-conditionally-hidden",
1465
- "data-formie-loading",
1466
- "disabled"
1467
- ]
1468
- }), () => {
1469
- e.removeEventListener("input", o, !0), e.removeEventListener("change", o, !0), e.removeEventListener("reset", a), r.removeEventListener("formie:conditions:evaluated", s), l.disconnect();
1470
- };
1471
- }
1472
- const Kn = "STALE_SUBMISSION_STATE", St = /* @__PURE__ */ new WeakMap(), Te = /* @__PURE__ */ new WeakMap(), j = _("general", "submit-result");
1473
- function ze(e, t, r) {
1474
- let n = e.querySelector(`input[name="${t}"]`);
1475
- n || (n = document.createElement("input"), n.type = "hidden", n.name = t, e.appendChild(n)), n.value = r;
1476
- }
1477
- function At(e, t) {
1478
- e.setAttribute("data-formie-internal-navigation", t);
1479
- }
1480
- function ae(e, t) {
1481
- e.querySelector(`input[name="${t}"]`)?.remove();
1482
- }
1483
- function Gn(e, t) {
1484
- try {
1485
- const r = new URL(e, window.location.href);
1486
- return r.searchParams.delete(t), r.toString();
1487
- } catch {
1488
- return e;
1489
- }
1490
- }
1491
- function Jn(e) {
1492
- try {
1493
- return new URL(e, window.location.href).origin === window.location.origin;
1494
- } catch {
1495
- return !1;
1496
- }
1497
- }
1498
- function ar(e) {
1499
- return Array.from(e.querySelectorAll("[data-formie-page]"));
1500
- }
1501
- function Yn(e) {
1502
- return Array.from(e.querySelectorAll("[data-formie-tab]"));
1503
- }
1504
- function Zn(e, t, r) {
1505
- return t < 0 || r < 1 ? 0 : (e.dataset.formieProgressCalculation === "page-position" ? "page-position" : "completion") === "page-position" ? Math.round((t + 1) / r * 100) : Math.round(t / r * 100);
1506
- }
1507
- function Qn(e) {
1508
- return e <= 0 ? "start" : e >= 100 ? "end" : "middle";
1509
- }
1510
- function Xn(e) {
1511
- return (e.dataset.formieSubmitAction || "").trim();
1512
- }
1513
- function wt(e, t) {
1514
- const r = t.meta?.effectiveSubmitAction;
1515
- return typeof r == "string" && r.trim() !== "" ? r.trim() : Xn(e);
1516
- }
1517
- function Tt(e) {
1518
- const t = e.dataset.formieSubmitActionFormHide;
1519
- if (t === void 0)
1520
- return !1;
1521
- const r = t.trim().toLowerCase();
1522
- return r === "true" || r === "1" || r === "";
1523
- }
1524
- function st(e, t) {
1525
- const r = [
1526
- "[data-formie-form-header]",
1527
- "[data-formie-form-navigation]",
1528
- "[data-formie-form-body]",
1529
- "[data-formie-form-footer]"
1530
- ];
1531
- e.toggleAttribute("data-formie-form-hidden", t), r.forEach((n) => {
1532
- e.querySelectorAll(n).forEach((i) => {
1533
- const o = i;
1534
- t ? o.hidden = !0 : o.hidden = !1;
1535
- });
1536
- });
1537
- }
1538
- function B(e) {
1539
- const t = St.get(e);
1540
- typeof t == "number" && (window.clearTimeout(t), St.delete(e));
1541
- }
1542
- function ei(e, t) {
1543
- Te.has(e) || Te.set(e, e.innerHTML), e.textContent = t;
1544
- }
1545
- function We(e) {
1546
- const t = Te.get(e);
1547
- t !== void 0 && (e.innerHTML = t, Te.delete(e));
1548
- }
1549
- function ti(e, t) {
1550
- const r = e.querySelector("[data-formie-progress-bar]"), n = e.querySelector("[data-formie-progress-value]");
1551
- r && (r.style.width = `${t}%`, r.setAttribute("aria-valuenow", `${t}`), r.setAttribute("data-formie-progress-state", Qn(t)), n && (n.textContent = `${t}%`, n.setAttribute("data-formie-progress-value", `${t}`)));
1552
- }
1553
- function ri(e, t) {
1554
- if (!t)
1555
- return;
1556
- const r = (e.dataset.formieLoadingIndicator || "").trim();
1557
- if (r) {
1558
- if (t.setAttribute("data-formie-loading-indicator", r), r === "spinner") {
1559
- ue(t, e, "loading", !0), We(t), t.removeAttribute("data-formie-loading-text");
1560
- return;
1561
- }
1562
- if (r === "text") {
1563
- const n = (e.dataset.formieLoadingIndicatorText || "").trim(), i = t.textContent?.trim() || "", o = n || i;
1564
- t.setAttribute("data-formie-loading-text", o), ei(t, o);
1565
- return;
1566
- }
1567
- We(t), t.removeAttribute("data-formie-loading-text");
1568
- }
1569
- }
1570
- function sr(e) {
1571
- return Array.from(e.querySelectorAll("[data-formie-action]"));
1572
- }
1573
- function lr(e, t) {
1574
- if (e.getAttribute("data-formie-loading") === "true")
1575
- return;
1576
- e.setAttribute("data-formie-loading", "true"), sr(e).forEach((n) => {
1577
- "disabled" in n && (n.disabled ? n.setAttribute("data-formie-was-disabled", "true") : n.removeAttribute("data-formie-was-disabled"), n.disabled = !0);
1578
- }), t && (t.setAttribute("data-formie-loading", "true"), ri(e, t));
1579
- }
1580
- function Me(e) {
1581
- if (e.removeAttribute("data-formie-loading"), sr(e).forEach((r) => {
1582
- if ("disabled" in r) {
1583
- const n = r, i = n.getAttribute("data-formie-was-disabled") === "true";
1584
- n.disabled = i;
1585
- }
1586
- We(r), r.removeAttribute("data-formie-was-disabled"), r.removeAttribute("data-formie-loading"), ue(r, e, "loading", !1), r.removeAttribute("data-formie-loading-indicator"), r.removeAttribute("data-formie-loading-text");
1587
- }), e.dataset.formieDisableSubmitUntilValid === "true") {
1588
- const r = e;
1589
- r.formieValidation && at(e, r.formieValidation);
1590
- }
1591
- }
1592
- function lt(e, t) {
1593
- const r = ar(e), n = Yn(e), i = r.findIndex((o) => o.getAttribute("data-formie-page-id") === t);
1594
- if (r.forEach((o) => {
1595
- o.getAttribute("data-formie-page-id") === t ? (o.removeAttribute("data-formie-page-hidden"), le(o, e, "pageHidden")) : (o.setAttribute("data-formie-page-hidden", "true"), O(o, e, "pageHidden"));
1596
- }), n.forEach((o, a) => {
1597
- const s = o.getAttribute("data-formie-page-id") === t, l = i > -1 && a < i;
1598
- ue(o, e, "tabCurrent", s), ue(o, e, "tabComplete", l), s ? o.setAttribute("aria-current", "page") : o.removeAttribute("aria-current"), l ? o.setAttribute("data-formie-tab-complete", "true") : o.removeAttribute("data-formie-tab-complete");
1599
- }), i > -1 && r.length > 0) {
1600
- const o = Zn(e, i, r.length);
1601
- ti(e, o);
1602
- }
1603
- if (ze(e, "pageId", t), J(e), e.dataset.formieDisableSubmitUntilValid === "true") {
1604
- const o = e;
1605
- o.formieValidation && at(e, o.formieValidation);
1606
- }
1607
- }
1608
- function ni(e, t) {
1609
- const r = t.meta?.submissionUid;
1610
- typeof r == "string" && r.trim() !== "" && ze(e, "submissionUid", r);
1611
- const n = t.meta?.session?.continuation?.continuationToken;
1612
- typeof n == "string" && n.trim() !== "" ? ze(e, "continuationToken", n) : ae(e, "continuationToken");
1613
- }
1614
- function ii(e) {
1615
- const t = e.getAttribute("action");
1616
- t && e.setAttribute("action", Gn(t, "resumeToken"));
1617
- try {
1618
- const r = new URL(window.location.href);
1619
- if (!r.searchParams.has("resumeToken"))
1620
- return;
1621
- r.searchParams.delete("resumeToken"), window.history.replaceState({}, document.title, `${r.pathname}${r.search}${r.hash}`);
1622
- } catch {
1623
- }
1624
- }
1625
- function oi(e, t) {
1626
- const r = t.meta?.resumeUrl;
1627
- if (typeof r != "string" || r.trim() === "")
1628
- return;
1629
- const n = r.trim();
1630
- if (!Jn(n))
1631
- return;
1632
- e.getAttribute("action") && e.setAttribute("action", n);
1633
- try {
1634
- const o = new URL(n, window.location.href);
1635
- window.history.replaceState({}, document.title, `${o.pathname}${o.search}${o.hash}`);
1636
- } catch {
1637
- }
1638
- }
1639
- function be(e, t = {}) {
1640
- const n = e.formieValidation, i = ar(e)[0]?.getAttribute("data-formie-page-id");
1641
- if (B(e), e.reset(), t.preserveHiddenState || st(e, !1), ae(e, "submissionId"), ae(e, "submissionUid"), ae(e, "continuationToken"), ae(e, "pageId"), ii(e), n?.resetLiveState(), i) {
1642
- lt(e, i), e.dispatchEvent(new CustomEvent(je("reset"), { bubbles: !0 }));
1643
- return;
1644
- }
1645
- J(e), e.dispatchEvent(new CustomEvent(je("reset"), { bubbles: !0 }));
1646
- }
1647
- function ai(e) {
1648
- return e.code === Kn || e.meta?.resetState === !0;
1649
- }
1650
- function si(e, t) {
1651
- const r = t.submitData, n = /* @__PURE__ */ new Set();
1652
- let i = !1;
1653
- if (Array.isArray(r) && r.length > 0) {
1654
- const p = r.filter(
1655
- (h) => typeof h == "object" && h !== null && "event" in h && typeof h.event == "string"
1656
- );
1657
- for (const h of p) {
1658
- const u = h.event;
1659
- n.add(u), j.log("Dispatching submitData event.", {
1660
- eventName: u
1661
- }), u.startsWith("formie:payment:") && (i = !0), e.dispatchEvent(new CustomEvent(u, {
1662
- bubbles: !0,
1663
- detail: { data: h.data }
1664
- }));
1665
- }
1666
- }
1667
- const o = t.meta || {}, a = (o.paymentAction && typeof o.paymentAction == "object" ? o.paymentAction : null) || (o.paymentDecision && typeof o.paymentDecision == "object" ? o.paymentDecision.action : null), s = a ? String(a.event || "") : "", l = a ? a.payload : void 0, d = s;
1668
- return d && !n.has(d) && (d.startsWith("formie:payment:") && (i = !0), e.dispatchEvent(new CustomEvent(d, {
1669
- bubbles: !0,
1670
- detail: { data: l }
1671
- })), j.log("Dispatching fallback payment action event.", {
1672
- eventName: d
1673
- })), { hasPaymentFollowUpEvent: i };
1674
- }
1675
- function li(e, t, r) {
1676
- if (j.log("Applying submit result state.", {
1677
- ok: t.ok,
1678
- action: r,
1679
- code: t.code,
1680
- hasRedirect: !!t.redirect?.url,
1681
- hasSubmitData: Array.isArray(t.submitData) && t.submitData.length > 0
1682
- }), ai(t)) {
1683
- be(e), j.log("Resetting state due to stale/reset marker.");
1684
- return;
1685
- }
1686
- const n = si(e, t);
1687
- if (!t.ok && t.redirect?.url && !n.hasPaymentFollowUpEvent) {
1688
- j.log("Applying redirect fallback for failed result.", {
1689
- url: t.redirect.url,
1690
- target: t.redirect.target
1691
- }), B(e), t.redirect.target === "new-tab" ? window.open(t.redirect.url, "_blank") : (At(e, "redirect"), window.location.href = t.redirect.url);
1692
- return;
1693
- }
1694
- if (ni(e, t), !t.ok) {
1695
- j.log("Non-redirect failure; keeping current form state."), B(e);
1696
- return;
1697
- }
1698
- if (Kt(e, r), t.nextPage?.id) {
1699
- B(e), e.formieValidation?.resetLiveState(), lt(e, t.nextPage.id), j.log("Advanced to next page.", {
1700
- nextPageId: t.nextPage.id
1701
- });
1702
- return;
1703
- }
1704
- if (r === "save") {
1705
- B(e), oi(e, t), j.log("Applied save/resume token state.");
1706
- return;
1707
- }
1708
- if (r === "submit" && !t.redirect?.url) {
1709
- const i = wt(e, t), o = i === "message" && Tt(e);
1710
- if (i === "reload") {
1711
- B(e), At(e, "reload"), window.location.reload();
1712
- return;
1713
- }
1714
- if (i === "reset") {
1715
- be(e);
1716
- return;
1717
- }
1718
- B(e), be(e, { preserveHiddenState: o });
1719
- return;
1720
- }
1721
- if (r === "submit" && t.redirect?.url && t.redirect.target === "new-tab") {
1722
- const o = wt(e, t) === "message" && Tt(e);
1723
- B(e), be(e, { preserveHiddenState: o });
1724
- return;
1725
- }
1726
- B(e);
1727
- }
1728
- const Ce = /* @__PURE__ */ new WeakMap();
1729
- function ur(e) {
1730
- return (e.dataset.formieSubmitAction || "").trim();
1731
- }
1732
- function ui(e) {
1733
- return (e.dataset.formieErrorMessagePosition || "top-form").trim() || "top-form";
1734
- }
1735
- function cr(e) {
1736
- return (e.dataset.formieSubmitActionMessagePosition || "").trim();
1737
- }
1738
- function ci(e) {
1739
- const t = (e.dataset.formieSubmitActionMessageTimeout || "").trim();
1740
- if (!t)
1741
- return null;
1742
- const r = Number.parseFloat(t);
1743
- return !Number.isFinite(r) || r < 0 ? null : Math.round(r * 1e3);
1744
- }
1745
- function ut(e) {
1746
- const t = e.dataset.formieSubmitActionFormHide;
1747
- if (t === void 0)
1748
- return !1;
1749
- const r = t.trim().toLowerCase();
1750
- return r === "true" || r === "1" || r === "";
1751
- }
1752
- function di(e) {
1753
- const t = Ce.get(e);
1754
- typeof t == "number" && (window.clearTimeout(t), Ce.delete(e));
1755
- }
1756
- function dr(e) {
1757
- return e.querySelector("[data-formie-form-messages-top]") || e;
1758
- }
1759
- function fr(e) {
1760
- return e.querySelector("[data-formie-form-messages-bottom]") || e;
1761
- }
1762
- function fi(e, t) {
1763
- return t === "bottom-form" ? fr(e) : dr(e);
1764
- }
1765
- function mi(e, t) {
1766
- return t === "top-form" ? dr(e) : t === "bottom-form" && !ut(e) ? fr(e) : e;
1767
- }
1768
- function pi(e) {
1769
- const t = ui(e), r = fi(e, t);
1770
- let n = r.querySelector("[data-formie-error-container], [data-formie-errors]");
1771
- return n || (n = document.createElement("div"), n.setAttribute("data-formie-errors", "true"), O(n, e, "errors")), n.setAttribute("data-formie-error-container", "true"), t === "bottom-form" ? r.append(n) : r.prepend(n), n;
1772
- }
1773
- function gi(e, t) {
1774
- let r = t.querySelector("[data-formie-error-message-container], [data-formie-message][data-formie-message-error]");
1775
- return r || (r = document.createElement("div"), r.setAttribute("data-formie-error-message-container", "true"), t.appendChild(r)), r.setAttribute("data-formie-message", "true"), r.setAttribute("data-formie-message-error", "true"), O(r, e, "message", "messageError"), r.setAttribute("role", "alert"), r.setAttribute("aria-live", "polite"), r.setAttribute("aria-atomic", "true"), r;
1776
- }
1777
- function hi(e, t) {
1778
- let r = e.querySelector("[data-formie-success-container]");
1779
- const n = mi(e, t);
1780
- return r || (r = document.createElement("div"), r.setAttribute("data-formie-success-container", "true"), O(r, e, "successes")), t === "bottom-form" ? n.append(r) : n.prepend(r), r;
1781
- }
1782
- function bi(e) {
1783
- return rr(e, (t) => {
1784
- O(t, e, "fieldErrors");
1785
- });
1786
- }
1787
- function yi(e, t) {
1788
- const r = (e.getAttribute("aria-describedby") || "").trim();
1789
- if (!r)
1790
- return;
1791
- const n = r.split(/\s+/).filter((i) => i !== t).join(" ").trim();
1792
- if (n) {
1793
- e.setAttribute("aria-describedby", n);
1794
- return;
1795
- }
1796
- e.removeAttribute("aria-describedby");
1797
- }
1798
- function vi(e, t) {
1799
- e.setAttribute("aria-errormessage", t);
1800
- }
1801
- function Ei(e, t) {
1802
- e.getAttribute("aria-errormessage") === t && e.removeAttribute("aria-errormessage");
1803
- }
1804
- function mr(e) {
1805
- e.querySelectorAll("[data-formie-field-handle]").forEach((t) => {
1806
- const r = t, n = r.querySelector("[data-formie-field-errors]"), i = n?.id || "", o = Array.from(r.querySelectorAll("[data-formie-field-error]")).map((a) => a.id).filter(Boolean);
1807
- le(r, e, "fieldLayoutError"), r.removeAttribute("data-formie-field-has-error"), r.querySelectorAll("[data-formie-field-error]").forEach((a) => {
1808
- a.remove();
1809
- }), n && !n.querySelector("[data-formie-field-error]") && (n.innerHTML = ""), r.querySelectorAll("input, select, textarea").forEach((a) => {
1810
- const s = a;
1811
- s.removeAttribute("aria-invalid"), le(s, e, "fieldControlError"), s.removeAttribute("data-formie-input-has-error"), i && yi(s, i), o.forEach((l) => {
1812
- Ei(s, l);
1813
- });
1814
- });
1815
- }), J(e);
1816
- }
1817
- function pr(e) {
1818
- e.querySelectorAll("[data-formie-error-container], [data-formie-errors]").forEach((t) => {
1819
- const r = t;
1820
- r.querySelectorAll("[data-formie-error]").forEach((n) => {
1821
- n.remove();
1822
- }), le(r, e, "message", "messageError"), r.removeAttribute("data-formie-message"), r.removeAttribute("data-formie-message-error"), r.removeAttribute("role"), r.removeAttribute("aria-live"), r.removeAttribute("aria-atomic"), r.querySelector("[data-formie-error]") || (r.innerHTML = "");
1823
- });
1824
- }
1825
- function ct(e) {
1826
- di(e), e.querySelectorAll("[data-formie-message-success]:not([data-formie-success-container])").forEach((t) => {
1827
- t.remove();
1828
- }), e.querySelectorAll("[data-formie-success-container]").forEach((t) => {
1829
- const r = t;
1830
- r.querySelectorAll("[data-formie-success]").forEach((n) => {
1831
- n.remove();
1832
- }), le(r, e, "message", "messageSuccess"), r.removeAttribute("data-formie-message"), r.removeAttribute("data-formie-message-success"), r.removeAttribute("role"), r.removeAttribute("aria-live"), r.removeAttribute("aria-atomic"), r.querySelector("[data-formie-success]") || (r.innerHTML = "");
1833
- }), ur(e) === "message" && ut(e) || st(e, !1);
1834
- }
1835
- function gr(e) {
1836
- e.querySelectorAll('[aria-invalid="true"]').forEach((t) => {
1837
- t.removeAttribute("aria-invalid");
1838
- });
1839
- }
1840
- function Mt(e, t) {
1841
- const r = (e.getAttribute("aria-describedby") || "").trim(), n = r ? r.split(/\s+/) : [];
1842
- n.includes(t) || n.push(t), e.setAttribute("aria-describedby", n.join(" ").trim());
1843
- }
1844
- function Si(e, t) {
1845
- Object.entries(t).forEach(([r, n]) => {
1846
- const i = e.querySelector(`[data-formie-field-handle="${r}"]`);
1847
- if (!i)
1848
- return;
1849
- const o = bi(i), a = o.id && o.id.trim() ? o.id : `${r}-errors`;
1850
- o.id = a, o.setAttribute("aria-live", "polite"), o.setAttribute("aria-atomic", "true"), O(i, e, "fieldLayoutError"), i.setAttribute("data-formie-field-has-error", "true"), n.forEach((l, d) => {
1851
- const p = document.createElement("div");
1852
- p.setAttribute("data-formie-field-error", "true"), p.setAttribute("role", "alert"), p.id = `${a}-${d + 1}`, O(p, e, "fieldError"), p.textContent = l, o.appendChild(p);
1853
- });
1854
- const s = o.querySelector("[data-formie-field-error]")?.id;
1855
- i.querySelectorAll("input, select, textarea").forEach((l) => {
1856
- const d = l;
1857
- d.setAttribute("aria-invalid", "true"), O(d, e, "fieldControlError"), d.setAttribute("data-formie-input-has-error", "true"), Mt(d, a), s && vi(d, s);
1858
- const p = i.querySelector("[data-formie-instructions]");
1859
- p?.id && Mt(d, p.id);
1860
- });
1861
- }), J(e);
1862
- }
1863
- function Ct(e, t) {
1864
- const r = pi(e), n = gi(e, r);
1865
- O(r, e, "errors"), t.forEach((i) => {
1866
- const o = document.createElement("div");
1867
- o.setAttribute("data-formie-error", "true"), o.setAttribute("role", "alert"), O(o, e, "error"), o.innerHTML = i, n.appendChild(o);
1868
- });
1869
- }
1870
- function Ai(e, t) {
1871
- return !t.message || t.nextPage || t.redirect ? !1 : t.action === "save" ? !0 : ur(e) === "message" && cr(e) !== "";
1872
- }
1873
- function wi(e, t) {
1874
- const r = cr(e);
1875
- if (!r)
1876
- return;
1877
- const n = hi(e, r);
1878
- O(n, e, "message", "messageSuccess"), n.setAttribute("data-formie-message", "true"), n.setAttribute("data-formie-message-success", "true"), n.setAttribute("role", "status"), n.setAttribute("aria-live", "polite"), n.setAttribute("aria-atomic", "true");
1879
- const i = document.createElement("div");
1880
- i.setAttribute("data-formie-success", "true"), O(i, e, "success"), i.innerHTML = t, n.appendChild(i), ut(e) && st(e, !0);
1881
- const o = ci(e);
1882
- if (o !== null) {
1883
- const a = window.setTimeout(() => {
1884
- Ce.delete(e), ct(e);
1885
- }, o);
1886
- Ce.set(e, a);
1887
- }
1888
- }
1889
- function Le(e, t) {
1890
- if (mr(e), pr(e), ct(e), gr(e), t.ok) {
1891
- Ai(e, t) && wi(e, t.message || "");
1892
- return;
1893
- }
1894
- if (t.fieldErrors && Si(e, t.fieldErrors), t.formErrors?.length) {
1895
- Ct(e, t.formErrors);
1896
- return;
1897
- }
1898
- !t.fieldErrors && t.message && Ct(e, [t.message]);
1899
- }
1900
- const Ti = _("general", "submit-flow");
1901
- function Mi(e) {
1902
- return !(!e.ok && e.stage === "validate");
1903
- }
1904
- function hr(e) {
1905
- return e ? !!(e.keepSubmitLoading === !0 || e.ok && e.redirect?.url && e.redirect.target !== "new-tab") : !1;
1906
- }
1907
- function br(e) {
1908
- mr(e), pr(e), ct(e), gr(e);
1909
- }
1910
- async function yr(e) {
1911
- const {
1912
- id: t,
1913
- target: r,
1914
- form: n,
1915
- bus: i,
1916
- validator: o,
1917
- validateOnSubmit: a,
1918
- action: s,
1919
- submitter: l,
1920
- waitForSubmitDelay: d,
1921
- onRefreshTokensAfterSubmit: p,
1922
- dispatchSubmitResult: h
1923
- } = e;
1924
- br(n), lr(n, l || null);
1925
- let u = {
1926
- ok: !1,
1927
- code: "SUBMIT_ERROR",
1928
- message: "Submission failed.",
1929
- formErrors: ["Submission failed."]
1930
- };
1931
- try {
1932
- await d(n), u = await tr(n, s, i, {
1933
- validator: o,
1934
- validateOnSubmit: a
1935
- }), Le(n, u), li(n, u, s), Mi(u) && await p(u), h(u);
1936
- } catch (c) {
1937
- u = {
1938
- ok: !1,
1939
- code: "SUBMIT_ERROR",
1940
- message: c instanceof Error ? c.message : "Submission failed.",
1941
- formErrors: [c instanceof Error ? c.message : "Submission failed."]
1942
- }, Le(n, u), h(u), Ti.warn("Submit failed with exception.", {
1943
- id: t,
1944
- action: s,
1945
- target: r,
1946
- error: c instanceof Error ? c.message : c
1947
- });
1948
- } finally {
1949
- hr(u) || Me(n);
1950
- }
1951
- return u;
1952
- }
1953
- class vr {
1954
- constructor() {
1955
- this.modules = /* @__PURE__ */ new Map();
1956
- }
1957
- register(t, r = {}) {
1958
- const n = this.modules.get(t.id);
1959
- return n === t ? !0 : n && !r.replace ? (console.warn(
1960
- `[formie] Module "${t.id}" is already registered. Pass { replace: true } to override the existing definition.`
1961
- ), !1) : (this.modules.set(t.id, t), !0);
1962
- }
1963
- unregister(t) {
1964
- this.modules.delete(t);
1965
- }
1966
- get(t) {
1967
- return this.modules.get(t) || null;
1968
- }
1969
- getAll() {
1970
- return Array.from(this.modules.values());
1971
- }
1972
- }
1973
- const Ci = {
1974
- // Address providers stay behind lazy importer entries because their SDKs are
1975
- // optional and often much heavier than the base form client.
1976
- "address-finder": () => import("./address-finder-BU4roxT6.js").then((e) => e.addressFinderModule),
1977
- "google-address": () => import("./google-address-BD8IZ86V.js").then((e) => e.googleAddressModule),
1978
- loqate: () => import("./loqate-B-ZNS65B.js").then((e) => e.loqateModule),
1979
- "place-kit": () => import("./place-kit-DizZWV_e.js").then((e) => e.placeKitModule)
1980
- }, Li = {
1981
- // Module ids map directly to importer functions so the loader can fetch only
1982
- // the captcha chunks required by the current form manifest.
1983
- "captcha-eu": () => import("./captcha-eu-BAPzHNts.js").then((e) => e.captchaEuModule),
1984
- "friendly-captcha-v1": () => import("./friendly-captcha-v1-DdlcGiFY.js").then((e) => e.friendlyCaptchaV1Module),
1985
- "friendly-captcha-v2": () => import("./friendly-captcha-v2-76w-YnFm.js").then((e) => e.friendlyCaptchaV2Module),
1986
- hcaptcha: () => import("./hcaptcha-BNNTL6uf.js").then((e) => e.hcaptchaModule),
1987
- "recaptcha-enterprise": () => import("./recaptcha-enterprise-BbOvO7JZ.js").then((e) => e.recaptchaEnterpriseModule),
1988
- "recaptcha-v2-checkbox": () => import("./recaptcha-v2-checkbox-SY3ti5iQ.js").then((e) => e.recaptchaV2CheckboxModule),
1989
- "recaptcha-v2-invisible": () => import("./recaptcha-v2-invisible-DSmQnn6c.js").then((e) => e.recaptchaV2InvisibleModule),
1990
- "recaptcha-v3": () => import("./recaptcha-v3-DNh7YCnR.js").then((e) => e.recaptchaV3Module),
1991
- snaptcha: () => import("./snaptcha-VuOUOaLj.js").then((e) => e.snaptchaModule),
1992
- turnstile: () => import("./turnstile-9tM7q_LK.js").then((e) => e.turnstileModule)
1993
- }, Ii = {
1994
- // Keep the builtin map flat and explicit so manifest ids remain the source of
1995
- // truth for lazy-loading first-party field enhancements.
1996
- calculations: () => import("./calculations-C9t6Zop9.js").then((e) => e.calculationsModule),
1997
- "checkbox-radio": () => import("./checkbox-radio-CHeLNVIK.js").then((e) => e.checkboxRadioModule),
1998
- conditions: () => import("./conditions-DKxVCsjD.js").then((e) => e.conditionsModule),
1999
- "date-picker": () => import("./date-picker-B3iQ797Z.js").then((e) => e.datePickerModule),
2000
- "file-upload": () => import("./file-upload-DP2TOUYV.js").then((e) => e.fileUploadModule),
2001
- hidden: () => import("./hidden-CW6Rcf1N.js").then((e) => e.hiddenModule),
2002
- "phone-country": () => import("./phone-country-Cm5YUeXI.js").then((e) => e.phoneCountryModule),
2003
- repeater: () => import("./repeater-DM0vuFNQ.js").then((e) => e.repeaterModule),
2004
- "rich-text": () => import("./rich-text-C8aGYp70.js").then((e) => e.richTextModule),
2005
- signature: () => import("./signature-pFhZfH7d.js").then((e) => e.signatureModule),
2006
- summary: () => import("./summary-Da7Ktg3N.js").then((e) => e.summaryModule),
2007
- table: () => import("./table-C0PmR9bI.js").then((e) => e.tableModule),
2008
- "text-limit": () => import("./text-limit-mLEwZDIa.js").then((e) => e.textLimitModule)
2009
- }, Ri = {
2010
- // Keep payment providers lazy and separately addressable so forms only ship
2011
- // the payment SDK wrapper code they actually declare in their manifest.
2012
- bpoint: () => import("./bpoint-uNg5j6rt.js").then((e) => e.bpointModule),
2013
- eway: () => import("./eway-DCielIML.js").then((e) => e.ewayModule),
2014
- "go-cardless": () => import("./go-cardless-rwCkzbNK.js").then((e) => e.goCardlessModule),
2015
- mollie: () => import("./mollie-BDAZ-1X4.js").then((e) => e.mollieModule),
2016
- moneris: () => import("./moneris-B1b0uEtY.js").then((e) => e.monerisModule),
2017
- opayo: () => import("./opayo-CC5hraHo.js").then((e) => e.opayoModule),
2018
- paddle: () => import("./paddle-B4GmrDsq.js").then((e) => e.paddleModule),
2019
- paypal: () => import("./paypal-BFS6XsIS.js").then((e) => e.paypalModule),
2020
- payway: () => import("./payway-DekoJead.js").then((e) => e.paywayModule),
2021
- square: () => import("./square-BR9pvToy.js").then((e) => e.squareModule),
2022
- stripe: () => import("./stripe-OHUwoV9g.js").then((e) => e.stripeModule)
2023
- }, Fi = {
2024
- ...Ii,
2025
- ...Ci,
2026
- ...Li,
2027
- ...Ri
2028
- }, _e = /* @__PURE__ */ new Map(), D = _("general", "loader"), ki = new Function("src", "return import(src);");
2029
- async function ye(e, t, r, n) {
2030
- await e(Br(r), n), await e(Ur(t, r), n);
2031
- }
2032
- function Er(e) {
2033
- return !!e && typeof e == "object" && typeof e.id == "string" && typeof e.setup == "function" && typeof e.match == "function";
2034
- }
2035
- async function Pi(e, t) {
2036
- const r = Fi[e];
2037
- return r ? (_e.has(e) || _e.set(e, (async () => {
2038
- try {
2039
- const n = await r();
2040
- return Er(n) ? (t.registry.register(n), n) : null;
2041
- } catch (n) {
2042
- return console.error("[formie] Failed to load builtin module:", e, n), D.warn("Failed loading builtin module.", { moduleId: e, error: n }), null;
2043
- }
2044
- })()), _e.get(e) || null) : null;
2045
- }
2046
- async function qi(e) {
2047
- try {
2048
- const t = await ki(e), r = t?.default || t?.formieModule || null;
2049
- return Er(r) ? r : null;
2050
- } catch (t) {
2051
- return console.error("[formie] Failed to load module from src:", e, t), D.warn("Failed loading module from src.", { src: e, error: t }), null;
2052
- }
2053
- }
2054
- async function Vi(e, t) {
2055
- const r = t.registry.get(e.id);
2056
- if (r)
2057
- return r;
2058
- const n = await Pi(e.id, t);
2059
- if (n)
2060
- return n;
2061
- if (e.src) {
2062
- const i = await qi(e.src);
2063
- if (i)
2064
- return t.registry.register(i), i;
2065
- }
2066
- return null;
2067
- }
2068
- function De(e) {
2069
- return typeof window.CSS?.escape == "function" ? window.CSS.escape(e) : e.replace(/["\\]/g, "\\$&");
2070
- }
2071
- function ve(e, t) {
2072
- return e.matches(t) ? [e, ...Array.from(e.querySelectorAll(t))] : Array.from(e.querySelectorAll(t));
2073
- }
2074
- function Oi(e, t) {
2075
- const r = t.setupContext.root, n = t.setupContext.form, i = e.targetType, o = e.targetId;
2076
- return i === "selector" ? ve(r, o).map((a) => ({ scope: i, element: a })) : i === "field" ? ve(r, `[data-formie-field-handle="${De(o)}"]`).map((a) => ({ scope: i, element: a })) : i === "page" ? ve(r, `[data-formie-page-id="${De(o)}"]`).map((a) => ({ scope: i, element: a })) : i === "button" ? ve(r, `[data-formie-action="${De(o)}"]`).map((a) => ({ scope: i, element: a })) : [{
2077
- scope: "form",
2078
- element: n || r
2079
- }];
2080
- }
2081
- function $i(e, t) {
2082
- return (e.targets && e.targets.length > 0 ? e.targets : [{
2083
- targetType: "form",
2084
- targetId: "form"
2085
- }]).flatMap((n) => Oi(n, t));
2086
- }
2087
- async function Sr(e, t) {
2088
- const r = [];
2089
- D.log("Loading module manifest.", {
2090
- manifestCount: e.length
2091
- });
2092
- for (const n of e) {
2093
- const i = await Vi(n, t);
2094
- if (!i) {
2095
- D.warn("Skipping manifest item (definition not resolved).", {
2096
- moduleId: n.id,
2097
- src: n.src
2098
- });
2099
- continue;
2100
- }
2101
- const o = $i(n, t);
2102
- D.log("Resolved module targets.", {
2103
- moduleId: i.id,
2104
- targets: n.targets || [],
2105
- targetCount: o.length
2106
- }), o.length === 0 && i.kind === "address" && console.warn(
2107
- `[formie] Address module "${n.id}" skipped: no target element found for fieldHandle="${n.targets?.find((a) => a.targetType === "field")?.targetId ?? "?"}". Check that the Address field exists in the rendered form.`
2108
- );
2109
- for (const a of o) {
2110
- const s = {
2111
- ...t.matchContext,
2112
- target: a.element,
2113
- scope: a.scope,
2114
- manifestItem: n
2115
- };
2116
- if (!i.match(s)) {
2117
- i.kind === "address" && console.warn(
2118
- `[formie] Address module "${i.id}" skipped: target element does not contain [data-formie-address-autocomplete-input]. Enable the Auto-Complete subfield.`
2119
- ), D.log("Module target did not match predicate.", {
2120
- moduleId: i.id,
2121
- scope: a.scope
2122
- });
2123
- continue;
2124
- }
2125
- const l = n.config || t.setupContext.options, d = i.id, p = {
2126
- moduleId: i.id,
2127
- moduleKind: i.kind,
2128
- target: a.element,
2129
- scope: a.scope,
2130
- options: l,
2131
- manifestItem: n
2132
- };
2133
- await ye(t.setupContext.emit, d, "before-setup", p);
2134
- let h = null;
2135
- try {
2136
- const u = await i.setup({
2137
- ...t.setupContext,
2138
- target: a.element,
2139
- scope: a.scope,
2140
- options: l
2141
- });
2142
- u && (h = u);
2143
- } catch (u) {
2144
- console.error(`[formie] Module "${i.id}" setup failed:`, u), D.warn("Module setup failed.", {
2145
- moduleId: i.id,
2146
- scope: a.scope,
2147
- error: u
2148
- });
2149
- }
2150
- await ye(t.setupContext.emit, d, "after-setup", {
2151
- ...p,
2152
- instanceCreated: !!h
2153
- }), h && (D.log("Module instance created.", {
2154
- moduleId: i.id,
2155
- scope: a.scope
2156
- }), r.push({
2157
- ...h,
2158
- destroy: async () => {
2159
- D.log("Destroying module instance.", {
2160
- moduleId: i.id,
2161
- scope: a.scope
2162
- }), await ye(t.setupContext.emit, d, "before-destroy", p), await h.destroy(), await ye(t.setupContext.emit, d, "after-destroy", p), D.log("Module instance destroyed.", {
2163
- moduleId: i.id,
2164
- scope: a.scope
2165
- });
2166
- }
2167
- }));
2168
- }
2169
- }
2170
- return D.log("Module manifest processing complete.", {
2171
- instanceCount: r.length
2172
- }), r;
2173
- }
2174
- const Hi = /* @__PURE__ */ new Set([
2175
- "CRAFT_CSRF_TOKEN",
2176
- "action",
2177
- "redirect",
2178
- "requestToken",
2179
- "renderId",
2180
- "submitAction",
2181
- "pageId",
2182
- "draftContextToken",
2183
- "draftContext",
2184
- "continuationToken"
2185
- ]);
2186
- function Ke(e, t) {
2187
- if (e == null)
2188
- return String(e);
2189
- if (typeof e == "string")
2190
- return JSON.stringify(e);
2191
- if (typeof e == "number" || typeof e == "boolean")
2192
- return String(e);
2193
- if (typeof e == "function")
2194
- return "[function]";
2195
- if (typeof File < "u" && e instanceof File)
2196
- return `[file:${e.name}:${e.size}:${e.type}]`;
2197
- if (typeof Blob < "u" && e instanceof Blob)
2198
- return `[blob:${e.size}:${e.type}]`;
2199
- if (Array.isArray(e))
2200
- return `[${e.map((r) => Ke(r, t)).join(",")}]`;
2201
- if (typeof e == "object") {
2202
- if (t.has(e))
2203
- return "[circular]";
2204
- t.add(e);
2205
- const r = Object.entries(e).sort(([n], [i]) => n.localeCompare(i)).map(([n, i]) => `${JSON.stringify(n)}:${Ke(i, t)}`);
2206
- return t.delete(e), `{${r.join(",")}}`;
2207
- }
2208
- return JSON.stringify(String(e));
2209
- }
2210
- function _i(e) {
2211
- return Ke(e, /* @__PURE__ */ new WeakSet());
2212
- }
2213
- function Di(e) {
2214
- if (!e)
2215
- return !1;
2216
- const t = e.endsWith("[]") ? e.slice(0, -2) : e;
2217
- return !Hi.has(t);
2218
- }
2219
- function Lt(e) {
2220
- const t = Array.from(new FormData(e).entries()).filter(([r]) => Di(String(r || "")));
2221
- return _i(t);
2222
- }
2223
- function xi(e, t = {}) {
2224
- let r = null, n = !1, i = !1, o = null, a = null, s = null;
2225
- const l = () => {
2226
- o !== null && (window.cancelAnimationFrame(o), o = null), a !== null && (window.clearTimeout(a), a = null), s !== null && (window.clearTimeout(s), s = null);
2227
- }, d = () => n ? (i = Lt(e) !== r, i) : !1, p = () => {
2228
- r = Lt(e), n = !0, i = !1;
2229
- }, h = () => {
2230
- l(), n = !1, o = window.requestAnimationFrame(() => {
2231
- o = null, s = window.setTimeout(() => {
2232
- s = null, p();
2233
- }, 0);
2234
- });
2235
- }, u = () => {
2236
- a !== null && window.clearTimeout(a), a = window.setTimeout(() => {
2237
- a = null, d();
2238
- }, 120);
2239
- }, c = (b) => {
2240
- t.shouldWarn && !t.shouldWarn() || d() && (b.preventDefault(), b.returnValue = "");
2241
- };
2242
- return e.addEventListener("input", u), e.addEventListener("change", u), window.addEventListener("beforeunload", c), h(), {
2243
- captureBaseline: p,
2244
- scheduleBaselineCapture: h,
2245
- refreshDirtyState: d,
2246
- destroy: () => {
2247
- l(), e.removeEventListener("input", u), e.removeEventListener("change", u), window.removeEventListener("beforeunload", c);
2248
- }
2249
- };
2250
- }
2251
- const X = '[data-formie]:not([data-formie-init="false"]), [data-formie-form]:not([data-formie-init="false"])', Ni = 300, Ui = "/actions/formie/server/forms/render", It = "/api", Bi = "/actions/formie/server/forms/refresh-tokens", ji = "/actions/formie/server/submissions/submit", zi = "/actions/formie/server/submissions/set-page", Wi = "/actions/formie/server/submissions/clear-submission", Ki = "/actions/formie/file-upload/hydrate", L = _("general", "client"), Rt = /* @__PURE__ */ new Set();
2252
- function ce(e, t) {
2253
- if (e == null || e === "")
2254
- return t;
2255
- const r = e.toLowerCase();
2256
- return !(r === "false" || r === "0" || r === "off");
2257
- }
2258
- function Ge(e) {
2259
- return e.formieRefreshTokens != null && e.formieRefreshTokens !== "" ? ce(e.formieRefreshTokens, !1) : e.formieStaticCache != null && e.formieStaticCache !== "" ? ce(e.formieStaticCache, !1) : !1;
2260
- }
2261
- function ee(e) {
2262
- const t = e instanceof HTMLElement ? e.dataset : {};
2263
- return {
2264
- mode: "server-rendered",
2265
- transport: t.formieTransport || "rest",
2266
- formHandle: t.formieHandle,
2267
- endpoint: t.formieEndpoint,
2268
- staticCache: Ge(t),
2269
- autoVisible: ce(t.formieAutoVisible, !0),
2270
- compatibility: ce(t.formieCompatibility, !1)
2271
- };
2272
- }
2273
- function Fe(e) {
2274
- return e || "server-rendered";
2275
- }
2276
- function ke(e) {
2277
- return e || "rest";
2278
- }
2279
- function Se(e) {
2280
- return e instanceof HTMLFormElement ? e : e.querySelector("form");
2281
- }
2282
- function Gi(e, t) {
2283
- Rt.has(e) || (Rt.add(e), L.warn(t));
2284
- }
2285
- function Ar(e, t) {
2286
- if (!e)
2287
- return e;
2288
- try {
2289
- return new URL(e).toString();
2290
- } catch {
2291
- }
2292
- if (!t)
2293
- return e;
2294
- try {
2295
- return new URL(e, t).toString();
2296
- } catch {
2297
- return e;
2298
- }
2299
- }
2300
- function re(e, t) {
2301
- const r = (e || "").trim();
2302
- return r ? r.includes("/actions/") ? r : Ar(t, r) : t;
2303
- }
2304
- function Ji(e, t) {
2305
- return re(e.endpoint || t.dataset.formieEndpoint, Ui);
2306
- }
2307
- function Yi(e, t) {
2308
- const r = (e.endpoint || t.dataset.formieEndpoint || "").trim();
2309
- return r ? r.includes("/graphql") || r.endsWith("/api") || r.includes("/actions/graphql/") ? r : Ar(It, r) : It;
2310
- }
2311
- function dt(e, t) {
2312
- return re(
2313
- t.dataset.formieRefreshTokensEndpoint || e.endpoint || t.dataset.formieEndpoint,
2314
- Bi
2315
- );
2316
- }
2317
- function Ft(e, t) {
2318
- if (!e)
2319
- return t;
2320
- try {
2321
- const r = new URL(e, window.location.origin), n = new URL(t, window.location.origin);
2322
- return r.searchParams.forEach((i, o) => {
2323
- n.searchParams.has(o) || n.searchParams.set(o, i);
2324
- }), n.toString();
2325
- } catch {
2326
- return t;
2327
- }
2328
- }
2329
- function Zi(e, t, r) {
2330
- const n = r.endpoint || e.dataset.formieEndpoint, i = re(n, ji), o = t.getAttribute("action");
2331
- t.setAttribute("action", Ft(o, i)), t.querySelectorAll("[data-formie-tab-link]").forEach((a) => {
2332
- const s = a.getAttribute("href"), l = re(n, zi);
2333
- a.setAttribute("href", Ft(s, l));
2334
- }), t.querySelectorAll("[data-formie-file-upload-hydrate-endpoint]").forEach((a) => {
2335
- a.setAttribute(
2336
- "data-formie-file-upload-hydrate-endpoint",
2337
- re(n, Ki)
2338
- );
2339
- });
2340
- }
2341
- function ft(e, t) {
2342
- if (e === "graphql" && t !== "server-rendered")
2343
- throw new Error(`Formie ${t} mode does not support GraphQL transport yet.`);
2344
- }
2345
- function mt(e) {
2346
- if (e == null)
2347
- return !1;
2348
- const t = e.trim().toLowerCase();
2349
- return t === "true" || t === "1" || t === "";
2350
- }
2351
- function Qi(e) {
2352
- return ce(e.dataset.formieAutomaticSubmissionState, !0);
2353
- }
2354
- function Xi(e, t, r) {
2355
- return re(
2356
- r.dataset.formieClearSubmissionEndpoint || e.endpoint || t.dataset.formieEndpoint,
2357
- Wi
2358
- );
2359
- }
2360
- function eo(e) {
2361
- return mt(e.dataset.formieUnloadWarning);
2362
- }
2363
- function kt(e, t) {
2364
- e.setAttribute("data-formie-internal-navigation", t);
2365
- }
2366
- function xe(e) {
2367
- e.removeAttribute("data-formie-internal-navigation");
2368
- }
2369
- function Pt(e) {
2370
- return e.getAttribute("data-formie-internal-navigation") !== null;
2371
- }
2372
- function qt(e, t) {
2373
- if (!e)
2374
- return !1;
2375
- try {
2376
- return new URL(e, window.location.origin).searchParams.has(t);
2377
- } catch {
2378
- return !1;
2379
- }
2380
- }
2381
- function to(e) {
2382
- return qt(window.location.href, "resumeToken") || qt(e.getAttribute("action"), "resumeToken");
2383
- }
2384
- function ro(e) {
2385
- return e instanceof MouseEvent ? e.button === 0 && !e.metaKey && !e.ctrlKey && !e.shiftKey && !e.altKey : !0;
2386
- }
2387
- function no(e, t = 0) {
2388
- if (!e)
2389
- return t;
2390
- const r = Number.parseInt(e, 10);
2391
- return Number.isFinite(r) ? r : t;
2392
- }
2393
- function io(e) {
2394
- return Math.max(0, no(e.dataset.formieSubmitDelay, Ni));
2395
- }
2396
- function Je(e) {
2397
- return mt(e.dataset.formieValidationOnSubmit);
2398
- }
2399
- async function Ye(e) {
2400
- const t = io(e);
2401
- t < 1 || await new Promise((r) => {
2402
- window.setTimeout(r, t);
2403
- });
2404
- }
2405
- function Vt(e, t) {
2406
- const r = e?.getAttribute(t)?.trim();
2407
- if (!r)
2408
- return null;
2409
- try {
2410
- return JSON.parse(r);
2411
- } catch (n) {
2412
- return console.error(`[formie] Failed to parse ${t}.`, n), null;
2413
- }
2414
- }
2415
- function Ot(e, t) {
2416
- const r = t || (e instanceof HTMLFormElement ? e : null);
2417
- if (!r)
2418
- return null;
2419
- const n = Vt(r, "data-formie-modules"), i = Vt(r, "data-formie-theme");
2420
- return !n && !i ? null : {
2421
- modules: n || void 0,
2422
- theme: i || void 0
2423
- };
2424
- }
2425
- function oo(e) {
2426
- if (!(e instanceof HTMLElement))
2427
- return !0;
2428
- if (!e.isConnected || e.hidden || e.closest("[hidden]"))
2429
- return !1;
2430
- const t = window.getComputedStyle(e);
2431
- return t.display === "none" || t.visibility === "hidden" ? !1 : e.getClientRects().length > 0;
2432
- }
2433
- function ao(e, t) {
2434
- return t === document ? !0 : t instanceof Element ? t === e || t.contains(e) : !0;
2435
- }
2436
- function V(e) {
2437
- const t = e, r = t.id ? `#${t.id}` : "", n = t.dataset?.formieHandle ? `[handle="${t.dataset.formieHandle}"]` : "";
2438
- return `${t.tagName ? t.tagName.toLowerCase() : "element"}${r}${n}`;
2439
- }
2440
- function pt(e, t) {
2441
- if (t) {
2442
- if (t.csrf?.param && t.csrf?.token) {
2443
- const r = e.querySelector(`input[name="${t.csrf.param}"]`);
2444
- r && (r.value = t.csrf.token);
2445
- }
2446
- if (t.requestToken) {
2447
- const r = e.querySelector('input[name="requestToken"]');
2448
- r && (r.value = t.requestToken);
2449
- }
2450
- if (t.renderId) {
2451
- const r = e.querySelector('input[name="renderId"]');
2452
- r && (r.value = t.renderId);
2453
- }
2454
- t.captchas && typeof t.captchas == "object" && Object.values(t.captchas).forEach((r) => {
2455
- if (!r || typeof r != "object")
2456
- return;
2457
- const n = r;
2458
- if (!n.sessionKey)
2459
- return;
2460
- const i = e.querySelector(`input[name="${n.sessionKey}"]`);
2461
- i && typeof n.value == "string" && (i.value = n.value);
2462
- });
2463
- }
2464
- }
2465
- async function so(e, t) {
2466
- const r = Fe(t.mode), n = ke(t.transport);
2467
- if (r !== "server-rendered")
2468
- return null;
2469
- if (t.payload)
2470
- return t.payload.html && (e.innerHTML = t.payload.html), t.payload;
2471
- ft(n, r);
2472
- const i = !!Se(e), o = t.formHandle || e.dataset.formieHandle;
2473
- if (i || !o)
2474
- return null;
2475
- const a = {
2476
- mode: r,
2477
- endpoint: t.endpoint,
2478
- locale: t.locale,
2479
- siteId: t.siteId,
2480
- theme: t.theme,
2481
- themeConfig: t.themeConfig
2482
- }, s = n === "graphql" ? Yi(t, e) : Ji(t, e), l = n === "graphql" ? await fn(s, o, a) : await dn(s, o, {
2483
- ...a,
2484
- endpoint: s
2485
- });
2486
- return l?.html && (e.innerHTML = l.html), l;
2487
- }
2488
- async function wr(e, t, r) {
2489
- if (t.refreshTokens === !1)
2490
- return;
2491
- ft(ke(t.transport), Fe(t.mode));
2492
- const n = t.formHandle || e.dataset.formieHandle;
2493
- if (!n)
2494
- return;
2495
- const i = dt(t, e), a = r.querySelector('input[name="renderId"]')?.value || void 0, s = await nt(i, n, a);
2496
- pt(r, s), I(e, "formie:refresh-tokens:refreshed", s);
2497
- }
2498
- function lo(e, t, r, n, i, o) {
2499
- const a = String(
2500
- t.dataset.formieSubmitMethod || ""
2501
- ).trim().toLowerCase(), s = Xi(r, e, t);
2502
- let l = !1;
2503
- const d = t.querySelectorAll("[data-formie-action]"), p = (c) => {
2504
- if (c) {
2505
- t.setAttribute("data-formie-pending-action", c);
2506
- return;
2507
- }
2508
- t.removeAttribute("data-formie-pending-action");
2509
- };
2510
- if (eo(t)) {
2511
- const c = xi(t, {
2512
- shouldWarn: () => !Pt(t)
2513
- }), b = (f) => {
2514
- if (!(f instanceof CustomEvent))
2515
- return;
2516
- const v = f.detail;
2517
- v?.ok && v.action === "save" && c.scheduleBaselineCapture();
2518
- }, A = () => {
2519
- c.scheduleBaselineCapture();
2520
- };
2521
- e.addEventListener("formie:submit:result", b), t.addEventListener("formie:state:reset", A), o.push(() => {
2522
- e.removeEventListener("formie:submit:result", b), t.removeEventListener("formie:state:reset", A), c.destroy();
2523
- });
2524
- }
2525
- if (d.forEach((c) => {
2526
- const b = (A) => {
2527
- const f = A.currentTarget.getAttribute("data-formie-action"), v = t.querySelector('input[name="submitAction"]');
2528
- p(f), f && v && (v.value = f);
2529
- };
2530
- c.addEventListener("click", b), o.push(() => {
2531
- c.removeEventListener("click", b);
2532
- });
2533
- }), t.querySelectorAll("[data-formie-tab-link]").forEach((c) => {
2534
- const b = async (A) => {
2535
- if (a !== "ajax") {
2536
- ro(A) && kt(t, "set-page");
2537
- return;
2538
- }
2539
- A.preventDefault();
2540
- const f = A.currentTarget, v = f?.getAttribute("data-formie-page-id"), E = f?.getAttribute("href");
2541
- if (!(!v || !E)) {
2542
- lt(t, v), I(e, "formie:page:navigate", {
2543
- pageId: v,
2544
- href: E
2545
- });
2546
- try {
2547
- const y = await mn(E, t, v);
2548
- I(e, "formie:page:navigate:after", {
2549
- pageId: v,
2550
- href: E,
2551
- response: y
2552
- });
2553
- } catch (y) {
2554
- console.error("[formie] Failed to persist page navigation state.", y), I(e, "formie:page:navigate:error", {
2555
- pageId: v,
2556
- href: E,
2557
- error: y
2558
- });
2559
- }
2560
- }
2561
- };
2562
- c.addEventListener("click", b), o.push(() => {
2563
- c.removeEventListener("click", b);
2564
- });
2565
- }), !Qi(t)) {
2566
- let c = !1;
2567
- const b = () => {
2568
- c || Pt(t) || to(t) || (c = !0, pn(s, t));
2569
- };
2570
- window.addEventListener("pagehide", b), window.addEventListener("beforeunload", b), o.push(() => {
2571
- window.removeEventListener("pagehide", b), window.removeEventListener("beforeunload", b);
2572
- });
2573
- }
2574
- const u = async (c) => {
2575
- if (l)
2576
- return;
2577
- const b = a === "ajax";
2578
- if (c.preventDefault(), t.getAttribute("data-formie-loading") === "true") {
2579
- if (!(t.getAttribute("data-formie-internal-resubmit") === "true"))
2580
- return;
2581
- t.removeAttribute("data-formie-internal-resubmit");
2582
- } else
2583
- t.removeAttribute("data-formie-internal-resubmit");
2584
- const f = c.submitter, v = f?.getAttribute("data-formie-action"), E = t.getAttribute("data-formie-pending-action"), y = t.querySelector('input[name="submitAction"]'), m = v || E || y?.value || "submit";
2585
- let g = null, S = !1;
2586
- try {
2587
- if (b)
2588
- g = await yr({
2589
- target: e,
2590
- form: t,
2591
- bus: n,
2592
- validator: i,
2593
- validateOnSubmit: Je(t),
2594
- action: m,
2595
- submitter: f,
2596
- waitForSubmitDelay: Ye,
2597
- onRefreshTokensAfterSubmit: async () => {
2598
- await wr(e, r, t);
2599
- },
2600
- dispatchSubmitResult: (M) => {
2601
- I(e, "formie:submit:result", M);
2602
- }
2603
- });
2604
- else {
2605
- if (br(t), lr(t, f), await Ye(t), g = await tr(t, m, n, {
2606
- validator: i,
2607
- validateOnSubmit: Je(t),
2608
- preflightOnly: !0
2609
- }), g.ok) {
2610
- Kt(t, m), l = !0, kt(t, "submit"), p(null);
2611
- let M = !1;
2612
- const T = () => {
2613
- M = !0, l = !1, xe(t), Me(t);
2614
- };
2615
- if (typeof t.requestSubmit == "function") {
2616
- t.addEventListener("invalid", T, !0);
2617
- try {
2618
- t.requestSubmit();
2619
- } finally {
2620
- t.removeEventListener("invalid", T, !0);
2621
- }
2622
- } else
2623
- t.submit();
2624
- if (M)
2625
- return;
2626
- S = !0;
2627
- return;
2628
- }
2629
- Le(t, g), I(e, "formie:submit:result", g), xe(t);
2630
- }
2631
- } catch (M) {
2632
- l = !1, g = {
2633
- ok: !1,
2634
- code: "SUBMIT_ERROR",
2635
- message: M instanceof Error ? M.message : "Submission failed.",
2636
- formErrors: [M instanceof Error ? M.message : "Submission failed."]
2637
- }, Le(t, g), I(e, "formie:submit:result", g), xe(t);
2638
- } finally {
2639
- p(null), !b && !S && !hr(g) && Me(t);
2640
- }
2641
- };
2642
- t.addEventListener("submit", u), o.push(() => {
2643
- t.removeEventListener("submit", u);
2644
- });
2645
- }
2646
- async function uo(e, t, r) {
2647
- if (t.refreshTokens === !1 || !t.staticCache)
2648
- return;
2649
- ft(ke(t.transport), Fe(t.mode));
2650
- const n = t.formHandle || e.dataset.formieHandle, i = dt(t, e), a = r?.querySelector('input[name="renderId"]')?.value || void 0;
2651
- if (!n)
2652
- return;
2653
- const s = await nt(i, n, a);
2654
- !s || !r || (pt(r, s), I(e, "formie:refresh-tokens:after", s));
2655
- }
2656
- function co() {
2657
- const e = /* @__PURE__ */ new Map(), t = new vr(), r = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), i = [
2658
- "prepare",
2659
- "normalize",
2660
- "validate",
2661
- "screen",
2662
- "authorize",
2663
- "dispatch",
2664
- "finalize"
2665
- ], o = async (f) => {
2666
- const v = n.get(f);
2667
- if (v) {
2668
- await v;
2669
- return;
2670
- }
2671
- const E = (async () => {
2672
- L.log("Unmount requested.", { target: V(f) });
2673
- const y = r.get(f);
2674
- y && (y(), r.delete(f));
2675
- const m = e.get(f);
2676
- if (!m) {
2677
- L.log("Unmount skipped (no mounted state).", { target: V(f) });
2678
- return;
2679
- }
2680
- I(f, "formie:unmount:before", {
2681
- id: m.instance.id
2682
- }), m.unbinds.forEach((g) => {
2683
- g();
2684
- }), m.unbinds = [], m.validator?.destroy(), m.validator = null;
2685
- for (const g of m.modules)
2686
- await g.destroy();
2687
- m.modules = [], m.bus.clear(), e.delete(f), I(f, "formie:unmount:after", {
2688
- id: m.instance.id
2689
- }), L.log("Unmount complete.", { id: m.instance.id, target: V(f) });
2690
- })().finally(() => {
2691
- n.delete(f);
2692
- });
2693
- n.set(f, E), await E;
2694
- }, a = async (f, v) => {
2695
- L.log("Mount requested.", {
2696
- target: V(f),
2697
- mode: v.mode,
2698
- autoVisible: v.autoVisible
2699
- });
2700
- const E = r.get(f);
2701
- E && (E(), r.delete(f));
2702
- const y = e.get(f);
2703
- if (y)
2704
- return L.log("Mount skipped (already mounted).", {
2705
- id: y.instance.id,
2706
- target: V(f)
2707
- }), y.instance;
2708
- const m = new Gt(), g = [], S = f?.id || `formie-${e.size + 1}`, M = ee(f), T = {
2709
- ...M,
2710
- ...v,
2711
- mode: Fe(v.mode ?? M.mode),
2712
- transport: ke(v.transport ?? M.transport)
2713
- }, R = xr(T.compatibility);
2714
- if (T.mode !== "server-rendered" && !Se(f))
2715
- throw new Error(`Formie ${T.mode} mode is not implemented yet in the browser client.`);
2716
- const P = await so(f, T), w = Se(f);
2717
- T.staticCache = v.staticCache ?? Ge(w ? w.dataset : f.dataset);
2718
- const q = Ot(f, w), N = P || q ? {
2719
- ...P || {},
2720
- ...q || {}
2721
- } : null, z = N?.theme, Y = {}, fe = (N?.modules || []).filter((C) => !!C?.id && !!C?.type);
2722
- L.log("Resolved mount payload.", {
2723
- target: V(f),
2724
- hasRenderPayload: !!P,
2725
- hasEmbeddedPayload: !!q,
2726
- moduleCount: fe.length
2727
- });
2728
- const ne = yt(f, z, w), k = w ? new Un(w, {
2729
- live: mt(w.dataset.formieValidationOnFocus),
2730
- errorMessage: w.dataset.formieErrorMessage || "",
2731
- fieldContainerErrorClass: ne.fieldLayoutError || [],
2732
- inputErrorClass: ne.fieldControlError || [],
2733
- messagesClass: ne.fieldErrors || [],
2734
- messageClass: ne.fieldError || []
2735
- }) : null;
2736
- if (w && k) {
2737
- const C = w;
2738
- C.formieValidation = k, Y.validation = k;
2739
- const $ = {
2740
- validator: k,
2741
- addValidator: k.addValidator.bind(k),
2742
- removeValidator: k.removeValidator.bind(k)
2743
- };
2744
- I(w, "formie:validator:ready", $), I(f, "formie:validator:ready", $);
2745
- }
2746
- w && ((P || T.endpoint || f.dataset.formieEndpoint) && Zi(f, w, T), J(w)), Object.keys(ne).length && I(f, "formie:theme:applied", {
2747
- hasClasses: !0
2748
- });
2749
- const me = await Sr(fe, {
2750
- registry: t,
2751
- matchContext: {
2752
- root: f,
2753
- form: w,
2754
- mode: T.mode
2755
- },
2756
- setupContext: {
2757
- formId: S,
2758
- root: f,
2759
- form: w,
2760
- target: f,
2761
- scope: "form",
2762
- state: Y,
2763
- on: (C, $) => m.on(C, $),
2764
- emit: (C, $) => (I(f, C, $), m.emitSafe(C, $).then((Z) => {
2765
- Z.failed.length > 0 && L.warn("Lifecycle listeners failed.", {
2766
- eventName: C,
2767
- failed: Z.failed.length
2768
- });
2769
- }))
2770
- }
2771
- });
2772
- L.log("Module setup complete.", {
2773
- target: V(f),
2774
- moduleInstances: me.length
2775
- });
2776
- const qe = {
2777
- id: S,
2778
- root: f,
2779
- submit: async (C = "submit") => {
2780
- if (L.log("Submit requested.", {
2781
- id: S,
2782
- target: V(f),
2783
- action: C
2784
- }), !w)
2785
- return {
2786
- ok: !1,
2787
- code: "FORM_NOT_FOUND",
2788
- message: "No form element found for mount target.",
2789
- formErrors: ["No form element found for mount target."]
2790
- };
2791
- const $ = w.querySelector('input[name="submitAction"]');
2792
- if ($ && ($.value = C), w.getAttribute("data-formie-loading") === "true")
2793
- return {
2794
- ok: !1,
2795
- code: "SUBMIT_IN_PROGRESS",
2796
- message: "Submission already in progress.",
2797
- formErrors: []
2798
- };
2799
- const Z = w.querySelector(`[data-formie-action="${C}"]`), Q = await yr({
2800
- id: S,
2801
- target: f,
2802
- form: w,
2803
- bus: m,
2804
- validator: k,
2805
- validateOnSubmit: Je(w),
2806
- action: C,
2807
- submitter: Z,
2808
- waitForSubmitDelay: Ye,
2809
- onRefreshTokensAfterSubmit: async () => {
2810
- await wr(f, T, w);
2811
- },
2812
- dispatchSubmitResult: (Ve) => {
2813
- I(f, "formie:submit:result", Ve);
2814
- }
2815
- });
2816
- return L.log("Submit completed.", {
2817
- id: S,
2818
- action: C,
2819
- ok: Q.ok,
2820
- code: Q.code,
2821
- message: Q.message
2822
- }), Q;
2823
- },
2824
- destroy: async () => {
2825
- await o(f);
2826
- },
2827
- on: (C, $) => m.on(C, $)
2828
- };
2829
- w && (Jr({
2830
- target: f,
2831
- form: w,
2832
- validatorDetail: k ? {
2833
- validator: k,
2834
- addValidator: k.addValidator.bind(k),
2835
- removeValidator: k.removeValidator.bind(k)
2836
- } : null,
2837
- options: R,
2838
- unbinds: g
2839
- }), Gr({
2840
- target: f,
2841
- form: w,
2842
- instance: qe,
2843
- options: R,
2844
- unbinds: g
2845
- })), w && (lo(f, w, T, m, k, g), k && g.push(Wn(w, k, f)), await uo(f, T, w)), i.forEach((C) => {
2846
- const $ = m.on(`formie:stage:${C}:before`, async (W) => {
2847
- I(f, `formie:stage:${C}:before`, W);
2848
- }), Z = m.on(`formie:stage:${C}:before`, async (W) => {
2849
- for (const ie of me)
2850
- ie.onBeforeStage && await ie.onBeforeStage(W);
2851
- }), Q = m.on(`formie:stage:${C}:after`, async (W) => {
2852
- I(f, `formie:stage:${C}:after`, W);
2853
- }), Ve = m.on(`formie:stage:${C}:after`, async (W) => {
2854
- const ie = W;
2855
- for (const bt of me)
2856
- bt.onAfterStage && await bt.onAfterStage(ie, ie.result);
2857
- });
2858
- g.push($, Z, Q, Ve);
2859
- });
2860
- const Or = m.on("formie:submit:before", async (C) => {
2861
- I(f, "formie:submit:before", C);
2862
- }), $r = m.on("formie:submit:after", async (C) => {
2863
- I(f, "formie:submit:after", C);
2864
- }), Hr = m.on("formie:submit:final:before", async (C) => {
2865
- I(f, "formie:submit:final:before", C);
2866
- }), _r = m.on("formie:submit:final:after", async (C) => {
2867
- I(f, "formie:submit:final:after", C);
2868
- });
2869
- return g.push(
2870
- Or,
2871
- $r,
2872
- Hr,
2873
- _r
2874
- ), e.set(f, {
2875
- options: T,
2876
- bus: m,
2877
- form: w,
2878
- validator: k,
2879
- modules: me,
2880
- unbinds: g,
2881
- instance: qe
2882
- }), I(f, "formie:mount:after", {
2883
- id: S,
2884
- mode: T.mode
2885
- }), L.log("Mount complete.", {
2886
- id: S,
2887
- target: V(f),
2888
- mode: T.mode
2889
- }), qe;
2890
- }, s = (f, v) => {
2891
- if (!v.autoVisible || oo(f) || typeof IntersectionObserver > "u")
2892
- return a(f, v);
2893
- if (e.has(f))
2894
- return Promise.resolve(e.get(f)?.instance || null);
2895
- if (r.has(f))
2896
- return L.log("Mount deferred (already waiting visibility).", {
2897
- target: V(f)
2898
- }), Promise.resolve(null);
2899
- const E = new IntersectionObserver((y) => {
2900
- y.some((g) => g.target === f && g.isIntersecting) && (E.disconnect(), r.delete(f), L.log("Visibility reached, proceeding mount.", {
2901
- target: V(f)
2902
- }), a(f, {
2903
- ...v,
2904
- autoVisible: !1
2905
- }));
2906
- }, {
2907
- threshold: 0.01
2908
- });
2909
- return E.observe(f), r.set(f, () => {
2910
- E.disconnect();
2911
- }), L.log("Mount deferred until visible.", {
2912
- target: V(f)
2913
- }), Promise.resolve(null);
2914
- };
2915
- return {
2916
- mount: a,
2917
- unmount: o,
2918
- update: async (f, v) => {
2919
- const E = e.get(f);
2920
- if (!E)
2921
- return a(f, {
2922
- ...ee(f),
2923
- ...v,
2924
- mode: v.mode || "server-rendered"
2925
- });
2926
- E.options = {
2927
- ...E.options,
2928
- ...v
2929
- };
2930
- const y = v.payload?.theme || E.options.payload?.theme || Ot(f, E.form)?.theme, m = yt(f, y, E.form);
2931
- return E.validator && (E.validator.config.fieldContainerErrorClass = m.fieldLayoutError || [], E.validator.config.inputErrorClass = m.fieldControlError || [], E.validator.config.messagesClass = m.fieldErrors || [], E.validator.config.messageClass = m.fieldError || []), Object.keys(m).length && I(f, "formie:theme:applied", {
2932
- hasClasses: !0,
2933
- reason: "update"
2934
- }), E.instance;
2935
- },
2936
- getInstance: (f) => e.get(f)?.instance || null,
2937
- refreshForCache: async (f) => {
2938
- Gi(
2939
- "refreshForCache",
2940
- "Global `Formie.refreshForCache()` has been deprecated. Use built-in static-cache token refresh handling instead."
2941
- );
2942
- let v = null;
2943
- if (typeof f == "string") {
2944
- const P = document.getElementById(f);
2945
- P ? v = P : v = document.querySelector(`[data-formie-form-id="${f}"]`);
2946
- } else
2947
- v = f;
2948
- if (!v) {
2949
- L.warn("refreshForCache target not found.", {
2950
- targetOrId: f
2951
- });
2952
- return;
2953
- }
2954
- const E = e.get(v), y = Se(v), m = E?.options || ee(v);
2955
- if (!y) {
2956
- L.warn("refreshForCache found no form element for target.", {
2957
- target: V(v)
2958
- });
2959
- return;
2960
- }
2961
- const g = m.formHandle || v.dataset.formieHandle || y.dataset.formieHandle, S = dt(m, v), T = y.querySelector('input[name="renderId"]')?.value || void 0;
2962
- if (!g) {
2963
- L.warn("refreshForCache found no form handle for target.", {
2964
- target: V(v)
2965
- });
2966
- return;
2967
- }
2968
- const R = await nt(S, g, T);
2969
- R && (pt(y, R), I(v, "formie:refresh-tokens:after", R));
2970
- },
2971
- registerModule: (f, v) => t.register(f, v),
2972
- unregisterModule: (f) => {
2973
- t.unregister(f);
2974
- },
2975
- getRegisteredModules: () => t.getAll(),
2976
- scan: async (f) => {
2977
- const v = f || document, E = Array.from(v.querySelectorAll(X));
2978
- L.log("Scan started.", {
2979
- scope: v === document ? "document" : v,
2980
- targetCount: E.length
2981
- });
2982
- const m = (await Promise.all(E.map((g) => {
2983
- const S = ee(g);
2984
- return s(g, S);
2985
- }))).filter((g) => !!g);
2986
- return L.log("Scan finished.", {
2987
- mountedCount: m.length,
2988
- deferredCount: E.length - m.length
2989
- }), m;
2990
- },
2991
- observe: (f) => {
2992
- if (typeof MutationObserver > "u")
2993
- return () => {
2994
- };
2995
- const v = f || document;
2996
- L.log("Observer started.", {
2997
- scope: v === document ? "document" : v
2998
- });
2999
- const E = new MutationObserver((y) => {
3000
- y.forEach((m) => {
3001
- m.addedNodes.forEach((g) => {
3002
- g instanceof Element && (g.matches(X) && (L.log("Observer detected new root.", {
3003
- target: V(g)
3004
- }), s(g, ee(g))), g.querySelectorAll(X).forEach((S) => {
3005
- L.log("Observer detected new nested root.", {
3006
- target: V(S)
3007
- }), s(S, ee(S));
3008
- }));
3009
- }), m.removedNodes.forEach((g) => {
3010
- g instanceof Element && (e.has(g) && (L.log("Observer detected removed root.", {
3011
- target: V(g)
3012
- }), o(g)), g.querySelectorAll(X).forEach((S) => {
3013
- e.has(S) && (L.log("Observer detected removed nested root.", {
3014
- target: V(S)
3015
- }), o(S));
3016
- }));
3017
- });
3018
- });
3019
- });
3020
- return E.observe(v, {
3021
- childList: !0,
3022
- subtree: !0
3023
- }), () => {
3024
- E.disconnect(), L.log("Observer stopped."), r.forEach((m, g) => {
3025
- ao(g, v) && (m(), r.delete(g));
3026
- });
3027
- const y = [];
3028
- v instanceof Element && v.matches(X) && y.push(v), v.querySelectorAll(X).forEach((m) => {
3029
- y.push(m);
3030
- }), y.forEach((m) => {
3031
- e.has(m) && o(m);
3032
- });
3033
- };
3034
- }
3035
- };
3036
- }
3037
- const Tr = _("general", "module-hydrator");
3038
- async function ha(e) {
3039
- const t = e.root, r = e.form ?? (t instanceof HTMLFormElement ? t : t.closest("form")), n = e.modules ?? [], i = e.mode ?? "server-rendered", o = e.registry ?? new vr(), a = new Gt(), s = await Sr(n, {
3040
- registry: o,
3041
- setupContext: {
3042
- formId: r?.id || t.id || "formie-modules",
3043
- root: t,
3044
- form: r,
3045
- target: t,
3046
- scope: "form",
3047
- state: {},
3048
- options: {},
3049
- on: (l, d) => a.on(l, d),
3050
- emit: async (l, d) => {
3051
- await a.emit(l, d);
3052
- }
3053
- },
3054
- matchContext: {
3055
- root: t,
3056
- form: r,
3057
- mode: i
3058
- }
3059
- });
3060
- return Tr.log("Hydrated module manifest.", {
3061
- moduleCount: n.length,
3062
- instanceCount: s.length,
3063
- mode: i
3064
- }), {
3065
- destroy: async () => {
3066
- await fo(s), a.clear();
3067
- },
3068
- on: (l, d) => a.on(l, d),
3069
- emit: async (l, d) => {
3070
- await a.emit(l, d);
3071
- },
3072
- registerModule: (l, d = {}) => o.register(l, d),
3073
- unregisterModule: (l) => {
3074
- o.unregister(l);
3075
- },
3076
- getRegisteredModules: () => o.getAll()
3077
- };
3078
- }
3079
- async function fo(e) {
3080
- for (const t of e)
3081
- try {
3082
- await t.destroy();
3083
- } catch (r) {
3084
- console.error("[formie] Failed to destroy module instance.", r), Tr.warn("Failed destroying module instance.", { error: r });
3085
- }
3086
- }
3087
- function Pe(e) {
3088
- return e instanceof Element;
3089
- }
3090
- function mo(e) {
3091
- return e.ok;
3092
- }
3093
- function po(e) {
3094
- return typeof e == "string" ? `selector "${e}"` : Pe(e) ? `element "${e.tagName.toLowerCase()}"` : "provided element collection";
3095
- }
3096
- function go(e) {
3097
- const t = /* @__PURE__ */ new Set(), r = [];
3098
- for (const n of e)
3099
- !Pe(n) || t.has(n) || (t.add(n), r.push(n));
3100
- return r;
3101
- }
3102
- function Ze(e) {
3103
- return typeof e == "string" ? Array.from(document.querySelectorAll(e)) : Pe(e) ? [e] : go(e);
3104
- }
3105
- function ho() {
3106
- return document.readyState !== "loading" ? Promise.resolve() : new Promise((e) => {
3107
- document.addEventListener("DOMContentLoaded", () => e(), { once: !0 });
3108
- });
3109
- }
3110
- async function bo(e) {
3111
- const t = Ze(e);
3112
- return t.length > 0 || typeof e != "string" ? t : (await ho(), Ze(e));
3113
- }
3114
- function yo(e) {
3115
- return typeof e == "string" ? document : Pe(e) ? e.getRootNode() : document;
3116
- }
3117
- function vo(e) {
3118
- const {
3119
- element: t,
3120
- observe: r,
3121
- allowEmpty: n,
3122
- client: i,
3123
- onReady: o,
3124
- onResult: a,
3125
- onSuccess: s,
3126
- onError: l,
3127
- onEvent: d,
3128
- ...p
3129
- } = e;
3130
- return {
3131
- mode: "server-rendered",
3132
- ...p
3133
- };
3134
- }
3135
- async function $t(e, t, r, n) {
3136
- const i = [], o = vo(e);
3137
- for (const a of n) {
3138
- const s = r.get(a);
3139
- if (s) {
3140
- i.push(s.instance);
3141
- continue;
3142
- }
3143
- const l = await t.mount(a, o), d = [];
3144
- if (e.onReady?.(l), d.push(l.on("formie:submit:result", (p) => {
3145
- const h = p;
3146
- e.onResult?.(h, l), mo(h) ? e.onSuccess?.(h, l) : e.onError?.(h, l);
3147
- })), e.onEvent)
3148
- for (const p of Nr)
3149
- d.push(l.on(p, (h) => {
3150
- e.onEvent?.({
3151
- name: p,
3152
- payload: h
3153
- }, l);
3154
- }));
3155
- r.set(a, {
3156
- instance: l,
3157
- unsubs: d
3158
- }), i.push(l);
3159
- }
3160
- return i;
3161
- }
3162
- async function ba(e) {
3163
- const t = e.client ?? co(), r = /* @__PURE__ */ new Map(), n = await bo(e.element);
3164
- if (n.length === 0 && !e.allowEmpty)
3165
- throw new Error(`Formie could not find any elements for ${po(e.element)}.`);
3166
- await $t(e, t, r, n);
3167
- const i = e.observe ? t.observe(yo(e.element)) : null;
3168
- return {
3169
- client: t,
3170
- get instances() {
3171
- return Array.from(r.values()).map(({ instance: o }) => o);
3172
- },
3173
- get(o) {
3174
- const a = typeof o == "string" ? document.querySelector(o) : o;
3175
- return a ? r.get(a)?.instance ?? t.getInstance(a) : null;
3176
- },
3177
- async rescan() {
3178
- const o = Ze(e.element);
3179
- return o.length === 0 ? Array.from(r.values()).map(({ instance: a }) => a) : $t(e, t, r, o);
3180
- },
3181
- async destroy() {
3182
- i?.();
3183
- const o = Array.from(r.entries());
3184
- for (const [a, s] of o)
3185
- s.unsubs.forEach((l) => l()), await t.unmount(a), r.delete(a);
3186
- }
3187
- };
3188
- }
3189
- const gt = 2e3, ya = 5e3, va = 5e3, Ea = 12e4;
3190
- async function ht(e) {
3191
- await new Promise((t) => {
3192
- window.setTimeout(t, Math.max(e, 0));
3193
- });
3194
- }
3195
- async function Sa(e, {
3196
- timeoutMs: t = 5e3,
3197
- intervalMs: r = 30
3198
- } = {}) {
3199
- const n = Date.now();
3200
- for (; Date.now() - n < t; ) {
3201
- const i = e();
3202
- if (i)
3203
- return i;
3204
- await ht(r);
3205
- }
3206
- throw new Error("Timed out waiting for async condition.");
3207
- }
3208
- function Mr(e, t) {
3209
- let r = null;
3210
- return (...n) => {
3211
- r !== null && window.clearTimeout(r), r = window.setTimeout(() => {
3212
- e(...n);
3213
- }, Math.max(t, 0));
3214
- };
3215
- }
3216
- function Aa(e) {
3217
- const t = String(e || "asyncDefer").toLowerCase();
3218
- return {
3219
- async: t.includes("async"),
3220
- defer: t.includes("defer")
3221
- };
3222
- }
3223
- function Cr(e, t) {
3224
- const r = Array.from(e.querySelectorAll(`input[name="${t}"], textarea[name="${t}"]`));
3225
- for (const n of r) {
3226
- const i = String(n.value || "").trim();
3227
- if (i !== "")
3228
- return i;
3229
- }
3230
- return "";
3231
- }
3232
- function Qe(e, t) {
3233
- return t.some((r) => Cr(e, r) !== "");
3234
- }
3235
- function Eo(e, t) {
3236
- t.forEach((r) => {
3237
- Array.from(e.querySelectorAll(`input[name="${r}"], textarea[name="${r}"]`)).forEach((i) => {
3238
- i.value = "";
3239
- });
3240
- });
3241
- }
3242
- function Lr(e, t, {
3243
- value: r = "",
3244
- container: n
3245
- } = {}) {
3246
- let i = e.querySelector(`input[name="${t}"]`);
3247
- return i || (i = document.createElement("input"), i.type = "hidden", i.name = t, (n || (e instanceof HTMLElement ? e : null))?.appendChild(i)), i.value = r, i;
3248
- }
3249
- async function Ir(e, t, r) {
3250
- if (Qe(e, t))
3251
- return !0;
3252
- const n = Date.now() + Math.max(r, 0);
3253
- for (; Date.now() < n; )
3254
- if (await ht(120), Qe(e, t))
3255
- return !0;
3256
- return !1;
3257
- }
3258
- const So = /* @__PURE__ */ new Set([
3259
- "handle",
3260
- "placeholderSelector",
3261
- "errorMessage",
3262
- "sessionKey",
3263
- "value"
3264
- ]), Ao = "[data-formie-captcha-error-container]", wo = [
3265
- "formie:page:navigate",
3266
- "formie:page:navigate:after",
3267
- "formie:submit:result"
3268
- ];
3269
- function se(e, t, r) {
3270
- return e.addEventListener(t, r), () => {
3271
- e.removeEventListener(t, r);
3272
- };
3273
- }
3274
- function Ie(e, t) {
3275
- return e instanceof HTMLElement && e.matches(t) ? [e, ...Array.from(e.querySelectorAll(t))] : Array.from(e.querySelectorAll(t));
3276
- }
3277
- function Xe(e) {
3278
- if (!(e instanceof HTMLElement) || !e.isConnected || e.hidden || e.closest("[hidden]") || e.closest("[data-formie-page-hidden]") || e.closest('[aria-hidden="true"]'))
3279
- return !1;
3280
- const t = window.getComputedStyle(e);
3281
- return t.display !== "none" && t.visibility !== "hidden";
3282
- }
3283
- function Ne(e, t) {
3284
- const r = Ie(e, t);
3285
- return r.find((n) => Xe(n)) || r[0] || null;
3286
- }
3287
- function To(e) {
3288
- e.innerHTML = "";
3289
- const t = document.createElement("div");
3290
- return e.appendChild(t), t;
3291
- }
3292
- function et(e) {
3293
- e?.querySelector(Ao)?.remove();
3294
- }
3295
- function Mo(e, t, r) {
3296
- if (!e)
3297
- return;
3298
- et(e);
3299
- const n = document.createElement("div");
3300
- n.setAttribute("data-formie-captcha-error-container", ""), n.setAttribute("aria-live", "polite"), n.setAttribute("aria-atomic", "true"), O(n, r || e, "fieldErrors");
3301
- const i = document.createElement("div");
3302
- i.setAttribute("data-formie-captcha-error", ""), i.setAttribute("role", "alert"), O(i, r || e, "fieldError"), i.textContent = t, n.appendChild(i), e.appendChild(n);
3303
- }
3304
- function Co(e) {
3305
- const t = e instanceof CustomEvent ? e.detail : null;
3306
- return !t || typeof t != "object" ? null : t;
3307
- }
3308
- function Lo(e, t) {
3309
- if (!e?.captchas || typeof e.captchas != "object")
3310
- return null;
3311
- const r = e.captchas[t];
3312
- return !r || typeof r != "object" ? null : r;
3313
- }
3314
- function Io(e, t, r, n) {
3315
- const i = /* @__PURE__ */ new Set(), o = () => {
3316
- const d = Ie(e, t), p = new Set(d.filter((h) => Xe(h)));
3317
- d.forEach((h) => {
3318
- p.has(h) && !i.has(h) && (i.add(h), r(h));
3319
- }), Array.from(i).forEach((h) => {
3320
- p.has(h) || (i.delete(h), n(h));
3321
- });
3322
- }, a = Mr(o, 20), s = new MutationObserver(() => {
3323
- a();
3324
- });
3325
- s.observe(e, {
3326
- childList: !0,
3327
- subtree: !0,
3328
- attributes: !0,
3329
- attributeFilter: ["class", "style", "hidden", "aria-hidden", "data-formie-page-hidden"]
3330
- });
3331
- const l = [
3332
- se(window, "resize", () => {
3333
- a();
3334
- }),
3335
- ...wo.map((d) => se(e, d, () => {
3336
- a();
3337
- }))
3338
- ];
3339
- return o(), {
3340
- cleanup: () => {
3341
- s.disconnect(), l.forEach((d) => {
3342
- d();
3343
- }), Array.from(i).forEach((d) => {
3344
- n(d);
3345
- }), i.clear();
3346
- },
3347
- reconcile: a,
3348
- getVisible: () => Ie(e, t).filter((d) => Xe(d))
3349
- };
3350
- }
3351
- function Ro(e, t) {
3352
- return (typeof t.handle == "string" && t.handle.trim() !== "" ? t.handle.trim() : "") || e;
3353
- }
3354
- function Fo(e, t, {
3355
- defaultPlaceholderSelector: r,
3356
- defaultTokenFieldNames: n = [],
3357
- defaultWaitForValueMs: i = gt
3358
- }) {
3359
- const o = t || {}, a = Object.entries(o).reduce((c, [b, A]) => (So.has(b) || (c[b] = A), c), {}), s = n.map(String).filter(Boolean), l = Number(i), d = typeof o.placeholderSelector == "string" && o.placeholderSelector.trim() !== "" ? o.placeholderSelector.trim() : r, p = typeof o.errorMessage == "string" && o.errorMessage.trim() !== "" ? o.errorMessage.trim() : x("Captcha challenge must be completed."), h = typeof o.sessionKey == "string" && o.sessionKey.trim() !== "" ? o.sessionKey.trim() : null, u = typeof o.value == "string" ? o.value : null;
3360
- return {
3361
- handle: Ro(e, o),
3362
- ui: {
3363
- placeholderSelector: d,
3364
- errorMessage: p
3365
- },
3366
- transport: {
3367
- tokenFieldNames: s,
3368
- waitForValueMs: Number.isFinite(l) ? l : i,
3369
- sessionKey: h,
3370
- value: u
3371
- },
3372
- provider: a
3373
- };
3374
- }
3375
- function ko(e, t) {
3376
- const r = e.form || e.root, n = t.ui.placeholderSelector, i = t.handle;
3377
- return {
3378
- form: e.form,
3379
- root: e.root,
3380
- placeholder: {
3381
- query: () => Ie(e.root, n),
3382
- getPrimary: () => Ne(e.root, n),
3383
- observe: (o, a) => Io(e.root, n, o, a),
3384
- createContainer: (o) => To(o),
3385
- clear: (o) => {
3386
- o && (et(o), o.innerHTML = "");
3387
- }
3388
- },
3389
- errors: {
3390
- getDefaultMessage: () => t.ui.errorMessage,
3391
- show: (o, a) => {
3392
- Mo(a || Ne(e.root, n), o || t.ui.errorMessage, e.form || e.root);
3393
- },
3394
- clear: (o) => {
3395
- et(o || Ne(e.root, n));
3396
- }
3397
- },
3398
- tokens: {
3399
- names: t.transport.tokenFieldNames,
3400
- has: (o = t.transport.tokenFieldNames, a = r) => Qe(a, o),
3401
- read: (o = t.transport.tokenFieldNames[0], a = r) => o ? Cr(a, o) : "",
3402
- write: (o, {
3403
- names: a = t.transport.tokenFieldNames,
3404
- root: s = r,
3405
- container: l = e.form
3406
- } = {}) => {
3407
- a.forEach((d) => {
3408
- Lr(s, d, {
3409
- value: o,
3410
- container: l
3411
- });
3412
- });
3413
- },
3414
- clear: (o = t.transport.tokenFieldNames, a = r) => {
3415
- Eo(a, o);
3416
- },
3417
- wait: (o = t.transport.waitForValueMs, a = t.transport.tokenFieldNames, s = r) => Ir(s, a, o)
3418
- },
3419
- refresh: {
3420
- providerHandle: i,
3421
- onTokensRefreshed: (o) => {
3422
- const a = ["formie:refresh-tokens:after", "formie:refresh-tokens:refreshed"].map((s) => se(e.root, s, (l) => {
3423
- const d = Co(l), p = Lo(d, i);
3424
- p && o(p);
3425
- }));
3426
- return () => {
3427
- a.forEach((s) => {
3428
- s();
3429
- });
3430
- };
3431
- }
3432
- },
3433
- events: {
3434
- onRoot: (o, a) => se(e.root, o, a),
3435
- onForm: (o, a) => e.form ? se(e.form, o, a) : () => {
3436
- }
3437
- }
3438
- };
3439
- }
3440
- const G = _("captchas");
3441
- function Rr({
3442
- id: e,
3443
- defaultPlaceholderSelector: t,
3444
- defaultTokenFieldNames: r = [],
3445
- defaultWaitForValueMs: n = gt,
3446
- setup: i
3447
- }) {
3448
- return {
3449
- id: e,
3450
- kind: "captcha",
3451
- match: () => !0,
3452
- setup: async (o) => {
3453
- const a = Fo(e, o.options || {}, {
3454
- defaultPlaceholderSelector: t,
3455
- defaultTokenFieldNames: r,
3456
- defaultWaitForValueMs: n
3457
- });
3458
- G.log("Setup module.", {
3459
- moduleId: e,
3460
- placeholderSelector: a.ui.placeholderSelector,
3461
- tokenFieldNames: a.transport.tokenFieldNames
3462
- });
3463
- const s = ko(o, a);
3464
- return i({
3465
- ...o,
3466
- options: a,
3467
- services: s
3468
- });
3469
- }
3470
- };
3471
- }
3472
- function Po({
3473
- id: e,
3474
- defaultPlaceholderSelector: t,
3475
- defaultTokenFieldNames: r = [],
3476
- defaultWaitForValueMs: n = gt
3477
- }) {
3478
- return Rr({
3479
- id: e,
3480
- defaultPlaceholderSelector: t,
3481
- defaultTokenFieldNames: r,
3482
- defaultWaitForValueMs: n,
3483
- setup: async ({ services: i, options: o, root: a }) => {
3484
- const s = [];
3485
- let l = i.placeholder.getPrimary(), d = o.transport.sessionKey, p = o.transport.value || "";
3486
- const h = (c) => {
3487
- !c || !d || (c.innerHTML = "", Lr(c, d, {
3488
- value: p,
3489
- container: c
3490
- }));
3491
- }, u = i.placeholder.observe(
3492
- (c) => {
3493
- l = c, G.log("Passive placeholder visible.", {
3494
- moduleId: e
3495
- }), h(c);
3496
- },
3497
- (c) => {
3498
- l === c && (l = i.placeholder.getPrimary()), c.innerHTML = "";
3499
- }
3500
- );
3501
- return s.push(u.cleanup), h(l), s.push(i.refresh.onTokensRefreshed((c) => {
3502
- d = typeof c.sessionKey == "string" && c.sessionKey.trim() !== "" ? c.sessionKey.trim() : d, p = typeof c.value == "string" ? c.value : "";
3503
- const b = i.placeholder.getPrimary() || l;
3504
- l = b, h(b);
3505
- })), {
3506
- destroy: () => {
3507
- s.forEach((c) => {
3508
- c();
3509
- });
3510
- },
3511
- onBeforeStage: async (c) => {
3512
- if (c.stage !== "screen" || c.action !== "submit")
3513
- return;
3514
- const b = d ? [d] : o.transport.tokenFieldNames;
3515
- if (b.length === 0)
3516
- return;
3517
- if (!await Ir(a, b, o.transport.waitForValueMs)) {
3518
- const f = i.errors.getDefaultMessage();
3519
- i.errors.show(f, l), G.warn("Passive captcha missing token.", {
3520
- moduleId: e,
3521
- tokenFieldNames: b
3522
- }), c.abort(f);
3523
- }
3524
- }
3525
- };
3526
- }
3527
- });
3528
- }
3529
- function qo(e) {
3530
- return Rr({
3531
- id: e.id,
3532
- defaultPlaceholderSelector: e.defaultPlaceholderSelector,
3533
- defaultTokenFieldNames: e.defaultTokenFieldNames,
3534
- setup: async (t) => {
3535
- const r = [], n = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
3536
- let o = t.services.placeholder.getPrimary(), a = !1, s = null;
3537
- const l = async () => (s || (G.log("Loading captcha provider API.", {
3538
- moduleId: e.id
3539
- }), s = e.load(t)), s), d = async (c) => {
3540
- const b = n.get(c);
3541
- if (t.services.errors.clear(c), !b) {
3542
- c.innerHTML = "";
3543
- return;
3544
- }
3545
- const A = await l();
3546
- e.unmount && await e.unmount({
3547
- api: A,
3548
- widget: b,
3549
- placeholder: c,
3550
- services: t.services,
3551
- options: t.options,
3552
- provider: t.options.provider
3553
- }), n.delete(c), c.innerHTML = "", t.services.tokens.clear(), G.log("Unmounted captcha placeholder widget.", {
3554
- moduleId: e.id
3555
- }), o === c && (o = t.services.placeholder.getPrimary());
3556
- }, p = async (c) => {
3557
- if (a || n.has(c) || i.has(c))
3558
- return;
3559
- const b = (async () => {
3560
- const A = await l();
3561
- if (a || n.has(c))
3562
- return;
3563
- const f = t.services.placeholder.createContainer(c), v = await e.mount({
3564
- api: A,
3565
- placeholder: c,
3566
- container: f,
3567
- services: t.services,
3568
- options: t.options,
3569
- provider: t.options.provider
3570
- });
3571
- n.set(c, v), o = c, G.log("Mounted captcha placeholder widget.", {
3572
- moduleId: e.id
3573
- });
3574
- })().finally(() => {
3575
- i.delete(c);
3576
- });
3577
- i.set(c, b), await b;
3578
- }, h = t.services.placeholder.observe(
3579
- (c) => {
3580
- o = c, p(c);
3581
- },
3582
- (c) => {
3583
- d(c);
3584
- }
3585
- );
3586
- r.push(h.cleanup);
3587
- const u = async (c) => {
3588
- const A = h.getVisible();
3589
- if (e.reset) {
3590
- const f = await l();
3591
- for (const v of A) {
3592
- const E = n.get(v);
3593
- if (!E) {
3594
- await p(v);
3595
- continue;
3596
- }
3597
- await e.reset({
3598
- api: f,
3599
- widget: E,
3600
- placeholder: v,
3601
- services: t.services,
3602
- options: t.options,
3603
- provider: t.options.provider,
3604
- reason: c
3605
- }), t.services.tokens.clear(), t.services.errors.clear(v);
3606
- }
3607
- h.reconcile();
3608
- return;
3609
- }
3610
- for (const f of Array.from(n.keys()))
3611
- await d(f);
3612
- for (const f of A)
3613
- await p(f);
3614
- h.reconcile();
3615
- };
3616
- return r.push(t.services.events.onRoot("formie:submit:result", (c) => {
3617
- const b = c instanceof CustomEvent ? c.detail : null;
3618
- b?.stage !== "validate" && (b?.ok === !1 && b?.stage === "screen" || b?.ok !== !0 && u("submit-result"));
3619
- })), t.form && r.push(t.services.events.onForm(je("reset"), () => {
3620
- o = t.services.placeholder.getPrimary() || o, window.setTimeout(() => {
3621
- u("reset-state");
3622
- }, 0);
3623
- })), {
3624
- destroy: async () => {
3625
- a = !0, r.forEach((c) => {
3626
- c();
3627
- });
3628
- for (const c of Array.from(n.keys()))
3629
- await d(c);
3630
- },
3631
- onBeforeStage: async (c) => {
3632
- if (c.stage !== "screen" || c.action !== "submit")
3633
- return;
3634
- const b = h.getVisible();
3635
- if (b.length === 0)
3636
- return;
3637
- let A = b.find((E) => E === o) || b[0];
3638
- await p(A), A = o || A, t.services.errors.clear(A);
3639
- const f = n.get(A);
3640
- if (!f) {
3641
- const E = t.services.errors.getDefaultMessage();
3642
- t.services.errors.show(E, A), G.warn("Captcha widget unavailable at screen stage.", {
3643
- moduleId: e.id
3644
- }), c.abort(E);
3645
- return;
3646
- }
3647
- const v = await l();
3648
- await e.screen({
3649
- api: v,
3650
- widget: f,
3651
- placeholder: A,
3652
- services: t.services,
3653
- options: t.options,
3654
- provider: t.options.provider,
3655
- stageCtx: c
3656
- });
3657
- }
3658
- };
3659
- }
3660
- });
3661
- }
3662
- const wa = qo, Ta = Po, Ht = 2500, Vo = {
3663
- bpoint: ["bpointToken"],
3664
- stripe: ["stripePaymentIntentId"],
3665
- paypal: ["paypalOrderId", "paypalAuthId"],
3666
- payway: ["paywayTokenId"],
3667
- opayo: ["opayoTokenId"],
3668
- eway: ["ewayTokenData"],
3669
- "go-cardless": ["goCardlessRedirectId"],
3670
- mollie: ["molliePaymentId"],
3671
- moneris: ["monerisTokenId"],
3672
- paddle: ["paddleTransactionId"],
3673
- square: ["squarePaymentId"]
3674
- };
3675
- function Oo(e) {
3676
- return e.replace("{field:", "").replace("{", "").replace("}", "").replace("]", "").split("[").join("][");
3677
- }
3678
- function $o(e) {
3679
- return `fields[${Oo(e)}]`;
3680
- }
3681
- function Ho(e, t) {
3682
- const r = $o(t), n = Array.from(e.querySelectorAll(`[name="${r}"]`)), i = Array.from(e.querySelectorAll(`[name="${r}[]"]`));
3683
- return (i.length ? i : n).filter((o) => o instanceof HTMLElement);
3684
- }
3685
- function _t(e, t) {
3686
- const r = Ho(e, t);
3687
- for (const n of r) {
3688
- const o = n.closest("[data-formie-field-handle]")?.querySelector("[data-formie-field-label]")?.childNodes[0]?.textContent?.trim();
3689
- if (o)
3690
- return o;
3691
- }
3692
- return "";
3693
- }
3694
- function Ue(e) {
3695
- let t = e.replace(/[^\d.,-]/g, "");
3696
- const r = t.includes(","), n = t.includes(".");
3697
- return r && n ? t = t.replace(/\./g, "").replace(/,/, ".") : r && !n ? t = t.replace(/,/, ".") : t = t.replace(/,/g, ""), parseFloat(t);
3698
- }
3699
- function _o(e) {
3700
- return e.replace(/^\{field:/, "").replace(/^\{/, "").replace(/\}$/, "").trim();
3701
- }
3702
- function de(e) {
3703
- return _o(e).replace(/\]/g, "").split("[").join(".").replace(/\.+/g, ".").replace(/^\./, "").replace(/\.$/, "");
3704
- }
3705
- function Fr(e) {
3706
- const r = de(e).split(".").filter(Boolean);
3707
- if (!r.length)
3708
- return "";
3709
- const [n, ...i] = r;
3710
- return `fields[${n}]${i.map((o) => `[${o}]`).join("")}`;
3711
- }
3712
- function Do(e) {
3713
- const r = String(e || "").trim().match(/^fields\[([^\]]+)\](.*)$/);
3714
- if (!r)
3715
- return "";
3716
- const n = r[1] || "", i = r[2] || "", o = Array.from(i.matchAll(/\[([^\]]+)\]/g)).map((a) => a[1] || "").filter(Boolean);
3717
- return [n, ...o].join(".");
3718
- }
3719
- function xo(e) {
3720
- const t = e.split(";").map((a) => a.trim()).filter(Boolean);
3721
- if (!t.length)
3722
- return {
3723
- source: "",
3724
- transforms: []
3725
- };
3726
- const [r, ...n] = t, i = [];
3727
- let o = null;
3728
- return n.forEach((a) => {
3729
- if (a.startsWith("transform=")) {
3730
- o && i.push(o), o = {
3731
- id: decodeURIComponent(a.slice(10) || "").trim(),
3732
- params: {}
3733
- };
3734
- return;
3735
- }
3736
- if (!o || !a.includes("="))
3737
- return;
3738
- const [s, l] = a.split("=", 2), d = (s || "").trim();
3739
- !d || d === "transform" || (o.params[d] = decodeURIComponent(l || "").trim());
3740
- }), o && i.push(o), {
3741
- source: r || "",
3742
- transforms: i
3743
- };
3744
- }
3745
- function kr(e) {
3746
- const t = String(e || "").trim();
3747
- if (!t)
3748
- return {
3749
- raw: t,
3750
- target: "",
3751
- key: "",
3752
- selector: "",
3753
- defaultValue: "",
3754
- transforms: [],
3755
- isToken: !1,
3756
- isValid: !1
3757
- };
3758
- const r = t.match(/^\{([a-zA-Z]+)(?::(.*))?\}$/);
3759
- if (!r)
3760
- return {
3761
- raw: t,
3762
- target: "",
3763
- key: de(t),
3764
- selector: "",
3765
- defaultValue: "",
3766
- transforms: [],
3767
- isToken: !1,
3768
- isValid: !0
3769
- };
3770
- const n = (r[1] || "").trim().toLowerCase(), i = (r[2] || "").trim(), [o, a = ""] = i.split("|", 2), { source: s, transforms: l } = xo(o || "");
3771
- if (n !== "field")
3772
- return {
3773
- raw: t,
3774
- target: "",
3775
- key: "",
3776
- selector: "",
3777
- defaultValue: a.trim(),
3778
- transforms: l,
3779
- isToken: !0,
3780
- isValid: !1
3781
- };
3782
- const d = s.indexOf(":"), p = d === -1 ? s : s.slice(0, d), h = d === -1 ? "" : s.slice(d + 1), u = de(p);
3783
- return {
3784
- raw: t,
3785
- target: "field",
3786
- key: u,
3787
- selector: h.trim(),
3788
- defaultValue: a.trim(),
3789
- transforms: l,
3790
- isToken: !0,
3791
- isValid: u !== ""
3792
- };
3793
- }
3794
- function No(e) {
3795
- return e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement;
3796
- }
3797
- function Uo(e, t, r) {
3798
- const n = t.trim(), i = String(r.name || "").trim();
3799
- if (!n || !i)
3800
- return;
3801
- const o = e.get(n) || {
3802
- key: n,
3803
- names: [],
3804
- inputs: []
3805
- };
3806
- o.names.includes(i) || o.names.push(i), o.inputs.includes(r) || o.inputs.push(r), e.set(n, o);
3807
- }
3808
- function Bo(e) {
3809
- const t = /* @__PURE__ */ new Map();
3810
- return Array.from(e.querySelectorAll("[name]")).filter((n) => No(n)).forEach((n) => {
3811
- const i = Do(n.name);
3812
- i && Uo(t, i, n);
3813
- }), t;
3814
- }
3815
- function jo(e) {
3816
- if (!e.length)
3817
- return "";
3818
- const t = e[0];
3819
- if (t instanceof HTMLSelectElement && t.multiple)
3820
- return Array.from(t.selectedOptions).map((n) => n.value);
3821
- if (e.some((n) => n instanceof HTMLInputElement && (n.type === "checkbox" || n.type === "radio"))) {
3822
- const n = e.flatMap((i) => !(i instanceof HTMLInputElement) || !i.checked ? [] : [i.value]);
3823
- return n.length > 1 ? n : n[0] || "";
3824
- }
3825
- return t.value;
3826
- }
3827
- function Pr(e, t) {
3828
- return e.get(de(t)) || null;
3829
- }
3830
- function zo(e, t) {
3831
- const r = kr(e), n = r.key, i = Pr(t, n);
3832
- if (!i)
3833
- return {
3834
- key: n,
3835
- value: r.defaultValue,
3836
- found: !1
3837
- };
3838
- const o = jo(i.inputs);
3839
- return {
3840
- key: n,
3841
- value: o === "" && r.defaultValue !== "" ? r.defaultValue : o,
3842
- found: !0
3843
- };
3844
- }
3845
- function Ma(e, t, r) {
3846
- const n = kr(e), i = n.key;
3847
- if (!i)
3848
- return {
3849
- key: i,
3850
- value: n.defaultValue,
3851
- found: !1
3852
- };
3853
- const o = r ? Pr(r, i) : null, s = (o?.names?.length ? o.names : [Fr(i)]).flatMap((l) => {
3854
- const d = t.getAll(l).map((p) => String(p ?? ""));
3855
- return d.length ? d : t.getAll(`${l}[]`).map((p) => String(p ?? ""));
3856
- }).filter((l) => l !== "");
3857
- return s.length ? {
3858
- key: i,
3859
- value: s.length > 1 ? s : s[0],
3860
- found: !0
3861
- } : {
3862
- key: i,
3863
- value: n.defaultValue,
3864
- found: !1
3865
- };
3866
- }
3867
- function qr(e, t) {
3868
- const r = t.replace(/"/g, '\\"');
3869
- return e.querySelector(`input[name$="[${r}]"]`) || e.querySelector(`input[name$="${r}"]`);
3870
- }
3871
- function Ae(e, t) {
3872
- const r = t.find((n) => {
3873
- const i = qr(e, n);
3874
- return !i || String(i.value || "").trim() === "";
3875
- });
3876
- return {
3877
- ok: !r,
3878
- missingSuffix: r
3879
- };
3880
- }
3881
- async function Vr(e, t, r) {
3882
- const n = Ae(e, t);
3883
- if (n.ok)
3884
- return n;
3885
- const i = Date.now() + Math.max(r, 0);
3886
- for (; Date.now() < i; ) {
3887
- await ht(120);
3888
- const o = Ae(e, t);
3889
- if (o.ok)
3890
- return o;
3891
- }
3892
- return Ae(e, t);
3893
- }
3894
- const Wo = /* @__PURE__ */ new Set([
3895
- "handle",
3896
- "requiredInputSuffixes",
3897
- "waitForValueMs",
3898
- "errorMessage"
3899
- ]), Dt = "[data-payment-success]", xt = "[data-payment-error]";
3900
- function Ko(e, t) {
3901
- return (typeof t.handle == "string" && t.handle.trim() !== "" ? t.handle.trim() : "") || e;
3902
- }
3903
- function Go(e, t, r) {
3904
- const n = t || {}, i = Object.entries(n).reduce((l, [d, p]) => (Wo.has(d) || (l[d] = p), l), {}), o = Array.isArray(n.requiredInputSuffixes) ? n.requiredInputSuffixes.map(String).filter(Boolean) : r.defaultRequiredInputSuffixes || [], a = Number(n.waitForValueMs ?? r.defaultWaitForValueMs ?? Ht), s = typeof n.errorMessage == "string" && n.errorMessage.trim() !== "" ? n.errorMessage.trim() : "Payment authorization is incomplete.";
3905
- return {
3906
- handle: Ko(e, n),
3907
- transport: {
3908
- requiredInputSuffixes: o,
3909
- waitForValueMs: Number.isFinite(a) ? a : Ht,
3910
- errorMessage: s
3911
- },
3912
- provider: i
3913
- };
3914
- }
3915
- function Nt(e, t, r) {
3916
- return e.addEventListener(t, r), () => {
3917
- e.removeEventListener(t, r);
3918
- };
3919
- }
3920
- function Jo(e, t) {
3921
- const r = e.target, n = e.form, i = e.root, o = n || i, a = t.transport.requiredInputSuffixes, s = () => Bo(n || i), l = (y) => {
3922
- const g = zo(y, s()).value;
3923
- return Array.isArray(g) ? g[0] || "" : String(g || "");
3924
- };
3925
- return {
3926
- root: i,
3927
- form: n,
3928
- field: r,
3929
- updateInputs: (y, m) => {
3930
- const g = Array.isArray(y) ? y : [y];
3931
- for (const S of g) {
3932
- const M = qr(o, S) ?? r.querySelector(`input[name*="${S}"]`);
3933
- M && (M.value = m);
3934
- }
3935
- },
3936
- addError: (y) => {
3937
- const m = r.querySelector("[data-formie-field-type] > div, [data-field-type] > div") || r, g = m.querySelector(xt);
3938
- g && g.remove();
3939
- const S = document.createElement("div");
3940
- S.setAttribute("data-payment-error", ""), S.textContent = y, O(S, n || i, "fieldError"), m.appendChild(S);
3941
- },
3942
- removeError: () => {
3943
- r.querySelector(xt)?.remove();
3944
- },
3945
- addSuccess: (y) => {
3946
- const m = r.querySelector("[data-formie-field-type] > div, [data-field-type] > div") || r, g = m.querySelector(Dt);
3947
- g && g.remove();
3948
- const S = document.createElement("div");
3949
- S.setAttribute("data-payment-success", ""), S.textContent = y, O(S, n || i, "successMessage"), m.appendChild(S);
3950
- },
3951
- removeSuccess: () => {
3952
- r.querySelector(Dt)?.remove();
3953
- },
3954
- hasToken: () => Ae(o, a).ok,
3955
- waitForToken: (y = t.transport.waitForValueMs) => Vr(o, a, y).then((m) => m.ok),
3956
- getFieldValue: (y, m = "string") => {
3957
- const g = l(y);
3958
- return m === "float" || m === "int" || m === "number" ? Ue(g) : g;
3959
- },
3960
- resolveAmount: (y) => {
3961
- const m = n || i, S = String(y.type || "").toLowerCase() === "dynamic" && typeof y.variable == "string" && y.variable.trim() !== "", M = y.value ?? (S ? y.variable : y.fixed), T = String(M ?? "").trim(), R = typeof M == "number" ? M : Ue(T);
3962
- if (Number.isFinite(R) && R > 0)
3963
- return { ok: !0, value: R };
3964
- if (T !== "") {
3965
- const P = l(T), w = Ue(P);
3966
- if (Number.isFinite(w) && w > 0)
3967
- return { ok: !0, value: w };
3968
- const q = _t(m, T);
3969
- if (!P)
3970
- return {
3971
- ok: !1,
3972
- error: q ? x('Provide a value for "{label}" to proceed.', { label: q }) : x("Provide a payment amount to proceed.")
3973
- };
3974
- }
3975
- return {
3976
- ok: !1,
3977
- error: x("Payment amount must be greater than 0.")
3978
- };
3979
- },
3980
- resolveCurrency: (y) => {
3981
- const m = n || i, S = String(y.type || "").toLowerCase() === "dynamic" && typeof y.variable == "string" && y.variable.trim() !== "", M = y.value ?? (S ? y.variable : y.fixed ?? y.defaultCurrency ?? ""), T = String(M ?? "").trim(), R = T.toUpperCase();
3982
- if (/^[A-Z]{3}$/.test(R) && !S)
3983
- return { ok: !0, value: R };
3984
- if (T !== "") {
3985
- const P = String(l(T) || "").trim(), w = P.toUpperCase();
3986
- if (/^[A-Z]{3}$/.test(w))
3987
- return { ok: !0, value: w };
3988
- const q = _t(m, T);
3989
- if (!P)
3990
- return {
3991
- ok: !1,
3992
- error: q ? x('Provide a value for "{label}" to proceed.', { label: q }) : x("Provide a payment currency to proceed.")
3993
- };
3994
- }
3995
- return {
3996
- ok: !1,
3997
- error: x("Payment currency must be a valid 3-letter code.")
3998
- };
3999
- },
4000
- watchFieldValueChanges: (y, m, g = 600) => {
4001
- const S = n || i, M = y.map((q) => String(q || "").trim()).filter(Boolean);
4002
- if (M.length === 0)
4003
- return () => {
4004
- };
4005
- const T = s(), R = /* @__PURE__ */ new Set();
4006
- M.forEach((q) => {
4007
- const N = de(q), z = T.get(N);
4008
- if (z?.names?.length) {
4009
- z.names.forEach((fe) => {
4010
- R.add(fe);
4011
- });
4012
- return;
4013
- }
4014
- const Y = Fr(N);
4015
- Y && (R.add(Y), R.add(`${Y}[]`));
4016
- });
4017
- const P = Mr(() => {
4018
- m();
4019
- }, g), w = (q) => {
4020
- const z = q.target?.name || "";
4021
- !z || !R.has(z) || P();
4022
- };
4023
- return S.addEventListener("input", w), S.addEventListener("change", w), () => {
4024
- S.removeEventListener("input", w), S.removeEventListener("change", w);
4025
- };
4026
- },
4027
- triggerSubmit: () => {
4028
- n && n.setAttribute("data-formie-internal-resubmit", "true"), n && typeof n.requestSubmit == "function" ? n.requestSubmit() : n && n.submit();
4029
- },
4030
- releaseSubmitLoading: () => {
4031
- n && (n.removeAttribute("data-formie-internal-resubmit"), Me(n));
4032
- },
4033
- getBillingData: (y) => {
4034
- const m = {};
4035
- if (!y || typeof y != "object")
4036
- return { billing_details: m };
4037
- if (y.billingName) {
4038
- const g = l(y.billingName);
4039
- g && (m.name = g);
4040
- }
4041
- if (y.billingEmail) {
4042
- const g = l(y.billingEmail);
4043
- g && (m.email = g);
4044
- }
4045
- if (y.billingAddress) {
4046
- const g = y.billingAddress, S = {}, M = l(`${g}.address1`), T = l(`${g}.address2`), R = l(`${g}.address3`), P = l(`${g}.city`), w = l(`${g}.zip`), q = l(`${g}.state`), N = l(`${g}.country`);
4047
- M && (S.line1 = M), T && (S.line2 = T), R && (S.line3 = R), P && (S.city = P), w && (S.postal_code = w), q && (S.state = q), N && (S.country = N), Object.keys(S).length && (m.address = S);
4048
- }
4049
- return { billing_details: m };
4050
- },
4051
- events: {
4052
- onForm: (y, m) => n ? Nt(n, y, m) : () => {
4053
- },
4054
- onRoot: (y, m) => Nt(i, y, m)
4055
- }
4056
- };
4057
- }
4058
- const U = _("payments");
4059
- function Ut(e) {
4060
- const t = e;
4061
- return !t.closest("[data-formie-page-hidden]") && !t.closest("[hidden]");
4062
- }
4063
- function Yo(e) {
4064
- const t = e.defaultRequiredInputSuffixes ?? Vo[e.id] ?? [];
4065
- return {
4066
- id: e.id,
4067
- kind: "payment",
4068
- match: (r) => !!(r.target.querySelector('[data-formie-field-type="payment"]') || r.target.closest('[data-formie-field-type="payment"]') || r.target.getAttribute?.("data-formie-field-type") === "payment"),
4069
- setup: async (r) => {
4070
- const n = r.target, i = n.__formiePaymentModuleRegistry || {};
4071
- n.__formiePaymentModuleRegistry = i;
4072
- const o = i[e.id];
4073
- if (o?.destroy) {
4074
- U.warn("Found stale payment module instance; destroying previous.", {
4075
- moduleId: e.id
4076
- });
4077
- try {
4078
- await o.destroy();
4079
- } catch {
4080
- }
4081
- }
4082
- const a = Go(
4083
- e.id,
4084
- r.options || {},
4085
- {
4086
- defaultRequiredInputSuffixes: t
4087
- }
4088
- ), s = Jo(r, a), l = {
4089
- ...r,
4090
- options: a,
4091
- services: s
4092
- }, d = [];
4093
- let p = null, h = null, u = null, c = null;
4094
- const b = async () => (p || (U.log("Loading payment provider API.", { moduleId: e.id }), p = e.load(l)), p), A = async () => {
4095
- if (!e.mount || h || !Ut(r.target))
4096
- return;
4097
- const E = await b();
4098
- try {
4099
- h = await e.mount({
4100
- api: E,
4101
- field: r.target,
4102
- services: s,
4103
- options: a,
4104
- provider: a.provider
4105
- }), U.log("Payment widget mounted.", {
4106
- moduleId: e.id,
4107
- handle: a.handle
4108
- });
4109
- } catch {
4110
- U.warn("Payment widget mount failed.", {
4111
- moduleId: e.id,
4112
- handle: a.handle
4113
- });
4114
- }
4115
- };
4116
- if (d.push(r.on("formie:submit:before", () => {
4117
- s.removeError(), s.removeSuccess();
4118
- })), e.setup) {
4119
- const E = r.root || r.form || r.target;
4120
- u = await e.setup({ ...l, root: E }), u.destroy && d.push(u.destroy);
4121
- }
4122
- e.mount && Ut(r.target) && await A(), ["formie:page:navigate:after", "formie:submit:result"].forEach((E) => {
4123
- const y = () => {
4124
- A();
4125
- };
4126
- r.root.addEventListener(E, y), d.push(() => {
4127
- r.root.removeEventListener(E, y);
4128
- });
4129
- });
4130
- const v = async () => {
4131
- if (U.log("Destroying payment module.", {
4132
- moduleId: e.id,
4133
- handle: a.handle
4134
- }), d.forEach((E) => E()), h && e.unmount) {
4135
- const E = await b();
4136
- await e.unmount({
4137
- api: E,
4138
- widget: h,
4139
- field: r.target,
4140
- services: s,
4141
- options: a,
4142
- provider: a.provider
4143
- }), U.log("Payment widget unmounted.", {
4144
- moduleId: e.id,
4145
- handle: a.handle
4146
- });
4147
- }
4148
- i[e.id]?.destroy === v && delete i[e.id], U.log("Payment module destroy complete.", {
4149
- moduleId: e.id,
4150
- handle: a.handle
4151
- });
4152
- };
4153
- return i[e.id] = { destroy: v }, {
4154
- destroy: v,
4155
- onBeforeStage: async (E) => {
4156
- if (u?.onBeforeStage) {
4157
- await u.onBeforeStage(E);
4158
- return;
4159
- }
4160
- if (E.stage !== "authorize" || E.action !== "submit" || r.target.closest("[data-formie-page]")?.hasAttribute("data-formie-page-hidden"))
4161
- return;
4162
- await A();
4163
- const g = await b();
4164
- if (e.onBeforeAuthorize) {
4165
- c || (c = (async () => e.onBeforeAuthorize({
4166
- api: g,
4167
- widget: h,
4168
- field: r.target,
4169
- services: s,
4170
- options: a,
4171
- provider: a.provider,
4172
- stageCtx: E
4173
- }))().finally(() => {
4174
- c = null;
4175
- }));
4176
- const T = await c;
4177
- if (U.log("onBeforeAuthorize resolved.", {
4178
- moduleId: e.id,
4179
- handle: a.handle,
4180
- ok: T
4181
- }), !T) {
4182
- E.abort(a.transport.errorMessage);
4183
- return;
4184
- }
4185
- return;
4186
- }
4187
- if (a.transport.requiredInputSuffixes.length === 0)
4188
- return;
4189
- const S = r.form || r.root, M = await Vr(
4190
- S,
4191
- a.transport.requiredInputSuffixes,
4192
- a.transport.waitForValueMs
4193
- );
4194
- M.ok || (U.warn("Required payment input(s) missing.", {
4195
- moduleId: e.id,
4196
- handle: a.handle,
4197
- missingSuffix: M.missingSuffix
4198
- }), E.abort(a.transport.errorMessage));
4199
- },
4200
- onAfterStage: async (E, y) => {
4201
- E.stage !== "dispatch" || !e.onAfterSubmit || await e.onAfterSubmit({
4202
- field: r.target,
4203
- services: s,
4204
- options: a,
4205
- provider: a.provider,
4206
- result: y
4207
- });
4208
- }
4209
- };
4210
- }
4211
- };
4212
- }
4213
- const Ca = Yo, Zo = "[data-formie-address-autocomplete-input]", Bt = "[data-formie-address-location]", Qo = {
4214
- autoComplete: "[data-formie-address-autocomplete-input]",
4215
- address1: "[data-formie-address-line1-input]",
4216
- address2: "[data-formie-address-line2-input]",
4217
- address3: "[data-formie-address-line3-input]",
4218
- city: "[data-formie-address-city-input]",
4219
- state: "[data-formie-address-state-input]",
4220
- zip: "[data-formie-address-zip-input]",
4221
- country: "[data-formie-address-country-input]"
4222
- }, Xo = /* @__PURE__ */ new Set(["handle"]);
4223
- function ea(e, t) {
4224
- return (typeof t.handle == "string" && t.handle.trim() !== "" ? t.handle.trim() : "") || e;
4225
- }
4226
- function ta(e, t) {
4227
- const r = t || {}, n = Object.entries(r).reduce((i, [o, a]) => (Xo.has(o) || (i[o] = a), i), {});
4228
- return {
4229
- handle: ea(e, r),
4230
- provider: n
4231
- };
4232
- }
4233
- function ra(e, t, r) {
4234
- return e.addEventListener(t, r), () => {
4235
- e.removeEventListener(t, r);
4236
- };
4237
- }
4238
- function na(e) {
4239
- const t = e.target, r = e.form, n = e.root, i = Zo;
4240
- return {
4241
- root: n,
4242
- field: t,
4243
- form: r,
4244
- input: {
4245
- getAutocomplete: () => t.querySelector(i),
4246
- setValue: (o, a, s) => {
4247
- const l = Qo[o], d = t.querySelector(l);
4248
- d && (d.value = a || s || "");
4249
- }
4250
- },
4251
- location: {
4252
- getButton: () => t.querySelector(Bt),
4253
- onUseLocation: (o) => {
4254
- const a = t.querySelector(Bt);
4255
- if (!a)
4256
- return () => {
4257
- };
4258
- const s = (l) => {
4259
- l.preventDefault(), navigator.geolocation && navigator.geolocation.getCurrentPosition(
4260
- o,
4261
- () => {
4262
- },
4263
- { enableHighAccuracy: !0 }
4264
- );
4265
- };
4266
- return a.addEventListener("click", s), () => {
4267
- a.removeEventListener("click", s);
4268
- };
4269
- }
4270
- },
4271
- events: {
4272
- onField: (o, a) => ra(t, o, a)
4273
- }
4274
- };
4275
- }
4276
- const te = _("address");
4277
- function jt(e) {
4278
- const t = e;
4279
- return !t.closest("[data-formie-page-hidden]") && !t.closest("[hidden]");
4280
- }
4281
- function ia(e) {
4282
- return {
4283
- id: e.id,
4284
- kind: "address",
4285
- match: (t) => !!t.target.querySelector("[data-formie-address-autocomplete-input]"),
4286
- setup: async (t) => {
4287
- const r = ta(e.id, t.options || {}), n = na(t);
4288
- te.log("Setup module.", {
4289
- moduleId: e.id
4290
- });
4291
- const i = {
4292
- ...t,
4293
- options: r,
4294
- services: n
4295
- }, o = [];
4296
- let a = null, s = null;
4297
- if (!n.input.getAutocomplete())
4298
- return console.warn(
4299
- `[formie] Address module "${e.id}" skipped: no autocomplete input found in target. Ensure the Address field has the Auto-Complete subfield enabled.`
4300
- ), te.warn("Autocomplete input missing; skipping module.", {
4301
- moduleId: e.id
4302
- }), {
4303
- destroy: () => {
4304
- }
4305
- };
4306
- const d = async () => (a || (te.log("Loading provider API.", {
4307
- moduleId: e.id
4308
- }), a = e.load(i)), a), p = async () => {
4309
- if (s || !jt(t.target))
4310
- return;
4311
- const c = await d();
4312
- s = await e.mount({
4313
- api: c,
4314
- field: t.target,
4315
- services: n,
4316
- options: r,
4317
- provider: r.provider
4318
- }), te.log("Widget mounted.", {
4319
- moduleId: e.id
4320
- });
4321
- };
4322
- jt(t.target) && await p(), ["formie:page:navigate:after", "formie:submit:result"].forEach((c) => {
4323
- const b = () => {
4324
- p();
4325
- };
4326
- t.root.addEventListener(c, b), o.push(() => {
4327
- t.root.removeEventListener(c, b);
4328
- });
4329
- });
4330
- const u = n.location.onUseLocation((c) => {
4331
- e.onCurrentLocation && (async () => {
4332
- if (await p(), !s)
4333
- return;
4334
- const b = await d();
4335
- await e.onCurrentLocation?.(c, {
4336
- api: b,
4337
- widget: s,
4338
- field: t.target,
4339
- services: n,
4340
- options: r,
4341
- provider: r.provider
4342
- });
4343
- })();
4344
- });
4345
- return u && o.push(u), {
4346
- destroy: async () => {
4347
- if (te.log("Destroying module.", {
4348
- moduleId: e.id
4349
- }), o.forEach((c) => c()), s && e.unmount) {
4350
- const c = await d();
4351
- await e.unmount({
4352
- api: c,
4353
- widget: s,
4354
- field: t.target,
4355
- services: n,
4356
- options: r,
4357
- provider: r.provider
4358
- }), te.log("Widget unmounted.", {
4359
- moduleId: e.id
4360
- });
4361
- }
4362
- }
4363
- };
4364
- }
4365
- };
4366
- }
4367
- const La = ia;
4368
- export {
4369
- ga as $,
4370
- Qo as A,
4371
- Un as B,
4372
- ya as C,
4373
- oa as D,
4374
- Gr as E,
4375
- Nr as F,
4376
- Jr as G,
4377
- co as H,
4378
- Yr as I,
4379
- Zr as J,
4380
- ba as K,
4381
- Dr as L,
4382
- vr as M,
4383
- ir as N,
4384
- Br as O,
4385
- Ur as P,
4386
- ha as Q,
4387
- Do as R,
4388
- Wt as S,
4389
- pa as T,
4390
- aa as U,
4391
- kr as V,
4392
- Ma as W,
4393
- xr as X,
4394
- da as Y,
4395
- ma as Z,
4396
- Be as _,
4397
- wa as a,
4398
- Aa as b,
4399
- Ea as c,
4400
- La as d,
4401
- Ta as e,
4402
- va as f,
4403
- la as g,
4404
- _ as h,
4405
- Bo as i,
4406
- Fr as j,
4407
- sa as k,
4408
- ua as l,
4409
- je as m,
4410
- de as n,
4411
- Re as o,
4412
- Mr as p,
4413
- fa as q,
4414
- zo as r,
4415
- ht as s,
4416
- ue as t,
4417
- x as u,
4418
- Ca as v,
4419
- Sa as w,
4420
- ca as x,
4421
- O as y,
4422
- le as z
4423
- };