slim-select 4.0.6 → 4.0.7

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.
@@ -1549,6 +1549,11 @@ var F = class {
1549
1549
  getSelectedValues() {
1550
1550
  return this.getSelectedOptions().map((e) => e.value);
1551
1551
  }
1552
+ hasOptionValues(e) {
1553
+ if (e.length === 0) return !0;
1554
+ let t = new Set(Array.from(this.select.options).map((e) => e.value));
1555
+ return e.every((e) => t.has(e));
1556
+ }
1552
1557
  setSelected(e) {
1553
1558
  this.changeListen(!1);
1554
1559
  let t = this.select.childNodes;
@@ -1593,13 +1598,14 @@ var F = class {
1593
1598
  })), this.changeListen(!0);
1594
1599
  }
1595
1600
  updateOptions(e) {
1596
- if (!(!e || e.length === 0)) {
1597
- this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1), this.select.innerHTML = "";
1598
- for (let t of e) t instanceof j && this.select.appendChild(this.createOptgroup(t)), t instanceof A && this.select.appendChild(this.createOption(t));
1599
- if (this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
1600
- let e = this.pendingOptionsChange;
1601
- e.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(e), this.changeListen(!0)) : this.pendingOptionsChange = null;
1602
- }
1601
+ if (!e || e.length === 0) return;
1602
+ this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1);
1603
+ let t = this.getSelectedValues();
1604
+ this.select.innerHTML = "";
1605
+ for (let t of e) t instanceof j && this.select.appendChild(this.createOptgroup(t)), t instanceof A && this.select.appendChild(this.createOption(t));
1606
+ if (v(t, this.getSelectedValues()) || this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
1607
+ let e = this.pendingOptionsChange;
1608
+ e.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(e), this.changeListen(!0)) : this.pendingOptionsChange = null;
1603
1609
  }
1604
1610
  }
1605
1611
  createOptgroup(e) {
@@ -1731,12 +1737,30 @@ var R = class {
1731
1737
  }
1732
1738
  i.setData(e, n);
1733
1739
  let u = i.getData(!1);
1734
- r || i.snapshotCatalog(), a.updateOptions(u), o.renderValues(), o.renderOptions(u), s.afterChange && !v(c, i.getSelected()) && s.afterChange(i.getSelectedOptions());
1740
+ r || i.snapshotCatalog(), r || a.updateOptions(u), o.renderValues(), o.renderOptions(u), s.afterChange && !v(c, i.getSelected()) && s.afterChange(i.getSelectedOptions());
1741
+ }
1742
+ syncNativeSelection() {
1743
+ let { store: e, select: t } = this.deps, n = e.getSelectedOptions(), r = e.getSelectedValues();
1744
+ if (!t.hasOptionValues(r)) {
1745
+ if (n.length > 0) {
1746
+ t.updateOptions(n);
1747
+ return;
1748
+ }
1749
+ let r = e.getCatalogData().find((e) => e instanceof A && e.placeholder === !0);
1750
+ if (r) {
1751
+ t.updateOptions([new A({
1752
+ ...r,
1753
+ selected: !0
1754
+ })]);
1755
+ return;
1756
+ }
1757
+ }
1758
+ t.setSelectedByValue(r);
1735
1759
  }
1736
1760
  applySelection(e, t, n) {
1737
1761
  let { store: r, select: i, render: a, events: o } = this.deps, s = r.getSelected(), c = L(r, e);
1738
1762
  if (v(s, c)) return;
1739
- r.setSelectedBy("id", c), i.setSelectedByValue(r.getSelectedValues()), a.renderValues();
1763
+ r.setSelectedBy("id", c), this.syncNativeSelection(), a.renderValues();
1740
1764
  let l = a.content.search.input.value.trim();
1741
1765
  l === "" ? a.canUpdateOptionSelectionInPlace() ? a.updateOptionSelection() : a.renderOptions(r.getData(!1)) : a.hasRenderedOptions() ? a.updateOptionSelection() : this.deps.search && this.deps.search(l), n && o.afterChange && !v(s, r.getSelected()) && o.afterChange(r.getSelectedOptions());
1742
1766
  }
@@ -1756,7 +1780,11 @@ var R = class {
1756
1780
  c(n) || t.setData([...n, new A(e)], !0), t.snapshotCatalog();
1757
1781
  } else t.addOption(e), t.snapshotCatalog();
1758
1782
  let l = t.getData(!1);
1759
- n.updateOptions(l), r.renderValues(), r.renderOptions(l), i.afterChange && !v(a, t.getSelected()) && i.afterChange(t.getSelectedOptions());
1783
+ if (o) {
1784
+ let e = t.getSelectedOptions();
1785
+ e.length > 0 && n.updateOptions(e);
1786
+ } else n.updateOptions(l);
1787
+ r.renderValues(), r.renderOptions(l), i.afterChange && !v(a, t.getSelected()) && i.afterChange(t.getSelectedOptions());
1760
1788
  }
1761
1789
  }, z = class {
1762
1790
  selectEl;