@verbb/formie-browser 1.0.14 → 1.0.16

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 (156) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/chunks/{address-country-Dn71jroa.js → address-country-DLJF-OkC.js} +5 -9
  3. package/dist/chunks/{address-finder-O49uDRoR.js → address-finder-QK1m1eyv.js} +2 -2
  4. package/dist/chunks/{address-state-ByYatUur.js → address-state-CHKit8AW.js} +113 -112
  5. package/dist/chunks/{api-DYYsVIub.js → api-BPtH5RBA.js} +162 -130
  6. package/dist/chunks/{api-D6kJ7kXZ.js → api-BR2Gqy37.js} +313 -303
  7. package/dist/chunks/{api-ghNr2uxX.js → api-CmuOZ0i3.js} +1 -1
  8. package/dist/chunks/{async-nPFRNQ06.js → async-2GdXNFCE.js} +18 -1
  9. package/dist/chunks/{bpoint-D0RKFM4F.js → bpoint-GvYfyPjD.js} +1 -1
  10. package/dist/chunks/{calculations-YEoVCG2q.js → calculations-DeEmdUDq.js} +5 -7
  11. package/dist/chunks/{captcha-eu-DERJbXnH.js → captcha-eu-eU_M6snp.js} +2 -2
  12. package/dist/chunks/{checkbox-radio-gsm8QPJg.js → checkbox-radio-CSXo6svm.js} +4 -12
  13. package/dist/chunks/{combobox-CWNdx4Fk.js → combobox-CJh2DoSO.js} +323 -363
  14. package/dist/chunks/{conditions-DqNHLTbN.js → conditions-Dz3068K0.js} +140 -153
  15. package/dist/chunks/{country-from-ip-DDj_mFki.js → country-from-ip-BqQ-BqLH.js} +1 -1
  16. package/dist/chunks/{custom-google-maps-C4l2S3GO.js → custom-google-maps-rNm5VFbb.js} +2 -6
  17. package/dist/chunks/{custom-link-CLazgKYH.js → custom-link-CLqFCssQ.js} +1 -1
  18. package/dist/chunks/{custom-maps-DqcAlD0v.js → custom-maps-DgjYQDLj.js} +4 -8
  19. package/dist/chunks/{date-picker-RUnevF7l.js → date-picker-BVJxJVYT.js} +42 -58
  20. package/dist/chunks/{debug-BV0DvdHx.js → debug-rhzqP1j2.js} +2 -14
  21. package/dist/chunks/{dist-ZLeW0zZ3.js → dist-CJReDlDK.js} +13 -8
  22. package/dist/chunks/{eway-or6dtjoT.js → eway-BZuTBAUW.js} +3 -3
  23. package/dist/chunks/{field-references.resolver-Ca8MguFv.js → field-references.resolver-uSHf5-NP.js} +1 -1
  24. package/dist/chunks/{file-upload-Bm-TXyNB.js → file-upload-vEUr_EuP.js} +131 -113
  25. package/dist/chunks/{friendly-captcha-v1-GFqCt1Mh.js → friendly-captcha-v1-C_cF1WD2.js} +2 -2
  26. package/dist/chunks/{friendly-captcha-v2-WoW246JG.js → friendly-captcha-v2-BenESH-n.js} +2 -2
  27. package/dist/chunks/{friendly-challenge-DPG9MJb1.js → friendly-challenge-BgPBEMXx.js} +21 -35
  28. package/dist/chunks/{go-cardless-DzJ-0FKg.js → go-cardless-DWZeB0Bq.js} +2 -6
  29. package/dist/chunks/{google-address-C1P1nTDM.js → google-address-DQR6rsbh.js} +15 -10
  30. package/dist/chunks/{hcaptcha-D0T8aIHz.js → hcaptcha-COilLmRT.js} +2 -2
  31. package/dist/chunks/{hidden-BZhXnNPe.js → hidden-Bc2TpcgF.js} +1 -1
  32. package/dist/chunks/{http-C2QdHuWO.js → http-Dj_skqaa.js} +1 -1
  33. package/dist/chunks/{leaflet-src-DE6rv6M-.js → leaflet-src-Cg-LUOD8.js} +74 -122
  34. package/dist/chunks/{loqate-DD1S7PY9.js → loqate-ZZClcacr.js} +2 -2
  35. package/dist/chunks/{mollie-DG8Ju83x.js → mollie-8OMXIYa8.js} +2 -6
  36. package/dist/chunks/{moneris-C8m3Fvqu.js → moneris-qYHJ9EFy.js} +1 -1
  37. package/dist/chunks/opayo-DlWPEnla.js +159 -0
  38. package/dist/chunks/{paddle-BIYR9Um3.js → paddle-CArfWih0.js} +2 -2
  39. package/dist/chunks/{password-validation-C8_uO_c_.js → password-validation-HGOU9kf3.js} +2 -2
  40. package/dist/chunks/{paypal-B_yxIo2d.js → paypal-BcaMCMGY.js} +2 -2
  41. package/dist/chunks/{payway-CeOzS0sL.js → payway-vxC7_bfR.js} +4 -12
  42. package/dist/chunks/{phone-country-bAqje17P.js → phone-country-Bx9EG50h.js} +124 -141
  43. package/dist/chunks/{place-kit-BE5gi3vo.js → place-kit-BKk8xDXf.js} +10 -10
  44. package/dist/chunks/{placekit-autocomplete.esm-CZZERYur.js → placekit-autocomplete.esm-D2A_0iVU.js} +2 -5
  45. package/dist/chunks/{recaptcha-enterprise-CruXddZq.js → recaptcha-enterprise-Cx6HUpMa.js} +6 -12
  46. package/dist/chunks/recaptcha-shared-CcMI-r8t.js +33 -0
  47. package/dist/chunks/{recaptcha-v2-checkbox-CCnJYCnG.js → recaptcha-v2-checkbox-DQ9BJzcv.js} +2 -2
  48. package/dist/chunks/{recaptcha-v2-invisible-BuVqRRYn.js → recaptcha-v2-invisible-BP0T8Pan.js} +2 -2
  49. package/dist/chunks/recaptcha-v3-DKMGQ27K.js +38 -0
  50. package/dist/chunks/{repeater-DwE27jI1.js → repeater-BR0RUvTs.js} +50 -40
  51. package/dist/chunks/{rich-text-uV4o_pGk.js → rich-text-H2A6cm1t.js} +33 -11
  52. package/dist/chunks/{rolldown-runtime-DtPi1Y-2.js → rolldown-runtime-VHNaYcLd.js} +1 -1
  53. package/dist/chunks/{scripts-CbQ7agX3.js → scripts-DrccjrFv.js} +1 -1
  54. package/dist/chunks/{sdk-lkwSvlpM.js → sdk-_cmrRYgp.js} +4 -16
  55. package/dist/chunks/{shared-OKhSay59.js → shared-CJ1LIEh3.js} +1 -3
  56. package/dist/chunks/{signature-7cldFbqj.js → signature-CfKA_poI.js} +9 -41
  57. package/dist/chunks/skip-CEW89ExY.js +7 -0
  58. package/dist/chunks/{snaptcha-C04kNGYQ.js → snaptcha-P3EoSQud.js} +1 -1
  59. package/dist/chunks/{square-DEzxv9D9.js → square-Dyz0p_GU.js} +2 -2
  60. package/dist/chunks/{stripe-CVPQGDz3.js → stripe-Bfd_jp_k.js} +4 -7
  61. package/dist/chunks/{summary-BF_8mrXI.js → summary-B3CAebLV.js} +45 -37
  62. package/dist/chunks/{survey-likert-fk1hUPff.js → survey-likert-CEtUceag.js} +1 -1
  63. package/dist/chunks/{survey-rank-BsLGl2LX.js → survey-rank-Dtt97y6s.js} +3 -7
  64. package/dist/chunks/{survey-rating-DVS6e6fM.js → survey-rating-mlDMI0uq.js} +9 -23
  65. package/dist/chunks/{table-DnIBdeKF.js → table-0k6Md0IO.js} +2 -2
  66. package/dist/chunks/{text-limit-LGMPhFuC.js → text-limit-CTVML6s7.js} +10 -10
  67. package/dist/chunks/{turnstile-n9DNyPxi.js → turnstile-Sp4ubowK.js} +2 -2
  68. package/dist/chunks/{upload-manager-BbiUosZq.js → upload-manager-Ccg3d_4I.js} +258 -260
  69. package/dist/index.d.ts +1 -0
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +743 -734
  72. package/dist/js/core/create-formie-client.d.ts.map +1 -1
  73. package/dist/js/core/dom-events.d.ts +5 -0
  74. package/dist/js/core/dom-events.d.ts.map +1 -1
  75. package/dist/js/core/page-client-event.d.ts.map +1 -1
  76. package/dist/js/core/submit-result-state.d.ts.map +1 -1
  77. package/dist/js/core/submit-result-ui.d.ts +3 -1
  78. package/dist/js/core/submit-result-ui.d.ts.map +1 -1
  79. package/dist/js/core/validation-focus.d.ts.map +1 -1
  80. package/dist/js/modules/address/google-address.d.ts +10 -0
  81. package/dist/js/modules/address/google-address.d.ts.map +1 -1
  82. package/dist/js/modules/address/place-kit.d.ts.map +1 -1
  83. package/dist/js/modules/captchas/factories.d.ts.map +1 -1
  84. package/dist/js/modules/captchas/host.d.ts +4 -1
  85. package/dist/js/modules/captchas/host.d.ts.map +1 -1
  86. package/dist/js/modules/captchas/recaptcha-shared.d.ts +1 -1
  87. package/dist/js/modules/captchas/recaptcha-shared.d.ts.map +1 -1
  88. package/dist/js/modules/captchas/recaptcha-v3.d.ts.map +1 -1
  89. package/dist/js/modules/fields/address-state.d.ts.map +1 -1
  90. package/dist/js/modules/fields/combobox.d.ts +2 -0
  91. package/dist/js/modules/fields/combobox.d.ts.map +1 -1
  92. package/dist/js/modules/fields/conditions/effects.d.ts.map +1 -1
  93. package/dist/js/modules/fields/conditions.d.ts.map +1 -1
  94. package/dist/js/modules/fields/date-picker.d.ts.map +1 -1
  95. package/dist/js/modules/fields/file-upload.d.ts.map +1 -1
  96. package/dist/js/modules/fields/phone-country.d.ts.map +1 -1
  97. package/dist/js/modules/fields/repeater.d.ts.map +1 -1
  98. package/dist/js/modules/fields/rich-text.d.ts.map +1 -1
  99. package/dist/js/modules/fields/summary.d.ts.map +1 -1
  100. package/dist/js/modules/fields/text-limit.d.ts.map +1 -1
  101. package/dist/js/modules/fields/upload-manager.d.ts.map +1 -1
  102. package/dist/js/modules/payments/factories.d.ts.map +1 -1
  103. package/dist/js/modules/payments/opayo.d.ts.map +1 -1
  104. package/dist/js/submit/pipeline.d.ts +2 -0
  105. package/dist/js/submit/pipeline.d.ts.map +1 -1
  106. package/dist/js/utils/async.d.ts +1 -0
  107. package/dist/js/utils/async.d.ts.map +1 -1
  108. package/dist/js/utils/form-started-at.d.ts +1 -0
  109. package/dist/js/utils/form-started-at.d.ts.map +1 -1
  110. package/dist/js/utils/unload-warning.d.ts +4 -0
  111. package/dist/js/utils/unload-warning.d.ts.map +1 -1
  112. package/dist/js/validation/rules/required.d.ts.map +1 -1
  113. package/dist/js/validation/submit-readiness.d.ts.map +1 -1
  114. package/dist/js/validation/validator.d.ts +1 -0
  115. package/dist/js/validation/validator.d.ts.map +1 -1
  116. package/package.json +3 -3
  117. package/src/index.ts +1 -0
  118. package/src/js/core/create-formie-client.ts +37 -28
  119. package/src/js/core/dom-events.ts +30 -1
  120. package/src/js/core/page-client-event.ts +5 -7
  121. package/src/js/core/submit-result-state.ts +30 -2
  122. package/src/js/core/submit-result-ui.ts +25 -3
  123. package/src/js/core/validation-focus.ts +17 -3
  124. package/src/js/modules/address/google-address.ts +95 -37
  125. package/src/js/modules/address/place-kit.ts +13 -7
  126. package/src/js/modules/captchas/factories.ts +241 -101
  127. package/src/js/modules/captchas/host.ts +16 -0
  128. package/src/js/modules/captchas/recaptcha-enterprise.ts +1 -1
  129. package/src/js/modules/captchas/recaptcha-shared.ts +23 -5
  130. package/src/js/modules/captchas/recaptcha-v3.ts +23 -14
  131. package/src/js/modules/fields/address-country.ts +5 -5
  132. package/src/js/modules/fields/address-state.ts +80 -27
  133. package/src/js/modules/fields/combobox.ts +22 -1
  134. package/src/js/modules/fields/conditions/effects.ts +4 -5
  135. package/src/js/modules/fields/conditions.ts +9 -0
  136. package/src/js/modules/fields/date-picker.ts +6 -3
  137. package/src/js/modules/fields/file-upload.ts +55 -18
  138. package/src/js/modules/fields/phone-country.ts +25 -2
  139. package/src/js/modules/fields/repeater.ts +55 -4
  140. package/src/js/modules/fields/rich-text.ts +33 -0
  141. package/src/js/modules/fields/summary.ts +63 -10
  142. package/src/js/modules/fields/text-limit.ts +11 -0
  143. package/src/js/modules/fields/upload-manager.ts +54 -18
  144. package/src/js/modules/payments/factories.ts +87 -54
  145. package/src/js/modules/payments/opayo.ts +7 -0
  146. package/src/js/submit/pipeline.ts +16 -9
  147. package/src/js/utils/async.ts +34 -0
  148. package/src/js/utils/form-started-at.ts +19 -4
  149. package/src/js/utils/unload-warning.ts +63 -7
  150. package/src/js/validation/rules/required.ts +18 -0
  151. package/src/js/validation/submit-readiness.ts +2 -0
  152. package/src/js/validation/validator.ts +29 -6
  153. package/src/vendor.d.ts +2 -0
  154. package/dist/chunks/opayo-B3EvrVxw.js +0 -188
  155. package/dist/chunks/recaptcha-shared-AQRMDMme.js +0 -27
  156. package/dist/chunks/recaptcha-v3-CloqhO2A.js +0 -28
