@stonecrop/aform 0.62.5 → 0.62.7

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.
package/dist/aform.js CHANGED
@@ -532,7 +532,17 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
532
532
  });
533
533
  watch(() => dropdown.open, (open) => emit("update:open", open));
534
534
  const linkResults = ref([]);
535
- const optionCount = () => linkPicker.value ? linkResults.value.length : dropdown.results.length;
535
+ const optionCount = () => {
536
+ if (dropdown.loading) return 0;
537
+ return linkPicker.value ? linkResults.value.length : dropdown.results.length;
538
+ };
539
+ let latestSearch = 0;
540
+ const startSearch = () => ++latestSearch;
541
+ const isLatestSearch = (searchId) => searchId === latestSearch;
542
+ const cancelSearch = () => {
543
+ latestSearch++;
544
+ dropdown.loading = false;
545
+ };
536
546
  const committedValue = ref(modelValue.value ?? "");
537
547
  const linkText = (value) => {
538
548
  const record = asLinkValue(value);
@@ -599,15 +609,17 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
599
609
  if (!__props.linkFilterFunction || __props.mode === "read") return;
600
610
  dropdown.activeItemIndex = null;
601
611
  dropdown.open = true;
612
+ const searchId = startSearch();
602
613
  if (__props.isAsync) dropdown.loading = true;
614
+ let results;
603
615
  try {
604
- const fn = typeof __props.linkFilterFunction === "string" ? deserializeFunction(__props.linkFilterFunction) : __props.linkFilterFunction;
605
- linkResults.value = await fn(text) ?? [];
616
+ results = await (typeof __props.linkFilterFunction === "string" ? deserializeFunction(__props.linkFilterFunction) : __props.linkFilterFunction)(text) ?? [];
606
617
  } catch {
607
- linkResults.value = [];
608
- } finally {
609
- dropdown.loading = false;
618
+ results = [];
610
619
  }
620
+ if (!isLatestSearch(searchId)) return;
621
+ linkResults.value = results;
622
+ dropdown.loading = false;
611
623
  };
612
624
  const embeddedLinkFilterQuery = () => {
613
625
  if (!__props.embedded || !linkPicker.value) return search.value;
@@ -624,17 +636,22 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
624
636
  const filter = async () => {
625
637
  dropdown.open = true;
626
638
  dropdown.activeItemIndex = null;
639
+ const searchId = startSearch();
627
640
  if (__props.filterFunction) {
628
641
  if (__props.isAsync) dropdown.loading = true;
642
+ let results;
629
643
  try {
630
- const filteredResults = await __props.filterFunction(search.value || "");
631
- dropdown.results = filteredResults || [];
644
+ results = await __props.filterFunction(search.value || "") || [];
632
645
  } catch {
633
- dropdown.results = [];
634
- } finally {
635
- if (__props.isAsync) dropdown.loading = false;
646
+ results = [];
636
647
  }
637
- } else filterResults();
648
+ if (!isLatestSearch(searchId)) return;
649
+ dropdown.results = results;
650
+ dropdown.loading = false;
651
+ } else {
652
+ dropdown.loading = false;
653
+ filterResults();
654
+ }
638
655
  };
639
656
  const setChoiceResult = (result) => {
640
657
  modelValue.value = result;
@@ -643,6 +660,7 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
643
660
  closeDropdown(result);
644
661
  };
645
662
  const selectLinkOption = (option) => {
663
+ cancelSearch();
646
664
  linkModel.value = option;
647
665
  search.value = linkText(option);
648
666
  dropdown.open = false;
@@ -655,6 +673,7 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
655
673
  dropdown.results = __props.isAsync ? [] : choiceList.value;
656
674
  };
657
675
  const closeDropdown = (result) => {
676
+ cancelSearch();
658
677
  dropdown.activeItemIndex = null;
659
678
  dropdown.open = false;
660
679
  if (linkPicker.value) {
@@ -738,6 +757,7 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
738
757
  ensureDropdownOpen();
739
758
  return;
740
759
  }
760
+ if (dropdown.loading) return;
741
761
  if (linkPicker.value) {
742
762
  if (dropdown.activeItemIndex !== null && linkResults.value[dropdown.activeItemIndex]) selectLinkOption(linkResults.value[dropdown.activeItemIndex]);
743
763
  return;
@@ -863,7 +883,7 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
863
883
  }, toDisplayString(errorText.value), 9, _hoisted_11$5)), [[vShow, errorText.value]]) : createCommentVNode("", true)], 64))], 2);
864
884
  };
865
885
  }
866
- }), [["__scopeId", "data-v-486dd9d1"]]);
886
+ }), [["__scopeId", "data-v-31db14b6"]]);
867
887
  // src/components/form/ACurrencyInput.vue?vue&type=script&setup=true&lang.ts
868
888
  var _hoisted_1$24 = { class: "aform_form-element acurrency" };
869
889
  var _hoisted_2$20 = { class: "aform_display-value" };