@danielgindi/selectbox 2.0.51 → 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/css/droplist.css +1 -1
- package/css/droplist.css.map +1 -1
- package/dist/lib.cjs.js +118 -15
- 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 +151 -48
- 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 +118 -15
- 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/DropList.js +90 -41
- package/lib/SelectBox.js +61 -7
- package/package.json +2 -1
- package/scss/droplist.scss +11 -8
- package/vue/DropList.vue +51 -31
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';
|
|
@@ -91,7 +91,8 @@ const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
|
91
91
|
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderNoResultsItem]
|
|
92
92
|
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderNoResultsItem]
|
|
93
93
|
* @property {function(name: string, data: *)} [on]
|
|
94
|
-
* @property {boolean} [isHeaderVisible=false] show header element
|
|
94
|
+
* @property {boolean} [isHeaderVisible=false] show header element
|
|
95
|
+
* @property {boolean} [isFooterVisible=false] show footer element
|
|
95
96
|
* @property {boolean} [searchable=false] include inline search box
|
|
96
97
|
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
97
98
|
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
@@ -164,7 +165,8 @@ const DefaultOptions$1 = {
|
|
|
164
165
|
|
|
165
166
|
on: null,
|
|
166
167
|
|
|
167
|
-
isHeaderVisible: false,
|
|
168
|
+
isHeaderVisible: false,
|
|
169
|
+
isFooterVisible: false,
|
|
168
170
|
searchable: false,
|
|
169
171
|
noResultsText: 'No matching results',
|
|
170
172
|
filterThrottleWindow: 300,
|
|
@@ -237,7 +239,8 @@ class DropList {
|
|
|
237
239
|
positionOptionsProvider: o.positionOptionsProvider ?? null,
|
|
238
240
|
|
|
239
241
|
searchable: o.searchable,
|
|
240
|
-
isHeaderVisible: o.isHeaderVisible,
|
|
242
|
+
isHeaderVisible: o.isHeaderVisible,
|
|
243
|
+
isFooterVisible: o.isFooterVisible,
|
|
241
244
|
|
|
242
245
|
silenceEvents: true,
|
|
243
246
|
mitt: mitt(),
|
|
@@ -291,20 +294,27 @@ class DropList {
|
|
|
291
294
|
menuEl.role = 'menu';
|
|
292
295
|
p.menuEl = menuEl;
|
|
293
296
|
|
|
294
|
-
p.headerEl = createElement('div', {
|
|
295
|
-
class: p.baseClassName + '_header',
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (o.
|
|
303
|
-
this.
|
|
304
|
-
|
|
305
|
-
wrapperEl.appendChild(menuEl);
|
|
297
|
+
p.headerEl = createElement('div', {
|
|
298
|
+
class: p.baseClassName + '_header',
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
p.footerEl = createElement('div', {
|
|
302
|
+
class: p.baseClassName + '_footer',
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
if (o.searchable) {
|
|
306
|
+
this.setSearchable(true);
|
|
307
|
+
}
|
|
306
308
|
|
|
307
|
-
|
|
309
|
+
if (o.isHeaderVisible)
|
|
310
|
+
this.setHeaderVisible(o.isHeaderVisible);
|
|
311
|
+
|
|
312
|
+
wrapperEl.appendChild(menuEl);
|
|
313
|
+
|
|
314
|
+
if (o.isFooterVisible)
|
|
315
|
+
this.setFooterVisible(o.isFooterVisible);
|
|
316
|
+
|
|
317
|
+
p.items = [];
|
|
308
318
|
p.groupCount = 0; // This will keep state of how many `group` items we have
|
|
309
319
|
p.mouseHandled = false;
|
|
310
320
|
|
|
@@ -1555,17 +1565,23 @@ class DropList {
|
|
|
1555
1565
|
let verticalBorderWidth = (parseFloat(elComputedStyle.borderTopWidth) || 0) +
|
|
1556
1566
|
(parseFloat(elComputedStyle.borderBottomWidth) || 0);
|
|
1557
1567
|
|
|
1558
|
-
let headerHeight = 0;
|
|
1559
|
-
if (p.headerEl) {
|
|
1560
|
-
headerHeight = getElementHeight(p.headerEl, true, true);
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1568
|
+
let headerHeight = 0;
|
|
1569
|
+
if (p.headerEl) {
|
|
1570
|
+
headerHeight = getElementHeight(p.headerEl, true, true);
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
let footerHeight = 0;
|
|
1574
|
+
if (p.footerEl) {
|
|
1575
|
+
footerHeight = getElementHeight(p.footerEl, true, true);
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
if (p.virtualListHelper.isVirtual()) {
|
|
1579
|
+
maxViewHeight =
|
|
1580
|
+
p.virtualListHelper.estimateFullHeight() +
|
|
1581
|
+
verticalPadding +
|
|
1582
|
+
verticalBorderWidth +
|
|
1583
|
+
headerHeight +
|
|
1584
|
+
footerHeight;
|
|
1569
1585
|
} else {
|
|
1570
1586
|
// Another method to calculate height is measuring the whole thing at once.
|
|
1571
1587
|
// This causes relayout of course.
|
|
@@ -1706,12 +1722,12 @@ class DropList {
|
|
|
1706
1722
|
viewCss.left += 'px';
|
|
1707
1723
|
viewCss.top += 'px';
|
|
1708
1724
|
setCssProps(el, viewCss);
|
|
1709
|
-
setElementHeight(el, viewSize.height, true, true);
|
|
1710
|
-
|
|
1711
|
-
if (menuEl !== el) {
|
|
1712
|
-
let menuHeight = viewSize.height - headerHeight - verticalBorderWidth - verticalPadding;
|
|
1713
|
-
setElementHeight(menuEl, menuHeight, true, true);
|
|
1714
|
-
}
|
|
1725
|
+
setElementHeight(el, viewSize.height, true, true);
|
|
1726
|
+
|
|
1727
|
+
if (menuEl !== el) {
|
|
1728
|
+
let menuHeight = viewSize.height - headerHeight - footerHeight - verticalBorderWidth - verticalPadding;
|
|
1729
|
+
setElementHeight(menuEl, menuHeight, true, true);
|
|
1730
|
+
}
|
|
1715
1731
|
|
|
1716
1732
|
// Update the scroll position for virtual lists
|
|
1717
1733
|
p.virtualListHelper.render();
|
|
@@ -2041,13 +2057,46 @@ class DropList {
|
|
|
2041
2057
|
* Get a reference to the header element in order to add custom content.
|
|
2042
2058
|
* @returns {Element}
|
|
2043
2059
|
*/
|
|
2044
|
-
getHeaderElement() {
|
|
2045
|
-
return this._p.headerEl;
|
|
2046
|
-
}
|
|
2047
|
-
|
|
2048
|
-
/**
|
|
2049
|
-
*
|
|
2050
|
-
* You should probably call `relayout()` after this.
|
|
2060
|
+
getHeaderElement() {
|
|
2061
|
+
return this._p.headerEl;
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
/**
|
|
2065
|
+
* Change visibility of the footer element
|
|
2066
|
+
* You should probably call `relayout()` after this.
|
|
2067
|
+
* @param {boolean} visible
|
|
2068
|
+
*/
|
|
2069
|
+
setFooterVisible(visible) {
|
|
2070
|
+
let isVisible = this.isFooterVisible();
|
|
2071
|
+
if (isVisible === !!visible)
|
|
2072
|
+
return;
|
|
2073
|
+
|
|
2074
|
+
if (visible) {
|
|
2075
|
+
this._p.el.appendChild(this._p.footerEl);
|
|
2076
|
+
} else {
|
|
2077
|
+
this._p.footerEl.remove();
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
/**
|
|
2082
|
+
* Is the footer element visible?
|
|
2083
|
+
* @returns {boolean}
|
|
2084
|
+
*/
|
|
2085
|
+
isFooterVisible() {
|
|
2086
|
+
return !!this._p.footerEl.parentNode;
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
/**
|
|
2090
|
+
* Get a reference to the footer element in order to add custom content.
|
|
2091
|
+
* @returns {Element}
|
|
2092
|
+
*/
|
|
2093
|
+
getFooterElement() {
|
|
2094
|
+
return this._p.footerEl;
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
/**
|
|
2098
|
+
* Set inline search visibility
|
|
2099
|
+
* You should probably call `relayout()` after this.
|
|
2051
2100
|
* @param {boolean} searchable
|
|
2052
2101
|
*/
|
|
2053
2102
|
setSearchable(searchable) {
|
|
@@ -3941,7 +3990,7 @@ class SelectBox {
|
|
|
3941
3990
|
p.items = items.slice(0);
|
|
3942
3991
|
p.itemsChanged = true;
|
|
3943
3992
|
|
|
3944
|
-
this.
|
|
3993
|
+
this._refreshItemByValueMap();
|
|
3945
3994
|
|
|
3946
3995
|
if (resetValues) {
|
|
3947
3996
|
this.setSelectedValues(this.getSelectedValues());
|
|
@@ -3972,10 +4021,17 @@ class SelectBox {
|
|
|
3972
4021
|
updateItemByValue(value, newItem) {
|
|
3973
4022
|
const p = this._p;
|
|
3974
4023
|
|
|
3975
|
-
let existingItem =
|
|
3976
|
-
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
|
+
|
|
3977
4030
|
Object.assign(existingItem, newItem);
|
|
3978
4031
|
|
|
4032
|
+
p.itemByValueMap.set(existingItem[p.valueProp], existingItem);
|
|
4033
|
+
}
|
|
4034
|
+
|
|
3979
4035
|
if (p.dropList) {
|
|
3980
4036
|
p.dropList.updateItemByValue(value, newItem);
|
|
3981
4037
|
}
|
|
@@ -4545,7 +4601,7 @@ class SelectBox {
|
|
|
4545
4601
|
if (p.dropList)
|
|
4546
4602
|
p.dropList.setValueProp(prop);
|
|
4547
4603
|
|
|
4548
|
-
this.
|
|
4604
|
+
this._refreshItemByValueMap();
|
|
4549
4605
|
|
|
4550
4606
|
return this;
|
|
4551
4607
|
}
|
|
@@ -4731,7 +4787,7 @@ class SelectBox {
|
|
|
4731
4787
|
|
|
4732
4788
|
selectedValues.push(value);
|
|
4733
4789
|
|
|
4734
|
-
let item =
|
|
4790
|
+
let item = this._getItemByValue(value);
|
|
4735
4791
|
if (item !== undefined) {
|
|
4736
4792
|
selectedItems.push(item);
|
|
4737
4793
|
} else {
|
|
@@ -5026,7 +5082,7 @@ class SelectBox {
|
|
|
5026
5082
|
* This reduces search time greatly (i.e when checking items), especially when Vue proxies are in place.
|
|
5027
5083
|
* @private
|
|
5028
5084
|
*/
|
|
5029
|
-
|
|
5085
|
+
_refreshItemByValueMap() {
|
|
5030
5086
|
const p = this._p;
|
|
5031
5087
|
|
|
5032
5088
|
const itemByValueMap = p.itemByValueMap = new Map();
|
|
@@ -5034,6 +5090,52 @@ class SelectBox {
|
|
|
5034
5090
|
for (let item of p.items) {
|
|
5035
5091
|
itemByValueMap.set(item[valueProp], item);
|
|
5036
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
|
+
}
|
|
5037
5139
|
}
|
|
5038
5140
|
|
|
5039
5141
|
/** @private */
|
|
@@ -5418,7 +5520,8 @@ class SelectBox {
|
|
|
5418
5520
|
}
|
|
5419
5521
|
break;
|
|
5420
5522
|
|
|
5421
|
-
case 'select':
|
|
5523
|
+
case 'select':
|
|
5524
|
+
case 'subitems:select': {
|
|
5422
5525
|
if (p.multi) return;
|
|
5423
5526
|
|
|
5424
5527
|
const item = event.item;
|