@danielgindi/selectbox 2.0.3 → 2.0.5

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/lib/DropList.js CHANGED
@@ -652,7 +652,8 @@ class DropList {
652
652
  const p = this._p;
653
653
 
654
654
  if (this.hasFocusedItem() && p.multi) {
655
- let item = p.items[p.focusItemIndex];
655
+ const items = p.filteredItems ?? p.items;
656
+ let item = items[p.focusItemIndex];
656
657
  if (item._nocheck || item._nointeraction) return this;
657
658
 
658
659
  item._checked = !item._checked;
@@ -720,7 +721,7 @@ class DropList {
720
721
  const p = this._p, labelProp = p.labelProp, valueProp = p.valueProp;
721
722
 
722
723
  let isMulti = p.multi;
723
- let items = p.items;
724
+ const items = p.items;
724
725
 
725
726
  if (atIndex == null || atIndex < 0 || atIndex >= p.items.length) {
726
727
  atIndex = -1;
@@ -1185,11 +1186,10 @@ class DropList {
1185
1186
  if (!Array.isArray(filteredItems)) {
1186
1187
  if (term) {
1187
1188
  const matcher = new RegExp(escapeRegex(term), 'i');
1188
- const labelProp = p.labelProp;
1189
1189
 
1190
1190
  filteredItems = p.items.filter(x => {
1191
1191
  if (!filterGroups && x._group) return true;
1192
- return matcher.test(x[labelProp]);
1192
+ return matcher.test(x.label);
1193
1193
  });
1194
1194
  } else {
1195
1195
  filteredItems = null;
@@ -1230,7 +1230,7 @@ class DropList {
1230
1230
  p.filteredItems = null;
1231
1231
  }
1232
1232
 
1233
- this.needsRefilter = false;
1233
+ p.needsRefilter = false;
1234
1234
 
1235
1235
  const items = p.filteredItems ?? p.items;
1236
1236
  p.hasNoResultsItem = items.length === 0 && !!p.noResultsText;
@@ -1251,11 +1251,17 @@ class DropList {
1251
1251
  return this;
1252
1252
  }
1253
1253
 
1254
- getFilteredItemCount() {
1254
+ rushRefilter() {
1255
1255
  const p = this._p;
1256
-
1257
1256
  if (p.needsRefilter)
1258
1257
  this._refilterItems();
1258
+ return this;
1259
+ }
1260
+
1261
+ getFilteredItemCount() {
1262
+ const p = this._p;
1263
+
1264
+ this.rushRefilter();
1259
1265
 
1260
1266
  if (p.filteredItems)
1261
1267
  return p.filteredItems.length;
@@ -1457,6 +1463,8 @@ class DropList {
1457
1463
 
1458
1464
  // Calculate virtual viewport size
1459
1465
  if (p.virtualListHelper.isVirtual()) {
1466
+ // Avoid extremely high size which will cause laying out the whole list
1467
+ menuEl.style.height = Math.min(el.clientHeight, document.body.clientHeight) + 'px';
1460
1468
  p.virtualListHelper.render();
1461
1469
  }
1462
1470
 
@@ -1701,6 +1709,8 @@ class DropList {
1701
1709
  setCheckedValues(values) {
1702
1710
  const p = this._p;
1703
1711
 
1712
+ this.rushRefilter();
1713
+
1704
1714
  let groupIndexes = [];
1705
1715
 
1706
1716
  for (let i = 0, count = p.items.length; i < count; i++) {
@@ -1764,7 +1774,7 @@ class DropList {
1764
1774
 
1765
1775
  excludeGroups = excludeGroups && p.groupCount > 0;
1766
1776
 
1767
- let items = [];
1777
+ const items = [];
1768
1778
 
1769
1779
  for (let i = 0, count = p.items.length; i < count; i++) {
1770
1780
  let item = p.items[i];
@@ -1805,9 +1815,7 @@ class DropList {
1805
1815
  }
1806
1816
  });
1807
1817
 
1808
- if (p.needsRefilter) {
1809
- this._refilterItems();
1810
- }
1818
+ this.rushRefilter();
1811
1819
 
1812
1820
  const el = p.el;
1813
1821
  el.style.position = 'absolute';
@@ -2015,6 +2023,8 @@ class DropList {
2015
2023
  setFocusedItemAtIndex(itemIndex) {
2016
2024
  const p = this._p;
2017
2025
 
2026
+ this.rushRefilter();
2027
+
2018
2028
  if (p.filteredItems) {
2019
2029
  const item = p.items[itemIndex];
2020
2030
  itemIndex = p.items.indexOf(item);
@@ -2212,6 +2222,8 @@ class DropList {
2212
2222
  setSingleSelectedItemAtIndex(itemIndex) {
2213
2223
  const p = this._p;
2214
2224
 
2225
+ this.rushRefilter();
2226
+
2215
2227
  let itemEl = null;
2216
2228
 
2217
2229
  if (itemIndex > -1 && !p.items[itemIndex]._nointeraction) {
@@ -2971,7 +2983,7 @@ class DropList {
2971
2983
  let affectedItems = 0;
2972
2984
 
2973
2985
  if (p.autoCheckGroupChildren) {
2974
- let items = p.filteredItems ?? p.items;
2986
+ const items = p.filteredItems ?? p.items;
2975
2987
  let groupIndex = items.indexOf(item);
2976
2988
 
2977
2989
  for (let i = groupIndex + 1, len = items.length; i < len; i++) {
@@ -3014,7 +3026,7 @@ class DropList {
3014
3026
  affectedItems: affectedItems,
3015
3027
  });
3016
3028
  } else if (p.groupCount > 0 && p.autoCheckGroupChildren) {
3017
- let items = p.filteredItems ?? p.items;
3029
+ const items = p.filteredItems ?? p.items;
3018
3030
  let itemIndex = items.indexOf(item);
3019
3031
  let groupIndex = -1;
3020
3032
 
@@ -3040,7 +3052,7 @@ class DropList {
3040
3052
  if (!(p.multi && p.autoCheckGroupChildren && groupIndex > -1))
3041
3053
  return this;
3042
3054
 
3043
- let items = p.filteredItems ?? p.items;
3055
+ const items = p.filteredItems ?? p.items;
3044
3056
  let groupItem = items[groupIndex];
3045
3057
 
3046
3058
  if (!groupItem || !groupItem._group) return this;
@@ -3166,7 +3178,7 @@ class DropList {
3166
3178
  _determineVirtualMode(targetItemCount) {
3167
3179
  const p = this._p;
3168
3180
 
3169
- let items = p.filteredItems ?? p.items;
3181
+ const items = p.filteredItems ?? p.items;
3170
3182
  if (targetItemCount === undefined) {
3171
3183
  targetItemCount = items.length;
3172
3184
  }
package/lib/SelectBox.js CHANGED
@@ -380,8 +380,7 @@ class SelectBox {
380
380
  p.resizeObserver.observe(p.el);
381
381
  }
382
382
 
383
- if (o.filterFn)
384
- this.setFilterFn(o.filterFn);
383
+ this.setFilterFn(o.filterFn);
385
384
 
386
385
  this.setItems(o.items);
387
386
  delete o.items; // we do not need this in memory anymore
@@ -1174,6 +1173,10 @@ class SelectBox {
1174
1173
  const p = this._p;
1175
1174
  if (p.filterFn === fn)
1176
1175
  return this;
1176
+
1177
+ // Do not keep this reference, as far as the user is concerned - he/she did not set a custom filter.
1178
+ p.filterFn = fn;
1179
+
1177
1180
  if (!fn) {
1178
1181
  // Add search by multi-item label
1179
1182
  fn = (items, term) => {
@@ -1187,7 +1190,6 @@ class SelectBox {
1187
1190
  });
1188
1191
  };
1189
1192
  }
1190
- p.filterFn = fn;
1191
1193
  p.dropList?.setFilterFn(fn);
1192
1194
  return this;
1193
1195
  }
@@ -2306,6 +2308,7 @@ class SelectBox {
2306
2308
  p.splitListCheckedGroups);
2307
2309
  }
2308
2310
  dropList.setItems(items);
2311
+ dropList.invokeRefilter();
2309
2312
  p.itemsChanged = false;
2310
2313
  p.selectionChanged = true;
2311
2314
  p.resortBySelectionNeeded = false;
package/package.json CHANGED
@@ -1,63 +1,63 @@
1
- {
2
- "name": "@danielgindi/selectbox",
3
- "version": "2.0.3",
4
- "description": "A collection of dom utilities. So you can work natively with the dom without dom frameworks.",
5
- "main": "dist/lib.cjs.min.js",
6
- "module": "lib/index.js",
7
- "broswer": "dist/lib.umd.min.js",
8
- "author": {
9
- "name": "Daniel Cohen Gindi",
10
- "email": "danielgindi@gmail.com"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git://github.com/danielgindi/selectbox.git"
15
- },
16
- "directories": {
17
- "dist": "dist",
18
- "lib": "lib"
19
- },
20
- "scripts": {
21
- "build": "npm run lint && node ./scripts/build.js",
22
- "lint": "eslint -f codeframe ./",
23
- "lint-fix": "eslint -f codeframe --fix ./",
24
- "prepublishOnly": "npm run build",
25
- "prepare": "husky"
26
- },
27
- "bugs": {
28
- "url": "https://github.com/danielgindi/selectbox/issues"
29
- },
30
- "homepage": "https://github.com/danielgindi/selectbox#readme",
31
- "license": "MIT",
32
- "devDependencies": {
33
- "@babel/core": "^7.26.9",
34
- "@babel/preset-env": "^7.26.9",
35
- "@babel/runtime": "^7.26.9",
36
- "@eslint/eslintrc": "^3.2.0",
37
- "@eslint/js": "^9.20.0",
38
- "@rollup/plugin-babel": "^6.0.4",
39
- "@rollup/plugin-commonjs": "^28.0.2",
40
- "@rollup/plugin-node-resolve": "^16.0.0",
41
- "@rollup/plugin-terser": "^0.4.4",
42
- "core-js": "^3.40.0",
43
- "eslint": "^9.20.1",
44
- "eslint-formatter-codeframe": "^7.32.1",
45
- "eslint-plugin-vue": "^9.32.0",
46
- "fs-extra": "^11.3.0",
47
- "globals": "^15.15.0",
48
- "husky": "^9.1.7",
49
- "pinst": "^3.0.0",
50
- "rollup": "^4.34.8",
51
- "sass": "^1.85.0"
52
- },
53
- "dependencies": {
54
- "@danielgindi/dom-utils": "^1.0.11",
55
- "@danielgindi/virtual-list-helper": "^1.0.13",
56
- "fast-deep-equal": "^3.1.3",
57
- "keycode-js": "^3.1.0",
58
- "mitt": "^3.0.1"
59
- },
60
- "peerDependencies": {
61
- "vue": "^2.* || ^3.*"
62
- }
63
- }
1
+ {
2
+ "name": "@danielgindi/selectbox",
3
+ "version": "2.0.5",
4
+ "description": "A collection of dom utilities. So you can work natively with the dom without dom frameworks.",
5
+ "main": "dist/lib.cjs.min.js",
6
+ "module": "lib/index.js",
7
+ "broswer": "dist/lib.umd.min.js",
8
+ "author": {
9
+ "name": "Daniel Cohen Gindi",
10
+ "email": "danielgindi@gmail.com"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git://github.com/danielgindi/selectbox.git"
15
+ },
16
+ "directories": {
17
+ "dist": "dist",
18
+ "lib": "lib"
19
+ },
20
+ "scripts": {
21
+ "build": "npm run lint && node ./scripts/build.js",
22
+ "lint": "eslint -f codeframe ./",
23
+ "lint-fix": "eslint -f codeframe --fix ./",
24
+ "prepublishOnly": "npm run build",
25
+ "prepare": "husky"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/danielgindi/selectbox/issues"
29
+ },
30
+ "homepage": "https://github.com/danielgindi/selectbox#readme",
31
+ "license": "MIT",
32
+ "devDependencies": {
33
+ "@babel/core": "^7.26.9",
34
+ "@babel/preset-env": "^7.26.9",
35
+ "@babel/runtime": "^7.26.9",
36
+ "@eslint/eslintrc": "^3.2.0",
37
+ "@eslint/js": "^9.20.0",
38
+ "@rollup/plugin-babel": "^6.0.4",
39
+ "@rollup/plugin-commonjs": "^28.0.2",
40
+ "@rollup/plugin-node-resolve": "^16.0.0",
41
+ "@rollup/plugin-terser": "^0.4.4",
42
+ "core-js": "^3.40.0",
43
+ "eslint": "^9.20.1",
44
+ "eslint-formatter-codeframe": "^7.32.1",
45
+ "eslint-plugin-vue": "^9.32.0",
46
+ "fs-extra": "^11.3.0",
47
+ "globals": "^15.15.0",
48
+ "husky": "^9.1.7",
49
+ "pinst": "^3.0.0",
50
+ "rollup": "^4.34.8",
51
+ "sass": "^1.85.0"
52
+ },
53
+ "dependencies": {
54
+ "@danielgindi/dom-utils": "^1.0.11",
55
+ "@danielgindi/virtual-list-helper": "^1.0.13",
56
+ "fast-deep-equal": "^3.1.3",
57
+ "keycode-js": "^3.1.0",
58
+ "mitt": "^3.0.1"
59
+ },
60
+ "peerDependencies": {
61
+ "vue": "^2.* || ^3.*"
62
+ }
63
+ }