@danielgindi/selectbox 2.0.52 → 2.0.53

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/dist/lib.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 2.0.52
2
+ * @danielgindi/selectbox 2.0.53
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  (function (global, factory) {
@@ -10479,7 +10479,7 @@
10479
10479
  p.items = items.slice(0);
10480
10480
  p.itemsChanged = true;
10481
10481
 
10482
- this._updateItemByValueMap();
10482
+ this._refreshItemByValueMap();
10483
10483
 
10484
10484
  if (resetValues) {
10485
10485
  this.setSelectedValues(this.getSelectedValues());
@@ -10510,9 +10510,16 @@
10510
10510
  updateItemByValue(value, newItem) {
10511
10511
  const p = this._p;
10512
10512
 
10513
- let existingItem = p.itemByValueMap.get(value);
10514
- if (existingItem)
10515
- Object.assign(existingItem, newItem);
10513
+ let existingItem = this._getItemByValue(value);
10514
+ if (existingItem) {var _p$itemByValueMap;
10515
+ const valueProp = existingItem[p.valueProp];
10516
+ if ((_p$itemByValueMap = p.itemByValueMap) !== null && _p$itemByValueMap !== void 0 && _p$itemByValueMap.has(valueProp))
10517
+ p.itemByValueMap.delete(valueProp);
10518
+
10519
+ Object.assign(existingItem, newItem);
10520
+
10521
+ p.itemByValueMap.set(existingItem[p.valueProp], existingItem);
10522
+ }
10516
10523
 
10517
10524
  if (p.dropList) {
10518
10525
  p.dropList.updateItemByValue(value, newItem);
@@ -11083,7 +11090,7 @@
11083
11090
  if (p.dropList)
11084
11091
  p.dropList.setValueProp(prop);
11085
11092
 
11086
- this._updateItemByValueMap();
11093
+ this._refreshItemByValueMap();
11087
11094
 
11088
11095
  return this;
11089
11096
  }
@@ -11269,7 +11276,7 @@
11269
11276
 
11270
11277
  selectedValues.push(value);
11271
11278
 
11272
- let item = p.itemByValueMap.get(value);
11279
+ let item = this._getItemByValue(value);
11273
11280
  if (item !== undefined) {
11274
11281
  selectedItems.push(item);
11275
11282
  } else {
@@ -11564,7 +11571,7 @@
11564
11571
  * This reduces search time greatly (i.e when checking items), especially when Vue proxies are in place.
11565
11572
  * @private
11566
11573
  */
11567
- _updateItemByValueMap() {
11574
+ _refreshItemByValueMap() {
11568
11575
  const p = this._p;
11569
11576
 
11570
11577
  const itemByValueMap = p.itemByValueMap = new Map();
@@ -11572,6 +11579,52 @@
11572
11579
  for (let item of p.items) {
11573
11580
  itemByValueMap.set(item[valueProp], item);
11574
11581
  }
11582
+
11583
+ p.subitemByValueMap = null;
11584
+ }
11585
+
11586
+ /**
11587
+ * @param {*} value
11588
+ * @returns {DropList.ItemBase|undefined}
11589
+ * @private
11590
+ */
11591
+ _getItemByValue(value) {
11592
+ const p = this._p;
11593
+ let item = p.itemByValueMap.get(value);
11594
+ if (item !== undefined)
11595
+ return item;
11596
+
11597
+ if (!p.subitemByValueMap)
11598
+ this._refreshSubitemByValueMap();
11599
+
11600
+ return p.subitemByValueMap.get(value);
11601
+ }
11602
+
11603
+ /** @private */
11604
+ _refreshSubitemByValueMap() {
11605
+ const p = this._p;
11606
+ const subitemByValueMap = p.subitemByValueMap = new Map();
11607
+ this._addSubitemsToValueMap(p.items, subitemByValueMap, p.valueProp);
11608
+ }
11609
+
11610
+ /**
11611
+ * @param {DropList.ItemBase[]} items
11612
+ * @param {Map<*, DropList.ItemBase>} itemByValueMap
11613
+ * @param {string} valueProp
11614
+ * @private
11615
+ */
11616
+ _addSubitemsToValueMap(items, itemByValueMap, valueProp) {
11617
+ for (let item of items) {var _item$_subitems;
11618
+ if (!((_item$_subitems = item._subitems) !== null && _item$_subitems !== void 0 && _item$_subitems.length))
11619
+ continue;
11620
+
11621
+ for (let subitem of item._subitems) {
11622
+ if (!itemByValueMap.has(subitem[valueProp]))
11623
+ itemByValueMap.set(subitem[valueProp], subitem);
11624
+ }
11625
+
11626
+ this._addSubitemsToValueMap(item._subitems, itemByValueMap, valueProp);
11627
+ }
11575
11628
  }
11576
11629
 
11577
11630
  /** @private */
@@ -11956,7 +12009,8 @@
11956
12009
  }
11957
12010
  break;
11958
12011
 
11959
- case 'select':{
12012
+ case 'select':
12013
+ case 'subitems:select':{
11960
12014
  if (p.multi) return;
11961
12015
 
11962
12016
  const item = event.item;