@verbb/formie-browser 1.0.13 → 1.0.15

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 (389) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/dist/chunks/{address-country-Rx6GQTND.js → address-country-BcEQKw0T.js} +11 -5
  3. package/dist/chunks/{address-finder-k7_BXaRe.js → address-finder-BWGINCSA.js} +3 -3
  4. package/dist/chunks/address-state-DI3ndhMU.js +365 -0
  5. package/dist/chunks/{api-BUb6P-xu.js → api-BK9b340y.js} +93 -63
  6. package/dist/chunks/{api-DqpfkZWL.js → api-Dxl_CKw-.js} +202 -193
  7. package/dist/chunks/{api-sPqGbOww.js → api-ghNr2uxX.js} +15 -9
  8. package/dist/chunks/{async-nPFRNQ06.js → async-2GdXNFCE.js} +18 -1
  9. package/dist/chunks/{bpoint-Dlq34XH1.js → bpoint-BwtuyN_O.js} +3 -3
  10. package/dist/chunks/calculations-YEoVCG2q.js +310 -0
  11. package/dist/chunks/{captcha-eu-CGm8Lbrj.js → captcha-eu-DWLoQFKB.js} +6 -5
  12. package/dist/chunks/{checkbox-radio-BY2aTCOG.js → checkbox-radio-gsm8QPJg.js} +74 -75
  13. package/dist/chunks/{combobox-C0EuExSI.js → combobox-Ba08_cHL.js} +340 -328
  14. package/dist/chunks/conditions-Ceeg6ReZ.js +467 -0
  15. package/dist/chunks/country-from-ip-DDj_mFki.js +29 -0
  16. package/dist/chunks/csrf-DxHg_ZYt.js +61 -0
  17. package/dist/chunks/{custom-google-maps-BsaSirEZ.js → custom-google-maps-C4l2S3GO.js} +9 -3
  18. package/dist/chunks/{custom-link-CJ1-FjEM.js → custom-link-CLazgKYH.js} +8 -2
  19. package/dist/chunks/{custom-maps-DYW_pBid.js → custom-maps-DqcAlD0v.js} +10 -4
  20. package/dist/chunks/{date-picker-F9BUBDSW.js → date-picker-DaPvMrop.js} +467 -443
  21. package/dist/chunks/{dist-D6i-VNgM.js → dist-ZLeW0zZ3.js} +1281 -453
  22. package/dist/chunks/{eway-D9_m8ooj.js → eway-uw0DzU-L.js} +5 -5
  23. package/dist/chunks/field-references.resolver-Ca8MguFv.js +104 -0
  24. package/dist/chunks/{file-upload-rqfZNqlH.js → file-upload-B8_mH012.js} +119 -99
  25. package/dist/chunks/friendly-captcha-v1-CVXaXgDO.js +34 -0
  26. package/dist/chunks/{friendly-captcha-v2-CLSAbkqx.js → friendly-captcha-v2-DkeIVTKI.js} +6 -5
  27. package/dist/chunks/{friendly-challenge-8uPatWqk.js → friendly-challenge-DPG9MJb1.js} +111 -102
  28. package/dist/chunks/{go-cardless-DAT3ZaQf.js → go-cardless-c4wLJdOt.js} +2 -2
  29. package/dist/chunks/google-address-JHYvjwgN.js +168 -0
  30. package/dist/chunks/{hcaptcha-CGLAmgjO.js → hcaptcha-Dt3ELLlP.js} +4 -4
  31. package/dist/chunks/{hidden-D7_Ch-QN.js → hidden-BZhXnNPe.js} +8 -2
  32. package/dist/chunks/http-C2QdHuWO.js +27 -0
  33. package/dist/chunks/{leaflet-src-j-lHNmhR.js → leaflet-src-DE6rv6M-.js} +42 -46
  34. package/dist/chunks/{loqate-CJPzBmSm.js → loqate-m51iPyO1.js} +3 -3
  35. package/dist/chunks/{mollie-Bibhl67p.js → mollie-Bn0PX173.js} +2 -2
  36. package/dist/chunks/{moneris-H2wSqk9h.js → moneris-BRbUvI4t.js} +3 -3
  37. package/dist/chunks/opayo-BwWdInEP.js +188 -0
  38. package/dist/chunks/{paddle-DkvIxQdG.js → paddle-CympHVvd.js} +4 -4
  39. package/dist/chunks/{password-validation-D06uH9va.js → password-validation-C8_uO_c_.js} +18 -12
  40. package/dist/chunks/{paypal-CQpAF7Ua.js → paypal-h75h6wae.js} +8 -6
  41. package/dist/chunks/{payway-CwDkC7YZ.js → payway-C9rHTCC_.js} +4 -4
  42. package/dist/chunks/{phone-country-D3ayr60L.js → phone-country-B8fv-L5_.js} +80 -63
  43. package/dist/chunks/{place-kit-BGHklIZ-.js → place-kit-BnZGQ-L1.js} +11 -11
  44. package/dist/chunks/{placekit-autocomplete.esm-DWVabQlq.js → placekit-autocomplete.esm-CZZERYur.js} +11 -15
  45. package/dist/chunks/{recaptcha-enterprise-XPId5-bS.js → recaptcha-enterprise-CUs8BO6V.js} +4 -4
  46. package/dist/chunks/{recaptcha-shared-CLYJvojk.js → recaptcha-shared-DTbTw-MF.js} +2 -2
  47. package/dist/chunks/{recaptcha-v2-checkbox-Cy-0PEPc.js → recaptcha-v2-checkbox-P1McW4Pv.js} +4 -4
  48. package/dist/chunks/{recaptcha-v2-invisible-BwRH540O.js → recaptcha-v2-invisible-FGDqozSP.js} +4 -4
  49. package/dist/chunks/{recaptcha-v3-No4Ykrhk.js → recaptcha-v3-CflUHeZD.js} +4 -4
  50. package/dist/chunks/{repeater-BVnPUqTj.js → repeater-CyhDbozO.js} +60 -40
  51. package/dist/chunks/request-profile-DhwkeCpS.js +10 -0
  52. package/dist/chunks/rich-text-uV4o_pGk.js +361 -0
  53. package/dist/chunks/{chunk-3b4jIN3o.js → rolldown-runtime-DtPi1Y-2.js} +2 -2
  54. package/dist/chunks/{scripts-CbQ7agX3.js → scripts-DrccjrFv.js} +1 -1
  55. package/dist/chunks/{sdk-BhHAYgga.js → sdk-lkwSvlpM.js} +282 -234
  56. package/dist/chunks/{shared-Bx9s0i0P.js → shared-OKhSay59.js} +27 -21
  57. package/dist/chunks/{signature-IOhuicje.js → signature-7cldFbqj.js} +138 -112
  58. package/dist/chunks/skip-CEW89ExY.js +7 -0
  59. package/dist/chunks/{snaptcha-DKx98oon.js → snaptcha-C3QLYxFT.js} +2 -2
  60. package/dist/chunks/{square-DwdcOI1G.js → square-C1z5DPVw.js} +9 -7
  61. package/dist/chunks/{stripe-DaoG2FT1.js → stripe-Dmkdkq1y.js} +11 -12
  62. package/dist/chunks/{summary-Dks0gXS3.js → summary-Bn-g5SDx.js} +48 -46
  63. package/dist/chunks/{survey-likert-DkE6bR7B.js → survey-likert-fk1hUPff.js} +7 -1
  64. package/dist/chunks/{survey-rank-DN6x4IZM.js → survey-rank-BsLGl2LX.js} +37 -25
  65. package/dist/chunks/{survey-rating-BnsNL9U5.js → survey-rating-DVS6e6fM.js} +17 -5
  66. package/dist/chunks/{table-CAjCJHrL.js → table-j7MlLLCc.js} +22 -16
  67. package/dist/chunks/{text-limit-BGaY0jhI.js → text-limit-LGMPhFuC.js} +40 -34
  68. package/dist/chunks/{theme-classes-Tv7q7ToE.js → theme-classes-DAQuEqdP.js} +1 -1
  69. package/dist/chunks/{turnstile-DJakPzQD.js → turnstile-ptihQfLl.js} +4 -4
  70. package/dist/chunks/{upload-manager-W-QDgxKD.js → upload-manager-BW7l-BhF.js} +459 -387
  71. package/dist/chunks/{utils-Vqp8i_RM.js → utils-DpUBPadZ.js} +20 -14
  72. package/dist/css/formie-base.css +104 -1
  73. package/dist/css/theme/_messages.css +2 -0
  74. package/dist/css/theme/_tokens.css +31 -25
  75. package/dist/css/theme/forms/_form.css +5 -1
  76. package/dist/index.d.ts +5 -4
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +1779 -1415
  79. package/dist/js/contracts/client.d.ts +5 -3
  80. package/dist/js/contracts/client.d.ts.map +1 -1
  81. package/dist/js/contracts/common.d.ts +2 -2
  82. package/dist/js/contracts/common.d.ts.map +1 -1
  83. package/dist/js/contracts/modules.d.ts +37 -12
  84. package/dist/js/contracts/modules.d.ts.map +1 -1
  85. package/dist/js/contracts/schema.d.ts +20 -38
  86. package/dist/js/contracts/schema.d.ts.map +1 -1
  87. package/dist/js/contracts/theme.d.ts +4 -1
  88. package/dist/js/contracts/theme.d.ts.map +1 -1
  89. package/dist/js/core/client-rendered-modules.d.ts +17 -0
  90. package/dist/js/core/client-rendered-modules.d.ts.map +1 -0
  91. package/dist/js/core/create-formie-client.d.ts.map +1 -1
  92. package/dist/js/core/field-error-aria.d.ts +23 -0
  93. package/dist/js/core/field-error-aria.d.ts.map +1 -0
  94. package/dist/js/core/hydrate-modules.d.ts +10 -8
  95. package/dist/js/core/hydrate-modules.d.ts.map +1 -1
  96. package/dist/js/core/submit-result-state.d.ts.map +1 -1
  97. package/dist/js/core/submit-result-ui.d.ts +3 -1
  98. package/dist/js/core/submit-result-ui.d.ts.map +1 -1
  99. package/dist/js/core/validation-focus.d.ts.map +1 -1
  100. package/dist/js/modules/address/address-finder.d.ts +1 -1
  101. package/dist/js/modules/address/address-finder.d.ts.map +1 -1
  102. package/dist/js/modules/address/factories.d.ts +3 -3
  103. package/dist/js/modules/address/factories.d.ts.map +1 -1
  104. package/dist/js/modules/address/google-address.d.ts +12 -1
  105. package/dist/js/modules/address/google-address.d.ts.map +1 -1
  106. package/dist/js/modules/address/index.d.ts +2 -2
  107. package/dist/js/modules/address/index.d.ts.map +1 -1
  108. package/dist/js/modules/address/loqate.d.ts +1 -1
  109. package/dist/js/modules/address/loqate.d.ts.map +1 -1
  110. package/dist/js/modules/address/place-kit.d.ts +1 -1
  111. package/dist/js/modules/address/place-kit.d.ts.map +1 -1
  112. package/dist/js/modules/captchas/captcha-eu.d.ts +1 -1
  113. package/dist/js/modules/captchas/captcha-eu.d.ts.map +1 -1
  114. package/dist/js/modules/captchas/factories.d.ts +11 -11
  115. package/dist/js/modules/captchas/factories.d.ts.map +1 -1
  116. package/dist/js/modules/captchas/friendly-captcha-v1.d.ts +1 -1
  117. package/dist/js/modules/captchas/friendly-captcha-v1.d.ts.map +1 -1
  118. package/dist/js/modules/captchas/friendly-captcha-v2.d.ts +1 -1
  119. package/dist/js/modules/captchas/friendly-captcha-v2.d.ts.map +1 -1
  120. package/dist/js/modules/captchas/hcaptcha.d.ts +1 -1
  121. package/dist/js/modules/captchas/hcaptcha.d.ts.map +1 -1
  122. package/dist/js/modules/captchas/index.d.ts +2 -2
  123. package/dist/js/modules/captchas/index.d.ts.map +1 -1
  124. package/dist/js/modules/captchas/recaptcha-enterprise.d.ts +1 -1
  125. package/dist/js/modules/captchas/recaptcha-enterprise.d.ts.map +1 -1
  126. package/dist/js/modules/captchas/recaptcha-v2-checkbox.d.ts +1 -1
  127. package/dist/js/modules/captchas/recaptcha-v2-checkbox.d.ts.map +1 -1
  128. package/dist/js/modules/captchas/recaptcha-v2-invisible.d.ts +1 -1
  129. package/dist/js/modules/captchas/recaptcha-v2-invisible.d.ts.map +1 -1
  130. package/dist/js/modules/captchas/recaptcha-v3.d.ts +1 -1
  131. package/dist/js/modules/captchas/recaptcha-v3.d.ts.map +1 -1
  132. package/dist/js/modules/captchas/snaptcha.d.ts +1 -1
  133. package/dist/js/modules/captchas/snaptcha.d.ts.map +1 -1
  134. package/dist/js/modules/captchas/turnstile.d.ts +1 -1
  135. package/dist/js/modules/captchas/turnstile.d.ts.map +1 -1
  136. package/dist/js/modules/fields/address-country.d.ts +2 -2
  137. package/dist/js/modules/fields/address-country.d.ts.map +1 -1
  138. package/dist/js/modules/fields/address-state.d.ts +2 -2
  139. package/dist/js/modules/fields/address-state.d.ts.map +1 -1
  140. package/dist/js/modules/fields/calculations.d.ts +2 -2
  141. package/dist/js/modules/fields/calculations.d.ts.map +1 -1
  142. package/dist/js/modules/fields/checkbox-radio.d.ts +2 -2
  143. package/dist/js/modules/fields/checkbox-radio.d.ts.map +1 -1
  144. package/dist/js/modules/fields/combobox.d.ts +2 -2
  145. package/dist/js/modules/fields/combobox.d.ts.map +1 -1
  146. package/dist/js/modules/fields/conditions/config.d.ts.map +1 -1
  147. package/dist/js/modules/fields/conditions/effects.d.ts +1 -0
  148. package/dist/js/modules/fields/conditions/effects.d.ts.map +1 -1
  149. package/dist/js/modules/fields/conditions/evaluator.d.ts +4 -1
  150. package/dist/js/modules/fields/conditions/evaluator.d.ts.map +1 -1
  151. package/dist/js/modules/fields/conditions/references.d.ts.map +1 -1
  152. package/dist/js/modules/fields/conditions/submission-context.d.ts +15 -0
  153. package/dist/js/modules/fields/conditions/submission-context.d.ts.map +1 -0
  154. package/dist/js/modules/fields/conditions/types.d.ts +3 -1
  155. package/dist/js/modules/fields/conditions/types.d.ts.map +1 -1
  156. package/dist/js/modules/fields/conditions/values.d.ts +1 -1
  157. package/dist/js/modules/fields/conditions/values.d.ts.map +1 -1
  158. package/dist/js/modules/fields/conditions.d.ts +2 -2
  159. package/dist/js/modules/fields/conditions.d.ts.map +1 -1
  160. package/dist/js/modules/fields/custom-google-maps.d.ts +2 -2
  161. package/dist/js/modules/fields/custom-google-maps.d.ts.map +1 -1
  162. package/dist/js/modules/fields/custom-link.d.ts +2 -2
  163. package/dist/js/modules/fields/custom-link.d.ts.map +1 -1
  164. package/dist/js/modules/fields/custom-maps.d.ts +2 -2
  165. package/dist/js/modules/fields/custom-maps.d.ts.map +1 -1
  166. package/dist/js/modules/fields/date-picker.d.ts +2 -2
  167. package/dist/js/modules/fields/date-picker.d.ts.map +1 -1
  168. package/dist/js/modules/fields/file-upload.d.ts +2 -2
  169. package/dist/js/modules/fields/file-upload.d.ts.map +1 -1
  170. package/dist/js/modules/fields/hidden.d.ts +2 -2
  171. package/dist/js/modules/fields/hidden.d.ts.map +1 -1
  172. package/dist/js/modules/fields/index.d.ts +2 -2
  173. package/dist/js/modules/fields/index.d.ts.map +1 -1
  174. package/dist/js/modules/fields/password-validation.d.ts +2 -2
  175. package/dist/js/modules/fields/password-validation.d.ts.map +1 -1
  176. package/dist/js/modules/fields/phone-country.d.ts +2 -2
  177. package/dist/js/modules/fields/phone-country.d.ts.map +1 -1
  178. package/dist/js/modules/fields/repeater.d.ts +2 -2
  179. package/dist/js/modules/fields/repeater.d.ts.map +1 -1
  180. package/dist/js/modules/fields/rich-text.d.ts +2 -2
  181. package/dist/js/modules/fields/rich-text.d.ts.map +1 -1
  182. package/dist/js/modules/fields/shared.d.ts +1 -0
  183. package/dist/js/modules/fields/shared.d.ts.map +1 -1
  184. package/dist/js/modules/fields/signature.d.ts +2 -2
  185. package/dist/js/modules/fields/signature.d.ts.map +1 -1
  186. package/dist/js/modules/fields/summary.d.ts +2 -2
  187. package/dist/js/modules/fields/summary.d.ts.map +1 -1
  188. package/dist/js/modules/fields/survey-likert.d.ts +2 -2
  189. package/dist/js/modules/fields/survey-likert.d.ts.map +1 -1
  190. package/dist/js/modules/fields/survey-rank.d.ts +2 -2
  191. package/dist/js/modules/fields/survey-rank.d.ts.map +1 -1
  192. package/dist/js/modules/fields/survey-rating.d.ts +2 -2
  193. package/dist/js/modules/fields/survey-rating.d.ts.map +1 -1
  194. package/dist/js/modules/fields/table.d.ts +2 -2
  195. package/dist/js/modules/fields/table.d.ts.map +1 -1
  196. package/dist/js/modules/fields/text-limit.d.ts +2 -2
  197. package/dist/js/modules/fields/text-limit.d.ts.map +1 -1
  198. package/dist/js/modules/fields/upload-manager.d.ts +2 -2
  199. package/dist/js/modules/fields/upload-manager.d.ts.map +1 -1
  200. package/dist/js/modules/loader.d.ts +10 -4
  201. package/dist/js/modules/loader.d.ts.map +1 -1
  202. package/dist/js/modules/payments/bpoint.d.ts +1 -1
  203. package/dist/js/modules/payments/bpoint.d.ts.map +1 -1
  204. package/dist/js/modules/payments/eway.d.ts +1 -1
  205. package/dist/js/modules/payments/eway.d.ts.map +1 -1
  206. package/dist/js/modules/payments/factories.d.ts +7 -7
  207. package/dist/js/modules/payments/factories.d.ts.map +1 -1
  208. package/dist/js/modules/payments/go-cardless.d.ts +1 -1
  209. package/dist/js/modules/payments/go-cardless.d.ts.map +1 -1
  210. package/dist/js/modules/payments/index.d.ts +2 -2
  211. package/dist/js/modules/payments/index.d.ts.map +1 -1
  212. package/dist/js/modules/payments/mollie.d.ts +1 -1
  213. package/dist/js/modules/payments/mollie.d.ts.map +1 -1
  214. package/dist/js/modules/payments/moneris.d.ts +1 -1
  215. package/dist/js/modules/payments/moneris.d.ts.map +1 -1
  216. package/dist/js/modules/payments/opayo.d.ts +1 -1
  217. package/dist/js/modules/payments/opayo.d.ts.map +1 -1
  218. package/dist/js/modules/payments/paddle.d.ts +1 -1
  219. package/dist/js/modules/payments/paddle.d.ts.map +1 -1
  220. package/dist/js/modules/payments/paypal.d.ts +1 -1
  221. package/dist/js/modules/payments/paypal.d.ts.map +1 -1
  222. package/dist/js/modules/payments/payway.d.ts +1 -1
  223. package/dist/js/modules/payments/payway.d.ts.map +1 -1
  224. package/dist/js/modules/payments/square.d.ts +1 -1
  225. package/dist/js/modules/payments/square.d.ts.map +1 -1
  226. package/dist/js/modules/payments/stripe.d.ts +1 -1
  227. package/dist/js/modules/payments/stripe.d.ts.map +1 -1
  228. package/dist/js/modules/payments/utils.d.ts +6 -0
  229. package/dist/js/modules/payments/utils.d.ts.map +1 -1
  230. package/dist/js/modules/registry.d.ts +6 -4
  231. package/dist/js/modules/registry.d.ts.map +1 -1
  232. package/dist/js/submit/pipeline.d.ts.map +1 -1
  233. package/dist/js/theme/browser-theme-state.generated.d.ts +24 -0
  234. package/dist/js/theme/browser-theme-state.generated.d.ts.map +1 -0
  235. package/dist/js/theme/theme-classes.d.ts +3 -3
  236. package/dist/js/theme/theme-classes.d.ts.map +1 -1
  237. package/dist/js/transport/forms-api.d.ts +5 -3
  238. package/dist/js/transport/forms-api.d.ts.map +1 -1
  239. package/dist/js/utils/async.d.ts +1 -0
  240. package/dist/js/utils/async.d.ts.map +1 -1
  241. package/dist/js/utils/country-from-ip.d.ts +2 -2
  242. package/dist/js/utils/country-from-ip.d.ts.map +1 -1
  243. package/dist/js/utils/csrf.d.ts +17 -0
  244. package/dist/js/utils/csrf.d.ts.map +1 -0
  245. package/dist/js/utils/field-references.parser.d.ts +1 -0
  246. package/dist/js/utils/field-references.parser.d.ts.map +1 -1
  247. package/dist/js/utils/field-references.resolver.d.ts.map +1 -1
  248. package/dist/js/utils/field-references.types.d.ts +1 -0
  249. package/dist/js/utils/field-references.types.d.ts.map +1 -1
  250. package/dist/js/utils/http.d.ts +3 -1
  251. package/dist/js/utils/http.d.ts.map +1 -1
  252. package/dist/js/utils/request-profile.d.ts +4 -0
  253. package/dist/js/utils/request-profile.d.ts.map +1 -0
  254. package/dist/js/utils/unload-warning.d.ts.map +1 -1
  255. package/dist/js/validation/rules/email.d.ts.map +1 -1
  256. package/dist/js/validation/rules/match.d.ts.map +1 -1
  257. package/dist/js/validation/rules/number.d.ts.map +1 -1
  258. package/dist/js/validation/rules/required.d.ts.map +1 -1
  259. package/dist/js/validation/rules/shared.d.ts.map +1 -1
  260. package/dist/js/validation/rules/url.d.ts.map +1 -1
  261. package/dist/js/validation/skip.d.ts +7 -0
  262. package/dist/js/validation/skip.d.ts.map +1 -0
  263. package/dist/js/validation/submit-readiness.d.ts.map +1 -1
  264. package/dist/js/validation/validator.d.ts.map +1 -1
  265. package/package.json +43 -12
  266. package/src/css/formie-base.css +104 -1
  267. package/src/css/theme/_messages.css +2 -0
  268. package/src/css/theme/_tokens.css +31 -25
  269. package/src/css/theme/forms/_form.css +5 -1
  270. package/src/index.ts +13 -8
  271. package/src/js/contracts/client.ts +5 -3
  272. package/src/js/contracts/common.ts +5 -6
  273. package/src/js/contracts/modules.ts +41 -12
  274. package/src/js/contracts/schema.ts +21 -43
  275. package/src/js/contracts/theme.ts +6 -1
  276. package/src/js/core/client-rendered-modules.ts +69 -0
  277. package/src/js/core/create-formie-client.ts +132 -86
  278. package/src/js/core/field-error-aria.ts +93 -0
  279. package/src/js/core/hydrate-modules.ts +54 -29
  280. package/src/js/core/submit-result-state.ts +51 -45
  281. package/src/js/core/submit-result-ui.ts +25 -68
  282. package/src/js/core/validation-focus.ts +20 -20
  283. package/src/js/modules/address/address-finder.ts +1 -1
  284. package/src/js/modules/address/factories.ts +15 -13
  285. package/src/js/modules/address/google-address.ts +102 -40
  286. package/src/js/modules/address/index.ts +2 -2
  287. package/src/js/modules/address/loqate.ts +1 -1
  288. package/src/js/modules/address/place-kit.ts +14 -8
  289. package/src/js/modules/captchas/captcha-eu.ts +2 -2
  290. package/src/js/modules/captchas/factories.ts +66 -42
  291. package/src/js/modules/captchas/friendly-captcha-v1.ts +12 -2
  292. package/src/js/modules/captchas/friendly-captcha-v2.ts +4 -2
  293. package/src/js/modules/captchas/hcaptcha.ts +5 -5
  294. package/src/js/modules/captchas/index.ts +2 -2
  295. package/src/js/modules/captchas/recaptcha-enterprise.ts +2 -2
  296. package/src/js/modules/captchas/recaptcha-v2-checkbox.ts +3 -3
  297. package/src/js/modules/captchas/recaptcha-v2-invisible.ts +2 -2
  298. package/src/js/modules/captchas/recaptcha-v3.ts +2 -2
  299. package/src/js/modules/captchas/snaptcha.ts +1 -1
  300. package/src/js/modules/captchas/turnstile.ts +3 -3
  301. package/src/js/modules/fields/address-country.ts +11 -9
  302. package/src/js/modules/fields/address-state.ts +94 -35
  303. package/src/js/modules/fields/calculations.ts +5 -3
  304. package/src/js/modules/fields/checkbox-radio.ts +24 -42
  305. package/src/js/modules/fields/combobox.ts +28 -9
  306. package/src/js/modules/fields/conditions/config.ts +17 -20
  307. package/src/js/modules/fields/conditions/effects.ts +25 -29
  308. package/src/js/modules/fields/conditions/evaluator.ts +21 -29
  309. package/src/js/modules/fields/conditions/references.ts +16 -5
  310. package/src/js/modules/fields/conditions/submission-context.ts +80 -0
  311. package/src/js/modules/fields/conditions/types.ts +3 -1
  312. package/src/js/modules/fields/conditions/values.ts +31 -6
  313. package/src/js/modules/fields/conditions.ts +65 -18
  314. package/src/js/modules/fields/custom-google-maps.ts +5 -3
  315. package/src/js/modules/fields/custom-link.ts +5 -3
  316. package/src/js/modules/fields/custom-maps.ts +5 -3
  317. package/src/js/modules/fields/date-picker.ts +40 -7
  318. package/src/js/modules/fields/file-upload.ts +62 -23
  319. package/src/js/modules/fields/hidden.ts +5 -3
  320. package/src/js/modules/fields/index.ts +2 -2
  321. package/src/js/modules/fields/password-validation.ts +5 -3
  322. package/src/js/modules/fields/phone-country.ts +35 -8
  323. package/src/js/modules/fields/repeater.ts +60 -7
  324. package/src/js/modules/fields/rich-text.ts +20 -4
  325. package/src/js/modules/fields/shared.ts +13 -0
  326. package/src/js/modules/fields/signature.ts +24 -4
  327. package/src/js/modules/fields/summary.ts +8 -20
  328. package/src/js/modules/fields/survey-likert.ts +5 -3
  329. package/src/js/modules/fields/survey-rank.ts +21 -3
  330. package/src/js/modules/fields/survey-rating.ts +17 -3
  331. package/src/js/modules/fields/table.ts +5 -3
  332. package/src/js/modules/fields/text-limit.ts +5 -3
  333. package/src/js/modules/fields/upload-manager.ts +244 -67
  334. package/src/js/modules/loader.ts +345 -281
  335. package/src/js/modules/payments/bpoint.ts +2 -2
  336. package/src/js/modules/payments/eway.ts +2 -2
  337. package/src/js/modules/payments/factories.ts +53 -52
  338. package/src/js/modules/payments/go-cardless.ts +1 -1
  339. package/src/js/modules/payments/index.ts +2 -2
  340. package/src/js/modules/payments/mollie.ts +1 -1
  341. package/src/js/modules/payments/moneris.ts +2 -2
  342. package/src/js/modules/payments/opayo.ts +21 -8
  343. package/src/js/modules/payments/paddle.ts +10 -6
  344. package/src/js/modules/payments/payment.ts +22 -18
  345. package/src/js/modules/payments/paypal.ts +1 -1
  346. package/src/js/modules/payments/payway.ts +2 -2
  347. package/src/js/modules/payments/square.ts +2 -2
  348. package/src/js/modules/payments/stripe.ts +5 -5
  349. package/src/js/modules/payments/utils.ts +14 -0
  350. package/src/js/modules/registry.ts +19 -11
  351. package/src/js/submit/pipeline.ts +10 -11
  352. package/src/js/theme/browser-theme-state.generated.ts +25 -0
  353. package/src/js/theme/theme-classes.ts +3 -3
  354. package/src/js/transport/forms-api.ts +66 -67
  355. package/src/js/utils/async.ts +34 -0
  356. package/src/js/utils/country-from-ip.ts +14 -9
  357. package/src/js/utils/csrf.ts +136 -0
  358. package/src/js/utils/field-references.parser.ts +13 -113
  359. package/src/js/utils/field-references.resolver.ts +27 -64
  360. package/src/js/utils/field-references.row-scope.ts +1 -1
  361. package/src/js/utils/field-references.types.ts +1 -0
  362. package/src/js/utils/http.ts +5 -5
  363. package/src/js/utils/request-profile.ts +10 -0
  364. package/src/js/utils/unload-warning.ts +12 -4
  365. package/src/js/validation/rules/email.ts +3 -5
  366. package/src/js/validation/rules/match.ts +2 -1
  367. package/src/js/validation/rules/minmax.ts +4 -43
  368. package/src/js/validation/rules/number.ts +3 -47
  369. package/src/js/validation/rules/pattern.ts +3 -8
  370. package/src/js/validation/rules/required.ts +14 -1
  371. package/src/js/validation/rules/shared.ts +5 -1
  372. package/src/js/validation/rules/url.ts +3 -10
  373. package/src/js/validation/skip.ts +9 -0
  374. package/src/js/validation/submit-readiness.ts +9 -2
  375. package/src/js/validation/validator.ts +49 -61
  376. package/dist/chunks/address-state-BwE01m2_.js +0 -344
  377. package/dist/chunks/calculations-Dv3hYb8_.js +0 -299
  378. package/dist/chunks/conditions-CPH1snCx.js +0 -424
  379. package/dist/chunks/country-from-ip-BwxKaBuJ.js +0 -26
  380. package/dist/chunks/field-references.resolver-CHwn0G0L.js +0 -145
  381. package/dist/chunks/friendly-captcha-v1-C_2reOXr.js +0 -31
  382. package/dist/chunks/google-address-BH3Zhi06.js +0 -161
  383. package/dist/chunks/http-D-JExro7.js +0 -27
  384. package/dist/chunks/opayo-CR0DtsLa.js +0 -179
  385. package/dist/chunks/rich-text-Bg_--4TG.js +0 -349
  386. package/dist/js/modules/fields/conditions/transforms.d.ts +0 -3
  387. package/dist/js/modules/fields/conditions/transforms.d.ts.map +0 -1
  388. package/src/js/modules/fields/conditions/transforms.ts +0 -206
  389. package/src/js/modules/payments/stub-payment-module.ts +0 -87
