@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/dist/lib.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 2.0.6
2
+ * @danielgindi/selectbox 2.0.8
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  (function (global, factory) {
@@ -184,7 +184,7 @@
184
184
  'hide': the drop list was hidden.
185
185
  'hide:after': emitted after the hide css transition has ended, or immediately after 'hide'.
186
186
  'check' {value, item, checked: boolean, isGroup: boolean, isCheckingGroup: boolean}: item was selected (in multi mode).
187
- 'groupcheck' {value, item, affectedItems}: item was selected (in multi mode).
187
+ 'groupcheck' {value, item, affectedCount: number}: item was selected (in multi mode).
188
188
  'blur' {event}: element lost focus
189
189
  'show_subitems {value, item, el, droplist: DropList}': subitems dropdown will show.
190
190
  'hide_subitems {value, item, el}': subitems dropdown did hide.
@@ -777,6 +777,10 @@
777
777
  p.groupCount++;
778
778
  }
779
779
 
780
+ if (typeof oitem._level === 'number') {
781
+ item._level = oitem._level;
782
+ }
783
+
780
784
  if (oitem._child) {
781
785
  // This is used for setting a child class,
782
786
  // But can be used to determine that current item is not part of above group,
@@ -879,6 +883,10 @@
879
883
  }
880
884
  }
881
885
 
886
+ if (hasOwnProperty.call(newItem, '_level')) {
887
+ newItem._level = item._level;
888
+ }
889
+
882
890
  if (hasOwnProperty.call(newItem, '_child'))
883
891
  item._child = !!newItem._child;
884
892
 
@@ -1184,7 +1192,15 @@
1184
1192
  if (typeof fn === 'function') {
1185
1193
  // Send the original items to the filter function
1186
1194
  filteredItems = p.filterFn(
1187
- p.items.map((x) => x[ItemSymbol] ?? x),
1195
+ p.items.map((x) => {
1196
+ const y = x[ItemSymbol];
1197
+ if (y !== undefined) {
1198
+ y[ItemSymbol] = x;
1199
+ return y;
1200
+ }
1201
+
1202
+ return x;
1203
+ }),
1188
1204
  term);
1189
1205
 
1190
1206
  if (Array.isArray(filteredItems)) {
@@ -1200,6 +1216,7 @@
1200
1216
  _nointeraction: !!oitem._nointeraction,
1201
1217
  _subitems: oitem._subitems,
1202
1218
  _group: !!oitem._group,
1219
+ _level: !!oitem._level,
1203
1220
  _checked: !!oitem._checked
1204
1221
  };
1205
1222
  }
