@syncfusion/ej2-dropdowns 34.2.3 → 34.2.5

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.
@@ -9612,8 +9612,129 @@ let DropDownTree = class DropDownTree extends Component {
9612
9612
  checkOnClick: true
9613
9613
  });
9614
9614
  this.treeObj.root = this.root ? this.root : this;
9615
+ this.treeObj.filterIndeterminateNodes = [];
9616
+ this.treeObj.filterCheckedNodes = [];
9615
9617
  this.treeObj.appendTo(this.tree);
9616
9618
  }
9619
+ updateIndeterminateNodes() {
9620
+ if (!(this.allowFiltering && this.treeSettings.autoCheck) || (this.isRemoteData || this.treeSettings.loadOnDemand)) {
9621
+ return;
9622
+ }
9623
+ const checkedNodes = Array.isArray(this.value) ? this.value.slice() : [];
9624
+ const checkedSet = {};
9625
+ for (let i = 0; i < checkedNodes.length; i++) {
9626
+ checkedSet[checkedNodes[i]] = true;
9627
+ }
9628
+ const treeData = this.treeObj.element.classList.contains('e-filtering') ? this.treeData : this.treeItems;
9629
+ const valueField = this.fields.value;
9630
+ const parentValueField = this.fields.parentValue;
9631
+ const hasChildrenField = this.fields.hasChildren;
9632
+ const childField = this.fields.child;
9633
+ const indeterminateNodes = [];
9634
+ const childrenMap = {};
9635
+ for (let i = 0; i < treeData.length; i++) {
9636
+ const node = treeData[i];
9637
+ const nodeId = getValue(valueField, node);
9638
+ const nodePid = getValue(parentValueField, node);
9639
+ if (isNullOrUndefined(node) || isNullOrUndefined(nodeId) || isNullOrUndefined(nodePid)) {
9640
+ continue;
9641
+ }
9642
+ const parentId = nodePid.toString();
9643
+ if (!childrenMap[parentId]) {
9644
+ childrenMap[parentId] = [];
9645
+ }
9646
+ childrenMap[parentId].push(nodeId.toString());
9647
+ }
9648
+ const allNodes = treeData.slice();
9649
+ if (!isNullOrUndefined(childField)) {
9650
+ const collectNestedChildren = (nodes, fields) => {
9651
+ if (!nodes) {
9652
+ return;
9653
+ }
9654
+ for (let i = 0; i < nodes.length; i++) {
9655
+ const node = nodes[i];
9656
+ if (isNullOrUndefined(node)) {
9657
+ continue;
9658
+ }
9659
+ const nodeId = getValue(fields.value, node);
9660
+ if (isNullOrUndefined(nodeId)) {
9661
+ continue;
9662
+ }
9663
+ allNodes.push(node);
9664
+ const childMapper = fields.child;
9665
+ let childrenArr;
9666
+ if (typeof childMapper === 'string') {
9667
+ childrenArr = node[childMapper];
9668
+ }
9669
+ else if (!isNullOrUndefined(childMapper)) {
9670
+ childrenArr = node[childMapper.value];
9671
+ }
9672
+ else {
9673
+ childrenArr = null;
9674
+ }
9675
+ if (!isNullOrUndefined(childrenArr) && Array.isArray(childrenArr) && childrenArr.length) {
9676
+ const parentId = nodeId.toString();
9677
+ if (!childrenMap[parentId]) {
9678
+ childrenMap[parentId] = [];
9679
+ }
9680
+ for (let k = 0; k < childrenArr.length; k++) {
9681
+ const childId = getValue(fields.value, childrenArr[k]);
9682
+ if (!isNullOrUndefined(childId) && childrenMap[parentId].indexOf(childId.toString()) === -1) {
9683
+ childrenMap[parentId].push(childId.toString());
9684
+ }
9685
+ }
9686
+ const nextFields = (typeof childMapper !== 'string' && !isNullOrUndefined(childMapper)) ?
9687
+ childMapper : fields;
9688
+ collectNestedChildren(childrenArr, nextFields);
9689
+ }
9690
+ }
9691
+ };
9692
+ collectNestedChildren(treeData, this.fields);
9693
+ }
9694
+ for (let i = 0; i < allNodes.length; i++) {
9695
+ const node = allNodes[i];
9696
+ const nodeId = getValue(valueField, node);
9697
+ if (isNullOrUndefined(node) || isNullOrUndefined(nodeId)) {
9698
+ continue;
9699
+ }
9700
+ const nodeIdStr = nodeId.toString();
9701
+ if (hasChildrenField && getValue(hasChildrenField, node) === false) {
9702
+ continue;
9703
+ }
9704
+ if (checkedSet[nodeIdStr]) {
9705
+ continue;
9706
+ }
9707
+ const descendants = [];
9708
+ const queue = childrenMap[nodeIdStr] ? childrenMap[nodeIdStr].slice() : [];
9709
+ let head = 0;
9710
+ while (head < queue.length) {
9711
+ const current = queue[head];
9712
+ head++;
9713
+ descendants.push(current);
9714
+ const kids = childrenMap[current];
9715
+ if (kids) {
9716
+ for (let j = 0; j < kids.length; j++) {
9717
+ queue.push(kids[j]);
9718
+ }
9719
+ }
9720
+ }
9721
+ if (descendants.length === 0) {
9722
+ continue;
9723
+ }
9724
+ let checkedDescendantCount = 0;
9725
+ for (let j = 0; j < descendants.length; j++) {
9726
+ if (checkedSet[descendants[j]]) {
9727
+ checkedDescendantCount++;
9728
+ }
9729
+ }
9730
+ if (checkedDescendantCount > 0 && checkedDescendantCount < descendants.length &&
9731
+ indeterminateNodes.indexOf(nodeIdStr) === -1) {
9732
+ indeterminateNodes.push(nodeIdStr);
9733
+ }
9734
+ }
9735
+ this.treeObj.filterCheckedNodes = checkedNodes;
9736
+ this.treeObj.filterIndeterminateNodes = indeterminateNodes;
9737
+ }
9617
9738
  /* To render the popup element */
