@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/eslint.config.mjs
CHANGED
package/lib/DropList.js
CHANGED
|
@@ -63,7 +63,8 @@ const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
|
63
63
|
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderNoResultsItem]
|
|
64
64
|
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderNoResultsItem]
|
|
65
65
|
* @property {function(name: string, data: *)} [on]
|
|
66
|
-
* @property {boolean} [isHeaderVisible=false] show header element
|
|
66
|
+
* @property {boolean} [isHeaderVisible=false] show header element
|
|
67
|
+
* @property {boolean} [isFooterVisible=false] show footer element
|
|
67
68
|
* @property {boolean} [searchable=false] include inline search box
|
|
68
69
|
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
69
70
|
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
@@ -136,7 +137,8 @@ export const DefaultOptions = {
|
|
|
136
137
|
|
|
137
138
|
on: null,
|
|
138
139
|
|
|
139
|
-
isHeaderVisible: false,
|
|
140
|
+
isHeaderVisible: false,
|
|
141
|
+
isFooterVisible: false,
|
|
140
142
|
searchable: false,
|
|
141
143
|
noResultsText: 'No matching results',
|
|
142
144
|
filterThrottleWindow: 300,
|
|
@@ -209,7 +211,8 @@ class DropList {
|
|
|
209
211
|
positionOptionsProvider: o.positionOptionsProvider ?? null,
|
|
210
212
|
|
|
211
213
|
searchable: o.searchable,
|
|
212
|
-
isHeaderVisible: o.isHeaderVisible,
|
|
214
|
+
isHeaderVisible: o.isHeaderVisible,
|
|
215
|
+
isFooterVisible: o.isFooterVisible,
|
|
213
216
|
|
|
214
217
|
silenceEvents: true,
|
|
215
218
|
mitt: mitt(),
|
|
@@ -263,20 +266,27 @@ class DropList {
|
|
|
263
266
|
menuEl.role = 'menu';
|
|
264
267
|
p.menuEl = menuEl;
|
|
265
268
|
|
|
266
|
-
p.headerEl = createElement('div', {
|
|
267
|
-
class: p.baseClassName + '_header',
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (o.
|
|
275
|
-
this.
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
269
|
+
p.headerEl = createElement('div', {
|
|
270
|
+
class: p.baseClassName + '_header',
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
p.footerEl = createElement('div', {
|
|
274
|
+
class: p.baseClassName + '_footer',
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
if (o.searchable) {
|
|
278
|
+
this.setSearchable(true);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (o.isHeaderVisible)
|
|
282
|
+
this.setHeaderVisible(o.isHeaderVisible);
|
|
283
|
+
|
|
284
|
+
wrapperEl.appendChild(menuEl);
|
|
285
|
+
|
|
286
|
+
if (o.isFooterVisible)
|
|
287
|
+
this.setFooterVisible(o.isFooterVisible);
|
|
288
|
+
|
|
289
|
+
p.items = [];
|
|
280
290
|
p.groupCount = 0; // This will keep state of how many `group` items we have
|
|
281
291
|
p.mouseHandled = false;
|
|
282
292
|
|
|
@@ -1527,17 +1537,23 @@ class DropList {
|
|
|
1527
1537
|
let verticalBorderWidth = (parseFloat(elComputedStyle.borderTopWidth) || 0) +
|
|
1528
1538
|
(parseFloat(elComputedStyle.borderBottomWidth) || 0);
|
|
1529
1539
|
|
|
1530
|
-
let headerHeight = 0;
|
|
1531
|
-
if (p.headerEl) {
|
|
1532
|
-
headerHeight = getElementHeight(p.headerEl, true, true);
|
|
1533
|
-
}
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1540
|
+
let headerHeight = 0;
|
|
1541
|
+
if (p.headerEl) {
|
|
1542
|
+
headerHeight = getElementHeight(p.headerEl, true, true);
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
let footerHeight = 0;
|
|
1546
|
+
if (p.footerEl) {
|
|
1547
|
+
footerHeight = getElementHeight(p.footerEl, true, true);
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
if (p.virtualListHelper.isVirtual()) {
|
|
1551
|
+
maxViewHeight =
|
|
1552
|
+
p.virtualListHelper.estimateFullHeight() +
|
|
1553
|
+
verticalPadding +
|
|
1554
|
+
verticalBorderWidth +
|
|
1555
|
+
headerHeight +
|
|
1556
|
+
footerHeight;
|
|
1541
1557
|
} else {
|
|
1542
1558
|
// Another method to calculate height is measuring the whole thing at once.
|
|
1543
1559
|
// This causes relayout of course.
|
|
@@ -1678,12 +1694,12 @@ class DropList {
|
|
|
1678
1694
|
viewCss.left += 'px';
|
|
1679
1695
|
viewCss.top += 'px';
|
|
1680
1696
|
setCssProps(el, viewCss);
|
|
1681
|
-
setElementHeight(el, viewSize.height, true, true);
|
|
1682
|
-
|
|
1683
|
-
if (menuEl !== el) {
|
|
1684
|
-
let menuHeight = viewSize.height - headerHeight - verticalBorderWidth - verticalPadding;
|
|
1685
|
-
setElementHeight(menuEl, menuHeight, true, true);
|
|
1686
|
-
}
|
|
1697
|
+
setElementHeight(el, viewSize.height, true, true);
|
|
1698
|
+
|
|
1699
|
+
if (menuEl !== el) {
|
|
1700
|
+
let menuHeight = viewSize.height - headerHeight - footerHeight - verticalBorderWidth - verticalPadding;
|
|
1701
|
+
setElementHeight(menuEl, menuHeight, true, true);
|
|
1702
|
+
}
|
|
1687
1703
|
|
|
1688
1704
|
// Update the scroll position for virtual lists
|
|
1689
1705
|
p.virtualListHelper.render();
|
|
@@ -2013,13 +2029,46 @@ class DropList {
|
|
|
2013
2029
|
* Get a reference to the header element in order to add custom content.
|
|
2014
2030
|
* @returns {Element}
|
|
2015
2031
|
*/
|
|
2016
|
-
getHeaderElement() {
|
|
2017
|
-
return this._p.headerEl;
|
|
2018
|
-
}
|
|
2019
|
-
|
|
2020
|
-
/**
|
|
2021
|
-
*
|
|
2022
|
-
* You should probably call `relayout()` after this.
|
|
2032
|
+
getHeaderElement() {
|
|
2033
|
+
return this._p.headerEl;
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
/**
|
|
2037
|
+
* Change visibility of the footer element
|
|
2038
|
+
* You should probably call `relayout()` after this.
|
|
2039
|
+
* @param {boolean} visible
|
|
2040
|
+
*/
|
|
2041
|
+
setFooterVisible(visible) {
|
|
2042
|
+
let isVisible = this.isFooterVisible();
|
|
2043
|
+
if (isVisible === !!visible)
|
|
2044
|
+
return;
|
|
2045
|
+
|
|
2046
|
+
if (visible) {
|
|
2047
|
+
this._p.el.appendChild(this._p.footerEl);
|
|
2048
|
+
} else {
|
|
2049
|
+
this._p.footerEl.remove();
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
/**
|
|
2054
|
+
* Is the footer element visible?
|
|
2055
|
+
* @returns {boolean}
|
|
2056
|
+
*/
|
|
2057
|
+
isFooterVisible() {
|
|
2058
|
+
return !!this._p.footerEl.parentNode;
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
/**
|
|
2062
|
+
* Get a reference to the footer element in order to add custom content.
|
|
2063
|
+
* @returns {Element}
|
|
2064
|
+
*/
|
|
2065
|
+
getFooterElement() {
|
|
2066
|
+
return this._p.footerEl;
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
/**
|
|
2070
|
+
* Set inline search visibility
|
|
2071
|
+
* You should probably call `relayout()` after this.
|
|
2023
2072
|
* @param {boolean} searchable
|
|
2024
2073
|
*/
|
|
2025
2074
|
setSearchable(searchable) {
|
package/lib/SelectBox.js
CHANGED
|
@@ -624,7 +624,7 @@ class SelectBox {
|
|
|
624
624
|
p.items = items.slice(0);
|
|
625
625
|
p.itemsChanged = true;
|
|
626
626
|
|
|
627
|
-
this.
|
|
627
|
+
this._refreshItemByValueMap();
|
|
628
628
|
|
|
629
629
|
if (resetValues) {
|
|
630
630
|
this.setSelectedValues(this.getSelectedValues());
|
|
@@ -655,10 +655,17 @@ class SelectBox {
|
|
|
655
655
|
updateItemByValue(value, newItem) {
|
|
656
656
|
const p = this._p;
|
|
657
657
|
|
|
658
|
-
let existingItem =
|
|
659
|
-
if (existingItem)
|
|
658
|
+
let existingItem = this._getItemByValue(value);
|
|
659
|
+
if (existingItem) {
|
|
660
|
+
const valueProp = existingItem[p.valueProp];
|
|
661
|
+
if (p.itemByValueMap?.has(valueProp))
|
|
662
|
+
p.itemByValueMap.delete(valueProp);
|
|
663
|
+
|
|
660
664
|
Object.assign(existingItem, newItem);
|
|
661
665
|
|
|
666
|
+
p.itemByValueMap.set(existingItem[p.valueProp], existingItem);
|
|
667
|
+
}
|
|
668
|
+
|
|
662
669
|
if (p.dropList) {
|
|
663
670
|
p.dropList.updateItemByValue(value, newItem);
|
|
664
671
|
}
|
|
@@ -1228,7 +1235,7 @@ class SelectBox {
|
|
|
1228
1235
|
if (p.dropList)
|
|
1229
1236
|
p.dropList.setValueProp(prop);
|
|
1230
1237
|
|
|
1231
|
-
this.
|
|
1238
|
+
this._refreshItemByValueMap();
|
|
1232
1239
|
|
|
1233
1240
|
return this;
|
|
1234
1241
|
}
|
|
@@ -1414,7 +1421,7 @@ class SelectBox {
|
|
|
1414
1421
|
|
|
1415
1422
|
selectedValues.push(value);
|
|
1416
1423
|
|
|
1417
|
-
let item =
|
|
1424
|
+
let item = this._getItemByValue(value);
|
|
1418
1425
|
if (item !== undefined) {
|
|
1419
1426
|
selectedItems.push(item);
|
|
1420
1427
|
} else {
|
|
@@ -1709,7 +1716,7 @@ class SelectBox {
|
|
|
1709
1716
|
* This reduces search time greatly (i.e when checking items), especially when Vue proxies are in place.
|
|
1710
1717
|
* @private
|
|
1711
1718
|
*/
|
|
1712
|
-
|
|
1719
|
+
_refreshItemByValueMap() {
|
|
1713
1720
|
const p = this._p;
|
|
1714
1721
|
|
|
1715
1722
|
const itemByValueMap = p.itemByValueMap = new Map();
|
|
@@ -1717,6 +1724,52 @@ class SelectBox {
|
|
|
1717
1724
|
for (let item of p.items) {
|
|
1718
1725
|
itemByValueMap.set(item[valueProp], item);
|
|
1719
1726
|
}
|
|
1727
|
+
|
|
1728
|
+
p.subitemByValueMap = null;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
/**
|
|
1732
|
+
* @param {*} value
|
|
1733
|
+
* @returns {DropList.ItemBase|undefined}
|
|
1734
|
+
* @private
|
|
1735
|
+
*/
|
|
1736
|
+
_getItemByValue(value) {
|
|
1737
|
+
const p = this._p;
|
|
1738
|
+
let item = p.itemByValueMap.get(value);
|
|
1739
|
+
if (item !== undefined)
|
|
1740
|
+
return item;
|
|
1741
|
+
|
|
1742
|
+
if (!p.subitemByValueMap)
|
|
1743
|
+
this._refreshSubitemByValueMap();
|
|
1744
|
+
|
|
1745
|
+
return p.subitemByValueMap.get(value);
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
/** @private */
|
|
1749
|
+
_refreshSubitemByValueMap() {
|
|
1750
|
+
const p = this._p;
|
|
1751
|
+
const subitemByValueMap = p.subitemByValueMap = new Map();
|
|
1752
|
+
this._addSubitemsToValueMap(p.items, subitemByValueMap, p.valueProp);
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
/**
|
|
1756
|
+
* @param {DropList.ItemBase[]} items
|
|
1757
|
+
* @param {Map<*, DropList.ItemBase>} itemByValueMap
|
|
1758
|
+
* @param {string} valueProp
|
|
1759
|
+
* @private
|
|
1760
|
+
*/
|
|
1761
|
+
_addSubitemsToValueMap(items, itemByValueMap, valueProp) {
|
|
1762
|
+
for (let item of items) {
|
|
1763
|
+
if (!item._subitems?.length)
|
|
1764
|
+
continue;
|
|
1765
|
+
|
|
1766
|
+
for (let subitem of item._subitems) {
|
|
1767
|
+
if (!itemByValueMap.has(subitem[valueProp]))
|
|
1768
|
+
itemByValueMap.set(subitem[valueProp], subitem);
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
this._addSubitemsToValueMap(item._subitems, itemByValueMap, valueProp);
|
|
1772
|
+
}
|
|
1720
1773
|
}
|
|
1721
1774
|
|
|
1722
1775
|
/** @private */
|
|
@@ -2101,7 +2154,8 @@ class SelectBox {
|
|
|
2101
2154
|
}
|
|
2102
2155
|
break;
|
|
2103
2156
|
|
|
2104
|
-
case 'select':
|
|
2157
|
+
case 'select':
|
|
2158
|
+
case 'subitems:select': {
|
|
2105
2159
|
if (p.multi) return;
|
|
2106
2160
|
|
|
2107
2161
|
const item = event.item;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielgindi/selectbox",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.53",
|
|
4
4
|
"description": "A collection of dom utilities. So you can work natively with the dom without dom frameworks.",
|
|
5
5
|
"main": "dist/lib.cjs.min.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"lib": "lib"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
+
"benchmark": "node ./benchmarks/selectbox-value-lookup.mjs",
|
|
21
22
|
"build": "npm run lint && node ./scripts/build.js",
|
|
22
23
|
"lint": "eslint -f codeframe ./",
|
|
23
24
|
"lint-fix": "eslint -f codeframe --fix ./",
|
package/scss/droplist.scss
CHANGED
|
@@ -32,14 +32,17 @@
|
|
|
32
32
|
max-width: 100%;
|
|
33
33
|
line-height: 1.3;
|
|
34
34
|
|
|
35
|
-
.droplist_header
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
.droplist_header,
|
|
36
|
+
.droplist_footer {
|
|
37
|
+
position: relative;
|
|
38
|
+
padding: 0.5em;
|
|
39
|
+
box-sizing: inherit;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.droplist_header {
|
|
43
|
+
input[type=search] {
|
|
44
|
+
box-sizing: inherit;
|
|
45
|
+
width: 100%;
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
|
package/vue/DropList.vue
CHANGED
|
@@ -50,13 +50,17 @@ export const PropTypes = {
|
|
|
50
50
|
type: Boolean,
|
|
51
51
|
default: false,
|
|
52
52
|
},
|
|
53
|
-
isHeaderVisible: {
|
|
54
|
-
type: Boolean,
|
|
55
|
-
default: false,
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
type: Boolean,
|
|
59
|
-
default: false,
|
|
53
|
+
isHeaderVisible: {
|
|
54
|
+
type: Boolean,
|
|
55
|
+
default: false,
|
|
56
|
+
},
|
|
57
|
+
isFooterVisible: {
|
|
58
|
+
type: Boolean,
|
|
59
|
+
default: false,
|
|
60
|
+
},
|
|
61
|
+
searchable: {
|
|
62
|
+
type: Boolean,
|
|
63
|
+
default: false,
|
|
60
64
|
},
|
|
61
65
|
noResultsText: {
|
|
62
66
|
type: String,
|
|
@@ -207,12 +211,12 @@ export default {
|
|
|
207
211
|
opts.direction = this.direction;
|
|
208
212
|
}
|
|
209
213
|
|
|
210
|
-
for (let key of ['autoItemBlur', 'capturesFocus', 'multi',
|
|
211
|
-
'autoCheckGroupChildren', 'useExactTargetWidth', 'constrainToWindow',
|
|
212
|
-
'autoFlipDirection', 'estimateWidth',
|
|
213
|
-
'isHeaderVisible',
|
|
214
|
-
'searchable', 'filterOnEmptyTerm',
|
|
215
|
-
'filterGroups', 'filterEmptyGroups']) {
|
|
214
|
+
for (let key of ['autoItemBlur', 'capturesFocus', 'multi',
|
|
215
|
+
'autoCheckGroupChildren', 'useExactTargetWidth', 'constrainToWindow',
|
|
216
|
+
'autoFlipDirection', 'estimateWidth',
|
|
217
|
+
'isHeaderVisible', 'isFooterVisible',
|
|
218
|
+
'searchable', 'filterOnEmptyTerm',
|
|
219
|
+
'filterGroups', 'filterEmptyGroups']) {
|
|
216
220
|
if (typeof this[key] === 'boolean') {
|
|
217
221
|
opts[key] = this[key];
|
|
218
222
|
}
|
|
@@ -353,13 +357,19 @@ export default {
|
|
|
353
357
|
this.relayout();
|
|
354
358
|
},
|
|
355
359
|
|
|
356
|
-
isHeaderVisible(v) {
|
|
357
|
-
if (this.nonReactive.instance)
|
|
358
|
-
this.nonReactive.instance.setHeaderVisible(v);
|
|
359
|
-
this.relayout();
|
|
360
|
-
},
|
|
361
|
-
|
|
362
|
-
|
|
360
|
+
isHeaderVisible(v) {
|
|
361
|
+
if (this.nonReactive.instance)
|
|
362
|
+
this.nonReactive.instance.setHeaderVisible(v);
|
|
363
|
+
this.relayout();
|
|
364
|
+
},
|
|
365
|
+
|
|
366
|
+
isFooterVisible(v) {
|
|
367
|
+
if (this.nonReactive.instance)
|
|
368
|
+
this.nonReactive.instance.setFooterVisible(v);
|
|
369
|
+
this.relayout();
|
|
370
|
+
},
|
|
371
|
+
|
|
372
|
+
positionOptions: {
|
|
363
373
|
deep: true,
|
|
364
374
|
handler() {
|
|
365
375
|
this.relayout();
|
|
@@ -453,11 +463,16 @@ export default {
|
|
|
453
463
|
}
|
|
454
464
|
|
|
455
465
|
const headerRenderer = createSlotBasedRenderFunc(this, 'header');
|
|
456
|
-
if (headerRenderer) {
|
|
457
|
-
headerRenderer({}, list.getHeaderElement());
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
|
|
466
|
+
if (headerRenderer) {
|
|
467
|
+
headerRenderer({}, list.getHeaderElement());
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const footerRenderer = createSlotBasedRenderFunc(this, 'footer');
|
|
471
|
+
if (footerRenderer) {
|
|
472
|
+
footerRenderer({}, list.getFooterElement());
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
list.show();
|
|
461
476
|
|
|
462
477
|
this._setupAutoRelayout();
|
|
463
478
|
},
|
|
@@ -526,12 +541,17 @@ export default {
|
|
|
526
541
|
this.nonReactive.instance.relayout();
|
|
527
542
|
},
|
|
528
543
|
|
|
529
|
-
getHeaderElement() {
|
|
530
|
-
if (this.nonReactive.instance)
|
|
531
|
-
this.nonReactive.instance.getHeaderElement();
|
|
532
|
-
},
|
|
533
|
-
|
|
534
|
-
|
|
544
|
+
getHeaderElement() {
|
|
545
|
+
if (this.nonReactive.instance)
|
|
546
|
+
return this.nonReactive.instance.getHeaderElement();
|
|
547
|
+
},
|
|
548
|
+
|
|
549
|
+
getFooterElement() {
|
|
550
|
+
if (this.nonReactive.instance)
|
|
551
|
+
return this.nonReactive.instance.getFooterElement();
|
|
552
|
+
},
|
|
553
|
+
|
|
554
|
+
elContains(other, considerSublists = true) {
|
|
535
555
|
return !!this.listRef?.elContains(other, considerSublists);
|
|
536
556
|
},
|
|
537
557
|
},
|