vue3-extended-multiselect 1.5.1 → 1.5.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.5.1**
3
+ Current `vue3-extended-multiselect` version: **1.5.3**
4
4
 
5
5
  ***
6
6
 
@@ -195,4 +195,13 @@ Adding descriptive comments for some types in typings.
195
195
 
196
196
  ### 1.5.1 (2023-01-25)
197
197
 
198
- * Fixing bug with missing toggle on option click in single selection.
198
+ * Fixing bug with missing toggle on option click in single selection.
199
+
200
+ ### 1.5.2 (2023-01-25)
201
+
202
+ * Fixing bug with empty class list in toggle restrictor when "disabled" prop equals true.
203
+
204
+ ### 1.5.3 (2023-01-25)
205
+
206
+ * Fixing bug with incorrect setting of preselected options from v-model.
207
+ * Fixing bug with incompatible single preselected option.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # vue3-extended-multiselect v1.5.1
1
+ # vue3-extended-multiselect v1.5.3
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.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "Extended multiselect component for applications based on Vue 3 framework",
5
5
  "keywords": [
6
6
  "multiselect",
@@ -253,7 +253,7 @@ import ExtendedMultiselectToggle from "./ExtendedMultiselectToggle.vue";
253
253
 
254
254
  /**
255
255
  * @author Ridiger Daniil Dmitrievich
256
- * @version 1.5.1
256
+ * @version 1.5.3
257
257
  */
258
258
 
259
259
  const props = defineProps({
@@ -909,6 +909,7 @@ const {
909
909
  label,
910
910
  loading,
911
911
  loaderIconFilter,
912
+ modelValue,
912
913
  multiple,
913
914
  options,
914
915
  optionsCountRestriction,
@@ -1312,25 +1313,29 @@ const selectByEnter = (keyboardEvent) => {
1312
1313
  * Sets preselected option provided by "preselectedOption" prop
1313
1314
  * @function
1314
1315
  * @emits extended:select-option
1316
+ * @param {UnionPropType} preselectedOption - option to be selected
1315
1317
  */
1316
- const setPreselectedOption = () => {
1317
- const availableOptionType = optionTypeRestrictor(preselectedOption.value);
1318
+ const setPreselectedOption = (preselectedOption) => {
1319
+ const availableOptionType = optionTypeRestrictor(preselectedOption);
1318
1320
  const mappedOptions = restrictedOptions.value.map((restrictedOption) => {
1319
1321
  return JSON.stringify(restrictedOption);
1320
1322
  });
1321
1323
 
1322
1324
  if (!availableOptionType) return;
1323
- if (!mappedOptions.includes(JSON.stringify(preselectedOption.value)) && showInsertWarnings.value) {
1324
- console.warn("vue-extended-multiselect: option in «preselectedOption» property should be the same as analogue in «options» property");
1325
+ if (!mappedOptions.includes(JSON.stringify(preselectedOption))) {
1326
+ if (showInsertWarnings.value) {
1327
+ console.warn("vue-extended-multiselect: option in «preselectedOption» property should be the same as analogue in «options» property");
1328
+ }
1329
+
1325
1330
  return;
1326
1331
  }
1327
1332
 
1328
- const isObjectOrArray = typeof preselectedOption.value === "object";
1329
- const label = createLabel(isObjectOrArray, preselectedOption.value);
1333
+ const isObjectOrArray = typeof preselectedOption === "object";
1334
+ const label = createLabel(isObjectOrArray, preselectedOption);
1330
1335
 
1331
1336
  emitter.value.emit("extended:select-option", {
1332
1337
  label,
1333
- option: preselectedOption.value,
1338
+ option: preselectedOption,
1334
1339
  });
1335
1340
  };
1336
1341
 
@@ -1339,14 +1344,15 @@ const setPreselectedOption = () => {
1339
1344
  * if "multiple" prop equals true
1340
1345
  * @function
1341
1346
  * @emits extended:select-option
1347
+ * @param {Array} preselectedOptions - options to be selected
1342
1348
  */
1343
- const setPreselectedOptions = async () => {
1349
+ const setPreselectedOptions = async (preselectedOptions) => {
1344
1350
  let allOptionsWereSelected = 0;
1345
1351
  const mappedOptions = restrictedOptions.value.map((restrictedOption) => {
1346
1352
  return JSON.stringify(restrictedOption);
1347
1353
  });
1348
1354
 
1349
- preselectedOptions.value.forEach((preselectedOption) => {
1355
+ preselectedOptions.forEach((preselectedOption) => {
1350
1356
  const availableOptionType = optionTypeRestrictor(preselectedOption);
1351
1357
 
1352
1358
  if (!preselectedOption || !availableOptionType) return;
@@ -1365,22 +1371,38 @@ const setPreselectedOptions = async () => {
1365
1371
  }
1366
1372
  });
1367
1373
 
1368
- if (allOptionsWereSelected !== preselectedOptions.value.length && showInsertWarnings.value) {
1374
+ if (allOptionsWereSelected !== preselectedOptions.length && showInsertWarnings.value) {
1369
1375
  console.warn("vue-extended-multiselect: options in «preselectedOptions» property should be the same as analogues in «options» property");
1370
1376
  }
1371
1377
  };
1372
1378
 
1373
1379
  /**
1374
1380
  * Determines conditions that control preselected options installattion
1381
+ * if "modelValue" prop is defined
1382
+ * @function
1383
+ */
1384
+ const setPreselectedOptionsByModelValue = () => {
1385
+ if (!modelValue.value) return;
1386
+
1387
+ if (Array.isArray(modelValue.value) && multiple.value) {
1388
+ setPreselectedOptions(modelValue.value);
1389
+ } else {
1390
+ setPreselectedOption(modelValue.value);
1391
+ }
1392
+ }
1393
+
1394
+ /**
1395
+ * Determines conditions that control preselected options installattion
1396
+ * by "preselectedOption" and "preselectedOptions" props
1375
1397
  * @function
1376
1398
  */
1377
1399
  const setPreselectedOptionsByConditions = () => {
1378
1400
  if (preselectedOption.value && !multiple.value) {
1379
- setPreselectedOption();
1401
+ setPreselectedOption(preselectedOption.value);
1380
1402
  }
1381
1403
 
1382
1404
  if (preselectedOptions.value && multiple.value) {
1383
- setPreselectedOptions();
1405
+ setPreselectedOptions(preselectedOptions.value);
1384
1406
  }
1385
1407
  };
1386
1408
 
@@ -1439,14 +1461,14 @@ const toggleBlockRestrictor = (mouseEvent) => {
1439
1461
 
1440
1462
  if (extendedMultiselectToggle.value) {
1441
1463
  generalRestriction = (filteredHasBlock.length && dropdownActive.value && filteredCustomSelf)
1442
- || (filteredSelf && dropdownActive.value && filteredCustomSelf);
1464
+ || (filteredSelf.length && dropdownActive.value && filteredCustomSelf)
1465
+ || (filteredHasSlot.length && dropdownActive.value && filteredCustomSelf);
1443
1466
  } else {
1444
1467
  generalRestriction = (filteredHasBlock.length && dropdownActive.value)
1445
- || (filteredSelf && dropdownActive.value);
1468
+ || (filteredSelf.length && dropdownActive.value)
1469
+ || (filteredHasSlot.length && dropdownActive.value);
1446
1470
  }
1447
-
1448
- console.info(generalRestriction)
1449
-
1471
+
1450
1472
  if (generalRestriction) {
1451
1473
  emitter.value.emit("extended:skip-block-blur");
1452
1474
  return true;
@@ -1498,7 +1520,7 @@ const toggleDetector = (mouseEvent, pattern, mode) => {
1498
1520
  && (target.classList
1499
1521
  && !target.classList.contains("extended__multiselect-wrapper")
1500
1522
  && !target.classList.contains("extended__multiselect-options_container")
1501
- || !target.classList.length)
1523
+ || target.classList && !target.classList.length)
1502
1524
  && mode
1503
1525
  && !filteredHasToggle.length
1504
1526
  ) {
@@ -1721,6 +1743,8 @@ onMounted(() => {
1721
1743
  setPreselectedOptionsByConditions();
1722
1744
  }
1723
1745
 
1746
+ setPreselectedOptionsByModelValue();
1747
+
1724
1748
  if (
1725
1749
  defaultExpanded.value
1726
1750
  && !inputDisabled.value