@signal24/vue-foundation 4.25.5 → 4.25.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/package.json
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
|
|
52
52
|
<script lang="ts" setup generic="T, V = T">
|
|
53
53
|
import { debounce, groupBy, isEqual, uniq } from 'lodash';
|
|
54
|
-
import { computed, onMounted, ref, watch } from 'vue';
|
|
54
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
|
55
55
|
|
|
56
56
|
import { isNotNullOrUndefined } from '@/helpers';
|
|
57
57
|
|
|
@@ -111,8 +111,7 @@ const searchField = ref<HTMLInputElement>();
|
|
|
111
111
|
const optionsContainer = ref<HTMLDivElement>();
|
|
112
112
|
|
|
113
113
|
const isLoading = ref(false);
|
|
114
|
-
const
|
|
115
|
-
const loadedOptions = ref<T[]>();
|
|
114
|
+
const remoteOptions = ref<T[]>();
|
|
116
115
|
const isSearching = ref(false);
|
|
117
116
|
const searchText = ref('');
|
|
118
117
|
const selectedOption = ref<T | null>(null);
|
|
@@ -122,9 +121,12 @@ const highlightedOptionKey = ref<string | symbol | null>(null);
|
|
|
122
121
|
const shouldShowCreateOption = ref(false);
|
|
123
122
|
const shouldShowCreateTextOnNewItem = computed(() => props.showCreateTextOnNewItem ?? true);
|
|
124
123
|
|
|
124
|
+
const isLoaded = computed(() => !!(props.options || remoteOptions.value));
|
|
125
|
+
const loadedOptions = computed(() => props.options ?? remoteOptions.value ?? []);
|
|
126
|
+
|
|
125
127
|
const effectivePrependOptions = computed(() => props.prependOptions ?? []);
|
|
126
128
|
const effectiveAppendOptions = computed(() => props.appendOptions ?? []);
|
|
127
|
-
const effectiveDisabled = computed(() => !!props.disabled ||
|
|
129
|
+
const effectiveDisabled = computed(() => !!props.disabled || !isLoaded.value);
|
|
128
130
|
const effectivePlaceholder = computed(() => {
|
|
129
131
|
if (!isLoaded.value && props.preload) return 'Loading...';
|
|
130
132
|
if (props.nullTitle) return props.nullTitle;
|
|
@@ -158,7 +160,7 @@ const effectiveSelectionFormatter = computed(() => {
|
|
|
158
160
|
return effectiveFormatter.value;
|
|
159
161
|
});
|
|
160
162
|
|
|
161
|
-
const allOptions = computed(() => [...effectivePrependOptions.value, ...
|
|
163
|
+
const allOptions = computed(() => [...effectivePrependOptions.value, ...loadedOptions.value, ...effectiveAppendOptions.value]);
|
|
162
164
|
const isGrouped = computed(() => !!(props.groupField || props.groupFormatter));
|
|
163
165
|
|
|
164
166
|
const optionsDescriptors = computed(() => {
|
|
@@ -254,13 +256,6 @@ const groupedOptions = computed(() => {
|
|
|
254
256
|
|
|
255
257
|
// watch props
|
|
256
258
|
watch(() => props.modelValue, handleValueChanged);
|
|
257
|
-
watch(
|
|
258
|
-
() => props.options,
|
|
259
|
-
() => {
|
|
260
|
-
loadedOptions.value = props.options;
|
|
261
|
-
isLoaded.value = true;
|
|
262
|
-
}
|
|
263
|
-
);
|
|
264
259
|
|
|
265
260
|
// watch data
|
|
266
261
|
|
|
@@ -306,10 +301,7 @@ watch(effectiveOptions, () => {
|
|
|
306
301
|
onMounted(async () => {
|
|
307
302
|
shouldShowCreateOption.value = props.onCreateItem !== undefined;
|
|
308
303
|
|
|
309
|
-
if (props.
|
|
310
|
-
loadedOptions.value = [...props.options];
|
|
311
|
-
isLoaded.value = true;
|
|
312
|
-
} else if (props.loadOptions && props.preload) {
|
|
304
|
+
if (props.loadOptions && props.preload) {
|
|
313
305
|
await loadRemoteOptions();
|
|
314
306
|
}
|
|
315
307
|
|
|
@@ -335,17 +327,20 @@ onMounted(async () => {
|
|
|
335
327
|
}
|
|
336
328
|
});
|
|
337
329
|
|
|
330
|
+
onBeforeUnmount(() => {
|
|
331
|
+
optionsContainer.value?.remove();
|
|
332
|
+
});
|
|
333
|
+
|
|
338
334
|
async function loadRemoteOptions() {
|
|
339
335
|
await reloadOptions();
|
|
340
|
-
if (
|
|
336
|
+
if (remoteOptions.value) emit('optionsLoaded', remoteOptions.value);
|
|
341
337
|
}
|
|
342
338
|
|
|
343
339
|
async function reloadOptions() {
|
|
344
340
|
const effectiveSearchText = props.remoteSearch && isSearching.value && searchText.value.length ? searchText.value : null;
|
|
345
341
|
isLoading.value = true;
|
|
346
|
-
|
|
342
|
+
remoteOptions.value = (await props.loadOptions?.(effectiveSearchText)) ?? [];
|
|
347
343
|
isLoading.value = false;
|
|
348
|
-
isLoaded.value = true;
|
|
349
344
|
}
|
|
350
345
|
|
|
351
346
|
function reloadOptionsIfSearching() {
|
|
@@ -571,7 +566,7 @@ function handleValueChanged() {
|
|
|
571
566
|
}
|
|
572
567
|
|
|
573
568
|
function addRemoteOption(option: T) {
|
|
574
|
-
|
|
569
|
+
remoteOptions.value!.unshift(option);
|
|
575
570
|
}
|
|
576
571
|
|
|
577
572
|
function focusNextInput() {
|