vue3-extended-multiselect 2.2.3 → 2.3.1

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.
@@ -341,12 +341,12 @@ const _hoisted_2$e = /*#__PURE__*/createElementVNode("g", null, [
341
341
  /*#__PURE__*/createElementVNode("path", { d: "M96.1,103.6c-10.4,8.4-23.5,12.4-36.8,11.1c-10.5-1-20.3-5.1-28.2-11.8H44v-8H18v26h8v-11.9c9.1,7.7,20.4,12.5,32.6,13.6 c1.9,0.2,3.7,0.3,5.5,0.3c13.5,0,26.5-4.6,37-13.2c19.1-15.4,26.6-40.5,19.1-63.9l-7.6,2.4C119,68.6,112.6,90.3,96.1,103.6z" }),
342
342
  /*#__PURE__*/createElementVNode("path", { d: "M103,19.7c-21.2-18.7-53.5-20-76.1-1.6C7.9,33.5,0.4,58.4,7.7,81.7l7.6-2.4C9,59.2,15.5,37.6,31.9,24.4 C51.6,8.4,79.7,9.6,98,26H85v8h26V8h-8V19.7z" })
343
343
  ], -1 /* HOISTED */);
344
- const _hoisted_3$7 = [
344
+ const _hoisted_3$8 = [
345
345
  _hoisted_2$e
346
346
  ];
347
347
 
348
348
  function render$8(_ctx, _cache) {
349
- return (openBlock(), createElementBlock("svg", _hoisted_1$f, [..._hoisted_3$7]))
349
+ return (openBlock(), createElementBlock("svg", _hoisted_1$f, [..._hoisted_3$8]))
350
350
  }
351
351
 
352
352
  const script$f = {};
@@ -762,6 +762,7 @@ const _hoisted_2$b = {
762
762
  key: 0,
763
763
  class: "extended__multiselect-placeholder"
764
764
  };
765
+ const _hoisted_3$7 = ["onClick"];
765
766
 
766
767
 
767
768
  var script$b = {
@@ -1107,20 +1108,20 @@ return (_ctx, _cache) => {
1107
1108
  }, [
1108
1109
  createElementVNode("span", null, toDisplayString(unref(optionCreateLabel)(option)), 1 /* TEXT */),
1109
1110
  createElementVNode("div", {
1110
- class: normalizeClass(deselectClasses.value)
1111
+ class: normalizeClass(deselectClasses.value),
1112
+ onClick: withModifiers($event => (deselectBlock(index)), ["stop"])
1111
1113
  }, [
1112
1114
  (!showLoaderIcon.value)
1113
1115
  ? (openBlock(), createBlock(script$d, {
1114
1116
  key: 0,
1115
- class: "extended__multiselect_deselect-block-icon",
1116
- onClick: withModifiers($event => (deselectBlock(index)), ["stop"])
1117
- }, null, 8 /* PROPS */, ["onClick"]))
1117
+ class: "extended__multiselect_deselect-block-icon"
1118
+ }))
1118
1119
  : (openBlock(), createBlock(script$e, {
1119
1120
  key: 1,
1120
1121
  "icon-filter": __props.iconFilter,
1121
1122
  "icon-size": "deselect"
1122
1123
  }, null, 8 /* PROPS */, ["icon-filter"]))
1123
- ], 2 /* CLASS */)
1124
+ ], 10 /* CLASS, PROPS */, _hoisted_3$7)
1124
1125
  ], 2 /* CLASS */)
1125
1126
  ])
1126
1127
  ]))
