@danielgindi/selectbox 1.0.65 → 1.0.68
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.cjs.js +91 -35
- 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 +56 -14
- 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 +91 -35
- 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/lib/SelectBox.js +55 -13
- package/package.json +1 -1
package/dist/lib.es6.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @danielgindi/selectbox 1.0.
|
|
2
|
+
* @danielgindi/selectbox 1.0.68
|
|
3
3
|
* git://github.com/danielgindi/selectbox.git
|
|
4
4
|
*/
|
|
5
5
|
import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
|
|
@@ -2574,6 +2574,7 @@ class SelectBox {
|
|
|
2574
2574
|
}
|
|
2575
2575
|
|
|
2576
2576
|
this.setItems(o.items);
|
|
2577
|
+
delete o.items; // we do not need this in memory anymore
|
|
2577
2578
|
|
|
2578
2579
|
if (o.multi && Array.isArray(o.selectedValues)) {
|
|
2579
2580
|
this.setSelectedValues(o.selectedValues);
|
|
@@ -2725,6 +2726,8 @@ class SelectBox {
|
|
|
2725
2726
|
p.filteredItems = null;
|
|
2726
2727
|
p.itemsChanged = true;
|
|
2727
2728
|
|
|
2729
|
+
this._updateItemByValueMap();
|
|
2730
|
+
|
|
2728
2731
|
if (resetValues) {
|
|
2729
2732
|
this.setSelectedValues(this.getSelectedValues());
|
|
2730
2733
|
}
|
|
@@ -2754,9 +2757,9 @@ class SelectBox {
|
|
|
2754
2757
|
}
|
|
2755
2758
|
|
|
2756
2759
|
updateItemByValue(value, newItem) {
|
|
2757
|
-
const p = this._p
|
|
2760
|
+
const p = this._p;
|
|
2758
2761
|
|
|
2759
|
-
let existingItem = p.
|
|
2762
|
+
let existingItem = p.itemByValueMap.get(value);
|
|
2760
2763
|
if (existingItem)
|
|
2761
2764
|
Object.assign(existingItem, newItem);
|
|
2762
2765
|
|
|
@@ -3278,11 +3281,17 @@ class SelectBox {
|
|
|
3278
3281
|
*/
|
|
3279
3282
|
setValueProp(prop) {
|
|
3280
3283
|
const p = this._p;
|
|
3284
|
+
|
|
3285
|
+
if (p.valueProp === prop)
|
|
3286
|
+
return this;
|
|
3287
|
+
|
|
3281
3288
|
p.valueProp = prop;
|
|
3282
3289
|
|
|
3283
3290
|
if (p.dropList)
|
|
3284
3291
|
p.dropList.setValueProp(prop);
|
|
3285
3292
|
|
|
3293
|
+
this._updateItemByValueMap();
|
|
3294
|
+
|
|
3286
3295
|
return this;
|
|
3287
3296
|
}
|
|
3288
3297
|
|
|
@@ -3434,7 +3443,7 @@ class SelectBox {
|
|
|
3434
3443
|
|
|
3435
3444
|
selectedValues.push(value);
|
|
3436
3445
|
|
|
3437
|
-
let item = p.
|
|
3446
|
+
let item = p.itemByValueMap.get(value);
|
|
3438
3447
|
if (item !== undefined) {
|
|
3439
3448
|
selectedItems.push(item);
|
|
3440
3449
|
} else {
|
|
@@ -3655,6 +3664,21 @@ class SelectBox {
|
|
|
3655
3664
|
return this;
|
|
3656
3665
|
}
|
|
3657
3666
|
|
|
3667
|
+
/**
|
|
3668
|
+
* Prepare the mapping between values and items.
|
|
3669
|
+
* This reduces search time greatly (i.e when checking items), especially when Vue proxies are in place.
|
|
3670
|
+
* @private
|
|
3671
|
+
*/
|
|
3672
|
+
_updateItemByValueMap() {
|
|
3673
|
+
const p = this._p;
|
|
3674
|
+
|
|
3675
|
+
const itemByValueMap = p.itemByValueMap = new Map();
|
|
3676
|
+
const valueProp = p.valueProp;
|
|
3677
|
+
for (let item of p.items) {
|
|
3678
|
+
itemByValueMap.set(item[valueProp], item);
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
|
|
3658
3682
|
/** @private */
|
|
3659
3683
|
_renderBase() {
|
|
3660
3684
|
const p = this._p;
|
|
@@ -4725,15 +4749,18 @@ class SelectBox {
|
|
|
4725
4749
|
|
|
4726
4750
|
/**
|
|
4727
4751
|
* @param {DropList.ItemBase} item
|
|
4752
|
+
* @returns {boolean} true if rendered, false if not
|
|
4728
4753
|
* @private
|
|
4729
4754
|
*/
|
|
4730
4755
|
_addMultiItemElement(item) {
|
|
4731
4756
|
const p = this._p;
|
|
4732
4757
|
const itemEl = this._renderMultiItem(item);
|
|
4733
|
-
if (!itemEl) return;
|
|
4758
|
+
if (!itemEl) return false;
|
|
4734
4759
|
|
|
4735
4760
|
before(p.inputWrapper, itemEl);
|
|
4736
4761
|
p.multiItemEls.push(itemEl);
|
|
4762
|
+
|
|
4763
|
+
return true;
|
|
4737
4764
|
}
|
|
4738
4765
|
|
|
4739
4766
|
/** @private */
|
|
@@ -4755,10 +4782,13 @@ class SelectBox {
|
|
|
4755
4782
|
|
|
4756
4783
|
/** @private */
|
|
4757
4784
|
_syncClearButton() {
|
|
4758
|
-
const p = this._p
|
|
4785
|
+
const p = this._p,
|
|
4786
|
+
multiItemLabelProp = p.multiItemLabelProp;
|
|
4759
4787
|
|
|
4760
4788
|
// Set clear button
|
|
4761
|
-
if (p.selectedItems.length > 0 &&
|
|
4789
|
+
if (p.selectedItems.length > 0 &&
|
|
4790
|
+
p.selectedItems.some(x => x[multiItemLabelProp] !== false) &&
|
|
4791
|
+
p.clearable && p.showSelection) {
|
|
4762
4792
|
if (!p.clearButtonWrapper) {
|
|
4763
4793
|
p.clearButtonWrapper = createElement(
|
|
4764
4794
|
p.multi ? 'li' : 'span',
|
|
@@ -4788,7 +4818,8 @@ class SelectBox {
|
|
|
4788
4818
|
|
|
4789
4819
|
/** @private */
|
|
4790
4820
|
_syncPlaceholder() {
|
|
4791
|
-
const p = this._p
|
|
4821
|
+
const p = this._p,
|
|
4822
|
+
multiItemLabelProp = p.multiItemLabelProp;
|
|
4792
4823
|
|
|
4793
4824
|
let placeholder = '';
|
|
4794
4825
|
|
|
@@ -4798,7 +4829,9 @@ class SelectBox {
|
|
|
4798
4829
|
} else {
|
|
4799
4830
|
placeholder = defaultMultiPlaceholderFormatter(p.selectedItems, p.labelProp);
|
|
4800
4831
|
}
|
|
4801
|
-
} else if (p.selectedItems.length === 0 ||
|
|
4832
|
+
} else if (p.selectedItems.length === 0 ||
|
|
4833
|
+
!p.showSelection ||
|
|
4834
|
+
p.selectedItems.every(x => x[multiItemLabelProp] === false)) {
|
|
4802
4835
|
placeholder = p.placeholder == null ? '' : (p.placeholder + '');
|
|
4803
4836
|
}
|
|
4804
4837
|
|
|
@@ -4827,13 +4860,16 @@ class SelectBox {
|
|
|
4827
4860
|
* @returns {SelectBox}
|
|
4828
4861
|
*/
|
|
4829
4862
|
_syncFull(fullItemsRender) {
|
|
4830
|
-
const p = this._p
|
|
4863
|
+
const p = this._p,
|
|
4864
|
+
multiItemLabelProp = p.multiItemLabelProp;
|
|
4831
4865
|
|
|
4832
4866
|
this._renderBase();
|
|
4833
4867
|
this._syncClearButton();
|
|
4834
4868
|
this._syncPlaceholder();
|
|
4835
4869
|
|
|
4836
|
-
fullItemsRender = p.multi &&
|
|
4870
|
+
fullItemsRender = p.multi &&
|
|
4871
|
+
p.showSelection &&
|
|
4872
|
+
(fullItemsRender || p.selectedItems.filter(x => x[multiItemLabelProp] !== false).length !== p.multiItemEls.length);
|
|
4837
4873
|
|
|
4838
4874
|
if (fullItemsRender || !p.showSelection || !p.multi) {
|
|
4839
4875
|
// Remove all item elements
|
|
@@ -4886,8 +4922,9 @@ class SelectBox {
|
|
|
4886
4922
|
break;
|
|
4887
4923
|
}
|
|
4888
4924
|
|
|
4889
|
-
|
|
4890
|
-
|
|
4925
|
+
if (this._addMultiItemElement(items[i])) {
|
|
4926
|
+
actualItemCount++;
|
|
4927
|
+
}
|
|
4891
4928
|
}
|
|
4892
4929
|
|
|
4893
4930
|
if (addRestItem) {
|
|
@@ -5416,6 +5453,11 @@ class SelectBox {
|
|
|
5416
5453
|
stickyGroup = groups[0].filter(x => stickyValues.has(x[valueProp]));
|
|
5417
5454
|
if (stickyGroup.length > 0) {
|
|
5418
5455
|
groups[0] = groups[0].filter(x => !stickyValues.has(x[valueProp]));
|
|
5456
|
+
|
|
5457
|
+
if (groups[0].length === 0)
|
|
5458
|
+
groups.shift();
|
|
5459
|
+
} else {
|
|
5460
|
+
stickyGroup = null;
|
|
5419
5461
|
}
|
|
5420
5462
|
}
|
|
5421
5463
|
|
|
@@ -5440,7 +5482,7 @@ class SelectBox {
|
|
|
5440
5482
|
});
|
|
5441
5483
|
}
|
|
5442
5484
|
|
|
5443
|
-
if (stickyGroup
|
|
5485
|
+
if (stickyGroup) {
|
|
5444
5486
|
groups.unshift(stickyGroup);
|
|
5445
5487
|
}
|
|
5446
5488
|
|