@@ -1,8 +1,8 @@
1
1
  import { a as e } from "./event-names-BCI2FLD8.js";
2
- import { t } from "./debug-BV0DvdHx.js";
2
+ import { t } from "./debug-rhzqP1j2.js";
3
3
  import { t as n } from "./theme-classes-DAQuEqdP.js";
4
- import { i as r } from "./i18n-BY1ds1BL.js";
5
- import { n as i, t as a } from "./async-nPFRNQ06.js";
4
+ import { n as r, t as i } from "./async-2GdXNFCE.js";
5
+ import { i as a } from "./i18n-BY1ds1BL.js";
6
6
  //#region src/js/modules/captchas/constants.ts
7
7
  var o = 2e3, s = 5e3, c = 5e3, l = 12e4;
8
8
  //#endregion
@@ -38,8 +38,8 @@ function m(e, t, { value: n = "", container: r } = {}) {
38
38
  }
39
39
  async function h(e, t, n) {
40
40
  if (f(e, t)) return !0;
41
- let r = Date.now() + Math.max(n, 0);
42
- for (; Date.now() < r;) if (await i(120), f(e, t)) return !0;
41
+ let i = Date.now() + Math.max(n, 0);
42
+ for (; Date.now() < i;) if (await r(120), f(e, t)) return !0;
43
43
  return !1;
44
44
  }
