vue3-extended-multiselect 1.7.1 → 1.7.3

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.7.0**
3
+ Current `vue3-extended-multiselect` version: **1.7.3**
4
4
 
5
5
  ***
6
6
 
@@ -277,4 +277,12 @@ Adding descriptive comments for some types in typings.
277
277
  ### 1.7.1 (2023-02-07)
278
278
 
279
279
  * Adding instance.js file with noт-reactive instance of local event emitter.
280
- * Fixing bug with not clotting options list when clicking on another instance.
280
+ * Fixing bug with not clotting options list when clicking on another instance.
281
+
282
+ ### 1.7.2 (2023-02-07)
283
+
284
+ * Changing event type to collapse the list of options when clicking on another instance.
285
+
286
+ ### 1.7.3 (2023-02-07)
287
+
288
+ * Fixing bug with disabled removal of selected options based on external modelValue changes.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # vue3-extended-multiselect v1.7.1
1
+ # vue3-extended-multiselect v1.7.3
2
2
 
3
3
  ***
4
4
 
package/jest.config.js CHANGED
@@ -5,7 +5,7 @@ module.exports = {
5
5
  },
6
6
  expand: true,
7
7
  displayName: {
8
- name: "vue3-extended-multiselect 1.7.1",
8
+ name: "vue3-extended-multiselect 1.7.3",
9
9
  color: "bgGreen",
10
10
  },
11
11
  extraGlobals: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue3-extended-multiselect",
3
- "version": "1.7.1",
3
+ "version": "1.7.3",
4
4
  "description": "Extended multiselect component for applications based on Vue 3 framework",
