@syncfusion/ej2-lists 26.2.10 → 26.2.14

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.
@@ -1328,6 +1328,7 @@ var ListView = /** @__PURE__ @class */ (function (_super) {
1328
1328
  }
1329
1329
  break;
1330
1330
  case 'dataSource':
1331
+ this.previousScrollTop = this.element.scrollTop;
1331
1332
  if (this.enableVirtualization) {
1332
1333
  this.virtualizationModule.reRenderUiVirtualization();
1333
1334
  }
@@ -1724,6 +1725,28 @@ var ListView = /** @__PURE__ @class */ (function (_super) {
1724
1725
  this.virtualizationModule.refreshItemHeight();
1725
1726
  }
1726
1727
  };
1728
+ ListView.prototype.handleCheckboxState = function (li, checkIcon, checkboxElement, isCheckedBefore, isFocusedBefore, eventArgs, isSetCheckboxLI, textAreaFocus) {
1729
+ this.trigger('select', eventArgs, function (observedArgs) {
1730
+ if (observedArgs.cancel) {
1731
+ if (isSetCheckboxLI ? isCheckedBefore : !isCheckedBefore) {
1732
+ checkIcon.classList.add(classNames.checked);
1733
+ li.classList.add(classNames.selected);
1734
+ }
1735
+ else {
1736
+ checkIcon.classList.remove(classNames.checked);
1737
+ li.classList.remove(classNames.selected);
1738
+ }
1739
+ checkboxElement.setAttribute('aria-checked', isSetCheckboxLI ? (isCheckedBefore ? 'true' : 'false') : (isCheckedBefore ? 'false' : 'true'));
1740
+ merge(eventArgs, { isChecked: checkIcon.classList.contains(classNames.checked) });
1741
+ if (isFocusedBefore) {
1742
+ li.classList.remove(classNames.focused);
1743
+ if (textAreaFocus) {
1744
+ textAreaFocus.classList.remove('e-focused');
1745
+ }
1746
+ }
1747
+ }
1748
+ });
1749
+ };
1727
1750
  ListView.prototype.clickHandler = function (e) {
1728
1751
  if (Array.isArray(this.dataSource) && this.dataSource.length === 0) {
1729
1752
  return;
@@ -1765,7 +1788,10 @@ var ListView = /** @__PURE__ @class */ (function (_super) {
1765
1788
  var eventArgs = this.selectEventData(li, e);
1766
1789
  var checkIcon = li.querySelector('.' + classNames.checkboxIcon);
1767
1790
  merge(eventArgs, { isChecked: checkIcon.classList.contains(classNames.checked) });
1768
- this.trigger('select', eventArgs);
1791
+ var checkboxElement = li.querySelector('.' + classNames.checkboxWrapper);
1792
+ var isCheckedBefore = checkIcon.classList.contains(classNames.checked);
1793
+ var isFocusedBefore = li.classList.contains(classNames.focused);
1794
+ this.handleCheckboxState(li, checkIcon, checkboxElement, isCheckedBefore, isFocusedBefore, eventArgs, false);
1769
1795
  }
1770
1796
  }
1771
1797
  else if (li.classList.contains(classNames.hasChild)) {
@@ -1986,7 +2012,13 @@ var ListView = /** @__PURE__ @class */ (function (_super) {
1986
2012
  }
1987
2013
  var eventArgs = this.selectEventData(li, e);
1988
2014
  merge(eventArgs, { isChecked: checkIcon ? checkIcon.classList.contains(classNames.checked) : false });
1989
- this.trigger('select', eventArgs);
2015
+ if (!isNullOrUndefined(li)) {
2016
+ var cbElement = li.querySelector('.' + classNames.checkboxWrapper);
2017
+ var checkboxIcon = li.querySelector('.' + classNames.checkboxIcon);
2018
+ var isCheckedBefore = checkboxIcon.classList.contains(classNames.checked);
2019
+ var isFocusedBefore = li.classList.contains(classNames.focused);
2020
+ this.handleCheckboxState(li, checkboxIcon, cbElement, isCheckedBefore, isFocusedBefore, eventArgs, false);
2021
+ }
1990
2022
  this.updateSelectedId();
1991
2023
  }
1992
2024
  };
@@ -2061,8 +2093,9 @@ var ListView = /** @__PURE__ @class */ (function (_super) {
2061
2093
  if (!isNullOrUndefined(this.scroll)) {
2062
2094
  EventHandler.remove(this.element, 'scroll', this.onListScroll);
2063
2095
  }
2064
- if (this.touchModule)
2096
+ if (this.touchModule) {
2065
2097
  this.touchModule.destroy();
2098
+ }
2066
2099
  this.touchModule = null;
2067
2100
  };
2068
2101
  ListView.prototype.removeFocus = function () {
@@ -2115,7 +2148,9 @@ var ListView = /** @__PURE__ @class */ (function (_super) {
2115
2148
  var checkboxElement = li.querySelector('.' + classNames.checkboxWrapper);
2116
2149
  var checkIcon = checkboxElement.querySelector('.' + classNames.checkboxIcon + '.' + classNames.icon);
2117
2150
  this.removeHover();
2118
- if (!checkIcon.classList.contains(classNames.checked)) {
2151
+ var isCheckedBefore = checkIcon.classList.contains(classNames.checked);
2152
+ var isFocusedBefore = li.classList.contains(classNames.focused);
2153
+ if (!isCheckedBefore) {
2119
2154
  checkIcon.classList.add(classNames.checked);
2120
2155
  li.classList.add(classNames.selected);
2121
2156
  }
@@ -2130,7 +2165,7 @@ var ListView = /** @__PURE__ @class */ (function (_super) {
2130
2165
  if (this.enableVirtualization) {
2131
2166
  this.virtualizationModule.setCheckboxLI(li, e);
2132
2167
  }
2133
- this.trigger('select', eventArgs);
2168
+ this.handleCheckboxState(li, checkIcon, checkboxElement, isCheckedBefore, isFocusedBefore, eventArgs, true, textAreaFocus);
2134
2169
  this.setSelectedItemData(li);
2135
2170
  this.renderSubList(li);
2136
2171
  }
@@ -2199,6 +2234,10 @@ var ListView = /** @__PURE__ @class */ (function (_super) {
2199
2234
  _this.selectedLI = li;
2200
2235
  _this.renderSubList(li);
2201
2236
  }
2237
+ else {
2238
+ li.classList.remove(classNames.selected);
2239
+ _this.selectedLI = li;
2240
+ }
2202
2241
  });
2203
2242
  }
2204
2243
  };
@@ -2417,6 +2456,9 @@ var ListView = /** @__PURE__ @class */ (function (_super) {
2417
2456
  var ele = this.element.querySelector('[pid=\'' + uID + '\']');
2418
2457
  this.curDSLevel.push(uID);
2419
2458
  this.setViewDataSource(this.getSubDS());
2459
+ if (this.enableVirtualization) {
2460
+ this.virtualizationModule.updateDOMItemCount();
2461
+ }
2420
2462
  if (!ele) {
2421
2463
  var data = this.curViewDS;
2422
2464
  ele = ListBase.createListFromJson(this.createElement, data, this.listBaseOption, this.curDSLevel.length, null, this);
@@ -2525,6 +2567,9 @@ var ListView = /** @__PURE__ @class */ (function (_super) {
2525
2567
  }
2526
2568
  this.curDSLevel.pop();
2527
2569
  this.setViewDataSource(this.getSubDS());
2570
+ if (this.enableVirtualization) {
2571
+ this.virtualizationModule.updateDOMItemCount();
2572
+ }
2528
2573
  var toUL = this.element.querySelector('[data-uid=\'' + pID + '\']');
2529
2574
  var fromUL = this.curUL;
2530
2575
  if (!toUL) {
@@ -3221,18 +3266,21 @@ var Virtualization = /** @__PURE__ @class */ (function () {
3221
3266
  */
3222
3267
  Virtualization.prototype.uiVirtualization = function () {
3223
3268
  this.wireScrollEvent(false);
3269
+ var isRendered = this.listViewInstance.isRendered;
3270
+ var firstIndex = isRendered && !isNullOrUndefined(this.uiFirstIndex) ? this.uiFirstIndex : 0;
3224
3271
  var curViewDS = this.listViewInstance.curViewDS;
3225
- var firstDs = curViewDS.slice(0, 1);
3272
+ var firstDs = curViewDS.slice(firstIndex, firstIndex + 1);
3226
3273
  this.listViewInstance.ulElement = this.listViewInstance.curUL = ListBase.createList(this.listViewInstance.createElement, firstDs, this.listViewInstance.listBaseOption, null, this.listViewInstance);
3227
3274
  this.listViewInstance.contentContainer = this.listViewInstance.createElement('div', { className: classNames.container });
3228
3275
  this.listViewInstance.element.appendChild(this.listViewInstance.contentContainer);
3229
3276
  this.listViewInstance.contentContainer.appendChild(this.listViewInstance.ulElement);
3230
3277
  this.listItemHeight = this.listViewInstance.ulElement.firstElementChild.getBoundingClientRect().height;
3231
3278
  this.expectedDomItemCount = this.ValidateItemCount(10000);
3232
- this.domItemCount = this.ValidateItemCount(Object.keys(this.listViewInstance.curViewDS).length);
3233
- this.uiFirstIndex = 0;
3234
- this.uiLastIndex = this.domItemCount - 1;
3235
- var otherDs = curViewDS.slice(1, this.domItemCount);
3279
+ this.updateDOMItemCount();
3280
+ var lastIndex = isRendered && !isNullOrUndefined(this.uiLastIndex) ? this.uiLastIndex : this.domItemCount - 1;
3281
+ this.uiFirstIndex = firstIndex;
3282
+ this.uiLastIndex = lastIndex;
3283
+ var otherDs = curViewDS.slice(firstIndex + 1, lastIndex + 1);
3236
3284
  var listItems = ListBase.createListItemFromJson(this.listViewInstance.createElement, otherDs, this.listViewInstance.listBaseOption, null, null, this.listViewInstance);
3237
3285
  append(listItems, this.listViewInstance.ulElement);
3238
3286
  this.listViewInstance.liCollection = this.listViewInstance.curUL.querySelectorAll('li');
@@ -3241,11 +3289,14 @@ var Virtualization = /** @__PURE__ @class */ (function () {
3241
3289
  this.bottomElement = this.listViewInstance.createElement('div');
3242
3290
  this.listViewInstance.ulElement.insertBefore(this.bottomElement, null);
3243
3291
  this.totalHeight = (Object.keys(curViewDS).length * this.listItemHeight) - (this.domItemCount * this.listItemHeight);
3244
- this.topElement.style.height = 0 + 'px';
3245
- this.bottomElement.style.height = this.totalHeight + 'px';
3246
- this.topElementHeight = 0;
3247
- this.bottomElementHeight = this.totalHeight;
3248
- this.listDiff = 0;
3292
+ this.topElement.style.height = isRendered ? this.topElementHeight + 'px' : '0px';
3293
+ this.bottomElement.style.height = isRendered ? (this.totalHeight - this.topElementHeight) + 'px' : this.totalHeight + 'px';
3294
+ this.topElementHeight = isRendered ? this.topElementHeight : 0;
3295
+ this.bottomElementHeight = isRendered ? (this.totalHeight - this.topElementHeight) : this.totalHeight;
3296
+ this.listDiff = isRendered ? this.listDiff : 0;
3297
+ if (isRendered) {
3298
+ this.listViewInstance.element.scrollTop = this.listViewInstance.previousScrollTop;
3299
+ }
3249
3300
  this.uiIndicesInitialization();
3250
3301
  };
3251
3302
  Virtualization.prototype.wireScrollEvent = function (destroy) {
@@ -3287,6 +3338,9 @@ var Virtualization = /** @__PURE__ @class */ (function () {
3287
3338
  }
3288
3339
  return itemCount;
3289
3340
  };
3341
+ Virtualization.prototype.updateDOMItemCount = function () {
3342
+ this.domItemCount = this.ValidateItemCount(Object.keys(this.listViewInstance.curViewDS).length);
3343
+ };
3290
3344
  Virtualization.prototype.uiIndicesInitialization = function () {
3291
3345
  this.uiIndices = { 'activeIndices': [], 'disabledItemIndices': [], 'hiddenItemIndices': [] };
3292
3346
  var data = this.listViewInstance.curViewDS;
@@ -3586,18 +3640,19 @@ var Virtualization = /** @__PURE__ @class */ (function () {
3586
3640
  }
3587
3641
  };
3588
3642
  Virtualization.prototype.selectItem = function (obj) {
3643
+ var _this = this;
3589
3644
  var resutJSON = this.findDSAndIndexFromId(this.listViewInstance.curViewDS, obj);
3590
3645
  if (Object.keys(resutJSON).length) {
3591
3646
  var isSelected = this.activeIndex === resutJSON.index;
3592
- var isChecked = void 0;
3647
+ var isChecked_1;
3593
3648
  this.activeIndex = resutJSON.index;
3594
3649
  if (this.listViewInstance.showCheckBox) {
3595
3650
  if (this.uiIndices.activeIndices.indexOf(resutJSON.index) === -1) {
3596
- isChecked = true;
3651
+ isChecked_1 = true;
3597
3652
  this.uiIndices.activeIndices.push(resutJSON.index);
3598
3653
  }
3599
3654
  else {
3600
- isChecked = false;
3655
+ isChecked_1 = false;
3601
3656
  this.uiIndices.activeIndices.splice(this.uiIndices.activeIndices.indexOf(resutJSON.index), 1);
3602
3657
  }
3603
3658
  if (this.listViewInstance.curUL.querySelector('.' + classNames.focused)) {
@@ -3613,10 +3668,10 @@ var Virtualization = /** @__PURE__ @class */ (function () {
3613
3668
  }
3614
3669
  }
3615
3670
  else {
3616
- var eventArgs = void 0;
3671
+ var eventArgs_1;
3617
3672
  if (typeof this.listViewInstance.dataSource[0] === 'string' ||
3618
3673
  typeof this.listViewInstance.dataSource[0] === 'number') {
3619
- eventArgs = {
3674
+ eventArgs_1 = {
3620
3675
  text: this.listViewInstance.curViewDS[this.activeIndex],
3621
3676
  data: this.listViewInstance.curViewDS[this.activeIndex],
3622
3677
  index: this.activeIndex
@@ -3624,19 +3679,33 @@ var Virtualization = /** @__PURE__ @class */ (function () {
3624
3679
  }
3625
3680
  else {
3626
3681
  var curViewDS = this.listViewInstance.curViewDS;
3627
- eventArgs = {
3682
+ eventArgs_1 = {
3628
3683
  text: curViewDS[this.activeIndex][this.listViewInstance.fields.text],
3629
3684
  data: curViewDS[this.activeIndex],
3630
3685
  index: this.activeIndex
3631
3686
  };
3632
3687
  }
3633
3688
  if (this.listViewInstance.showCheckBox) {
3634
- eventArgs.isChecked = isChecked;
3635
- this.listViewInstance.trigger('select', eventArgs);
3689
+ this.listViewInstance.trigger('select', eventArgs_1, function (observedArgs) {
3690
+ if (observedArgs.cancel) {
3691
+ if (!isChecked_1) {
3692
+ eventArgs_1.isChecked = isChecked_1;
3693
+ _this.uiIndices.activeIndices.push(resutJSON.index);
3694
+ }
3695
+ else {
3696
+ eventArgs_1.isChecked = !isChecked_1;
3697
+ _this.uiIndices.activeIndices.splice(_this.uiIndices.activeIndices.indexOf(resutJSON.index), 1);
3698
+ }
3699
+ }
3700
+ });
3636
3701
  }
3637
3702
  else if (!isSelected) {
3638
3703
  this.listViewInstance.removeSelect();
3639
- this.listViewInstance.trigger('select', eventArgs);
3704
+ this.listViewInstance.trigger('select', eventArgs_1, function (observedArgs) {
3705
+ if (observedArgs.cancel) {
3706
+ _this.activeIndex = undefined;
3707
+ }
3708
+ });
3640
3709
  }
3641
3710
  }
3642
3711
  }