@danielgindi/selectbox 1.0.63 → 1.0.64

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 1.0.63
2
+ * @danielgindi/selectbox 1.0.64
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  'use strict';
@@ -8271,17 +8271,17 @@ var DropList = /*#__PURE__*/function () {
8271
8271
  function _updateGroupStateForItem(item) {
8272
8272
  var p = this._p;
8273
8273
 
8274
- if (p.multi && p.autoCheckGroupChildren) {
8275
-
8276
- var items, groupIndex, itemIndex;
8274
+ if (!p.multi)
8275
+ return this;
8277
8276
 
8278
- if (item._group) {var _item$ItemSymbol5;
8279
- // Now loop through children below the group
8277
+ if (item._group) {var _item$ItemSymbol5;
8278
+ // Now loop through children below the group
8280
8279
 
8281
- items = p.items;
8282
- groupIndex = items.indexOf(item);
8280
+ var affectedItems = 0;
8283
8281
 
8284
- var affectedItems = 0;
8282
+ if (p.autoCheckGroupChildren) {
8283
+ var items = p.items;
8284
+ var groupIndex = items.indexOf(item);
8285
8285
 
8286
8286
  for (var i = groupIndex + 1, len = items.length; i < len; i++) {var _next$ItemSymbol;
8287
8287
  var next = items[i];
@@ -8314,29 +8314,29 @@ var DropList = /*#__PURE__*/function () {
8314
8314
  isCheckingGroup: true });
8315
8315
 
8316
8316
  }
8317
+ }
8317
8318
 
8318
- // Fire event
8319
- this._trigger('groupcheck', {
8320
- value: item.value,
8321
- item: (_item$ItemSymbol5 = item[ItemSymbol$1]) !== null && _item$ItemSymbol5 !== void 0 ? _item$ItemSymbol5 : item,
8322
- affectedItems: affectedItems });
8323
-
8324
- } else if (p.groupCount > 0) {
8325
- items = p.items;
8326
- itemIndex = items.indexOf(item);
8327
- groupIndex = -1;
8328
-
8329
- // Find the group index
8330
- for (var _i8 = itemIndex - 1; _i8 >= 0; _i8--) {
8331
- if (items[_i8]._group) {
8332
- groupIndex = _i8;
8333
- break;
8334
- }
8319
+ // Fire event
8320
+ this._trigger('groupcheck', {
8321
+ value: item.value,
8322
+ item: (_item$ItemSymbol5 = item[ItemSymbol$1]) !== null && _item$ItemSymbol5 !== void 0 ? _item$ItemSymbol5 : item,
8323
+ affectedItems: affectedItems });
8324
+
8325
+ } else if (p.groupCount > 0 && p.autoCheckGroupChildren) {
8326
+ var _items = p.items;
8327
+ var itemIndex = _items.indexOf(item);
8328
+ var _groupIndex = -1;
8329
+
8330
+ // Find the group index
8331
+ for (var _i8 = itemIndex - 1; _i8 >= 0; _i8--) {
8332
+ if (_items[_i8]._group) {
8333
+ _groupIndex = _i8;
8334
+ break;
8335
8335
  }
8336
+ }
8336
8337
 
8337
- if (groupIndex > -1) {
8338
- this._updateGroupCheckedState(groupIndex, true);
8339
- }
8338
+ if (_groupIndex > -1) {
8339
+ this._updateGroupCheckedState(_groupIndex, true);
8340
8340
  }
8341
8341
  }
8342
8342
 
@@ -8346,50 +8346,50 @@ var DropList = /*#__PURE__*/function () {
8346
8346
  function _updateGroupCheckedState(groupIndex, fireEvents) {
8347
8347
  var p = this._p;
8348
8348
 
8349
- if (p.multi && p.autoCheckGroupChildren && groupIndex > -1) {
8349
+ if (!(p.multi && p.autoCheckGroupChildren && groupIndex > -1))
8350
+ return this;
8350
8351
 
8351
- var items = p.items;
8352
- var groupItem = items[groupIndex];
8353
- if (!groupItem || !groupItem._group) return this;
8352
+ var items = p.items;
8353
+ var groupItem = items[groupIndex];
8354
8354
 
8355
- var item,hasChecked = false,hasUnchecked = false;
8355
+ if (!groupItem || !groupItem._group) return this;
8356
8356
 
8357
- for (var i = groupIndex + 1, len = items.length; i < len; i++) {
8358
- item = items[i];
8357
+ var item,hasChecked = false,hasUnchecked = false;
8359
8358
 
8360
- // Hit the next group, break out
8361
- if (item._group || !item._child && items[i - 1]._child)
8362
- break;
8359
+ for (var i = groupIndex + 1, len = items.length; i < len; i++) {
8360
+ item = items[i];
8363
8361
 
8364
- if (item._checked) {
8365
- hasChecked = true;
8366
- } else if (!item._checked) {
8367
- hasUnchecked = true;
8368
- }
8362
+ // Hit the next group, break out
8363
+ if (item._group || !item._child && items[i - 1]._child)
8364
+ break;
8365
+
8366
+ if (item._checked) {
8367
+ hasChecked = true;
8368
+ } else if (!item._checked) {
8369
+ hasUnchecked = true;
8369
8370
  }
8371
+ }
8370
8372
 
8371
- // See if we need to update the group
8372
- var shouldCheckGroup = hasChecked && !hasUnchecked;
8373
- if (!!groupItem._checked !== shouldCheckGroup) {
8374
- // Update state
8375
- groupItem._checked = shouldCheckGroup;
8373
+ var shouldCheckGroup = hasChecked && !hasUnchecked;
8374
+ if (!!groupItem._checked !== shouldCheckGroup) {
8375
+ // Update state
8376
+ groupItem._checked = shouldCheckGroup;
8376
8377
 
8377
- // Update DOM
8378
- var nextEl = p.virtualListHelper.getItemElementAt(groupIndex);
8379
- if (nextEl) {
8380
- DomCompat.toggleClass(nextEl, "".concat(p.baseClassName, "__item_checked"), groupItem._checked);
8381
- }
8378
+ // Update DOM
8379
+ var nextEl = p.virtualListHelper.getItemElementAt(groupIndex);
8380
+ if (nextEl) {
8381
+ DomCompat.toggleClass(nextEl, "".concat(p.baseClassName, "__item_checked"), groupItem._checked);
8382
+ }
8382
8383
 
8383
- if (fireEvents) {var _groupItem$ItemSymbol;
8384
- // Fire event
8385
- this._trigger('check', {
8386
- value: groupItem.value,
8387
- item: (_groupItem$ItemSymbol = groupItem[ItemSymbol$1]) !== null && _groupItem$ItemSymbol !== void 0 ? _groupItem$ItemSymbol : groupItem,
8388
- checked: groupItem._checked,
8389
- isGroup: groupItem._group,
8390
- isCheckingGroup: false });
8384
+ if (fireEvents) {var _groupItem$ItemSymbol;
8385
+ // Fire event
8386
+ this._trigger('check', {
8387
+ value: groupItem.value,
8388
+ item: (_groupItem$ItemSymbol = groupItem[ItemSymbol$1]) !== null && _groupItem$ItemSymbol !== void 0 ? _groupItem$ItemSymbol : groupItem,
8389
+ checked: groupItem._checked,
8390
+ isGroup: groupItem._group,
8391
+ isCheckingGroup: false });
8391
8392
 
8392
- }
8393
8393
  }
8394
8394
  }
8395
8395
 
@@ -9660,6 +9660,7 @@ var inputBackbufferCssProps = [
9660
9660
  * @property {boolean} [sortSelectedItems=true] Should the selected items be sorted?
9661
9661
  * @property {boolean} [sortListItems=false] Sort list items
9662
9662
  * @property {boolean} [sortListCheckedFirst=true] When sorting - put checked items first (applicable to `multi` mode only)
9663
+ * @property {boolean} [treatGroupSelectionAsItems=false] Treat group items as normal items
9663
9664
  * @property {*[]} [stickyValues]
9664
9665
  * @property {function(a: DropList.ItemBase, b: DropList.ItemBase):number} [sortItemComparator]
9665
9666
  * @property {boolean} [splitListCheckedGroups=true] Split groups to "checked" and "unchecked", works with `sortCheckedFirst` only
@@ -9705,6 +9706,7 @@ var defaultOptions = {
9705
9706
  stickyValues: null,
9706
9707
  sortItemComparator: null,
9707
9708
  splitListCheckedGroups: true,
9709
+ treatGroupSelectionAsItems: false,
9708
9710
  blurOnSingleSelection: 'touch',
9709
9711
  multi: false,
9710
9712
  showSelection: true,
@@ -9794,6 +9796,7 @@ var SelectBox = /*#__PURE__*/function () {
9794
9796
  stickyValues: Array.isArray(o.stickyValues) ? new Set(o.stickyValues) : null,
9795
9797
  sortItemComparator: o.sortItemComparator,
9796
9798
  splitListCheckedGroups: !!o.splitListCheckedGroups,
9799
+ treatGroupSelectionAsItems: o.treatGroupSelectionAsItems,
9797
9800
  blurOnSingleSelection: o.blurOnSingleSelection,
9798
9801
  multi: o.multi,
9799
9802
  showSelection: o.showSelection,
@@ -10339,6 +10342,29 @@ var SelectBox = /*#__PURE__*/function () {
10339
10342
  return this._p.sortItemComparator;
10340
10343
  }
10341
10344
 
10345
+ /**
10346
+ * @param {boolean} treatGroupSelectionAsItems
10347
+ * @returns {SelectBox}
10348
+ */ }, { key: "setTreatGroupSelectionAsItems", value:
10349
+ function setTreatGroupSelectionAsItems(treatGroupSelectionAsItems) {
10350
+ var p = this._p;
10351
+ treatGroupSelectionAsItems = !!treatGroupSelectionAsItems;
10352
+ if (p.treatGroupSelectionAsItems === treatGroupSelectionAsItems)
10353
+ return this;
10354
+
10355
+ p.treatGroupSelectionAsItems = treatGroupSelectionAsItems;
10356
+ p.itemsChanged = true;
10357
+ this._scheduleSync();
10358
+ return this;
10359
+ }
10360
+
10361
+ /**
10362
+ * @returns {boolean}
10363
+ */ }, { key: "isTreatGroupSelectionAsItemsEnabled", value:
10364
+ function isTreatGroupSelectionAsItemsEnabled() {
10365
+ return !this._p.treatGroupSelectionAsItems;
10366
+ }
10367
+
10342
10368
  /**
10343
10369
  * @param {boolean} splitListCheckedGroups
10344
10370
  * @returns {SelectBox}
@@ -11290,7 +11316,7 @@ var SelectBox = /*#__PURE__*/function () {
11290
11316
  var value = event.value;
11291
11317
 
11292
11318
  var checked = event.checked;
11293
- if (event.isGroup) return; // Ignore groups
11319
+ if (event.isGroup && !p.treatGroupSelectionAsItems) return; // Ignore groups
11294
11320
 
11295
11321
  var selEvt = { value: value, item: item, cancel: false };
11296
11322
  _this5._trigger((checked ? 'addsel' : 'removesel') + ':before', selEvt);
@@ -11326,7 +11352,7 @@ var SelectBox = /*#__PURE__*/function () {
11326
11352
  _this5._scheduleSync('full');
11327
11353
  } else {
11328
11354
  if (p.maxMultiItems != null &&
11329
- p.selectedItems.filter(function (x) {return !x._group;}).length > p.maxMultiItems) {
11355
+ (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter(function (x) {return !x._group;})).length > p.maxMultiItems) {
11330
11356
  _this5._scheduleSync('addOrUpdateMultiItemRestElement');
11331
11357
  } else {
11332
11358
  _this5._scheduleSync('addMultiItemElement', item);
@@ -11337,7 +11363,7 @@ var SelectBox = /*#__PURE__*/function () {
11337
11363
  }
11338
11364
  } else {
11339
11365
  if (p.maxMultiItems != null &&
11340
- p.selectedItems.filter(function (x) {return !x._group;}).length === p.maxMultiItems) {
11366
+ (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter(function (x) {return !x._group;})).length === p.maxMultiItems) {
11341
11367
  _this5._scheduleSync('removeMultiItemRestElement');
11342
11368
  } else {
11343
11369
  _this5._scheduleSync('removeMultiItemElement', item);
@@ -11789,6 +11815,7 @@ var SelectBox = /*#__PURE__*/function () {
11789
11815
  var p = this._p;
11790
11816
 
11791
11817
  var term = p.filterTerm;
11818
+ var treatGroupSelectionAsItems = p.treatGroupSelectionAsItems;
11792
11819
 
11793
11820
  if (term || p.filterOnEmptyTerm && p.filterFn) {
11794
11821
  var fn = p.filterFn;
@@ -11807,7 +11834,7 @@ var SelectBox = /*#__PURE__*/function () {
11807
11834
  multiItemLabelProp = p.multiItemLabelProp;
11808
11835
 
11809
11836
  filteredItems = p.items.filter(function (x) {
11810
- if (x._group) return true;
11837
+ if (!treatGroupSelectionAsItems && x._group) return true;
11811
11838
  return matcher.test(x[labelProp] || x[multiItemLabelProp]);
11812
11839
  });
11813
11840
  } else {
@@ -11817,7 +11844,7 @@ var SelectBox = /*#__PURE__*/function () {
11817
11844
 
11818
11845
  p.filteredItems = filteredItems;
11819
11846
 
11820
- if (filteredItems) {
11847
+ if (filteredItems && !treatGroupSelectionAsItems) {
11821
11848
  // Clean up groups without children
11822
11849
 
11823
11850
  var lastGroup = -1;
@@ -12075,7 +12102,7 @@ var SelectBox = /*#__PURE__*/function () {
12075
12102
  var p = this._p;
12076
12103
 
12077
12104
  var items = p.selectedItems.slice(0);
12078
- var count = items.filter(function (x) {return !x._group;}).length - p.maxMultiItems;
12105
+ var count = (p.treatGroupSelectionAsItems ? items : items.filter(function (x) {return !x._group;})).length - p.maxMultiItems;
12079
12106
  var label = p.multiItemsRestLabelProvider ?
12080
12107
  p.multiItemsRestLabelProvider(count, items) : "+ ".concat(
12081
12108
  count);
@@ -12180,6 +12207,7 @@ var SelectBox = /*#__PURE__*/function () {
12180
12207
  if (p.multi) {
12181
12208
  if (fullItemsRender) {
12182
12209
  var items = p.selectedItems;
12210
+ var treatGroupSelectionAsItems = p.treatGroupSelectionAsItems;
12183
12211
 
12184
12212
  // Sort these
12185
12213
  if (p.sortSelectedItems) {
@@ -12212,7 +12240,7 @@ var SelectBox = /*#__PURE__*/function () {
12212
12240
 
12213
12241
  // Add item elements
12214
12242
  for (var i = 0; i < items.length; i++) {
12215
- if (items[i]._group) continue;
12243
+ if (!treatGroupSelectionAsItems && items[i]._group) continue;
12216
12244
 
12217
12245
  if (max != null && actualItemCount === max) {
12218
12246
  addRestItem = true;
@@ -12325,7 +12353,8 @@ var SelectBox = /*#__PURE__*/function () {
12325
12353
 
12326
12354
  if (item !== undefined) {
12327
12355
  if (value === RestMultiItemsSymbol) {
12328
- var items = p.selectedItems.filter(function (x) {return !x._group;}).slice(p.maxMultiItems);
12356
+ var items = (p.treatGroupSelectionAsItems ? p.selectedItems : p.selectedItems.filter(function (x) {return !x._group;})).
12357
+ slice(p.maxMultiItems);
12329
12358
  var itemsToRemove = [];var _iterator4 = _createForOfIteratorHelper(
12330
12359
 
12331
12360
  items),_step4;try {for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {var _item3 = _step4.value;