@@ -3006,17 +3023,19 @@
3006
3023
  if (item._group) {
3007
3024
  // Now loop through children below the group
3008
3025
 
3009
- let affectedItems = 0;
3026
+ let affectedCount = 0;
3010
3027
 
3011
3028
  if (p.autoCheckGroupChildren) {
3012
3029
  const items = p.filteredItems ?? p.items;
3013
3030
  let groupIndex = items.indexOf(item);
3031
+ const groupLevel = item._level;
3014
3032
 
3015
3033
  for (let i = groupIndex + 1, len = items.length; i < len; i++) {
3016
3034
  let next = items[i];
3017
3035
 
3018
3036
  // Hit the next group, break out
3019
- if (next._group || !next._child && items[i - 1]._child)
3037
+ if (!next._child && items[i - 1]._child || (
3038
+ groupLevel === undefined ? next._group || next._level !== undefined : next._level <= groupLevel))
3020
3039
  break;
3021
3040
 
3022
3041
  // No change, skip
@@ -3026,7 +3045,7 @@
3026
3045
  // Update state
3027
3046
  next._checked = item._checked;
3028
3047
 
3029
- affectedItems++;
3048
+ affectedCount++;
3030
3049
 
3031
3050
  // Update DOM
3032
3051
  let nextEl = p.virtualListHelper.getItemElementAt(i);
@@ -3049,7 +3068,7 @@
3049
3068
  this._trigger('groupcheck', {
3050
3069
  value: item.value,
3051
3070
  item: item[ItemSymbol] ?? item,
3052
- affectedItems: affectedItems
3071
+ affectedCount: affectedCount
3053
3072
  });
3054
3073
  } else if (p.groupCount > 0 && p.autoCheckGroupChildren) {
3055
3074
  const items = p.filteredItems ?? p.items;
@@ -3083,18 +3102,21 @@
3083
3102
 
3084
3103
  if (!groupItem || !groupItem._group) return this;
3085
3104
 
3086
- let item,hasChecked = false,hasUnchecked = false;
3105
+ let next,hasChecked = false,hasUnchecked = false;
3106
+
3107
+ const groupLevel = groupItem._level;
3087
3108
 
3088
3109
  for (let i = groupIndex + 1, len = items.length; i < len; i++) {
3089
- item = items[i];
3110
+ next = items[i];
3090
3111
 
3091
3112
  // Hit the next group, break out
3092
- if (item._group || !item._child && items[i - 1]._child)
3113
+ if (!next._child && items[i - 1]._child || (
3114
+ groupLevel === undefined ? next._group || next._level !== undefined : next._level <= groupLevel))
3093
3115
  break;
3094
3116
 
3095
- if (item._checked) {
3117
+ if (next._checked) {
3096
3118
  hasChecked = true;
3097
- } else if (!item._checked) {
3119
+ } else if (!next._checked) {
3098
3120
  hasUnchecked = true;
3099
3121
  }
3100
3122
  }
@@ -3451,11 +3473,12 @@
3451
3473
  'open' { list: DropList }: the drop list is opening
3452
3474
  'open:before' { list: DropList }: the drop list will open
3453
3475
  'close': the drop list is closing
3454
- 'addsel:before' {value, item, cancel: false}: an item selection is about to be added (in multi mode). return false to abort.
3455
- 'removesel:before' {value, item, cancel: false}: an item selection is about to be removed (in multi mode). return false to abort.
3476
+ 'addsel:before' {value, item, cancel: false, isCheckingGroup: bool}: an item selection is about to be added (in multi mode). return false to abort.
3477
+ 'removesel:before' {value, item, cancel: false, isCheckingGroup: bool}: an item selection is about to be removed (in multi mode). return false to abort.
3478
+ 'addsel' {value, item, isCheckingGroup: bool}: an item selection has been added (in multi mode)
3479
+ 'removesel' {value, item, isCheckingGroup: bool}: an item selection has been removed (in multi mode)
3480
+ 'groupcheck' {value, item, affectedCount: number}: an item selection has been removed (in multi mode)
3456
3481
  'select:before' {value, item, cancel: false}: an item is about to be selected (in single mode). return false to abort.
3457
- 'addsel' {value, item}: an item selection has been added (in multi mode)
3458
- 'removesel' {value, item}: an item selection has been removed (in multi mode)
3459
3482
  'select' {value, item}: an item has been selected (in single mode)
3460
3483
  'search' {value}: input box value has changed
3461
3484
  'search:focus': input box has gained focus
@@ -5133,7 +5156,12 @@
5133
5156
  let checked = event.checked;
5134
5157
  if (event.isGroup && !p.treatGroupSelectionAsItems) return; // Ignore groups
5135
5158
 
5136
- let selEvt = { value: value, item: item, cancel: false };
5159
+ let selEvt = {
5160
+ value: value,
5161
+ item: item,
5162
+ cancel: false,
5163
+ isCheckingGroup: event.isCheckingGroup
5164
+ };
5137
5165
  this._trigger((checked ? 'addsel' : 'removesel') + ':before', selEvt);
5138
5166
 
5139
5167
  if (selEvt.cancel) {
@@ -5191,16 +5219,26 @@
5191
5219
  this._scheduleSync('syncPlaceholder');
5192
5220
  }
5193
5221
 
5194
- this._trigger(checked ? 'addsel' : 'removesel', { value: value, item: item });
5222
+ this._trigger(checked ? 'addsel' : 'removesel', {
5223
+ value: value,
5224
+ item: item,
5225
+ isCheckingGroup: event.isCheckingGroup
5226
+ });
5195
5227
  }
5196
5228
  break;
5197
5229
 
5198
5230
  case 'groupcheck':{
5199
5231
  if (!p.multi) return;
5200
5232
 
5201
- if (event.affectedItems) {
5233
+ if (event.affectedCount) {
5202
5234
  this._scheduleSync(p.sortSelectedItems ? 'full' : 'render_base');
5203
5235
  }
5236
+
5237
+ this._trigger('groupcheck', {
5238
+ value: event.value,
5239
+ item: event.item,
5240
+ affectedCount: event.affectedCount
5241
+ });
5204
5242
  }
5205
5243
  break;
5206
5244