@danielgindi/selectbox 2.0.6 → 2.0.8

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
@@ -158,7 +158,7 @@ Emits the following events:
158
158
  'hide': the drop list was hidden.
159
159
  'hide:after': emitted after the hide css transition has ended, or immediately after 'hide'.
160
160
  'check' {value, item, checked: boolean, isGroup: boolean, isCheckingGroup: boolean}: item was selected (in multi mode).
161
- 'groupcheck' {value, item, affectedItems}: item was selected (in multi mode).
161
+ 'groupcheck' {value, item, affectedCount: number}: item was selected (in multi mode).
162
162
  'blur' {event}: element lost focus
163
163
  'show_subitems {value, item, el, droplist: DropList}': subitems dropdown will show.
164
164
  'hide_subitems {value, item, el}': subitems dropdown did hide.
@@ -751,6 +751,10 @@ class DropList {
751
751
  p.groupCount++;
752
752
  }
753
753
 
754
+ if (typeof oitem._level === 'number') {
755
+ item._level = oitem._level;
756
+ }
757
+
754
758
  if (oitem._child) {
755
759
  // This is used for setting a child class,
756
760
  // But can be used to determine that current item is not part of above group,
@@ -853,6 +857,10 @@ class DropList {
853
857
  }
854
858
  }
855
859
 
860
+ if (hasOwnProperty.call(newItem, '_level')) {
861
+ newItem._level = item._level;
862
+ }
863
+
856
864
  if (hasOwnProperty.call(newItem, '_child'))
857
865
  item._child = !!newItem._child;
858
866
 
