vue3-extended-multiselect 2.2.3 → 2.3.0

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.
@@ -1625,6 +1625,24 @@ const rollUp = () => {
1625
1625
  emitter.value.emit("extended:rollup-options", true);
1626
1626
  };
1627
1627
 
1628
+ /**
1629
+ * Rolls up options list after option selection
1630
+ * and sets single option label
1631
+ * @function
1632
+ * @param {UnionPropType} option - option to be selected
1633
+ */
1634
+ const rollupIfSelected = (option) => {
1635
+ if (toggleOptionsBySelect.value) {
1636
+ rollUp();
1637
+ }
1638
+
1639
+ if (multiple.value) {
1640
+ return;
1641
+ } else {
1642
+ singleLabel.value = option.label;
1643
+ }
1644
+ };
1645
+
1628
1646
  /**
1629
1647
  * Activates debounced version of options list filter
1630
1648
  * @function
@@ -1638,6 +1656,7 @@ const search = () => {
1638
1656
  * @listens extended:field-focus
1639
1657
  * @listens extended:rollup-options
1640
1658
  * @listens extended:select-option
1659
+ * @listens extended:preselect-option
1641
1660
  * @listens extended:deselect-option
1642
1661
  * @listens extended:clean-options
1643
1662
  * @listens extended:clear-field
@@ -1661,16 +1680,11 @@ onBeforeMount(() => {
1661
1680
  });
1662
1681
 
1663
1682
  emitter.value.on("extended:select-option", (option) => {
1683
+ rollupIfSelected(option);
1684
+ });
1664
1685
 
1665
- if (toggleOptionsBySelect.value) {
1666
- rollUp();
1667
- }
1668
-
1669
- if (multiple.value) {
1670
- return;
1671
- } else {
1672
- singleLabel.value = option.label;
1673
- }
1686
+ emitter.value.on("extended:preselect-option", (option) => {
1687
+ rollupIfSelected(option);
1674
1688
  });
1675
1689
 
1676
1690
  emitter.value.on("extended:deselect-option", () => {
@@ -3614,7 +3628,7 @@ const _hoisted_3 = { class: "extended__multiselect-cancel_wrapper" };
3614
3628
 
3615
3629
  /**
3616
3630
  * @author Ridiger Daniil Dmitrievich, 2022
3617
- * @version 2.2.2
3631
+ * @version 2.3.0
3618
3632
  */
3619
3633
 
3620
3634
  var script = {
@@ -4696,7 +4710,7 @@ const selectByEnter = (keyboardEvent) => {
4696
4710
  /**
4697
4711
  * Sets preselected option provided by "preselectedOption" prop
4698
4712
  * @function
4699
- * @emits extended:select-option
4713
+ * @emits extended:preselect-option
4700
4714
  * @param {UnionPropType} preselectedOption - option to be selected
4701
4715
  * @param {boolean} restriction - restriction of preselected option
4702
4716
  */
@@ -4721,7 +4735,7 @@ const setPreselectedOption = (preselectedOption, restriction = true) => {
4721
4735
  const isObjectOrArray = typeof preselectedOption === "object";
4722
4736
  const label = createLabel(isObjectOrArray, preselectedOption);
4723
4737
 
4724
- emitter.value.emit("extended:select-option", {
4738
+ emitter.value.emit("extended:preselect-option", {
4725
4739
  label,
4726
4740
  option: preselectedOption,
4727
4741
  });
@@ -4731,7 +4745,7 @@ const setPreselectedOption = (preselectedOption, restriction = true) => {
4731
4745
  * Sets preselected options provided by "preselectedOptions" prop
4732
4746
  * if "multiple" prop equals true
4733
4747
  * @function
4734
- * @emits extended:select-option
4748
+ * @emits extended:preselect-option
4735
4749
  * @param {Array} preselectedOptions - options to be selected
4736
4750
  * @param {boolean} restriction - restriction of preselected options
4737
4751
  */
@@ -4756,7 +4770,7 @@ const setPreselectedOptions = async (preselectedOptions, restriction = true) =>
4756
4770
 
4757
4771
  allOptionsWereSelected++;
4758
4772
 
4759
- emitter.value.emit("extended:select-option", {
4773
+ emitter.value.emit("extended:preselect-option", {
4760
4774
  label,
4761
4775
  option: preselectedOption,
4762
4776
  });
@@ -4780,7 +4794,7 @@ const setPreselectedOptionsByModelValue = (withRemoval = false) => {
4780
4794
 
4781
4795
  if (withRemoval) selectedOptionsWatcher.value();
4782
4796
 
4783
- if (multiple.value) {
4797
+ if (Array.isArray(modelValue.value) && multiple.value) {
4784
4798
  if (withRemoval) removeSelectedOptions();
4785
4799
 
4786
4800
  setPreselectedOptions(modelValue.value, false);
@@ -4817,7 +4831,7 @@ const setPreselectedOptionsByConditions = () => {
4817
4831
  }
4818
4832
  }
4819
4833
 
4820
- if (preselectedOptions.value && multiple.value) {
4834
+ if (!!preselectedOptions.value.length && multiple.value) {
4821
4835
  const initialLength = selectedOptions.value.length;
4822
4836
 
4823
4837
  setPreselectedOptions(preselectedOptions.value);
@@ -5056,6 +5070,7 @@ const updateModelValue = () => {
5056
5070
  * @listens extended:rollup-options
5057
5071
  * @listens extended:toggle-options
5058
5072
  * @listens extended:select-option
5073
+ * @listens extended:preselect-option
5059
5074
  * @listens extended:deselect-option
5060
5075
  * @listens extended:create-option
5061
5076
  * @listens extended:increase-display
@@ -5109,6 +5124,16 @@ onBeforeMount(() => {
5109
5124
  updateModelValue();
5110
5125
  });
5111
5126
 
5127
+ emitter.value.on("extended:preselect-option", (option) => {
5128
+ if (multiple.value) {
5129
+ selectedOptions.value.push(option.option);
5130
+ } else {
5131
+ selectedOptions.value = [option.option];
5132
+ }
5133
+
5134
+ updateModelValue();
5135
+ });
5136
+
5112
5137
  emitter.value.on("extended:deselect-option", (payload) => {
5113
5138
  if (multiple.value && (payload && !payload.clearAll)) {
5114
5139
  const deselectedOption = selectedOptions.value[payload.index];