@danielgindi/selectbox 1.0.35 → 1.0.43

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
@@ -131,7 +131,7 @@ Emits the following events:
131
131
  'hide:before': the drop list will hide.
132
132
  'hide': the drop list was hidden.
133
133
  'hide:after': emitted after the hide css transition has ended, or immediately after 'hide'.
134
- 'check' {value, item, isCheckingGroup}: item was selected (in multi mode).
134
+ 'check' {value, item, checked: boolean, isGroup: boolean, isCheckingGroup: boolean}: item was selected (in multi mode).
135
135
  'groupcheck' {value, item, affectedItems}: item was selected (in multi mode).
136
136
  */
137
137
 
@@ -230,8 +230,13 @@ class DropList {
230
230
 
231
231
  if ((/**@type any*/index) === GhostSymbol) {
232
232
  item = {
233
- [p.labelProp]: p.lastMeasureLongestLabelText,
234
- [p.valueProp]: 'Measure',
233
+ label: p.lastMeasureLongestLabelText,
234
+ value: 'Measure',
235
+
236
+ [ItemSymbol]: {
237
+ [p.labelProp]: p.lastMeasureLongestLabelText,
238
+ [p.valueProp]: 'Measure',
239
+ },
235
240
  };
236
241
  itemEl.setAttribute('aria-hidden', 'true');
237
242
  } else {
@@ -285,7 +290,7 @@ class DropList {
285
290
  const fn = p.unrenderItem;
286
291
  p.virtualListHelper.setOnItemUnrender(el => {
287
292
  try {
288
- fn(el[ItemSymbol], el);
293
+ fn(el[ItemSymbol][ItemSymbol], el);
289
294
  } catch (err) { console.error(err); } // eslint-disable-line no-console
290
295
  delete el[ItemSymbol];
291
296
 
@@ -425,7 +430,7 @@ class DropList {
425
430
  if (!item)
426
431
  return;
427
432
 
428
- this._trigger('itemblur', { value: item[p.valueProp], item: item });
433
+ this._trigger('itemblur', { value: item.value, item: item[ItemSymbol] ?? item });
429
434
  }
430
435
 
431
436
  nextPage(event) {
@@ -447,7 +452,13 @@ class DropList {
447
452
  if (p.focusItemEl) {
448
453
  toggleClass(p.focusItemEl, `${p.baseClassName}__item_checked`, item._checked);
449
454
  }
450
- this._trigger('check', { value: item[p.valueProp], item: item });
455
+ this._trigger('check', {
456
+ value: item.value,
457
+ item: item[ItemSymbol] ?? item,
458
+ checked: item._checked,
459
+ isGroup: item._group,
460
+ isCheckingGroup: false,
461
+ });
451
462
 
452
463
  this._updateGroupStateForItem(item);
453
464
  }
@@ -472,7 +483,7 @@ class DropList {
472
483
  this._setSingleSelectedItemEl(p.focusItemEl);
473
484
  }
474
485
 
475
- this._trigger('select', { value: item ? item[p.valueProp] : undefined, item: item });
486
+ this._trigger('select', { value: item ? item.value : undefined, item: item[ItemSymbol] ?? item });
476
487
 
477
488
  return true;
478
489
  }
@@ -511,8 +522,8 @@ class DropList {
511
522
  //noinspection PointlessBooleanExpressionJS
512
523
  let item = {
513
524
  [ItemSymbol]: oitem,
514
- [labelProp]: oitem[labelProp],
515
- [valueProp]: oitem[valueProp],
525
+ label: oitem[labelProp],
526
+ value: oitem[valueProp],
516
527
  _nocheck: !!oitem._nocheck,
517
528
  _nointeraction: !!oitem._nointeraction,
518
529
  };
@@ -563,10 +574,10 @@ class DropList {
563
574
  item[ItemSymbol] = newItem;
564
575
 
565
576
  if (hasOwnProperty.call(newItem, p.labelProp))
566
- item[p.labelProp] = newItem[p.labelProp];
577
+ item.label = newItem[p.labelProp];
567
578
 
568
579
  if (hasOwnProperty.call(newItem, p.valueProp))
569
- item[p.valueProp] = newItem[p.valueProp];
580
+ item.value = newItem[p.valueProp];
570
581
 
571
582
  if (hasOwnProperty.call(newItem, '_nocheck'))
572
583
  item._nocheck = !!newItem._nocheck;
@@ -634,12 +645,12 @@ class DropList {
634
645
  }
635
646
 
636
647
  itemDataByValue(value) {
637
- const p = this._p, valueProp = p.valueProp;
648
+ const p = this._p;
638
649
 
639
650
  for (let i = 0, count = p.items.length; i < count; i++) {
640
651
  let item = p.items[i];
641
- if (item[valueProp] === value) {
642
- return item;
652
+ if (item.value === value) {
653
+ return item[ItemSymbol];
643
654
  }
644
655
  }
645
656
 
@@ -647,11 +658,11 @@ class DropList {
647
658
  }
648
659
 
649
660
  itemIndexByValue(value) {
650
- const p = this._p, valueProp = p.valueProp;
661
+ const p = this._p;
651
662
 
652
663
  for (let i = 0, count = p.items.length; i < count; i++) {
653
664
  let item = p.items[i];
654
- if (item[valueProp] === value) {
665
+ if (item.value === value) {
655
666
  return i;
656
667
  }
657
668
  }
@@ -660,11 +671,11 @@ class DropList {
660
671
  }
661
672
 
662
673
  itemIndexByValueOrLabel(value, label) {
663
- const p = this._p, labelProp = p.labelProp, valueProp = p.valueProp;
674
+ const p = this._p;
664
675
 
665
676
  for (let i = 0, count = p.items.length; i < count; i++) {
666
677
  let item = p.items[i];
667
- if (item[valueProp] === value || item[labelProp] === label) {
678
+ if (item.value === value || item.label === label) {
668
679
  return i;
669
680
  }
670
681
  }
@@ -673,7 +684,7 @@ class DropList {
673
684
  }
674
685
 
675
686
  items() {
676
- return this._p.items.slice(0);
687
+ return this._p.items.map(x => x[ItemSymbol]);
677
688
  }
678
689
 
679
690
  itemsReference() {
@@ -685,7 +696,7 @@ class DropList {
685
696
  }
686
697
 
687
698
  itemAtIndex(index) {
688
- return this._p.items[index];
699
+ return this._p.items[index]?.[ItemSymbol];
689
700
  }
690
701
 
691
702
  /**
@@ -965,13 +976,13 @@ class DropList {
965
976
  * @returns {DropList} self
966
977
  */
967
978
  setCheckedValues(values) {
968
- const p = this._p, valueProp = p.valueProp;
979
+ const p = this._p;
969
980
 
970
981
  let groupIndexes = [];
971
982
 
972
983
  for (let i = 0, count = p.items.length; i < count; i++) {
973
984
  let item = p.items[i];
974
- let checked = !item._nocheck && values.indexOf(item[valueProp]) !== -1;
985
+ let checked = !item._nocheck && values.indexOf(item.value) !== -1;
975
986
 
976
987
  if (item._group) {
977
988
  groupIndexes.push(i);
@@ -1003,7 +1014,7 @@ class DropList {
1003
1014
  * @returns {Array<*>} self
1004
1015
  */
1005
1016
  getCheckedValues(excludeGroups) {
1006
- const p = this._p, valueProp = p.valueProp;
1017
+ const p = this._p;
1007
1018
 
1008
1019
  excludeGroups = excludeGroups && p.groupCount > 0;
1009
1020
 
@@ -1013,7 +1024,7 @@ class DropList {
1013
1024
  let item = p.items[i];
1014
1025
  if (!item._checked) continue;
1015
1026
  if (excludeGroups && item._group) continue;
1016
- values.push(item[valueProp]);
1027
+ values.push(item.value);
1017
1028
  }
1018
1029
 
1019
1030
  return values;
@@ -1036,7 +1047,7 @@ class DropList {
1036
1047
  let item = p.items[i];
1037
1048
  if (!item._checked) continue;
1038
1049
  if (excludeGroups && item._group) continue;
1039
- items.push(item);
1050
+ items.push(item[ItemSymbol]);
1040
1051
  }
1041
1052
 
1042
1053
  return items;
@@ -1215,7 +1226,7 @@ class DropList {
1215
1226
  itemElement.classList.add(`${p.baseClassName}__item_focus`);
1216
1227
  p.focusItemEl = itemElement;
1217
1228
 
1218
- this._trigger('itemfocus', { value: itemElement[p.valueProp], item: itemElement[ItemSymbol], event: null });
1229
+ this._trigger('itemfocus', { value: itemElement.value, item: itemElement[ItemSymbol], event: null });
1219
1230
  }
1220
1231
  }
1221
1232
 
@@ -1372,15 +1383,15 @@ class DropList {
1372
1383
  }
1373
1384
 
1374
1385
  _getItemIndex(item) {
1375
- const p = this._p, labelProp = p.labelProp, valueProp = p.valueProp;
1386
+ const p = this._p;
1376
1387
 
1377
1388
  let itemIndex = -1;
1378
1389
 
1379
1390
  if (item) {
1380
1391
  itemIndex = p.items.indexOf(item);
1381
1392
  if (itemIndex === -1) {
1382
- let value = (item && item[valueProp] !== undefined) ? item[valueProp] : item;
1383
- let label = (item && item[labelProp]) ? item[labelProp] : value;
1393
+ let value = (item && item.value !== undefined) ? item.value : item;
1394
+ let label = (item && item.label) ? item.label : value;
1384
1395
  itemIndex = this.itemIndexByValueOrLabel(value, label);
1385
1396
  }
1386
1397
  }
@@ -1616,7 +1627,7 @@ class DropList {
1616
1627
  }
1617
1628
 
1618
1629
  _keydownFreeType(evt) {
1619
- const p = this._p, labelProp = p.labelProp;
1630
+ const p = this._p;
1620
1631
 
1621
1632
  // noinspection JSDeprecatedSymbols
1622
1633
  let character = evt.key || String.fromCharCode(evt.keyCode);
@@ -1635,7 +1646,7 @@ class DropList {
1635
1646
  // These are all the possible matches
1636
1647
  for (let i = 0, count = p.items.length; i < count; i++) {
1637
1648
  item = p.items[i];
1638
- if (regex.test(item[labelProp])) {
1649
+ if (regex.test(item.label)) {
1639
1650
  matchIndices.push(i);
1640
1651
  }
1641
1652
  }
@@ -1648,7 +1659,7 @@ class DropList {
1648
1659
 
1649
1660
  for (let i = 0, count = p.items.length; i < count; i++) {
1650
1661
  item = p.items[i];
1651
- if (regex.test(item[labelProp])) {
1662
+ if (regex.test(item.label)) {
1652
1663
  matchIndices.push(i);
1653
1664
  }
1654
1665
  }
@@ -1722,7 +1733,7 @@ class DropList {
1722
1733
  p.focusItemIndex = itemIndex;
1723
1734
 
1724
1735
  const item = p.items[itemIndex];
1725
- this._trigger('itemfocus', { value: item[p.valueProp], item: item, event: event });
1736
+ this._trigger('itemfocus', { value: item.value, item: item[ItemSymbol] ?? item, event: event });
1726
1737
  }
1727
1738
 
1728
1739
  _delayBlur() {
@@ -1875,7 +1886,7 @@ class DropList {
1875
1886
  }
1876
1887
 
1877
1888
  _updateGroupStateForItem(item) {
1878
- const p = this._p, valueProp = p.valueProp;
1889
+ const p = this._p;
1879
1890
 
1880
1891
  if (p.multi && p.autoCheckGroupChildren) {
1881
1892
 
@@ -1912,11 +1923,17 @@ class DropList {
1912
1923
  }
1913
1924
 
1914
1925
  // Fire event
1915
- this._trigger('check', { value: next[valueProp], item: next, isCheckingGroup: true });
1926
+ this._trigger('check', {
1927
+ value: next.value,
1928
+ item: next[ItemSymbol] ?? next,
1929
+ checked: item._checked,
1930
+ isGroup: item._group,
1931
+ isCheckingGroup: true,
1932
+ });
1916
1933
  }
1917
1934
 
1918
1935
  // Fire event
1919
- this._trigger('groupcheck', { value: item[valueProp], item: item, affectedItems: affectedItems });
1936
+ this._trigger('groupcheck', { value: item.value, item: item[ItemSymbol] ?? item, affectedItems: affectedItems });
1920
1937
  } else if (p.groupCount > 0) {
1921
1938
  items = p.items;
1922
1939
  itemIndex = items.indexOf(item);
@@ -1978,7 +1995,13 @@ class DropList {
1978
1995
 
1979
1996
  if (fireEvents) {
1980
1997
  // Fire event
1981
- this._trigger('check', { value: groupItem[p.valueProp], item: groupItem });
1998
+ this._trigger('check', {
1999
+ value: groupItem.value,
2000
+ item: groupItem[ItemSymbol] ?? groupItem,
2001
+ checked: item._checked,
2002
+ isGroup: item._group,
2003
+ isCheckingGroup: false,
2004
+ });
1982
2005
  }
1983
2006
  }
1984
2007
  }
@@ -1994,7 +2017,6 @@ class DropList {
1994
2017
  const p = this._p;
1995
2018
 
1996
2019
  if (p.lastMeasureItemCount !== p.items.length) {
1997
- const labelProp = p.labelProp, valueProp = p.valueProp;
1998
2020
  let longestLabel = p.lastMeasureLongestLabel || 1,
1999
2021
  longestLabelText = p.lastMeasureLongestLabelText || '';
2000
2022
 
@@ -2003,9 +2025,9 @@ class DropList {
2003
2025
  i++) {
2004
2026
 
2005
2027
  const item = items[i];
2006
- let text = item[labelProp];
2028
+ let text = item.label;
2007
2029
  if (text == null)
2008
- text = item[valueProp];
2030
+ text = item.value;
2009
2031
  if (text == null)
2010
2032
  text = '';
2011
2033
 
@@ -2054,7 +2076,7 @@ class DropList {
2054
2076
  }
2055
2077
 
2056
2078
  _renderItemContent(item, itemEl) {
2057
- const p = this._p, labelProp = p.labelProp;
2079
+ const p = this._p;
2058
2080
 
2059
2081
  // NOTE: a "measure" item will not have full data of original item.
2060
2082
  // so for a custom renderer - we try to send original item, and fallback to our private list item.
@@ -2062,7 +2084,7 @@ class DropList {
2062
2084
  if (!p.renderItem || p.renderItem(item[ItemSymbol] || item, itemEl) === false) {
2063
2085
  itemEl.appendChild(createElement('span', {
2064
2086
  class: `${p.baseClassName}__item_label`,
2065
- textContent: item[labelProp],
2087
+ textContent: item.label,
2066
2088
  }));
2067
2089
 
2068
2090
  if (p.multi) {
package/lib/SelectBox.js CHANGED
@@ -253,6 +253,7 @@ class SelectBox {
253
253
 
254
254
  items: [],
255
255
  filteredItems: null,
256
+ currentItemsView: [], // contains the final version of items sent to DropList
256
257
  itemsChanged: true,
257
258
 
258
259
  sink: new DomEventsSink(),
@@ -1729,8 +1730,8 @@ class SelectBox {
1729
1730
  const item = /**@type DropList.Item*/event.item;
1730
1731
  const value = event.value;
1731
1732
 
1732
- let checked = item._checked;
1733
- if (item._group) return; // Ignore groups
1733
+ let checked = event.checked;
1734
+ if (event.isGroup) return; // Ignore groups
1734
1735
 
1735
1736
  let selEvt = { value: value, item: item, cancel: false };
1736
1737
  this._trigger((checked ? 'addsel' : 'removesel') + ':before', selEvt);
@@ -1874,16 +1875,26 @@ class SelectBox {
1874
1875
 
1875
1876
  switch (evt.key) {
1876
1877
  case VALUE_PAGE_UP:
1877
- dropList.previousPage(evt);
1878
+ if (dropList.isVisible())
1879
+ dropList.previousPage(evt);
1878
1880
  break;
1879
1881
  case VALUE_PAGE_DOWN:
1880
- dropList.nextPage(evt);
1882
+ if (dropList.isVisible())
1883
+ dropList.nextPage(evt);
1881
1884
  break;
1882
1885
  case VALUE_UP:
1883
- dropList.previous(evt);
1886
+ if (dropList.isVisible()) {
1887
+ dropList.previous(evt);
1888
+ } else {
1889
+ this._movePrev();
1890
+ }
1884
1891
  break;
1885
1892
  case VALUE_DOWN:
1886
- dropList.next(evt);
1893
+ if (dropList.isVisible()) {
1894
+ dropList.next(evt);
1895
+ } else {
1896
+ this._moveNext();
1897
+ }
1887
1898
  break;
1888
1899
 
1889
1900
  }
@@ -1891,7 +1902,7 @@ class SelectBox {
1891
1902
 
1892
1903
  case VALUE_SPACE:
1893
1904
  if (p.lastKeyAllowsSpaceToggle) {
1894
- if (dropList.hasFocusedItem()) {
1905
+ if (dropList.isVisible() && dropList.hasFocusedItem()) {
1895
1906
  suppressKeyPress = true;
1896
1907
  suppressKeyPressRepeat = true;
1897
1908
  if (p.multi)
@@ -1913,7 +1924,7 @@ class SelectBox {
1913
1924
  break;
1914
1925
 
1915
1926
  case VALUE_TAB:
1916
- if (dropList.hasFocusedItem()) {
1927
+ if (dropList.isVisible() && dropList.hasFocusedItem()) {
1917
1928
  dropList.triggerItemSelection(evt);
1918
1929
  }
1919
1930
  break;
@@ -1970,18 +1981,27 @@ class SelectBox {
1970
1981
 
1971
1982
  switch (evt.key) {
1972
1983
  case VALUE_PAGE_UP:
1973
- dropList.previousPage(evt);
1984
+ if (dropList.isVisible())
1985
+ dropList.previousPage(evt);
1974
1986
  break;
1975
1987
  case VALUE_PAGE_DOWN:
1976
- dropList.nextPage(evt);
1988
+ if (dropList.isVisible())
1989
+ dropList.nextPage(evt);
1977
1990
  break;
1978
1991
  case VALUE_UP:
1979
- dropList.previous(evt);
1992
+ if (dropList.isVisible()) {
1993
+ dropList.previous(evt);
1994
+ } else {
1995
+ this._movePrev();
1996
+ }
1980
1997
  break;
1981
1998
  case VALUE_DOWN:
1982
- dropList.next(evt);
1999
+ if (dropList.isVisible()) {
2000
+ dropList.next(evt);
2001
+ } else {
2002
+ this._moveNext();
2003
+ }
1983
2004
  break;
1984
-
1985
2005
  }
1986
2006
  break;
1987
2007
  }
@@ -2066,6 +2086,40 @@ class SelectBox {
2066
2086
  });
2067
2087
  }
2068
2088
 
2089
+ _movePrev() {
2090
+ const p = this._p;
2091
+
2092
+ if (this.isMultiEnabled()) return;
2093
+
2094
+ let selectedItems = this.getSelectedItems();
2095
+ let items = p.filteredItems ?? p.items;
2096
+ if (p.currentItemsView && p.currentItemsView.length === items.length)
2097
+ items = p.currentItemsView;
2098
+ if ((items.length + (p.clearable ? 1 : 0)) > 1) {
2099
+ let nextIndex = selectedItems.length > 0 ? items.indexOf(selectedItems[0]) - 1 : (items.length - 1);
2100
+ if (nextIndex === -1 && !p.clearable)
2101
+ nextIndex = items.length - 1;
2102
+ this.setSelectedItems(nextIndex === -1 ? [] : [items[nextIndex]]);
2103
+ }
2104
+ }
2105
+
2106
+ _moveNext() {
2107
+ const p = this._p;
2108
+
2109
+ if (this.isMultiEnabled()) return;
2110
+
2111
+ let selectedItems = this.getSelectedItems();
2112
+ let items = p.filteredItems ?? p.items;
2113
+ if (p.currentItemsView && p.currentItemsView.length === items.length)
2114
+ items = p.currentItemsView;
2115
+ if ((items.length + (p.clearable ? 1 : 0)) > 1) {
2116
+ let nextIndex = selectedItems.length > 0 ? items.indexOf(selectedItems[0]) + 1 : 0;
2117
+ if (nextIndex === items.length)
2118
+ nextIndex = p.clearable ? -1 : 0;
2119
+ this.setSelectedItems(nextIndex === -1 ? [] : [items[nextIndex]]);
2120
+ }
2121
+ }
2122
+
2069
2123
  /** @private */
2070
2124
  _updateListItems() {
2071
2125
  const p = this._p;
@@ -2104,6 +2158,7 @@ class SelectBox {
2104
2158
  }
2105
2159
 
2106
2160
  dropList.addItems(items);
2161
+ p.currentItemsView = items;
2107
2162
  p.itemsChanged = false;
2108
2163
  p.selectionChanged = true;
2109
2164
  p.resortBySelectionNeeded = false;
@@ -3059,7 +3114,7 @@ class SelectBox {
3059
3114
  }
3060
3115
 
3061
3116
  const aLabel = a[labelProp] || a[multiItemLabelProp];
3062
- const bLabel = a[labelProp] || a[multiItemLabelProp];
3117
+ const bLabel = b[labelProp] || b[multiItemLabelProp];
3063
3118
 
3064
3119
  if (aLabel < bLabel) return -1;
3065
3120
  if (aLabel > bLabel) return 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/selectbox",
3
- "version": "1.0.35",
3
+ "version": "1.0.43",
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,26 +31,30 @@
31
31
  "homepage": "https://github.com/danielgindi/selectbox#readme",
32
32
  "license": "MIT",
33
33
  "devDependencies": {
34
- "@babel/core": "^7.15.8",
35
- "@babel/preset-env": "^7.15.8",
36
- "@babel/runtime": "^7.15.4",
34
+ "@babel/core": "^7.16.0",
35
+ "@babel/preset-env": "^7.16.0",
36
+ "@babel/runtime": "^7.16.3",
37
37
  "@rollup/plugin-babel": "^5.3.0",
38
- "@rollup/plugin-commonjs": "^21.0.0",
39
- "@rollup/plugin-node-resolve": "^13.0.5",
40
- "core-js": "^3.18.2",
41
- "eslint": "^7.32.0",
42
- "eslint-plugin-vue": "^7.19.1",
38
+ "@rollup/plugin-commonjs": "^21.0.1",
39
+ "@rollup/plugin-node-resolve": "^13.0.6",
40
+ "core-js": "^3.19.1",
41
+ "eslint": "^8.2.0",
42
+ "eslint-formatter-codeframe": "^7.32.1",
43
+ "eslint-plugin-vue": "^8.0.3",
43
44
  "fs-extra": "^10.0.0",
44
- "husky": "^7.0.2",
45
+ "husky": "^7.0.4",
45
46
  "pinst": "^2.1.6",
46
- "rollup": "^2.58.0",
47
+ "rollup": "^2.59.0",
47
48
  "rollup-plugin-terser": "^7.0.2",
48
- "sass": "^1.42.1"
49
+ "sass": "^1.43.4"
49
50
  },
50
51
  "dependencies": {
51
- "@danielgindi/dom-utils": "^1.0.4",
52
+ "@danielgindi/dom-utils": "^1.0.5",
52
53
  "@danielgindi/virtual-list-helper": "^1.0.3",
53
54
  "keycode-js": "^3.1.0",
54
55
  "mitt": "^3.0.0"
56
+ },
57
+ "peerDependencies": {
58
+ "vue": "^2.*"
55
59
  }
56
60
  }
package/vue/DropList.vue CHANGED
@@ -7,27 +7,9 @@
7
7
  </template>
8
8
 
9
9
  <script>
10
- import Vue from 'vue';
11
10
  import DropList from '../lib/DropList';
12
11
  import DomEventsSink from '@danielgindi/dom-utils/lib/DomEventsSink';
13
-
14
- const generateVNodeRenderer = vnode => {
15
- return new Vue({
16
- render() {
17
- return vnode;
18
- },
19
- });
20
- };
21
-
22
- const generateVNodesRenderer = vnodes => {
23
- return new Vue({
24
- render(h) {
25
- return h('div', vnodes);
26
- },
27
- });
28
- };
29
-
30
- const VueInstanceSymbol = Symbol('vue_instance');
12
+ import { createSlotBasedRenderFunc, createSlotBasedUnrenderFunc } from './utils/slots.js';
31
13
 
32
14
  export default {
33
15
  props: {
@@ -152,8 +134,18 @@
152
134
  opts.keyDownHandler = this.keyDownHandler;
153
135
  }
154
136
 
155
- opts.renderItem = this.renderItem || this._createSlotBasedRenderFunc('item');
156
- opts.unrenderItem = this.unrenderItem || this._createSlotBasedUnrenderFunc('item');
137
+ opts.renderItem = this.renderItem;
138
+ if (!opts.renderItem) {
139
+ opts.renderItem = createSlotBasedRenderFunc(this, 'item');
140
+ }
141
+
142
+ opts.unrenderItem = this.unrenderItem;
143
+ if (!opts.unrenderItem) {
144
+ let fn = createSlotBasedUnrenderFunc(this, 'item');
145
+ if (fn) {
146
+ opts.unrenderItem = (item, el) => fn(el);
147
+ }
148
+ }
157
149
 
158
150
  return opts;
159
151
  },
@@ -242,65 +234,6 @@
242
234
  }
243
235
  },
244
236
 
245
- _createSlotBasedRenderFunc(slotName, onAfterUpdate) {
246
- if (this.$scopedSlots[slotName]) {
247
- return (item, parent) => {
248
- let vnode = this.$scopedSlots[slotName](item);
249
- let vm;
250
-
251
- if (Array.isArray(vnode)) {
252
- vm = generateVNodesRenderer(vnode);
253
- vm.$mount();
254
- let nodes = vm.$el.childNodes;
255
- nodes[0][VueInstanceSymbol] = vm;
256
- for (let node of nodes)
257
- parent.appendChild(node);
258
- } else {
259
- vm = generateVNodeRenderer(vnode);
260
- vm.$mount();
261
- vm.$el[VueInstanceSymbol] = vm;
262
- parent.appendChild(vm.$el);
263
- }
264
-
265
- if (onAfterUpdate) {
266
- vm.$on('hook:updated', () => {
267
- vm.$nextTick(() => onAfterUpdate(item));
268
- });
269
- }
270
- };
271
- }
272
-
273
- if (this.$slots[slotName]) {
274
- return (item, parent) => {
275
- let vnode = this.$slots[slotName];
276
- let vm = generateVNodeRenderer(vnode);
277
- vm.$mount();
278
- vm.$el[VueInstanceSymbol] = vm;
279
- parent.appendChild(vm.$el);
280
-
281
- if (onAfterUpdate) {
282
- vm.$on('hook:updated', () => {
283
- vm.$nextTick(() => onAfterUpdate(item));
284
- });
285
- }
286
- };
287
- }
288
- },
289
-
290
- _createSlotBasedUnrenderFunc(slotName) {
291
- if (this.$slots[slotName] || this.$slots[slotName]) {
292
- return (_item, parent) => {
293
- if (parent.childNodes.length > 0) {
294
- let node = parent.childNodes[0][VueInstanceSymbol];
295
- if (node) {
296
- node.$destroy();
297
- delete parent.childNodes[0][VueInstanceSymbol];
298
- }
299
- }
300
- };
301
- }
302
- },
303
-
304
237
  _createList() {
305
238
  this._destroyList();
306
239