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