9618
9739
  renderPopup() {
9619
9740
  if (this.isFilteredData) {
@@ -9910,6 +10031,7 @@ let DropDownTree = class DropDownTree extends Component {
9910
10031
  this.isFilterRestore = false;
9911
10032
  }
9912
10033
  }
10034
+ this.updateIndeterminateNodes();
9913
10035
  }
9914
10036
  restoreFilterSelection() {
9915
10037
  if (this.treeObj.checkedNodes) {
@@ -10192,6 +10314,21 @@ let DropDownTree = class DropDownTree extends Component {
10192
10314
  this.triggerChangeEvent(this.keyEventArgs);
10193
10315
  this.isValueChange = false;
10194
10316
  }
10317
+ if (!this.isRemoteData && !this.treeSettings.loadOnDemand) {
10318
+ const treeData = this.treeObj.getTreeData();
10319
+ if (this.showCheckBox && this.treeSettings.autoCheck &&
10320
+ treeData.length > 0 && this.treeData && this.treeData.length > 0) {
10321
+ for (let i = 0; i < treeData.length; i++) {
10322
+ for (let j = 0; j < this.treeData.length; j++) {
10323
+ if (treeData[i][this.fields.value] === this.treeData[j][this.fields.value]) {
10324
+ this.treeData[j].selected = treeData[i].selected !== undefined ?
10325
+ treeData[i].selected : false;
10326
+ }
10327
+ }
10328
+ }
10329
+ }
10330
+ }
10331
+ this.updateIndeterminateNodes();
10195
10332
  }
10196
10333
  beforeCheck(args) {
10197
10334
  if (args.isInteracted) {
@@ -10503,8 +10640,31 @@ let DropDownTree = class DropDownTree extends Component {
10503
10640
  .filter((childNode) => !isNullOrUndefined(childNode) && !isNullOrUndefined(childNode.pid) && !isNullOrUndefined(childNode.id) && childNode.pid.toString() === parentId)
10504
10641
  .map((childNode) => childNode.id.toString());
10505
10642
  }
10643
+ restoreRootParentValues() {
10644
+ const treeData = this.getFilteredTreeData();
10645
+ treeData.forEach((node) => {
10646
+ if (isNullOrUndefined(node) || isNullOrUndefined(node.id)) {
10647
+ return;
10648
+ }
10649
+ if (isNullOrUndefined(node.pid)) {
10650
+ const rootId = node.id.toString();
10651
+ const currentValues = this.value.map((item) => item.toString());
10652
+ if (currentValues.indexOf(rootId) === -1) {
10653
+ const childValues = [];
10654
+ this.getChildren(rootId, childValues);
10655
+ const hasSelectedChild = childValues.some((childId) => currentValues.indexOf(childId) !== -1);
10656
+ if (hasSelectedChild) {
10657
+ this.value.push(rootId);
10658
+ }
10659
+ }
10660
+ }
10661
+ });
10662
+ }
10506
10663
  updateFilteredAutoCheckValues() {
10507
10664
  const treeData = this.getFilteredTreeData();
10665
+ if (!this.isNodeChecked && Array.isArray(this.value) && this.value.length > 0 && this.showCheckBox) {
10666
+ this.restoreRootParentValues();
10667
+ }
10508
10668
  let currentValues = Array.isArray(this.value) ? this.value.map((item) => item.toString()) : [];
10509
10669
  const removeParent = (parentId) => {
10510
10670
  this.value = this.value.filter((value) => value.toString() !== parentId);
@@ -10593,24 +10753,44 @@ let DropDownTree = class DropDownTree extends Component {
10593
10753
  this.value = this.value.filter((value) => removeValues.indexOf(value.toString()) === -1);
10594
10754
  currentValues = this.value.map((item) => item.toString());
10595
10755
  }
10596
- treeData.forEach((node) => {
10597
- if (isNullOrUndefined(node) || isNullOrUndefined(node.id)) {
10598
- return;
10599
- }
10600
- if (!node.haschild) {
10601
- return;
10602
- }
10603
- const parentId = node.id.toString();
10604
- if (currentValues.indexOf(parentId) === -1) {
10605
- return;
10606
- }
10607
- const hasDirectChild = treeData.some((childNode) => !isNullOrUndefined(childNode) && !isNullOrUndefined(childNode.pid) && !isNullOrUndefined(childNode.id) && childNode.pid.toString() === parentId &&
10608
- currentValues.indexOf(childNode.id.toString()) !== -1);
10609
- if (!hasDirectChild) {
10610
- removeParent(parentId);
10611
- currentValues = this.value.map((item) => item.toString());
10612
- }
10613
- });
10756
+ let stabilized = false;
10757
+ const valueBeforeReconciliation = [...this.value];
10758
+ let iterationCount = 0;
10759
+ const maxIterations = treeData.length + 1;
10760
+ while (!stabilized && iterationCount < maxIterations) {
10761
+ stabilized = true;
10762
+ iterationCount++;
10763
+ treeData.forEach((node) => {
10764
+ if (isNullOrUndefined(node) || isNullOrUndefined(node.id)) {
10765
+ return;
10766
+ }
10767
+ if (!node.haschild) {
10768
+ return;
10769
+ }
10770
+ const parentId = node.id.toString();
10771
+ const directChildren = this.getDirectChildren(parentId);
10772
+ if (!directChildren.length) {
10773
+ return;
10774
+ }
10775
+ const allDirectChildrenChecked = directChildren.every((childId) => currentValues.indexOf(childId) !== -1);
10776
+ if (allDirectChildrenChecked) {
10777
+ if (currentValues.indexOf(parentId) === -1) {
10778
+ this.value.push(parentId);
10779
+ currentValues = this.value.map((item) => item.toString());
10780
+ stabilized = false;
10781
+ }
10782
+ }
10783
+ else if (currentValues.indexOf(parentId) !== -1) {
10784
+ removeParent(parentId);
10785
+ currentValues = this.value.map((item) => item.toString());
10786
+ stabilized = false;
10787
+ }
10788
+ });
10789
+ }
10790
+ if ((valueBeforeReconciliation.length > 0 && this.value.length === 0) ||
10791
+ iterationCount >= maxIterations) {
10792
+ this.value = valueBeforeReconciliation;
10793
+ }
10614
10794
  }
10615
10795
  updateSelectedValues() {
10616
10796
  this.dataValue = '';
@@ -10626,7 +10806,8 @@ let DropDownTree = class DropDownTree extends Component {
10626
10806
  if (!this.isFilteredData) {
10627
10807
  this.selectedData = [];
10628
10808
  }
10629
- if (this.treeSettings.autoCheck && this.isFilteredData && !isNullOrUndefined(this.value)) {
10809
+ if (!this.isRemoteData && !this.treeSettings.loadOnDemand && this.treeSettings.autoCheck &&
10810
+ this.isFilteredData && !isNullOrUndefined(this.value)) {
10630
10811
  this.updateFilteredAutoCheckValues();
10631
10812
  }
10632
10813
  if (!isNullOrUndefined(this.value)) {
@@ -10703,6 +10884,7 @@ let DropDownTree = class DropDownTree extends Component {
10703
10884
  else {
10704
10885
  this.inputWrapper.setAttribute('aria-label', this.getModuleName());
10705
10886
  }
10887
+ this.updateIndeterminateNodes();
10706
10888
  }
10707
10889
  setChipValues(text, value) {
10708
10890
  if (!this.inputWrapper.contains(this.chipWrapper)) {
@@ -23528,7 +23710,7 @@ let ListBox = ListBox_1 = class ListBox extends DropDownBase {
23528
23710
  }
23529
23711
  }
23530
23712
  KeyUp(e) {
23531
- if (this.allowFiltering && e.ctrlKey && e.keyCode === 65) {
23713
+ if (this.allowFiltering && ((e.ctrlKey && e.keyCode === 65) || e.keyCode === 16)) {
23532
23714
  e.preventDefault();
23533
23715
  return;
23534
23716
  }
@@ -23536,7 +23718,7 @@ let ListBox = ListBox_1 = class ListBox extends DropDownBase {
23536
23718
  const isBracketKey = e.keyCode === 219 || e.keyCode === 220 || e.keyCode === 221 || e.keyCode === 222;
23537
23719
  const isNumericKeyPadSpecialKey = e.keyCode === 107 || e.keyCode === 109 || e.keyCode === 111;
23538
23720
  const isWordCharacter = e.key && e.key.match(/\w/);
23539
- const isWordAccentCharacter = e.key && e.key.match(/[A-Za-z0-9\u00C0-\u024F ,>/:;\-+=[\]\\ ']/);
23721
+ const isWordAccentCharacter = e.key && e.key.match(/[A-Za-z0-9\u00C0-\u024F ,>/:;\-+=[\]\\ '@!#$%^&*()]/);
23540
23722
  if (!isNullOrUndefined(isWordCharacter) || !isNullOrUndefined(isWordAccentCharacter)
23541
23723
  || isSpecialKey || isBracketKey || isNumericKeyPadSpecialKey) {
23542
23724
  this.isValidKey = true;