@danielgindi/selectbox 2.0.53 → 2.0.54
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 +4717 -13521
- package/dist/lib.cjs.js.map +1 -1
- package/dist/lib.cjs.min.js +2 -4
- package/dist/lib.cjs.min.js.map +1 -1
- package/dist/lib.es6.js +4701 -7041
- package/dist/lib.es6.js.map +1 -1
- package/dist/lib.es6.min.js +2 -4
- package/dist/lib.es6.min.js.map +1 -1
- package/dist/lib.umd.js +4743 -13539
- package/dist/lib.umd.js.map +1 -1
- package/dist/lib.umd.min.js +2 -4
- package/dist/lib.umd.min.js.map +1 -1
- package/lib/DropList.js +108 -94
- package/lib/SelectBox.js +16 -7
- package/package.json +12 -18
package/lib/DropList.js
CHANGED
|
@@ -63,8 +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
|
|
67
|
-
* @property {boolean} [isFooterVisible=false] show footer element
|
|
66
|
+
* @property {boolean} [isHeaderVisible=false] show header element
|
|
67
|
+
* @property {boolean} [isFooterVisible=false] show footer element
|
|
68
68
|
* @property {boolean} [searchable=false] include inline search box
|
|
69
69
|
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
70
70
|
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
@@ -137,8 +137,8 @@ export const DefaultOptions = {
|
|
|
137
137
|
|
|
138
138
|
on: null,
|
|
139
139
|
|
|
140
|
-
isHeaderVisible: false,
|
|
141
|
-
isFooterVisible: false,
|
|
140
|
+
isHeaderVisible: false,
|
|
141
|
+
isFooterVisible: false,
|
|
142
142
|
searchable: false,
|
|
143
143
|
noResultsText: 'No matching results',
|
|
144
144
|
filterThrottleWindow: 300,
|
|
@@ -163,7 +163,7 @@ Emits the following events:
|
|
|
163
163
|
'groupcheck' {value, item, affectedCount: number}: item was selected (in multi mode).
|
|
164
164
|
'blur' {event}: element lost focus
|
|
165
165
|
'show_subitems {value, item, el, droplist: DropList}': subitems dropdown will show.
|
|
166
|
-
'hide_subitems {value, item, el}': subitems dropdown did hide.
|
|
166
|
+
'hide_subitems {value, item, el, droplist: DropList}': subitems dropdown did hide.
|
|
167
167
|
'subitems:select' {value, item, event?, el}: item was selected (in single mode).
|
|
168
168
|
'subitems:blur' {event}: subitems element lost focus
|
|
169
169
|
*/
|
|
@@ -211,8 +211,8 @@ class DropList {
|
|
|
211
211
|
positionOptionsProvider: o.positionOptionsProvider ?? null,
|
|
212
212
|
|
|
213
213
|
searchable: o.searchable,
|
|
214
|
-
isHeaderVisible: o.isHeaderVisible,
|
|
215
|
-
isFooterVisible: o.isFooterVisible,
|
|
214
|
+
isHeaderVisible: o.isHeaderVisible,
|
|
215
|
+
isFooterVisible: o.isFooterVisible,
|
|
216
216
|
|
|
217
217
|
silenceEvents: true,
|
|
218
218
|
mitt: mitt(),
|
|
@@ -266,27 +266,27 @@ class DropList {
|
|
|
266
266
|
menuEl.role = 'menu';
|
|
267
267
|
p.menuEl = menuEl;
|
|
268
268
|
|
|
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 = [];
|
|
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 = [];
|
|
290
290
|
p.groupCount = 0; // This will keep state of how many `group` items we have
|
|
291
291
|
p.mouseHandled = false;
|
|
292
292
|
|
|
@@ -445,7 +445,7 @@ class DropList {
|
|
|
445
445
|
}
|
|
446
446
|
|
|
447
447
|
get el() {
|
|
448
|
-
return this._p
|
|
448
|
+
return this._p?.el ?? null;
|
|
449
449
|
}
|
|
450
450
|
|
|
451
451
|
/**
|
|
@@ -697,6 +697,11 @@ class DropList {
|
|
|
697
697
|
return false;
|
|
698
698
|
}
|
|
699
699
|
|
|
700
|
+
if (item._subitems?.length) {
|
|
701
|
+
this._showSublist(item, p.focusItemEl);
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
|
|
700
705
|
if (p.multi) {
|
|
701
706
|
if (this.hasFocusedItem()) {
|
|
702
707
|
this.toggleFocusedItem();
|
|
@@ -1537,23 +1542,23 @@ class DropList {
|
|
|
1537
1542
|
let verticalBorderWidth = (parseFloat(elComputedStyle.borderTopWidth) || 0) +
|
|
1538
1543
|
(parseFloat(elComputedStyle.borderBottomWidth) || 0);
|
|
1539
1544
|
|
|
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;
|
|
1545
|
+
let headerHeight = 0;
|
|
1546
|
+
if (p.headerEl) {
|
|
1547
|
+
headerHeight = getElementHeight(p.headerEl, true, true);
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
let footerHeight = 0;
|
|
1551
|
+
if (p.footerEl) {
|
|
1552
|
+
footerHeight = getElementHeight(p.footerEl, true, true);
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
if (p.virtualListHelper.isVirtual()) {
|
|
1556
|
+
maxViewHeight =
|
|
1557
|
+
p.virtualListHelper.estimateFullHeight() +
|
|
1558
|
+
verticalPadding +
|
|
1559
|
+
verticalBorderWidth +
|
|
1560
|
+
headerHeight +
|
|
1561
|
+
footerHeight;
|
|
1557
1562
|
} else {
|
|
1558
1563
|
// Another method to calculate height is measuring the whole thing at once.
|
|
1559
1564
|
// This causes relayout of course.
|
|
@@ -1694,12 +1699,12 @@ class DropList {
|
|
|
1694
1699
|
viewCss.left += 'px';
|
|
1695
1700
|
viewCss.top += 'px';
|
|
1696
1701
|
setCssProps(el, viewCss);
|
|
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
|
-
}
|
|
1702
|
+
setElementHeight(el, viewSize.height, true, true);
|
|
1703
|
+
|
|
1704
|
+
if (menuEl !== el) {
|
|
1705
|
+
let menuHeight = viewSize.height - headerHeight - footerHeight - verticalBorderWidth - verticalPadding;
|
|
1706
|
+
setElementHeight(menuEl, menuHeight, true, true);
|
|
1707
|
+
}
|
|
1703
1708
|
|
|
1704
1709
|
// Update the scroll position for virtual lists
|
|
1705
1710
|
p.virtualListHelper.render();
|
|
@@ -1865,7 +1870,7 @@ class DropList {
|
|
|
1865
1870
|
if (!p.onDocumentMouseDown) {
|
|
1866
1871
|
// Detect mouse tap outside of the droplist, to blur the focused item
|
|
1867
1872
|
p.sink.add(document, 'mousedown', p.onDocumentMouseDown = (event) => {
|
|
1868
|
-
if (!
|
|
1873
|
+
if (!this.elContains(event.target, true))
|
|
1869
1874
|
this._delayBlurItemOnBlur();
|
|
1870
1875
|
});
|
|
1871
1876
|
}
|
|
@@ -2029,46 +2034,46 @@ class DropList {
|
|
|
2029
2034
|
* Get a reference to the header element in order to add custom content.
|
|
2030
2035
|
* @returns {Element}
|
|
2031
2036
|
*/
|
|
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.
|
|
2037
|
+
getHeaderElement() {
|
|
2038
|
+
return this._p.headerEl;
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
/**
|
|
2042
|
+
* Change visibility of the footer element
|
|
2043
|
+
* You should probably call `relayout()` after this.
|
|
2044
|
+
* @param {boolean} visible
|
|
2045
|
+
*/
|
|
2046
|
+
setFooterVisible(visible) {
|
|
2047
|
+
let isVisible = this.isFooterVisible();
|
|
2048
|
+
if (isVisible === !!visible)
|
|
2049
|
+
return;
|
|
2050
|
+
|
|
2051
|
+
if (visible) {
|
|
2052
|
+
this._p.el.appendChild(this._p.footerEl);
|
|
2053
|
+
} else {
|
|
2054
|
+
this._p.footerEl.remove();
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
/**
|
|
2059
|
+
* Is the footer element visible?
|
|
2060
|
+
* @returns {boolean}
|
|
2061
|
+
*/
|
|
2062
|
+
isFooterVisible() {
|
|
2063
|
+
return !!this._p.footerEl.parentNode;
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
/**
|
|
2067
|
+
* Get a reference to the footer element in order to add custom content.
|
|
2068
|
+
* @returns {Element}
|
|
2069
|
+
*/
|
|
2070
|
+
getFooterElement() {
|
|
2071
|
+
return this._p.footerEl;
|
|
2072
|
+
}
|
|
2073
|
+
|
|
2074
|
+
/**
|
|
2075
|
+
* Set inline search visibility
|
|
2076
|
+
* You should probably call `relayout()` after this.
|
|
2072
2077
|
* @param {boolean} searchable
|
|
2073
2078
|
*/
|
|
2074
2079
|
setSearchable(searchable) {
|
|
@@ -2163,6 +2168,8 @@ class DropList {
|
|
|
2163
2168
|
if (!item._subitems?.length) return;
|
|
2164
2169
|
|
|
2165
2170
|
const p = this._p;
|
|
2171
|
+
if (p.currentSubDropList?.item === item)
|
|
2172
|
+
return;
|
|
2166
2173
|
|
|
2167
2174
|
const droplist = new DropList({
|
|
2168
2175
|
baseClassName: p.baseClassName,
|
|
@@ -2204,6 +2211,12 @@ class DropList {
|
|
|
2204
2211
|
.on('subitems:select', event => {
|
|
2205
2212
|
this._trigger('subitems:select', event);
|
|
2206
2213
|
})
|
|
2214
|
+
.on('show_subitems', event => {
|
|
2215
|
+
this._trigger('show_subitems', event);
|
|
2216
|
+
})
|
|
2217
|
+
.on('hide_subitems', event => {
|
|
2218
|
+
this._trigger('hide_subitems', event);
|
|
2219
|
+
})
|
|
2207
2220
|
.on('blur', onBlur)
|
|
2208
2221
|
.on('subitems:blur', onBlur)
|
|
2209
2222
|
.on('_back_key_pressed', () => {
|
|
@@ -2259,6 +2272,7 @@ class DropList {
|
|
|
2259
2272
|
value: data.item.value,
|
|
2260
2273
|
item: data.item,
|
|
2261
2274
|
el: data.itemElement,
|
|
2275
|
+
droplist: data.droplist,
|
|
2262
2276
|
});
|
|
2263
2277
|
}
|
|
2264
2278
|
|
|
@@ -2923,7 +2937,7 @@ class DropList {
|
|
|
2923
2937
|
_move(direction, event) {
|
|
2924
2938
|
const p = this._p;
|
|
2925
2939
|
|
|
2926
|
-
let next, nextIndex, directionUp
|
|
2940
|
+
let next, nextIndex, directionUp;
|
|
2927
2941
|
const items = p.filteredItems ?? p.items;
|
|
2928
2942
|
|
|
2929
2943
|
if (direction === 'first') {
|
package/lib/SelectBox.js
CHANGED
|
@@ -502,7 +502,7 @@ class SelectBox {
|
|
|
502
502
|
}
|
|
503
503
|
|
|
504
504
|
get el() {
|
|
505
|
-
return this._p
|
|
505
|
+
return this._p?.el ?? null;
|
|
506
506
|
}
|
|
507
507
|
|
|
508
508
|
get droplistInstance() {
|
|
@@ -1969,6 +1969,12 @@ class SelectBox {
|
|
|
1969
1969
|
p.resortBySelectionNeeded = true;
|
|
1970
1970
|
}
|
|
1971
1971
|
|
|
1972
|
+
const preventDropListMouseDownBlur = (event) => {
|
|
1973
|
+
const li = closestUntil(event.target, 'li', event.currentTarget);
|
|
1974
|
+
if (!li) return;
|
|
1975
|
+
|
|
1976
|
+
event.preventDefault();
|
|
1977
|
+
};
|
|
1972
1978
|
const dropList = p.dropList = new DropList({
|
|
1973
1979
|
virtualMinItems: 10,
|
|
1974
1980
|
|
|
@@ -2176,6 +2182,14 @@ class SelectBox {
|
|
|
2176
2182
|
}
|
|
2177
2183
|
break;
|
|
2178
2184
|
|
|
2185
|
+
case 'show_subitems':
|
|
2186
|
+
p.sink.add(event.droplist.el, 'mousedown.subitems', preventDropListMouseDownBlur);
|
|
2187
|
+
break;
|
|
2188
|
+
|
|
2189
|
+
case 'hide_subitems':
|
|
2190
|
+
p.sink.remove(event.droplist.el, '.subitems');
|
|
2191
|
+
break;
|
|
2192
|
+
|
|
2179
2193
|
case 'blur':
|
|
2180
2194
|
this._handleOnBlur();
|
|
2181
2195
|
break;
|
|
@@ -2191,12 +2205,7 @@ class SelectBox {
|
|
|
2191
2205
|
},
|
|
2192
2206
|
});
|
|
2193
2207
|
|
|
2194
|
-
p.sink.add(dropList.el, 'mousedown',
|
|
2195
|
-
const li = closestUntil(event.target, 'li', event.currentTarget);
|
|
2196
|
-
if (!li) return;
|
|
2197
|
-
|
|
2198
|
-
event.preventDefault();
|
|
2199
|
-
});
|
|
2208
|
+
p.sink.add(dropList.el, 'mousedown', preventDropListMouseDownBlur);
|
|
2200
2209
|
|
|
2201
2210
|
this._registerDropdownEvents();
|
|
2202
2211
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielgindi/selectbox",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.54",
|
|
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",
|
|
@@ -32,26 +32,20 @@
|
|
|
32
32
|
"homepage": "https://github.com/danielgindi/selectbox#readme",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"@eslint/eslintrc": "^3.3.4",
|
|
39
|
-
"@eslint/js": "^9.39.3",
|
|
40
|
-
"@rollup/plugin-babel": "^6.1.0",
|
|
41
|
-
"@rollup/plugin-commonjs": "^29.0.0",
|
|
42
|
-
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
43
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
44
|
-
"core-js": "^3.48.0",
|
|
45
|
-
"eslint": "^9.39.3",
|
|
35
|
+
"@eslint/eslintrc": "^3.3.6",
|
|
36
|
+
"@eslint/js": "^10.0.1",
|
|
37
|
+
"eslint": "^10.7.0",
|
|
46
38
|
"eslint-formatter-codeframe": "^7.32.2",
|
|
47
|
-
"eslint-plugin-vue": "^9.
|
|
48
|
-
"
|
|
49
|
-
"globals": "^17.4.0",
|
|
39
|
+
"eslint-plugin-vue": "^10.9.2",
|
|
40
|
+
"globals": "^17.7.0",
|
|
50
41
|
"husky": "^9.1.7",
|
|
42
|
+
"magic-string": "^0.30.21",
|
|
51
43
|
"pinst": "^3.0.0",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"vite": "^8.1.
|
|
44
|
+
"sass": "^1.101.0",
|
|
45
|
+
"terser": "^5.49.0",
|
|
46
|
+
"vite": "^8.1.5",
|
|
47
|
+
"vue": "^3.5.40",
|
|
48
|
+
"vue-eslint-parser": "^10.4.1"
|
|
55
49
|
},
|
|
56
50
|
"dependencies": {
|
|
57
51
|
"@danielgindi/dom-utils": "^1.0.11",
|