@samline/forms 2.9.0 → 2.11.0

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.
@@ -240,12 +240,37 @@ var restoreCursor = (field, position) => {
240
240
  var state = null;
241
241
  var MISSING_MESSAGE = "[samline/forms] The `format()` and `formatAll()` methods require the @samline/formatter package. Install it with: npm i @samline/formatter (or pnpm/bun/yarn equivalent).";
242
242
  var warned = false;
243
+ var phonePromise = null;
244
+ var PHONE_MESSAGE = "[samline/forms] Phone formatting needs `@samline/formatter/phone` (@samline/formatter >= 3.0.0 makes phones opt-in) and it could not be loaded.";
243
245
  var warnOnce = () => {
244
246
  if (warned) return;
245
247
  warned = true;
246
248
  console.error(MISSING_MESSAGE);
247
249
  };
248
- var loadFormatter = () => {
250
+ var ensurePhone = (formatter) => {
251
+ if (typeof formatter.isPhoneRegistered !== "function") return Promise.resolve(true);
252
+ if (formatter.isPhoneRegistered()) return Promise.resolve(true);
253
+ if (!phonePromise) {
254
+ phonePromise = (async () => {
255
+ try {
256
+ const mod = await import("@samline/formatter/phone");
257
+ mod.registerPhone();
258
+ return true;
259
+ } catch {
260
+ console.error(PHONE_MESSAGE);
261
+ phonePromise = null;
262
+ return false;
263
+ }
264
+ })();
265
+ }
266
+ return phonePromise;
267
+ };
268
+ var loadFormatter = async (options = {}) => {
269
+ const formatter = await loadFormatterModule();
270
+ if (!formatter || !options.phone) return formatter;
271
+ return await ensurePhone(formatter) ? formatter : null;
272
+ };
273
+ var loadFormatterModule = () => {
249
274
  if (state && state.status === "resolved") {
250
275
  if (!state.module) warnOnce();
251
276
  return Promise.resolve(state.module);
@@ -380,7 +405,7 @@ var applyFormat = async (state2, helpers, config) => {
380
405
  phase1Entries.push(entry);
381
406
  }
382
407
  }
383
- const formatter = await loadFormatter();
408
+ const formatter = await loadFormatter({ phone: formatType === "phone" });
384
409
  if (state2.isDestroyed) {
385
410
  rollbackPhase1(phase1Entries, bucket, state2.formattedFields);
386
411
  return;
@@ -1482,6 +1507,10 @@ var createFormController = (target, options = {}) => {
1482
1507
  };
1483
1508
  const handleSubmitEvent = (event) => {
1484
1509
  if (!state2.element || state2.isDestroyed || !state2.api) return;
1510
+ if (!state2.isAutoSubmitting && state2.autoSubmitTimer) {
1511
+ clearTimeout(state2.autoSubmitTimer);
1512
+ state2.autoSubmitTimer = null;
1513
+ }
1485
1514
  if (normalizedOptions.clearErrorsOnSubmit) state2.manualErrors = {};
1486
1515
  const validation = state2.api.validate();
1487
1516
  const handlers = Array.from(state2.submitHandlers);