@danielgindi/selectbox 1.0.62 → 1.0.65

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
@@ -1954,17 +1954,17 @@ class DropList {
1954
1954
  _updateGroupStateForItem(item) {
1955
1955
  const p = this._p;
1956
1956
 
1957
- if (p.multi && p.autoCheckGroupChildren) {
1957
+ if (!p.multi)
1958
+ return this;
1958
1959
 
1959
- let items, groupIndex, itemIndex;
1960
+ if (item._group) {
1961
+ // Now loop through children below the group
1960
1962
 
1961
- if (item._group) {
1962
- // Now loop through children below the group
1963
-
1964
- items = p.items;
1965
- groupIndex = items.indexOf(item);
1963
+ let affectedItems = 0;
1966
1964
 
1967
- let affectedItems = 0;
1965
+ if (p.autoCheckGroupChildren) {
1966
+ let items = p.items;
1967
+ let groupIndex = items.indexOf(item);
1968
1968
 
1969
1969
  for (let i = groupIndex + 1, len = items.length; i < len; i++) {
1970
1970
  let next = items[i];
@@ -1997,30 +1997,30 @@ class DropList {
1997
1997
  isCheckingGroup: true,
1998
1998
  });
1999
1999
  }
2000
+ }
2000
2001
 
2001
- // Fire event
2002
- this._trigger('groupcheck', {
2003
- value: item.value,
2004
- item: item[ItemSymbol] ?? item,
2005
- affectedItems: affectedItems,
2006
- });
2007
- } else if (p.groupCount > 0) {
2008
- items = p.items;
2009
- itemIndex = items.indexOf(item);
2010
- groupIndex = -1;
2011
-
2012
- // Find the group index
2013
- for (let i = itemIndex - 1; i >= 0; i--) {
2014
- if (items[i]._group) {
2015
- groupIndex = i;
2016
- break;
2017
- }
2018
- }
2002
+ // Fire event
2003
+ this._trigger('groupcheck', {
2004
+ value: item.value,
2005
+ item: item[ItemSymbol] ?? item,
2006
+ affectedItems: affectedItems,
2007
+ });
2008
+ } else if (p.groupCount > 0 && p.autoCheckGroupChildren) {
2009
+ let items = p.items;
2010
+ let itemIndex = items.indexOf(item);
2011
+ let groupIndex = -1;
2019
2012
 
2020
- if (groupIndex > -1) {
2021
- this._updateGroupCheckedState(groupIndex, true);
2013
+ // Find the group index
2014
+ for (let i = itemIndex - 1; i >= 0; i--) {
2015
+ if (items[i]._group) {
2016
+ groupIndex = i;
2017
+ break;
2022
2018
  }
2023
2019
  }
2020
+
2021
+ if (groupIndex > -1) {
2022
+ this._updateGroupCheckedState(groupIndex, true);
2023
+ }
2024
2024
  }
2025
2025
 
2026
2026
  return this;
@@ -2029,50 +2029,50 @@ class DropList {
2029
2029
  _updateGroupCheckedState(groupIndex, fireEvents) {
2030
2030
  const p = this._p;
2031
2031
 
2032
- if (p.multi && p.autoCheckGroupChildren && groupIndex > -1) {
2032
+ if (!(p.multi && p.autoCheckGroupChildren && groupIndex > -1))
2033
+ return this;
2033
2034
 
2034
- let items = p.items;
2035
- let groupItem = items[groupIndex];
2036
- if (!groupItem || !groupItem._group) return this;
2035
+ let items = p.items;
2036
+ let groupItem = items[groupIndex];
2037
2037
 
2038
- let item, hasChecked = false, hasUnchecked = false;
2038
+ if (!groupItem || !groupItem._group) return this;
2039
2039
 
2040
- for (let i = groupIndex + 1, len = items.length; i < len; i++) {
2041
- item = items[i];
2040
+ let item, hasChecked = false, hasUnchecked = false;
2042
2041
 
2043
- // Hit the next group, break out
2044
- if (item._group || (!item._child && items[i - 1]._child))
2045
- break;
2042
+ for (let i = groupIndex + 1, len = items.length; i < len; i++) {
2043
+ item = items[i];
2046
2044
 
2047
- if (item._checked) {
2048
- hasChecked = true;
2049
- } else if (!item._checked) {
2050
- hasUnchecked = true;
2051
- }
2045
+ // Hit the next group, break out
2046
+ if (item._group || (!item._child && items[i - 1]._child))
2047
+ break;
2048
+
2049
+ if (item._checked) {
2050
+ hasChecked = true;
2051
+ } else if (!item._checked) {
2052
+ hasUnchecked = true;
2052
2053
  }
2054
+ }
2053
2055
 
2054
- // See if we need to update the group
2055
- let shouldCheckGroup = hasChecked && !hasUnchecked;
2056
- if (!!groupItem._checked !== shouldCheckGroup) {
2057
- // Update state
2058
- groupItem._checked = shouldCheckGroup;
2056
+ let shouldCheckGroup = hasChecked && !hasUnchecked;
2057
+ if (!!groupItem._checked !== shouldCheckGroup) {
2058
+ // Update state
2059
+ groupItem._checked = shouldCheckGroup;
2059
2060
 
2060
- // Update DOM
2061
- let nextEl = p.virtualListHelper.getItemElementAt(groupIndex);
2062
- if (nextEl) {
2063
- toggleClass(nextEl, `${p.baseClassName}__item_checked`, groupItem._checked);
2064
- }
2061
+ // Update DOM
2062
+ let nextEl = p.virtualListHelper.getItemElementAt(groupIndex);
2063
+ if (nextEl) {
2064
+ toggleClass(nextEl, `${p.baseClassName}__item_checked`, groupItem._checked);
2065
+ }
2065
2066
 
2066
- if (fireEvents) {
2067
- // Fire event
2068
- this._trigger('check', {
2069
- value: groupItem.value,
2070
- item: groupItem[ItemSymbol] ?? groupItem,
2071
- checked: groupItem._checked,
2072
- isGroup: groupItem._group,
2073
- isCheckingGroup: false,
2074
- });
2075
- }
2067
+ if (fireEvents) {
2068
+ // Fire event
2069
+ this._trigger('check', {
2070
+ value: groupItem.value,
2071
+ item: groupItem[ItemSymbol] ?? groupItem,
2072
+ checked: groupItem._checked,
2073
+ isGroup: groupItem._group,
2074
+ isCheckingGroup: false,
2075
+ });
2076
2076
  }
2077
2077
  }
2078
2078
 
package/lib/SelectBox.js CHANGED
@@ -85,6 +85,7 @@ const inputBackbufferCssProps = [
85
85
  * @property {boolean} [sortSelectedItems=true] Should the selected items be sorted?
86
86
  * @property {boolean} [sortListItems=false] Sort list items
87
87
  * @property {boolean} [sortListCheckedFirst=true] When sorting - put checked items first (applicable to `multi` mode only)
88
+ * @property {boolean} [treatGroupSelectionAsItems=false] Treat group items as normal items
88
89
  * @property {*[]} [stickyValues]
89
90
  * @property {function(a: DropList.ItemBase, b: DropList.ItemBase):number} [sortItemComparator]
90
91
  * @property {boolean} [splitListCheckedGroups=true] Split groups to "checked" and "unchecked", works with `sortCheckedFirst` only
@@ -130,6 +131,7 @@ const defaultOptions = {
130
131
  stickyValues: null,
131
132
  sortItemComparator: null,
132
133
  splitListCheckedGroups: true,
134
+ treatGroupSelectionAsItems: false,
133
135
  blurOnSingleSelection: 'touch',
134
136
  multi: false,
135
137
  showSelection: true,
@@ -219,6 +221,7 @@ class SelectBox {
219
221
  stickyValues: Array.isArray(o.stickyValues) ? new Set(o.stickyValues) : null,
220
222
  sortItemComparator: o.sortItemComparator,
221
223
  splitListCheckedGroups: !!o.splitListCheckedGroups,
224
+ treatGroupSelectionAsItems: o.treatGroupSelectionAsItems,
222
225
  blurOnSingleSelection: o.blurOnSingleSelection,
223
226
  multi: o.multi,
224
227
  showSelection: o.showSelection,
@@ -764,6 +767,29 @@ class SelectBox {
764
767
  return this._p.sortItemComparator;
765
768
  }
766
769
 
770
+ /**
771
+ * @param {boolean} treatGroupSelectionAsItems
772
+ * @returns {SelectBox}
773
+ */
774
+ setTreatGroupSelectionAsItems(treatGroupSelectionAsItems) {
775
+ const p = this._p;
776
+ treatGroupSelectionAsItems = !!treatGroupSelectionAsItems;
777
+ if (p.treatGroupSelectionAsItems === treatGroupSelectionAsItems)
778
+ return this;
779
+
780
+ p.treatGroupSelectionAsItems = treatGroupSelectionAsItems;
781
+ p.itemsChanged = true;
782
+ this._scheduleSync();
783
+ return this;
784
+ }
785
+
786
+ /**
787
+ * @returns {boolean}
788
+ */
789
+ isTreatGroupSelectionAsItemsEnabled() {
790
+ return !this._p.treatGroupSelectionAsItems;
791
+ }
792
+
767
793
  /**
768
794
  * @param {boolean} splitListCheckedGroups
769
795
  * @returns {SelectBox}
@@ -1715,7 +1741,7 @@ class SelectBox {
1715
1741
  const value = event.value;
1716
1742
 
1717
1743
  let checked = event.checked;
1718
- if (event.isGroup) return; // Ignore groups
1744
+ if (event.isGroup && !p.treatGroupSelectionAsItems) return; // Ignore groups
1719
1745
 
1720
1746
  let selEvt = { value: value, item: item, cancel: false };
1721
1747
  this._trigger((checked ? 'addsel' : 'removesel') + ':before', selEvt);
@@ -1751,7 +1777,7 @@ class SelectBox {
1751
1777
  this._scheduleSync('full');
1752
1778
  } else {
1753
1779
  if (p.maxMultiItems != null &&
1754
- p.selectedItems.filter(x => !x._group).length > p.maxMultiItems) {
1780
+ (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter(x => !x._group)).length > p.maxMultiItems) {
1755
1781
  this._scheduleSync('addOrUpdateMultiItemRestElement');
1756
1782
  } else {
1757
1783
  this._scheduleSync('addMultiItemElement', item);
@@ -1762,7 +1788,7 @@ class SelectBox {
1762
1788
  }
1763
1789
  } else {
1764
1790
  if (p.maxMultiItems != null &&
1765
- p.selectedItems.filter(x => !x._group).length === p.maxMultiItems) {
1791
+ (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter(x => !x._group)).length === p.maxMultiItems) {
1766
1792
  this._scheduleSync('removeMultiItemRestElement');
1767
1793
  } else {
1768
1794
  this._scheduleSync('removeMultiItemElement', item);
@@ -2214,6 +2240,7 @@ class SelectBox {
2214
2240
  const p = this._p;
2215
2241
 
2216
2242
  const term = p.filterTerm;
2243
+ const treatGroupSelectionAsItems = p.treatGroupSelectionAsItems;
2217
2244
 
2218
2245
  if (term || (p.filterOnEmptyTerm && p.filterFn)) {
2219
2246
  let fn = p.filterFn;
@@ -2232,7 +2259,7 @@ class SelectBox {
2232
2259
  multiItemLabelProp = p.multiItemLabelProp;
2233
2260
 
2234
2261
  filteredItems = p.items.filter(x => {
2235
- if (x._group) return true;
2262
+ if (!treatGroupSelectionAsItems && x._group) return true;
2236
2263
  return matcher.test(x[labelProp] || x[multiItemLabelProp]);
2237
2264
  });
2238
2265
  } else {
@@ -2242,7 +2269,7 @@ class SelectBox {
2242
2269
 
2243
2270
  p.filteredItems = filteredItems;
2244
2271
 
2245
- if (filteredItems) {
2272
+ if (filteredItems && !treatGroupSelectionAsItems) {
2246
2273
  // Clean up groups without children
2247
2274
 
2248
2275
  let lastGroup = -1;
@@ -2500,7 +2527,7 @@ class SelectBox {
2500
2527
  const p = this._p;
2501
2528
 
2502
2529
  let items = p.selectedItems.slice(0);
2503
- let count = items.filter(x => !x._group).length - p.maxMultiItems;
2530
+ let count = (p.treatGroupSelectionAsItems ? items : items.filter(x => !x._group)).length - p.maxMultiItems;
2504
2531
  let label = p.multiItemsRestLabelProvider
2505
2532
  ? p.multiItemsRestLabelProvider(count, items)
2506
2533
  : `+ ${count}`;
@@ -2605,6 +2632,7 @@ class SelectBox {
2605
2632
  if (p.multi) {
2606
2633
  if (fullItemsRender) {
2607
2634
  const items = p.selectedItems;
2635
+ const treatGroupSelectionAsItems = p.treatGroupSelectionAsItems;
2608
2636
 
2609
2637
  // Sort these
2610
2638
  if (p.sortSelectedItems) {
@@ -2637,7 +2665,7 @@ class SelectBox {
2637
2665
 
2638
2666
  // Add item elements
2639
2667
  for (let i = 0; i < items.length; i++) {
2640
- if (items[i]._group) continue;
2668
+ if (!treatGroupSelectionAsItems && items[i]._group) continue;
2641
2669
 
2642
2670
  if (max != null && actualItemCount === max) {
2643
2671
  addRestItem = true;
@@ -2750,7 +2778,8 @@ class SelectBox {
2750
2778
 
2751
2779
  if (item !== undefined) {
2752
2780
  if (value === RestMultiItemsSymbol) {
2753
- let items = p.selectedItems.filter(x => !x._group).slice(p.maxMultiItems);
2781
+ let items = (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter(x => !x._group))
2782
+ .slice(p.maxMultiItems);
2754
2783
  let itemsToRemove = [];
2755
2784
 
2756
2785
  for (let item of items) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/selectbox",
3
- "version": "1.0.62",
3
+ "version": "1.0.65",
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",
@@ -31,22 +31,22 @@
31
31
  "homepage": "https://github.com/danielgindi/selectbox#readme",
32
32
  "license": "MIT",
33
33
  "devDependencies": {
34
- "@babel/core": "^7.17.9",
35
- "@babel/preset-env": "^7.16.11",
36
- "@babel/runtime": "^7.17.9",
34
+ "@babel/core": "^7.18.2",
35
+ "@babel/preset-env": "^7.18.2",
36
+ "@babel/runtime": "^7.18.3",
37
37
  "@rollup/plugin-babel": "^5.3.1",
38
38
  "@rollup/plugin-commonjs": "^22.0.0",
39
- "@rollup/plugin-node-resolve": "^13.2.1",
40
- "core-js": "^3.22.3",
41
- "eslint": "^8.14.0",
39
+ "@rollup/plugin-node-resolve": "^13.3.0",
40
+ "core-js": "^3.22.8",
41
+ "eslint": "^8.17.0",
42
42
  "eslint-formatter-codeframe": "^7.32.1",
43
- "eslint-plugin-vue": "^8.7.1",
43
+ "eslint-plugin-vue": "^9.1.0",
44
44
  "fs-extra": "^10.1.0",
45
- "husky": "^7.0.4",
45
+ "husky": "^8.0.1",
46
46
  "pinst": "^3.0.0",
47
- "rollup": "^2.70.2",
47
+ "rollup": "^2.75.5",
48
48
  "rollup-plugin-terser": "^7.0.2",
49
- "sass": "^1.51.0"
49
+ "sass": "^1.52.2"
50
50
  },
51
51
  "dependencies": {
52
52
  "@danielgindi/dom-utils": "^1.0.8",
package/vue/SelectBox.vue CHANGED
@@ -213,6 +213,22 @@
213
213
  type: Boolean,
214
214
  default: false,
215
215
  },
216
+ treatGroupSelectionAsItems: {
217
+ type: Boolean,
218
+ default: false,
219
+ },
220
+ autoCheckGroupChildren: {
221
+ type: Boolean,
222
+ default: true,
223
+ },
224
+ constrainListToWindow: {
225
+ type: Boolean,
226
+ default: true,
227
+ },
228
+ autoFlipListDirection: {
229
+ type: Boolean,
230
+ default: true,
231
+ },
216
232
  },
217
233
 
218
234
  data() {
@@ -233,6 +249,18 @@
233
249
  opts.additionalClasses = this.additionalDroplistClassesList;
234
250
  }
235
251
 
252
+ if (typeof this.autoCheckGroupChildren === 'boolean' && this.multi) {
253
+ opts.autoCheckGroupChildren = this.autoCheckGroupChildren;
254
+ }
255
+
256
+ if (typeof this.constrainListToWindow === 'boolean') {
257
+ opts.constrainToWindow = this.constrainListToWindow;
258
+ }
259
+
260
+ if (typeof this.autoFlipListDirection === 'boolean') {
261
+ opts.autoFlipDirection = this.autoFlipListDirection;
262
+ }
263
+
236
264
  opts.virtualMinItems = this.virtualMinItems;
237
265
  opts.useExactTargetWidth = this.fixedDroplistWidth;
238
266
 
@@ -565,6 +593,11 @@
565
593
  if (this._box)
566
594
  this._box.setIsLoadingMode(!!this.isLoadingMode);
567
595
  },
596
+
597
+ treatGroupSelectionAsItems() {
598
+ if (this._box)
599
+ this._box.setTreatGroupSelectionAsItems(!!this.treatGroupSelectionAsItems);
600
+ },
568
601
  },
569
602
 
570
603
  mounted() {
@@ -682,6 +715,7 @@
682
715
  on: this._handleBoxEvents.bind(this),
683
716
  additionalClasses: this.additionalClassesList,
684
717
  isLoadingMode: this.isLoadingMode,
718
+ treatGroupSelectionAsItems: this.treatGroupSelectionAsItems,
685
719
  });
686
720
 
687
721
  box.setValue(this.value === null ? undefined : this.value);