vue3-extended-multiselect 1.8.0 → 1.8.2
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 +11 -2
- package/README.md +1 -2
- package/jest.config.js +1 -1
- package/package.json +1 -1
- package/src/components/Vue3ExtendedMultiselect.vue +59 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Patch notes
|
|
2
2
|
|
|
3
|
-
Current `vue3-extended-multiselect` version: **1.8.
|
|
3
|
+
Current `vue3-extended-multiselect` version: **1.8.2**
|
|
4
4
|
|
|
5
5
|
***
|
|
6
6
|
|
|
@@ -302,4 +302,13 @@ Adding descriptive comments for some types in typings.
|
|
|
302
302
|
* Adding type for "update-wrapper" event.
|
|
303
303
|
* Adding tools.spec.js file with unit-tests for tools.
|
|
304
304
|
* Moving local emitter files to tools directory.
|
|
305
|
-
* Removal of "lodash-es" dependency.
|
|
305
|
+
* Removal of "lodash-es" dependency.
|
|
306
|
+
|
|
307
|
+
### 1.8.1 (2023-02-21)
|
|
308
|
+
|
|
309
|
+
* Removal of "update:wrapper" event.
|
|
310
|
+
* Fixing bug with incorrect v-model updating in custom wrappers.
|
|
311
|
+
|
|
312
|
+
### 1.8.2 (2023-02-21)
|
|
313
|
+
|
|
314
|
+
* Fixing bug with non-updating modelValue by handling preselected options.
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# vue3-extended-multiselect v1.8.
|
|
1
|
+
# vue3-extended-multiselect v1.8.2
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -122,7 +122,6 @@ Event name | Event appointment | Listener method | Simplified event payload | Fi
|
|
|
122
122
|
**active**|Dropdown options list expanding.|@active|—|``inputId`` — id of search field set by "id" prop|
|
|
123
123
|
**close**|Rolling up dropdown options list.|@close|``options`` — array of selected options|``options`` — array of selected options,<br/>``inputId`` — id of search field set by "id" prop|
|
|
124
124
|
**increase**|Increasing current limit of displayed elements with selected options.|@increase|``limit`` — current limit of options to be shown next|``limit`` — current limit of options to be shown next,<br/>``inputId`` — id of search field set by "id" prop|
|
|
125
|
-
**update:wrapper**|Notifies wrapper component that inner modelValue has been updated by external modelValue update|@update:wrapper|``options`` — array of selected options|``options`` — array of selected options,<br/>``inputId`` — id of search field set by "id" prop|
|
|
126
125
|
|
|
127
126
|
## Styling with css
|
|
128
127
|
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -262,7 +262,7 @@ import ExtendedMultiselectToggle from "./ExtendedMultiselectToggle.vue";
|
|
|
262
262
|
|
|
263
263
|
/**
|
|
264
264
|
* @author Ridiger Daniil Dmitrievich, 2022
|
|
265
|
-
* @version 1.8.
|
|
265
|
+
* @version 1.8.2
|
|
266
266
|
*/
|
|
267
267
|
|
|
268
268
|
const props = defineProps({
|
|
@@ -903,6 +903,7 @@ const emit = defineEmits([
|
|
|
903
903
|
]);
|
|
904
904
|
|
|
905
905
|
const dropdownActive = ref(false);
|
|
906
|
+
const skipNextUpdate = ref(false);
|
|
906
907
|
const externalOptionsLoader = ref(null);
|
|
907
908
|
const chosenToggleAppearanceSide = ref(null);
|
|
908
909
|
const selectedOptionsWatcher = ref(null);
|
|
@@ -1086,6 +1087,17 @@ const internalLoading = computed(() => {
|
|
|
1086
1087
|
return loading.value;
|
|
1087
1088
|
});
|
|
1088
1089
|
|
|
1090
|
+
/**
|
|
1091
|
+
* Defines mapped list of previously restricted options
|
|
1092
|
+
* @function
|
|
1093
|
+
* @returns {Array} options
|
|
1094
|
+
*/
|
|
1095
|
+
const mappedOptions = computed(() => {
|
|
1096
|
+
return restrictedOptions.value.map((restrictedOption) => {
|
|
1097
|
+
return JSON.stringify(restrictedOption);
|
|
1098
|
+
});
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1089
1101
|
/**
|
|
1090
1102
|
* Defines a list of options filtered by maximal admissible options amount
|
|
1091
1103
|
* @function
|
|
@@ -1156,6 +1168,11 @@ watch(dropdownActive, (value) => {
|
|
|
1156
1168
|
* @function
|
|
1157
1169
|
*/
|
|
1158
1170
|
watch(modelValue, () => {
|
|
1171
|
+
if (skipNextUpdate.value) {
|
|
1172
|
+
skipNextUpdate.value = false;
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1159
1176
|
setPreselectedOptionsByModelValue(true);
|
|
1160
1177
|
}, { deep: true });
|
|
1161
1178
|
|
|
@@ -1324,12 +1341,15 @@ const selectByEnter = (keyboardEvent) => {
|
|
|
1324
1341
|
*/
|
|
1325
1342
|
const setPreselectedOption = (preselectedOption, restriction = true) => {
|
|
1326
1343
|
const availableOptionType = optionTypeRestrictor(preselectedOption);
|
|
1327
|
-
const
|
|
1328
|
-
return JSON.stringify(
|
|
1344
|
+
const mappedSelectedOptions = selectedOptions.value.map((selectedOption) => {
|
|
1345
|
+
return JSON.stringify(selectedOption);
|
|
1329
1346
|
});
|
|
1330
1347
|
|
|
1331
1348
|
if (!availableOptionType) return;
|
|
1332
|
-
if (
|
|
1349
|
+
if (
|
|
1350
|
+
(!mappedOptions.value.includes(JSON.stringify(preselectedOption)) && restriction)
|
|
1351
|
+
&& !mappedSelectedOptions.includes(JSON.stringify(preselectedOption))
|
|
1352
|
+
) {
|
|
1333
1353
|
if (showInsertWarnings.value) {
|
|
1334
1354
|
console.warn("vue-extended-multiselect: option in «preselectedOption» property should be the same as analogue in «options» property");
|
|
1335
1355
|
}
|
|
@@ -1356,8 +1376,8 @@ const setPreselectedOption = (preselectedOption, restriction = true) => {
|
|
|
1356
1376
|
*/
|
|
1357
1377
|
const setPreselectedOptions = async (preselectedOptions, restriction = true) => {
|
|
1358
1378
|
let allOptionsWereSelected = 0;
|
|
1359
|
-
const
|
|
1360
|
-
return JSON.stringify(
|
|
1379
|
+
const mappedSelectedOptions = selectedOptions.value.map((selectedOption) => {
|
|
1380
|
+
return JSON.stringify(selectedOption);
|
|
1361
1381
|
});
|
|
1362
1382
|
|
|
1363
1383
|
preselectedOptions.forEach((preselectedOption) => {
|
|
@@ -1366,7 +1386,10 @@ const setPreselectedOptions = async (preselectedOptions, restriction = true) =>
|
|
|
1366
1386
|
if (!preselectedOption || !availableOptionType) return;
|
|
1367
1387
|
if (selectedOptions.value.includes(preselectedOption)) return;
|
|
1368
1388
|
|
|
1369
|
-
if (
|
|
1389
|
+
if (
|
|
1390
|
+
(mappedOptions.value.includes(JSON.stringify(preselectedOption)) || !restriction)
|
|
1391
|
+
&& !mappedSelectedOptions.includes(JSON.stringify(preselectedOption))
|
|
1392
|
+
) {
|
|
1370
1393
|
const isObjectOrArray = typeof option === "object";
|
|
1371
1394
|
const label = createLabel(isObjectOrArray, preselectedOption);
|
|
1372
1395
|
|
|
@@ -1407,17 +1430,12 @@ const setPreselectedOptionsByModelValue = (withRemoval = false) => {
|
|
|
1407
1430
|
}
|
|
1408
1431
|
|
|
1409
1432
|
if (withRemoval) {
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1433
|
+
updateModelValue();
|
|
1434
|
+
|
|
1435
|
+
skipNextUpdate.value = true;
|
|
1413
1436
|
|
|
1414
|
-
emit("update:wrapper", eventData);
|
|
1415
1437
|
selectedOptionsWatcher.value = watch(selectedOptions, (value) => {
|
|
1416
|
-
|
|
1417
|
-
emit("update:modelValue", value);
|
|
1418
|
-
} else {
|
|
1419
|
-
emit("update:modelValue", value[0]);
|
|
1420
|
-
}
|
|
1438
|
+
updateModelValue();
|
|
1421
1439
|
|
|
1422
1440
|
if (resetSearchByValue.value) {
|
|
1423
1441
|
emitter.value.emit("extended:clear-field");
|
|
@@ -1434,10 +1452,20 @@ const setPreselectedOptionsByModelValue = (withRemoval = false) => {
|
|
|
1434
1452
|
const setPreselectedOptionsByConditions = () => {
|
|
1435
1453
|
if (preselectedOption.value && !multiple.value) {
|
|
1436
1454
|
setPreselectedOption(preselectedOption.value);
|
|
1455
|
+
|
|
1456
|
+
if (selectedOptions.value.length) {
|
|
1457
|
+
updateModelValue();
|
|
1458
|
+
}
|
|
1437
1459
|
}
|
|
1438
1460
|
|
|
1439
1461
|
if (preselectedOptions.value && multiple.value) {
|
|
1462
|
+
const initialLength = selectedOptions.value.length;
|
|
1463
|
+
|
|
1440
1464
|
setPreselectedOptions(preselectedOptions.value);
|
|
1465
|
+
|
|
1466
|
+
if (initialLength !== selectedOptions.value.length) {
|
|
1467
|
+
updateModelValue();
|
|
1468
|
+
}
|
|
1441
1469
|
}
|
|
1442
1470
|
};
|
|
1443
1471
|
|
|
@@ -1645,6 +1673,20 @@ const toggleRestrictor = (mouseEvent) => {
|
|
|
1645
1673
|
}
|
|
1646
1674
|
};
|
|
1647
1675
|
|
|
1676
|
+
/**
|
|
1677
|
+
* Triggers modelValue updating when v-model has
|
|
1678
|
+
* been changed programmatically
|
|
1679
|
+
* @function
|
|
1680
|
+
* @emits update:modelValue
|
|
1681
|
+
*/
|
|
1682
|
+
const updateModelValue = () => {
|
|
1683
|
+
if (multiple.value) {
|
|
1684
|
+
emit("update:modelValue", selectedOptions.value);
|
|
1685
|
+
} else {
|
|
1686
|
+
emit("update:modelValue", selectedOptions.value[0]);
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1648
1690
|
/**
|
|
1649
1691
|
* "onBeforeMount" hook of the Vue3ExtendedMultiselect component
|
|
1650
1692
|
* @emits select
|
|
@@ -1664,11 +1706,7 @@ const toggleRestrictor = (mouseEvent) => {
|
|
|
1664
1706
|
*/
|
|
1665
1707
|
onBeforeMount(() => {
|
|
1666
1708
|
selectedOptionsWatcher.value = watch(selectedOptions, (value) => {
|
|
1667
|
-
|
|
1668
|
-
emit("update:modelValue", value);
|
|
1669
|
-
} else {
|
|
1670
|
-
emit("update:modelValue", value[0]);
|
|
1671
|
-
}
|
|
1709
|
+
updateModelValue();
|
|
1672
1710
|
|
|
1673
1711
|
if (resetSearchByValue.value) {
|
|
1674
1712
|
emitter.value.emit("extended:clear-field");
|