@@ -1158,7 +1166,15 @@ class DropList {
1158
1166
  if (typeof fn === 'function') {
1159
1167
  // Send the original items to the filter function
1160
1168
  filteredItems = p.filterFn(
1161
- p.items.map(x => x[ItemSymbol] ?? x),
1169
+ p.items.map(x => {
1170
+ const y = x[ItemSymbol];
1171
+ if (y !== undefined) {
1172
+ y[ItemSymbol] = x;
1173
+ return y;
1174
+ }
1175
+
1176
+ return x;
1177
+ }),
1162
1178
  term);
1163
1179
 
1164
1180
  if (Array.isArray(filteredItems)) {
@@ -1174,6 +1190,7 @@ class DropList {
1174
1190
  _nointeraction: !!oitem._nointeraction,
1175
1191
  _subitems: oitem._subitems,
1176
1192
  _group: !!oitem._group,
1193
+ _level: !!oitem._level,
1177
1194
  _checked: !!oitem._checked,
1178
1195
  };
1179
1196
  }
@@ -2980,17 +2997,19 @@ class DropList {
2980
2997
  if (item._group) {
2981
2998
  // Now loop through children below the group
2982
2999
 
2983
- let affectedItems = 0;
3000
+ let affectedCount = 0;
2984
3001
 
2985
3002
  if (p.autoCheckGroupChildren) {
2986
3003
  const items = p.filteredItems ?? p.items;
2987
3004
  let groupIndex = items.indexOf(item);
3005
+ const groupLevel = item._level;
2988
3006
 
2989
3007
  for (let i = groupIndex + 1, len = items.length; i < len; i++) {
2990
3008
  let next = items[i];
2991
3009
 
2992
3010
  // Hit the next group, break out
2993
- if (next._group || (!next._child && items[i - 1]._child))
3011
+ if ((!next._child && items[i - 1]._child) ||
3012
+ (groupLevel === undefined ? next._group || next._level !== undefined : next._level <= groupLevel))
2994
3013
  break;
2995
3014
 
2996
3015
  // No change, skip
@@ -3000,7 +3019,7 @@ class DropList {
3000
3019
  // Update state
3001
3020
  next._checked = item._checked;
3002
3021
 
3003
- affectedItems++;
3022
+ affectedCount++;
3004
3023
 
3005
3024
  // Update DOM
3006
3025
  let nextEl = p.virtualListHelper.getItemElementAt(i);
@@ -3023,7 +3042,7 @@ class DropList {
3023
3042
  this._trigger('groupcheck', {
3024
3043
  value: item.value,
3025
3044
  item: item[ItemSymbol] ?? item,
3026
- affectedItems: affectedItems,
3045
+ affectedCount: affectedCount,
3027
3046
  });
3028
3047
  } else if (p.groupCount > 0 && p.autoCheckGroupChildren) {
3029
3048
  const items = p.filteredItems ?? p.items;
@@ -3057,18 +3076,21 @@ class DropList {
3057
3076
 
3058
3077
  if (!groupItem || !groupItem._group) return this;
3059
3078
 
3060
- let item, hasChecked = false, hasUnchecked = false;
3079
+ let next, hasChecked = false, hasUnchecked = false;
3080
+
3081
+ const groupLevel = groupItem._level;
3061
3082
 
3062
3083
  for (let i = groupIndex + 1, len = items.length; i < len; i++) {
3063
- item = items[i];
3084
+ next = items[i];
3064
3085
 
3065
3086
  // Hit the next group, break out
3066
- if (item._group || (!item._child && items[i - 1]._child))
3087
+ if ((!next._child && items[i - 1]._child) ||
3088
+ (groupLevel === undefined ? next._group || next._level !== undefined : next._level <= groupLevel))
3067
3089
  break;
3068
3090
 
3069
- if (item._checked) {
3091
+ if (next._checked) {
3070
3092
  hasChecked = true;
3071
- } else if (!item._checked) {
3093
+ } else if (!next._checked) {
3072
3094
  hasUnchecked = true;
3073
3095
  }
3074
3096
  }
package/lib/SelectBox.js CHANGED
@@ -179,11 +179,12 @@ Emits the following events:
179
179
  'open' { list: DropList }: the drop list is opening
180
180
  'open:before' { list: DropList }: the drop list will open
181
181
  'close': the drop list is closing
182
- 'addsel:before' {value, item, cancel: false}: an item selection is about to be added (in multi mode). return false to abort.
183
- 'removesel:before' {value, item, cancel: false}: an item selection is about to be removed (in multi mode). return false to abort.
182
+ 'addsel:before' {value, item, cancel: false, isCheckingGroup: bool}: an item selection is about to be added (in multi mode). return false to abort.
183
+ 'removesel:before' {value, item, cancel: false, isCheckingGroup: bool}: an item selection is about to be removed (in multi mode). return false to abort.
184
+ 'addsel' {value, item, isCheckingGroup: bool}: an item selection has been added (in multi mode)
185
+ 'removesel' {value, item, isCheckingGroup: bool}: an item selection has been removed (in multi mode)
186
+ 'groupcheck' {value, item, affectedCount: number}: an item selection has been removed (in multi mode)
184
187
  'select:before' {value, item, cancel: false}: an item is about to be selected (in single mode). return false to abort.
185
- 'addsel' {value, item}: an item selection has been added (in multi mode)
186
- 'removesel' {value, item}: an item selection has been removed (in multi mode)
187
188
  'select' {value, item}: an item has been selected (in single mode)
188
189
  'search' {value}: input box value has changed
189
190
  'search:focus': input box has gained focus
@@ -1861,7 +1862,12 @@ class SelectBox {
1861
1862
  let checked = event.checked;
1862
1863
  if (event.isGroup && !p.treatGroupSelectionAsItems) return; // Ignore groups
1863
1864
 
1864
- let selEvt = { value: value, item: item, cancel: false };
1865
+ let selEvt = {
1866
+ value: value,
1867
+ item: item,
1868
+ cancel: false,
1869
+ isCheckingGroup: event.isCheckingGroup,
1870
+ };
1865
1871
  this._trigger((checked ? 'addsel' : 'removesel') + ':before', selEvt);
1866
1872
 
1867
1873
  if (selEvt.cancel) {
@@ -1919,16 +1925,26 @@ class SelectBox {
1919
1925
  this._scheduleSync('syncPlaceholder');
1920
1926
  }
1921
1927
 
1922
- this._trigger(checked ? 'addsel' : 'removesel', { value: value, item: item });
1928
+ this._trigger(checked ? 'addsel' : 'removesel', {
1929
+ value: value,
1930
+ item: item,
1931
+ isCheckingGroup: event.isCheckingGroup,
1932
+ });
1923
1933
  }
1924
1934
  break;
1925
1935
 
1926
1936
  case 'groupcheck': {
1927
1937
  if (!p.multi) return;
1928
1938
 
1929
- if (event.affectedItems) {
1939
+ if (event.affectedCount) {
1930
1940
  this._scheduleSync(p.sortSelectedItems ? 'full' : 'render_base');
1931
1941
  }
1942
+
1943
+ this._trigger('groupcheck', {
1944
+ value: event.value,
1945
+ item: event.item,
1946
+ affectedCount: event.affectedCount,
1947
+ });
1932
1948
  }
1933
1949
  break;
1934
1950
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/selectbox",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
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",
package/vue/SelectBox.vue CHANGED
@@ -724,8 +724,9 @@
724
724
 
725
725
  if (event === 'select' ||
726
726
  event === 'clear' ||
727
- event === 'addsel' ||
728
- event === 'removesel') {
727
+ event === 'groupcheck' ||
728
+ (event === 'addsel' && !event.isCheckingGroup) ||
729
+ (event === 'removesel' && !event.isCheckingGroup)) {
729
730
  let value = event === 'select' ? data.value : this.nonReactive.instance.getValue();
730
731
  if (value === undefined && event !== 'select' && this.emitNullForEmptyValue)
731
732
  value = null;