@winchsa/ui 0.1.63 → 0.1.64

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.
@@ -52,6 +52,7 @@ const emits = defineEmits(["update:model-value"]);
52
52
  const defaultOptions = ref(props.options ?? []);
53
53
  const displayedOptions = ref(props.options ?? []);
54
54
  const loadedValuesHaveBeenSet = ref(false);
55
+ const resolvingMissingValues = ref(false);
55
56
  const loading = ref(false);
56
57
  const showTeleport = ref(false);
57
58
  const search = ref("");
@@ -60,7 +61,7 @@ const errorState = ref(false);
60
61
  const isOpen = ref(false);
61
62
  const value = computed({
62
63
  get() {
63
- if (props.trackByValue && !loadedValuesHaveBeenSet.value) {
64
+ if (props.trackByValue && (!loadedValuesHaveBeenSet.value || resolvingMissingValues.value)) {
64
65
  return props.multiple ? [] : null;
65
66
  }
66
67
  return props.modelValue;
@@ -70,6 +71,8 @@ const value = computed({
70
71
  }
71
72
  });
72
73
  const isLoading = computed(() => props.isLoading || loading.value);
74
+ const hasTrackByValue = computed(() => Array.isArray(props.trackByValue) ? props.trackByValue.length > 0 : !!props.trackByValue);
75
+ const isResolvingSelection = computed(() => hasTrackByValue.value && (!loadedValuesHaveBeenSet.value && loading.value || resolvingMissingValues.value));
73
76
  const params = computed(() => buildQueryString(props.params));
74
77
  const elementId = computed(() => {
75
78
  const attrs = useAttrs();
@@ -114,7 +117,8 @@ const sharedMultiSelectProps = computed(() => ({
114
117
  groupLabel: props.groupLabel,
115
118
  label: props.itemLabel,
116
119
  trackBy: props.trackBy,
117
- placeholder: hasValue.value ? "" : internalPlaceholder.value || t("inputs.placeholder_select"),
120
+ placeholder: hasValue.value || isResolvingSelection.value ? "" : internalPlaceholder.value || t("inputs.placeholder_select"),
121
+ loading: isResolvingSelection.value,
118
122
  showLabels: false,
119
123
  clearOnSelect: true,
120
124
  showNoOptions: isLoading.value ? false : props.showNoOptions,
@@ -206,9 +210,14 @@ watch([() => props.trackByValue, defaultOptions], async ([trackByValue, _default
206
210
  (value2) => !items.some((item) => item?.[props.trackBy] == value2)
207
211
  );
208
212
  if (missingIds.length > 0 && props.url) {
209
- const fetchedItems = await Promise.all(missingIds.map((id) => getRecords(id)));
210
- if (fetchedItems.length > 0) {
211
- items = items.concat(fetchedItems.flat());
213
+ resolvingMissingValues.value = true;
214
+ try {
215
+ const fetchedItems = await Promise.all(missingIds.map((id) => getRecords(id)));
216
+ if (fetchedItems.length > 0) {
217
+ items = items.concat(fetchedItems.flat());
218
+ }
219
+ } finally {
220
+ resolvingMissingValues.value = false;
212
221
  }
213
222
  }
214
223
  const optionsToSelect = loadedValues.map((value2) => items.find((item) => item?.[props.trackBy] == value2)).filter(Boolean);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@winchsa/ui",
3
- "version": "0.1.63",
3
+ "version": "0.1.64",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "publishConfig": {