@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/benchmarks/selectbox-value-lookup.mjs +311 -0
- package/dist/lib.cjs.js +63 -9
- package/dist/lib.cjs.js.map +1 -1
- package/dist/lib.cjs.min.js +2 -2
- package/dist/lib.cjs.min.js.map +1 -1
- package/dist/lib.es6.js +62 -8
- package/dist/lib.es6.js.map +1 -1
- package/dist/lib.es6.min.js +2 -2
- package/dist/lib.es6.min.js.map +1 -1
- package/dist/lib.umd.js +63 -9
- package/dist/lib.umd.js.map +1 -1
- package/dist/lib.umd.min.js +2 -2
- package/dist/lib.umd.min.js.map +1 -1
- package/eslint.config.mjs +1 -1
- package/lib/SelectBox.js +61 -7
- package/package.json +2 -1
package/dist/lib.es6.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @danielgindi/selectbox 2.0.
|
|
2
|
+
* @danielgindi/selectbox 2.0.53
|
|
3
3
|
* git://github.com/danielgindi/selectbox.git
|
|
4
4
|
*/
|
|
5
5
|
import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
|
|
@@ -3990,7 +3990,7 @@ class SelectBox {
|
|
|
3990
3990
|
p.items = items.slice(0);
|
|
3991
3991
|
p.itemsChanged = true;
|
|
3992
3992
|
|
|
3993
|
-
this.
|
|
3993
|
+
this._refreshItemByValueMap();
|
|
3994
3994
|
|
|
3995
3995
|
if (resetValues) {
|
|
3996
3996
|
this.setSelectedValues(this.getSelectedValues());
|
|
@@ -4021,10 +4021,17 @@ class SelectBox {
|
|
|
4021
4021
|
updateItemByValue(value, newItem) {
|
|
4022
4022
|
const p = this._p;
|
|
4023
4023
|
|
|
4024
|
-
let existingItem =
|
|
4025
|
-
if (existingItem)
|
|
4024
|
+
let existingItem = this._getItemByValue(value);
|
|
4025
|
+
if (existingItem) {
|
|
4026
|
+
const valueProp = existingItem[p.valueProp];
|
|
4027
|
+
if (p.itemByValueMap?.has(valueProp))
|
|
4028
|
+
p.itemByValueMap.delete(valueProp);
|
|
4029
|
+
|
|
4026
4030
|
Object.assign(existingItem, newItem);
|
|
4027
4031
|
|
|
4032
|
+
p.itemByValueMap.set(existingItem[p.valueProp], existingItem);
|
|
4033
|
+
}
|
|
4034
|
+
|
|
4028
4035
|
if (p.dropList) {
|
|
4029
4036
|
p.dropList.updateItemByValue(value, newItem);
|
|
4030
4037
|
}
|
|
@@ -4594,7 +4601,7 @@ class SelectBox {
|
|
|
4594
4601
|
if (p.dropList)
|
|
4595
4602
|
p.dropList.setValueProp(prop);
|
|
4596
4603
|
|
|
4597
|
-
this.
|
|
4604
|
+
this._refreshItemByValueMap();
|
|
4598
4605
|
|
|
4599
4606
|
return this;
|
|
4600
4607
|
}
|
|
@@ -4780,7 +4787,7 @@ class SelectBox {
|
|
|
4780
4787
|
|
|
4781
4788
|
selectedValues.push(value);
|
|
4782
4789
|
|
|
4783
|
-
let item =
|
|
4790
|
+
let item = this._getItemByValue(value);
|
|
4784
4791
|
if (item !== undefined) {
|
|
4785
4792
|
selectedItems.push(item);
|
|
4786
4793
|
} else {
|
|
@@ -5075,7 +5082,7 @@ class SelectBox {
|
|
|
5075
5082
|
* This reduces search time greatly (i.e when checking items), especially when Vue proxies are in place.
|
|
5076
5083
|
* @private
|
|
5077
5084
|
*/
|
|
5078
|
-
|
|
5085
|
+
_refreshItemByValueMap() {
|
|
5079
5086
|
const p = this._p;
|
|
5080
5087
|
|
|
5081
5088
|
const itemByValueMap = p.itemByValueMap = new Map();
|
|
@@ -5083,6 +5090,52 @@ class SelectBox {
|
|
|
5083
5090
|
for (let item of p.items) {
|
|
5084
5091
|
itemByValueMap.set(item[valueProp], item);
|
|
5085
5092
|
}
|
|
5093
|
+
|
|
5094
|
+
p.subitemByValueMap = null;
|
|
5095
|
+
}
|
|
5096
|
+
|
|
5097
|
+
/**
|
|
5098
|
+
* @param {*} value
|
|
5099
|
+
* @returns {DropList.ItemBase|undefined}
|
|
5100
|
+
* @private
|
|
5101
|
+
*/
|
|
5102
|
+
_getItemByValue(value) {
|
|
5103
|
+
const p = this._p;
|
|
5104
|
+
let item = p.itemByValueMap.get(value);
|
|
5105
|
+
if (item !== undefined)
|
|
5106
|
+
return item;
|
|
5107
|
+
|
|
5108
|
+
if (!p.subitemByValueMap)
|
|
5109
|
+
this._refreshSubitemByValueMap();
|
|
5110
|
+
|
|
5111
|
+
return p.subitemByValueMap.get(value);
|
|
5112
|
+
}
|
|
5113
|
+
|
|
5114
|
+
/** @private */
|
|
5115
|
+
_refreshSubitemByValueMap() {
|
|
5116
|
+
const p = this._p;
|
|
5117
|
+
const subitemByValueMap = p.subitemByValueMap = new Map();
|
|
5118
|
+
this._addSubitemsToValueMap(p.items, subitemByValueMap, p.valueProp);
|
|
5119
|
+
}
|
|
5120
|
+
|
|
5121
|
+
/**
|
|
5122
|
+
* @param {DropList.ItemBase[]} items
|
|
5123
|
+
* @param {Map<*, DropList.ItemBase>} itemByValueMap
|
|
5124
|
+
* @param {string} valueProp
|
|
5125
|
+
* @private
|
|
5126
|
+
*/
|
|
5127
|
+
_addSubitemsToValueMap(items, itemByValueMap, valueProp) {
|
|
5128
|
+
for (let item of items) {
|
|
5129
|
+
if (!item._subitems?.length)
|
|
5130
|
+
continue;
|
|
5131
|
+
|
|
5132
|
+
for (let subitem of item._subitems) {
|
|
5133
|
+
if (!itemByValueMap.has(subitem[valueProp]))
|
|
5134
|
+
itemByValueMap.set(subitem[valueProp], subitem);
|
|
5135
|
+
}
|
|
5136
|
+
|
|
5137
|
+
this._addSubitemsToValueMap(item._subitems, itemByValueMap, valueProp);
|
|
5138
|
+
}
|
|
5086
5139
|
}
|
|
5087
5140
|
|
|
5088
5141
|
/** @private */
|
|
@@ -5467,7 +5520,8 @@ class SelectBox {
|
|
|
5467
5520
|
}
|
|
5468
5521
|
break;
|
|
5469
5522
|
|
|
5470
|
-
case 'select':
|
|
5523
|
+
case 'select':
|
|
5524
|
+
case 'subitems:select': {
|
|
5471
5525
|
if (p.multi) return;
|
|
5472
5526
|
|
|
5473
5527
|
const item = event.item;
|