45
45
  //#endregion
@@ -98,17 +98,18 @@ function O(e, t) {
98
98
  return !n || typeof n != "object" ? null : n;
99
99
  }
100
100
  function k(e, t, n, r) {
101
- let i = /* @__PURE__ */ new Set(), o = () => {
102
- let a = x(e, t), o = new Set(a.filter((e) => S(e)));
103
- a.forEach((e) => {
104
- o.has(e) && !i.has(e) && (i.add(e), n(e));
105
- }), Array.from(i).forEach((e) => {
106
- o.has(e) || (i.delete(e), r(e));
101
+ let a = /* @__PURE__ */ new Set(), o = !0, s = () => {
102
+ if (!o) return;
103
+ let i = x(e, t), s = new Set(i.filter((e) => S(e)));
104
+ i.forEach((e) => {
105
+ s.has(e) && !a.has(e) && (a.add(e), n(e));
106
+ }), Array.from(a).forEach((e) => {
107
+ s.has(e) || (a.delete(e), r(e));
107
108
  });
108
- }, s = a(o, 20), c = new MutationObserver(() => {
109
- s();
109
+ }, c = i(s, 20), l = new MutationObserver(() => {
110
+ c();
110
111
  });
111
- c.observe(e, {
112
+ l.observe(e, {
112
113
  childList: !0,
113
114
  subtree: !0,
114
115
  attributes: !0,
@@ -120,33 +121,29 @@ function k(e, t, n, r) {
120
121
  "data-formie-page-hidden"
121
122
  ]
122
123
  });
123
- let l = [b(window, "resize", () => {
124
- s();
124
+ let u = [b(window, "resize", () => {
125
+ c();
125
126
  }), ...v.map((t) => b(e, t, () => {
126
- if (y.has(t)) {
127
- o();
128
- return;
129
- }
130
- s();
127
+ y.has(t) ? s() : c();
131
128
  }))];
132
- return o(), {
129
+ return s(), {
133
130
  cleanup: () => {
134
- c.disconnect(), l.forEach((e) => {
131
+ o && (o = !1, l.disconnect(), u.forEach((e) => {
135
132
  e();
136
- }), Array.from(i).forEach((e) => {
133
+ }), Array.from(a).forEach((e) => {
137
134
  r(e);
138
- }), i.clear();
135
+ }), a.clear());
139
136
  },
140
- reconcile: s,
141
- reconcileImmediate: o,
137
+ reconcile: c,
138
+ reconcileImmediate: s,
142
139
  getVisible: () => x(e, t).filter((e) => S(e))
143
140
  };
144
141
  }
145
142
  function A(e, t) {
146
143
  return (typeof t.handle == "string" && t.handle.trim() !== "" ? t.handle.trim() : "") || e;
147
144
  }
148
- function j(e, t, { defaultPlaceholderSelector: n, defaultTokenFieldNames: i = [], defaultWaitForValueMs: a = o }) {
149
- let s = t || {}, c = Object.entries(s).reduce((e, [t, n]) => (g.has(t) || (e[t] = n), e), {}), l = i.map(String).filter(Boolean), u = Number(a), d = typeof s.placeholderSelector == "string" && s.placeholderSelector.trim() !== "" ? s.placeholderSelector.trim() : n, f = typeof s.errorMessage == "string" && s.errorMessage.trim() !== "" ? s.errorMessage.trim() : r("Captcha challenge must be completed."), p = typeof s.sessionKey == "string" && s.sessionKey.trim() !== "" ? s.sessionKey.trim() : null, m = typeof s.value == "string" ? s.value : null;
145
+ function j(e, t, { defaultPlaceholderSelector: n, defaultTokenFieldNames: r = [], defaultWaitForValueMs: i = o }) {
146
+ let s = t || {}, c = Object.entries(s).reduce((e, [t, n]) => (g.has(t) || (e[t] = n), e), {}), l = r.map(String).filter(Boolean), u = Number(i), d = typeof s.placeholderSelector == "string" && s.placeholderSelector.trim() !== "" ? s.placeholderSelector.trim() : n, f = typeof s.errorMessage == "string" && s.errorMessage.trim() !== "" ? s.errorMessage.trim() : a("Captcha challenge must be completed."), p = typeof s.sessionKey == "string" && s.sessionKey.trim() !== "" ? s.sessionKey.trim() : null, m = typeof s.value == "string" ? s.value : null;
150
147
  return {
151
148
  handle: A(e, s),
152
149
  ui: {
@@ -155,22 +152,22 @@ function j(e, t, { defaultPlaceholderSelector: n, defaultTokenFieldNames: i = []
155
152
  },
156
153
  transport: {
157
154
  tokenFieldNames: l,
158
- waitForValueMs: Number.isFinite(u) ? u : a,
155
+ waitForValueMs: Number.isFinite(u) ? u : i,
159
156
  sessionKey: p,
160
157
  value: m
161
158
  },
162
159
  provider: c
163
160
  };
164
161
  }
165
- function M(e, t) {
166
- let n = e.form || e.root, r = t.ui.placeholderSelector, i = t.handle;
162
+ function M(e, t, n = {}) {
163
+ let r = e.form || e.root, i = t.ui.placeholderSelector, a = t.handle;
167
164
  return {
168
165
  form: e.form,
169
166
  root: e.root,
170
167
  placeholder: {
171
- query: () => x(e.root, r),
172
- getPrimary: () => C(e.root, r),
173
- observe: (t, n) => k(e.root, r, t, n),
168
+ query: () => x(e.root, i),
169
+ getPrimary: () => C(e.root, i),
170
+ observe: (t, n) => k(e.root, i, t, n),
174
171
  createContainer: (e) => w(e),
175
172
  clear: (e) => {
176
173
  e && (T(e), e.innerHTML = "");
@@ -178,35 +175,35 @@ function M(e, t) {
178
175
  },
179
176
  errors: {
180
177
  getDefaultMessage: () => t.ui.errorMessage,
181
- show: (n, i) => {
182
- E(i || C(e.root, r), n || t.ui.errorMessage, e.form || e.root);
178
+ show: (r, a) => {
179
+ n.isActive?.() !== !1 && E(a || C(e.root, i), r || t.ui.errorMessage, e.form || e.root);
183
180
  },
184
181
  clear: (t) => {
185
- T(t || C(e.root, r));
182
+ n.isActive?.() !== !1 && T(t || C(e.root, i));
186
183
  }
187
184
  },
188
185
  tokens: {
189
186
  names: t.transport.tokenFieldNames,
190
- has: (e = t.transport.tokenFieldNames, r = n) => f(r, e),
191
- read: (e = t.transport.tokenFieldNames[0], r = n) => e ? d(r, e) : "",
192
- write: (r, { names: i = t.transport.tokenFieldNames, root: a = n, container: o = e.form } = {}) => {
193
- i.forEach((e) => {
194
- m(a, e, {
195
- value: r,
196
- container: o
187
+ has: (e = t.transport.tokenFieldNames, n = r) => f(n, e),
188
+ read: (e = t.transport.tokenFieldNames[0], n = r) => e ? d(n, e) : "",
189
+ write: (i, { names: a = t.transport.tokenFieldNames, root: o = r, container: s = e.form } = {}) => {
190
+ n.isActive?.() !== !1 && (n.onTokenFieldNames?.(a), a.forEach((e) => {
191
+ m(o, e, {
192
+ value: i,
193
+ container: s
197
194
  });
198
- });
195
+ }));
199
196
  },
200
- clear: (e = t.transport.tokenFieldNames, r = n) => {
201
- p(r, e);
197
+ clear: (e = t.transport.tokenFieldNames, i = r) => {
198
+ n.isActive?.() !== !1 && p(i, e);
202
199
  },
203
- wait: (e = t.transport.waitForValueMs, r = t.transport.tokenFieldNames, i = n) => h(i, r, e)
200
+ wait: (e = t.transport.waitForValueMs, n = t.transport.tokenFieldNames, i = r) => h(i, n, e)
204
201
  },
205
202
  refresh: {
206
- providerHandle: i,
203
+ providerHandle: a,
207
204
  onTokensRefreshed: (t) => {
208
205
  let n = ["formie:refresh-tokens:after", "formie:refresh-tokens:refreshed"].map((n) => b(e.root, n, (e) => {
209
- let n = O(D(e), i);
206
+ let n = O(D(e), a);
210
207
  n && t(n);
211
208
  }));
212
209
  return () => {
@@ -249,22 +246,45 @@ function P({ moduleId: e, defaultPlaceholderSelector: t, defaultTokenFieldNames:
249
246
  if (!e) throw Error("The CAPTCHA needs a supported placeholder in the client-rendered form.");
250
247
  s = document.createElement("div"), s.setAttribute(e, ""), (a.form ?? a.root).append(s);
251
248
  }
252
- let c = M(a, o), l = await i({
253
- ...a,
254
- options: o,
255
- services: c
256
- });
257
- if (!l) {
258
- s?.remove();
259
- return;
260
- }
261
- let u = l.destroy;
262
- return {
263
- ...l,
264
- destroy: async () => {
265
- await u(), s?.remove();
266
- }
249
+ let c = new Set(o.transport.tokenFieldNames), l = !0, u = (e) => {
250
+ e.filter(Boolean).forEach((e) => c.add(e));
267
251
  };
252
+ u(o.transport.sessionKey ? [o.transport.sessionKey] : []);
253
+ let d = M(a, o, {
254
+ onTokenFieldNames: u,
255
+ isActive: () => l
256
+ }), f = d.events.onForm("formie:unload-warning:collect-exclusions", (e) => {
257
+ let t = e.detail;
258
+ t?.form === a.form && t.exclude(...c);
259
+ }), p = d.refresh.onTokensRefreshed((e) => {
260
+ typeof e.sessionKey == "string" && e.sessionKey.trim() !== "" && u([e.sessionKey.trim()]);
261
+ }), m = () => {
262
+ l = !1, f(), p(), s?.remove();
263
+ };
264
+ try {
265
+ let e = await i({
266
+ ...a,
267
+ options: o,
268
+ services: d
269
+ });
270
+ if (!e) {
271
+ m();
272
+ return;
273
+ }
274
+ let t = e.destroy;
275
+ return {
276
+ ...e,
277
+ destroy: async () => {
278
+ try {
279
+ await t();
280
+ } finally {
281
+ m();
282
+ }
283
+ }
284
+ };
285
+ } catch (e) {
286
+ throw m(), e;
287
+ }
268
288
  }
269
289
  };
270
290
  }
@@ -316,28 +336,38 @@ function I(t) {
316
336
  defaultPlaceholderSelector: t.defaultPlaceholderSelector,
317
337
  defaultTokenFieldNames: t.defaultTokenFieldNames,
318
338
  setup: async (n) => {
319
- let r = [], i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = n.services.placeholder.getPrimary(), s = !1, c, l = null, u = async () => (l ||= (N.log("Loading captcha provider API.", { moduleId: t.moduleId }), t.load(n)), l), d = async (e) => {
320
- let r = i.get(e);
321
- if (n.services.errors.clear(e), !r) {
322
- e.innerHTML = "";
323
- return;
324
- }
325
- let a = await u();
326
- t.unmount && await t.unmount({
327
- api: a,
328
- widget: r,
329
- placeholder: e,
330
- services: n.services,
331
- options: n.options,
332
- provider: n.options.provider
333
- }), i.delete(e), e.innerHTML = "", n.services.tokens.clear(), N.log("Unmounted captcha placeholder widget.", { moduleId: t.moduleId }), o === e && (o = n.services.placeholder.getPrimary());
334
- }, f = async (e) => {
335
- if (s || i.has(e)) return;
339
+ let r = [], i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = null, c = n.services.placeholder.getPrimary(), l = !1, u, d = null, f = async () => (d ||= (N.log("Loading captcha provider API.", { moduleId: t.moduleId }), t.load(n)), d), p = (e) => {
340
+ let r = o.get(e);
341
+ if (r) return r;
342
+ let s = (async () => {
343
+ await a.get(e)?.catch(() => {}), n.services.errors.clear(e);
344
+ let r = i.has(e), o = i.get(e);
345
+ i.delete(e);
346
+ try {
347
+ if (r && t.unmount) {
348
+ let r = await f();
349
+ await t.unmount({
350
+ api: r,
351
+ widget: o,
352
+ placeholder: e,
353
+ services: n.services,
354
+ options: n.options,
355
+ provider: n.options.provider
356
+ });
357
+ }
358
+ } finally {
359
+ e.innerHTML = "", n.services.tokens.clear(), c === e && (c = n.services.placeholder.getPrimary());
360
+ }
361
+ })().finally(() => o.delete(e));
362
+ return o.set(e, s), s;
363
+ }, m = async (e) => {
364
+ let r = o.get(e);
365
+ if (r && await r, l || i.has(e)) return;
336
366
  if (a.has(e)) return a.get(e);
337
- let r = (async () => {
338
- let r = await u();
339
- if (s || i.has(e)) return;
340
- let a = n.services.placeholder.createContainer(e), c = await t.mount({
367
+ let s = (async () => {
368
+ let r = await f();
369
+ if (l || i.has(e)) return;
370
+ let a = n.services.placeholder.createContainer(e), o = await t.mount({
341
371
  api: r,
342
372
  placeholder: e,
343
373
  container: a,
@@ -345,30 +375,29 @@ function I(t) {
345
375
  options: n.options,
346
376
  provider: n.options.provider
347
377
  });
348
- i.set(e, c), o = e, N.log("Mounted captcha placeholder widget.", { moduleId: t.moduleId });
378
+ i.set(e, o), c = e, N.log("Mounted captcha placeholder widget.", { moduleId: t.moduleId });
349
379
  })().finally(() => {
350
380
  a.delete(e);
351
381
  });
352
- a.set(e, r), await r;
353
- }, p = n.services.placeholder.observe((e) => {
354
- o = e, f(e).catch((e) => {
355
- c = e;
382
+ a.set(e, s), await s;
383
+ }, h = n.services.placeholder.observe((e) => {
384
+ c = e, m(e).catch((e) => {
385
+ u = e;
356
386
  });
357
387
  }, (e) => {
358
- d(e);
388
+ l || p(e).catch((e) => {
389
+ u = e;
390
+ });
359
391
  });
360
- r.push(p.cleanup);
361
- let m = async (e) => {
362
- let r = p.getVisible();
392
+ r.push(h.cleanup);
393
+ let g = async (e) => {
394
+ if (l) return;
395
+ let r = h.getVisible();
363
396
  if (t.reset) {
364
- let a = await u();
397
+ let a = await f();
365
398
  for (let o of r) {
366
399
  let r = i.get(o);
367
- if (!r) {
368
- await f(o);
369
- continue;
370
- }
371
- await t.reset({
400
+ i.has(o) ? (await t.reset({
372
401
  api: a,
373
402
  widget: r,
374
403
  placeholder: o,
@@ -376,55 +405,58 @@ function I(t) {
376
405
  options: n.options,
377
406
  provider: n.options.provider,
378
407
  reason: e
379
- }), n.services.tokens.clear(), n.services.errors.clear(o);
408
+ }), n.services.tokens.clear(), n.services.errors.clear(o)) : await m(o);
380
409
  }
381
- p.reconcile();
382
- return;
410
+ h.reconcile();
411
+ } else {
412
+ for (let e of Array.from(i.keys())) await p(e);
413
+ for (let e of r) await m(e);
414
+ h.reconcile();
383
415
  }
384
- for (let e of Array.from(i.keys())) await d(e);
385
- for (let e of r) await f(e);
386
- p.reconcile();
387
416
  };
388
417
  r.push(n.services.events.onRoot("formie:submit:result", (e) => {
389
418
  let t = e instanceof CustomEvent ? e.detail : null;
390
- t?.stage !== "validate" && (t?.ok !== !1 || t?.stage !== "challenge") && t?.ok !== !0 && m("submit-result");
419
+ t?.stage !== "validate" && (t?.ok !== !1 || t?.stage !== "challenge") && t?.ok !== !0 && g("submit-result");
391
420
  })), n.form && r.push(n.services.events.onForm(e("reset"), () => {
392
- o = n.services.placeholder.getPrimary() || o, window.setTimeout(() => {
393
- m("reset-state");
421
+ c = n.services.placeholder.getPrimary() || c, window.setTimeout(() => {
422
+ g("reset-state");
394
423
  }, 0);
395
- })), p.reconcileImmediate();
424
+ }));
425
+ let _ = () => s || (l = !0, s = (async () => {
426
+ r.forEach((e) => e()), await Promise.allSettled([...a.values()]);
427
+ let e = (await Promise.allSettled(/* @__PURE__ */ new Set([...o.values(), ...Array.from(i.keys(), p)]))).flatMap((e) => e.status === "rejected" ? [e.reason] : []);
428
+ if (e.length) throw AggregateError(e, "CAPTCHA widgets could not clean up.");
429
+ })(), s);
430
+ h.reconcileImmediate();
396
431
  try {
397
- if (await Promise.all([...a.values()]), c) throw c;
432
+ if (await Promise.all([...a.values()]), u) throw u;
398
433
  } catch (e) {
399
- throw s = !0, r.forEach((e) => e()), e;
434
+ throw await _().catch((e) => {
435
+ N.warn("Captcha cleanup after failed setup.", { error: e });
436
+ }), e;
400
437
  }
401
438
  return {
402
439
  assertReady: () => {
403
- if (c) throw c;
404
- },
405
- destroy: async () => {
406
- s = !0, r.forEach((e) => {
407
- e();
408
- });
409
- for (let e of Array.from(i.keys())) await d(e);
440
+ if (u) throw u;
410
441
  },
442
+ destroy: _,
411
443
  beforeSubmit: async (e) => {
412
444
  if (e.action !== "submit") return;
413
- p.reconcileImmediate();
414
- let r = p.getVisible();
445
+ h.reconcileImmediate();
446
+ let r = h.getVisible();
415
447
  if (r.length === 0) return;
416
- let a = r.find((e) => e === o) || r[0];
417
- await f(a), a = o || a, n.services.errors.clear(a);
418
- let s = i.get(a);
419
- if (!s) {
448
+ let a = r.find((e) => e === c) || r[0];
449
+ await m(a), a = c || a, n.services.errors.clear(a);
450
+ let o = i.get(a);
451
+ if (!i.has(a)) {
420
452
  let r = n.services.errors.getDefaultMessage();
421
453
  n.services.errors.show(r, a), N.warn("Captcha widget unavailable at challenge stage.", { moduleId: t.moduleId }), e.abort(r);
422
454
  return;
423
455
  }
424
- let c = await u();
456
+ let s = await f();
425
457
  await t.challenge({
426
- api: c,
427
- widget: s,
458
+ api: s,
459
+ widget: o,
428
460
  placeholder: a,
429
461
  services: n.services,
430
462
  options: n.options,