@@ -1573,7 +1574,7 @@ watch(searchValue, (value) => {
1573
1574
  * @function
1574
1575
  * @emits extended:expand-options
1575
1576
  */
1576
- const expand = () => {
1577
+ const expand = (event) => {
1577
1578
  if (disabled.value) return;
1578
1579
 
1579
1580
  searchFieldFocused.value = true;
@@ -1625,6 +1626,24 @@ const rollUp = () => {
1625
1626
  emitter.value.emit("extended:rollup-options", true);
1626
1627
  };
1627
1628
 
1629
+ /**
1630
+ * Rolls up options list after option selection
1631
+ * and sets single option label
1632
+ * @function
1633
+ * @param {UnionPropType} option - option to be selected
1634
+ */
1635
+ const rollupIfSelected = (option) => {
1636
+ if (toggleOptionsBySelect.value) {
1637
+ rollUp();
1638
+ }
1639
+
1640
+ if (multiple.value) {
1641
+ return;
1642
+ } else {
1643
+ singleLabel.value = option.label;
1644
+ }
1645
+ };
1646
+
1628
1647
  /**
1629
1648
  * Activates debounced version of options list filter
1630
1649
  * @function
@@ -1638,6 +1657,7 @@ const search = () => {
1638
1657
  * @listens extended:field-focus
1639
1658
  * @listens extended:rollup-options
1640
1659
  * @listens extended:select-option
1660
+ * @listens extended:preselect-option
1641
1661
  * @listens extended:deselect-option
1642
1662
  * @listens extended:clean-options
1643
1663
  * @listens extended:clear-field
@@ -1661,16 +1681,11 @@ onBeforeMount(() => {
1661
1681
  });
1662
1682
 
1663
1683
  emitter.value.on("extended:select-option", (option) => {
1684
+ rollupIfSelected(option);
1685
+ });
1664
1686
 
1665
- if (toggleOptionsBySelect.value) {
1666
- rollUp();
1667
- }
1668
-
1669
- if (multiple.value) {
1670
- return;
1671
- } else {
1672
- singleLabel.value = option.label;
1673
- }
1687
+ emitter.value.on("extended:preselect-option", (option) => {
1688
+ rollupIfSelected(option);
1674
1689
  });
1675
1690
 
1676
1691
  emitter.value.on("extended:deselect-option", () => {
@@ -3614,7 +3629,7 @@ const _hoisted_3 = { class: "extended__multiselect-cancel_wrapper" };
3614
3629
 
3615
3630
  /**
3616
3631
  * @author Ridiger Daniil Dmitrievich, 2022
3617
- * @version 2.2.2
3632
+ * @version 2.3.1
3618
3633
  */
3619
3634
 
3620
3635
  var script = {
@@ -4285,6 +4300,7 @@ const togglePattern = /^extended__multiselect-toggle_wrapper/i;
4285
4300
  const extendedMultiselect = ref(null);
4286
4301
  const extendedMultiselectToggle = ref(null);
4287
4302
  const extendedMultiselectWrapper = ref(null);
4303
+ const extendedMultiselectOptions = ref(null);
4288
4304
 
4289
4305
  const {
4290
4306
  defaultExpanded,
@@ -4696,7 +4712,7 @@ const selectByEnter = (keyboardEvent) => {
4696
4712
  /**
4697
4713
  * Sets preselected option provided by "preselectedOption" prop
4698
4714
  * @function
4699
- * @emits extended:select-option
4715
+ * @emits extended:preselect-option
4700
4716
  * @param {UnionPropType} preselectedOption - option to be selected
4701
4717
  * @param {boolean} restriction - restriction of preselected option
4702
4718
  */
@@ -4721,7 +4737,7 @@ const setPreselectedOption = (preselectedOption, restriction = true) => {
4721
4737
  const isObjectOrArray = typeof preselectedOption === "object";
4722
4738
  const label = createLabel(isObjectOrArray, preselectedOption);
4723
4739
 
4724
- emitter.value.emit("extended:select-option", {
4740
+ emitter.value.emit("extended:preselect-option", {
4725
4741
  label,
4726
4742
  option: preselectedOption,
4727
4743
  });
@@ -4731,7 +4747,7 @@ const setPreselectedOption = (preselectedOption, restriction = true) => {
4731
4747
  * Sets preselected options provided by "preselectedOptions" prop
4732
4748
  * if "multiple" prop equals true
4733
4749
  * @function
4734
- * @emits extended:select-option
4750
+ * @emits extended:preselect-option
4735
4751
  * @param {Array} preselectedOptions - options to be selected
4736
4752
  * @param {boolean} restriction - restriction of preselected options
4737
4753
  */
@@ -4756,7 +4772,7 @@ const setPreselectedOptions = async (preselectedOptions, restriction = true) =>
4756
4772
 
4757
4773
  allOptionsWereSelected++;
4758
4774
 
4759
- emitter.value.emit("extended:select-option", {
4775
+ emitter.value.emit("extended:preselect-option", {
4760
4776
  label,
4761
4777
  option: preselectedOption,
4762
4778
  });
@@ -4780,7 +4796,7 @@ const setPreselectedOptionsByModelValue = (withRemoval = false) => {
4780
4796
 
4781
4797
  if (withRemoval) selectedOptionsWatcher.value();
4782
4798
 
4783
- if (multiple.value) {
4799
+ if (Array.isArray(modelValue.value) && multiple.value) {
4784
4800
  if (withRemoval) removeSelectedOptions();
4785
4801
 
4786
4802
  setPreselectedOptions(modelValue.value, false);
@@ -4817,7 +4833,7 @@ const setPreselectedOptionsByConditions = () => {
4817
4833
  }
4818
4834
  }
4819
4835
 
4820
- if (preselectedOptions.value && multiple.value) {
4836
+ if (!!preselectedOptions.value.length && multiple.value) {
4821
4837
  const initialLength = selectedOptions.value.length;
4822
4838
 
4823
4839
  setPreselectedOptions(preselectedOptions.value);
@@ -4834,15 +4850,17 @@ const setPreselectedOptionsByConditions = () => {
4834
4850
  * @returns {string} position
4835
4851
  */
4836
4852
  const toggleAppearanceRestrictor = () => {
4837
- if (!window) return "under";
4853
+ if (!window || !extendedMultiselectOptions.value.$el) return "under";
4838
4854
 
4839
4855
  const innerHeight = window.innerHeight;
4856
+ const offsetHeight = extendedMultiselectOptions.value.$el.offsetHeight
4857
+ + extendedMultiselect.value.offsetHeight;
4840
4858
  const offsetTop = extendedMultiselect.value
4841
4859
  ? extendedMultiselect.value.getBoundingClientRect().y
4842
4860
  : 0;
4843
4861
  const difference = innerHeight - offsetTop;
4844
4862
 
4845
- if (difference > toggleMaxHeight.value) {
4863
+ if (difference > offsetHeight) {
4846
4864
  return "under";
4847
4865
  } else {
4848
4866
  return "atop";
@@ -4854,7 +4872,7 @@ const toggleAppearanceRestrictor = () => {
4854
4872
  * @function
4855
4873
  */
4856
4874
  const toggleAppearanceRestrictorActivate = () => {
4857
- if (!dropdownActive.value) {
4875
+ if (dropdownActive.value) {
4858
4876
  chosenToggleAppearanceSide.value = toggleAppearanceSide.value !== "auto"
4859
4877
  ? toggleAppearanceSide.value
4860
4878
  : toggleAppearanceRestrictor();
@@ -4974,15 +4992,17 @@ const toggleDetector = (mouseEvent, pattern, mode) => {
4974
4992
  const toggleOptions = () => {
4975
4993
  if (internalLoading.value || disabled.value || dropdownDisabled.value) return;
4976
4994
 
4977
- toggleAppearanceRestrictorActivate();
4995
+ dropdownActive.value = !dropdownActive.value;
4996
+
4997
+ nextTick(() => {
4998
+ toggleAppearanceRestrictorActivate();
4999
+ });
4978
5000
 
4979
5001
  if (!dropdownActive.value) {
4980
5002
  activeEmitter();
4981
5003
  } else {
4982
5004
  closeEmitter();
4983
5005
  }
4984
-
4985
- dropdownActive.value = !dropdownActive.value;
4986
5006
  };
4987
5007
 
4988
5008
  /**
@@ -5056,6 +5076,7 @@ const updateModelValue = () => {
5056
5076
  * @listens extended:rollup-options
5057
5077
  * @listens extended:toggle-options
5058
5078
  * @listens extended:select-option
5079
+ * @listens extended:preselect-option
5059
5080
  * @listens extended:deselect-option
5060
5081
  * @listens extended:create-option
5061
5082
  * @listens extended:increase-display
@@ -5109,6 +5130,16 @@ onBeforeMount(() => {
5109
5130
  updateModelValue();
5110
5131
  });
5111
5132
 
5133
+ emitter.value.on("extended:preselect-option", (option) => {
5134
+ if (multiple.value) {
5135
+ selectedOptions.value.push(option.option);
5136
+ } else {
5137
+ selectedOptions.value = [option.option];
5138
+ }
5139
+
5140
+ updateModelValue();
5141
+ });
5142
+
5112
5143
  emitter.value.on("extended:deselect-option", (payload) => {
5113
5144
  if (multiple.value && (payload && !payload.clearAll)) {
5114
5145
  const deselectedOption = selectedOptions.value[payload.index];
@@ -5238,15 +5269,21 @@ onMounted(() => {
5238
5269
  && typeof options.value !== "function"
5239
5270
  ) {
5240
5271
  dropdownActive.value = true;
5272
+
5273
+ nextTick(() => {
5274
+ toggleAppearanceRestrictorActivate();
5275
+ });
5241
5276
  }
5242
5277
 
5243
5278
  emitter.value.on("extended:expand-options", () => {
5244
5279
  if (dropdownActive.value || dropdownDisabled.value) return;
5245
-
5246
- toggleAppearanceRestrictorActivate();
5247
- activeEmitter();
5248
-
5280
+
5249
5281
  dropdownActive.value = true;
5282
+
5283
+ nextTick(() => {
5284
+ toggleAppearanceRestrictorActivate();
5285
+ });
5286
+ activeEmitter();
5250
5287
  });
5251
5288
 
5252
5289
  emitter.value.on("extended:loader-pattern-changed", async (pattern) => {
@@ -5426,6 +5463,8 @@ return (_ctx, _cache) => {
5426
5463
  (dropdownActive.value)
5427
5464
  ? (openBlock(), createBlock(script$9, {
5428
5465
  key: 0,
5466
+ ref_key: "extendedMultiselectOptions",
5467
+ ref: extendedMultiselectOptions,
5429
5468
  "auto-select-created-option": __props.autoSelectCreatedOption,
5430
5469
  "clear-by-select-when-multiple": __props.clearBySelectWhenMultiple,
5431
5470
  "create-on-the-go": __props.createOnTheGo,