package/dist/index.js CHANGED
@@ -1,15 +1,20 @@
1
- import { c as e, d as t, l as n, o as r, r as i, t as a, u as o } from "./chunks/event-names-BCI2FLD8.js";
2
- import { a as s, c, d as l, f as u, i as d, l as f, n as p, o as m, p as h, r as g, s as _, t as v, u as y } from "./chunks/api-DqpfkZWL.js";
3
- import { a as b, i as x, n as ee, r as te, t as S } from "./chunks/debug-BV0DvdHx.js";
4
- import { n as ne, r as C, t as w } from "./chunks/theme-classes-Tv7q7ToE.js";
5
- import { t as T } from "./chunks/http-D-JExro7.js";
6
- import { a as E, i as D, n as re, r as ie, t as ae } from "./chunks/i18n-BY1ds1BL.js";
7
- import { n as oe, t as se } from "./chunks/api-BUb6P-xu.js";
8
- import { n as ce, r as le, t as ue } from "./chunks/field-references.keys-58ZSTrCW.js";
9
- import { i as de, n as fe, r as pe, t as me } from "./chunks/field-references.resolver-CHwn0G0L.js";
10
- import { t as he } from "./chunks/api-sPqGbOww.js";
1
+ import { n as e } from "./chunks/request-profile-DhwkeCpS.js";
2
+ import { i as t, m as n, t as r } from "./chunks/dist-ZLeW0zZ3.js";
3
+ import { c as i, d as a, l as o, o as s, r as c, t as l, u } from "./chunks/event-names-BCI2FLD8.js";
4
+ import { a as d, c as f, d as p, f as m, i as h, l as g, n as _, o as v, p as y, r as b, s as x, t as S, u as C } from "./chunks/api-Dxl_CKw-.js";
5
+ import { a as ee, i as te, n as w, r as T, t as E } from "./chunks/debug-BV0DvdHx.js";
6
+ import { i as D, r as ne, t as O } from "./chunks/theme-classes-DAQuEqdP.js";
7
+ import { n as k } from "./chunks/skip-CEW89ExY.js";
8
+ import { i as re, t as ie } from "./chunks/csrf-DxHg_ZYt.js";
9
+ import { n as A, t as ae } from "./chunks/http-C2QdHuWO.js";
10
+ import { i as oe } from "./chunks/async-2GdXNFCE.js";
11
+ import { a as se, i as ce, n as le, r as ue, t as de } from "./chunks/i18n-BY1ds1BL.js";
12
+ import { n as fe, t as pe } from "./chunks/api-BK9b340y.js";
13
+ import { n as me, r as he, t as ge } from "./chunks/field-references.keys-58ZSTrCW.js";
14
+ import { i as _e, n as ve, r as ye, t as be } from "./chunks/field-references.resolver-Ca8MguFv.js";
15
+ import { t as xe } from "./chunks/api-ghNr2uxX.js";
11
16
  //#region src/js/compatibility/event-map.ts
