vue3-extended-multiselect 1.1.4 → 1.1.6

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Patch notes
2
2
 
3
- Current `vue3-extended-multiselect` version: **1.1.4**
3
+ Current `vue3-extended-multiselect` version: **1.1.6**
4
4
 
5
5
  ***
6
6
 
@@ -114,4 +114,12 @@ Adding descriptive comments for some types in typings.
114
114
 
115
115
  ### 1.1.4 (2022-13-11)
116
116
  * Adding "optionCreateLabel" to expose as utility.
117
- * Fix bug with wrong name of label field
117
+ * Fix bug with wrong name of label field
118
+
119
+ ### 1.1.5 (2022-13-11)
120
+ * Fix bug with empty raw options list when using async loader.
121
+
122
+ ### 1.1.6 (2022-13-11)
123
+ * Fix bug with extra call of async loader by changing value of search field.
124
+ * Adding new internal prop "externalOptionsLoader" to ExtendedMultiselectInput.
125
+ * Searching for options by async loader is moved to in separate method.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # vue3-extended-multiselect v1.1.4
1
+ # vue3-extended-multiselect v1.1.6
2
2
 
3
3
  ***
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue3-extended-multiselect",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Extended multiselect component for applications based on Vue 3 framework",
5
5
  "keywords": [
6
6
  "multiselect",
@@ -336,6 +336,17 @@ const props = defineProps({
336
336
  required: true,
337
337
  },
338
338
 
339
+ /**
340
+ * Loader function provided by user.
341
+ * @property {Function} externalOptionsLoader
342
+ * @default null
343
+ * @param {string} value - value of search field
344
+ */
345
+ externalOptionsLoader: {
346
+ type: Boolean,
347
+ default: null,
348
+ },
349
+
339
350
  /**
340
351
  * Provides function that creates limit message for maximal of selected
341
352
  * options to ExtendedMultiselectMultiple child component
@@ -372,9 +383,13 @@ const blurSkipByBlock = ref(0);
372
383
  const labelBlocks = ref([]);
373
384
  const searchDebounce = ref(debounce(() => {
374
385
  const searchPattern = searchValue.value ? new RegExp(`${searchValue.value}`, "i") : null;
375
- emitter.emit("extended:search-pattern-changed", searchValue.value);
376
386
 
377
- setSearchPattern(searchPattern);
387
+ if (externalOptionsLoader.value) {
388
+ emitter.emit("extended:loader-pattern-changed", searchValue.value);
389
+ } else {
390
+ emitter.emit("extended:search-pattern-changed", searchValue.value);
391
+ setSearchPattern(searchPattern);
392
+ }
378
393
  }, 250));
379
394
 
380
395
  /**
@@ -386,6 +401,7 @@ const {
386
401
  createOnTheGo,
387
402
  createOptionPlaceholder,
388
403
  disabled,
404
+ externalOptionsLoader,
389
405
  increaseDisplayBy,
390
406
  multiple,
391
407
  placeholder,
@@ -31,6 +31,7 @@
31
31
  :create-on-the-go="createOnTheGo"
32
32
  :disabled="inputDisabled"
33
33
  :dropdown-active="dropdownActive"
34
+ :external-options-loader="externalOptionsLoader"
34
35
  :loading="internalLoading"
35
36
  :multiple="multiple"
36
37
  :search-filter-active="searchFilterActive"
@@ -805,7 +806,7 @@ const props = defineProps({
805
806
 
806
807
  /**
807
808
  * Defines function that creates custom label for each option
808
- * @default ()=>null
809
+ * @default (option)=>null
809
810
  * @property {Function} createCustomOptionLabel
810
811
  */
811
812
  createCustomOptionLabel: {
@@ -816,7 +817,7 @@ const props = defineProps({
816
817
  /**
817
818
  * Defines function that creates notification when maximal limit
818
819
  * of selected options has been reached
819
- * @default ()=>string
820
+ * @default (number)=>string
820
821
  * @property {Function} multipleBlocksLimitMessage
821
822
  */
822
823
  multipleBlocksLimitMessage: {
@@ -859,6 +860,7 @@ const emit = defineEmits([
859
860
  const dropdownActive = ref(false);
860
861
  const inputDisabled = ref(false);
861
862
  const internalLoader = ref(false);
863
+ const externalOptionsLoader = ref(null);
862
864
  const chosenToggleAppearanceSide = ref(null);
863
865
  const rawOptions = ref([]);
864
866
  const selectedOptions = ref([]);
@@ -1040,6 +1042,8 @@ const internalLoading = computed(() => {
1040
1042
  * @returns {Array} options
1041
1043
  */
1042
1044
  const restrictedOptions = computed(() => {
1045
+ if (!rawOptions.value) return [];
1046
+
1043
1047
  return optionsCountRestriction.value
1044
1048
  ? rawOptions.value.filter((option, index) => index + 1 <= optionsCountRestriction.value)
1045
1049
  : rawOptions.value;
@@ -1229,6 +1233,21 @@ const fieldFocus = (mouseEvent) => {
1229
1233
  emitter.emit("extended:field-focus");
1230
1234
  };
1231
1235
 
1236
+ /**
1237
+ * Initialises options list loading by external async method
1238
+ * @function
1239
+ * @param {string} pattern - value of search field
1240
+ */
1241
+ const loadOptionsByExternalLoader = (pattern) => {
1242
+ internalLoader.value = true;
1243
+ externalOptionsLoader.value = options.value;
1244
+ options.value(pattern).then(options => {
1245
+ rawOptions.value = options;
1246
+ internalLoader.value = false;
1247
+ setPreselectedOptionsByConditions();
1248
+ });
1249
+ };
1250
+
1232
1251
  /**
1233
1252
  * Emits event whose listener resets index of "enter" key pressing
1234
1253
  * @function
@@ -1646,15 +1665,11 @@ onBeforeMount(() => {
1646
1665
  /**
1647
1666
  * "onMounted" hook of the Vue3ExtendedMultiselect component
1648
1667
  * @listens extended:expand-options
1668
+ * @listens extended:loader-pattern-changed
1649
1669
  */
1650
1670
  onMounted(() => {
1651
1671
  if (typeof options.value === "function") {
1652
- internalLoader.value = true;
1653
- options.value().then(options => {
1654
- rawOptions.value = options;
1655
- internalLoader.value = false;
1656
- setPreselectedOptionsByConditions();
1657
- });
1672
+ loadOptionsByExternalLoader();
1658
1673
  } else {
1659
1674
  rawOptions.value = options.value;
1660
1675
  setPreselectedOptionsByConditions();
@@ -1677,6 +1692,10 @@ onMounted(() => {
1677
1692
 
1678
1693
  dropdownActive.value = true;
1679
1694
  });
1695
+
1696
+ emitter.on("extended:loader-pattern-changed", (pattern) => {
1697
+ loadOptionsByExternalLoader(pattern);
1698
+ });
1680
1699
  });
1681
1700
 
1682
1701
  defineExpose({