5
5
  "keywords": [
6
6
  "multiselect",
@@ -262,7 +262,7 @@ import ExtendedMultiselectToggle from "./ExtendedMultiselectToggle.vue";
262
262
 
263
263
  /**
264
264
  * @author Ridiger Daniil Dmitrievich, 2022
265
- * @version 1.7.1
265
+ * @version 1.7.3
266
266
  */
267
267
 
268
268
  const props = defineProps({
@@ -904,6 +904,7 @@ const emit = defineEmits([
904
904
  const dropdownActive = ref(false);
905
905
  const externalOptionsLoader = ref(null);
906
906
  const chosenToggleAppearanceSide = ref(null);
907
+ const selectedOptionsWatcher = ref(null);
907
908
  const rawOptions = ref([]);
908
909
  const selectedOptions = ref([]);
909
910
  const togglePattern = /^extended__multiselect-toggle_wrapper/i;
@@ -1150,21 +1151,11 @@ watch(dropdownActive, (value) => {
1150
1151
  });
1151
1152
 
1152
1153
  /**
1153
- * Clears value of search field after changing selected option/options
1154
- * if "resetSearchByValue" prop equals true
1154
+ * Changes selected options based on external modelValue changes
1155
1155
  * @function
1156
- * @emits extended:clear-field
1157
1156
  */
1158
- watch(selectedOptions, (value) => {
1159
- if (multiple.value) {
1160
- emit("update:modelValue", value);
1161
- } else {
1162
- emit("update:modelValue", value[0]);
1163
- }
1164
-
1165
- if (resetSearchByValue.value) {
1166
- emitter.value.emit("extended:clear-field");
1167
- }
1157
+ watch(modelValue, () => {
1158
+ setPreselectedOptionsByModelValue(true);
1168
1159
  }, { deep: true });
1169
1160
 
1170
1161
  /**
@@ -1231,8 +1222,6 @@ const createEventFields = (field, fieldName) => {
1231
1222
  * @param {MouseEvent} mouseEvent - MouseEvent instance
1232
1223
  */
1233
1224
  const fieldFocus = (mouseEvent) => {
1234
- rollupInstanses();
1235
-
1236
1225
  if (disabled.value) return;
1237
1226
 
1238
1227
  if (!toggleOptionsBySelect.value) {
@@ -1268,6 +1257,25 @@ const loadOptionsByExternalLoader = (pattern, initialValue) => {
1268
1257
  });
1269
1258
  };
1270
1259
 
1260
+ /**
1261
+ * Makes removal of selected options based on external modelValue changes
1262
+ * @function
1263
+ * @param {boolean} single - "multiple" prop flag
1264
+ */
1265
+ const removeSelectedOptions = (single = false) => {
1266
+ if (!single) {
1267
+ const modelValueMapped = modelValue.value.map((option) => {
1268
+ return JSON.stringify(option);
1269
+ });
1270
+
1271
+ selectedOptions.value = selectedOptions.value.filter((option) => {
1272
+ return modelValueMapped.includes(JSON.stringify(option));
1273
+ });
1274
+ } else {
1275
+ if (!modelValue.value) cancel();
1276
+ }
1277
+ }
1278
+
1271
1279
  /**
1272
1280
  * Emits event whose listener resets index of "enter" key pressing
1273
1281
  * @function
@@ -1379,15 +1387,36 @@ const setPreselectedOptions = async (preselectedOptions, restriction = true) =>
1379
1387
  * Determines conditions that control preselected options installattion
1380
1388
  * if "modelValue" prop is defined
1381
1389
  * @function
1390
+ * @param {boolean} withRemoval - removal of selected options flag
1382
1391
  */
1383
- const setPreselectedOptionsByModelValue = () => {
1384
- if (!modelValue.value) return;
1392
+ const setPreselectedOptionsByModelValue = (withRemoval = false) => {
1393
+ if (!modelValue.value && !withRemoval) return;
1394
+
1395
+ if (withRemoval) selectedOptionsWatcher.value();
1396
+
1397
+ if (multiple.value) {
1398
+ if (withRemoval) removeSelectedOptions();
1385
1399
 
1386
- if (Array.isArray(modelValue.value) && multiple.value) {
1387
1400
  setPreselectedOptions(modelValue.value, false);
1388
1401
  } else {
1402
+ if (withRemoval) removeSelectedOptions(true);
1403
+
1389
1404
  setPreselectedOption(modelValue.value, false);
1390
1405
  }
1406
+
1407
+ if (withRemoval) {
1408
+ selectedOptionsWatcher.value = watch(selectedOptions, (value) => {
1409
+ if (multiple.value) {
1410
+ emit("update:modelValue", value);
1411
+ } else {
1412
+ emit("update:modelValue", value[0]);
1413
+ }
1414
+
1415
+ if (resetSearchByValue.value) {
1416
+ emitter.value.emit("extended:clear-field");
1417
+ }
1418
+ }, { deep: true });
1419
+ }
1391
1420
  }
1392
1421
 
1393
1422
  /**
@@ -1599,6 +1628,8 @@ const toggleOptionsRestrictor = (mouseEvent) => {
1599
1628
  * @param {MouseEvent} mouseEvent - MouseEvent instance
1600
1629
  */
1601
1630
  const toggleRestrictor = (mouseEvent) => {
1631
+ rollupInstanses();
1632
+
1602
1633
  const targetContentBlock = toggleBlockRestrictor(mouseEvent);
1603
1634
 
1604
1635
  if (targetContentBlock) return;
@@ -1628,6 +1659,18 @@ const toggleRestrictor = (mouseEvent) => {
1628
1659
  * @listens extended:search-pattern-changed
1629
1660
  */
1630
1661
  onBeforeMount(() => {
1662
+ selectedOptionsWatcher.value = watch(selectedOptions, (value) => {
1663
+ if (multiple.value) {
1664
+ emit("update:modelValue", value);
1665
+ } else {
1666
+ emit("update:modelValue", value[0]);
1667
+ }
1668
+
1669
+ if (resetSearchByValue.value) {
1670
+ emitter.value.emit("extended:clear-field");
1671
+ }
1672
+ }, { deep: true });
1673
+
1631
1674
  chosenToggleAppearanceSide.value = toggleAppearanceSide.value;
1632
1675
 
1633
1676
  emitter.value.on("extended:rollup-options", () => {