12
- var ge = [
17
+ var Se = [
13
18
  {
14
19
  legacyEvent: "onFormieLoaded",
15
20
  canonicalEvent: "formie:mount:after",
@@ -62,7 +67,7 @@ var ge = [
62
67
  canonicalEvent: "formie:submit:after",
63
68
  disposition: "approximate"
64
69
  }
65
- ], _e = [
70
+ ], Ce = [
66
71
  {
67
72
  legacyEvent: "formieValidatorInitialized",
68
73
  canonicalEvent: "formie:validator:ready",
@@ -84,7 +89,7 @@ var ge = [
84
89
  disposition: "safe"
85
90
  }
86
91
  ];
87
- function ve(e) {
92
+ function we(e) {
88
93
  if (!e) return {
89
94
  enabled: !1,
90
95
  legacyDomEvents: !1,
@@ -104,18 +109,18 @@ function ve(e) {
104
109
  }
105
110
  //#endregion
106
111
  //#region src/js/compatibility/dom-adapter.ts
107
- function ye(e, t, n) {
112
+ function Te(e, t, n) {
108
113
  e.dispatchEvent(new CustomEvent(t, {
109
114
  bubbles: !0,
110
115
  detail: n
111
116
  }));
112
117
  }
113
- function be(e, t) {
118
+ function Ee(e, t) {
114
119
  if (e.canonicalEvent !== "formie:submit:result") return !0;
115
120
  let n = t;
116
- return e.legacyEvent === "onAfterFormieSubmit" ? !!n?.ok : e.legacyEvent === "onFormieSubmitError" ? n?.ok === !1 : !0;
121
+ return e.legacyEvent === "onAfterFormieSubmit" ? !!n?.ok : e.legacyEvent !== "onFormieSubmitError" || n?.ok === !1;
117
122
  }
118
- function xe(e, t) {
123
+ function De(e, t) {
119
124
  let n = t && typeof t == "object" ? t : {}, r = typeof n.pageId == "string" ? n.pageId : "", i = Array.from(e.querySelectorAll("[data-formie-page-id]"));
120
125
  return { data: {
121
126
  nextPageId: r,
@@ -123,7 +128,7 @@ function xe(e, t) {
123
128
  totalPages: i.length
124
129
  } };
125
130
  }
126
- function Se(e, t, n, r, i) {
131
+ function Oe(e, t, n, r, i) {
127
132
  let a = globalThis.Formie || i;
128
133
  return e.legacyEvent === "onFormieLoaded" ? { formie: a } : e.legacyEvent === "onFormieInit" ? {
129
134
  formie: a,
@@ -135,44 +140,44 @@ function Se(e, t, n, r, i) {
135
140
  form: r,
136
141
  target: n,
137
142
  instance: i
138
- } : e.legacyEvent === "onFormiePageToggle" ? xe(r, t) : t;
143
+ } : e.legacyEvent === "onFormiePageToggle" ? De(r, t) : t;
139
144
  }
140
- function Ce({ target: e, form: n, instance: r, options: i, unbinds: a }) {
141
- i.legacyDomEvents && ge.forEach((i) => {
142
- let o = (t) => {
143
- !(t instanceof CustomEvent) || !be(i, t.detail) || ye(i.target === "document" ? document : n, i.legacyEvent, Se(i, t.detail, e, n, r));
145
+ function ke({ target: e, form: t, instance: n, options: r, unbinds: i }) {
146
+ r.legacyDomEvents && Se.forEach((r) => {
147
+ let o = (i) => {
148
+ i instanceof CustomEvent && Ee(r, i.detail) && Te(r.target === "document" ? document : t, r.legacyEvent, Oe(r, i.detail, e, t, n));
144
149
  };
145
- e.addEventListener(t(i.canonicalEvent), o), a.push(() => {
146
- e.removeEventListener(t(i.canonicalEvent), o);
150
+ e.addEventListener(a(r.canonicalEvent), o), i.push(() => {
151
+ e.removeEventListener(a(r.canonicalEvent), o);
147
152
  });
148
153
  });
149
154
  }
150
155
  //#endregion
151
156
  //#region src/js/compatibility/validator-adapter.ts
152
- function O(e, t, n) {
157
+ function j(e, t, n) {
153
158
  e.dispatchEvent(new CustomEvent(t, {
154
159
  bubbles: !0,
155
160
  detail: n
156
161
  }));
157
162
  }
158
- function k(e, t) {
163
+ function Ae(e, t) {
159
164
  return !!e && typeof e == "object" && e.validator === t;
160
165
  }
161
- function we({ target: e, form: t, validatorDetail: n, options: r, unbinds: i }) {
166
+ function je({ target: e, form: t, validatorDetail: n, options: r, unbinds: i }) {
162
167
  if (!r.legacyValidatorEvents || !n) return;
163
168
  let { validator: a, addValidator: o, removeValidator: s } = n, c = {
164
169
  ...n,
165
170
  form: t,
166
171
  target: e
167
172
  };
168
- O(document, "formieValidatorInitialized", c);
173
+ j(document, "formieValidatorInitialized", c);
169
174
  let l = (e) => {
170
- !(e instanceof CustomEvent) || !k(e.detail, a) || O(document, "formieValidatorDestroyed", {
175
+ e instanceof CustomEvent && Ae(e.detail, a) && j(document, "formieValidatorDestroyed", {
171
176
  ...c,
172
177
  ...e.detail
173
178
  });
174
179
  }, u = (n) => {
175
- !(n instanceof CustomEvent) || !k(n.detail, a) || !(n.target instanceof Element) || t.contains(n.target) && O(n.target, "formieValidatorShowError", {
180
+ n instanceof CustomEvent && Ae(n.detail, a) && n.target instanceof Element && t.contains(n.target) && j(n.target, "formieValidatorShowError", {
176
181
  ...n.detail,
177
182
  addValidator: o,
178
183
  removeValidator: s,
@@ -180,7 +185,7 @@ function we({ target: e, form: t, validatorDetail: n, options: r, unbinds: i })
180
185
  target: e
181
186
  });
182
187
  }, d = (n) => {
183
- !(n instanceof CustomEvent) || !k(n.detail, a) || !(n.target instanceof Element) || t.contains(n.target) && O(n.target, "formieValidatorClearError", {
188
+ n instanceof CustomEvent && Ae(n.detail, a) && n.target instanceof Element && t.contains(n.target) && j(n.target, "formieValidatorClearError", {
184
189
  ...n.detail,
185
190
  addValidator: o,
186
191
  removeValidator: s,
@@ -194,17 +199,17 @@ function we({ target: e, form: t, validatorDetail: n, options: r, unbinds: i })
194
199
  }
195
200
  //#endregion
196
201
  //#region src/js/core/error-aria-live.ts
197
- function Te(e) {
202
+ function Me(e) {
198
203
  let t = (e.dataset.formieErrorAriaLive || "polite").trim().toLowerCase();
199
204
  return t === "assertive" || t === "off" ? t : "polite";
200
205
  }
201
- function Ee(e, t) {
206
+ function Ne(e, t) {
202
207
  return e === "off" ? null : t ? e : "polite";
203
208
  }
204
- function De(e) {
209
+ function Pe(e) {
205
210
  return e === "off" ? null : e;
206
211
  }
207
- function Oe(e, t) {
212
+ function Fe(e, t) {
208
213
  if (t) {
209
214
  e.setAttribute("aria-live", t), e.setAttribute("aria-atomic", "true");
210
215
  return;
@@ -212,39 +217,62 @@ function Oe(e, t) {
212
217
  e.removeAttribute("aria-live"), e.removeAttribute("aria-atomic");
213
218
  }
214
219
  //#endregion
215
- //#region src/js/core/validation-focus.ts
216
- function ke(e, t) {
220
+ //#region src/js/core/field-error-aria.ts
221
+ function Ie(e, t) {
217
222
  let n = (e.getAttribute("aria-describedby") || "").trim(), r = n ? n.split(/\s+/) : [];
218
223
  r.includes(t) || r.push(t), e.setAttribute("aria-describedby", r.join(" ").trim());
219
224
  }
220
- function Ae(e) {
221
- return Array.from(e.querySelectorAll("[data-formie-field-handle]")).find((e) => e.getAttribute("data-formie-field-has-error") === "true" ? !0 : e.querySelector("[data-formie-field-error]") !== null) || null;
225
+ function Le(e, t = document) {
226
+ let n = (e.getAttribute("aria-describedby") || "").trim();
227
+ if (!n) return;
228
+ let r = n.split(/\s+/).filter((e) => !!e && !!t.getElementById(e));
229
+ if (r.length) {
230
+ e.setAttribute("aria-describedby", r.join(" "));
231
+ return;
232
+ }
233
+ e.removeAttribute("aria-describedby");
234
+ }
235
+ function M(e, t) {
236
+ e.setAttribute("aria-errormessage", t), Ie(e, t);
222
237
  }
223
- function je(e) {
224
- return e.querySelector("[aria-invalid=\"true\"]") || e.querySelector("input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled])");
238
+ function Re(e, t = []) {
239
+ t.forEach((t) => {
240
+ e.getAttribute("aria-errormessage") === t && e.removeAttribute("aria-errormessage");
241
+ }), !t.length && e.hasAttribute("aria-errormessage") && e.removeAttribute("aria-errormessage"), Le(e);
225
242
  }
226
- function Me(e) {
243
+ //#endregion
244
+ //#region src/js/core/validation-focus.ts
245
+ function ze(e) {
246
+ return Array.from(e.querySelectorAll("[data-formie-field-handle]")).find((e) => e.getAttribute("data-formie-field-has-error") === "true" || e.querySelector("[data-formie-field-error]") !== null) || null;
247
+ }
248
+ function Be(e) {
249
+ return Array.from(e.querySelectorAll("[aria-invalid=\"true\"]")).find((e) => !k(e)) || (Array.from(e.querySelectorAll("input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled])")).find((e) => !k(e)) ?? null);
250
+ }
251
+ function Ve(e) {
227
252
  return e.querySelector("[data-formie-message-error], [data-formie-error-container], [data-formie-errors]");
228
253
  }
229
- function Ne(e) {
254
+ function He(e) {
230
255
  e.querySelectorAll("[data-formie-field-handle]").forEach((t) => {
231
256
  let n = t;
232
- if (!(n.getAttribute("data-formie-field-has-error") === "true" || n.querySelector("[data-formie-field-error]") !== null)) return;
233
- n.setAttribute("data-formie-field-has-error", "true"), w(n, e, "fieldLayoutError");
234
- let r = n.querySelector("[data-formie-field-errors]")?.id || "", i = n.querySelector("[data-formie-field-error]")?.id || "";
257
+ if (n.getAttribute("data-formie-field-has-error") !== "true" && n.querySelector("[data-formie-field-error]") === null) return;
258
+ n.setAttribute("data-formie-field-has-error", "true"), O(n, e, "fieldLayoutError");
259
+ let r = n.querySelector("[data-formie-field-error]")?.id || "";
235
260
  n.querySelectorAll("input, select, textarea").forEach((t) => {
236
- let n = t;
237
- n.setAttribute("aria-invalid", "true"), w(n, e, "fieldControlError"), n.setAttribute("data-formie-input-has-error", "true"), r && ke(n, r), i && n.setAttribute("aria-errormessage", i);
261
+ let i = t;
262
+ if (k(i)) return;
263
+ i.setAttribute("aria-invalid", "true"), O(i, e, "fieldControlError"), i.setAttribute("data-formie-input-has-error", "true"), r && M(i, r);
264
+ let a = n.querySelector("[data-formie-instructions]");
265
+ a?.id && Ie(i, a.id);
238
266
  });
239
267
  });
240
268
  }
241
- function Pe(e) {
242
- return !!Ae(e) || !!Me(e);
269
+ function Ue(e) {
270
+ return !!ze(e) || !!Ve(e);
243
271
  }
244
- function Fe(e) {
245
- let t = Ae(e);
272
+ function We(e) {
273
+ let t = ze(e);
246
274
  if (t) {
247
- let e = je(t);
275
+ let e = Be(t);
248
276
  if (e) {
249
277
  if (e.scrollIntoView({
250
278
  behavior: "smooth",
@@ -261,72 +289,16 @@ function Fe(e) {
261
289
  block: "center"
262
290
  }), !0;
263
291
  }
264
- let n = Me(e);
292
+ let n = Ve(e);
265
293
  return n ? (n.scrollIntoView({
266
294
  behavior: "smooth",
267
295
  block: "center"
268
296
  }), !0) : !1;
269
297
  }
270
298
  //#endregion
271
- //#region src/js/events/event-bus.ts
272
- var Ie = class {
273
- constructor() {
274
- this.listeners = /* @__PURE__ */ new Map();
275
- }
276
- on(e, t) {
277
- return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e)?.add(t), () => {
278
- this.listeners.get(e)?.delete(t);
279
- };
280
- }
281
- async emit(e, t) {
282
- let n = this.listeners.get(e);
283
- if (!(!n || n.size === 0)) for (let e of n) await e(t);
284
- }
285
- async emitSafe(e, t) {
286
- let n = this.listeners.get(e), r = {
287
- eventName: e,
288
- total: n?.size || 0,
289
- succeeded: 0,
290
- failed: []
291
- };
292
- if (!n || n.size === 0) return r;
293
- let i = 0;
294
- for (let e of n) {
295
- try {
296
- await e(t), r.succeeded += 1;
297
- } catch (e) {
298
- r.failed.push({
299
- index: i,
300
- error: e
301
- });
302
- }
303
- i += 1;
304
- }
305
- return r;
306
- }
307
- async emitParallelSafe(e, t) {
308
- let n = this.listeners.get(e), r = {
309
- eventName: e,
310
- total: n?.size || 0,
311
- succeeded: 0,
312
- failed: []
313
- };
314
- return !n || n.size === 0 || (await Promise.allSettled(Array.from(n).map(async (e) => e(t)))).forEach((e, t) => {
315
- if (e.status === "fulfilled") {
316
- r.succeeded += 1;
317
- return;
318
- }
319
- r.failed.push({
320
- index: t,
321
- error: e.reason
322
- });
323
- }), r;
324
- }
325
- clear() {
326
- this.listeners.clear();
327
- }
328
- }, A = S("general", "transport");
329
- function Le(e) {
299
+ //#region src/js/transport/forms-api.ts
300
+ var N = E("general", "transport");
301
+ function Ge(e) {
330
302
  let t = {};
331
303
  return [
332
304
  "theme",
@@ -337,90 +309,98 @@ function Le(e) {
337
309
  e[n] !== void 0 && (t[n] = e[n]);
338
310
  }), t;
339
311
  }
340
- function Re(e, t = "", n = {}) {
341
- if (Array.isArray(e)) {
342
- let r = e.map((e) => typeof e == "string" ? e : String(e ?? "")).filter((e) => e.trim() !== "");
343
- return t && r.length && (n[t] = (n[t] || []).concat(r)), n;
344
- }
345
- return e && typeof e == "object" && Object.entries(e).forEach(([e, r]) => {
346
- Re(r, t ? `${t}.${e}` : e, n);
347
- }), n;
348
- }
349
- function ze(e, t) {
350
- let n = e.success === !0, r = e.keepSubmitLoading === !0, i = e.errors, a = Re(i || {}), o = a.form || [], s = {};
351
- Object.entries(a).forEach(([e, t]) => {
352
- if (e === "form") return;
353
- let n = e.split(".")[0];
354
- s[n] = (s[n] || []).concat(t);
312
+ function Ke(e, t) {
313
+ let n = e.success === !0, r = e.completion && typeof e.completion == "object" ? e.completion : null, i = e.payment && typeof e.payment == "object" ? e.payment : null, a = [
314
+ "requiresAction",
315
+ "pending",
316
+ "unknown"
317
+ ].includes(i?.status || ""), o = e.errors, s = Object.fromEntries(Object.entries(o && typeof o == "object" ? o : {}).map(([e, t]) => [e, Array.isArray(t) ? t.filter((e) => typeof e == "string") : []])), c = s.form || [], l = {};
318
+ Object.entries(s).forEach(([e, t]) => {
319
+ e !== "form" && (l[e] = t);
355
320
  });
356
- let c = !n && o.length === 0 && Object.keys(s).length > 0 ? [t || "Submission failed."] : o, l = !n && r && c.length === 0 && Object.keys(s).length === 0;
321
+ let u = !n && c.length === 0 && Object.keys(l).length > 0 ? [t || "Submission failed."] : c, d = !n && a && u.length === 0 && Object.keys(l).length === 0;
357
322
  return {
358
323
  ok: n,
324
+ outcome: typeof e.outcome == "string" ? e.outcome : void 0,
325
+ version: typeof e.version == "number" ? e.version : null,
326
+ submissionUid: typeof e.submissionUid == "string" ? e.submissionUid : null,
327
+ errors: e.errors,
328
+ session: e.session,
329
+ completion: r,
359
330
  action: e.submitAction === "back" || e.submitAction === "save" || e.submitAction === "submit" ? e.submitAction : void 0,
360
- message: e.submitActionMessage || (n ? "Submission completed." : l ? "" : c[0] || "Submission failed."),
331
+ message: r?.message || e.successMessage || e.submitActionMessage || (n ? "Submission completed." : d ? "" : u[0] || "Submission failed."),
361
332
  code: n ? void 0 : String(e.code || "SUBMIT_ERROR"),
362
- keepSubmitLoading: r,
363
- fieldErrors: Object.keys(s).length ? s : void 0,
364
- formErrors: c.length ? c : void 0,
333
+ keepSubmitLoading: a,
334
+ payment: i,
335
+ fieldErrors: Object.keys(l).length ? l : void 0,
336
+ formErrors: u.length ? u : void 0,
365
337
  nextPage: e.nextPageId ? { id: String(e.nextPageId) } : null,
366
- redirect: e.redirectUrl ? {
338
+ redirect: i?.status === "requiresAction" && i.action?.type === "redirect" && i.action.url ? {
339
+ url: i.action.url,
340
+ target: "same-tab"
341
+ } : r?.url ? {
342
+ url: r.url,
343
+ target: r.target
344
+ } : e.redirectUrl ? {
367
345
  url: String(e.redirectUrl),
368
- target: e.submitActionTab === "new-tab" ? "new-tab" : "same-tab"
346
+ target: e.redirectTarget === "new-tab" ? "new-tab" : "same-tab"
369
347
  } : null,
370
348
  submitData: Array.isArray(e.submitData) ? e.submitData : void 0,
371
349
  clientEvents: Array.isArray(e.clientEvents) ? e.clientEvents : void 0,
372
350
  meta: e
373
351
  };
374
352
  }
375
- async function Be(e, t, n = {}) {
376
- let r = JSON.stringify({
353
+ async function qe(e, t, n = {}, r = {}) {
354
+ let i = JSON.stringify({
377
355
  handle: t,
378
356
  renderOptions: n
379
357
  });
380
- A.log("requestRender start.", {
358
+ N.log("requestRender start.", {
381
359
  endpoint: e,
382
360
  handle: t
383
361
  });
384
- let i = await T(e, {
362
+ let a = await A(e, {
363
+ ...r,
385
364
  method: "POST",
386
- body: r,
365
+ body: i,
387
366
  headers: { "Content-Type": "application/json" }
388
367
  });
389
- return A.log("requestRender complete.", { hasHtml: !!i.html }), i;
368
+ return N.log("requestRender complete.", { hasHtml: !!a.html }), a;
390
369
  }
391
- async function Ve(e, t, n = {}) {
392
- let r = JSON.stringify({
370
+ async function Je(e, t, n = {}, r = {}) {
371
+ let i = JSON.stringify({
393
372
  query: "\nquery FormieHtmlForm($handle: String!, $input: ServerRenderPayloadInput) {\n formieHtmlForm(handle: $handle, input: $input) {\n html\n }\n}",
394
373
  variables: {
395
374
  handle: t,
396
- input: Le(n)
375
+ input: Ge(n)
397
376
  }
398
377
  });
399
- A.log("requestGraphqlRender start.", {
378
+ N.log("requestGraphqlRender start.", {
400
379
  endpoint: e,
401
380
  handle: t
402
381
  });
403
- let i = await T(e, {
382
+ let a = await A(e, {
383
+ ...r,
404
384
  method: "POST",
405
- body: r,
385
+ body: i,
406
386
  headers: { "Content-Type": "application/json" }
407
387
  });
408
- if (Array.isArray(i.errors) && i.errors.length > 0) throw Error(i.errors.map((e) => e.message || "Unknown GraphQL error").join("; "));
409
- if (!i.data?.formieHtmlForm) throw Error(`Form not found for handle "${t}".`);
410
- let a = i.data.formieHtmlForm;
411
- return A.log("requestGraphqlRender complete.", { hasHtml: !!a.html }), a;
412
- }
413
- async function j(e, t, n) {
414
- let r = new URL(e, window.location.origin);
415
- r.searchParams.set("handle", t), n && r.searchParams.set("renderId", n), A.log("requestRefreshTokens start.", {
416
- endpoint: r.toString(),
388
+ if (Array.isArray(a.errors) && a.errors.length > 0) throw Error(a.errors.map((e) => e.message || "Unknown GraphQL error").join("; "));
389
+ if (!a.data?.formieHtmlForm) throw Error(`Form not found for handle "${t}".`);
390
+ let o = a.data.formieHtmlForm;
391
+ return N.log("requestGraphqlRender complete.", { hasHtml: !!o.html }), o;
392
+ }
393
+ async function P(e, t, n, r = {}, i) {
394
+ let a = new URL(e, window.location.origin);
395
+ a.searchParams.set("handle", t), n && a.searchParams.set("renderId", n), i && a.searchParams.set("requestToken", i), N.log("requestRefreshTokens start.", {
396
+ endpoint: a.toString(),
417
397
  handle: t,
418
398
  hasRenderId: !!n
419
399
  });
420
- let i = await T(r.toString());
421
- return A.log("requestRefreshTokens complete.", { hasRefreshTokens: !!i.refreshTokens }), i.refreshTokens || i;
400
+ let o = await A(a.toString(), r);
401
+ return N.log("requestRefreshTokens complete.", { hasRefreshTokens: !!o.refreshTokens }), o.refreshTokens || o;
422
402
  }
423
- async function He(e, t, n) {
403
+ async function Ye(e, t, n) {
424
404
  let r = new URL(e, window.location.origin), i = new FormData();
425
405
  if (n && i.append("pageId", n), t) {
426
406
  [
@@ -428,26 +408,32 @@ async function He(e, t, n) {
428
408
  "renderId",
429
409
  "draftContextToken",
430
410
  "draftContext",
431
- "continuationToken"
411
+ "progressId",
412
+ "requestToken",
413
+ "expectedVersion"
432
414
  ].forEach((e) => {
433
415
  let n = t.querySelector(`input[name="${e}"]`)?.value?.trim();
434
416
  n && i.append(e, n);
435
- });
436
- let e = t.querySelector("input[name=\"CRAFT_CSRF_TOKEN\"]")?.value?.trim();
437
- e && i.append("CRAFT_CSRF_TOKEN", e);
417
+ }), ie(i, t);
418
+ for (let [e, n] of new FormData(t)) e.startsWith("fields[") && i.append(e, n);
438
419
  }
439
- A.log("requestSetPage start.", {
420
+ N.log("requestSetPage start.", {
440
421
  requestUrl: r.toString(),
441
422
  pageId: n || null
442
423
  });
443
- let a = await T(r.toString(), {
424
+ let a = await (await ae(r.toString(), {
444
425
  method: "POST",
445
- body: i
446
- });
447
- return A.log("requestSetPage complete.", a), a;
426
+ body: i,
427
+ profile: t?.dataset.formieRequestProfile
428
+ })).json();
429
+ if (t && a.session) {
430
+ let e = a.session, n = t.querySelector("input[name=\"expectedVersion\"]"), r = t.querySelector("input[name=\"requestToken\"]");
431
+ n && (n.value = String(e.version)), r && e.tokens?.request && (r.value = e.tokens.request);
432
+ }
433
+ return N.log("requestSetPage complete.", a), a;
448
434
  }
449
- function Ue(e, t) {
450
- let n = new URL(e, window.location.origin), r = new FormData();
435
+ function Xe(e, t) {
436
+ let n = new URL(e, window.location.origin), i = new FormData();
451
437
  [
452
438
  "handle",
453
439
  "renderId",
@@ -455,75 +441,69 @@ function Ue(e, t) {
455
441
  "draftContext"
456
442
  ].forEach((e) => {
457
443
  let n = t.querySelector(`input[name="${e}"]`)?.value?.trim();
458
- n && r.append(e, n);
459
- });
460
- let i = t.querySelector("input[name=\"CRAFT_CSRF_TOKEN\"]")?.value?.trim();
461
- i && r.append("CRAFT_CSRF_TOKEN", i), A.log("clearSubmissionOnUnload start.", { requestUrl: n.toString() });
444
+ n && i.append(e, n);
445
+ }), ie(i, t), N.log("clearSubmissionOnUnload start.", { requestUrl: n.toString() });
462
446
  try {
463
- if (typeof navigator.sendBeacon == "function" && navigator.sendBeacon(n.toString(), r)) return;
447
+ if (t.dataset.formieRequestProfile !== "cross-origin-public" && typeof navigator.sendBeacon == "function" && navigator.sendBeacon(n.toString(), i)) return;
464
448
  } catch {}
465
- fetch(n.toString(), {
449
+ r(n.toString(), {
466
450
  method: "POST",
467
- body: r,
468
- credentials: "include",
451
+ body: i,
469
452
  keepalive: !0,
470
453
  headers: { Accept: "application/json" }
471
- });
454
+ }, { profile: t.dataset.formieRequestProfile });
472
455
  }
473
- async function We(e, t) {
474
- let n = (e.getAttribute("method") || "POST").toUpperCase(), r = e.getAttribute("action") || window.location.href, i = e.dataset.formieErrorMessage?.trim() || "Submission failed.";
475
- A.log("submitForm start.", {
456
+ async function Ze(e, t) {
457
+ let n = (e.getAttribute("method") || "POST").toUpperCase(), i = e.getAttribute("action") || window.location.href, a = e.dataset.formieErrorMessage?.trim() || "Submission failed.";
458
+ N.log("submitForm start.", {
476
459
  method: n,
477
- action: r,
460
+ action: i,
478
461
  submitAction: t.get("submitAction")
479
462
  });
480
- let a = await fetch(r, {
463
+ let o = await r(i, {
481
464
  method: n,
482
465
  body: t,
483
- credentials: "include",
484
466
  headers: { Accept: "application/json" }
485
- }), o = a.headers.get("content-type") || "";
486
- if (!o.includes("application/json")) return a.ok ? (A.log("submitForm non-JSON success response.", {
487
- status: a.status,
488
- contentType: o
467
+ }, { profile: e.dataset.formieRequestProfile }), s = o.headers.get("content-type") || "";
468
+ if (!s.includes("application/json")) return o.ok ? (N.log("submitForm non-JSON success response.", {
469
+ status: o.status,
470
+ contentType: s
489
471
  }), {
490
472
  ok: !0,
491
473
  message: "Submission completed."
492
- }) : (A.warn("submitForm non-JSON HTTP error.", {
493
- status: a.status,
494
- contentType: o
474
+ }) : (N.warn("submitForm non-JSON HTTP error.", {
475
+ status: o.status,
476
+ contentType: s
495
477
  }), {
496
478
  ok: !1,
497
479
  code: "HTTP_ERROR",
498
- message: `Request failed (${a.status}).`,
499
- formErrors: [`Request failed (${a.status}).`]
480
+ message: `Request failed (${o.status}).`,
481
+ formErrors: [`Request failed (${o.status}).`]
500
482
  });
501
- let s = ze(await a.json(), i);
502
- return A.log("submitForm JSON response normalized.", {
503
- ok: s.ok,
504
- code: s.code,
505
- hasRedirect: !!s.redirect?.url,
506
- hasSubmitData: Array.isArray(s.submitData) && s.submitData.length > 0
507
- }), s;
483
+ let c = Ke(await o.json(), a);
484
+ return N.log("submitForm JSON response normalized.", {
485
+ ok: c.ok,
486
+ code: c.code,
487
+ hasRedirect: !!c.redirect?.url,
488
+ hasSubmitData: Array.isArray(c.submitData) && c.submitData.length > 0
489
+ }), c;
508
490
  }
509
491
  //#endregion
510
492
  //#region src/js/submit/pipeline.ts
511
- var Ge = [
493
+ var Qe = [
512
494
  "prepare",
513
- "normalize",
514
495
  "validate",
515
- "screen",
516
- "authorize",
517
- "dispatch",
518
- "finalize"
519
- ], Ke = [
496
+ "challenge",
497
+ "payment",
498
+ "send",
499
+ "result"
500
+ ], $e = [
520
501
  "prepare",
521
- "normalize",
522
502
  "validate",
523
- "screen",
524
- "authorize"
525
- ], M = S("general", "pipeline");
526
- function qe(e, t) {
503
+ "challenge",
504
+ "payment"
505
+ ], F = E("general", "pipeline");
506
+ function I(e, t) {
527
507
  return {
528
508
  ok: !1,
529
509
  stage: e,
@@ -532,13 +512,13 @@ function qe(e, t) {
532
512
  formErrors: [t || "Submission aborted."]
533
513
  };
534
514
  }
535
- function Je(e) {
515
+ function et(e) {
536
516
  return e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement;
537
517
  }
538
- function Ye(e) {
518
+ function tt(e) {
539
519
  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)));
540
520
  }
541
- function Xe(e, t) {
521
+ function nt(e, t) {
542
522
  if (t instanceof HTMLInputElement) {
543
523
  if (t.type === "file") {
544
524
  Array.from(t.files || []).forEach((n) => {
@@ -557,49 +537,49 @@ function Xe(e, t) {
557
537
  }
558
538
  e.append(t.name, t.value);
559
539
  }
560
- function Ze(e, t) {
540
+ function rt(e, t) {
561
541
  t.querySelectorAll("input, select, textarea").forEach((t) => {
562
- let n = Je(t) ? t : null;
563
- !n || n.closest("[data-formie-page]") || Ye(n) && Xe(e, n);
542
+ let n = et(t) ? t : null;
543
+ n && !n.closest("[data-formie-page]") && tt(n) && nt(e, n);
564
544
  });
565
545
  }
566
- function Qe(e, t) {
546
+ function it(e, t) {
567
547
  let n = /* @__PURE__ */ new Set();
568
548
  return t.querySelectorAll("input, select, textarea").forEach((t) => {
569
- let r = Je(t) ? t : null;
570
- !r || !r.name || r.disabled || r instanceof HTMLInputElement && (r.type === "submit" || r.type === "button" || r.type === "reset" || r.type === "image") || (r.name.startsWith("fields[") && n.add(r.name), Ye(r) && Xe(e, r));
549
+ let r = et(t) ? t : null;
550
+ r && r.name && !r.disabled && (r instanceof HTMLInputElement && (r.type === "submit" || r.type === "button" || r.type === "reset" || r.type === "image") || (r.name.startsWith("fields[") && n.add(r.name), tt(r) && nt(e, r)));
571
551
  }), n;
572
552
  }
573
- function $e(e, t) {
553
+ function at(e, t) {
574
554
  t.forEach((t) => {
575
555
  e.has(t) || e.append(t, "");
576
556
  });
577
557
  }
578
- function et(e, t) {
579
- let n = c(e), r = n.find((e) => !e.hasAttribute("data-formie-page-hidden")) || null;
558
+ function ot(e, t) {
559
+ let n = f(e), r = n.find((e) => !e.hasAttribute("data-formie-page-hidden")) || null;
580
560
  if (!n.length || !r) {
581
561
  let n = new FormData(e);
582
562
  return n.set("submitAction", t), n;
583
563
  }
584
564
  let i = new FormData();
585
- return Ze(i, e), $e(i, Qe(i, r)), i.set("submitAction", t), i;
565
+ return rt(i, e), at(i, it(i, r)), i.set("submitAction", t), i;
586
566
  }
587
- function tt(e, t) {
567
+ function st(e, t) {
588
568
  if (t !== "submit") return !1;
589
- let n = c(e);
590
- return n.length ? (n.find((e) => !e.hasAttribute("data-formie-page-hidden")) || n[n.length - 1]) === n[n.length - 1] : !0;
569
+ let n = f(e);
570
+ return !n.length || (n.find((e) => !e.hasAttribute("data-formie-page-hidden")) || n[n.length - 1]) === n[n.length - 1];
591
571
  }
592
- async function nt(e, t, n, r = {}) {
593
- M.log("Starting submit pipeline.", {
572
+ async function ct(e, t, n, r = {}) {
573
+ F.log("Starting submit pipeline.", {
594
574
  action: t,
595
575
  preflightOnly: r.preflightOnly === !0
596
576
  });
597
- let i = !1, a, o = null, s = tt(e, t), c = {
577
+ let i = !1, a, o = null, s = st(e, t), c = {
598
578
  form: e,
599
579
  action: t,
600
- formData: et(e, t),
580
+ formData: ot(e, t),
601
581
  abort: (e) => {
602
- i = !0, a = e, M.warn("Pipeline aborted.", { reason: e });
582
+ i = !0, a = e, F.warn("Pipeline aborted.", { reason: e });
603
583
  },
604
584
  isAborted: () => i,
605
585
  abortReason: () => a
@@ -608,11 +588,10 @@ async function nt(e, t, n, r = {}) {
608
588
  let t = e.form.querySelector("input[name=\"submitAction\"]");
609
589
  return t && (t.value = e.action), e.formData.set("submitAction", e.action), null;
610
590
  },
611
- normalize: async () => null,
612
591
  validate: async (e) => {
613
592
  if (e.action !== "submit" || r.validateOnSubmit === !1) return null;
614
593
  if (r.validator) {
615
- let { scope: t, final: n } = f(e.form), i = r.validator.submit(n ? e.form : t, { final: n });
594
+ let { scope: t, final: n } = g(e.form), i = r.validator.submit(n ? e.form : t, { final: n });
616
595
  if (i.length > 0) {
617
596
  let e = i[0]?.input;
618
597
  if (e) {
@@ -645,71 +624,71 @@ async function nt(e, t, n, r = {}) {
645
624
  formErrors: ["Validation failed."]
646
625
  });
647
626
  },
648
- screen: async () => null,
649
- authorize: async () => null,
650
- dispatch: async (e) => {
651
- e.formData = et(e.form, e.action);
652
- let t = await We(e.form, e.formData);
627
+ challenge: async () => null,
628
+ payment: async () => null,
629
+ send: async (e) => {
630
+ e.formData = ot(e.form, e.action);
631
+ let t = await Ze(e.form, e.formData);
653
632
  return o = t, t;
654
633
  },
655
- finalize: async (e) => (o && o.ok && o.redirect?.url && (o.redirect.target === "new-tab" ? window.open(o.redirect.url, "_blank") : window.location.href = o.redirect.url), null)
634
+ result: async (e) => (o && o.ok && o.redirect?.url && (o.redirect.target === "new-tab" ? window.open(o.redirect.url, "_blank", "noopener,noreferrer") : (e.form.setAttribute("data-formie-internal-navigation", "redirect"), window.location.href = o.redirect.url)), null)
656
635
  };
657
636
  {
658
637
  let e = await n.emitSafe("formie:submit:before", c);
659
- e.failed.length > 0 && M.warn("Submit before listeners failed.", {
638
+ e.failed.length > 0 && F.warn("Submit before listeners failed.", {
660
639
  eventName: e.eventName,
661
640
  failed: e.failed.length
662
641
  });
663
642
  }
664
643
  if (s) {
665
644
  let e = await n.emitSafe("formie:submit:final:before", c);
666
- e.failed.length > 0 && M.warn("Final submit before listeners failed.", {
645
+ e.failed.length > 0 && F.warn("Final submit before listeners failed.", {
667
646
  eventName: e.eventName,
668
647
  failed: e.failed.length
669
648
  });
670
649
  }
671
- let u = r.preflightOnly ? Ke : Ge;
650
+ let u = r.preflightOnly ? $e : Qe;
672
651
  for (let e of u) {
673
- if (M.log("Stage start.", {
652
+ if (F.log("Stage start.", {
674
653
  stage: e,
675
654
  action: t
676
- }), i) return M.warn("Stage skipped due to abort.", {
655
+ }), i) return F.warn("Stage skipped due to abort.", {
677
656
  stage: e,
678
657
  reason: a
679
- }), qe(e, a);
658
+ }), I(e, a);
680
659
  {
681
660
  let t = await n.emitSafe(`formie:stage:${e}:before`, {
682
661
  ...c,
683
662
  stage: e
684
663
  });
685
- t.failed.length > 0 && M.warn("Stage before listeners failed.", {
664
+ t.failed.length > 0 && F.warn("Stage before listeners failed.", {
686
665
  stage: e,
687
666
  failed: t.failed.length
688
667
  });
689
668
  }
690
669
  if (i) {
691
- let t = qe(e, a);
670
+ let t = I(e, a);
692
671
  {
693
672
  let r = await n.emitSafe("formie:submit:after", t);
694
- r.failed.length > 0 && M.warn("Submit after listeners failed (abort before stage).", {
673
+ r.failed.length > 0 && F.warn("Submit after listeners failed (abort before stage).", {
695
674
  stage: e,
696
675
  failed: r.failed.length
697
676
  });
698
677
  }
699
678
  if (s) {
700
679
  let r = await n.emitSafe("formie:submit:final:after", t);
701
- r.failed.length > 0 && M.warn("Final submit after listeners failed (abort before stage).", {
680
+ r.failed.length > 0 && F.warn("Final submit after listeners failed (abort before stage).", {
702
681
  stage: e,
703
682
  failed: r.failed.length
704
683
  });
705
684
  }
706
- return M.warn("Aborted after stage before-hooks.", {
685
+ return F.warn("Aborted after stage before-hooks.", {
707
686
  stage: e,
708
687
  reason: a
709
688
  }), t;
710
689
  }
711
690
  let r = await l[e](c);
712
- M.log("Stage runner complete.", {
691
+ F.log("Stage runner complete.", {
713
692
  stage: e,
714
693
  hasResult: !!r,
715
694
  ok: r ? r.ok : void 0,
@@ -721,28 +700,28 @@ async function nt(e, t, n, r = {}) {
721
700
  stage: e,
722
701
  result: r
723
702
  });
724
- t.failed.length > 0 && M.warn("Stage after listeners failed.", {
703
+ t.failed.length > 0 && F.warn("Stage after listeners failed.", {
725
704
  stage: e,
726
705
  failed: t.failed.length
727
706
  });
728
707
  }
729
708
  if (i) {
730
- let t = qe(e, a);
709
+ let t = I(e, a);
731
710
  {
732
711
  let r = await n.emitSafe("formie:submit:after", t);
733
- r.failed.length > 0 && M.warn("Submit after listeners failed (abort after stage).", {
712
+ r.failed.length > 0 && F.warn("Submit after listeners failed (abort after stage).", {
734
713
  stage: e,
735
714
  failed: r.failed.length
736
715
  });
737
716
  }
738
717
  if (s) {
739
718
  let r = await n.emitSafe("formie:submit:final:after", t);
740
- r.failed.length > 0 && M.warn("Final submit after listeners failed (abort after stage).", {
719
+ r.failed.length > 0 && F.warn("Final submit after listeners failed (abort after stage).", {
741
720
  stage: e,
742
721
  failed: r.failed.length
743
722
  });
744
723
  }
745
- return M.warn("Aborted after stage after-hooks.", {
724
+ return F.warn("Aborted after stage after-hooks.", {
746
725
  stage: e,
747
726
  reason: a
748
727
  }), t;
@@ -750,19 +729,19 @@ async function nt(e, t, n, r = {}) {
750
729
  if (r && !r.ok) {
751
730
  {
752
731
  let t = await n.emitSafe("formie:submit:after", r);
753
- t.failed.length > 0 && M.warn("Submit after listeners failed (failed stage).", {
732
+ t.failed.length > 0 && F.warn("Submit after listeners failed (failed stage).", {
754
733
  stage: e,
755
734
  failed: t.failed.length
756
735
  });
757
736
  }
758
737
  if (s) {
759
738
  let t = await n.emitSafe("formie:submit:final:after", r);
760
- t.failed.length > 0 && M.warn("Final submit after listeners failed (failed stage).", {
739
+ t.failed.length > 0 && F.warn("Final submit after listeners failed (failed stage).", {
761
740
  stage: e,
762
741
  failed: t.failed.length
763
742
  });
764
743
  }
765
- return M.warn("Pipeline short-circuited by failed stage.", {
744
+ return F.warn("Pipeline short-circuited by failed stage.", {
766
745
  stage: e,
767
746
  code: r.code,
768
747
  message: r.message
@@ -771,18 +750,19 @@ async function nt(e, t, n, r = {}) {
771
750
  }
772
751
  let d = o || {
773
752
  ok: !0,
774
- stage: r.preflightOnly ? "authorize" : "finalize",
753
+ stage: r.preflightOnly ? "payment" : "result",
754
+ code: r.preflightOnly ? "PREFLIGHT_COMPLETE" : void 0,
775
755
  message: r.preflightOnly ? "Submission preflight completed." : "Submission completed."
776
756
  };
777
757
  {
778
758
  let e = await n.emitSafe("formie:submit:after", d);
779
- e.failed.length > 0 && M.warn("Submit after listeners failed (success).", { failed: e.failed.length });
759
+ e.failed.length > 0 && F.warn("Submit after listeners failed (success).", { failed: e.failed.length });
780
760
  }
781
761
  if (s) {
782
762
  let e = await n.emitSafe("formie:submit:final:after", d);
783
- e.failed.length > 0 && M.warn("Final submit after listeners failed (success).", { failed: e.failed.length });
763
+ e.failed.length > 0 && F.warn("Final submit after listeners failed (success).", { failed: e.failed.length });
784
764
  }
785
- return M.log("Pipeline completed.", {
765
+ return F.log("Pipeline completed.", {
786
766
  ok: d.ok,
787
767
  stage: d.stage,
788
768
  code: d.code
@@ -790,157 +770,857 @@ async function nt(e, t, n, r = {}) {
790
770
  }
791
771
  //#endregion
792
772
  //#region src/js/core/field-error-container.ts
793
- function rt(e) {
773
+ function lt(e) {
794
774
  return e.querySelector("[data-formie-field-layout]")?.getAttribute("data-formie-error-position")?.trim() === "above" ? "above" : "below";
795
775
  }
796
- function it(e, t) {
776
+ function ut(e, t) {
797
777
  let n = e.querySelector("[data-formie-field-errors]");
798
778
  if (n) return n;
799
- let r = e.querySelector("[data-formie-field-content]"), i = e.querySelector("[data-formie-field-control]"), a = rt(e), o = document.createElement("div");
779
+ let r = e.querySelector("[data-formie-field-content]"), i = e.querySelector("[data-formie-field-control]"), a = lt(e), o = document.createElement("div");
800
780
  return o.setAttribute("data-formie-field-errors", "true"), t?.(o), r && i ? a === "above" ? r.insertBefore(o, i) : r.appendChild(o) : e.appendChild(o), o;
801
781
  }
802
782
  //#endregion
803
- //#region src/js/validation/rules/email.ts
804
- var at = {
805
- rule: ({ input: e, getRule: t }) => !t("email") || !e.value || e.value.length < 1 ? !0 : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.value),
806
- message: ({ input: e, label: t, t: n }) => e.getAttribute("data-formie-validation-email-message") ?? e.getAttribute("data-formie-pattern-email-message") ?? e.getAttribute("data-pattern-email-message") ?? n("{label} is not a valid email address.", { label: t })
807
- };
808
- //#endregion
809
- //#region src/js/validation/rules/shared.ts
810
- function ot(e) {
811
- return e?.querySelector("[data-formie-field-label]")?.childNodes[0]?.textContent?.trim() || "";
783
+ //#region src/js/core/submit-result-ui.ts
784
+ var L = /* @__PURE__ */ new WeakMap();
785
+ function dt(e) {
786
+ return (e.dataset.formieCompletionBehavior || e.dataset.formieSubmitAction || "").trim();
812
787
  }
813
- function st(e) {
814
- let t = e.getRule("match");
815
- if (!t || t === !0 || typeof t != "object" || !e.field) return null;
816
- let n = typeof t.fieldHandle == "string" ? t.fieldHandle.trim() : "";
817
- if (!n) return null;
818
- let r = e.form.querySelector(`[data-formie-field-handle="${n}"]`);
819
- return r ? r.querySelector(e.config.fieldsSelector) : null;
788
+ function ft(e) {
789
+ return (e.dataset.formieErrorMessagePosition || "top-form").trim() || "top-form";
820
790
  }
821
- //#endregion
822
- //#region src/js/validation/rules.ts
823
- var ct = {
824
- required: {
825
- rule: ({ input: e, getRule: t }) => {
826
- if (!t("required") || e.type === "hidden") return !0;
827
- if (e.type === "checkbox" || e.type === "radio") {
828
- let t = e.form?.querySelectorAll(`[name="${e.name}"]:not([type="hidden"]):not([disabled])`) || [];
829
- return t.length ? Array.from(t).some((e) => e instanceof HTMLInputElement && e.checked) : e instanceof HTMLInputElement ? e.checked : !0;
830
- }
831
- return e.value.trim() !== "";
832
- },
833
- message: ({ input: e, label: t, t: n }) => e.getAttribute("data-formie-required-message") ?? e.getAttribute("data-required-message") ?? n("{label} cannot be blank.", { label: t })
834
- },
835
- email: at,
836
- url: {
837
- rule: ({ input: e, getRule: t }) => {
838
- if (!t("url") || !e.value || e.value.length < 1) return !0;
839
- try {
840
- return new URL(e.value), !0;
841
- } catch {
842
- return !1;
843
- }
844
- },
845
- message: ({ input: e, label: t, t: n }) => e.getAttribute("data-formie-pattern-url-message") ?? e.getAttribute("data-pattern-url-message") ?? n("{label} is not a valid URL.", { label: t })
846
- },
847
- number: {
848
- rule: ({ input: e, getRule: t }) => {
849
- let n = t("number");
850
- if (!n || !e.value || e.value.trim() === "") return !0;
851
- let r = parseFloat(e.value);
852
- if (Number.isNaN(r)) return !1;
853
- if (n !== !0 && typeof n == "object") {
854
- let e = typeof n.min == "number" ? n.min : null, t = typeof n.max == "number" ? n.max : null;
855
- if (e !== null && r < e || t !== null && r > t) return !1;
856
- }
857
- return !0;
858
- },
859
- message: ({ input: e, label: t, getRule: n, t: r }) => {
860
- let i = n("number"), a = i !== !0 && i && typeof i == "object" && typeof i.min == "number" ? i.min : null, o = i !== !0 && i && typeof i == "object" && typeof i.max == "number" ? i.max : null;
861
- return a !== null && o !== null || a !== null ? e.getAttribute("data-formie-validation-number-min-message") ?? r("{label} must be no less than {min}.", {
862
- label: t,
863
- min: a
864
- }) : o === null ? e.getAttribute("data-formie-validation-number-message") ?? e.getAttribute("data-formie-pattern-number-message") ?? e.getAttribute("data-pattern-number-message") ?? r("{label} is not a valid number.", { label: t }) : e.getAttribute("data-formie-validation-number-max-message") ?? r("{label} must be no greater than {max}.", {
865
- label: t,
866
- max: o
867
- });
868
- }
869
- },
870
- match: {
871
- rule: (e) => {
872
- let t = st(e);
873
- return t ? t.value === e.input.value : !0;
874
- },
875
- message: (e) => {
876
- let t = st(e)?.closest("[data-formie-field-handle]"), n = ot(t);
877
- return e.input.getAttribute("data-formie-validation-match-message") ?? e.t("{label} must match {value}.", {
878
- label: e.label,
879
- value: n
880
- });
881
- }
791
+ function pt(e) {
792
+ return (e.dataset.formieSuccessMessagePosition || e.dataset.formieSubmitActionMessagePosition || "").trim();
793
+ }
794
+ function mt(e) {
795
+ let t = (e.dataset.formieSuccessMessageTimeout || e.dataset.formieSubmitActionMessageTimeout || "").trim();
796
+ if (!t) return null;
797
+ let n = Number.parseFloat(t);
798
+ return !Number.isFinite(n) || n < 0 ? null : Math.round(n * 1e3);
799
+ }
800
+ function R(e) {
801
+ let t = e.dataset.formieHideFormAfterSubmit ?? e.dataset.formieSubmitActionFormHide;
802
+ if (t === void 0) return !1;
803
+ let n = t.trim().toLowerCase();
804
+ return n === "true" || n === "1" || n === "";
805
+ }
806
+ function ht(e) {
807
+ let t = L.get(e);
808
+ typeof t == "number" && (window.clearTimeout(t), L.delete(e));
809
+ }
810
+ function gt(e) {
811
+ return e.querySelector("[data-formie-form-messages-top]") || e;
812
+ }
813
+ function _t(e) {
814
+ return e.querySelector("[data-formie-form-messages-bottom]") || e;
815
+ }
816
+ function vt(e, t) {
817
+ return t === "bottom-form" ? _t(e) : gt(e);
818
+ }
819
+ function yt(e, t) {
820
+ return t === "top-form" ? gt(e) : t === "bottom-form" && !R(e) ? _t(e) : e;
821
+ }
822
+ function bt(e) {
823
+ let t = ft(e), n = vt(e, t), r = n.querySelector("[data-formie-error-container], [data-formie-errors]");
824
+ return r || (r = document.createElement("div"), r.setAttribute("data-formie-errors", "true"), O(r, e, "errors")), r.setAttribute("data-formie-error-container", "true"), t === "bottom-form" ? n.append(r) : n.prepend(r), r;
825
+ }
826
+ function xt(e, t) {
827
+ let n = t.querySelector("[data-formie-error-message-container], [data-formie-message][data-formie-message-error]");
828
+ return n || (n = document.createElement("div"), n.setAttribute("data-formie-error-message-container", "true"), t.appendChild(n)), n.setAttribute("data-formie-message", "true"), n.setAttribute("data-formie-message-error", "true"), O(n, e, "message", "messageError"), n.setAttribute("role", "alert"), Fe(n, Pe(Me(e))), n;
829
+ }
830
+ function St(e, t) {
831
+ let n = e.querySelector("[data-formie-success-container]"), r = yt(e, t);
832
+ return n || (n = document.createElement("div"), n.setAttribute("data-formie-success-container", "true"), O(n, e, "successes")), t === "bottom-form" ? r.append(n) : r.prepend(n), n;
833
+ }
834
+ function Ct(e) {
835
+ return ut(e, (t) => {
836
+ O(t, e, "fieldErrors");
837
+ });
838
+ }
839
+ function wt(e) {
840
+ e.querySelectorAll("[data-formie-field-handle]").forEach((t) => {
841
+ let n = t, r = n.querySelector("[data-formie-field-errors]"), i = Array.from(n.querySelectorAll("[data-formie-field-error]")).map((e) => e.id).filter(Boolean);
842
+ D(n, e, "fieldLayoutError"), n.removeAttribute("data-formie-field-has-error"), n.querySelectorAll("[data-formie-field-error]").forEach((e) => {
843
+ e.remove();
844
+ }), r && !r.querySelector("[data-formie-field-error]") && (r.innerHTML = ""), n.querySelectorAll("input, select, textarea").forEach((t) => {
845
+ let n = t;
846
+ n.removeAttribute("aria-invalid"), D(n, e, "fieldControlError"), n.removeAttribute("data-formie-input-has-error"), Re(n, i);
847
+ });
848
+ }), C(e);
849
+ }
850
+ function Tt(e) {
851
+ e.querySelectorAll("[data-formie-error-container], [data-formie-errors]").forEach((t) => {
852
+ let n = t;
853
+ n.querySelectorAll("[data-formie-error]").forEach((e) => {
854
+ e.remove();
855
+ }), D(n, e, "message", "messageError"), n.removeAttribute("data-formie-message"), n.removeAttribute("data-formie-message-error"), n.removeAttribute("role"), n.removeAttribute("aria-live"), n.removeAttribute("aria-atomic"), n.querySelector("[data-formie-error]") || (n.innerHTML = "");
856
+ });
857
+ }
858
+ function Et(e) {
859
+ ht(e), e.querySelectorAll("[data-formie-message-success]:not([data-formie-success-container])").forEach((e) => {
860
+ e.remove();
861
+ }), e.querySelectorAll("[data-formie-success-container]").forEach((t) => {
862
+ let n = t;
863
+ n.querySelectorAll("[data-formie-success]").forEach((e) => {
864
+ e.remove();
865
+ }), D(n, e, "message", "messageSuccess"), n.removeAttribute("data-formie-message"), n.removeAttribute("data-formie-message-success"), n.removeAttribute("role"), n.removeAttribute("aria-live"), n.removeAttribute("aria-atomic"), n.querySelector("[data-formie-success]") || (n.innerHTML = "");
866
+ }), dt(e) === "message" && R(e) || d(e, !1);
867
+ }
868
+ function Dt(e) {
869
+ e.querySelectorAll("[aria-invalid=\"true\"]").forEach((e) => {
870
+ e.removeAttribute("aria-invalid");
871
+ });
872
+ }
873
+ function Ot(e, t) {
874
+ let n = Pe(Me(e));
875
+ Object.entries(t).forEach(([t, r]) => {
876
+ let i = `fields[${t.split(".").join("][")}]`, a = e.querySelector(`[name="${CSS.escape(i)}"], [name="${CSS.escape(i + "[]")}"]`)?.closest("[data-formie-field-handle]") || e.querySelector(`[data-formie-field-handle="${CSS.escape(t)}"]`);
877
+ if (!a) return;
878
+ let o = Ct(a), s = o.id && o.id.trim() ? o.id : `${t}-errors`;
879
+ o.id = s, Fe(o, n), O(a, e, "fieldLayoutError"), a.setAttribute("data-formie-field-has-error", "true"), r.forEach((t, n) => {
880
+ let r = document.createElement("div");
881
+ r.setAttribute("data-formie-field-error", "true"), r.id = `${s}-${n + 1}`, O(r, e, "fieldError"), r.textContent = t, o.appendChild(r);
882
+ });
883
+ let c = o.querySelector("[data-formie-field-error]")?.id;
884
+ a.querySelectorAll("input, select, textarea").forEach((t) => {
885
+ let n = t;
886
+ n.setAttribute("aria-invalid", "true"), O(n, e, "fieldControlError"), n.setAttribute("data-formie-input-has-error", "true"), c && M(n, c);
887
+ let r = a.querySelector("[data-formie-instructions]");
888
+ r?.id && Ie(n, r.id);
889
+ });
890
+ }), C(e);
891
+ }
892
+ function kt(e, t) {
893
+ let n = bt(e), r = xt(e, n);
894
+ O(n, e, "errors"), t.forEach((t) => {
895
+ let n = document.createElement("div");
896
+ n.setAttribute("data-formie-error", "true"), n.setAttribute("role", "alert"), O(n, e, "error"), n.innerHTML = t, r.appendChild(n);
897
+ });
898
+ }
899
+ function At(e) {
900
+ if (e.ok || e.keepSubmitLoading !== !0) return !1;
901
+ let t = e.payment?.status;
902
+ return t === "requiresAction" || t === "pending" || t === "unknown";
903
+ }
904
+ function jt(e, t) {
905
+ let n = bt(e), r = xt(e, n);
906
+ O(n, e, "errors");
907
+ let i = document.createElement("div");
908
+ i.setAttribute("data-formie-notice", "true"), i.setAttribute("role", "status"), O(i, e, "message"), i.textContent = t, r.appendChild(i);
909
+ }
910
+ function Mt(e, t) {
911
+ return !t.message || t.nextPage || t.redirect ? !1 : t.action === "save" || dt(e) === "message" && pt(e) !== "";
912
+ }
913
+ function Nt(e, t, n = {}) {
914
+ let r = pt(e);
915
+ if (!r) return;
916
+ let i = St(e, r);
917
+ O(i, e, "message", "messageSuccess"), i.setAttribute("data-formie-message", "true"), i.setAttribute("data-formie-message-success", "true"), i.setAttribute("role", "status"), i.setAttribute("aria-live", "polite"), i.setAttribute("aria-atomic", "true");
918
+ let a = document.createElement("div");
919
+ a.setAttribute("data-formie-success", "true"), O(a, e, "success"), a.innerHTML = t, i.appendChild(a), n.hideForm !== !1 && R(e) && d(e, !0);
920
+ let o = mt(e);
921
+ if (o !== null) {
922
+ let t = window.setTimeout(() => {
923
+ L.delete(e), Et(e);
924
+ }, o);
925
+ L.set(e, t);
882
926
  }
883
- }, lt = {
884
- 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,})+$/,
885
- 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*)?$/,
886
- number: /^(?:[-+]?[0-9]*[.,]?[0-9]+)$/,
887
- color: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,
888
- 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))/,
889
- time: /^(?:(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9]))$/,
890
- month: /^(?:(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])))$/
891
- }, N = S("general", "validator");
892
- function P(e) {
893
- return !!e && (e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement);
894
927
  }
895
- function ut(e, t) {
896
- let n = (e.getAttribute("aria-describedby") || "").trim();
897
- if (!n) return;
898
- let r = n.split(/\s+/).filter((e) => e !== t);
899
- if (r.length) {
900
- e.setAttribute("aria-describedby", r.join(" "));
928
+ function z(e, t) {
929
+ if (wt(e), Tt(e), Et(e), Dt(e), t.ok) {
930
+ Mt(e, t) && Nt(e, t.message || "", { hideForm: t.action !== "save" });
901
931
  return;
902
932
  }
903
- e.removeAttribute("aria-describedby");
933
+ if (!t.ok) {
934
+ if (At(t)) {
935
+ let n = String(t.payment?.message || "").trim();
936
+ n && jt(e, n);
937
+ return;
938
+ }
939
+ t.fieldErrors && Ot(e, t.fieldErrors), t.formErrors?.length ? kt(e, t.formErrors) : !t.fieldErrors && t.message && kt(e, [t.message]), We(e);
940
+ }
904
941
  }
905
- function dt(e, t) {
906
- let n = (e.getAttribute("aria-describedby") || "").trim(), r = n ? n.split(/\s+/) : [];
907
- r.includes(t) || r.push(t), e.setAttribute("aria-describedby", r.join(" ").trim());
942
+ //#endregion
943
+ //#region src/js/core/submit-flow.ts
944
+ var Pt = E("general", "submit-flow");
945
+ function Ft(e) {
946
+ return !(!e.ok && e.stage === "validate");
908
947
  }
909
- function ft(e, t) {
910
- e.setAttribute("aria-errormessage", t);
948
+ function It(e) {
949
+ return e ? !!(e.keepSubmitLoading === !0 || e.ok && e.redirect?.url && e.redirect.target !== "new-tab") : !1;
911
950
  }
912
- function pt(e, t) {
913
- e.getAttribute("aria-errormessage") === t && e.removeAttribute("aria-errormessage");
951
+ function Lt(e) {
952
+ wt(e), Tt(e), Et(e), Dt(e);
914
953
  }
915
- var mt = class {
916
- constructor(e, t = {}) {
917
- this.errors = [], this.validators = {}, this.boundListeners = !1, this.activated = /* @__PURE__ */ new WeakSet(), this.submitted = !1, this.initialValues = /* @__PURE__ */ new WeakMap(), this.form = e, this.onBlur = this.blurHandler.bind(this), this.onChange = this.changeHandler.bind(this), this.onInput = this.inputHandler.bind(this), this.config = {
918
- live: !1,
919
- errorAriaLive: "polite",
920
- errorMessage: "",
921
- fieldContainerErrorClass: [],
922
- inputErrorClass: [],
923
- messagesClass: [],
924
- messageClass: [],
925
- fieldsSelector: "input:not([type=\"hidden\"]):not([type=\"submit\"]):not([type=\"button\"]):not([disabled]), select:not([disabled]), textarea:not([disabled])",
926
- patterns: lt,
927
- ...t
928
- }, Object.entries(ct).forEach(([e, t]) => {
929
- this.addValidator(e, t.rule, t.message);
930
- }), this.init();
954
+ async function Rt(e) {
955
+ let { id: t, target: n, form: r, bus: i, validator: a, validateOnSubmit: o, action: s, submitter: c, waitForSubmitDelay: l, onRefreshTokensAfterSubmit: u, dispatchSubmitResult: d } = e;
956
+ Lt(r), v(r, c || null);
957
+ let f = {
958
+ ok: !1,
959
+ code: "SUBMIT_ERROR",
960
+ message: "Submission failed.",
961
+ formErrors: ["Submission failed."]
962
+ };
963
+ try {
964
+ await l(r), f = await ct(r, s, i, {
965
+ validator: a,
966
+ validateOnSubmit: o
967
+ }), z(r, f), d(f), b(r, f, s), Ft(f) && await u(f);
968
+ } catch (e) {
969
+ f = {
970
+ ok: !1,
971
+ code: "SUBMIT_ERROR",
972
+ message: e instanceof Error ? e.message : "Submission failed.",
973
+ formErrors: [e instanceof Error ? e.message : "Submission failed."]
974
+ }, z(r, f), d(f), Pt.warn("Submit failed with exception.", {
975
+ id: t,
976
+ action: s,
977
+ target: n,
978
+ error: e instanceof Error ? e.message : e
979
+ });
980
+ } finally {
981
+ It(f) || h(r);
982
+ }
983
+ return f;
984
+ }
985
+ //#endregion
986
+ //#region src/js/events/event-bus.ts
987
+ var zt = class {
988
+ listeners = /* @__PURE__ */ new Map();
989
+ on(e, t) {
990
+ return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e)?.add(t), () => {
991
+ this.listeners.get(e)?.delete(t);
992
+ };
993
+ }
994
+ async emit(e, t) {
995
+ let n = this.listeners.get(e);
996
+ if (n && n.size !== 0) for (let e of n) await e(t);
997
+ }
998
+ async emitSafe(e, t) {
999
+ let n = this.listeners.get(e), r = {
1000
+ eventName: e,
1001
+ total: n?.size || 0,
1002
+ succeeded: 0,
1003
+ failed: []
1004
+ };
1005
+ if (!n || n.size === 0) return r;
1006
+ let i = 0;
1007
+ for (let e of n) {
1008
+ try {
1009
+ await e(t), r.succeeded += 1;
1010
+ } catch (e) {
1011
+ r.failed.push({
1012
+ index: i,
1013
+ error: e
1014
+ });
1015
+ }
1016
+ i += 1;
1017
+ }
1018
+ return r;
1019
+ }
1020
+ async emitParallelSafe(e, t) {
1021
+ let n = this.listeners.get(e), r = {
1022
+ eventName: e,
1023
+ total: n?.size || 0,
1024
+ succeeded: 0,
1025
+ failed: []
1026
+ };
1027
+ return !n || n.size === 0 || (await Promise.allSettled(Array.from(n).map(async (e) => e(t)))).forEach((e, t) => {
1028
+ if (e.status === "fulfilled") {
1029
+ r.succeeded += 1;
1030
+ return;
1031
+ }
1032
+ r.failed.push({
1033
+ index: t,
1034
+ error: e.reason
1035
+ });
1036
+ }), r;
1037
+ }
1038
+ clear() {
1039
+ this.listeners.clear();
1040
+ }
1041
+ }, B = class {
1042
+ modules = /* @__PURE__ */ new Map();
1043
+ register(e, t = {}) {
1044
+ if (!/^[a-z][a-z0-9.-]*:[a-z][a-z0-9.-]*$/.test(e.moduleId) || e.version !== 2 || !Array.isArray(e.surfaces) || e.surfaces.length === 0 || e.surfaces.some((e) => ![
1045
+ "server-rendered",
1046
+ "client-rendered",
1047
+ "cp-edit"
1048
+ ].includes(e)) || ![
1049
+ "field",
1050
+ "captcha",
1051
+ "payment",
1052
+ "address",
1053
+ "core"
1054
+ ].includes(e.kind) || typeof e.match != "function" || typeof e.setup != "function") throw Error("Unsupported browser module definition. Register a namespaced moduleId compatible with version 2.");
1055
+ let n = this.modules.get(e.moduleId);
1056
+ return n === e ? !0 : n && !t.replace ? (console.warn(`[formie] Module "${e.moduleId}" is already registered. Pass { replace: true } to override the existing definition.`), !1) : (this.modules.set(e.moduleId, e), !0);
1057
+ }
1058
+ unregister(e) {
1059
+ this.modules.delete(e);
1060
+ }
1061
+ get(e) {
1062
+ return this.modules.get(e) || null;
1063
+ }
1064
+ getAll() {
1065
+ return Array.from(this.modules.values());
1066
+ }
1067
+ }, Bt = new B(), Vt = {
1068
+ "address-finder": () => import("./chunks/address-finder-BWGINCSA.js").then((e) => e.addressFinderModule),
1069
+ "google-address": () => import("./chunks/google-address-JHYvjwgN.js").then((e) => e.googleAddressModule),
1070
+ loqate: () => import("./chunks/loqate-m51iPyO1.js").then((e) => e.loqateModule),
1071
+ "place-kit": () => import("./chunks/place-kit-BnZGQ-L1.js").then((e) => e.placeKitModule)
1072
+ }, Ht = {
1073
+ "captcha-eu": () => import("./chunks/captcha-eu-DWLoQFKB.js").then((e) => e.captchaEuModule),
1074
+ "friendly-captcha-v1": () => import("./chunks/friendly-captcha-v1-CVXaXgDO.js").then((e) => e.friendlyCaptchaV1Module),
1075
+ "friendly-captcha-v2": () => import("./chunks/friendly-captcha-v2-DkeIVTKI.js").then((e) => e.friendlyCaptchaV2Module),
1076
+ hcaptcha: () => import("./chunks/hcaptcha-Dt3ELLlP.js").then((e) => e.hcaptchaModule),
1077
+ "recaptcha-enterprise": () => import("./chunks/recaptcha-enterprise-CUs8BO6V.js").then((e) => e.recaptchaEnterpriseModule),
1078
+ "recaptcha-v2-checkbox": () => import("./chunks/recaptcha-v2-checkbox-P1McW4Pv.js").then((e) => e.recaptchaV2CheckboxModule),
1079
+ "recaptcha-v2-invisible": () => import("./chunks/recaptcha-v2-invisible-FGDqozSP.js").then((e) => e.recaptchaV2InvisibleModule),
1080
+ "recaptcha-v3": () => import("./chunks/recaptcha-v3-CflUHeZD.js").then((e) => e.recaptchaV3Module),
1081
+ snaptcha: () => import("./chunks/snaptcha-C3QLYxFT.js").then((e) => e.snaptchaModule),
1082
+ turnstile: () => import("./chunks/turnstile-ptihQfLl.js").then((e) => e.turnstileModule)
1083
+ }, Ut = {
1084
+ calculations: () => import("./chunks/calculations-YEoVCG2q.js").then((e) => e.calculationsModule),
1085
+ "checkbox-radio": () => import("./chunks/checkbox-radio-gsm8QPJg.js").then((e) => e.checkboxRadioModule),
1086
+ combobox: () => import("./chunks/combobox-Ba08_cHL.js").then((e) => e.comboboxModule),
1087
+ conditions: () => import("./chunks/conditions-Ceeg6ReZ.js").then((e) => e.conditionsModule),
1088
+ "custom-google-maps": () => import("./chunks/custom-google-maps-C4l2S3GO.js").then((e) => e.customGoogleMapsModule),
1089
+ "custom-link": () => import("./chunks/custom-link-CLazgKYH.js").then((e) => e.customLinkModule),
1090
+ "custom-maps": () => import("./chunks/custom-maps-DqcAlD0v.js").then((e) => e.customMapsModule),
1091
+ "date-picker": () => import("./chunks/date-picker-DaPvMrop.js").then((e) => e.datePickerModule),
1092
+ "file-upload": () => import("./chunks/file-upload-B8_mH012.js").then((e) => e.fileUploadModule),
1093
+ "upload-manager": () => import("./chunks/upload-manager-BW7l-BhF.js").then((e) => e.uploadManagerModule),
1094
+ hidden: () => import("./chunks/hidden-BZhXnNPe.js").then((e) => e.hiddenModule),
1095
+ "phone-country": () => import("./chunks/phone-country-B8fv-L5_.js").then((e) => e.phoneCountryModule),
1096
+ "password-validation": () => import("./chunks/password-validation-C8_uO_c_.js").then((e) => e.passwordValidationModule),
1097
+ "address-country": () => import("./chunks/address-country-BcEQKw0T.js").then((e) => e.addressCountryModule),
1098
+ "address-state": () => import("./chunks/address-state-DI3ndhMU.js").then((e) => e.addressStateModule),
1099
+ repeater: () => import("./chunks/repeater-CyhDbozO.js").then((e) => e.repeaterModule),
1100
+ "rich-text": () => import("./chunks/rich-text-uV4o_pGk.js").then((e) => e.richTextModule),
1101
+ signature: () => import("./chunks/signature-7cldFbqj.js").then((e) => e.signatureModule),
1102
+ summary: () => import("./chunks/summary-Bn-g5SDx.js").then((e) => e.summaryModule),
1103
+ "survey-likert": () => import("./chunks/survey-likert-fk1hUPff.js").then((e) => e.surveyLikertModule),
1104
+ "survey-rank": () => import("./chunks/survey-rank-BsLGl2LX.js").then((e) => e.surveyRankModule),
1105
+ "survey-rating": () => import("./chunks/survey-rating-DVS6e6fM.js").then((e) => e.surveyRatingModule),
1106
+ table: () => import("./chunks/table-j7MlLLCc.js").then((e) => e.tableModule),
1107
+ "text-limit": () => import("./chunks/text-limit-LGMPhFuC.js").then((e) => e.textLimitModule)
1108
+ }, Wt = {
1109
+ bpoint: () => import("./chunks/bpoint-BwtuyN_O.js").then((e) => e.bpointModule),
1110
+ eway: () => import("./chunks/eway-uw0DzU-L.js").then((e) => e.ewayModule),
1111
+ "go-cardless": () => import("./chunks/go-cardless-c4wLJdOt.js").then((e) => e.goCardlessModule),
1112
+ mollie: () => import("./chunks/mollie-Bn0PX173.js").then((e) => e.mollieModule),
1113
+ moneris: () => import("./chunks/moneris-BRbUvI4t.js").then((e) => e.monerisModule),
1114
+ opayo: () => import("./chunks/opayo-BwWdInEP.js").then((e) => e.opayoModule),
1115
+ paddle: () => import("./chunks/paddle-CympHVvd.js").then((e) => e.paddleModule),
1116
+ paypal: () => import("./chunks/paypal-h75h6wae.js").then((e) => e.paypalModule),
1117
+ payway: () => import("./chunks/payway-C9rHTCC_.js").then((e) => e.paywayModule),
1118
+ square: () => import("./chunks/square-C1z5DPVw.js").then((e) => e.squareModule),
1119
+ stripe: () => import("./chunks/stripe-Dmkdkq1y.js").then((e) => e.stripeModule)
1120
+ }, Gt = {
1121
+ ...Ut,
1122
+ ...Vt,
1123
+ ...Ht,
1124
+ ...Wt
1125
+ }, V = /* @__PURE__ */ new Map();
1126
+ function Kt(e) {
1127
+ if (e instanceof Error) return {
1128
+ name: e.name || "Error",
1129
+ message: e.message || "No error message was provided.",
1130
+ stack: e.stack
1131
+ };
1132
+ if (typeof e == "string") return {
1133
+ name: "Error",
1134
+ message: e
1135
+ };
1136
+ try {
1137
+ return {
1138
+ name: "Error",
1139
+ message: JSON.stringify(e) || String(e)
1140
+ };
1141
+ } catch {
1142
+ return {
1143
+ name: "Error",
1144
+ message: String(e)
1145
+ };
1146
+ }
1147
+ }
1148
+ function qt(e, t, n) {
1149
+ let r = [...t].filter((e) => e.required), i = [
1150
+ "Formie browser module diagnostics",
1151
+ `Surface: ${e}`,
1152
+ `Browser: ${typeof navigator > "u" ? "Unavailable" : navigator.userAgent}`
1153
+ ];
1154
+ return e === "cp-edit" && typeof location < "u" && i.push(`Page: ${location.origin}${location.pathname}`), r.forEach((t, r) => {
1155
+ let a = n.get(t.key);
1156
+ i.push("", `Failure ${r + 1}`, `Module: ${t.moduleId}`, `Key: ${t.key}`, `Code: ${t.code}`), e === "cp-edit" && a && (i.push(`Error: ${a.name}: ${a.message}`), a.stack && i.push("Stack:", a.stack));
1157
+ }), i.join("\n");
1158
+ }
1159
+ async function Jt(e) {
1160
+ if (navigator.clipboard?.writeText) {
1161
+ await navigator.clipboard.writeText(e);
1162
+ return;
1163
+ }
1164
+ let t = document.createElement("textarea");
1165
+ t.value = e, t.setAttribute("readonly", ""), t.style.position = "fixed", t.style.opacity = "0", document.body.appendChild(t), t.select();
1166
+ try {
1167
+ if (!document.execCommand("copy")) throw Error("The browser did not allow clipboard access.");
1168
+ } finally {
1169
+ t.remove();
1170
+ }
1171
+ }
1172
+ async function Yt(e, t) {
1173
+ let n = t.get(e);
1174
+ if (n) return n;
1175
+ let r = e.startsWith("formie:") && Object.prototype.hasOwnProperty.call(Gt, e.slice(7)) ? Gt[e.slice(7)] : void 0;
1176
+ if (!r) throw Error(`Browser module ${e} is not registered.`);
1177
+ V.has(e) || V.set(e, r().catch((t) => {
1178
+ throw V.delete(e), t;
1179
+ }));
1180
+ let i = await V.get(e);
1181
+ if (i.moduleId !== e) throw Error(`Module definition does not match ${e}.`);
1182
+ return t.register(i), i;
1183
+ }
1184
+ function Xt(e, t, n) {
1185
+ return [...new Set(e.targets.flatMap((e) => {
1186
+ if (e.type === "form") return [n || t];
1187
+ let r = e.type === "selector" ? e.selector : e.type === "field" ? `[data-formie-field-uid="${CSS.escape(e.uid)}"]` : e.type === "page" ? `[data-formie-page-id="${CSS.escape(e.id)}"]` : `[data-formie-action="${CSS.escape(e.action)}"]`;
1188
+ return [...t.matches(r) ? [t] : [], ...t.querySelectorAll(r)];
1189
+ }))].filter((e) => !e.closest("[hidden], [data-formie-hidden=\"true\"], [data-formie-conditionally-hidden], [data-formie-page-hidden]"));
1190
+ }
1191
+ async function Zt(e, t) {
1192
+ n(e);
1193
+ let r = e.surface;
1194
+ if (t.matchContext.surface !== r || t.setupContext.surface !== r) throw Error(`Browser module manifest surface ${r} cannot mount as ${t.matchContext.surface}.`);
1195
+ let { root: i, form: a } = t.setupContext, o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), l = [], u = !1, d = Promise.resolve(), f = !1, p = async (e, n) => {
1196
+ let i = {
1197
+ key: e.key,
1198
+ moduleId: e.moduleId,
1199
+ required: e.required,
1200
+ surface: r,
1201
+ code: "MODULE_UNAVAILABLE",
1202
+ message: "A form feature could not start. Reload the page or contact the site administrator."
1203
+ };
1204
+ s.set(e.key, i), c.set(e.key, Kt(n)), console.error("[formie] Browser module failure", i, n), await t.setupContext.emit("formie:browser:module:error", i);
1205
+ }, m = async (e) => {
1206
+ try {
1207
+ await e.destroy();
1208
+ } catch (n) {
1209
+ console.error("[formie] Browser module disposal failed", n), await t.setupContext.emit("formie:browser:module:error", {
1210
+ key: e.key,
1211
+ moduleId: e.moduleId,
1212
+ surface: r,
1213
+ code: "MODULE_DISPOSE_FAILED",
1214
+ message: "A form feature could not clean up. Reload the page before continuing."
1215
+ });
1216
+ }
1217
+ }, h = () => [...s.values()].some((e) => e.required), g = () => {
1218
+ if (!a) return;
1219
+ let e = a.querySelector("[data-formie-module-error]");
1220
+ if (!e) {
1221
+ let t = document.createElement("p");
1222
+ t.textContent = r === "cp-edit" ? "Reload the page. If the problem continues, copy the technical details below." : "Reload the page or contact the site administrator.";
1223
+ let n = document.createElement("pre");
1224
+ if (n.dataset.formieModuleErrorDetails = "true", n.tabIndex = 0, r === "cp-edit") e = document.createElement("pk-alert"), e.className = "formie-module-error", e.setAttribute("variant", "error"), e.setAttribute("announce", "assertive"), e.setAttribute("heading", "A required form feature could not start."), e.setAttribute("details-label", "Details"), e.setAttribute("copy-label", "Copy details"), e.setAttribute("copied-label", "Details copied."), e.setAttribute("copyable", ""), n.slot = "details", e.append(t, n);
1225
+ else {
1226
+ e = document.createElement("div"), e.className = "formie-module-error formie-module-error--fallback";
1227
+ let r = document.createElement("div");
1228
+ r.className = "formie-module-error__notice", r.setAttribute("role", "alert");
1229
+ let i = document.createElement("span");
1230
+ i.className = "formie-module-error__indicator", i.setAttribute("aria-hidden", "true"), i.textContent = "!";
1231
+ let a = document.createElement("div");
1232
+ a.className = "formie-module-error__content";
1233
+ let o = document.createElement("strong");
1234
+ o.className = "formie-module-error__title", o.textContent = "A required form feature could not start.", a.append(o, t), r.append(i, a);
1235
+ let s = document.createElement("details");
1236
+ s.className = "formie-module-error__details";
1237
+ let c = document.createElement("summary");
1238
+ c.textContent = "Details";
1239
+ let l = document.createElement("div");
1240
+ l.className = "formie-module-error__actions";
1241
+ let u = document.createElement("button");
1242
+ u.className = "formie-module-error__copy", u.type = "button", u.textContent = "Copy details";
1243
+ let d = document.createElement("span");
1244
+ d.className = "formie-module-error__copy-status", d.setAttribute("role", "status"), d.setAttribute("aria-live", "polite"), u.addEventListener("click", async () => {
1245
+ try {
1246
+ await Jt(n.textContent || ""), d.textContent = "Details copied.";
1247
+ } catch {
1248
+ d.textContent = "Copy failed. Select the details above and copy them manually.";
1249
+ let e = document.createRange();
1250
+ e.selectNodeContents(n), window.getSelection()?.removeAllRanges(), window.getSelection()?.addRange(e);
1251
+ }
1252
+ }), l.append(u, d), s.append(c, n, l), e.append(r, s);
1253
+ }
1254
+ e.dataset.formieModuleError = "true", i !== a && a.contains(i) ? i.before(e) : a.prepend(e);
1255
+ }
1256
+ let t = e.querySelector("[data-formie-module-error-details]"), n = qt(r, s.values(), c);
1257
+ t && t.textContent !== n && (t.textContent = n);
1258
+ }, _ = (e) => {
1259
+ h() && (e.preventDefault(), e.stopImmediatePropagation(), g());
1260
+ }, v = async () => {
1261
+ let n = new Set(e.entries.map((e) => e.key));
1262
+ for (let e of s.keys()) n.has(e) || (s.delete(e), c.delete(e));
1263
+ let d = [];
1264
+ for (let [e, t] of o) n.has(e) || (d.push(...Array.from(t.values(), ({ instance: e }) => e)), o.delete(e), s.delete(e), c.delete(e));
1265
+ for (let e of d.reverse()) await m(e), l.splice(l.indexOf(e), 1);
1266
+ for (let n of e.entries) {
1267
+ if (u) continue;
1268
+ let e = s.get(n.key);
1269
+ e && s.set(n.key, {
1270
+ ...e,
1271
+ required: n.required
1272
+ });
1273
+ let d;
1274
+ try {
1275
+ d = Xt(n, i, a);
1276
+ } catch (e) {
1277
+ s.has(n.key) || await p(n, e);
1278
+ continue;
1279
+ }
1280
+ let f = o.get(n.key) ?? /* @__PURE__ */ new Map();
1281
+ o.set(n.key, f);
1282
+ for (let [e, t] of Array.from(f.entries()).reverse()) d.includes(e) || (await m(t.instance), f.delete(e), l.splice(l.indexOf(t.instance), 1));
1283
+ let h;
1284
+ try {
1285
+ h = await Yt(n.moduleId, t.registry);
1286
+ } catch (e) {
1287
+ s.has(n.key) || await p(n, e);
1288
+ continue;
1289
+ }
1290
+ let g = !1, _ = !1;
1291
+ for (let e of d) {
1292
+ if (u) return;
1293
+ let a = JSON.stringify([
1294
+ n.moduleId,
1295
+ n.config,
1296
+ n.required
1297
+ ]), o = f.get(e);
1298
+ if (o?.config === a) continue;
1299
+ let c = {
1300
+ ...t.setupContext,
1301
+ target: e,
1302
+ entryKey: n.key,
1303
+ surface: r,
1304
+ scope: n.targets[0]?.type ?? "form",
1305
+ options: n.config
1306
+ };
1307
+ try {
1308
+ if (o) {
1309
+ if (o.instance.update && o.moduleId === n.moduleId && o.required === n.required) {
1310
+ await o.instance.update(c), o.config = a;
1311
+ continue;
1312
+ }
1313
+ await m(o.instance), f.delete(e), l.splice(l.indexOf(o.instance), 1);
1314
+ }
1315
+ if (h.surfaces && !h.surfaces.includes(r)) throw Error(`Module ${n.moduleId} does not support ${r}.`);
1316
+ if (h.kind !== n.kind) throw Error(`Module ${n.moduleId} is registered as ${h.kind}, not ${n.kind}.`);
1317
+ if (!h.match({
1318
+ ...t.matchContext,
1319
+ target: e,
1320
+ scope: c.scope,
1321
+ manifestItem: n
1322
+ })) throw Error(`Module ${n.moduleId} does not support the rendered target.`);
1323
+ let s = await h.setup(c);
1324
+ if (!s) throw Error(`Module ${n.moduleId} did not initialize.`);
1325
+ if (u || !i.contains(e) && e !== i) {
1326
+ await m(s);
1327
+ continue;
1328
+ }
1329
+ s.key = n.key, s.moduleId = n.moduleId, s.kind = n.kind, s.target = e;
1330
+ let d = s.assertReady;
1331
+ s.assertReady = () => {
1332
+ try {
1333
+ d?.();
1334
+ } catch (e) {
1335
+ if (p(n, e), n.required) throw Error("A required form feature could not start.");
1336
+ }
1337
+ };
1338
+ let g = s.beforeSubmit, v = s.afterSubmit;
1339
+ s.beforeSubmit = async (e) => {
1340
+ try {
1341
+ await g?.(e);
1342
+ } catch (t) {
1343
+ await p(n, t), n.required && e.abort("A required form feature could not complete. Reload the page or contact the site administrator.");
1344
+ }
1345
+ }, s.afterSubmit = async (e, t) => {
1346
+ try {
1347
+ await v?.(e, t);
1348
+ } catch (e) {
1349
+ await p(n, e);
1350
+ }
1351
+ }, f.set(e, {
1352
+ instance: s,
1353
+ config: a,
1354
+ moduleId: n.moduleId,
1355
+ required: n.required
1356
+ }), l.push(s), _ = !0, await t.setupContext.emit("formie:browser:module:mount", {
1357
+ key: n.key,
1358
+ moduleId: n.moduleId,
1359
+ target: e
1360
+ });
1361
+ } catch (e) {
1362
+ g = !0, s.has(n.key) || await p(n, e);
1363
+ }
1364
+ }
1365
+ !g && (_ || d.length === 0) && (s.delete(n.key), c.delete(n.key));
1366
+ }
1367
+ h() ? g() : a?.querySelector("[data-formie-module-error]")?.remove();
1368
+ }, y = new MutationObserver(() => {
1369
+ f || u || (f = !0, d = d.then(async () => {
1370
+ f = !1, u || await v();
1371
+ }), d.catch((e) => console.error("[formie] Module reconciliation failed", e)));
1372
+ });
1373
+ return a?.addEventListener("submit", _, !0), await v(), y.observe(i, {
1374
+ childList: !0,
1375
+ subtree: !0,
1376
+ attributes: !0,
1377
+ attributeFilter: [
1378
+ "hidden",
1379
+ "data-formie-hidden",
1380
+ "data-formie-conditionally-hidden",
1381
+ "data-formie-page-hidden",
1382
+ "data-formie-field-uid",
1383
+ "data-formie-page-id",
1384
+ "data-formie-action"
1385
+ ]
1386
+ }), {
1387
+ get instances() {
1388
+ return l;
1389
+ },
1390
+ get failures() {
1391
+ return [...s.values()];
1392
+ },
1393
+ assertReady: () => {
1394
+ if (h()) throw Error("A required form feature could not start. Reload the page or contact the site administrator.");
1395
+ },
1396
+ destroy: async () => {
1397
+ u = !0, y.disconnect(), a?.removeEventListener("submit", _, !0), await d;
1398
+ for (let e of Array.from(o.values()).reverse()) for (let { instance: t } of Array.from(e.values()).reverse()) await m(t);
1399
+ o.clear(), l.splice(0), s.clear(), c.clear(), a?.querySelector("[data-formie-module-error]")?.remove();
1400
+ },
1401
+ updateManifest: async (t) => {
1402
+ if (n(t), t.surface !== r) throw Error("A mounted browser module runtime cannot change surfaces.");
1403
+ e = t, d = d.then(v), await d;
1404
+ }
1405
+ };
1406
+ }
1407
+ //#endregion
1408
+ //#region src/js/utils/form-started-at.ts
1409
+ var Qt = "formie:formStartedAt:";
1410
+ function $t(e) {
1411
+ let t = e.querySelector("input[name=\"formStartedAt\"]");
1412
+ if (!t) return;
1413
+ let n = e.querySelector("input[name=\"renderId\"]")?.value?.trim() ?? "", r = n ? `${Qt}${n}` : null, i = r ? sessionStorage.getItem(r) : null;
1414
+ i || (i = String(Date.now()), r && sessionStorage.setItem(r, i)), t.value = i;
1415
+ }
1416
+ //#endregion
1417
+ //#region src/js/utils/unload-warning.ts
1418
+ var en = /* @__PURE__ */ new Set([
1419
+ "action",
1420
+ "redirect",
1421
+ "requestToken",
1422
+ "uploadCreateToken",
1423
+ "renderId",
1424
+ "formStartedAt",
1425
+ "submitAction",
1426
+ "pageId",
1427
+ "draftContextToken",
1428
+ "draftContext",
1429
+ "progressId"
1430
+ ]);
1431
+ function tn(e, t) {
1432
+ if (e == null) return String(e);
1433
+ if (typeof e == "string") return JSON.stringify(e);
1434
+ if (typeof e == "number" || typeof e == "boolean") return String(e);
1435
+ if (typeof e == "function") return "[function]";
1436
+ if (typeof File < "u" && e instanceof File) return `[file:${e.name}:${e.size}:${e.type}]`;
1437
+ if (typeof Blob < "u" && e instanceof Blob) return `[blob:${e.size}:${e.type}]`;
1438
+ if (Array.isArray(e)) return `[${e.map((e) => tn(e, t)).join(",")}]`;
1439
+ if (typeof e == "object") {
1440
+ if (t.has(e)) return "[circular]";
1441
+ t.add(e);
1442
+ let n = Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).map(([e, n]) => `${JSON.stringify(e)}:${tn(n, t)}`);
1443
+ return t.delete(e), `{${n.join(",")}}`;
1444
+ }
1445
+ return JSON.stringify(String(e));
1446
+ }
1447
+ function nn(e) {
1448
+ return tn(e, /* @__PURE__ */ new WeakSet());
1449
+ }
1450
+ function rn(e, t) {
1451
+ if (!e) return !1;
1452
+ let n = e.endsWith("[]") ? e.slice(0, -2) : e;
1453
+ return !re(n, t) && !en.has(n);
1454
+ }
1455
+ function an(e) {
1456
+ return nn(Array.from(new FormData(e).entries()).filter(([t]) => rn(String(t || ""), e)));
1457
+ }
1458
+ function on(e, t = {}) {
1459
+ let n = null, r = !1, i = !1, a = null, o = null, s = null, c = () => {
1460
+ a !== null && (window.cancelAnimationFrame(a), a = null), o !== null && (window.clearTimeout(o), o = null), s !== null && (window.clearTimeout(s), s = null);
1461
+ }, l = () => r ? (i = an(e) !== n, i) : !1, u = () => {
1462
+ n = an(e), r = !0, i = !1;
1463
+ }, d = () => {
1464
+ c(), r = !1, a = window.requestAnimationFrame(() => {
1465
+ a = null, s = window.setTimeout(() => {
1466
+ s = null, u();
1467
+ }, 0);
1468
+ });
1469
+ }, f = () => {
1470
+ o !== null && window.clearTimeout(o), o = window.setTimeout(() => {
1471
+ o = null, l();
1472
+ }, 120);
1473
+ }, p = (e) => {
1474
+ (!t.shouldWarn || t.shouldWarn()) && l() && (e.preventDefault(), e.returnValue = "");
1475
+ };
1476
+ return e.addEventListener("input", f), e.addEventListener("change", f), window.addEventListener("beforeunload", p), d(), {
1477
+ captureBaseline: u,
1478
+ scheduleBaselineCapture: d,
1479
+ refreshDirtyState: l,
1480
+ destroy: () => {
1481
+ c(), e.removeEventListener("input", f), e.removeEventListener("change", f), window.removeEventListener("beforeunload", p);
1482
+ }
1483
+ };
1484
+ }
1485
+ //#endregion
1486
+ //#region src/js/validation/rules/email.ts
1487
+ var sn = {
1488
+ rule: ({ input: e, getRule: n }) => {
1489
+ let r = n("email");
1490
+ return !r || t(e.value, {
1491
+ ...typeof r == "object" ? r : {},
1492
+ type: "email"
1493
+ }) === null;
1494
+ },
1495
+ message: ({ input: e, label: t, t: n }) => e.getAttribute("data-formie-validation-email-message") ?? e.getAttribute("data-formie-pattern-email-message") ?? e.getAttribute("data-pattern-email-message") ?? n("{label} is not a valid email address.", { label: t })
1496
+ };
1497
+ //#endregion
1498
+ //#region src/js/validation/rules/shared.ts
1499
+ function cn(e) {
1500
+ return e?.querySelector("[data-formie-field-label]")?.childNodes[0]?.textContent?.trim() || "";
1501
+ }
1502
+ function ln(e) {
1503
+ let t = e.getRule("match");
1504
+ if (!t || t === !0 || typeof t != "object" || !e.field) return null;
1505
+ let n = typeof t.fieldHandle == "string" ? t.fieldHandle.trim() : "";
1506
+ if (!n) return null;
1507
+ let r = e.form.querySelector(`[data-formie-field-handle="${n}"]`);
1508
+ return r ? Array.from(r.querySelectorAll(e.config.fieldsSelector)).find((e) => (e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement) && !k(e)) ?? null : null;
1509
+ }
1510
+ //#endregion
1511
+ //#region src/js/validation/rules.ts
1512
+ var un = {
1513
+ required: {
1514
+ rule: ({ input: e, getRule: n }) => {
1515
+ if (!n("required") || e.type === "hidden") return !0;
1516
+ if (e instanceof HTMLInputElement && e.type === "file") {
1517
+ if (e.files?.length) return !0;
1518
+ let t = e.closest("[data-formie-field-handle]"), n = e.name.replace(/\[\]$/, "");
1519
+ return Array.from(t?.querySelectorAll("input[type=\"hidden\"][data-formie-file-upload-asset-id]") || []).some((e) => !e.disabled && e.name.startsWith(`${n}[`) && Number(e.getAttribute("data-formie-file-upload-asset-id")) > 0);
1520
+ }
1521
+ if (e.type === "checkbox" || e.type === "radio") {
1522
+ let t = e.form?.querySelectorAll(`[name="${e.name}"]:not([type="hidden"]):not([disabled])`) || [];
1523
+ return t.length ? Array.from(t).some((e) => e instanceof HTMLInputElement && e.checked) : e instanceof HTMLInputElement ? e.checked : !0;
1524
+ }
1525
+ return t(e.value, { type: "required" }) === null;
1526
+ },
1527
+ message: ({ input: e, label: t, t: n }) => e.getAttribute("data-formie-required-message") ?? e.getAttribute("data-required-message") ?? n("{label} cannot be blank.", { label: t })
1528
+ },
1529
+ email: sn,
1530
+ url: {
1531
+ rule: ({ input: e, getRule: n }) => {
1532
+ let r = n("url");
1533
+ return !r || t(e.value, {
1534
+ ...typeof r == "object" ? r : {},
1535
+ type: "url"
1536
+ }) === null;
1537
+ },
1538
+ message: ({ input: e, label: t, t: n }) => e.getAttribute("data-formie-pattern-url-message") ?? e.getAttribute("data-pattern-url-message") ?? n("{label} is not a valid URL.", { label: t })
1539
+ },
1540
+ number: {
1541
+ rule: ({ input: e, getRule: n }) => {
1542
+ let r = n("number");
1543
+ return !r || t(e.value, {
1544
+ ...typeof r == "object" ? r : {},
1545
+ type: "number"
1546
+ }) === null;
1547
+ },
1548
+ message: ({ input: e, label: n, getRule: r, t: i }) => {
1549
+ let a = r("number");
1550
+ return t(e.value, {
1551
+ ...typeof a == "object" ? a : {},
1552
+ type: "number"
1553
+ }, { label: n }) ?? i("{label} is not a valid number.", { label: n });
1554
+ }
1555
+ },
1556
+ match: {
1557
+ rule: (e) => {
1558
+ let n = ln(e);
1559
+ return !n || t(e.input.value, { type: "match" }, { comparison: n.value }) === null;
1560
+ },
1561
+ message: (e) => {
1562
+ let t = ln(e)?.closest("[data-formie-field-handle]"), n = cn(t);
1563
+ return e.input.getAttribute("data-formie-validation-match-message") ?? e.t("{label} must match {value}.", {
1564
+ label: e.label,
1565
+ value: n
1566
+ });
1567
+ }
1568
+ }
1569
+ }, dn = {
1570
+ 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,})+$/,
1571
+ 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*)?$/,
1572
+ number: /^(?:[-+]?[0-9]*[.,]?[0-9]+)$/,
1573
+ color: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,
1574
+ 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))/,
1575
+ time: /^(?:(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9]))$/,
1576
+ month: /^(?:(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])))$/
1577
+ }, H = E("general", "validator");
1578
+ function U(e) {
1579
+ return !!e && (e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement);
1580
+ }
1581
+ function fn(e) {
1582
+ return !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
1583
+ }
1584
+ var pn = class {
1585
+ form;
1586
+ errors = [];
1587
+ validators = {};
1588
+ boundListeners = !1;
1589
+ activated = /* @__PURE__ */ new WeakSet();
1590
+ submitted = !1;
1591
+ initialValues = /* @__PURE__ */ new WeakMap();
1592
+ onBlur;
1593
+ onChange;
1594
+ onInput;
1595
+ config;
1596
+ constructor(e, t = {}) {
1597
+ this.form = e, this.onBlur = this.blurHandler.bind(this), this.onChange = this.changeHandler.bind(this), this.onInput = this.inputHandler.bind(this), this.config = {
1598
+ live: !1,
1599
+ errorAriaLive: "polite",
1600
+ errorMessage: "",
1601
+ fieldContainerErrorClass: [],
1602
+ inputErrorClass: [],
1603
+ messagesClass: [],
1604
+ messageClass: [],
1605
+ fieldsSelector: "input:not([type=\"hidden\"]):not([type=\"submit\"]):not([type=\"button\"]):not([disabled]), select:not([disabled]), textarea:not([disabled])",
1606
+ patterns: dn,
1607
+ ...t
1608
+ }, Object.entries(un).forEach(([e, t]) => {
1609
+ this.addValidator(e, t.rule, t.message);
1610
+ }), this.init();
931
1611
  }
932
1612
  init() {
933
- N.log("Initializing validator.", {
1613
+ H.log("Initializing validator.", {
934
1614
  formId: this.form.id || null,
935
1615
  live: this.config.live
936
1616
  }), this.form.setAttribute("novalidate", "true"), this.inputs().forEach((e) => {
937
1617
  this.initialValues.set(e, this.getInputValue(e));
938
- }), this.config.live && this.addEventListeners(), this.emitEvent(document, n("ready"), { validator: this });
1618
+ }), this.config.live && this.addEventListeners(), this.emitEvent(document, o("ready"), { validator: this });
939
1619
  }
940
1620
  inputs(e = null) {
941
- if (P(e)) return [e];
1621
+ if (U(e)) return k(e) ? [] : [e];
942
1622
  let t = e || this.form;
943
- return Array.from(t.querySelectorAll(this.config.fieldsSelector)).filter((e) => P(e));
1623
+ return Array.from(t.querySelectorAll(this.config.fieldsSelector)).filter((e) => U(e) && !k(e));
944
1624
  }
945
1625
  getInputValue(e) {
946
1626
  return e instanceof HTMLInputElement && (e.type === "checkbox" || e.type === "radio") ? e.checked : e instanceof HTMLInputElement && e.type === "file" ? e.files?.length ? Array.from(e.files).map((e) => e.name).join("|") : "" : e.value ?? "";
@@ -980,7 +1660,7 @@ var mt = class {
980
1660
  }), r = !0;
981
1661
  }
982
1662
  }), !r && this.shouldShowError(e) && this.removeError(e);
983
- }), N.log("Validation pass complete.", {
1663
+ }), H.log("Validation pass complete.", {
984
1664
  errorCount: this.errors.length,
985
1665
  includeHiddenPages: t.includeHiddenPages === !0
986
1666
  }), this.errors;
@@ -996,685 +1676,162 @@ var mt = class {
996
1676
  e.removeAttribute("aria-invalid");
997
1677
  return;
998
1678
  }
999
- let r = t.querySelector("[data-formie-field-errors]"), i = r?.id || "";
1679
+ let n = t.querySelector("[data-formie-field-errors]"), r = Array.from(t.querySelectorAll("[data-formie-field-error]")).map((e) => e.id).filter(Boolean);
1000
1680
  t.querySelectorAll("[data-formie-field-error]").forEach((e) => {
1001
1681
  e.remove();
1002
- }), r && (r.innerHTML = ""), t.querySelectorAll("input, select, textarea").forEach((e) => {
1003
- let n = e;
1004
- n.removeAttribute("aria-invalid"), this.config.inputErrorClass.length && n.classList.remove(...this.config.inputErrorClass), n.removeAttribute("data-formie-input-has-error"), i && ut(n, i), t.querySelectorAll("[data-formie-field-error]").forEach((e) => {
1005
- let t = e.id;
1006
- t && pt(n, t);
1007
- });
1682
+ }), n && (n.innerHTML = ""), t.querySelectorAll("input, select, textarea").forEach((e) => {
1683
+ let t = e;
1684
+ t.removeAttribute("aria-invalid"), this.config.inputErrorClass.length && t.classList.remove(...this.config.inputErrorClass), t.removeAttribute("data-formie-input-has-error"), Re(t, r);
1008
1685
  });
1009
1686
  for (let e = t; e; e = e.parentElement?.closest("[data-formie-field-handle]")) this.config.fieldContainerErrorClass.length && e.classList.remove(...this.config.fieldContainerErrorClass), e.removeAttribute("data-formie-field-has-error");
1010
- this.emitEvent(e, n("clear-error"), { validator: this }), y(this.form);
1687
+ this.emitEvent(e, o("clear-error"), { validator: this }), C(this.form);
1011
1688
  }
1012
- showError(e, t, r) {
1013
- let i = e.closest("[data-formie-field-handle]");
1014
- if (!i) return;
1015
- let a = i.querySelector("[data-formie-field-errors]");
1016
- a ||= it(i, (e) => {
1689
+ showError(e, t, n) {
1690
+ let r = e.closest("[data-formie-field-handle]");
1691
+ if (!r) return;
1692
+ let i = r.querySelector("[data-formie-field-errors]");
1693
+ i ||= ut(r, (e) => {
1017
1694
  this.config.messagesClass.length && e.classList.add(...this.config.messagesClass);
1018
- }), this.config.messagesClass.length && a.classList.add(...this.config.messagesClass), a.innerHTML = "";
1019
- let o = i.getAttribute("data-formie-field-handle") || "field", s = `${o}-error`;
1020
- a.id = a.id || `${o}-errors`, Oe(a, Ee(this.config.errorAriaLive, this.submitted));
1695
+ }), this.config.messagesClass.length && i.classList.add(...this.config.messagesClass), i.innerHTML = "";
1696
+ let a = r.getAttribute("data-formie-field-handle") || "field";
1697
+ i.id = i.id || `${e.id || `${this.form.id}-${a}`}-errors`;
1698
+ let s = `${i.id}-1`;
1699
+ Fe(i, Ne(this.config.errorAriaLive, this.submitted));
1021
1700
  let c = document.createElement("div");
1022
- c.setAttribute("data-formie-field-error", "true"), c.setAttribute(`data-formie-field-error-${t}`, "true"), c.setAttribute("id", s), c.setAttribute("role", "alert"), this.config.messageClass.length && c.classList.add(...this.config.messageClass), c.textContent = r, a.appendChild(c), i.setAttribute("data-formie-field-has-error", "true"), i.querySelectorAll("input, select, textarea").forEach((e) => {
1701
+ c.setAttribute("data-formie-field-error", "true"), c.setAttribute(`data-formie-field-error-${t}`, "true"), c.setAttribute("id", s), this.config.messageClass.length && c.classList.add(...this.config.messageClass), c.textContent = n, i.appendChild(c), r.setAttribute("data-formie-field-has-error", "true"), r.querySelectorAll("input, select, textarea").forEach((e) => {
1023
1702
  let t = e;
1024
- t.setAttribute("aria-invalid", "true"), this.config.inputErrorClass.length && t.classList.add(...this.config.inputErrorClass), t.setAttribute("data-formie-input-has-error", "true"), dt(t, a.id), ft(t, s);
1703
+ k(t) || (t.setAttribute("aria-invalid", "true"), this.config.inputErrorClass.length && t.classList.add(...this.config.inputErrorClass), t.setAttribute("data-formie-input-has-error", "true"), M(t, s));
1025
1704
  });
1026
- for (let e = i; e; e = e.parentElement?.closest("[data-formie-field-handle]")) this.config.fieldContainerErrorClass.length && e.classList.add(...this.config.fieldContainerErrorClass), e.setAttribute("data-formie-field-has-error", "true");
1027
- this.emitEvent(e, n("show-error"), {
1705
+ for (let e = r; e; e = e.parentElement?.closest("[data-formie-field-handle]")) this.config.fieldContainerErrorClass.length && e.classList.add(...this.config.fieldContainerErrorClass), e.setAttribute("data-formie-field-has-error", "true");
1706
+ this.emitEvent(e, o("show-error"), {
1028
1707
  validator: this,
1029
1708
  validatorName: t,
1030
- errorMessage: r
1031
- }), y(this.form);
1709
+ errorMessage: n
1710
+ }), C(this.form);
1032
1711
  }
1033
1712
  getValidatorCallbackOptions(e) {
1034
1713
  let t = e.closest("[data-formie-field-handle]"), n = t?.querySelector("[data-formie-field-label]")?.childNodes[0]?.textContent?.trim() ?? "", r = this.parseValidationRules(t?.getAttribute("data-formie-validation"));
1035
- return {
1036
- t: D,
1037
- input: e,
1038
- label: n,
1039
- field: t,
1040
- form: this.form,
1041
- config: this.config,
1042
- rules: r,
1043
- getRule: (e) => this.getRule(t, e)
1044
- };
1045
- }
1046
- getErrorMessage(e, t, n, r) {
1047
- return (typeof n.errorMessage == "function" ? n.errorMessage(r) : n.errorMessage) ?? D("{label} is invalid.", { label: r.label });
1048
- }
1049
- getErrors() {
1050
- return this.errors;
1051
- }
1052
- getFieldErrors(e = this.errors) {
1053
- let t = {};
1054
- return e.forEach((e) => {
1055
- !e.handle || t[e.handle]?.length || (t[e.handle] = [e.message]);
1056
- }), t;
1057
- }
1058
- getRule(e, t) {
1059
- if (!e) return !1;
1060
- let n = this.parseValidationRules(e.getAttribute("data-formie-validation"));
1061
- return Object.prototype.hasOwnProperty.call(n, t) ? n[t] : !1;
1062
- }
1063
- parseValidationRules(e) {
1064
- let t = {};
1065
- if (!e) return t;
1066
- let n = null;
1067
- try {
1068
- n = JSON.parse(e);
1069
- } catch {
1070
- return N.warn("Invalid validation rules payload.", { formId: this.form.id || null }), t;
1071
- }
1072
- return Array.isArray(n) && n.forEach((e) => {
1073
- if (!e || typeof e != "object" || Array.isArray(e)) return;
1074
- let n = e, r = typeof n.type == "string" ? n.type.trim() : "";
1075
- r && (t[r] = n);
1076
- }), t;
1077
- }
1078
- destroy() {
1079
- N.log("Destroying validator.", { formId: this.form.id || null }), this.removeEventListeners(), this.form.removeAttribute("novalidate"), this.emitEvent(document, n("destroy"), { validator: this });
1080
- }
1081
- isVisible(e, t = {}) {
1082
- return e.disabled || e.hasAttribute("data-formie-conditions-disabled") || e.closest("[data-formie-conditions-disabled]") || e.closest("[data-formie-conditionally-hidden]") ? !1 : e.closest("[data-formie-page-hidden]") ? !!t.includeHiddenPages : !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
1083
- }
1084
- blurHandler(e) {
1085
- !(e.target instanceof HTMLElement) || !P(e.target) || !e.target.form?.isSameNode(this.form) || e instanceof CustomEvent || e.target instanceof HTMLInputElement && e.target.type === "file" || e.target instanceof HTMLInputElement && (e.target.type === "checkbox" || e.target.type === "radio") || (this.isDirty(e.target) && this.activated.add(e.target), this.shouldShowError(e.target) && this.validate(e.target));
1086
- }
1087
- changeHandler(e) {
1088
- if (!(!(e.target instanceof HTMLElement) || !P(e.target) || !e.target.form?.isSameNode(this.form)) && !(e instanceof CustomEvent)) {
1089
- if (e.target instanceof HTMLSelectElement) {
1090
- this.activated.add(e.target), this.validate(e.target);
1091
- return;
1092
- }
1093
- e.target instanceof HTMLInputElement && (e.target.type !== "file" && e.target.type !== "checkbox" && e.target.type !== "radio" || (this.activated.add(e.target), this.validate(e.target)));
1094
- }
1095
- }
1096
- inputHandler(e) {
1097
- !(e.target instanceof HTMLElement) || !P(e.target) || !e.target.form?.isSameNode(this.form) || e instanceof CustomEvent || e.target instanceof HTMLInputElement && (e.target.type === "checkbox" || e.target.type === "radio") || this.shouldShowError(e.target) && this.validate(e.target);
1098
- }
1099
- submit(e = null, { final: t = !1 } = {}) {
1100
- return this.submitted = !0, N.log("Submit validation requested.", { final: t }), this.boundListeners || this.addEventListeners(), this.removeAllErrors(), this.validate(e, { includeHiddenPages: t });
1101
- }
1102
- resetLiveState() {
1103
- this.submitted = !1, this.activated = /* @__PURE__ */ new WeakSet(), this.errors = [], this.removeAllErrors();
1104
- }
1105
- addEventListeners() {
1106
- 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, N.log("Event listeners attached."));
1107
- }
1108
- removeEventListeners() {
1109
- this.form.removeEventListener("blur", this.onBlur, !0), this.form.removeEventListener("change", this.onChange, !1), this.form.removeEventListener("input", this.onInput, !1), this.boundListeners = !1, N.log("Event listeners removed.");
1110
- }
1111
- emitEvent(e, t, n = {}) {
1112
- e.dispatchEvent(new CustomEvent(t, {
1113
- bubbles: !0,
1114
- detail: n
1115
- }));
1116
- }
1117
- addValidator(e, t, n) {
1118
- this.validators[e] = {
1119
- validate: t,
1120
- errorMessage: n
1121
- };
1122
- }
1123
- removeValidator(e) {
1124
- delete this.validators[e];
1125
- }
1126
- }, F = /* @__PURE__ */ new WeakMap();
1127
- function ht(e) {
1128
- return (e.dataset.formieSubmitAction || "").trim();
1129
- }
1130
- function gt(e) {
1131
- return (e.dataset.formieErrorMessagePosition || "top-form").trim() || "top-form";
1132
- }
1133
- function _t(e) {
1134
- return (e.dataset.formieSubmitActionMessagePosition || "").trim();
1135
- }
1136
- function vt(e) {
1137
- let t = (e.dataset.formieSubmitActionMessageTimeout || "").trim();
1138
- if (!t) return null;
1139
- let n = Number.parseFloat(t);
1140
- return !Number.isFinite(n) || n < 0 ? null : Math.round(n * 1e3);
1141
- }
1142
- function yt(e) {
1143
- let t = e.dataset.formieSubmitActionFormHide;
1144
- if (t === void 0) return !1;
1145
- let n = t.trim().toLowerCase();
1146
- return n === "true" || n === "1" || n === "";
1147
- }
1148
- function bt(e) {
1149
- let t = F.get(e);
1150
- typeof t == "number" && (window.clearTimeout(t), F.delete(e));
1151
- }
1152
- function xt(e) {
1153
- return e.querySelector("[data-formie-form-messages-top]") || e;
1154
- }
1155
- function St(e) {
1156
- return e.querySelector("[data-formie-form-messages-bottom]") || e;
1157
- }
1158
- function Ct(e, t) {
1159
- return t === "bottom-form" ? St(e) : xt(e);
1160
- }
1161
- function wt(e, t) {
1162
- return t === "top-form" ? xt(e) : t === "bottom-form" && !yt(e) ? St(e) : e;
1163
- }
1164
- function Tt(e) {
1165
- let t = gt(e), n = Ct(e, t), r = n.querySelector("[data-formie-error-container], [data-formie-errors]");
1166
- return r || (r = document.createElement("div"), r.setAttribute("data-formie-errors", "true"), w(r, e, "errors")), r.setAttribute("data-formie-error-container", "true"), t === "bottom-form" ? n.append(r) : n.prepend(r), r;
1167
- }
1168
- function Et(e, t) {
1169
- let n = t.querySelector("[data-formie-error-message-container], [data-formie-message][data-formie-message-error]");
1170
- return n || (n = document.createElement("div"), n.setAttribute("data-formie-error-message-container", "true"), t.appendChild(n)), n.setAttribute("data-formie-message", "true"), n.setAttribute("data-formie-message-error", "true"), w(n, e, "message", "messageError"), n.setAttribute("role", "alert"), Oe(n, De(Te(e))), n;
1171
- }
1172
- function Dt(e, t) {
1173
- let n = e.querySelector("[data-formie-success-container]"), r = wt(e, t);
1174
- return n || (n = document.createElement("div"), n.setAttribute("data-formie-success-container", "true"), w(n, e, "successes")), t === "bottom-form" ? r.append(n) : r.prepend(n), n;
1175
- }
1176
- function Ot(e) {
1177
- return it(e, (t) => {
1178
- w(t, e, "fieldErrors");
1179
- });
1180
- }
1181
- function kt(e, t) {
1182
- let n = (e.getAttribute("aria-describedby") || "").trim();
1183
- if (!n) return;
1184
- let r = n.split(/\s+/).filter((e) => e !== t).join(" ").trim();
1185
- if (r) {
1186
- e.setAttribute("aria-describedby", r);
1187
- return;
1188
- }
1189
- e.removeAttribute("aria-describedby");
1190
- }
1191
- function At(e, t) {
1192
- e.setAttribute("aria-errormessage", t);
1193
- }
1194
- function jt(e, t) {
1195
- e.getAttribute("aria-errormessage") === t && e.removeAttribute("aria-errormessage");
1196
- }
1197
- function Mt(e) {
1198
- e.querySelectorAll("[data-formie-field-handle]").forEach((t) => {
1199
- let n = t, r = n.querySelector("[data-formie-field-errors]"), i = r?.id || "", a = Array.from(n.querySelectorAll("[data-formie-field-error]")).map((e) => e.id).filter(Boolean);
1200
- C(n, e, "fieldLayoutError"), n.removeAttribute("data-formie-field-has-error"), n.querySelectorAll("[data-formie-field-error]").forEach((e) => {
1201
- e.remove();
1202
- }), r && !r.querySelector("[data-formie-field-error]") && (r.innerHTML = ""), n.querySelectorAll("input, select, textarea").forEach((t) => {
1203
- let n = t;
1204
- n.removeAttribute("aria-invalid"), C(n, e, "fieldControlError"), n.removeAttribute("data-formie-input-has-error"), i && kt(n, i), a.forEach((e) => {
1205
- jt(n, e);
1206
- });
1207
- });
1208
- }), y(e);
1209
- }
1210
- function Nt(e) {
1211
- e.querySelectorAll("[data-formie-error-container], [data-formie-errors]").forEach((t) => {
1212
- let n = t;
1213
- n.querySelectorAll("[data-formie-error]").forEach((e) => {
1214
- e.remove();
1215
- }), C(n, e, "message", "messageError"), n.removeAttribute("data-formie-message"), n.removeAttribute("data-formie-message-error"), n.removeAttribute("role"), n.removeAttribute("aria-live"), n.removeAttribute("aria-atomic"), n.querySelector("[data-formie-error]") || (n.innerHTML = "");
1216
- });
1217
- }
1218
- function Pt(e) {
1219
- bt(e), e.querySelectorAll("[data-formie-message-success]:not([data-formie-success-container])").forEach((e) => {
1220
- e.remove();
1221
- }), e.querySelectorAll("[data-formie-success-container]").forEach((t) => {
1222
- let n = t;
1223
- n.querySelectorAll("[data-formie-success]").forEach((e) => {
1224
- e.remove();
1225
- }), C(n, e, "message", "messageSuccess"), n.removeAttribute("data-formie-message"), n.removeAttribute("data-formie-message-success"), n.removeAttribute("role"), n.removeAttribute("aria-live"), n.removeAttribute("aria-atomic"), n.querySelector("[data-formie-success]") || (n.innerHTML = "");
1226
- }), ht(e) === "message" && yt(e) || s(e, !1);
1227
- }
1228
- function Ft(e) {
1229
- e.querySelectorAll("[aria-invalid=\"true\"]").forEach((e) => {
1230
- e.removeAttribute("aria-invalid");
1231
- });
1232
- }
1233
- function It(e, t) {
1234
- let n = (e.getAttribute("aria-describedby") || "").trim(), r = n ? n.split(/\s+/) : [];
1235
- r.includes(t) || r.push(t), e.setAttribute("aria-describedby", r.join(" ").trim());
1236
- }
1237
- function Lt(e, t) {
1238
- let n = De(Te(e));
1239
- Object.entries(t).forEach(([t, r]) => {
1240
- let i = e.querySelector(`[data-formie-field-handle="${t}"]`);
1241
- if (!i) return;
1242
- let a = Ot(i), o = a.id && a.id.trim() ? a.id : `${t}-errors`;
1243
- a.id = o, Oe(a, n), w(i, e, "fieldLayoutError"), i.setAttribute("data-formie-field-has-error", "true"), r.forEach((t, n) => {
1244
- let r = document.createElement("div");
1245
- r.setAttribute("data-formie-field-error", "true"), r.setAttribute("role", "alert"), r.id = `${o}-${n + 1}`, w(r, e, "fieldError"), r.textContent = t, a.appendChild(r);
1246
- });
1247
- let s = a.querySelector("[data-formie-field-error]")?.id;
1248
- i.querySelectorAll("input, select, textarea").forEach((t) => {
1249
- let n = t;
1250
- n.setAttribute("aria-invalid", "true"), w(n, e, "fieldControlError"), n.setAttribute("data-formie-input-has-error", "true"), It(n, o), s && At(n, s);
1251
- let r = i.querySelector("[data-formie-instructions]");
1252
- r?.id && It(n, r.id);
1253
- });
1254
- }), y(e);
1255
- }
1256
- function Rt(e, t) {
1257
- let n = Tt(e), r = Et(e, n);
1258
- w(n, e, "errors"), t.forEach((t) => {
1259
- let n = document.createElement("div");
1260
- n.setAttribute("data-formie-error", "true"), n.setAttribute("role", "alert"), w(n, e, "error"), n.innerHTML = t, r.appendChild(n);
1261
- });
1262
- }
1263
- function zt(e) {
1264
- if (e.ok || e.keepSubmitLoading !== !0) return !1;
1265
- let t = e.meta || {}, n = String(t.paymentStatus || "");
1266
- return n === "actionRequired" || n === "pending";
1267
- }
1268
- function Bt(e, t) {
1269
- let n = Tt(e), r = Et(e, n);
1270
- w(n, e, "errors");
1271
- let i = document.createElement("div");
1272
- i.setAttribute("data-formie-notice", "true"), i.setAttribute("role", "status"), w(i, e, "message"), i.textContent = t, r.appendChild(i);
1273
- }
1274
- function Vt(e, t) {
1275
- return !t.message || t.nextPage || t.redirect ? !1 : t.action === "save" ? !0 : ht(e) === "message" && _t(e) !== "";
1276
- }
1277
- function Ht(e, t) {
1278
- let n = _t(e);
1279
- if (!n) return;
1280
- let r = Dt(e, n);
1281
- w(r, e, "message", "messageSuccess"), r.setAttribute("data-formie-message", "true"), r.setAttribute("data-formie-message-success", "true"), r.setAttribute("role", "status"), r.setAttribute("aria-live", "polite"), r.setAttribute("aria-atomic", "true");
1282
- let i = document.createElement("div");
1283
- i.setAttribute("data-formie-success", "true"), w(i, e, "success"), i.innerHTML = t, r.appendChild(i), yt(e) && s(e, !0);
1284
- let a = vt(e);
1285
- if (a !== null) {
1286
- let t = window.setTimeout(() => {
1287
- F.delete(e), Pt(e);
1288
- }, a);
1289
- F.set(e, t);
1290
- }
1291
- }
1292
- function I(e, t) {
1293
- if (Mt(e), Nt(e), Pt(e), Ft(e), t.ok) {
1294
- Vt(e, t) && Ht(e, t.message || "");
1295
- return;
1296
- }
1297
- if (!t.ok) {
1298
- if (zt(t)) {
1299
- let n = t.meta || {}, r = String(n.paymentMessage || "").trim();
1300
- r && Bt(e, r);
1301
- return;
1302
- }
1303
- t.fieldErrors && Lt(e, t.fieldErrors), t.formErrors?.length ? Rt(e, t.formErrors) : !t.fieldErrors && t.message && Rt(e, [t.message]), Fe(e);
1304
- }
1305
- }
1306
- //#endregion
1307
- //#region src/js/core/submit-flow.ts
1308
- var Ut = S("general", "submit-flow");
1309
- function Wt(e) {
1310
- return !(!e.ok && e.stage === "validate");
1311
- }
1312
- function Gt(e) {
1313
- return e ? !!(e.keepSubmitLoading === !0 || e.ok && e.redirect?.url && e.redirect.target !== "new-tab") : !1;
1314
- }
1315
- function Kt(e) {
1316
- Mt(e), Nt(e), Pt(e), Ft(e);
1317
- }
1318
- async function qt(e) {
1319
- let { id: t, target: n, form: r, bus: i, validator: a, validateOnSubmit: o, action: s, submitter: c, waitForSubmitDelay: l, onRefreshTokensAfterSubmit: u, dispatchSubmitResult: f } = e;
1320
- Kt(r), m(r, c || null);
1321
- let p = {
1322
- ok: !1,
1323
- code: "SUBMIT_ERROR",
1324
- message: "Submission failed.",
1325
- formErrors: ["Submission failed."]
1326
- };
1327
- try {
1328
- await l(r), p = await nt(r, s, i, {
1329
- validator: a,
1330
- validateOnSubmit: o
1331
- }), I(r, p), f(p), g(r, p, s), Wt(p) && await u(p);
1332
- } catch (e) {
1333
- p = {
1334
- ok: !1,
1335
- code: "SUBMIT_ERROR",
1336
- message: e instanceof Error ? e.message : "Submission failed.",
1337
- formErrors: [e instanceof Error ? e.message : "Submission failed."]
1338
- }, I(r, p), f(p), Ut.warn("Submit failed with exception.", {
1339
- id: t,
1340
- action: s,
1341
- target: n,
1342
- error: e instanceof Error ? e.message : e
1343
- });
1344
- } finally {
1345
- Gt(p) || d(r);
1346
- }
1347
- return p;
1348
- }
1349
- //#endregion
1350
- //#region src/js/modules/registry.ts
1351
- var L = class {
1352
- constructor() {
1353
- this.modules = /* @__PURE__ */ new Map();
1714
+ return {
1715
+ t: ce,
1716
+ input: e,
1717
+ label: n,
1718
+ field: t,
1719
+ form: this.form,
1720
+ config: this.config,
1721
+ rules: r,
1722
+ getRule: (e) => this.getRule(t, e)
1723
+ };
1354
1724
  }
1355
- register(e, t = {}) {
1356
- let n = this.modules.get(e.id);
1357
- return n === e ? !0 : n && !t.replace ? (console.warn(`[formie] Module "${e.id}" is already registered. Pass { replace: true } to override the existing definition.`), !1) : (this.modules.set(e.id, e), !0);
1725
+ getErrorMessage(e, t, n, r) {
1726
+ return (typeof n.errorMessage == "function" ? n.errorMessage(r) : n.errorMessage) ?? ce("{label} is invalid.", { label: r.label });
1358
1727
  }
1359
- unregister(e) {
1360
- this.modules.delete(e);
1728
+ getErrors() {
1729
+ return this.errors;
1361
1730
  }
1362
- get(e) {
1363
- return this.modules.get(e) || null;
1731
+ getFieldErrors(e = this.errors) {
1732
+ let t = {};
1733
+ return e.forEach((e) => {
1734
+ e.handle && !t[e.handle]?.length && (t[e.handle] = [e.message]);
1735
+ }), t;
1364
1736
  }
1365
- getAll() {
1366
- return Array.from(this.modules.values());
1737
+ getRule(e, t) {
1738
+ if (!e) return !1;
1739
+ let n = this.parseValidationRules(e.getAttribute("data-formie-validation"));
1740
+ return Object.prototype.hasOwnProperty.call(n, t) ? n[t] : !1;
1367
1741
  }
1368
- }, Jt = {
1369
- "address-finder": () => import("./chunks/address-finder-k7_BXaRe.js").then((e) => e.addressFinderModule),
1370
- "google-address": () => import("./chunks/google-address-BH3Zhi06.js").then((e) => e.googleAddressModule),
1371
- loqate: () => import("./chunks/loqate-CJPzBmSm.js").then((e) => e.loqateModule),
1372
- "place-kit": () => import("./chunks/place-kit-BGHklIZ-.js").then((e) => e.placeKitModule)
1373
- }, Yt = {
1374
- "captcha-eu": () => import("./chunks/captcha-eu-CGm8Lbrj.js").then((e) => e.captchaEuModule),
1375
- "friendly-captcha-v1": () => import("./chunks/friendly-captcha-v1-C_2reOXr.js").then((e) => e.friendlyCaptchaV1Module),
1376
- "friendly-captcha-v2": () => import("./chunks/friendly-captcha-v2-CLSAbkqx.js").then((e) => e.friendlyCaptchaV2Module),
1377
- hcaptcha: () => import("./chunks/hcaptcha-CGLAmgjO.js").then((e) => e.hcaptchaModule),
1378
- "recaptcha-enterprise": () => import("./chunks/recaptcha-enterprise-XPId5-bS.js").then((e) => e.recaptchaEnterpriseModule),
1379
- "recaptcha-v2-checkbox": () => import("./chunks/recaptcha-v2-checkbox-Cy-0PEPc.js").then((e) => e.recaptchaV2CheckboxModule),
1380
- "recaptcha-v2-invisible": () => import("./chunks/recaptcha-v2-invisible-BwRH540O.js").then((e) => e.recaptchaV2InvisibleModule),
1381
- "recaptcha-v3": () => import("./chunks/recaptcha-v3-No4Ykrhk.js").then((e) => e.recaptchaV3Module),
1382
- snaptcha: () => import("./chunks/snaptcha-DKx98oon.js").then((e) => e.snaptchaModule),
1383
- turnstile: () => import("./chunks/turnstile-DJakPzQD.js").then((e) => e.turnstileModule)
1384
- }, Xt = {
1385
- calculations: () => import("./chunks/calculations-Dv3hYb8_.js").then((e) => e.calculationsModule),
1386
- "checkbox-radio": () => import("./chunks/checkbox-radio-BY2aTCOG.js").then((e) => e.checkboxRadioModule),
1387
- combobox: () => import("./chunks/combobox-C0EuExSI.js").then((e) => e.comboboxModule),
1388
- conditions: () => import("./chunks/conditions-CPH1snCx.js").then((e) => e.conditionsModule),
1389
- "custom-google-maps": () => import("./chunks/custom-google-maps-BsaSirEZ.js").then((e) => e.customGoogleMapsModule),
1390
- "custom-link": () => import("./chunks/custom-link-CJ1-FjEM.js").then((e) => e.customLinkModule),
1391
- "custom-maps": () => import("./chunks/custom-maps-DYW_pBid.js").then((e) => e.customMapsModule),
1392
- "date-picker": () => import("./chunks/date-picker-F9BUBDSW.js").then((e) => e.datePickerModule),
1393
- "file-upload": () => import("./chunks/file-upload-rqfZNqlH.js").then((e) => e.fileUploadModule),
1394
- "upload-manager": () => import("./chunks/upload-manager-W-QDgxKD.js").then((e) => e.uploadManagerModule),
1395
- hidden: () => import("./chunks/hidden-D7_Ch-QN.js").then((e) => e.hiddenModule),
1396
- "phone-country": () => import("./chunks/phone-country-D3ayr60L.js").then((e) => e.phoneCountryModule),
1397
- "password-validation": () => import("./chunks/password-validation-D06uH9va.js").then((e) => e.passwordValidationModule),
1398
- "address-country": () => import("./chunks/address-country-Rx6GQTND.js").then((e) => e.addressCountryModule),
1399
- "address-state": () => import("./chunks/address-state-BwE01m2_.js").then((e) => e.addressStateModule),
1400
- repeater: () => import("./chunks/repeater-BVnPUqTj.js").then((e) => e.repeaterModule),
1401
- "rich-text": () => import("./chunks/rich-text-Bg_--4TG.js").then((e) => e.richTextModule),
1402
- signature: () => import("./chunks/signature-IOhuicje.js").then((e) => e.signatureModule),
1403
- summary: () => import("./chunks/summary-Dks0gXS3.js").then((e) => e.summaryModule),
1404
- "survey-likert": () => import("./chunks/survey-likert-DkE6bR7B.js").then((e) => e.surveyLikertModule),
1405
- "survey-rank": () => import("./chunks/survey-rank-DN6x4IZM.js").then((e) => e.surveyRankModule),
1406
- "survey-rating": () => import("./chunks/survey-rating-BnsNL9U5.js").then((e) => e.surveyRatingModule),
1407
- table: () => import("./chunks/table-CAjCJHrL.js").then((e) => e.tableModule),
1408
- "text-limit": () => import("./chunks/text-limit-BGaY0jhI.js").then((e) => e.textLimitModule)
1409
- }, Zt = {
1410
- bpoint: () => import("./chunks/bpoint-Dlq34XH1.js").then((e) => e.bpointModule),
1411
- eway: () => import("./chunks/eway-D9_m8ooj.js").then((e) => e.ewayModule),
1412
- "go-cardless": () => import("./chunks/go-cardless-DAT3ZaQf.js").then((e) => e.goCardlessModule),
1413
- mollie: () => import("./chunks/mollie-Bibhl67p.js").then((e) => e.mollieModule),
1414
- moneris: () => import("./chunks/moneris-H2wSqk9h.js").then((e) => e.monerisModule),
1415
- opayo: () => import("./chunks/opayo-CR0DtsLa.js").then((e) => e.opayoModule),
1416
- paddle: () => import("./chunks/paddle-DkvIxQdG.js").then((e) => e.paddleModule),
1417
- paypal: () => import("./chunks/paypal-CQpAF7Ua.js").then((e) => e.paypalModule),
1418
- payway: () => import("./chunks/payway-CwDkC7YZ.js").then((e) => e.paywayModule),
1419
- square: () => import("./chunks/square-DwdcOI1G.js").then((e) => e.squareModule),
1420
- stripe: () => import("./chunks/stripe-DaoG2FT1.js").then((e) => e.stripeModule)
1421
- }, Qt = {
1422
- ...Xt,
1423
- ...Jt,
1424
- ...Yt,
1425
- ...Zt
1426
- }, R = /* @__PURE__ */ new Map(), z = S("general", "loader"), $t = Function("src", "return import(src);");
1427
- async function B(t, n, i, a) {
1428
- await t(r(i), a), await t(e(n, i), a);
1429
- }
1430
- function en(e) {
1431
- return !!e && typeof e == "object" && typeof e.id == "string" && typeof e.setup == "function" && typeof e.match == "function";
1432
- }
1433
- async function tn(e, t) {
1434
- let n = Qt[e];
1435
- return n ? (R.has(e) || R.set(e, (async () => {
1742
+ parseValidationRules(e) {
1743
+ let t = {};
1744
+ if (!e) return t;
1745
+ let n = null;
1436
1746
  try {
1437
- let e = await n();
1438
- return en(e) ? (t.registry.register(e), e) : null;
1439
- } catch (t) {
1440
- return console.error("[formie] Failed to load builtin module:", e, t), z.warn("Failed loading builtin module.", {
1441
- moduleId: e,
1442
- error: t
1443
- }), null;
1747
+ n = JSON.parse(e);
1748
+ } catch {
1749
+ return H.warn("Invalid validation rules payload.", { formId: this.form.id || null }), t;
1444
1750
  }
1445
- })()), R.get(e) || null) : null;
1446
- }
1447
- async function nn(e) {
1448
- try {
1449
- let t = await $t(e), n = t?.default || t?.formieModule || null;
1450
- return en(n) ? n : null;
1451
- } catch (t) {
1452
- return console.error("[formie] Failed to load module from src:", e, t), z.warn("Failed loading module from src.", {
1453
- src: e,
1454
- error: t
1455
- }), null;
1751
+ return Array.isArray(n) && n.forEach((e) => {
1752
+ if (!e || typeof e != "object" || Array.isArray(e)) return;
1753
+ let n = e, r = typeof n.type == "string" ? n.type.trim() : "";
1754
+ r && (t[r] = n);
1755
+ }), t;
1456
1756
  }
1457
- }
1458
- async function rn(e, t) {
1459
- let n = t.registry.get(e.id);
1460
- if (n) return n;
1461
- let r = await tn(e.id, t);
1462
- if (r) return r;
1463
- if (e.src) {
1464
- let n = await nn(e.src);
1465
- if (n) return t.registry.register(n), n;
1466
- }
1467
- return null;
1468
- }
1469
- function V(e) {
1470
- return typeof window.CSS?.escape == "function" ? window.CSS.escape(e) : e.replace(/["\\]/g, "\\$&");
1471
- }
1472
- function H(e, t) {
1473
- return e.matches(t) ? [e, ...Array.from(e.querySelectorAll(t))] : Array.from(e.querySelectorAll(t));
1474
- }
1475
- function an(e, t) {
1476
- let n = t.setupContext.root, r = t.setupContext.form, i = e.targetType, a = e.targetId;
1477
- return i === "selector" ? H(n, a).map((e) => ({
1478
- scope: i,
1479
- element: e
1480
- })) : i === "field" ? H(n, `[data-formie-field-handle="${V(a)}"]`).map((e) => ({
1481
- scope: i,
1482
- element: e
1483
- })) : i === "page" ? H(n, `[data-formie-page-id="${V(a)}"]`).map((e) => ({
1484
- scope: i,
1485
- element: e
1486
- })) : i === "button" ? H(n, `[data-formie-action="${V(a)}"]`).map((e) => ({
1487
- scope: i,
1488
- element: e
1489
- })) : [{
1490
- scope: "form",
1491
- element: r || n
1492
- }];
1493
- }
1494
- function on(e, t) {
1495
- return (e.targets && e.targets.length > 0 ? e.targets : [{
1496
- targetType: "form",
1497
- targetId: "form"
1498
- }]).flatMap((e) => an(e, t));
1499
- }
1500
- async function sn(e, t) {
1501
- let n = [];
1502
- z.log("Loading module manifest.", { manifestCount: e.length });
1503
- for (let r of e) {
1504
- let e = await rn(r, t);
1505
- if (!e) {
1506
- z.warn("Skipping manifest item (definition not resolved).", {
1507
- moduleId: r.id,
1508
- src: r.src
1509
- });
1510
- continue;
1757
+ destroy() {
1758
+ H.log("Destroying validator.", { formId: this.form.id || null }), this.removeEventListeners(), this.form.removeAttribute("novalidate"), this.emitEvent(document, o("destroy"), { validator: this });
1759
+ }
1760
+ isVisible(e, t = {}) {
1761
+ if (e.disabled || e.hasAttribute("data-formie-conditions-disabled") || e.closest("[data-formie-conditions-disabled]") || e.closest("[data-formie-conditionally-hidden]")) return !1;
1762
+ if (e.closest("[data-formie-page-hidden]")) return !!t.includeHiddenPages;
1763
+ let n = e.closest("[data-formie-field-handle]")?.querySelector("[data-formie-rich-text]");
1764
+ if (n instanceof HTMLElement) return fn(n);
1765
+ if (e instanceof HTMLSelectElement && e.hasAttribute("data-formie-combobox-input")) {
1766
+ let t = e.nextElementSibling;
1767
+ if (t instanceof HTMLElement && t.classList.contains("formie-combobox")) return fn(t);
1511
1768
  }
1512
- let i = on(r, t);
1513
- z.log("Resolved module targets.", {
1514
- moduleId: e.id,
1515
- targets: r.targets || [],
1516
- targetCount: i.length
1517
- }), i.length === 0 && e.kind === "address" && console.warn(`[formie] Address module "${r.id}" skipped: no target element found for fieldHandle="${r.targets?.find((e) => e.targetType === "field")?.targetId ?? "?"}". Check that the Address field exists in the rendered form.`);
1518
- for (let a of i) {
1519
- let i = {
1520
- ...t.matchContext,
1521
- target: a.element,
1522
- scope: a.scope,
1523
- manifestItem: r
1524
- };
1525
- if (!e.match(i)) {
1526
- e.kind === "address" && console.warn(`[formie] Address module "${e.id}" skipped: target element does not contain [data-formie-address-autocomplete-input]. Enable the Auto-Complete subfield.`), z.log("Module target did not match predicate.", {
1527
- moduleId: e.id,
1528
- scope: a.scope
1529
- });
1530
- continue;
1531
- }
1532
- let o = r.config || t.setupContext.options, s = e.id, c = {
1533
- moduleId: e.id,
1534
- moduleKind: e.kind,
1535
- target: a.element,
1536
- scope: a.scope,
1537
- options: o,
1538
- manifestItem: r
1539
- };
1540
- await B(t.setupContext.emit, s, "before-setup", c);
1541
- let l = null;
1542
- try {
1543
- let n = await e.setup({
1544
- ...t.setupContext,
1545
- target: a.element,
1546
- scope: a.scope,
1547
- options: o
1548
- });
1549
- n && (l = n);
1550
- } catch (t) {
1551
- console.error(`[formie] Module "${e.id}" setup failed:`, t), z.warn("Module setup failed.", {
1552
- moduleId: e.id,
1553
- scope: a.scope,
1554
- error: t
1555
- });
1769
+ return fn(e);
1770
+ }
1771
+ blurHandler(e) {
1772
+ e.target instanceof HTMLElement && U(e.target) && !k(e.target) && e.target.form?.isSameNode(this.form) && (e instanceof CustomEvent || e.target instanceof HTMLInputElement && e.target.type === "file" || e.target instanceof HTMLInputElement && (e.target.type === "checkbox" || e.target.type === "radio") || (this.isDirty(e.target) && this.activated.add(e.target), this.shouldShowError(e.target) && this.validate(e.target)));
1773
+ }
1774
+ changeHandler(e) {
1775
+ if (e.target instanceof HTMLElement && U(e.target) && !k(e.target) && e.target.form?.isSameNode(this.form) && !(e instanceof CustomEvent)) {
1776
+ if (e.target instanceof HTMLSelectElement) {
1777
+ this.activated.add(e.target), this.validate(e.target);
1778
+ return;
1556
1779
  }
1557
- await B(t.setupContext.emit, s, "after-setup", {
1558
- ...c,
1559
- instanceCreated: !!l
1560
- }), l && (z.log("Module instance created.", {
1561
- moduleId: e.id,
1562
- scope: a.scope
1563
- }), n.push({
1564
- ...l,
1565
- destroy: async () => {
1566
- z.log("Destroying module instance.", {
1567
- moduleId: e.id,
1568
- scope: a.scope
1569
- }), await B(t.setupContext.emit, s, "before-destroy", c), await l.destroy(), await B(t.setupContext.emit, s, "after-destroy", c), z.log("Module instance destroyed.", {
1570
- moduleId: e.id,
1571
- scope: a.scope
1572
- });
1573
- }
1574
- }));
1780
+ e.target instanceof HTMLInputElement && (e.target.type === "file" || e.target.type === "checkbox" || e.target.type === "radio") && (this.activated.add(e.target), this.validate(e.target));
1575
1781
  }
1576
1782
  }
1577
- return z.log("Module manifest processing complete.", { instanceCount: n.length }), n;
1578
- }
1579
- //#endregion
1580
- //#region src/js/utils/form-started-at.ts
1581
- var cn = "formie:formStartedAt:";
1582
- function ln(e) {
1583
- let t = e.querySelector("input[name=\"formStartedAt\"]");
1584
- if (!t) return;
1585
- let n = e.querySelector("input[name=\"renderId\"]")?.value?.trim() ?? "", r = n ? `${cn}${n}` : null, i = r ? sessionStorage.getItem(r) : null;
1586
- i || (i = String(Date.now()), r && sessionStorage.setItem(r, i)), t.value = i;
1587
- }
1588
- //#endregion
1589
- //#region src/js/utils/unload-warning.ts
1590
- var un = new Set([
1591
- "CRAFT_CSRF_TOKEN",
1592
- "action",
1593
- "redirect",
1594
- "requestToken",
1595
- "renderId",
1596
- "formStartedAt",
1597
- "submitAction",
1598
- "pageId",
1599
- "draftContextToken",
1600
- "draftContext",
1601
- "continuationToken"
1602
- ]);
1603
- function dn(e, t) {
1604
- if (e == null) return String(e);
1605
- if (typeof e == "string") return JSON.stringify(e);
1606
- if (typeof e == "number" || typeof e == "boolean") return String(e);
1607
- if (typeof e == "function") return "[function]";
1608
- if (typeof File < "u" && e instanceof File) return `[file:${e.name}:${e.size}:${e.type}]`;
1609
- if (typeof Blob < "u" && e instanceof Blob) return `[blob:${e.size}:${e.type}]`;
1610
- if (Array.isArray(e)) return `[${e.map((e) => dn(e, t)).join(",")}]`;
1611
- if (typeof e == "object") {
1612
- if (t.has(e)) return "[circular]";
1613
- t.add(e);
1614
- let n = Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).map(([e, n]) => `${JSON.stringify(e)}:${dn(n, t)}`);
1615
- return t.delete(e), `{${n.join(",")}}`;
1783
+ inputHandler(e) {
1784
+ e.target instanceof HTMLElement && U(e.target) && !k(e.target) && e.target.form?.isSameNode(this.form) && (e instanceof CustomEvent || e.target instanceof HTMLInputElement && (e.target.type === "checkbox" || e.target.type === "radio") || this.shouldShowError(e.target) && this.validate(e.target));
1616
1785
  }
1617
- return JSON.stringify(String(e));
1618
- }
1619
- function fn(e) {
1620
- return dn(e, /* @__PURE__ */ new WeakSet());
1621
- }
1622
- function pn(e) {
1623
- if (!e) return !1;
1624
- let t = e.endsWith("[]") ? e.slice(0, -2) : e;
1625
- return !un.has(t);
1626
- }
1627
- function mn(e) {
1628
- return fn(Array.from(new FormData(e).entries()).filter(([e]) => pn(String(e || ""))));
1629
- }
1630
- function hn(e, t = {}) {
1631
- let n = null, r = !1, i = !1, a = null, o = null, s = null, c = () => {
1632
- a !== null && (window.cancelAnimationFrame(a), a = null), o !== null && (window.clearTimeout(o), o = null), s !== null && (window.clearTimeout(s), s = null);
1633
- }, l = () => r ? (i = mn(e) !== n, i) : !1, u = () => {
1634
- n = mn(e), r = !0, i = !1;
1635
- }, d = () => {
1636
- c(), r = !1, a = window.requestAnimationFrame(() => {
1637
- a = null, s = window.setTimeout(() => {
1638
- s = null, u();
1639
- }, 0);
1640
- });
1641
- }, f = () => {
1642
- o !== null && window.clearTimeout(o), o = window.setTimeout(() => {
1643
- o = null, l();
1644
- }, 120);
1645
- }, p = (e) => {
1646
- t.shouldWarn && !t.shouldWarn() || l() && (e.preventDefault(), e.returnValue = "");
1647
- };
1648
- return e.addEventListener("input", f), e.addEventListener("change", f), window.addEventListener("beforeunload", p), d(), {
1649
- captureBaseline: u,
1650
- scheduleBaselineCapture: d,
1651
- refreshDirtyState: l,
1652
- destroy: () => {
1653
- c(), e.removeEventListener("input", f), e.removeEventListener("change", f), window.removeEventListener("beforeunload", p);
1654
- }
1655
- };
1656
- }
1786
+ submit(e = null, { final: t = !1 } = {}) {
1787
+ return this.submitted = !0, H.log("Submit validation requested.", { final: t }), this.boundListeners || this.addEventListeners(), this.removeAllErrors(), this.validate(e, { includeHiddenPages: t });
1788
+ }
1789
+ resetLiveState() {
1790
+ this.submitted = !1, this.activated = /* @__PURE__ */ new WeakSet(), this.errors = [], this.removeAllErrors();
1791
+ }
1792
+ addEventListeners() {
1793
+ 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, H.log("Event listeners attached."));
1794
+ }
1795
+ removeEventListeners() {
1796
+ this.form.removeEventListener("blur", this.onBlur, !0), this.form.removeEventListener("change", this.onChange, !1), this.form.removeEventListener("input", this.onInput, !1), this.boundListeners = !1, H.log("Event listeners removed.");
1797
+ }
1798
+ emitEvent(e, t, n = {}) {
1799
+ e.dispatchEvent(new CustomEvent(t, {
1800
+ bubbles: !0,
1801
+ detail: n
1802
+ }));
1803
+ }
1804
+ addValidator(e, t, n) {
1805
+ this.validators[e] = {
1806
+ validate: t,
1807
+ errorMessage: n
1808
+ };
1809
+ }
1810
+ removeValidator(e) {
1811
+ delete this.validators[e];
1812
+ }
1813
+ };
1657
1814
  //#endregion
1658
1815
  //#region src/js/validation/enter-key-guard.ts
1659
- function gn(e) {
1816
+ function mn(e) {
1660
1817
  return e.hasAttribute("data-formie-conditionally-hidden") || !!e.closest("[data-formie-conditionally-hidden]") || e.hasAttribute("data-formie-page-hidden") || !!e.closest("[data-formie-page-hidden]");
1661
1818
  }
1662
- function _n(e, t) {
1819
+ function hn(e, t) {
1663
1820
  let n = e.querySelectorAll(`[data-formie-action="${t}"]`);
1664
- return Array.from(n).some((e) => !gn(e));
1821
+ return Array.from(n).some((e) => !mn(e));
1665
1822
  }
1666
- function vn(e) {
1667
- let { final: t } = f(e);
1823
+ function gn(e) {
1824
+ let { final: t } = g(e);
1668
1825
  return "submit";
1669
1826
  }
1670
- function yn(e) {
1671
- return !_n(e, vn(e));
1827
+ function _n(e) {
1828
+ return !hn(e, gn(e));
1672
1829
  }
1673
- function bn(e) {
1830
+ function vn(e) {
1674
1831
  let t = (t) => {
1675
1832
  if (t.key !== "Enter" || t.defaultPrevented) return;
1676
1833
  let n = t.target;
1677
- (n instanceof HTMLInputElement || n instanceof HTMLSelectElement) && (n instanceof HTMLInputElement && (n.type === "button" || n.type === "submit" || n.type === "reset" || n.type === "file") || yn(e) && t.preventDefault());
1834
+ (n instanceof HTMLInputElement || n instanceof HTMLSelectElement) && (n instanceof HTMLInputElement && (n.type === "button" || n.type === "submit" || n.type === "reset" || n.type === "file") || _n(e) && t.preventDefault());
1678
1835
  };
1679
1836
  return e.addEventListener("keydown", t, !0), () => {
1680
1837
  e.removeEventListener("keydown", t, !0);
@@ -1682,40 +1839,42 @@ function bn(e) {
1682
1839
  }
1683
1840
  //#endregion
1684
1841
  //#region src/js/core/create-formie-client.ts
1685
- var U = "[data-formie]:not([data-formie-init=\"false\"]), [data-formie-form]:not([data-formie-init=\"false\"])", xn = 300, Sn = "/actions/formie/server/forms/render", Cn = "/api", wn = "/actions/formie/server/forms/refresh-tokens", Tn = "/actions/formie/server/submissions/submit", En = "/actions/formie/server/submissions/set-page", Dn = "/actions/formie/server/submissions/clear-submission", On = "/actions/formie/file-upload/hydrate", W = S("general", "client"), kn = /* @__PURE__ */ new Set();
1686
- function G(e, t) {
1842
+ var W = "[data-formie]:not([data-formie-init=\"false\"]), [data-formie-form]:not([data-formie-init=\"false\"])", yn = 300, bn = "/actions/formie/server/forms/render", xn = "/api", Sn = "/actions/formie/server/forms/refresh-tokens", Cn = "/actions/formie/server/submissions/submit", wn = "/actions/formie/server/submissions/set-page", Tn = "/actions/formie/server/submissions/clear-submission", En = "/actions/formie/file-upload/hydrate", G = E("general", "client"), Dn = /* @__PURE__ */ new Set();
1843
+ function K(e, t) {
1687
1844
  if (e == null || e === "") return t;
1688
1845
  let n = e.toLowerCase();
1689
- return !(n === "false" || n === "0" || n === "off");
1846
+ return n !== "false" && n !== "0" && n !== "off";
1690
1847
  }
1691
- function An(e) {
1692
- return e.formieRefreshTokens != null && e.formieRefreshTokens !== "" ? G(e.formieRefreshTokens, !1) : e.formieStaticCache != null && e.formieStaticCache !== "" ? G(e.formieStaticCache, !1) : !1;
1848
+ function On(e) {
1849
+ return e.formieRefreshTokens == null ? e.formieStaticCache != null && K(e.formieStaticCache, !0) : K(e.formieRefreshTokens, !0);
1693
1850
  }
1694
- function K(e) {
1851
+ function q(e) {
1695
1852
  let t = e instanceof HTMLElement ? e.dataset : {};
1696
1853
  return {
1697
1854
  mode: "server-rendered",
1698
1855
  transport: t.formieTransport || "rest",
1856
+ profile: t.formieRequestProfile,
1699
1857
  formHandle: t.formieHandle,
1700
1858
  endpoint: t.formieEndpoint,
1701
- staticCache: An(t),
1702
- autoVisible: G(t.formieAutoVisible, !0),
1703
- compatibility: G(t.formieCompatibility, !1)
1859
+ staticCache: On(t),
1860
+ autoVisible: K(t.formieAutoVisible, !0),
1861
+ compatibility: K(t.formieCompatibility, !1)
1704
1862
  };
1705
1863
  }
1706
- function q(e) {
1707
- return e || "server-rendered";
1864
+ function kn(e) {
1865
+ if (e && e !== "server-rendered") throw Error("@verbb/formie-browser enhances server-rendered HTML only. Use @verbb/formie-core for client-rendered forms.");
1866
+ return "server-rendered";
1708
1867
  }
1709
- function J(e) {
1868
+ function An(e) {
1710
1869
  return e || "rest";
1711
1870
  }
1712
- function Y(e) {
1871
+ function jn(e) {
1713
1872
  return e instanceof HTMLFormElement ? e : e.querySelector("form");
1714
1873
  }
1715
- function jn(e, t) {
1716
- kn.has(e) || (kn.add(e), W.warn(t));
1717
- }
1718
1874
  function Mn(e, t) {
1875
+ Dn.has(e) || (Dn.add(e), G.warn(t));
1876
+ }
1877
+ function Nn(e, t) {
1719
1878
  if (!e) return e;
1720
1879
  try {
1721
1880
  return new URL(e).toString();
@@ -1727,21 +1886,21 @@ function Mn(e, t) {
1727
1886
  return e;
1728
1887
  }
1729
1888
  }
1730
- function X(e, t) {
1889
+ function J(e, t) {
1731
1890
  let n = (e || "").trim();
1732
- return n ? n.includes("/actions/") ? n : Mn(t, n) : t;
1733
- }
1734
- function Nn(e, t) {
1735
- return X(e.endpoint || t.dataset.formieEndpoint, Sn);
1891
+ return n ? n.includes(t) ? n : Nn(t, n) : t;
1736
1892
  }
1737
1893
  function Pn(e, t) {
1738
- let n = (e.endpoint || t.dataset.formieEndpoint || "").trim();
1739
- return n ? n.includes("/graphql") || n.endsWith("/api") || n.includes("/actions/graphql/") ? n : Mn(Cn, n) : Cn;
1894
+ return J(e.endpoint || t.dataset.formieEndpoint, bn);
1740
1895
  }
1741
1896
  function Fn(e, t) {
1742
- return X(t.dataset.formieRefreshTokensEndpoint || e.endpoint || t.dataset.formieEndpoint, wn);
1897
+ let n = (e.endpoint || t.dataset.formieEndpoint || "").trim();
1898
+ return n ? n.includes("/graphql") || n.endsWith("/api") || n.includes("/actions/graphql/") ? n : Nn(xn, n) : xn;
1743
1899
  }
1744
1900
  function In(e, t) {
1901
+ return J(t.dataset.formieRefreshTokensEndpoint || e.endpoint || t.dataset.formieEndpoint, Sn);
1902
+ }
1903
+ function Ln(e, t) {
1745
1904
  if (!e) return t;
1746
1905
  try {
1747
1906
  let n = new URL(e, window.location.origin), r = new URL(t, window.location.origin);
@@ -1752,28 +1911,25 @@ function In(e, t) {
1752
1911
  return t;
1753
1912
  }
1754
1913
  }
1755
- function Ln(e, t, n) {
1756
- let r = n.endpoint || e.dataset.formieEndpoint, i = X(r, Tn), a = t.getAttribute("action");
1757
- t.setAttribute("action", In(a, i)), t.querySelectorAll("[data-formie-tab-link]").forEach((e) => {
1758
- let t = e.getAttribute("href"), n = X(r, En);
1759
- e.setAttribute("href", In(t, n));
1914
+ function Rn(e, t, n) {
1915
+ let r = n.endpoint || e.dataset.formieEndpoint, i = J(r, Cn), a = t.getAttribute("action");
1916
+ t.setAttribute("action", Ln(a, i)), t.querySelectorAll("[data-formie-tab-link]").forEach((e) => {
1917
+ let t = e.getAttribute("href"), n = J(r, wn);
1918
+ e.setAttribute("href", Ln(t, n));
1760
1919
  }), t.querySelectorAll("[data-formie-file-upload-hydrate-endpoint]").forEach((e) => {
1761
- e.setAttribute("data-formie-file-upload-hydrate-endpoint", X(r, On));
1920
+ e.setAttribute("data-formie-file-upload-hydrate-endpoint", J(r, En));
1762
1921
  });
1763
1922
  }
1764
- function Rn(e, t) {
1765
- if (e === "graphql" && t !== "server-rendered") throw Error(`Formie ${t} mode does not support GraphQL transport yet.`);
1766
- }
1767
1923
  function zn(e) {
1768
1924
  if (e == null) return !1;
1769
1925
  let t = e.trim().toLowerCase();
1770
1926
  return t === "true" || t === "1" || t === "";
1771
1927
  }
1772
1928
  function Bn(e) {
1773
- return G(e.dataset.formieAutomaticSubmissionState, !0);
1929
+ return K(e.dataset.formieAutomaticSubmissionState, !0);
1774
1930
  }
1775
1931
  function Vn(e, t, n) {
1776
- return X(n.dataset.formieClearSubmissionEndpoint || e.endpoint || t.dataset.formieEndpoint, Dn);
1932
+ return J(n.dataset.formieClearSubmissionEndpoint || e.endpoint || t.dataset.formieEndpoint, Tn);
1777
1933
  }
1778
1934
  function Hn(e) {
1779
1935
  return zn(e.dataset.formieUnloadWarning);
@@ -1781,13 +1937,13 @@ function Hn(e) {
1781
1937
  function Un(e, t) {
1782
1938
  e.setAttribute("data-formie-internal-navigation", t);
1783
1939
  }
1784
- function Wn(e) {
1940
+ function Y(e) {
1785
1941
  e.removeAttribute("data-formie-internal-navigation");
1786
1942
  }
1787
- function Gn(e) {
1943
+ function Wn(e) {
1788
1944
  return e.getAttribute("data-formie-internal-navigation") !== null;
1789
1945
  }
1790
- function Kn(e, t) {
1946
+ function Gn(e, t) {
1791
1947
  if (!e) return !1;
1792
1948
  try {
1793
1949
  return new URL(e, window.location.origin).searchParams.has(t);
@@ -1795,65 +1951,66 @@ function Kn(e, t) {
1795
1951
  return !1;
1796
1952
  }
1797
1953
  }
1798
- function qn(e) {
1799
- return Kn(window.location.href, "resumeToken") || Kn(e.getAttribute("action"), "resumeToken");
1954
+ function Kn(e) {
1955
+ return Gn(window.location.href, "resumeToken") || Gn(e.getAttribute("action"), "resumeToken");
1800
1956
  }
1801
- function Jn(e) {
1957
+ function qn(e) {
1802
1958
  return e instanceof MouseEvent ? e.button === 0 && !e.metaKey && !e.ctrlKey && !e.shiftKey && !e.altKey : !0;
1803
1959
  }
1804
- function Yn(e, t = 0) {
1960
+ function Jn(e, t = 0) {
1805
1961
  if (!e) return t;
1806
1962
  let n = Number.parseInt(e, 10);
1807
1963
  return Number.isFinite(n) ? n : t;
1808
1964
  }
1809
- function Xn(e) {
1810
- return Math.max(0, Yn(e.dataset.formieSubmitDelay, xn));
1965
+ function Yn(e) {
1966
+ return Math.max(0, Jn(e.dataset.formieSubmitDelay, yn));
1811
1967
  }
1812
- function Z(e) {
1968
+ function X(e) {
1813
1969
  return zn(e.dataset.formieValidationOnSubmit);
1814
1970
  }
1815
- async function Zn(e) {
1816
- let t = Xn(e);
1971
+ async function Xn(e) {
1972
+ let t = Yn(e);
1817
1973
  t < 1 || await new Promise((e) => {
1818
1974
  window.setTimeout(e, t);
1819
1975
  });
1820
1976
  }
1821
- function Qn(e, t) {
1977
+ function Zn(e, t) {
1822
1978
  let n = e?.getAttribute(t)?.trim();
1823
1979
  if (!n) return null;
1824
1980
  try {
1825
1981
  return JSON.parse(n);
1826
1982
  } catch (e) {
1983
+ if (t === "data-formie-modules") throw Error("Invalid browser-module manifest JSON. Update Formie and its browser packages together.");
1827
1984
  return console.error(`[formie] Failed to parse ${t}.`, e), null;
1828
1985
  }
1829
1986
  }
1830
- function $n(e, t) {
1987
+ function Qn(e, t) {
1831
1988
  let n = t || (e instanceof HTMLFormElement ? e : null);
1832
1989
  if (!n) return null;
1833
- let r = Qn(n, "data-formie-modules"), i = Qn(n, "data-formie-theme");
1990
+ let r = Zn(n, "data-formie-modules"), i = Zn(n, "data-formie-theme-classes") || Zn(n, "data-formie-theme");
1834
1991
  return !r && !i ? null : {
1835
1992
  modules: r || void 0,
1836
1993
  theme: i || void 0
1837
1994
  };
1838
1995
  }
1839
- function er(e) {
1996
+ function $n(e) {
1840
1997
  if (!(e instanceof HTMLElement)) return !0;
1841
1998
  if (!e.isConnected || e.hidden || e.closest("[hidden]")) return !1;
1842
1999
  let t = window.getComputedStyle(e);
1843
2000
  return t.display === "none" || t.visibility === "hidden" ? !1 : e.getClientRects().length > 0;
1844
2001
  }
1845
- function tr(e, t) {
2002
+ function er(e, t) {
1846
2003
  return t === document ? !0 : t instanceof Element ? t === e || t.contains(e) : !0;
1847
2004
  }
1848
- function Q(e) {
2005
+ function Z(e) {
1849
2006
  let t = e, n = t.id ? `#${t.id}` : "", r = t.dataset?.formieHandle ? `[handle="${t.dataset.formieHandle}"]` : "";
1850
2007
  return `${t.tagName ? t.tagName.toLowerCase() : "element"}${n}${r}`;
1851
2008
  }
1852
- function nr(e, t) {
2009
+ function tr(e, t) {
1853
2010
  if (t) {
1854
2011
  if (t.csrf?.param && t.csrf?.token) {
1855
2012
  let n = e.querySelector(`input[name="${t.csrf.param}"]`);
1856
- n ? n.value = t.csrf.token : (n = document.createElement("input"), n.type = "hidden", n.name = t.csrf.param, n.value = t.csrf.token, n.setAttribute("autocomplete", "off"), e.prepend(n));
2013
+ n ? n.value = t.csrf.token : (n = document.createElement("input"), n.type = "hidden", n.name = t.csrf.param, n.value = t.csrf.token, n.setAttribute("autocomplete", "off"), n.setAttribute("data-formie-csrf", ""), e.prepend(n));
1857
2014
  }
1858
2015
  if (t.requestToken) {
1859
2016
  let n = e.querySelector("input[name=\"requestToken\"]");
@@ -1863,6 +2020,10 @@ function nr(e, t) {
1863
2020
  let n = e.querySelector("input[name=\"renderId\"]");
1864
2021
  n && (n.value = t.renderId);
1865
2022
  }
2023
+ if (t.uploadCreateToken) {
2024
+ let n = e.querySelector("input[name=\"uploadCreateToken\"]");
2025
+ n || (n = document.createElement("input"), n.type = "hidden", n.name = "uploadCreateToken", e.append(n)), n.value = t.uploadCreateToken;
2026
+ }
1866
2027
  t.captchas && typeof t.captchas == "object" && Object.values(t.captchas).forEach((t) => {
1867
2028
  if (!t || typeof t != "object") return;
1868
2029
  let n = t;
@@ -1872,12 +2033,11 @@ function nr(e, t) {
1872
2033
  });
1873
2034
  }
1874
2035
  }
1875
- async function rr(e, t) {
1876
- let n = q(t.mode), r = J(t.transport);
2036
+ async function nr(e, t) {
2037
+ let n = kn(t.mode), r = An(t.transport);
1877
2038
  if (n !== "server-rendered") return null;
1878
2039
  if (t.payload) return t.payload.html && (e.innerHTML = t.payload.html), t.payload;
1879
- Rn(r, n);
1880
- let i = !!Y(e), a = t.formHandle || e.dataset.formieHandle;
2040
+ let i = !!jn(e), a = t.formHandle || e.dataset.formieHandle;
1881
2041
  if (i || !a) return null;
1882
2042
  let o = {
1883
2043
  mode: n,
@@ -1886,22 +2046,23 @@ async function rr(e, t) {
1886
2046
  siteId: t.siteId,
1887
2047
  theme: t.theme,
1888
2048
  themeConfig: t.themeConfig
1889
- }, s = r === "graphql" ? Pn(t, e) : Nn(t, e), c = r === "graphql" ? await Ve(s, a, o) : await Be(s, a, {
2049
+ }, s = r === "graphql" ? Fn(t, e) : Pn(t, e), c = r === "graphql" ? await Je(s, a, o, t) : await qe(s, a, {
1890
2050
  ...o,
1891
2051
  endpoint: s
1892
- });
2052
+ }, t);
1893
2053
  return c?.html && (e.innerHTML = c.html), c;
1894
2054
  }
1895
- async function ir(e, t, n) {
2055
+ async function rr(e, t, n) {
1896
2056
  if (t.refreshTokens === !1) return;
1897
- Rn(J(t.transport), q(t.mode));
1898
2057
  let r = t.formHandle || e.dataset.formieHandle;
1899
2058
  if (!r) return;
1900
- let i = await j(Fn(t, e), r, n.querySelector("input[name=\"renderId\"]")?.value || void 0);
1901
- nr(n, i), h(e, "formie:refresh-tokens:refreshed", i);
2059
+ let i = await P(In(t, e), r, n.querySelector("input[name=\"renderId\"]")?.value || void 0, t, n?.querySelector("input[name=\"requestToken\"]")?.value);
2060
+ tr(n, i), y(e, "formie:refresh-tokens:refreshed", i);
1902
2061
  }
1903
- function ar(e, t, n, r, i, a) {
1904
- let o = String(t.dataset.formieSubmitMethod || "").trim().toLowerCase(), s = Vn(n, e, t), c = !1, u = t.querySelectorAll("[data-formie-action]"), g = (e) => {
2062
+ function ir(e, t, n, r, i, a) {
2063
+ let o = () => {};
2064
+ t.dataset.formieRequestProfile = n.profile ?? "same-origin-browser", n.profile === "cross-origin-public" && (t.dataset.formieSubmitMethod = "ajax");
2065
+ let s = String(t.dataset.formieSubmitMethod || "").trim().toLowerCase(), c = Vn(n, e, t), l = !1, u = t.querySelectorAll("[data-formie-action]"), d = (e) => {
1905
2066
  if (e) {
1906
2067
  t.setAttribute("data-formie-pending-action", e);
1907
2068
  return;
@@ -1909,10 +2070,12 @@ function ar(e, t, n, r, i, a) {
1909
2070
  t.removeAttribute("data-formie-pending-action");
1910
2071
  };
1911
2072
  if (Hn(t)) {
1912
- let n = hn(t, { shouldWarn: () => !Gn(t) }), r = (e) => {
2073
+ let n = on(t, { shouldWarn: () => !Wn(t) });
2074
+ o = n.scheduleBaselineCapture;
2075
+ let r = (e) => {
1913
2076
  if (!(e instanceof CustomEvent)) return;
1914
2077
  let t = e.detail;
1915
- t?.ok && t.action === "save" && n.scheduleBaselineCapture();
2078
+ t?.ok && (t.action === "save" || t.outcome === "revised") && n.scheduleBaselineCapture();
1916
2079
  }, i = () => {
1917
2080
  n.scheduleBaselineCapture();
1918
2081
  };
@@ -1923,32 +2086,38 @@ function ar(e, t, n, r, i, a) {
1923
2086
  if (u.forEach((e) => {
1924
2087
  let n = (e) => {
1925
2088
  let n = e.currentTarget.getAttribute("data-formie-action"), r = t.querySelector("input[name=\"submitAction\"]");
1926
- g(n), n && r && (r.value = n);
2089
+ d(n), n && r && (r.value = n);
1927
2090
  };
1928
2091
  e.addEventListener("click", n), a.push(() => {
1929
2092
  e.removeEventListener("click", n);
1930
2093
  });
1931
2094
  }), t.querySelectorAll("[data-formie-tab-link]").forEach((n) => {
1932
2095
  let r = async (n) => {
1933
- if (o !== "ajax") {
1934
- Jn(n) && Un(t, "set-page");
2096
+ if (s !== "ajax") {
2097
+ qn(n) && Un(t, "set-page");
1935
2098
  return;
1936
2099
  }
1937
2100
  n.preventDefault();
1938
2101
  let r = n.currentTarget, i = r?.getAttribute("data-formie-page-id"), a = r?.getAttribute("href");
1939
- if (!(!i || !a)) {
1940
- p(t, i), h(e, "formie:page:navigate", {
2102
+ if (i && a) {
2103
+ y(e, "formie:page:navigate", {
1941
2104
  pageId: i,
1942
2105
  href: a
1943
2106
  });
1944
2107
  try {
1945
- h(e, "formie:page:navigate:after", {
2108
+ let n = await Ye(a, t, i);
2109
+ if (n.pageId && _(t, String(n.pageId)), !n.success) {
2110
+ let { form: e = [], ...r } = n.errors ?? {};
2111
+ Lt(t), Ot(t, r), kt(t, e), We(t);
2112
+ return;
2113
+ }
2114
+ y(e, "formie:page:navigate:after", {
1946
2115
  pageId: i,
1947
2116
  href: a,
1948
- response: await He(a, t, i)
2117
+ response: n
1949
2118
  });
1950
2119
  } catch (t) {
1951
- console.error("[formie] Failed to persist page navigation state.", t), h(e, "formie:page:navigate:error", {
2120
+ console.error("[formie] Failed to persist page navigation state.", t), y(e, "formie:page:navigate:error", {
1952
2121
  pageId: i,
1953
2122
  href: a,
1954
2123
  error: t
@@ -1961,48 +2130,48 @@ function ar(e, t, n, r, i, a) {
1961
2130
  });
1962
2131
  }), !Bn(t)) {
1963
2132
  let e = !1, n = () => {
1964
- e || Gn(t) || qn(t) || (e = !0, Ue(s, t));
2133
+ e || Wn(t) || Kn(t) || (e = !0, Xe(c, t));
1965
2134
  };
1966
2135
  window.addEventListener("pagehide", n), window.addEventListener("beforeunload", n), a.push(() => {
1967
2136
  window.removeEventListener("pagehide", n), window.removeEventListener("beforeunload", n);
1968
2137
  });
1969
2138
  }
1970
- let _ = async (a) => {
1971
- if (c) return;
1972
- let s = o === "ajax";
2139
+ let f = async (a) => {
2140
+ if (l) return;
2141
+ let o = s === "ajax";
1973
2142
  if (a.preventDefault(), t.getAttribute("data-formie-loading") === "true") {
1974
2143
  if (t.getAttribute("data-formie-internal-resubmit") !== "true") return;
1975
2144
  t.removeAttribute("data-formie-internal-resubmit");
1976
2145
  } else t.removeAttribute("data-formie-internal-resubmit");
1977
- let u = a.submitter, p = u?.getAttribute("data-formie-action"), _ = t.getAttribute("data-formie-pending-action"), v = t.querySelector("input[name=\"submitAction\"]"), y = p || _ || v?.value || "submit", b = null, x = !1;
2146
+ let c = a.submitter, u = c?.getAttribute("data-formie-action"), f = t.getAttribute("data-formie-pending-action"), m = t.querySelector("input[name=\"submitAction\"]"), _ = u || f || m?.value || "submit", b = null, x = !1;
1978
2147
  try {
1979
- if (s) b = await qt({
2148
+ if (o) b = await Rt({
1980
2149
  target: e,
1981
2150
  form: t,
1982
2151
  bus: r,
1983
2152
  validator: i,
1984
- validateOnSubmit: Z(t),
1985
- action: y,
1986
- submitter: u,
1987
- waitForSubmitDelay: Zn,
2153
+ validateOnSubmit: X(t),
2154
+ action: _,
2155
+ submitter: c,
2156
+ waitForSubmitDelay: Xn,
1988
2157
  onRefreshTokensAfterSubmit: async () => {
1989
- await ir(e, n, t);
2158
+ await rr(e, n, t);
1990
2159
  },
1991
2160
  dispatchSubmitResult: (t) => {
1992
- h(e, "formie:submit:result", t);
2161
+ y(e, "formie:submit:result", t);
1993
2162
  }
1994
2163
  });
1995
2164
  else {
1996
- if (Kt(t), m(t, u), await Zn(t), b = await nt(t, y, r, {
2165
+ if (Lt(t), v(t, c), await Xn(t), b = await ct(t, _, r, {
1997
2166
  validator: i,
1998
- validateOnSubmit: Z(t),
2167
+ validateOnSubmit: X(t),
1999
2168
  preflightOnly: !0
2000
2169
  }), b.ok) {
2001
- l(t, y), c = !0, Un(t, "submit"), g(null);
2170
+ p(t, _), l = !0, Un(t, "submit"), d(null);
2002
2171
  let e = !1, n = () => {
2003
- if (e = !0, c = !1, Wn(t), d(t), i && Z(t)) {
2004
- let { scope: e, final: n } = f(t), r = i.submit(n ? t : e, { final: n });
2005
- r.length > 0 && I(t, {
2172
+ if (e = !0, l = !1, Y(t), h(t), i && X(t)) {
2173
+ let { scope: e, final: n } = g(t), r = i.submit(n ? t : e, { final: n });
2174
+ r.length > 0 && z(t, {
2006
2175
  ok: !1,
2007
2176
  stage: "validate",
2008
2177
  code: "VALIDATION_FAILED",
@@ -2024,274 +2193,321 @@ function ar(e, t, n, r, i, a) {
2024
2193
  x = !0;
2025
2194
  return;
2026
2195
  }
2027
- I(t, b), h(e, "formie:submit:result", b), Wn(t);
2196
+ z(t, b), y(e, "formie:submit:result", b), Y(t);
2028
2197
  }
2029
2198
  } catch (n) {
2030
- c = !1, b = {
2199
+ l = !1, b = {
2031
2200
  ok: !1,
2032
2201
  code: "SUBMIT_ERROR",
2033
2202
  message: n instanceof Error ? n.message : "Submission failed.",
2034
2203
  formErrors: [n instanceof Error ? n.message : "Submission failed."]
2035
- }, I(t, b), h(e, "formie:submit:result", b), Wn(t);
2204
+ }, z(t, b), y(e, "formie:submit:result", b), Y(t);
2036
2205
  } finally {
2037
- g(null), !s && !x && !Gt(b) && d(t);
2206
+ d(null), !o && !x && !It(b) && h(t);
2038
2207
  }
2039
2208
  };
2040
- t.addEventListener("submit", _), a.push(() => {
2041
- t.removeEventListener("submit", _);
2042
- });
2209
+ return t.addEventListener("submit", f), a.push(() => {
2210
+ t.removeEventListener("submit", f);
2211
+ }), o;
2043
2212
  }
2044
- async function or(e, t, n) {
2213
+ async function ar(e, t, n) {
2045
2214
  if (t.refreshTokens === !1 || !t.staticCache) return;
2046
- Rn(J(t.transport), q(t.mode));
2047
- let r = t.formHandle || e.dataset.formieHandle, i = Fn(t, e), a = n?.querySelector("input[name=\"renderId\"]")?.value || void 0;
2215
+ let r = t.formHandle || e.dataset.formieHandle, i = In(t, e), a = n?.querySelector("input[name=\"renderId\"]")?.value || void 0;
2048
2216
  if (!r) return;
2049
- let o = await j(i, r, a);
2050
- !o || !n || (nr(n, o), h(e, "formie:refresh-tokens:after", o));
2217
+ let o = await P(i, r, a, t, n?.querySelector("input[name=\"requestToken\"]")?.value);
2218
+ o && n && (tr(n, o), y(e, "formie:refresh-tokens:after", o));
2051
2219
  }
2052
- function sr() {
2053
- let e = /* @__PURE__ */ new Map(), t = new L(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = [
2220
+ function or() {
2221
+ let t = /* @__PURE__ */ new Map(), r = new B(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = [
2054
2222
  "prepare",
2055
2223
  "normalize",
2056
2224
  "validate",
2057
- "screen",
2058
- "authorize",
2059
- "dispatch",
2060
- "finalize"
2061
- ], a = async (t) => {
2062
- let i = r.get(t);
2063
- if (i) {
2064
- await i;
2225
+ "challenge",
2226
+ "payment",
2227
+ "send",
2228
+ "result"
2229
+ ], s = async (e) => {
2230
+ let n = a.get(e);
2231
+ if (n) {
2232
+ await n;
2065
2233
  return;
2066
2234
  }
2067
- let a = (async () => {
2068
- W.log("Unmount requested.", { target: Q(t) });
2069
- let r = n.get(t);
2070
- r && (r(), n.delete(t));
2071
- let i = e.get(t);
2072
- if (!i) {
2073
- W.log("Unmount skipped (no mounted state).", { target: Q(t) });
2235
+ let r = (async () => {
2236
+ G.log("Unmount requested.", { target: Z(e) });
2237
+ let n = i.get(e);
2238
+ n && (n(), i.delete(e));
2239
+ let r = t.get(e);
2240
+ if (!r) {
2241
+ G.log("Unmount skipped (no mounted state).", { target: Z(e) });
2074
2242
  return;
2075
2243
  }
2076
- h(t, "formie:unmount:before", { id: i.instance.id }), i.unbinds.forEach((e) => {
2244
+ y(e, "formie:unmount:before", { id: r.instance.id }), r.unbinds.forEach((e) => {
2077
2245
  e();
2078
- }), i.unbinds = [], i.validator?.destroy(), i.validator = null;
2079
- for (let e of i.modules) await e.destroy();
2080
- i.modules = [], i.bus.clear(), e.delete(t), h(t, "formie:unmount:after", { id: i.instance.id }), W.log("Unmount complete.", {
2081
- id: i.instance.id,
2082
- target: Q(t)
2246
+ }), r.unbinds = [], r.validator?.destroy(), r.validator = null, await r.modules.destroy(), r.bus.clear(), t.delete(e), y(e, "formie:unmount:after", { id: r.instance.id }), G.log("Unmount complete.", {
2247
+ id: r.instance.id,
2248
+ target: Z(e)
2083
2249
  });
2084
2250
  })().finally(() => {
2085
- r.delete(t);
2251
+ a.delete(e);
2086
2252
  });
2087
- r.set(t, a), await a;
2088
- }, o = async (r, o) => {
2089
- W.log("Mount requested.", {
2090
- target: Q(r),
2091
- mode: o.mode,
2092
- autoVisible: o.autoVisible
2253
+ a.set(e, r), await r;
2254
+ }, c = async (a, c) => {
2255
+ G.log("Mount requested.", {
2256
+ target: Z(a),
2257
+ mode: c.mode,
2258
+ autoVisible: c.autoVisible
2093
2259
  });
2094
- let s = n.get(r);
2095
- s && (s(), n.delete(r));
2096
- let c = e.get(r);
2097
- if (c) return W.log("Mount skipped (already mounted).", {
2098
- id: c.instance.id,
2099
- target: Q(r)
2100
- }), c.instance;
2101
- let l = new Ie(), d = [], f = r?.id || `formie-${e.size + 1}`, p = K(r), m = {
2102
- ...p,
2103
- ...o,
2104
- mode: q(o.mode ?? p.mode),
2105
- transport: J(o.transport ?? p.transport)
2106
- }, g = ve(m.compatibility);
2107
- if (m.mode !== "server-rendered" && !Y(r)) throw Error(`Formie ${m.mode} mode is not implemented yet in the browser client.`);
2108
- let v = await rr(r, m), b = Y(r);
2109
- m.staticCache = o.staticCache ?? An(b ? b.dataset : r.dataset);
2110
- let x = $n(r, b), ee = v || x ? {
2111
- ...v || {},
2112
- ...x || {}
2113
- } : null, te = ee?.theme, S = {}, C = (ee?.modules || []).filter((e) => !!e?.id && !!e?.type);
2114
- W.log("Resolved mount payload.", {
2115
- target: Q(r),
2116
- hasRenderPayload: !!v,
2117
- hasEmbeddedPayload: !!x,
2118
- moduleCount: C.length
2260
+ let l = i.get(a);
2261
+ l && (l(), i.delete(a));
2262
+ let u = t.get(a);
2263
+ if (u) return G.log("Mount skipped (already mounted).", {
2264
+ id: u.instance.id,
2265
+ target: Z(a)
2266
+ }), u.instance;
2267
+ let d = new zt(), f = [], p = a?.id || `formie-${t.size + 1}`, h = q(a), g = {
2268
+ ...h,
2269
+ ...c,
2270
+ mode: kn(c.mode ?? h.mode),
2271
+ transport: An(c.transport ?? h.transport)
2272
+ }, _ = await nr(a, g), v = jn(a);
2273
+ c.compatibility === void 0 && v?.hasAttribute("data-formie-compatibility") && (g.compatibility = q(v).compatibility);
2274
+ let b = we(g.compatibility);
2275
+ v && e(v, g), g.staticCache = c.staticCache ?? On(v ? v.dataset : a.dataset);
2276
+ let S;
2277
+ try {
2278
+ S = Qn(a, v), _?.modules && n(_.modules), S?.modules && n(S.modules);
2279
+ } catch (e) {
2280
+ if (v) {
2281
+ v.addEventListener("submit", (e) => {
2282
+ e.preventDefault(), e.stopImmediatePropagation();
2283
+ }, !0);
2284
+ let e = document.createElement("div");
2285
+ e.setAttribute("role", "alert"), e.textContent = "This form requires a compatible Formie browser package. Update Formie and its browser packages together.", v.prepend(e);
2286
+ }
2287
+ throw e;
2288
+ }
2289
+ let ee = _ || S ? {
2290
+ ..._ || {},
2291
+ ...S || {}
2292
+ } : null, te = ee?.theme, w = {}, T = ee?.modules ?? {
2293
+ contractVersion: 2,
2294
+ surface: "server-rendered",
2295
+ entries: []
2296
+ };
2297
+ n(T), G.log("Resolved mount payload.", {
2298
+ target: Z(a),
2299
+ hasRenderPayload: !!_,
2300
+ hasEmbeddedPayload: !!S,
2301
+ moduleCount: T.entries.length
2119
2302
  });
2120
- let w = ne(r, te, b), T = b ? new mt(b, {
2121
- live: zn(b.dataset.formieValidationOnFocus),
2122
- errorAriaLive: Te(b),
2123
- errorMessage: b.dataset.formieErrorMessage || "",
2124
- fieldContainerErrorClass: w.fieldLayoutError || [],
2125
- inputErrorClass: w.fieldControlError || [],
2126
- messagesClass: w.fieldErrors || [],
2127
- messageClass: w.fieldError || []
2303
+ let E = ne(a, te, v), D = v ? new pn(v, {
2304
+ live: zn(v.dataset.formieValidationOnFocus),
2305
+ errorAriaLive: Me(v),
2306
+ errorMessage: v.dataset.formieErrorMessage || "",
2307
+ fieldContainerErrorClass: E.fieldLayoutError || [],
2308
+ inputErrorClass: E.fieldControlError || [],
2309
+ messagesClass: E.fieldErrors || [],
2310
+ messageClass: E.fieldError || []
2128
2311
  }) : null;
2129
- if (b && T) {
2130
- let e = b;
2131
- e.formieValidation = T, S.validation = T;
2312
+ if (v && D) {
2313
+ let e = v;
2314
+ e.formieValidation = D, w.validation = D;
2132
2315
  let t = {
2133
- validator: T,
2134
- addValidator: T.addValidator.bind(T),
2135
- removeValidator: T.removeValidator.bind(T)
2316
+ validator: D,
2317
+ addValidator: D.addValidator.bind(D),
2318
+ removeValidator: D.removeValidator.bind(D)
2136
2319
  };
2137
- h(b, "formie:validator:ready", t), h(r, "formie:validator:ready", t);
2320
+ y(v, "formie:validator:ready", t), y(a, "formie:validator:ready", t);
2138
2321
  }
2139
- b && (ln(b), m.themeConfig && typeof m.themeConfig == "object" && b.setAttribute("data-formie-theme-config", JSON.stringify(m.themeConfig)), m.theme && m.theme !== "formie" && b.setAttribute("data-formie-frontend-theme", m.theme), (v || m.endpoint || r.dataset.formieEndpoint) && Ln(r, b, m), m.mode === "server-rendered" && Pe(b) && (Ne(b), Fe(b)), y(b)), Object.keys(w).length && h(r, "formie:theme:applied", { hasClasses: !0 });
2140
- let E = await sn(C, {
2141
- registry: t,
2322
+ v && ($t(v), (_ || g.endpoint || a.dataset.formieEndpoint) && Rn(a, v, g), g.mode === "server-rendered" && Ue(v) && (He(v), We(v)), C(v)), Object.keys(E).length && y(a, "formie:theme:applied", { hasClasses: !0 }), v?.querySelector("craft-csrf-input") && await oe("craft-csrf-input", v);
2323
+ let O = await Zt(T, {
2324
+ registry: r,
2142
2325
  matchContext: {
2143
- root: r,
2144
- form: b,
2145
- mode: m.mode
2326
+ root: a,
2327
+ form: v,
2328
+ surface: T.surface
2146
2329
  },
2147
2330
  setupContext: {
2148
- formId: f,
2149
- root: r,
2150
- form: b,
2151
- target: r,
2331
+ formId: p,
2332
+ root: a,
2333
+ form: v,
2334
+ target: a,
2152
2335
  scope: "form",
2153
- state: S,
2154
- on: (e, t) => l.on(e, t),
2155
- emit: (e, t) => (h(r, e, t), l.emitSafe(e, t).then((t) => {
2156
- t.failed.length > 0 && W.warn("Lifecycle listeners failed.", {
2336
+ surface: T.surface,
2337
+ state: w,
2338
+ on: (e, t) => d.on(e, t),
2339
+ emit: (e, t) => (y(a, e, t), d.emitSafe(e, t).then((t) => {
2340
+ t.failed.length > 0 && G.warn("Lifecycle listeners failed.", {
2157
2341
  eventName: e,
2158
2342
  failed: t.failed.length
2159
2343
  });
2160
2344
  }))
2161
2345
  }
2162
2346
  });
2163
- W.log("Module setup complete.", {
2164
- target: Q(r),
2165
- moduleInstances: E.length
2347
+ G.log("Module setup complete.", {
2348
+ target: Z(a),
2349
+ moduleInstances: O.instances.length
2166
2350
  });
2167
- let D = {
2168
- id: f,
2169
- root: r,
2351
+ let k = {
2352
+ id: p,
2353
+ root: a,
2170
2354
  submit: async (e = "submit") => {
2171
- if (W.log("Submit requested.", {
2172
- id: f,
2173
- target: Q(r),
2355
+ if (G.log("Submit requested.", {
2356
+ id: p,
2357
+ target: Z(a),
2174
2358
  action: e
2175
- }), !b) return {
2359
+ }), !v) return {
2176
2360
  ok: !1,
2177
2361
  code: "FORM_NOT_FOUND",
2178
2362
  message: "No form element found for mount target.",
2179
2363
  formErrors: ["No form element found for mount target."]
2180
2364
  };
2181
- let t = b.querySelector("input[name=\"submitAction\"]");
2182
- if (t && (t.value = e), b.getAttribute("data-formie-loading") === "true") return {
2365
+ let t = v.querySelector("input[name=\"submitAction\"]");
2366
+ if (t && (t.value = e), v.getAttribute("data-formie-loading") === "true") return {
2183
2367
  ok: !1,
2184
2368
  code: "SUBMIT_IN_PROGRESS",
2185
2369
  message: "Submission already in progress.",
2186
2370
  formErrors: []
2187
2371
  };
2188
- let n = b.querySelector(`[data-formie-action="${e}"]`), i = await qt({
2189
- id: f,
2190
- target: r,
2191
- form: b,
2192
- bus: l,
2193
- validator: T,
2194
- validateOnSubmit: Z(b),
2372
+ let n = v.querySelector(`[data-formie-action="${e}"]`), r = await Rt({
2373
+ id: p,
2374
+ target: a,
2375
+ form: v,
2376
+ bus: d,
2377
+ validator: D,
2378
+ validateOnSubmit: X(v),
2195
2379
  action: e,
2196
2380
  submitter: n,
2197
- waitForSubmitDelay: Zn,
2381
+ waitForSubmitDelay: Xn,
2198
2382
  onRefreshTokensAfterSubmit: async () => {
2199
- await ir(r, m, b);
2383
+ await rr(a, g, v);
2200
2384
  },
2201
2385
  dispatchSubmitResult: (e) => {
2202
- h(r, "formie:submit:result", e);
2386
+ y(a, "formie:submit:result", e);
2203
2387
  }
2204
2388
  });
2205
- return W.log("Submit completed.", {
2206
- id: f,
2389
+ return G.log("Submit completed.", {
2390
+ id: p,
2207
2391
  action: e,
2208
- ok: i.ok,
2209
- code: i.code,
2210
- message: i.message
2211
- }), i;
2392
+ ok: r.ok,
2393
+ code: r.code,
2394
+ message: r.message
2395
+ }), r;
2212
2396
  },
2213
2397
  destroy: async () => {
2214
- await a(r);
2398
+ await s(a);
2215
2399
  },
2216
- on: (e, t) => l.on(e, t)
2400
+ on: (e, t) => d.on(e, t)
2217
2401
  };
2218
- b && (we({
2219
- target: r,
2220
- form: b,
2221
- validatorDetail: T ? {
2222
- validator: T,
2223
- addValidator: T.addValidator.bind(T),
2224
- removeValidator: T.removeValidator.bind(T)
2402
+ if (v && (je({
2403
+ target: a,
2404
+ form: v,
2405
+ validatorDetail: D ? {
2406
+ validator: D,
2407
+ addValidator: D.addValidator.bind(D),
2408
+ removeValidator: D.removeValidator.bind(D)
2225
2409
  } : null,
2226
- options: g,
2227
- unbinds: d
2228
- }), Ce({
2229
- target: r,
2230
- form: b,
2231
- instance: D,
2232
- options: g,
2233
- unbinds: d
2234
- })), b && (ar(r, b, m, l, T, d), T && (d.push(_(b, T, r)), d.push(bn(b))), await or(r, m, b), b.dispatchEvent(new CustomEvent("formie:state:reset")), window.setTimeout(() => {
2235
- b.dispatchEvent(new CustomEvent("formie:state:reset"));
2236
- }, 350)), i.forEach((e) => {
2237
- let t = l.on(`formie:stage:${e}:before`, async (t) => {
2238
- h(r, `formie:stage:${e}:before`, t);
2239
- }), n = l.on(`formie:stage:${e}:before`, async (e) => {
2240
- for (let t of E) t.onBeforeStage && await t.onBeforeStage(e);
2241
- }), i = l.on(`formie:stage:${e}:after`, async (t) => {
2242
- h(r, `formie:stage:${e}:after`, t);
2243
- }), a = l.on(`formie:stage:${e}:after`, async (e) => {
2244
- let t = e;
2245
- for (let e of E) e.onAfterStage && await e.onAfterStage(t, t.result);
2410
+ options: b,
2411
+ unbinds: f
2412
+ }), ke({
2413
+ target: a,
2414
+ form: v,
2415
+ instance: k,
2416
+ options: b,
2417
+ unbinds: f
2418
+ })), v) {
2419
+ let e = ir(a, v, g, d, D, f);
2420
+ D && (f.push(x(v, D, a)), f.push(vn(v))), await ar(a, g, v), e();
2421
+ let t = window.setTimeout(e, 350);
2422
+ f.push(() => window.clearTimeout(t));
2423
+ }
2424
+ o.forEach((e) => {
2425
+ let t = d.on(`formie:stage:${e}:before`, async (t) => {
2426
+ y(a, `formie:stage:${e}:before`, t);
2427
+ }), n = d.on(`formie:stage:${e}:before`, async (t) => {
2428
+ let n = {
2429
+ core: "prepare",
2430
+ field: "prepare",
2431
+ address: "prepare",
2432
+ captcha: "challenge",
2433
+ payment: "payment"
2434
+ }, r = t;
2435
+ if (e === "prepare") try {
2436
+ O.assertReady();
2437
+ } catch {
2438
+ r.abort("A required form feature could not start. Reload the page or contact the site administrator.");
2439
+ return;
2440
+ }
2441
+ for (let t of O.instances) if (t.beforeSubmit && n[t.kind ?? "core"] === e) {
2442
+ let { form: e, action: n, formData: i, abort: a, isAborted: o, abortReason: s } = r;
2443
+ await t.beforeSubmit({
2444
+ form: e,
2445
+ action: n,
2446
+ formData: i,
2447
+ abort: a,
2448
+ isAborted: o,
2449
+ abortReason: s
2450
+ });
2451
+ }
2452
+ }), r = d.on(`formie:stage:${e}:after`, async (t) => {
2453
+ y(a, `formie:stage:${e}:after`, t);
2246
2454
  });
2247
- d.push(t, n, i, a);
2455
+ f.push(t, n, r);
2248
2456
  });
2249
- let re = l.on("formie:submit:before", async (e) => {
2250
- h(r, "formie:submit:before", e);
2251
- }), ie = l.on("formie:submit:after", async (e) => {
2252
- h(r, "formie:submit:after", e);
2253
- }), ae = l.on("formie:submit:final:before", async (e) => {
2254
- h(r, "formie:submit:final:before", e);
2255
- }), oe = l.on("formie:submit:final:after", async (e) => {
2256
- h(r, "formie:submit:final:after", e);
2457
+ let re = d.on("formie:submit:before", async (e) => {
2458
+ y(a, "formie:submit:before", e);
2459
+ }), ie = d.on("formie:submit:after", async (e) => {
2460
+ if (y(a, "formie:submit:after", e), !v) return;
2461
+ let t = e;
2462
+ if (t.code === "PREFLIGHT_COMPLETE") return;
2463
+ let n = {
2464
+ form: v,
2465
+ action: t.action ?? "submit",
2466
+ formData: new FormData(v)
2467
+ };
2468
+ for (let e of O.instances) await e.afterSubmit?.(n, t);
2469
+ }), A = d.on("formie:submit:final:before", async (e) => {
2470
+ y(a, "formie:submit:final:before", e);
2471
+ }), ae = d.on("formie:submit:final:after", async (e) => {
2472
+ y(a, "formie:submit:final:after", e);
2257
2473
  });
2258
- return d.push(re, ie, ae, oe), e.set(r, {
2259
- options: m,
2260
- bus: l,
2261
- form: b,
2262
- validator: T,
2263
- modules: E,
2264
- unbinds: d,
2265
- instance: D
2266
- }), h(r, "formie:mount:after", {
2267
- id: f,
2268
- mode: m.mode
2269
- }), b instanceof HTMLFormElement && u(b), W.log("Mount complete.", {
2270
- id: f,
2271
- target: Q(r),
2272
- mode: m.mode
2273
- }), D;
2274
- }, s = (t, r) => {
2275
- if (!r.autoVisible || er(t) || typeof IntersectionObserver > "u") return o(t, r);
2276
- if (e.has(t)) return Promise.resolve(e.get(t)?.instance || null);
2277
- if (n.has(t)) return W.log("Mount deferred (already waiting visibility).", { target: Q(t) }), Promise.resolve(null);
2278
- let i = new IntersectionObserver((e) => {
2279
- e.some((e) => e.target === t && e.isIntersecting) && (i.disconnect(), n.delete(t), W.log("Visibility reached, proceeding mount.", { target: Q(t) }), o(t, {
2280
- ...r,
2474
+ return f.push(re, ie, A, ae), t.set(a, {
2475
+ options: g,
2476
+ bus: d,
2477
+ form: v,
2478
+ validator: D,
2479
+ modules: O,
2480
+ unbinds: f,
2481
+ instance: k
2482
+ }), y(a, "formie:mount:after", {
2483
+ id: p,
2484
+ mode: g.mode
2485
+ }), v instanceof HTMLFormElement && m(v), G.log("Mount complete.", {
2486
+ id: p,
2487
+ target: Z(a),
2488
+ mode: g.mode
2489
+ }), k;
2490
+ }, l = (e, n) => {
2491
+ if (!n.autoVisible || $n(e) || typeof IntersectionObserver > "u") return c(e, n);
2492
+ if (t.has(e)) return Promise.resolve(t.get(e)?.instance || null);
2493
+ if (i.has(e)) return G.log("Mount deferred (already waiting visibility).", { target: Z(e) }), Promise.resolve(null);
2494
+ let r = new IntersectionObserver((t) => {
2495
+ t.some((t) => t.target === e && t.isIntersecting) && (r.disconnect(), i.delete(e), G.log("Visibility reached, proceeding mount.", { target: Z(e) }), c(e, {
2496
+ ...n,
2281
2497
  autoVisible: !1
2282
2498
  }));
2283
2499
  }, { threshold: .01 });
2284
- return i.observe(t), n.set(t, () => {
2285
- i.disconnect();
2286
- }), W.log("Mount deferred until visible.", { target: Q(t) }), Promise.resolve(null);
2500
+ return r.observe(e), i.set(e, () => {
2501
+ r.disconnect();
2502
+ }), G.log("Mount deferred until visible.", { target: Z(e) }), Promise.resolve(null);
2287
2503
  };
2288
2504
  return {
2289
- mount: o,
2290
- unmount: a,
2291
- update: async (t, n) => {
2292
- let r = e.get(t);
2293
- if (!r) return o(t, {
2294
- ...K(t),
2505
+ mount: c,
2506
+ unmount: s,
2507
+ update: async (e, n) => {
2508
+ let r = t.get(e);
2509
+ if (!r) return c(e, {
2510
+ ...q(e),
2295
2511
  ...n,
2296
2512
  mode: n.mode || "server-rendered"
2297
2513
  });
@@ -2299,79 +2515,82 @@ function sr() {
2299
2515
  ...r.options,
2300
2516
  ...n
2301
2517
  };
2302
- let i = ne(t, n.payload?.theme || r.options.payload?.theme || $n(t, r.form)?.theme, r.form);
2303
- return r.validator && (r.validator.config.fieldContainerErrorClass = i.fieldLayoutError || [], r.validator.config.inputErrorClass = i.fieldControlError || [], r.validator.config.messagesClass = i.fieldErrors || [], r.validator.config.messageClass = i.fieldError || []), Object.keys(i).length && h(t, "formie:theme:applied", {
2518
+ let i = n.payload?.theme || r.options.payload?.theme || Qn(e, r.form)?.theme, a = ne(e, i, r.form);
2519
+ return r.validator && (r.validator.config.fieldContainerErrorClass = a.fieldLayoutError || [], r.validator.config.inputErrorClass = a.fieldControlError || [], r.validator.config.messagesClass = a.fieldErrors || [], r.validator.config.messageClass = a.fieldError || []), Object.keys(a).length && y(e, "formie:theme:applied", {
2304
2520
  hasClasses: !0,
2305
2521
  reason: "update"
2306
2522
  }), r.instance;
2307
2523
  },
2308
- getInstance: (t) => e.get(t)?.instance || null,
2309
- refreshForCache: async (t) => {
2310
- jn("refreshForCache", "Global `Formie.refreshForCache()` has been deprecated. Use built-in static-cache token refresh handling instead.");
2524
+ getInstance: (e) => t.get(e)?.instance || null,
2525
+ refreshForCache: async (e) => {
2526
+ Mn("refreshForCache", "Global `Formie.refreshForCache()` has been deprecated. Use built-in static-cache token refresh handling instead.");
2311
2527
  let n = null;
2312
- if (n = typeof t == "string" ? document.getElementById(t) || document.querySelector(`[data-formie-form-id="${t}"]`) : t, !n) {
2313
- W.warn("refreshForCache target not found.", { targetOrId: t });
2528
+ if (n = typeof e == "string" ? document.getElementById(e) || document.querySelector(`[data-formie-form-id="${e}"]`) : e, !n) {
2529
+ G.warn("refreshForCache target not found.", { targetOrId: e });
2314
2530
  return;
2315
2531
  }
2316
- let r = e.get(n), i = Y(n), a = r?.options || K(n);
2532
+ let r = t.get(n), i = jn(n), a = r?.options || q(n);
2317
2533
  if (!i) {
2318
- W.warn("refreshForCache found no form element for target.", { target: Q(n) });
2534
+ G.warn("refreshForCache found no form element for target.", { target: Z(n) });
2319
2535
  return;
2320
2536
  }
2321
- let o = a.formHandle || n.dataset.formieHandle || i.dataset.formieHandle, s = Fn(a, n), c = i.querySelector("input[name=\"renderId\"]")?.value || void 0;
2537
+ let o = a.formHandle || n.dataset.formieHandle || i.dataset.formieHandle, s = In(a, n), c = i.querySelector("input[name=\"renderId\"]")?.value || void 0;
2322
2538
  if (!o) {
2323
- W.warn("refreshForCache found no form handle for target.", { target: Q(n) });
2539
+ G.warn("refreshForCache found no form handle for target.", { target: Z(n) });
2324
2540
  return;
2325
2541
  }
2326
- let l = await j(s, o, c);
2327
- l && (nr(i, l), h(n, "formie:refresh-tokens:after", l));
2542
+ let l = await P(s, o, c, a, i?.querySelector("input[name=\"requestToken\"]")?.value);
2543
+ l && (tr(i, l), y(n, "formie:refresh-tokens:after", l));
2328
2544
  },
2329
- registerModule: (e, n) => t.register(e, n),
2545
+ registerModule: (e, t) => r.register(e, t),
2330
2546
  unregisterModule: (e) => {
2331
- t.unregister(e);
2547
+ r.unregister(e);
2332
2548
  },
2333
- getRegisteredModules: () => t.getAll(),
2549
+ getRegisteredModules: () => r.getAll(),
2334
2550
  scan: async (e) => {
2335
- let t = e || document, n = Array.from(t.querySelectorAll(U));
2336
- W.log("Scan started.", {
2551
+ let t = e || document, n = Array.from(t.querySelectorAll(W));
2552
+ G.log("Scan started.", {
2337
2553
  scope: t === document ? "document" : t,
2338
2554
  targetCount: n.length
2339
2555
  });
2340
- let r = (await Promise.all(n.map((e) => s(e, K(e))))).filter((e) => !!e);
2341
- return W.log("Scan finished.", {
2556
+ let r = (await Promise.all(n.map((e) => {
2557
+ let t = q(e);
2558
+ return l(e, t);
2559
+ }))).filter((e) => !!e);
2560
+ return G.log("Scan finished.", {
2342
2561
  mountedCount: r.length,
2343
2562
  deferredCount: n.length - r.length
2344
2563
  }), r;
2345
2564
  },
2346
- observe: (t) => {
2565
+ observe: (e) => {
2347
2566
  if (typeof MutationObserver > "u") return () => {};
2348
- let r = t || document;
2349
- W.log("Observer started.", { scope: r === document ? "document" : r });
2350
- let i = new MutationObserver((t) => {
2351
- t.forEach((t) => {
2352
- t.addedNodes.forEach((e) => {
2353
- e instanceof Element && (e.matches(U) && (W.log("Observer detected new root.", { target: Q(e) }), s(e, K(e))), e.querySelectorAll(U).forEach((e) => {
2354
- W.log("Observer detected new nested root.", { target: Q(e) }), s(e, K(e));
2567
+ let n = e || document;
2568
+ G.log("Observer started.", { scope: n === document ? "document" : n });
2569
+ let r = new MutationObserver((e) => {
2570
+ e.forEach((e) => {
2571
+ e.addedNodes.forEach((e) => {
2572
+ e instanceof Element && (e.matches(W) && (G.log("Observer detected new root.", { target: Z(e) }), l(e, q(e))), e.querySelectorAll(W).forEach((e) => {
2573
+ G.log("Observer detected new nested root.", { target: Z(e) }), l(e, q(e));
2355
2574
  }));
2356
- }), t.removedNodes.forEach((t) => {
2357
- t instanceof Element && (e.has(t) && (W.log("Observer detected removed root.", { target: Q(t) }), a(t)), t.querySelectorAll(U).forEach((t) => {
2358
- e.has(t) && (W.log("Observer detected removed nested root.", { target: Q(t) }), a(t));
2575
+ }), e.removedNodes.forEach((e) => {
2576
+ e instanceof Element && (t.has(e) && (G.log("Observer detected removed root.", { target: Z(e) }), s(e)), e.querySelectorAll(W).forEach((e) => {
2577
+ t.has(e) && (G.log("Observer detected removed nested root.", { target: Z(e) }), s(e));
2359
2578
  }));
2360
2579
  });
2361
2580
  });
2362
2581
  });
2363
- return i.observe(r, {
2582
+ return r.observe(n, {
2364
2583
  childList: !0,
2365
2584
  subtree: !0
2366
2585
  }), () => {
2367
- i.disconnect(), W.log("Observer stopped."), n.forEach((e, t) => {
2368
- tr(t, r) && (e(), n.delete(t));
2586
+ r.disconnect(), G.log("Observer stopped."), i.forEach((e, t) => {
2587
+ er(t, n) && (e(), i.delete(t));
2369
2588
  });
2370
- let t = [];
2371
- r instanceof Element && r.matches(U) && t.push(r), r.querySelectorAll(U).forEach((e) => {
2372
- t.push(e);
2373
- }), t.forEach((t) => {
2374
- e.has(t) && a(t);
2589
+ let e = [];
2590
+ n instanceof Element && n.matches(W) && e.push(n), n.querySelectorAll(W).forEach((t) => {
2591
+ e.push(t);
2592
+ }), e.forEach((e) => {
2593
+ t.has(e) && s(e);
2375
2594
  });
2376
2595
  };
2377
2596
  }
@@ -2379,9 +2598,13 @@ function sr() {
2379
2598
  }
2380
2599
  //#endregion
2381
2600
  //#region src/js/core/hydrate-modules.ts
2382
- var cr = S("general", "module-hydrator");
2383
- async function lr(e) {
2384
- let t = e.root, n = e.form ?? (t instanceof HTMLFormElement ? t : t.closest("form")), r = e.modules ?? [], i = e.mode ?? "server-rendered", a = e.registry ?? new L(), o = new Ie(), s = await sn(r, {
2601
+ var sr = E("general", "module-hydrator");
2602
+ async function cr(e) {
2603
+ let t = e.root, n = e.form ?? (t instanceof HTMLFormElement ? t : t.closest("form") ?? t.querySelector("form")), r = e.surface ?? "cp-edit", i = e.modules ?? {
2604
+ contractVersion: 2,
2605
+ surface: r,
2606
+ entries: []
2607
+ }, a = e.registry ?? new B(), o = new zt(), s = await Zt(i, {
2385
2608
  registry: a,
2386
2609
  setupContext: {
2387
2610
  formId: n?.id || t.id || "formie-modules",
@@ -2389,26 +2612,76 @@ async function lr(e) {
2389
2612
  form: n,
2390
2613
  target: t,
2391
2614
  scope: "form",
2615
+ surface: r,
2392
2616
  state: {},
2393
2617
  options: {},
2394
2618
  on: (e, t) => o.on(e, t),
2395
- emit: async (e, t) => {
2396
- await o.emit(e, t);
2619
+ emit: async (e, n) => {
2620
+ t.dispatchEvent(new CustomEvent(e, {
2621
+ detail: n,
2622
+ bubbles: !0
2623
+ })), await o.emit(e, n);
2397
2624
  }
2398
2625
  },
2399
2626
  matchContext: {
2400
2627
  root: t,
2401
2628
  form: n,
2402
- mode: i
2629
+ surface: r
2403
2630
  }
2404
2631
  });
2405
- return cr.log("Hydrated module manifest.", {
2406
- moduleCount: r.length,
2407
- instanceCount: s.length,
2408
- mode: i
2632
+ return sr.log("Hydrated module manifest.", {
2633
+ moduleCount: i.entries.length,
2634
+ instanceCount: s.instances.length,
2635
+ surface: r
2409
2636
  }), {
2637
+ get instances() {
2638
+ return s.instances;
2639
+ },
2640
+ get failures() {
2641
+ return s.failures;
2642
+ },
2643
+ prepare: async (e) => {
2644
+ if (!n) throw Error("Browser modules require a mounted form element.");
2645
+ s.assertReady(), s.instances.forEach((e) => e.assertReady?.());
2646
+ let t, r = {
2647
+ form: n,
2648
+ action: e === "back" || e === "save" ? e : "submit",
2649
+ formData: new FormData(n),
2650
+ abort: (e) => {
2651
+ t = e || "A form feature could not complete.";
2652
+ },
2653
+ isAborted: () => !!t,
2654
+ abortReason: () => t
2655
+ }, i = {
2656
+ core: 0,
2657
+ field: 0,
2658
+ address: 0,
2659
+ captcha: 1,
2660
+ payment: 2
2661
+ };
2662
+ for (let e of [...s.instances].sort((e, t) => i[e.kind ?? "core"] - i[t.kind ?? "core"])) if (await e.beforeSubmit?.(r), t) throw Error(t);
2663
+ return Object.fromEntries(Array.from(n.querySelectorAll("input[type=\"hidden\"][name]")).map((e) => [e.name, e.value]));
2664
+ },
2665
+ result: async (e) => {
2666
+ if (!n) return;
2667
+ let t = {
2668
+ form: n,
2669
+ action: e.action ?? "submit",
2670
+ formData: new FormData(n)
2671
+ };
2672
+ await o.emit("formie:submit:result", e);
2673
+ for (let n of s.instances) await n.afterSubmit?.(t, e);
2674
+ n.dispatchEvent(new CustomEvent("formie:submit:result", {
2675
+ detail: e,
2676
+ bubbles: !0
2677
+ }));
2678
+ },
2679
+ update: (e) => s.updateManifest(e),
2680
+ assertReady: () => {
2681
+ s.assertReady(), s.instances.forEach((e) => e.assertReady?.());
2682
+ },
2410
2683
  destroy: async () => {
2411
- await ur(s), o.clear();
2684
+ await s.destroy(), o.clear();
2412
2685
  },
2413
2686
  on: (e, t) => o.on(e, t),
2414
2687
  emit: async (e, t) => {
@@ -2421,81 +2694,74 @@ async function lr(e) {
2421
2694
  getRegisteredModules: () => a.getAll()
2422
2695
  };
2423
2696
  }
2424
- async function ur(e) {
2425
- for (let t of e) try {
2426
- await t.destroy();
2427
- } catch (e) {
2428
- console.error("[formie] Failed to destroy module instance.", e), cr.warn("Failed destroying module instance.", { error: e });
2429
- }
2430
- }
2431
2697
  //#endregion
2432
2698
  //#region src/js/core/formie.ts
2433
- function $(e) {
2699
+ function Q(e) {
2434
2700
  return e instanceof Element;
2435
2701
  }
2436
- function dr(e) {
2702
+ function lr(e) {
2437
2703
  return e.ok;
2438
2704
  }
2439
- function fr(e) {
2440
- return typeof e == "string" ? `selector "${e}"` : $(e) ? `element "${e.tagName.toLowerCase()}"` : "provided element collection";
2705
+ function ur(e) {
2706
+ return typeof e == "string" ? `selector "${e}"` : Q(e) ? `element "${e.tagName.toLowerCase()}"` : "provided element collection";
2441
2707
  }
2442
- function pr(e) {
2708
+ function dr(e) {
2443
2709
  let t = /* @__PURE__ */ new Set(), n = [];
2444
- for (let r of e) !$(r) || t.has(r) || (t.add(r), n.push(r));
2710
+ for (let r of e) Q(r) && !t.has(r) && (t.add(r), n.push(r));
2445
2711
  return n;
2446
2712
  }
2447
- function mr(e) {
2448
- return typeof e == "string" ? Array.from(document.querySelectorAll(e)) : $(e) ? [e] : pr(e);
2713
+ function $(e) {
2714
+ return typeof e == "string" ? Array.from(document.querySelectorAll(e)) : Q(e) ? [e] : dr(e);
2449
2715
  }
2450
- function hr() {
2716
+ function fr() {
2451
2717
  return document.readyState === "loading" ? new Promise((e) => {
2452
2718
  document.addEventListener("DOMContentLoaded", () => e(), { once: !0 });
2453
2719
  }) : Promise.resolve();
2454
2720
  }
2455
- async function gr(e) {
2456
- let t = mr(e);
2457
- return t.length > 0 || typeof e != "string" ? t : (await hr(), mr(e));
2721
+ async function pr(e) {
2722
+ let t = $(e);
2723
+ return t.length > 0 || typeof e != "string" ? t : (await fr(), $(e));
2458
2724
  }
2459
- function _r(e) {
2460
- return typeof e == "string" ? document : $(e) ? e.getRootNode() : document;
2725
+ function mr(e) {
2726
+ return typeof e == "string" ? document : Q(e) ? e.getRootNode() : document;
2461
2727
  }
2462
- function vr(e) {
2728
+ function hr(e) {
2463
2729
  let { element: t, observe: n, allowEmpty: r, client: i, onReady: a, onResult: o, onSuccess: s, onError: c, onEvent: l, ...u } = e;
2464
2730
  return {
2465
2731
  mode: "server-rendered",
2466
2732
  ...u
2467
2733
  };
2468
2734
  }
2469
- async function yr(e, t, n, r) {
2470
- let i = [], o = vr(e);
2471
- for (let s of r) {
2472
- let r = n.get(s);
2735
+ async function gr(e, t, n, r) {
2736
+ let i = [], a = hr(e);
2737
+ for (let o of r) {
2738
+ let r = n.get(o);
2473
2739
  if (r) {
2474
2740
  i.push(r.instance);
2475
2741
  continue;
2476
2742
  }
2477
- let c = await t.mount(s, o), l = [];
2478
- if (e.onReady?.(c), l.push(c.on("formie:submit:result", (t) => {
2743
+ let s = await t.mount(o, a), c = [];
2744
+ if (e.onReady?.(s), c.push(s.on("formie:submit:result", (t) => {
2479
2745
  let n = t;
2480
- e.onResult?.(n, c), dr(n) ? e.onSuccess?.(n, c) : e.onError?.(n, c);
2481
- })), e.onEvent) for (let t of a) l.push(c.on(t, (n) => {
2746
+ e.onResult?.(n, s), lr(n) ? e.onSuccess?.(n, s) : e.onError?.(n, s);
2747
+ })), e.onEvent) for (let t of l) c.push(s.on(t, (n) => {
2482
2748
  e.onEvent?.({
2483
2749
  name: t,
2484
2750
  payload: n
2485
- }, c);
2751
+ }, s);
2486
2752
  }));
2487
- n.set(s, {
2488
- instance: c,
2489
- unsubs: l
2490
- }), i.push(c);
2753
+ n.set(o, {
2754
+ instance: s,
2755
+ unsubs: c
2756
+ }), i.push(s);
2491
2757
  }
2492
2758
  return i;
2493
2759
  }
2494
- async function br(e) {
2495
- let t = e.client ?? sr(), n = /* @__PURE__ */ new Map(), r = await gr(e.element);
2496
- if (r.length === 0 && !e.allowEmpty) throw Error(`Formie could not find any elements for ${fr(e.element)}.`);
2497
- await yr(e, t, n, r);
2498
- let i = e.observe ? t.observe(_r(e.element)) : null;
2760
+ async function _r(e) {
2761
+ let t = e.client ?? or(), n = /* @__PURE__ */ new Map(), r = await pr(e.element);
2762
+ if (r.length === 0 && !e.allowEmpty) throw Error(`Formie could not find any elements for ${ur(e.element)}.`);
2763
+ await gr(e, t, n, r);
2764
+ let i = e.observe ? t.observe(mr(e.element)) : null;
2499
2765
  return {
2500
2766
  client: t,
2501
2767
  get instances() {
@@ -2506,8 +2772,8 @@ async function br(e) {
2506
2772
  return r ? n.get(r)?.instance ?? t.getInstance(r) : null;
2507
2773
  },
2508
2774
  async rescan() {
2509
- let r = mr(e.element);
2510
- return r.length === 0 ? Array.from(n.values()).map(({ instance: e }) => e) : yr(e, t, n, r);
2775
+ let r = $(e.element);
2776
+ return r.length === 0 ? Array.from(n.values()).map(({ instance: e }) => e) : gr(e, t, n, r);
2511
2777
  },
2512
2778
  async destroy() {
2513
2779
  i?.();
@@ -2517,4 +2783,102 @@ async function br(e) {
2517
2783
  };
2518
2784
  }
2519
2785
  //#endregion
2520
- export { a as FORMIE_HTML_EVENT_NAMES, mt as FormieValidator, ge as LEGACY_FORMIE_DOM_EVENT_BRIDGES, _e as LEGACY_FORMIE_VALIDATOR_EVENT_BRIDGES, L as ModuleRegistry, Ce as bindLegacyDomEventCompatibility, we as bindLegacyValidatorCompatibility, pe as buildFieldValueRegistry, S as createDebug, sr as createFormieClient, ee as debugLog, te as debugWarn, he as defineAddressModule, se as defineCaptchaModule, oe as definePassiveCaptchaModule, v as definePaymentModule, ue as fieldKeyToInputName, br as formie, i as getFieldModuleEventName, ae as getFormieTranslations, r as getGlobalModuleLifecycleEventName, e as getScopedModuleLifecycleEventName, lr as hydrateFormieModules, ce as inputNameToFieldKey, x as isFormieDebugEnabled, re as mergeFormieTranslations, le as normalizeFieldKey, o as normalizeFormieEventName, de as parseFieldReference, me as resolveFieldReferenceFromFormData, fe as resolveFieldReferenceLive, ve as resolveLegacyCompatibilityOptions, b as setFormieDebugEnabled, ie as setFormieTranslations, D as t, t as toDomEventName, E as translate };
2786
+ //#region src/js/core/client-rendered-modules.ts
2787
+ var vr = {
2788
+ conditions: {
2789
+ kind: "core",
2790
+ reason: "Core evaluates structured conditions and the adapter renders visibility."
2791
+ },
2792
+ repeater: {
2793
+ kind: "field",
2794
+ reason: "The adapter owns row markup and core owns row values."
2795
+ },
2796
+ signature: {
2797
+ kind: "field",
2798
+ reason: "The adapter owns its signature control and cleanup."
2799
+ },
2800
+ "file-upload": {
2801
+ kind: "field",
2802
+ reason: "The shared transport stages selected files and submits attachment capabilities."
2803
+ },
2804
+ "upload-manager": {
2805
+ kind: "field",
2806
+ reason: "Native file selection uses the shared staged upload transport."
2807
+ },
2808
+ "checkbox-radio": {
2809
+ kind: "field",
2810
+ reason: "Framework controls own checked state."
2811
+ },
2812
+ "text-limit": {
2813
+ kind: "field",
2814
+ reason: "Core validation enforces the structured minimum and maximum rules."
2815
+ },
2816
+ "date-picker": {
2817
+ kind: "field",
2818
+ reason: "The adapter renders the structured date input contract."
2819
+ }
2820
+ };
2821
+ async function yr(t, n, r = Bt) {
2822
+ for (let [e, t] of Object.entries(vr)) {
2823
+ let n = `formie:${e}`;
2824
+ r.get(n) || r.register({
2825
+ moduleId: n,
2826
+ version: 2,
2827
+ surfaces: ["client-rendered"],
2828
+ kind: t.kind,
2829
+ match: () => !0,
2830
+ setup: async (e) => (await e.emit("formie:browser:module:delegated", {
2831
+ moduleId: n,
2832
+ reason: t.reason,
2833
+ target: e.target
2834
+ }), { destroy: () => void 0 })
2835
+ });
2836
+ }
2837
+ let i = t instanceof HTMLFormElement ? t : t.querySelector("form"), a = () => {
2838
+ if (!i) return;
2839
+ let t = n.getState();
2840
+ e(i, n.getBrowserRequestOptions()), i.action = t.definition.submission.endpoint, t.session.tokens.csrf && i.setAttribute("data-formie-csrf-param", t.session.tokens.csrf.name);
2841
+ for (let [e, n] of Object.entries({
2842
+ handle: t.definition.handle,
2843
+ ...t.session.tokens.csrf ? { [t.session.tokens.csrf.name]: t.session.tokens.csrf.value } : {}
2844
+ })) {
2845
+ let t = i.querySelector(`input[type="hidden"][name="${CSS.escape(e)}"]`);
2846
+ t || (t = document.createElement("input"), t.type = "hidden", t.name = e, i.append(t)), t.value = n;
2847
+ }
2848
+ };
2849
+ a();
2850
+ let o = n.subscribe(a), s = await cr({
2851
+ root: t,
2852
+ modules: n.getState().definition.modules,
2853
+ surface: "client-rendered",
2854
+ registry: r
2855
+ });
2856
+ n.setBrowserModuleGuard(s.assertReady), n.setBrowserModulePreparation(s.prepare);
2857
+ let c = n.on("formie:submit:result", (e) => {
2858
+ let t = e, r = t.completion;
2859
+ t.success && r && (r.behavior === "redirect" && typeof r.url == "string" ? r.target === "new-tab" ? window.open(r.url, "_blank", "noopener,noreferrer") : window.location.assign(r.url) : r.behavior === "reload" ? window.location.reload() : r.behavior === "reset" && n.reset()), s.result({
2860
+ ok: t.success,
2861
+ outcome: t.outcome,
2862
+ version: t.version,
2863
+ submissionUid: t.submissionUid,
2864
+ errors: t.errors,
2865
+ session: t.session,
2866
+ completion: t.completion,
2867
+ meta: t
2868
+ });
2869
+ });
2870
+ return {
2871
+ ...s,
2872
+ get instances() {
2873
+ return s.instances;
2874
+ },
2875
+ get failures() {
2876
+ return s.failures;
2877
+ },
2878
+ destroy: async () => {
2879
+ c(), o(), await s.destroy();
2880
+ }
2881
+ };
2882
+ }
2883
+ //#endregion
2884
+ export { l as FORMIE_HTML_EVENT_NAMES, pn as FormieValidator, Se as LEGACY_FORMIE_DOM_EVENT_BRIDGES, Ce as LEGACY_FORMIE_VALIDATOR_EVENT_BRIDGES, B as ModuleRegistry, ke as bindLegacyDomEventCompatibility, je as bindLegacyValidatorCompatibility, ye as buildFieldValueRegistry, Bt as clientRenderedModuleRegistry, E as createDebug, or as createFormieClient, w as debugLog, T as debugWarn, xe as defineAddressModule, pe as defineCaptchaModule, fe as definePassiveCaptchaModule, S as definePaymentModule, ge as fieldKeyToInputName, _r as formie, c as getFieldModuleEventName, de as getFormieTranslations, s as getGlobalModuleLifecycleEventName, i as getScopedModuleLifecycleEventName, cr as hydrateFormieModules, me as inputNameToFieldKey, te as isFormieDebugEnabled, le as mergeFormieTranslations, yr as mountClientRenderedModules, he as normalizeFieldKey, u as normalizeFormieEventName, _e as parseFieldReference, be as resolveFieldReferenceFromFormData, ve as resolveFieldReferenceLive, we as resolveLegacyCompatibilityOptions, ee as setFormieDebugEnabled, ue as setFormieTranslations, ce as t, a as toDomEventName, se as translate };