@syncfusion/ej2-navigations 34.1.31 → 34.2.2
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/ej2-navigations.min.js +2 -2
- package/dist/ej2-navigations.umd.min.js +2 -2
- package/dist/ej2-navigations.umd.min.js.map +1 -1
- package/dist/es6/ej2-navigations.es2015.js +1496 -14
- package/dist/es6/ej2-navigations.es2015.js.map +1 -1
- package/dist/es6/ej2-navigations.es5.js +1498 -14
- package/dist/es6/ej2-navigations.es5.js.map +1 -1
- package/dist/global/ej2-navigations.min.js +2 -2
- package/dist/global/ej2-navigations.min.js.map +1 -1
- package/dist/global/index.d.ts +1 -1
- package/package.json +8 -7
- package/src/treeview/treeview-model.d.ts +26 -1
- package/src/treeview/treeview.d.ts +289 -0
- package/src/treeview/treeview.js +1498 -14
|
@@ -4,6 +4,7 @@ import { getScrollableParent, Popup, getZindexPartial, fit, isCollide, calculate
|
|
|
4
4
|
import { Button, createCheckBox, rippleMouseHandler } from '@syncfusion/ej2-buttons';
|
|
5
5
|
import { DataManager, Query } from '@syncfusion/ej2-data';
|
|
6
6
|
import { Input } from '@syncfusion/ej2-inputs';
|
|
7
|
+
import { Skeleton } from '@syncfusion/ej2-notifications';
|
|
7
8
|
|
|
8
9
|
var __extends = (undefined && undefined.__extends) || (function () {
|
|
9
10
|
var extendStatics = function (d, b) {
|
|
@@ -10873,6 +10874,9 @@ var CHILD = 'e-has-child';
|
|
|
10873
10874
|
var ITEM_ANIMATION_ACTIVE = 'e-animation-active';
|
|
10874
10875
|
var DISABLED$1 = 'e-disabled';
|
|
10875
10876
|
var PREVENTSELECT = 'e-prevent';
|
|
10877
|
+
var VIRTUALIZATION = 'e-virtualization';
|
|
10878
|
+
var VIRTUAL_MASK_PARENT = 'e-mask-parent';
|
|
10879
|
+
var VIRTUAL_MASK_ITEM = 'e-mask-item';
|
|
10876
10880
|
var treeAriaAttr = {
|
|
10877
10881
|
treeRole: 'group',
|
|
10878
10882
|
itemRole: 'treeitem',
|
|
@@ -11012,6 +11016,55 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
11012
11016
|
_this.isDropIn = false;
|
|
11013
11017
|
_this.OldCheckedData = [];
|
|
11014
11018
|
_this.isHiddenItem = false;
|
|
11019
|
+
// ── Virtualization state ──────────────────────────────────────────────────────────────
|
|
11020
|
+
/** Flat ordered list of all currently-visible (non-collapsed) tree nodes. */
|
|
11021
|
+
_this.virtualFlatNodes = [];
|
|
11022
|
+
/** Maps node id → index in virtualFlatNodes for O(1) lookups. */
|
|
11023
|
+
_this.virtualNodeMap = new Map();
|
|
11024
|
+
/** Set of expanded node IDs for O(1) lookup performance during flattening (avoids array indexOf). */
|
|
11025
|
+
_this.virtualExpandedNodesSet = new Set();
|
|
11026
|
+
/** Set of checked node IDs for O(1) lookup performance during flattening. */
|
|
11027
|
+
_this.virtualCheckedNodesSet = new Set();
|
|
11028
|
+
/** Set of indeterminate node IDs — persists across flattenVisibleNodes() rebuilds. */
|
|
11029
|
+
_this.virtualIndeterminateNodesSet = new Set();
|
|
11030
|
+
/** Set of selected node IDs for O(1) lookup performance during flattening. */
|
|
11031
|
+
_this.virtualSelectedNodesSet = new Set();
|
|
11032
|
+
/** Row height in pixels, measured from the first rendered item or set to 40 as a default. */
|
|
11033
|
+
_this.virtualItemHeight = 40;
|
|
11034
|
+
/** Height of the scrollable container in pixels. */
|
|
11035
|
+
_this.virtualViewportHeight = 0;
|
|
11036
|
+
/** scrollTop captured during the previous scroll handler invocation. */
|
|
11037
|
+
_this.virtualPrevScrollTop = 0;
|
|
11038
|
+
/** Index of the first rendered row in the current window. */
|
|
11039
|
+
_this.virtualStartIndex = 0;
|
|
11040
|
+
/** Index one past the last rendered row in the current window. */
|
|
11041
|
+
_this.virtualEndIndex = 0;
|
|
11042
|
+
/** Extra rows rendered above and below the visible window to smooth scrolling. */
|
|
11043
|
+
_this.virtualOverscanCount = 3;
|
|
11044
|
+
/** RequestAnimationFrame handle used for throttling scroll events. */
|
|
11045
|
+
_this.virtualScrollRAF = null;
|
|
11046
|
+
/** The `.e-mask-parent` overlay element shown during fast scroll. */
|
|
11047
|
+
_this.virtualMaskElement = null;
|
|
11048
|
+
/** Bound scroll handler stored for later removeEventListener. */
|
|
11049
|
+
_this.virtualScrollBound = null;
|
|
11050
|
+
/** Skeleton component instances inside the mask overlay. */
|
|
11051
|
+
_this.skeletonInstances = [];
|
|
11052
|
+
/** Set to true whenever the flat node list must be rebuilt on next render. */
|
|
11053
|
+
_this.virtualTreeDirty = false;
|
|
11054
|
+
/** The data-uid of the currently keyboard-focused node in virtual mode (persists across re-renders). */
|
|
11055
|
+
_this.virtualFocusedId = null;
|
|
11056
|
+
/**
|
|
11057
|
+
* Set to true by the document-level `keydown` handler when the user presses
|
|
11058
|
+
* the Tab key. The browser will auto-scroll the focused element into view
|
|
11059
|
+
* immediately after focus, which fires a `scroll` event on the TreeView
|
|
11060
|
+
* container. We want to skip the re-render that the virtual scroll handler
|
|
11061
|
+
* would otherwise trigger, because the element being focused is already
|
|
11062
|
+
* rendered (it is the single `<li tabindex="0">` of the current window) and
|
|
11063
|
+
* re-rendering would tear down the DOM element that is currently holding
|
|
11064
|
+
* focus. The flag is consumed (reset to `false`) inside `onVirtualScroll`
|
|
11065
|
+
* after the auto-scroll has been handled.
|
|
11066
|
+
*/
|
|
11067
|
+
_this.virtualSkipNextScrollRender = false;
|
|
11015
11068
|
return _this;
|
|
11016
11069
|
}
|
|
11017
11070
|
TreeView_1 = TreeView;
|
|
@@ -11313,6 +11366,24 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
11313
11366
|
}
|
|
11314
11367
|
};
|
|
11315
11368
|
TreeView.prototype.renderItems = function (isSorted) {
|
|
11369
|
+
// In virtual mode (with a fixed height) create only the container <ul> —
|
|
11370
|
+
// initVirtualization will populate the items directly, avoiding the O(n)
|
|
11371
|
+
// ListBase.createList cost.
|
|
11372
|
+
// updateCheckedStateFromDS / updateParentCheckState are intentionally skipped here:
|
|
11373
|
+
// they call getCheckedNodeDetails which traverses the DOM (no DOM exists yet in
|
|
11374
|
+
// virtual mode) and would throw on empty recursion results. The initial checked
|
|
11375
|
+
// state is derived from the raw data inside flattenNodeRecursive instead.
|
|
11376
|
+
//
|
|
11377
|
+
// When enableVirtualization is true but height is NOT provided, we fall through
|
|
11378
|
+
// to the normal (non-virtualized) rendering path so the tree is still visible.
|
|
11379
|
+
if (this.enableVirtualization && !isNullOrUndefined(this.height)) {
|
|
11380
|
+
this.ulElement = this.createElement('ul', {
|
|
11381
|
+
className: PARENTITEM + ' ' + 'e-ul',
|
|
11382
|
+
attrs: { role: 'group' }
|
|
11383
|
+
});
|
|
11384
|
+
this.element.appendChild(this.ulElement);
|
|
11385
|
+
return;
|
|
11386
|
+
}
|
|
11316
11387
|
this.listBaseOption.ariaAttributes.level = 1;
|
|
11317
11388
|
var sortedData = this.getSortedData(this.rootData);
|
|
11318
11389
|
this.ulElement = ListBase.createList(this.createElement, isSorted ? this.rootData : sortedData, this.listBaseOption);
|
|
@@ -12359,7 +12430,7 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
12359
12430
|
else if (state === 'indeterminate' && this.autoCheck) {
|
|
12360
12431
|
frameSpan.classList.remove(CHECK);
|
|
12361
12432
|
frameSpan.classList.add(INDETERMINATE);
|
|
12362
|
-
this.removeCheck(currLi);
|
|
12433
|
+
this.removeCheck(currLi, true);
|
|
12363
12434
|
ariaState = 'mixed';
|
|
12364
12435
|
}
|
|
12365
12436
|
ariaState = state === 'check' ? 'true' : state === 'uncheck' ? 'false' : ariaState;
|
|
@@ -12390,12 +12461,110 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
12390
12461
|
if (!isNullOrUndefined(id) && this.checkedNodes.indexOf(id) === -1) {
|
|
12391
12462
|
this.checkDisabledState(id);
|
|
12392
12463
|
}
|
|
12464
|
+
if (this.enableVirtualization) {
|
|
12465
|
+
// Clear any indeterminate state — node is now fully checked
|
|
12466
|
+
this.virtualIndeterminateNodesSet.delete(id);
|
|
12467
|
+
var actualIndex = this.virtualNodeMap.get(id);
|
|
12468
|
+
if (!isNullOrUndefined(actualIndex) && actualIndex > -1) {
|
|
12469
|
+
this.virtualFlatNodes[parseInt(actualIndex.toString(), 10)].isChecked = true;
|
|
12470
|
+
if (this.autoCheck && this.virtualFlatNodes[parseInt(actualIndex.toString(), 10)].hasChildren) {
|
|
12471
|
+
this.setVirtualChildCheckState(id, true);
|
|
12472
|
+
}
|
|
12473
|
+
}
|
|
12474
|
+
}
|
|
12393
12475
|
};
|
|
12394
|
-
TreeView.prototype.removeCheck = function (liEle) {
|
|
12395
|
-
var
|
|
12476
|
+
TreeView.prototype.removeCheck = function (liEle, isIndeterminate) {
|
|
12477
|
+
var id = liEle.getAttribute('data-uid');
|
|
12478
|
+
var index = this.checkedNodes.indexOf(id);
|
|
12396
12479
|
if (index > -1) {
|
|
12397
12480
|
this.checkedNodes.splice(index, 1);
|
|
12398
12481
|
}
|
|
12482
|
+
if (this.enableVirtualization) {
|
|
12483
|
+
var actualIndex = this.virtualNodeMap.get(id);
|
|
12484
|
+
if (!isNullOrUndefined(actualIndex) && actualIndex > -1) {
|
|
12485
|
+
if (isIndeterminate) {
|
|
12486
|
+
// Parent is transitioning to indeterminate — preserve children states
|
|
12487
|
+
// and mark this node as 'indeterminate' so scroll/collapse re-renders correctly.
|
|
12488
|
+
this.virtualFlatNodes[parseInt(actualIndex.toString(), 10)].isChecked = 'indeterminate';
|
|
12489
|
+
// Also record it in the persistent indeterminate set so flattenVisibleNodes()
|
|
12490
|
+
// can restore this state after a full rebuild (e.g. on collapse).
|
|
12491
|
+
this.virtualIndeterminateNodesSet.add(id);
|
|
12492
|
+
}
|
|
12493
|
+
else {
|
|
12494
|
+
// Node is being fully unchecked — clear indeterminate tracking too
|
|
12495
|
+
this.virtualIndeterminateNodesSet.delete(id);
|
|
12496
|
+
this.virtualCheckedNodesSet.delete(id);
|
|
12497
|
+
this.virtualFlatNodes[parseInt(actualIndex.toString(), 10)].isChecked = false;
|
|
12498
|
+
this.treeData[parseInt(id.toString(), 10) - 1].isChecked = false;
|
|
12499
|
+
if (this.autoCheck && this.virtualFlatNodes[parseInt(actualIndex.toString(), 10)].hasChildren) {
|
|
12500
|
+
this.setVirtualChildCheckState(id, false);
|
|
12501
|
+
}
|
|
12502
|
+
}
|
|
12503
|
+
}
|
|
12504
|
+
}
|
|
12505
|
+
};
|
|
12506
|
+
/**
|
|
12507
|
+
* Recursively sets the `isChecked` state of all descendants of the node with
|
|
12508
|
+
* `parentId` in `virtualFlatNodes`, keeping `checkedNodes` and
|
|
12509
|
+
* `virtualCheckedNodesSet` in sync. Used in virtual mode to honor the
|
|
12510
|
+
* `autoCheck` cascade when a parent checkbox is toggled.
|
|
12511
|
+
*
|
|
12512
|
+
* @param {string} parentId - The `data-uid` of the parent whose descendants should be updated.
|
|
12513
|
+
* @param {boolean} isChecked - The new state to apply to every descendant.
|
|
12514
|
+
* @returns {void}
|
|
12515
|
+
* @private
|
|
12516
|
+
*/
|
|
12517
|
+
TreeView.prototype.setVirtualChildCheckState = function (parentId, isChecked) {
|
|
12518
|
+
if (!this.virtualFlatNodes || this.virtualFlatNodes.length === 0) {
|
|
12519
|
+
return;
|
|
12520
|
+
}
|
|
12521
|
+
for (var i = 0; i < this.virtualFlatNodes.length; i++) {
|
|
12522
|
+
var node = this.virtualFlatNodes[parseInt(i.toString(), 10)];
|
|
12523
|
+
if (node.parentId === parentId) {
|
|
12524
|
+
node.isChecked = isChecked;
|
|
12525
|
+
if (isChecked) {
|
|
12526
|
+
this.virtualCheckedNodesSet.add(node.id);
|
|
12527
|
+
if (this.checkedNodes && this.checkedNodes.indexOf(node.id) === -1) {
|
|
12528
|
+
this.checkedNodes.push(node.id);
|
|
12529
|
+
}
|
|
12530
|
+
}
|
|
12531
|
+
else {
|
|
12532
|
+
this.virtualCheckedNodesSet.delete(node.id);
|
|
12533
|
+
var idx = this.checkedNodes ? this.checkedNodes.indexOf(node.id) : -1;
|
|
12534
|
+
if (idx !== -1) {
|
|
12535
|
+
this.checkedNodes.splice(idx, 1);
|
|
12536
|
+
}
|
|
12537
|
+
}
|
|
12538
|
+
if (node.hasChildren) {
|
|
12539
|
+
this.setVirtualChildCheckState(node.id, isChecked);
|
|
12540
|
+
}
|
|
12541
|
+
}
|
|
12542
|
+
}
|
|
12543
|
+
// Collapsed children are not present in virtualFlatNodes, so walk the raw data
|
|
12544
|
+
// to keep this.treeData and checkedNodes in sync for hidden descendants too.
|
|
12545
|
+
var collapsedChildren = this.getChildNodes(this.treeData, parentId);
|
|
12546
|
+
if (collapsedChildren) {
|
|
12547
|
+
for (var i = 0; i < collapsedChildren.length; i++) {
|
|
12548
|
+
var childId = collapsedChildren[parseInt(i.toString(), 10)][this.fields.id]
|
|
12549
|
+
? collapsedChildren[parseInt(i.toString(), 10)][this.fields.id].toString()
|
|
12550
|
+
: null;
|
|
12551
|
+
if (childId && (!this.virtualNodeMap || !this.virtualNodeMap.has(childId))) {
|
|
12552
|
+
this.updateField(this.treeData, this.fields, childId, this.fields.isChecked, isChecked);
|
|
12553
|
+
if (isChecked) {
|
|
12554
|
+
if (this.checkedNodes && this.checkedNodes.indexOf(childId) === -1) {
|
|
12555
|
+
this.checkedNodes.push(childId);
|
|
12556
|
+
}
|
|
12557
|
+
}
|
|
12558
|
+
else {
|
|
12559
|
+
var idx = this.checkedNodes ? this.checkedNodes.indexOf(childId) : -1;
|
|
12560
|
+
if (idx !== -1) {
|
|
12561
|
+
this.checkedNodes.splice(idx, 1);
|
|
12562
|
+
}
|
|
12563
|
+
}
|
|
12564
|
+
this.setVirtualChildCheckState(childId, isChecked);
|
|
12565
|
+
}
|
|
12566
|
+
}
|
|
12567
|
+
}
|
|
12399
12568
|
};
|
|
12400
12569
|
TreeView.prototype.getCheckEvent = function (currLi, action, e) {
|
|
12401
12570
|
this.checkActionNodes.push(this.getNodeData(currLi));
|
|
@@ -12427,6 +12596,9 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
12427
12596
|
return;
|
|
12428
12597
|
}
|
|
12429
12598
|
var liEle = ulEle ? selectAll('.' + LISTITEM, ulEle) : this.liList;
|
|
12599
|
+
if (!liEle) {
|
|
12600
|
+
return;
|
|
12601
|
+
}
|
|
12430
12602
|
var length = liEle.length;
|
|
12431
12603
|
for (var i = 0; i < length; i++) {
|
|
12432
12604
|
this.calculateWrap(liEle[parseInt(i.toString(), 10)]);
|
|
@@ -12515,6 +12687,10 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
12515
12687
|
}
|
|
12516
12688
|
this.isLoaded = true;
|
|
12517
12689
|
this.isNodeDropped = false;
|
|
12690
|
+
// Initialise (or re-initialise) virtual mode after data binding has settled
|
|
12691
|
+
if (this.enableVirtualization && !isNullOrUndefined(this.height)) {
|
|
12692
|
+
this.initVirtualization();
|
|
12693
|
+
}
|
|
12518
12694
|
};
|
|
12519
12695
|
TreeView.prototype.doSelectionAction = function () {
|
|
12520
12696
|
var sNodes = selectAll('.' + SELECTED$1, this.element);
|
|
@@ -12649,8 +12825,18 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
12649
12825
|
};
|
|
12650
12826
|
this.trigger('nodeClicked', eventArgs);
|
|
12651
12827
|
};
|
|
12652
|
-
TreeView.prototype.expandNode = function (currLi, icon, loaded) {
|
|
12828
|
+
TreeView.prototype.expandNode = function (currLi, icon, loaded, isKeyboardNav) {
|
|
12653
12829
|
var _this = this;
|
|
12830
|
+
// Virtual mode fast-path: rebuild the flat list and re-render the window.
|
|
12831
|
+
// Only engage when height is also set; without a fixed height the tree falls
|
|
12832
|
+
// back to normal rendering and the standard expand path must be used.
|
|
12833
|
+
if (this.enableVirtualization && !isNullOrUndefined(this.height)) {
|
|
12834
|
+
var id = currLi ? currLi.getAttribute('data-uid') : null;
|
|
12835
|
+
if (id) {
|
|
12836
|
+
this.handleVirtualExpand(id, isKeyboardNav);
|
|
12837
|
+
}
|
|
12838
|
+
return;
|
|
12839
|
+
}
|
|
12654
12840
|
this.renderReactTemplates();
|
|
12655
12841
|
if (icon.classList.contains(LOAD)) {
|
|
12656
12842
|
this.hideSpinner(icon);
|
|
@@ -12758,16 +12944,30 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
12758
12944
|
removeClass([icon], PROCESS);
|
|
12759
12945
|
}
|
|
12760
12946
|
else {
|
|
12761
|
-
|
|
12947
|
+
// Detect if event is keyboard navigation by checking for 'action' property
|
|
12948
|
+
var isKeyboardNav = e && e.action !== undefined;
|
|
12949
|
+
_this.nodeCollapseAction(currLi, icon, observedArgs, isKeyboardNav);
|
|
12762
12950
|
}
|
|
12763
12951
|
});
|
|
12764
12952
|
}
|
|
12765
12953
|
else {
|
|
12766
|
-
|
|
12954
|
+
// Detect if event is keyboard navigation by checking for 'action' property
|
|
12955
|
+
var isKeyboardNav = e && e.action !== undefined;
|
|
12956
|
+
this.nodeCollapseAction(currLi, icon, colArgs, isKeyboardNav);
|
|
12767
12957
|
}
|
|
12768
12958
|
};
|
|
12769
|
-
TreeView.prototype.nodeCollapseAction = function (currLi, icon, colArgs) {
|
|
12959
|
+
TreeView.prototype.nodeCollapseAction = function (currLi, icon, colArgs, isKeyboardNav) {
|
|
12770
12960
|
var _this = this;
|
|
12961
|
+
// Virtual mode fast-path: rebuild the flat list and re-render the window.
|
|
12962
|
+
// Only engage when height is also set; without a fixed height the tree falls
|
|
12963
|
+
// back to normal rendering and the standard collapse path must be used.
|
|
12964
|
+
if (this.enableVirtualization && !isNullOrUndefined(this.height)) {
|
|
12965
|
+
var id = currLi ? currLi.getAttribute('data-uid') : null;
|
|
12966
|
+
if (id) {
|
|
12967
|
+
this.handleVirtualCollapse(id, isKeyboardNav);
|
|
12968
|
+
}
|
|
12969
|
+
return;
|
|
12970
|
+
}
|
|
12771
12971
|
removeClass([icon], COLLAPSIBLE);
|
|
12772
12972
|
addClass([icon], EXPANDABLE);
|
|
12773
12973
|
var start = 0;
|
|
@@ -13231,6 +13431,10 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
13231
13431
|
li.setAttribute('tabindex', '0');
|
|
13232
13432
|
EventHandler.add(li, 'blur', this.focusOut, this);
|
|
13233
13433
|
this.updateIdAttr(focusedNode, li);
|
|
13434
|
+
// Track focused id for virtual mode re-render restoration
|
|
13435
|
+
if (this.enableVirtualization) {
|
|
13436
|
+
this.virtualFocusedId = li.getAttribute('data-uid');
|
|
13437
|
+
}
|
|
13234
13438
|
}
|
|
13235
13439
|
};
|
|
13236
13440
|
TreeView.prototype.addSelect = function (liEle) {
|
|
@@ -13289,6 +13493,9 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
13289
13493
|
}
|
|
13290
13494
|
};
|
|
13291
13495
|
TreeView.prototype.expandCollapseAction = function (currLi, e) {
|
|
13496
|
+
if (this.enableVirtualization && !isNullOrUndefined(this.height) && currLi.classList.contains(EDITING)) {
|
|
13497
|
+
return;
|
|
13498
|
+
}
|
|
13292
13499
|
var icon = select('div.' + ICON, currLi);
|
|
13293
13500
|
if (!icon || icon.classList.contains(PROCESS)) {
|
|
13294
13501
|
return;
|
|
@@ -13319,15 +13526,29 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
13319
13526
|
removeClass([icon], PROCESS);
|
|
13320
13527
|
}
|
|
13321
13528
|
else {
|
|
13322
|
-
|
|
13529
|
+
// Detect if event is keyboard navigation by checking for 'action' property
|
|
13530
|
+
var isKeyboardNav = e && e.action !== undefined;
|
|
13531
|
+
_this.nodeExpandAction(currLi, icon, expandChild, callback, isFromExpandAll, isKeyboardNav);
|
|
13323
13532
|
}
|
|
13324
13533
|
});
|
|
13325
13534
|
}
|
|
13326
13535
|
else {
|
|
13327
|
-
|
|
13536
|
+
// Detect if event is keyboard navigation by checking for 'action' property
|
|
13537
|
+
var isKeyboardNav = e && e.action !== undefined;
|
|
13538
|
+
this.nodeExpandAction(currLi, icon, expandChild, callback, isFromExpandAll, isKeyboardNav);
|
|
13539
|
+
}
|
|
13540
|
+
};
|
|
13541
|
+
TreeView.prototype.nodeExpandAction = function (currLi, icon, expandChild, callback, isFromExpandAll, isKeyboardNav) {
|
|
13542
|
+
// In virtual mode (with a fixed height) the flat <li> never has a child <ul>
|
|
13543
|
+
// in the DOM, so the PARENTITEM check below would always fail and fall into
|
|
13544
|
+
// renderChildNodes(), which corrupts the virtual DOM.
|
|
13545
|
+
// Delegate directly to expandNode() which has the handleVirtualExpand fast-path.
|
|
13546
|
+
// When height is not provided, fall through to normal expand logic below since
|
|
13547
|
+
// the tree is rendered with a full nested DOM structure.
|
|
13548
|
+
if (this.enableVirtualization && !isNullOrUndefined(this.height)) {
|
|
13549
|
+
this.expandNode(currLi, icon, undefined, isKeyboardNav);
|
|
13550
|
+
return;
|
|
13328
13551
|
}
|
|
13329
|
-
};
|
|
13330
|
-
TreeView.prototype.nodeExpandAction = function (currLi, icon, expandChild, callback, isFromExpandAll) {
|
|
13331
13552
|
var ul = select('.' + PARENTITEM, currLi);
|
|
13332
13553
|
if (ul && ul.nodeName === 'UL') {
|
|
13333
13554
|
this.expandNode(currLi, icon);
|
|
@@ -13441,6 +13662,19 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
13441
13662
|
});
|
|
13442
13663
|
};
|
|
13443
13664
|
TreeView.prototype.navigateToFocus = function (isUp) {
|
|
13665
|
+
// In virtual mode (with a fixed height) the element itself is the scroll
|
|
13666
|
+
// container; use ensureVirtualNodeVisible. When height is not provided,
|
|
13667
|
+
// the tree uses normal rendering, so fall through to the standard scroll logic.
|
|
13668
|
+
if (this.enableVirtualization && !isNullOrUndefined(this.height)) {
|
|
13669
|
+
var focusedLi = this.getFocusedNode();
|
|
13670
|
+
if (focusedLi) {
|
|
13671
|
+
var id = focusedLi.getAttribute('data-uid');
|
|
13672
|
+
if (id) {
|
|
13673
|
+
this.ensureVirtualNodeVisible(id);
|
|
13674
|
+
}
|
|
13675
|
+
}
|
|
13676
|
+
return;
|
|
13677
|
+
}
|
|
13444
13678
|
var focusNode = this.getFocusedNode().querySelector('.' + TEXTWRAP);
|
|
13445
13679
|
var pos = focusNode.getBoundingClientRect();
|
|
13446
13680
|
var parent = this.getScrollParent(this.element);
|
|
@@ -13861,6 +14095,46 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
13861
14095
|
return isNullOrUndefined(fNode) ? (isNullOrUndefined(selectedItem) ? this.element.firstElementChild : selectedItem) : fNode;
|
|
13862
14096
|
};
|
|
13863
14097
|
TreeView.prototype.focusNextNode = function (li, isTowards) {
|
|
14098
|
+
if (this.enableVirtualization && !isNullOrUndefined(this.height)) {
|
|
14099
|
+
// Determine the id of the node one step in the requested direction
|
|
14100
|
+
var currentId = li ? li.getAttribute('data-uid') : null;
|
|
14101
|
+
var currentIdx = -1;
|
|
14102
|
+
if (!isNullOrUndefined(currentId)) {
|
|
14103
|
+
var idx = this.virtualNodeMap.get(currentId);
|
|
14104
|
+
currentIdx = !isNullOrUndefined(idx) ? idx : -1;
|
|
14105
|
+
}
|
|
14106
|
+
var targetIdx = isTowards ? currentIdx + 1 : currentIdx - 1;
|
|
14107
|
+
if (targetIdx < 0 || targetIdx >= this.virtualFlatNodes.length) {
|
|
14108
|
+
return;
|
|
14109
|
+
}
|
|
14110
|
+
var targetId = this.virtualFlatNodes[parseInt(targetIdx.toString(), 10)].id;
|
|
14111
|
+
// ── Fix 1: set virtualFocusedId BEFORE calling ensureVirtualNodeVisible ──
|
|
14112
|
+
// renderVirtualItems() is called synchronously inside ensureVirtualNodeVisible
|
|
14113
|
+
// when a re-render is needed. If virtualFocusedId is still the old value at
|
|
14114
|
+
// that point, focus restoration falls back to the first item. Setting it here
|
|
14115
|
+
// ensures renderVirtualItems always restores focus to the correct target node.
|
|
14116
|
+
this.virtualFocusedId = targetId;
|
|
14117
|
+
// ── Fix 2: clear focus classes from ALL nested list items, not just top-level ones ──
|
|
14118
|
+
// With hierarchical virtual DOM, the currently focused <li> may be nested inside
|
|
14119
|
+
// a child <ul>. Using ':scope > li' only cleans up direct children and leaves
|
|
14120
|
+
// stale e-focused / e-node-focus classes on nested nodes across re-renders.
|
|
14121
|
+
var allLi = this.element.querySelectorAll('.' + LISTITEM + '.' + FOCUS);
|
|
14122
|
+
for (var k = 0; k < allLi.length; k++) {
|
|
14123
|
+
allLi[parseInt(k.toString(), 10)].classList.remove(FOCUS);
|
|
14124
|
+
allLi[parseInt(k.toString(), 10)].classList.remove(FOCUSED$1);
|
|
14125
|
+
allLi[parseInt(k.toString(), 10)].setAttribute('tabindex', '-1');
|
|
14126
|
+
}
|
|
14127
|
+
// Ensure the target <li> is in the DOM window (may trigger a re-render).
|
|
14128
|
+
// virtualFocusedId is already set above so renderVirtualItems restores focus correctly.
|
|
14129
|
+
this.ensureVirtualNodeVisible(targetId);
|
|
14130
|
+
// Re-query both nodes after the potential re-render so setFocus gets live DOM elements
|
|
14131
|
+
var prevNode = currentId ? this.getElement(currentId) : li;
|
|
14132
|
+
var nextNode_1 = this.getElement(targetId);
|
|
14133
|
+
if (!isNullOrUndefined(nextNode_1)) {
|
|
14134
|
+
this.setFocus(isNullOrUndefined(prevNode) ? nextNode_1 : prevNode, nextNode_1);
|
|
14135
|
+
}
|
|
14136
|
+
return;
|
|
14137
|
+
}
|
|
13864
14138
|
var nextNode = isTowards ? this.getNextNode(li) : this.getPrevNode(li);
|
|
13865
14139
|
this.setFocus(li, nextNode);
|
|
13866
14140
|
this.navigateToFocus(!isTowards);
|
|
@@ -13930,6 +14204,12 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
13930
14204
|
addClass([nextNode], FOCUS);
|
|
13931
14205
|
addClass([nextNode], FOCUSED$1);
|
|
13932
14206
|
nextNode.setAttribute('tabindex', '0');
|
|
14207
|
+
if (this.enableVirtualization && !isNullOrUndefined(this.height)) {
|
|
14208
|
+
nextNode.focus({ preventScroll: true });
|
|
14209
|
+
}
|
|
14210
|
+
else {
|
|
14211
|
+
nextNode.focus();
|
|
14212
|
+
}
|
|
13933
14213
|
nextNode.focus();
|
|
13934
14214
|
EventHandler.add(nextNode, 'blur', this.focusOut, this);
|
|
13935
14215
|
this.updateIdAttr(preNode, nextNode);
|
|
@@ -13948,6 +14228,30 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
13948
14228
|
if (!focusedElement) {
|
|
13949
14229
|
return;
|
|
13950
14230
|
}
|
|
14231
|
+
// Virtual-mode guard: when the browser moves focus into the TreeView (e.g. via
|
|
14232
|
+
// the Tab key) it always lands on the single `<li tabindex="0">`. In that
|
|
14233
|
+
// case the element is already the focusable one, FOCUS is already applied
|
|
14234
|
+
// and the only thing left to do is the keyboard focus styling. Skip the
|
|
14235
|
+
// redundant setAttribute/EventHandler.add work so we never re-render the
|
|
14236
|
+
// virtual window as a side effect of focusing the existing `tabindex="0"`
|
|
14237
|
+
// item.
|
|
14238
|
+
// ── Fix: Use document.activeElement to detect browser-focused node ──
|
|
14239
|
+
// After renderVirtualItems() restores focus, the browser-focused element is
|
|
14240
|
+
// the authoritative source, not getFocusedNode(). If they don't match, it means
|
|
14241
|
+
// renderVirtualItems already correctly set up the element, so we must not
|
|
14242
|
+
// override its setup by calling setFocus again.
|
|
14243
|
+
var actuallyFocusedElement = document.activeElement;
|
|
14244
|
+
var isAlreadyFocusedInVirtualMode = this.enableVirtualization
|
|
14245
|
+
&& actuallyFocusedElement === focusedElement
|
|
14246
|
+
&& actuallyFocusedElement.getAttribute('tabindex') === '0'
|
|
14247
|
+
&& actuallyFocusedElement.classList.contains(FOCUS);
|
|
14248
|
+
if (isAlreadyFocusedInVirtualMode) {
|
|
14249
|
+
if (this.isKeyboardFocus && !actuallyFocusedElement.classList.contains(FOCUSED$1)) {
|
|
14250
|
+
addClass([actuallyFocusedElement], FOCUSED$1);
|
|
14251
|
+
}
|
|
14252
|
+
this.isKeyboardFocus = false;
|
|
14253
|
+
return;
|
|
14254
|
+
}
|
|
13951
14255
|
if (!this.mouseDownStatus) {
|
|
13952
14256
|
if (focusedElement.classList.contains('e-disable')) {
|
|
13953
14257
|
focusedElement.setAttribute('tabindex', '-1');
|
|
@@ -13974,6 +14278,9 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
13974
14278
|
removeClass([focusedElement], FOCUS);
|
|
13975
14279
|
removeClass([focusedElement], FOCUSED$1);
|
|
13976
14280
|
EventHandler.remove(focusedElement, 'blur', this.focusOut);
|
|
14281
|
+
if (this.enableVirtualization) {
|
|
14282
|
+
this.virtualFocusedId = null;
|
|
14283
|
+
}
|
|
13977
14284
|
}
|
|
13978
14285
|
};
|
|
13979
14286
|
TreeView.prototype.onMouseOver = function (e) {
|
|
@@ -14187,6 +14494,19 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
14187
14494
|
else {
|
|
14188
14495
|
txtEle[ListBase.getDomSetter(this.listBaseOption)] = ListBase.getSanitizedText(newText, this.listBaseOption);
|
|
14189
14496
|
}
|
|
14497
|
+
// ── Virtual mode: sync the flat-node snapshot so re-renders show updated text ──
|
|
14498
|
+
// virtualFlatNodes is rebuilt from this.treeData (via flattenVisibleNodes) only on
|
|
14499
|
+
// expand/collapse/scroll. Between those events the snapshot is the single source of
|
|
14500
|
+
// truth used by createVirtualListItem. setValue() above updates this.editData (which
|
|
14501
|
+
// IS the treeData object reference), but virtualFlatNodes[idx].text still holds the
|
|
14502
|
+
// old value. Update it here so the next renderVirtualItems() call shows the new text.
|
|
14503
|
+
if (this.enableVirtualization) {
|
|
14504
|
+
var id = liEle.getAttribute('data-uid');
|
|
14505
|
+
var idx = this.virtualNodeMap ? this.virtualNodeMap.get(id) : undefined;
|
|
14506
|
+
if (!isNullOrUndefined(idx) && idx > -1) {
|
|
14507
|
+
this.virtualFlatNodes[parseInt(idx.toString(), 10)].text = newText;
|
|
14508
|
+
}
|
|
14509
|
+
}
|
|
14190
14510
|
if (isInput) {
|
|
14191
14511
|
removeClass([liEle], EDITING);
|
|
14192
14512
|
liEle.focus();
|
|
@@ -15564,6 +15884,31 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
15564
15884
|
TreeView.prototype.keyDownHandler = function (e) {
|
|
15565
15885
|
if (e.key === 'Tab' || e.keyCode === 9) {
|
|
15566
15886
|
this.isKeyboardFocus = true;
|
|
15887
|
+
// Mark the upcoming scroll event (if any) as Tab-induced so the
|
|
15888
|
+
// virtual scroll handler skips its re-render path. The browser
|
|
15889
|
+
// calls `Element.scrollIntoView` semantics on focus, which scrolls
|
|
15890
|
+
// a `<li tabindex="0">` in the middle of the tree into view and
|
|
15891
|
+
// therefore fires `scroll` on the container. Without this guard
|
|
15892
|
+
// the scroll handler would tear down the focused `<li>` and move
|
|
15893
|
+
// focus elsewhere.
|
|
15894
|
+
if (this.enableVirtualization) {
|
|
15895
|
+
this.virtualSkipNextScrollRender = true;
|
|
15896
|
+
}
|
|
15897
|
+
}
|
|
15898
|
+
// ── Fix: Also skip scroll render for arrow key navigation ──────────────────
|
|
15899
|
+
// Arrow Down/Up calls focusNextNode() which calls ensureVirtualNodeVisible()
|
|
15900
|
+
// to scroll the target node into view. Without this guard, the scroll event
|
|
15901
|
+
// would trigger onVirtualScroll() which re-renders the window and resets the
|
|
15902
|
+
// focus that focusNextNode() just set. This manifests as tabindex resetting
|
|
15903
|
+
// to the first item instead of staying on the arrow-navigated target.
|
|
15904
|
+
// Arrow Right/Left (expand/collapse) also calls renderVirtualItems() which
|
|
15905
|
+
// calls li.focus() in branch 2; that can trigger a scroll on an edge node,
|
|
15906
|
+
// so we consume it here to prevent a stale RAF re-render.
|
|
15907
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp' || e.keyCode === 40 || e.keyCode === 38
|
|
15908
|
+
|| e.key === 'ArrowRight' || e.key === 'ArrowLeft' || e.keyCode === 39 || e.keyCode === 37) {
|
|
15909
|
+
if (this.enableVirtualization) {
|
|
15910
|
+
this.virtualSkipNextScrollRender = true;
|
|
15911
|
+
}
|
|
15567
15912
|
}
|
|
15568
15913
|
};
|
|
15569
15914
|
TreeView.prototype.preventContextMenu = function (e) {
|
|
@@ -15920,6 +16265,18 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
15920
16265
|
if (this.dataType === 1) {
|
|
15921
16266
|
this.groupedData = this.getGroupedData(this.treeData, this.fields.parentID);
|
|
15922
16267
|
}
|
|
16268
|
+
// In virtual mode (with a fixed height), rebuild the flat node list and re-render
|
|
16269
|
+
// after deletion so the removed nodes are correctly reflected in the hierarchical
|
|
16270
|
+
// virtual DOM. When height is not provided, the tree uses normal rendering and
|
|
16271
|
+
// the DOM is already updated by removeNode() above.
|
|
16272
|
+
if (this.enableVirtualization && !isNullOrUndefined(this.height)) {
|
|
16273
|
+
this.virtualFlatNodes = this.flattenVisibleNodes();
|
|
16274
|
+
this.rebuildVirtualNodeMap();
|
|
16275
|
+
var win = this.getVirtualWindow();
|
|
16276
|
+
this.virtualStartIndex = win.startIndex;
|
|
16277
|
+
this.virtualEndIndex = win.endIndex;
|
|
16278
|
+
this.renderVirtualItems();
|
|
16279
|
+
}
|
|
15923
16280
|
this.triggerEvent('removeNode', nodeData);
|
|
15924
16281
|
};
|
|
15925
16282
|
TreeView.prototype.editSucess = function (target, newText, prevent) {
|
|
@@ -15980,6 +16337,1031 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
15980
16337
|
}
|
|
15981
16338
|
return parentsID;
|
|
15982
16339
|
};
|
|
16340
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
16341
|
+
// VIRTUALIZATION — private helpers
|
|
16342
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
16343
|
+
/**
|
|
16344
|
+
* Parses the `height` property (string like '400px' or number) to a pixel value.
|
|
16345
|
+
* Returns 0 if the value cannot be determined.
|
|
16346
|
+
*
|
|
16347
|
+
* @returns {number} Pixel height.
|
|
16348
|
+
* @private
|
|
16349
|
+
*/
|
|
16350
|
+
TreeView.prototype.parseHeightToPixels = function () {
|
|
16351
|
+
var h = this.height;
|
|
16352
|
+
if (isNullOrUndefined(h)) {
|
|
16353
|
+
return 0;
|
|
16354
|
+
}
|
|
16355
|
+
if (typeof h === 'number') {
|
|
16356
|
+
return h;
|
|
16357
|
+
}
|
|
16358
|
+
var parsed = parseFloat(h);
|
|
16359
|
+
return isNaN(parsed) ? 0 : parsed;
|
|
16360
|
+
};
|
|
16361
|
+
/**
|
|
16362
|
+
* Measures the height of the first rendered list item so subsequent calculations
|
|
16363
|
+
* use real layout values. Falls back to the stored `virtualItemHeight` default (40).
|
|
16364
|
+
*
|
|
16365
|
+
* @returns {number} Row height in pixels.
|
|
16366
|
+
* @private
|
|
16367
|
+
*/
|
|
16368
|
+
TreeView.prototype.measureVirtualItemHeight = function () {
|
|
16369
|
+
var firstLi = select('.' + LISTITEM, this.element);
|
|
16370
|
+
if (firstLi && firstLi.offsetHeight > 0) {
|
|
16371
|
+
return firstLi.offsetHeight;
|
|
16372
|
+
}
|
|
16373
|
+
return this.virtualItemHeight;
|
|
16374
|
+
};
|
|
16375
|
+
/**
|
|
16376
|
+
* Rebuilds the cached Sets for checked/selected nodes to enable O(1) lookup
|
|
16377
|
+
* during the flatten operation instead of O(n) array indexOf calls.
|
|
16378
|
+
*
|
|
16379
|
+
* @returns {void}
|
|
16380
|
+
* @private
|
|
16381
|
+
*/
|
|
16382
|
+
TreeView.prototype.rebuildVirtualCheckCache = function () {
|
|
16383
|
+
this.virtualExpandedNodesSet.clear();
|
|
16384
|
+
this.virtualCheckedNodesSet.clear();
|
|
16385
|
+
this.virtualSelectedNodesSet.clear();
|
|
16386
|
+
if (this.expandedNodes && Array.isArray(this.expandedNodes)) {
|
|
16387
|
+
for (var i = 0; i < this.expandedNodes.length; i++) {
|
|
16388
|
+
this.virtualExpandedNodesSet.add(this.expandedNodes[i]);
|
|
16389
|
+
}
|
|
16390
|
+
}
|
|
16391
|
+
if (this.checkedNodes && Array.isArray(this.checkedNodes)) {
|
|
16392
|
+
for (var i = 0; i < this.checkedNodes.length; i++) {
|
|
16393
|
+
this.virtualCheckedNodesSet.add(this.checkedNodes[i]);
|
|
16394
|
+
}
|
|
16395
|
+
}
|
|
16396
|
+
if (this.selectedNodes && Array.isArray(this.selectedNodes)) {
|
|
16397
|
+
for (var i = 0; i < this.selectedNodes.length; i++) {
|
|
16398
|
+
this.virtualSelectedNodesSet.add(this.selectedNodes[i]);
|
|
16399
|
+
}
|
|
16400
|
+
}
|
|
16401
|
+
};
|
|
16402
|
+
/**
|
|
16403
|
+
* Recursively walks the treeData (or groupedData for flat lists) and builds
|
|
16404
|
+
* `virtualFlatNodes` — an ordered list of every node that is currently visible
|
|
16405
|
+
* (i.e. its ancestors are all expanded). Uses cached Sets for O(1) state lookups.
|
|
16406
|
+
*
|
|
16407
|
+
* @returns {VirtualNodeData[]} Ordered flat list of visible nodes.
|
|
16408
|
+
* @private
|
|
16409
|
+
*/
|
|
16410
|
+
TreeView.prototype.flattenVisibleNodes = function () {
|
|
16411
|
+
// Build cached Sets for fast lookups
|
|
16412
|
+
this.rebuildVirtualCheckCache();
|
|
16413
|
+
var result = [];
|
|
16414
|
+
if (this.dataType === 1) {
|
|
16415
|
+
// Flat data with parentID field — use getChildGroup to find root nodes
|
|
16416
|
+
var rootNodes = [];
|
|
16417
|
+
if (this.groupedData) {
|
|
16418
|
+
rootNodes = this.getChildGroup(this.groupedData, null, true);
|
|
16419
|
+
}
|
|
16420
|
+
if (!rootNodes || rootNodes.length === 0) {
|
|
16421
|
+
rootNodes = this.rootData;
|
|
16422
|
+
}
|
|
16423
|
+
// Apply sortOrder to root-level nodes for flat data (same as hierarchical path below)
|
|
16424
|
+
rootNodes = this.getSortedData(rootNodes);
|
|
16425
|
+
this.flattenNodeRecursive(rootNodes, 1, null, result);
|
|
16426
|
+
}
|
|
16427
|
+
else {
|
|
16428
|
+
// Hierarchical data
|
|
16429
|
+
var sorted = this.getSortedData(this.rootData);
|
|
16430
|
+
this.flattenNodeRecursive(sorted, 1, null, result);
|
|
16431
|
+
}
|
|
16432
|
+
return result;
|
|
16433
|
+
};
|
|
16434
|
+
/**
|
|
16435
|
+
* Recursive helper for `flattenVisibleNodes`.
|
|
16436
|
+
*
|
|
16437
|
+
* @param {Object[]} nodes - Array of raw data objects at this level.
|
|
16438
|
+
* @param {number} level - 1-based depth level.
|
|
16439
|
+
* @param {string | null} parentId - The parent node id, or null for root.
|
|
16440
|
+
* @param {VirtualNodeData[]} result - Accumulator array.
|
|
16441
|
+
* @returns {void}
|
|
16442
|
+
* @private
|
|
16443
|
+
*/
|
|
16444
|
+
TreeView.prototype.flattenNodeRecursive = function (nodes, level, parentId, result) {
|
|
16445
|
+
if (!nodes || nodes.length === 0) {
|
|
16446
|
+
return;
|
|
16447
|
+
}
|
|
16448
|
+
// Cache field names and settings outside the loop to avoid repeated conversions
|
|
16449
|
+
var childFieldName = this.fields.child.toString();
|
|
16450
|
+
var expandedFieldName = this.fields.expanded;
|
|
16451
|
+
var isCheckedFieldName = this.fields.isChecked;
|
|
16452
|
+
var iconCssFieldName = this.fields.iconCss;
|
|
16453
|
+
var imageUrlFieldName = this.fields.imageUrl;
|
|
16454
|
+
var idFieldName = this.fields.id;
|
|
16455
|
+
var textFieldName = this.fields.text;
|
|
16456
|
+
var needsSorting = this.sortOrder !== 'None';
|
|
16457
|
+
var isDataTypeFlat = this.dataType === 1;
|
|
16458
|
+
var enableVirtualization = this.enableVirtualization;
|
|
16459
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
16460
|
+
var raw = nodes[i];
|
|
16461
|
+
var id = isNullOrUndefined(raw[idFieldName]) ? '' : raw[idFieldName].toString();
|
|
16462
|
+
var text = isNullOrUndefined(raw[textFieldName]) ? '' : raw[textFieldName].toString();
|
|
16463
|
+
// Use expandedNodes as the single source of truth.
|
|
16464
|
+
var inExpandedNodes = this.virtualExpandedNodesSet.has(id);
|
|
16465
|
+
var rawExpanded = !inExpandedNodes && getValue(expandedFieldName, raw) === true;
|
|
16466
|
+
var isExpanded = inExpandedNodes || rawExpanded;
|
|
16467
|
+
if (rawExpanded && id) {
|
|
16468
|
+
this.expandedNodes.push(id);
|
|
16469
|
+
this.virtualExpandedNodesSet.add(id);
|
|
16470
|
+
}
|
|
16471
|
+
// Inline hasChildRecords check to avoid function call (optimization)
|
|
16472
|
+
var hasChildren = false;
|
|
16473
|
+
if (isDataTypeFlat) {
|
|
16474
|
+
if (this.groupedData) {
|
|
16475
|
+
var groupedChild = this.getChildGroup(this.groupedData, id, false);
|
|
16476
|
+
hasChildren = !isNullOrUndefined(groupedChild) && groupedChild.length > 0;
|
|
16477
|
+
}
|
|
16478
|
+
}
|
|
16479
|
+
else {
|
|
16480
|
+
var childrenObj = getValue(childFieldName, raw);
|
|
16481
|
+
hasChildren = !isNullOrUndefined(childrenObj) && Array.isArray(childrenObj) && childrenObj.length > 0;
|
|
16482
|
+
}
|
|
16483
|
+
// Virtual-mode only: honour fields.isChecked === true on initial render
|
|
16484
|
+
if (enableVirtualization && id && isCheckedFieldName && !this.virtualCheckedNodesSet.has(id)) {
|
|
16485
|
+
var rawChecked = getValue(isCheckedFieldName, raw);
|
|
16486
|
+
if (!isNullOrUndefined(rawChecked) && rawChecked.toString() === 'true') {
|
|
16487
|
+
this.virtualCheckedNodesSet.add(id);
|
|
16488
|
+
if (this.checkedNodes && this.checkedNodes.indexOf(id) === -1) {
|
|
16489
|
+
this.checkedNodes.push(id);
|
|
16490
|
+
}
|
|
16491
|
+
}
|
|
16492
|
+
}
|
|
16493
|
+
// Use cached Sets for O(1) lookup
|
|
16494
|
+
var isSelected = this.virtualSelectedNodesSet.has(id);
|
|
16495
|
+
// Resolve checkbox state: indeterminate takes precedence over the checked set,
|
|
16496
|
+
// because a node can be in the indeterminate state without being in checkedNodes.
|
|
16497
|
+
var isChecked = (enableVirtualization && this.virtualIndeterminateNodesSet.has(id))
|
|
16498
|
+
? 'indeterminate'
|
|
16499
|
+
: this.virtualCheckedNodesSet.has(id);
|
|
16500
|
+
var isDisabled = false; // TODO: Check if any per-node disabled field exists
|
|
16501
|
+
var iconCssVal = raw[iconCssFieldName];
|
|
16502
|
+
var iconCss = isNullOrUndefined(iconCssVal) ? '' : iconCssVal.toString();
|
|
16503
|
+
var imageUrlVal = raw[imageUrlFieldName];
|
|
16504
|
+
var imageUrl = isNullOrUndefined(imageUrlVal) ? '' : imageUrlVal.toString();
|
|
16505
|
+
var node = {
|
|
16506
|
+
id: id, text: text, level: level, parentId: parentId, hasChildren: hasChildren, isExpanded: isExpanded,
|
|
16507
|
+
isSelected: isSelected, isChecked: isChecked, isDisabled: isDisabled, iconCss: iconCss, imageUrl: imageUrl, rawData: raw
|
|
16508
|
+
};
|
|
16509
|
+
result.push(node);
|
|
16510
|
+
if (isExpanded && hasChildren) {
|
|
16511
|
+
// Determine children list
|
|
16512
|
+
var children = [];
|
|
16513
|
+
if (isDataTypeFlat) {
|
|
16514
|
+
if (this.groupedData) {
|
|
16515
|
+
children = this.getChildGroup(this.groupedData, id, false);
|
|
16516
|
+
// Apply sortOrder to flat-data children (same as hierarchical path)
|
|
16517
|
+
if (needsSorting) {
|
|
16518
|
+
children = ListBase.getDataSource(children, ListBase.addSorting(this.sortOrder, this.fields.text));
|
|
16519
|
+
}
|
|
16520
|
+
}
|
|
16521
|
+
}
|
|
16522
|
+
else {
|
|
16523
|
+
var rawChildren = getValue(childFieldName, raw);
|
|
16524
|
+
if (!isNullOrUndefined(rawChildren) && Array.isArray(rawChildren)) {
|
|
16525
|
+
children = rawChildren;
|
|
16526
|
+
// Only sort if needed
|
|
16527
|
+
if (needsSorting) {
|
|
16528
|
+
children = ListBase.getDataSource(children, ListBase.addSorting(this.sortOrder, this.fields.text));
|
|
16529
|
+
}
|
|
16530
|
+
}
|
|
16531
|
+
}
|
|
16532
|
+
this.flattenNodeRecursive(children, level + 1, id, result);
|
|
16533
|
+
}
|
|
16534
|
+
}
|
|
16535
|
+
};
|
|
16536
|
+
/**
|
|
16537
|
+
* Checks whether a raw datasource node has child records.
|
|
16538
|
+
*
|
|
16539
|
+
* @param {Object} raw - Raw datasource object.
|
|
16540
|
+
* @returns {boolean} True if children exist.
|
|
16541
|
+
* @private
|
|
16542
|
+
*/
|
|
16543
|
+
TreeView.prototype.hasChildRecords = function (raw) {
|
|
16544
|
+
if (this.dataType === 1) {
|
|
16545
|
+
if (!this.groupedData) {
|
|
16546
|
+
return false;
|
|
16547
|
+
}
|
|
16548
|
+
var rawId = raw[this.fields.id];
|
|
16549
|
+
if (isNullOrUndefined(rawId)) {
|
|
16550
|
+
return false;
|
|
16551
|
+
}
|
|
16552
|
+
var groupedChild = this.getChildGroup(this.groupedData, rawId.toString(), false);
|
|
16553
|
+
return !isNullOrUndefined(groupedChild) && groupedChild.length > 0;
|
|
16554
|
+
}
|
|
16555
|
+
var childField = this.fields.child.toString();
|
|
16556
|
+
var children = getValue(childField, raw);
|
|
16557
|
+
return !isNullOrUndefined(children) && Array.isArray(children) && children.length > 0;
|
|
16558
|
+
};
|
|
16559
|
+
/**
|
|
16560
|
+
* Rebuilds `virtualNodeMap` (id → index) from the current `virtualFlatNodes`.
|
|
16561
|
+
*
|
|
16562
|
+
* @returns {void}
|
|
16563
|
+
* @private
|
|
16564
|
+
*/
|
|
16565
|
+
TreeView.prototype.rebuildVirtualNodeMap = function () {
|
|
16566
|
+
this.virtualNodeMap.clear();
|
|
16567
|
+
for (var i = 0; i < this.virtualFlatNodes.length; i++) {
|
|
16568
|
+
this.virtualNodeMap.set(this.virtualFlatNodes[parseInt(i.toString(), 10)].id, i);
|
|
16569
|
+
}
|
|
16570
|
+
};
|
|
16571
|
+
TreeView.prototype.getVirtualWindow = function (scrollTop) {
|
|
16572
|
+
var total = this.virtualFlatNodes.length;
|
|
16573
|
+
if (total === 0) {
|
|
16574
|
+
return { startIndex: 0, endIndex: 0 };
|
|
16575
|
+
}
|
|
16576
|
+
var st = scrollTop !== undefined ? scrollTop : this.element.scrollTop;
|
|
16577
|
+
var itemH = this.virtualItemHeight;
|
|
16578
|
+
var vpH = this.virtualViewportHeight;
|
|
16579
|
+
var rawStart = Math.floor(st / itemH) - this.virtualOverscanCount;
|
|
16580
|
+
var rawEnd = Math.ceil((st + vpH) / itemH) + this.virtualOverscanCount;
|
|
16581
|
+
var startIndex = Math.max(0, rawStart);
|
|
16582
|
+
var endIndex = Math.min(total, rawEnd);
|
|
16583
|
+
return { startIndex: startIndex, endIndex: endIndex };
|
|
16584
|
+
};
|
|
16585
|
+
TreeView.prototype.getVirtualWindowAt = function (scrollTop) {
|
|
16586
|
+
return this.getVirtualWindow(scrollTop);
|
|
16587
|
+
};
|
|
16588
|
+
TreeView.prototype.getVirtualPadding = function () {
|
|
16589
|
+
var total = this.virtualFlatNodes.length;
|
|
16590
|
+
var itemH = this.virtualItemHeight;
|
|
16591
|
+
var start = this.virtualStartIndex;
|
|
16592
|
+
var end = this.virtualEndIndex;
|
|
16593
|
+
var paddingTop = start * itemH;
|
|
16594
|
+
var paddingBottom = Math.max(0, (total - end) * itemH);
|
|
16595
|
+
return { paddingTop: paddingTop, paddingBottom: paddingBottom };
|
|
16596
|
+
};
|
|
16597
|
+
/**
|
|
16598
|
+
* Renders the virtual window into a **nested** `<ul>/<li>` hierarchy identical to
|
|
16599
|
+
* the non-virtualized DOM structure.
|
|
16600
|
+
*
|
|
16601
|
+
* ## Scroll math
|
|
16602
|
+
* The flat-index ↔ pixel mapping stays unchanged: every entry in
|
|
16603
|
+
* `virtualFlatNodes` represents exactly one `itemHeight` row.
|
|
16604
|
+
* `paddingTop = startIndex * itemHeight` and
|
|
16605
|
+
* `paddingBottom = (total - endIndex) * itemHeight` keep the scrollbar
|
|
16606
|
+
* thumb in the correct position.
|
|
16607
|
+
*
|
|
16608
|
+
* ## Ancestor injection
|
|
16609
|
+
* When `startIndex` points at a child node whose ancestor(s) have already
|
|
16610
|
+
* scrolled above the viewport (their flat indices are < startIndex), the
|
|
16611
|
+
* ancestors would normally be missing from the DOM, forcing the children to
|
|
16612
|
+
* fall back to the root `<ul>` as flat siblings — producing wrong HTML.
|
|
16613
|
+
*
|
|
16614
|
+
* To fix this, before rendering the window we walk the ancestor chain of the
|
|
16615
|
+
* first visible node and collect every ancestor that lies **outside** the
|
|
16616
|
+
* window. Those ancestors are injected as real `<li>` containers at the
|
|
16617
|
+
* very top of the root `<ul>`. To compensate for their presence, `paddingTop`
|
|
16618
|
+
* is reduced by `injectedCount * itemHeight` so the total scroll height
|
|
16619
|
+
* remains the same.
|
|
16620
|
+
*
|
|
16621
|
+
* Once the ancestors are in the DOM they are registered in `renderedParentMap`
|
|
16622
|
+
* so the normal window-rendering loop can nest children inside them exactly
|
|
16623
|
+
* as it does when both parent and child are in the same window.
|
|
16624
|
+
*
|
|
16625
|
+
* @returns {void}
|
|
16626
|
+
* @private
|
|
16627
|
+
*/
|
|
16628
|
+
TreeView.prototype.renderVirtualItems = function () {
|
|
16629
|
+
if (!this.ulElement) {
|
|
16630
|
+
return;
|
|
16631
|
+
}
|
|
16632
|
+
var ul = this.ulElement;
|
|
16633
|
+
// ── Snapshot focused ID BEFORE clearing the DOM ───────────────────────────
|
|
16634
|
+
// Removing a focused <li> from the DOM triggers a synchronous `blur` event,
|
|
16635
|
+
// which calls focusOut() and sets virtualFocusedId = null. Capturing the id
|
|
16636
|
+
// here (before any removeChild) ensures focus is correctly restored to the
|
|
16637
|
+
// same node after re-render even when keyboard navigation was in progress.
|
|
16638
|
+
var focusedUid = this.virtualFocusedId || null;
|
|
16639
|
+
// ── Clear previous render (direct children only) ─────────────────────────
|
|
16640
|
+
var existingItems = ul.querySelectorAll(':scope > li');
|
|
16641
|
+
for (var i = existingItems.length - 1; i >= 0; i--) {
|
|
16642
|
+
ul.removeChild(existingItems[parseInt(i.toString(), 10)]);
|
|
16643
|
+
}
|
|
16644
|
+
var renderedParentMap = new Map();
|
|
16645
|
+
var itemH = this.virtualItemHeight;
|
|
16646
|
+
var injectedCount = 0;
|
|
16647
|
+
if (this.virtualStartIndex < this.virtualFlatNodes.length) {
|
|
16648
|
+
var firstNode = this.virtualFlatNodes[this.virtualStartIndex];
|
|
16649
|
+
if (firstNode.parentId) {
|
|
16650
|
+
// Build the ancestor chain from root down to the immediate parent
|
|
16651
|
+
var ancestors = [];
|
|
16652
|
+
var searchId = firstNode.parentId;
|
|
16653
|
+
while (searchId) {
|
|
16654
|
+
var ancestorIdx = this.virtualNodeMap.get(searchId);
|
|
16655
|
+
if (!isNullOrUndefined(ancestorIdx) && ancestorIdx < this.virtualStartIndex) {
|
|
16656
|
+
var ancestor = this.virtualFlatNodes[parseInt(ancestorIdx.toString(), 10)];
|
|
16657
|
+
ancestors.unshift(ancestor); // prepend so root comes first
|
|
16658
|
+
searchId = ancestor.parentId;
|
|
16659
|
+
}
|
|
16660
|
+
else {
|
|
16661
|
+
break;
|
|
16662
|
+
}
|
|
16663
|
+
}
|
|
16664
|
+
// Inject each ancestor as a real <li> into the root <ul>
|
|
16665
|
+
// and register it in renderedParentMap for child-nesting below.
|
|
16666
|
+
for (var a = 0; a < ancestors.length; a++) {
|
|
16667
|
+
var ancestor = ancestors[parseInt(a.toString(), 10)];
|
|
16668
|
+
var ancestorLi = this.createVirtualListItem(ancestor, false);
|
|
16669
|
+
// Find the correct container: root or a previously injected ancestor's <ul>
|
|
16670
|
+
var targetUl = ul;
|
|
16671
|
+
if (ancestor.parentId && renderedParentMap.has(ancestor.parentId)) {
|
|
16672
|
+
var pe = renderedParentMap.get(ancestor.parentId);
|
|
16673
|
+
if (!pe.childUl) {
|
|
16674
|
+
pe.childUl = this.createElement('ul', {
|
|
16675
|
+
className: PARENTITEM + ' e-ul',
|
|
16676
|
+
attrs: { role: 'group' }
|
|
16677
|
+
});
|
|
16678
|
+
pe.li.appendChild(pe.childUl);
|
|
16679
|
+
}
|
|
16680
|
+
targetUl = pe.childUl;
|
|
16681
|
+
}
|
|
16682
|
+
targetUl.appendChild(ancestorLi);
|
|
16683
|
+
renderedParentMap.set(ancestor.id, { li: ancestorLi, childUl: null });
|
|
16684
|
+
injectedCount++;
|
|
16685
|
+
}
|
|
16686
|
+
}
|
|
16687
|
+
}
|
|
16688
|
+
// ── Scroll-space padding (adjusted for injected ancestors) ────────────────
|
|
16689
|
+
var total = this.virtualFlatNodes.length;
|
|
16690
|
+
var start = this.virtualStartIndex;
|
|
16691
|
+
var end = this.virtualEndIndex;
|
|
16692
|
+
var rawPaddingTop = start * itemH;
|
|
16693
|
+
// Subtract the height of injected ancestors so the scroll position is
|
|
16694
|
+
// exact: those ancestor rows are now real DOM elements, not hidden space.
|
|
16695
|
+
var adjustedPaddingTop = Math.max(0, rawPaddingTop - injectedCount * itemH);
|
|
16696
|
+
ul.style.paddingTop = adjustedPaddingTop + 'px';
|
|
16697
|
+
ul.style.paddingBottom = Math.max(0, (total - end) * itemH) + 'px';
|
|
16698
|
+
// ── Render window items (nested via renderedParentMap) ────────────────────
|
|
16699
|
+
var liListBuf = [];
|
|
16700
|
+
for (var i = start; i < end; i++) {
|
|
16701
|
+
var node = this.virtualFlatNodes[parseInt(i.toString(), 10)];
|
|
16702
|
+
var li = this.createVirtualListItem(node, i === start);
|
|
16703
|
+
// Find the correct parent container
|
|
16704
|
+
var targetUl = ul;
|
|
16705
|
+
if (node.parentId && renderedParentMap.has(node.parentId)) {
|
|
16706
|
+
var parentEntry = renderedParentMap.get(node.parentId);
|
|
16707
|
+
// Lazily create the child <ul> the first time a child needs it
|
|
16708
|
+
if (!parentEntry.childUl) {
|
|
16709
|
+
parentEntry.childUl = this.createElement('ul', {
|
|
16710
|
+
className: PARENTITEM + ' e-ul',
|
|
16711
|
+
attrs: { role: 'group' }
|
|
16712
|
+
});
|
|
16713
|
+
parentEntry.li.appendChild(parentEntry.childUl);
|
|
16714
|
+
}
|
|
16715
|
+
targetUl = parentEntry.childUl;
|
|
16716
|
+
}
|
|
16717
|
+
targetUl.appendChild(li);
|
|
16718
|
+
liListBuf.push(li);
|
|
16719
|
+
// Register this node so its children in the same window can nest under it
|
|
16720
|
+
if (node.isExpanded && node.hasChildren) {
|
|
16721
|
+
renderedParentMap.set(node.id, { li: li, childUl: null });
|
|
16722
|
+
}
|
|
16723
|
+
}
|
|
16724
|
+
// ── Restore focus / tabindex ──────────────────────────────────────────────
|
|
16725
|
+
// In virtual mode only the li that carries the 'e-active' class should be
|
|
16726
|
+
// focusable (tabindex='0'). All other rendered li elements must be set
|
|
16727
|
+
// to tabindex='-1' so the tab order remains unambiguous as the window
|
|
16728
|
+
// changes during scrolling.
|
|
16729
|
+
var focusRestored = false;
|
|
16730
|
+
// 1. Prefer the currently active node if it is in the rendered window.
|
|
16731
|
+
for (var k = 0; k < liListBuf.length; k++) {
|
|
16732
|
+
var li = liListBuf[parseInt(k.toString(), 10)];
|
|
16733
|
+
if (li.classList.contains(ACTIVE)) {
|
|
16734
|
+
li.setAttribute('tabindex', '0');
|
|
16735
|
+
// ── Fix: ensure FOCUS class set on active node too ──
|
|
16736
|
+
// This ensures focusIn() guard condition is met: tabindex='0' && FOCUS class
|
|
16737
|
+
addClass([li], FOCUS);
|
|
16738
|
+
focusRestored = true;
|
|
16739
|
+
break;
|
|
16740
|
+
}
|
|
16741
|
+
}
|
|
16742
|
+
// 2. Otherwise fall back to the previously focused node (if it is in window).
|
|
16743
|
+
if (!focusRestored && focusedUid) {
|
|
16744
|
+
for (var k = 0; k < liListBuf.length; k++) {
|
|
16745
|
+
var li = liListBuf[parseInt(k.toString(), 10)];
|
|
16746
|
+
if (li.getAttribute('data-uid') === focusedUid) {
|
|
16747
|
+
li.setAttribute('tabindex', '0');
|
|
16748
|
+
addClass([li], FOCUS);
|
|
16749
|
+
addClass([li], FOCUSED$1);
|
|
16750
|
+
// ── Fix: restore actual browser focus so keyboard events keep working ──
|
|
16751
|
+
// After renderVirtualItems() replaces all <li> elements the old element
|
|
16752
|
+
// is gone from the DOM and document.activeElement falls back to
|
|
16753
|
+
// document.body. Setting tabindex + classes is not enough — the new
|
|
16754
|
+
// element also needs a programmatic .focus() call so subsequent keyboard
|
|
16755
|
+
// events (Arrow keys, Home, End, etc.) are delivered to the TreeView.
|
|
16756
|
+
// Re-attach the blur→focusOut handler so virtualFocusedId is cleared
|
|
16757
|
+
// correctly when the user tabs away.
|
|
16758
|
+
// ── Use preventScroll:true ────────────────────────────────────────────
|
|
16759
|
+
// Without preventScroll the browser scrolls the container to bring this
|
|
16760
|
+
// node into view during the re-render, changing scrollTop AFTER the
|
|
16761
|
+
// correct paddingTop has been applied. This is the root cause of the
|
|
16762
|
+
// KBN expand position-jump bug: the render is correct but the browser
|
|
16763
|
+
// silently scrolls the viewport, making the parent node appear to jump.
|
|
16764
|
+
// ensureVirtualNodeVisible() handles any legitimate scroll-into-view
|
|
16765
|
+
// needs before renderVirtualItems() is called, so scroll here is wrong.
|
|
16766
|
+
EventHandler.add(li, 'blur', this.focusOut, this);
|
|
16767
|
+
li.focus({ preventScroll: true });
|
|
16768
|
+
focusRestored = true;
|
|
16769
|
+
break;
|
|
16770
|
+
}
|
|
16771
|
+
}
|
|
16772
|
+
}
|
|
16773
|
+
// 3. Finally default to the first item in the window.
|
|
16774
|
+
if (!focusRestored && liListBuf.length > 0) {
|
|
16775
|
+
var firstLi = liListBuf[0];
|
|
16776
|
+
firstLi.setAttribute('tabindex', '0');
|
|
16777
|
+
}
|
|
16778
|
+
// ── Fix: Ensure all other rendered nodes have tabindex="-1" ──
|
|
16779
|
+
// This prevents stale tabindex="0" on multiple nodes which breaks Tab order
|
|
16780
|
+
for (var k = 0; k < liListBuf.length; k++) {
|
|
16781
|
+
var li = liListBuf[parseInt(k.toString(), 10)];
|
|
16782
|
+
if (li.getAttribute('tabindex') !== '0') {
|
|
16783
|
+
li.setAttribute('tabindex', '-1');
|
|
16784
|
+
}
|
|
16785
|
+
}
|
|
16786
|
+
// Keep liList in sync so keyboard-navigation helpers stay functional.
|
|
16787
|
+
this.liList = liListBuf;
|
|
16788
|
+
};
|
|
16789
|
+
/**
|
|
16790
|
+
* Creates a single `<li>` element for the virtual window representing `node`.
|
|
16791
|
+
*
|
|
16792
|
+
* @param {VirtualNodeData} node - The node data.
|
|
16793
|
+
* @param {boolean} _isFirst - True if this is the first rendered item (unused here but kept for potential override).
|
|
16794
|
+
* @returns {HTMLElement} The constructed `<li>` element.
|
|
16795
|
+
* @private
|
|
16796
|
+
*/
|
|
16797
|
+
TreeView.prototype.createVirtualListItem = function (node, _isFirst) {
|
|
16798
|
+
var li = this.createElement('li', { className: LISTITEM });
|
|
16799
|
+
// Level class for CSS indentation
|
|
16800
|
+
li.classList.add('e-level-' + node.level);
|
|
16801
|
+
li.setAttribute('data-uid', node.id);
|
|
16802
|
+
li.setAttribute('aria-level', node.level.toString());
|
|
16803
|
+
li.setAttribute('role', 'treeitem');
|
|
16804
|
+
li.setAttribute('tabindex', '-1');
|
|
16805
|
+
// Full-row overlay (required for fullRowSelect mode)
|
|
16806
|
+
if (this.fullRowSelect) {
|
|
16807
|
+
var fullRow = this.createElement('div', { className: FULLROW });
|
|
16808
|
+
li.appendChild(fullRow);
|
|
16809
|
+
}
|
|
16810
|
+
// Text/icon wrapper
|
|
16811
|
+
var textWrap = this.createElement('div', { className: TEXTWRAP });
|
|
16812
|
+
// Expand/collapse icon
|
|
16813
|
+
if (node.hasChildren) {
|
|
16814
|
+
var iconSpan = this.createElement('div', {
|
|
16815
|
+
className: ICON + ' ' + (node.isExpanded ? COLLAPSIBLE : EXPANDABLE)
|
|
16816
|
+
});
|
|
16817
|
+
textWrap.appendChild(iconSpan);
|
|
16818
|
+
}
|
|
16819
|
+
// Checkbox
|
|
16820
|
+
if (this.showCheckBox) {
|
|
16821
|
+
var checkWrap = createCheckBox(this.createElement, false, {
|
|
16822
|
+
checked: node.isChecked === true,
|
|
16823
|
+
cssClass: CHECKBOXWRAP
|
|
16824
|
+
});
|
|
16825
|
+
if (node.isChecked === 'indeterminate') {
|
|
16826
|
+
var frame = checkWrap.querySelector('.' + CHECKBOXFRAME);
|
|
16827
|
+
if (frame) {
|
|
16828
|
+
frame.classList.add(INDETERMINATE);
|
|
16829
|
+
}
|
|
16830
|
+
}
|
|
16831
|
+
textWrap.appendChild(checkWrap);
|
|
16832
|
+
}
|
|
16833
|
+
// Icon
|
|
16834
|
+
if (node.iconCss) {
|
|
16835
|
+
var iconEl = this.createElement('span', {
|
|
16836
|
+
className: ICON + ' ' + node.iconCss
|
|
16837
|
+
});
|
|
16838
|
+
textWrap.appendChild(iconEl);
|
|
16839
|
+
}
|
|
16840
|
+
// Image
|
|
16841
|
+
if (node.imageUrl) {
|
|
16842
|
+
var img = document.createElement('img');
|
|
16843
|
+
img.src = node.imageUrl;
|
|
16844
|
+
img.classList.add(IMAGE);
|
|
16845
|
+
textWrap.appendChild(img);
|
|
16846
|
+
}
|
|
16847
|
+
// Text anchor
|
|
16848
|
+
var anchor = this.createElement('span', {
|
|
16849
|
+
className: 'e-list-text',
|
|
16850
|
+
innerHTML: node.text
|
|
16851
|
+
});
|
|
16852
|
+
textWrap.appendChild(anchor);
|
|
16853
|
+
li.appendChild(textWrap);
|
|
16854
|
+
// State classes
|
|
16855
|
+
if (node.isExpanded) {
|
|
16856
|
+
li.classList.add(EXPANDED);
|
|
16857
|
+
li.setAttribute('aria-expanded', 'true');
|
|
16858
|
+
}
|
|
16859
|
+
else if (node.hasChildren) {
|
|
16860
|
+
li.classList.add(NODECOLLAPSED);
|
|
16861
|
+
li.setAttribute('aria-expanded', 'false');
|
|
16862
|
+
}
|
|
16863
|
+
if (node.isSelected) {
|
|
16864
|
+
li.classList.add(ACTIVE);
|
|
16865
|
+
li.setAttribute('aria-selected', 'true');
|
|
16866
|
+
}
|
|
16867
|
+
if (node.isDisabled) {
|
|
16868
|
+
li.classList.add(DISABLED$1);
|
|
16869
|
+
li.setAttribute('aria-disabled', 'true');
|
|
16870
|
+
}
|
|
16871
|
+
if (node.hasChildren) {
|
|
16872
|
+
li.classList.add(CHILD);
|
|
16873
|
+
}
|
|
16874
|
+
// Wire the focus event so `focusIn()` fires when the user Tabs into this
|
|
16875
|
+
// item. The non-virtualized path registers this in `beforeNodeCreate()`,
|
|
16876
|
+
// but virtual items never go through that callback, so we must register
|
|
16877
|
+
// it here to keep focus styling (e.g. `e-focused`) consistent between
|
|
16878
|
+
// virtual and non-virtual modes. `unWireEvents()` already removes this
|
|
16879
|
+
// handler during teardown by iterating over the rendered `<li>`s.
|
|
16880
|
+
EventHandler.add(li, 'focus', this.focusIn, this);
|
|
16881
|
+
return li;
|
|
16882
|
+
};
|
|
16883
|
+
/**
|
|
16884
|
+
* Initialises the virtual-scrolling layout:
|
|
16885
|
+
* 1. Adds the `e-virtualization` CSS class and applies a fixed `height` + `overflow-y`.
|
|
16886
|
+
* 2. Flattens all visible nodes into `virtualFlatNodes`.
|
|
16887
|
+
* 3. Measures item height and viewport height.
|
|
16888
|
+
* 4. Computes the initial window and renders it.
|
|
16889
|
+
* 5. Wires the scroll event handler.
|
|
16890
|
+
*
|
|
16891
|
+
* @returns {void}
|
|
16892
|
+
* @private
|
|
16893
|
+
*/
|
|
16894
|
+
TreeView.prototype.initVirtualization = function () {
|
|
16895
|
+
addClass([this.element], VIRTUALIZATION);
|
|
16896
|
+
// Apply container height
|
|
16897
|
+
var px = this.parseHeightToPixels();
|
|
16898
|
+
if (px > 0) {
|
|
16899
|
+
this.element.style.height = px + 'px';
|
|
16900
|
+
this.element.style.overflowY = 'auto';
|
|
16901
|
+
}
|
|
16902
|
+
// Ensure the inner UL is ready
|
|
16903
|
+
if (!this.ulElement) {
|
|
16904
|
+
this.ulElement = select('.' + PARENTITEM, this.element);
|
|
16905
|
+
}
|
|
16906
|
+
if (!this.ulElement) {
|
|
16907
|
+
return;
|
|
16908
|
+
}
|
|
16909
|
+
// Make the UL position-relative for the absolute spacers
|
|
16910
|
+
this.ulElement.style.position = 'relative';
|
|
16911
|
+
// Rebuild flat list
|
|
16912
|
+
this.virtualFlatNodes = this.flattenVisibleNodes();
|
|
16913
|
+
this.rebuildVirtualNodeMap();
|
|
16914
|
+
// Measure dimensions
|
|
16915
|
+
this.virtualViewportHeight = px > 0 ? px : this.element.offsetHeight;
|
|
16916
|
+
// Render a single probe item to measure the real item height before the full render
|
|
16917
|
+
if (this.virtualFlatNodes.length > 0) {
|
|
16918
|
+
var probe = this.createVirtualListItem(this.virtualFlatNodes[0], true);
|
|
16919
|
+
this.ulElement.appendChild(probe);
|
|
16920
|
+
this.virtualItemHeight = probe.offsetHeight > 0 ? probe.offsetHeight : this.virtualItemHeight;
|
|
16921
|
+
this.ulElement.removeChild(probe);
|
|
16922
|
+
}
|
|
16923
|
+
// Compute window and render all items in the initial viewport
|
|
16924
|
+
var win = this.getVirtualWindow();
|
|
16925
|
+
this.virtualStartIndex = win.startIndex;
|
|
16926
|
+
this.virtualEndIndex = win.endIndex;
|
|
16927
|
+
this.renderVirtualItems();
|
|
16928
|
+
// Wire scroll
|
|
16929
|
+
this.wireVirtualScrollEvents();
|
|
16930
|
+
};
|
|
16931
|
+
/**
|
|
16932
|
+
* Wires the scroll event listener on the TreeView element.
|
|
16933
|
+
*
|
|
16934
|
+
* @returns {void}
|
|
16935
|
+
* @private
|
|
16936
|
+
*/
|
|
16937
|
+
TreeView.prototype.wireVirtualScrollEvents = function () {
|
|
16938
|
+
this.unwireVirtualScrollEvents();
|
|
16939
|
+
this.virtualScrollBound = this.onVirtualScroll.bind(this);
|
|
16940
|
+
this.element.addEventListener('scroll', this.virtualScrollBound, { passive: true });
|
|
16941
|
+
};
|
|
16942
|
+
/**
|
|
16943
|
+
* Removes the scroll event listener previously wired by `wireVirtualScrollEvents`.
|
|
16944
|
+
*
|
|
16945
|
+
* @returns {void}
|
|
16946
|
+
* @private
|
|
16947
|
+
*/
|
|
16948
|
+
TreeView.prototype.unwireVirtualScrollEvents = function () {
|
|
16949
|
+
if (this.virtualScrollBound) {
|
|
16950
|
+
this.element.removeEventListener('scroll', this.virtualScrollBound);
|
|
16951
|
+
this.virtualScrollBound = null;
|
|
16952
|
+
}
|
|
16953
|
+
if (this.virtualScrollRAF !== null) {
|
|
16954
|
+
cancelAnimationFrame(this.virtualScrollRAF);
|
|
16955
|
+
this.virtualScrollRAF = null;
|
|
16956
|
+
}
|
|
16957
|
+
};
|
|
16958
|
+
/**
|
|
16959
|
+
* Scroll handler for the virtual TreeView. Throttled via `requestAnimationFrame`.
|
|
16960
|
+
* Shows the loading mask during fast scrolls, re-renders the window, then hides the mask.
|
|
16961
|
+
*
|
|
16962
|
+
* @returns {void}
|
|
16963
|
+
* @private
|
|
16964
|
+
*/
|
|
16965
|
+
TreeView.prototype.onVirtualScroll = function () {
|
|
16966
|
+
var _this = this;
|
|
16967
|
+
if (this.virtualScrollRAF !== null) {
|
|
16968
|
+
cancelAnimationFrame(this.virtualScrollRAF);
|
|
16969
|
+
}
|
|
16970
|
+
// ── Tab-induced focus guard ────────────────────────────────────────────────
|
|
16971
|
+
// When the user Tabs into a `<li tabindex="0">` that is in the middle of
|
|
16972
|
+
// the treeview, the browser auto-scrolls the container so the focused
|
|
16973
|
+
// element becomes visible. That fires a `scroll` event here, but the
|
|
16974
|
+
// virtual window already contains the focused element — re-rendering
|
|
16975
|
+
// would destroy the focused `<li>` and break focus. Detect this case
|
|
16976
|
+
// via the flag set in `keyDownHandler` and skip the re-render entirely.
|
|
16977
|
+
if (this.virtualSkipNextScrollRender) {
|
|
16978
|
+
this.virtualSkipNextScrollRender = false;
|
|
16979
|
+
// Update prev scrollTop so a subsequent user-driven scroll still
|
|
16980
|
+
// calculates the correct delta.
|
|
16981
|
+
this.virtualPrevScrollTop = this.element.scrollTop;
|
|
16982
|
+
return;
|
|
16983
|
+
}
|
|
16984
|
+
var currentScrollTop = this.element.scrollTop;
|
|
16985
|
+
var delta = Math.abs(currentScrollTop - this.virtualPrevScrollTop);
|
|
16986
|
+
var fastScrollThreshold = this.virtualViewportHeight * 2;
|
|
16987
|
+
if (delta > fastScrollThreshold) {
|
|
16988
|
+
this.showVirtualMask(currentScrollTop);
|
|
16989
|
+
}
|
|
16990
|
+
this.virtualScrollRAF = requestAnimationFrame(function () {
|
|
16991
|
+
_this.virtualScrollRAF = null;
|
|
16992
|
+
_this.virtualPrevScrollTop = _this.element.scrollTop;
|
|
16993
|
+
var win = _this.getVirtualWindow();
|
|
16994
|
+
_this.virtualStartIndex = win.startIndex;
|
|
16995
|
+
_this.virtualEndIndex = win.endIndex;
|
|
16996
|
+
_this.renderVirtualItems();
|
|
16997
|
+
// Hide the skeleton mask after a short delay so it stays visible long enough
|
|
16998
|
+
// for the user to perceive the loading indicator even on short scrolls.
|
|
16999
|
+
setTimeout(function () {
|
|
17000
|
+
_this.hideVirtualMask();
|
|
17001
|
+
// Keep the (now hidden) mask's coords fresh for the next show.
|
|
17002
|
+
_this.updateMaskPosition();
|
|
17003
|
+
}, 200);
|
|
17004
|
+
});
|
|
17005
|
+
};
|
|
17006
|
+
/**
|
|
17007
|
+
* Creates the skeleton mask overlay used to indicate loading during fast scrolls.
|
|
17008
|
+
* Skeleton instances are stored in `skeletonInstances` for later disposal.
|
|
17009
|
+
*
|
|
17010
|
+
* @returns {void}
|
|
17011
|
+
* @private
|
|
17012
|
+
*/
|
|
17013
|
+
TreeView.prototype.createVirtualMask = function () {
|
|
17014
|
+
if (this.virtualMaskElement) {
|
|
17015
|
+
return;
|
|
17016
|
+
}
|
|
17017
|
+
// Use position:fixed so the mask is anchored to the visible viewport (not to the
|
|
17018
|
+
// scrolling container). Width/height/left/top are set/refreshed by
|
|
17019
|
+
// updateMaskPosition() so the mask always covers the TreeView's visible area
|
|
17020
|
+
// regardless of how the page itself is scrolled.
|
|
17021
|
+
var rect = this.element.getBoundingClientRect();
|
|
17022
|
+
var scrollBarWidth = this.element.offsetWidth - this.element.clientWidth;
|
|
17023
|
+
var maskParent = this.createElement('div', {
|
|
17024
|
+
className: VIRTUAL_MASK_PARENT,
|
|
17025
|
+
styles: "position:fixed;top:" + rect.top + "px;left:" + rect.left + "px;width:" + (rect.width - scrollBarWidth) + "px;height:" + rect.height + "px;z-index:10;overflow:hidden;background:#fff;pointer-events:none;display:none;"
|
|
17026
|
+
});
|
|
17027
|
+
var visibleRows = Math.ceil(this.virtualViewportHeight / this.virtualItemHeight) + 1;
|
|
17028
|
+
for (var r = 0; r < visibleRows; r++) {
|
|
17029
|
+
var maskItem = this.createElement('div', {
|
|
17030
|
+
className: VIRTUAL_MASK_ITEM,
|
|
17031
|
+
styles: "display:flex;align-items:center;height:" + this.virtualItemHeight + "px;padding:0 12px;gap:8px;"
|
|
17032
|
+
});
|
|
17033
|
+
// Skeleton circle for icon placeholder
|
|
17034
|
+
// const iconHolder: HTMLElement = this.createElement('span', {
|
|
17035
|
+
// styles: `width:20px;height:20px;`
|
|
17036
|
+
// });
|
|
17037
|
+
// maskItem.appendChild(iconHolder);
|
|
17038
|
+
// const iconSkel: Skeleton = new Skeleton({
|
|
17039
|
+
// shape: 'Circle',
|
|
17040
|
+
// width: '20px',
|
|
17041
|
+
// height: '20px',
|
|
17042
|
+
// cssClass: 'e-virtual-skel-icon'
|
|
17043
|
+
// });
|
|
17044
|
+
// iconSkel.appendTo(iconHolder);
|
|
17045
|
+
// this.skeletonInstances.push(iconSkel);
|
|
17046
|
+
// Skeleton text bar
|
|
17047
|
+
var textHolder = this.createElement('span');
|
|
17048
|
+
textHolder.style.flex = '1';
|
|
17049
|
+
textHolder.style.height = '14px';
|
|
17050
|
+
maskItem.appendChild(textHolder);
|
|
17051
|
+
var textSkel = new Skeleton({
|
|
17052
|
+
shape: 'Text',
|
|
17053
|
+
width: '80%',
|
|
17054
|
+
height: '14px',
|
|
17055
|
+
cssClass: 'e-virtual-skel-text'
|
|
17056
|
+
});
|
|
17057
|
+
textSkel.appendTo(textHolder);
|
|
17058
|
+
this.skeletonInstances.push(textSkel);
|
|
17059
|
+
maskParent.appendChild(maskItem);
|
|
17060
|
+
}
|
|
17061
|
+
this.virtualMaskElement = maskParent;
|
|
17062
|
+
this.element.appendChild(maskParent);
|
|
17063
|
+
};
|
|
17064
|
+
/**
|
|
17065
|
+
* Refreshes the mask position so it always overlays the TreeView's viewport.
|
|
17066
|
+
* Called on every show / scroll, since `position:fixed` is relative to the
|
|
17067
|
+
* page viewport, not to the TreeView scroll container.
|
|
17068
|
+
*
|
|
17069
|
+
* @returns {void}
|
|
17070
|
+
* @private
|
|
17071
|
+
*/
|
|
17072
|
+
TreeView.prototype.updateMaskPosition = function () {
|
|
17073
|
+
if (!this.virtualMaskElement) {
|
|
17074
|
+
return;
|
|
17075
|
+
}
|
|
17076
|
+
var rect = this.element.getBoundingClientRect();
|
|
17077
|
+
var scrollBarWidth = this.element.offsetWidth - this.element.clientWidth;
|
|
17078
|
+
this.virtualMaskElement.style.top = rect.top + 'px';
|
|
17079
|
+
this.virtualMaskElement.style.left = rect.left + 'px';
|
|
17080
|
+
this.virtualMaskElement.style.width = (rect.width - scrollBarWidth) + 'px';
|
|
17081
|
+
this.virtualMaskElement.style.height = rect.height + 'px';
|
|
17082
|
+
};
|
|
17083
|
+
/**
|
|
17084
|
+
* Destroys all skeleton instances and removes the mask overlay from the DOM.
|
|
17085
|
+
*
|
|
17086
|
+
* @returns {void}
|
|
17087
|
+
* @private
|
|
17088
|
+
*/
|
|
17089
|
+
TreeView.prototype.destroyVirtualMask = function () {
|
|
17090
|
+
for (var i = this.skeletonInstances.length - 1; i >= 0; i--) {
|
|
17091
|
+
this.skeletonInstances[parseInt(i.toString(), 10)].destroy();
|
|
17092
|
+
}
|
|
17093
|
+
this.skeletonInstances = [];
|
|
17094
|
+
if (this.virtualMaskElement) {
|
|
17095
|
+
if (this.virtualMaskElement.parentElement) {
|
|
17096
|
+
this.virtualMaskElement.parentElement.removeChild(this.virtualMaskElement);
|
|
17097
|
+
}
|
|
17098
|
+
this.virtualMaskElement = null;
|
|
17099
|
+
}
|
|
17100
|
+
};
|
|
17101
|
+
/**
|
|
17102
|
+
* Positions and shows the skeleton mask at the current `scrollTop` position.
|
|
17103
|
+
*
|
|
17104
|
+
* @param {number} _scrollTop - Current scrollTop of the container.
|
|
17105
|
+
* @returns {void}
|
|
17106
|
+
* @private
|
|
17107
|
+
*/
|
|
17108
|
+
TreeView.prototype.showVirtualMask = function (_scrollTop) {
|
|
17109
|
+
if (!this.virtualMaskElement) {
|
|
17110
|
+
this.createVirtualMask();
|
|
17111
|
+
}
|
|
17112
|
+
if (this.virtualMaskElement) {
|
|
17113
|
+
// Refresh the fixed-position coords in case the TreeView was moved/resized
|
|
17114
|
+
// since the last time the mask was shown.
|
|
17115
|
+
this.updateMaskPosition();
|
|
17116
|
+
this.virtualMaskElement.style.display = 'block';
|
|
17117
|
+
// Visually hide the real list while the skeleton is shown
|
|
17118
|
+
if (this.ulElement) {
|
|
17119
|
+
this.ulElement.style.visibility = 'hidden';
|
|
17120
|
+
}
|
|
17121
|
+
}
|
|
17122
|
+
};
|
|
17123
|
+
/**
|
|
17124
|
+
* Hides the skeleton mask overlay after the virtual window has been rendered.
|
|
17125
|
+
*
|
|
17126
|
+
* @returns {void}
|
|
17127
|
+
* @private
|
|
17128
|
+
*/
|
|
17129
|
+
TreeView.prototype.hideVirtualMask = function () {
|
|
17130
|
+
if (this.virtualMaskElement) {
|
|
17131
|
+
this.virtualMaskElement.style.display = 'none';
|
|
17132
|
+
// Restore real list visibility
|
|
17133
|
+
if (this.ulElement) {
|
|
17134
|
+
this.ulElement.style.visibility = '';
|
|
17135
|
+
}
|
|
17136
|
+
}
|
|
17137
|
+
};
|
|
17138
|
+
/**
|
|
17139
|
+
* Ensures the node identified by `id` is scrolled into view inside the virtual container.
|
|
17140
|
+
* If the node falls outside the rendered window, the container's `scrollTop` is adjusted so
|
|
17141
|
+
* that the node becomes visible, the window is re-computed and `renderVirtualItems` is called.
|
|
17142
|
+
*
|
|
17143
|
+
* @param {string} id - The `data-uid` of the target node.
|
|
17144
|
+
* @returns {void}
|
|
17145
|
+
* @private
|
|
17146
|
+
*/
|
|
17147
|
+
TreeView.prototype.ensureVirtualNodeVisible = function (id) {
|
|
17148
|
+
var idx = this.virtualNodeMap.get(id);
|
|
17149
|
+
if (isNullOrUndefined(idx)) {
|
|
17150
|
+
return;
|
|
17151
|
+
}
|
|
17152
|
+
var itemH = this.virtualItemHeight;
|
|
17153
|
+
var vpH = this.virtualViewportHeight;
|
|
17154
|
+
var nodeTop = idx * itemH;
|
|
17155
|
+
var nodeBottom = nodeTop + itemH;
|
|
17156
|
+
var currentTop = this.element.scrollTop;
|
|
17157
|
+
var currentBottom = currentTop + vpH;
|
|
17158
|
+
if (nodeTop < currentTop) {
|
|
17159
|
+
this.element.scrollTop = nodeTop;
|
|
17160
|
+
}
|
|
17161
|
+
else if (nodeBottom > currentBottom) {
|
|
17162
|
+
this.element.scrollTop = nodeBottom - vpH;
|
|
17163
|
+
}
|
|
17164
|
+
else {
|
|
17165
|
+
return; // already visible, no re-render needed
|
|
17166
|
+
}
|
|
17167
|
+
// Re-render the new window synchronously so the <li> is in the DOM
|
|
17168
|
+
var win = this.getVirtualWindow();
|
|
17169
|
+
this.virtualStartIndex = win.startIndex;
|
|
17170
|
+
this.virtualEndIndex = win.endIndex;
|
|
17171
|
+
this.renderVirtualItems();
|
|
17172
|
+
};
|
|
17173
|
+
TreeView.prototype.handleVirtualExpand = function (id, isKeyboardNav) {
|
|
17174
|
+
// ── Cancel any pending scroll RAF ─────────────────────────────────────────
|
|
17175
|
+
// A scroll RAF queued before the expand click would run asynchronously after
|
|
17176
|
+
// this synchronous expand completes, re-rendering the window from a stale
|
|
17177
|
+
// scrollTop and moving the parent node to the wrong position. Cancel it now
|
|
17178
|
+
// so the expand render is authoritative.
|
|
17179
|
+
if (this.virtualScrollRAF !== null) {
|
|
17180
|
+
cancelAnimationFrame(this.virtualScrollRAF);
|
|
17181
|
+
this.virtualScrollRAF = null;
|
|
17182
|
+
}
|
|
17183
|
+
if (this.expandedNodes.indexOf(id) === -1) {
|
|
17184
|
+
this.expandedNodes.push(id);
|
|
17185
|
+
}
|
|
17186
|
+
// Also update virtualExpandedNodesSet to keep it in sync
|
|
17187
|
+
if (this.virtualExpandedNodesSet) {
|
|
17188
|
+
this.virtualExpandedNodesSet.add(id);
|
|
17189
|
+
}
|
|
17190
|
+
if (this.rootData) {
|
|
17191
|
+
var acutalRootData = this.rootData.find(function (item) { return item.id === parseInt(id, 10); });
|
|
17192
|
+
acutalRootData.isExpanded = true;
|
|
17193
|
+
}
|
|
17194
|
+
// ── Fix: Pin focused ID to the expanding node for keyboard navigation ──
|
|
17195
|
+
// When keyboard-triggered, the expanded node IS definitively the focused node
|
|
17196
|
+
// (`id` comes from currLi.getAttribute('data-uid') in expandNode, where currLi
|
|
17197
|
+
// is getFocusedNode()). Set unconditionally — the old conditional guard
|
|
17198
|
+
// `!this.virtualFocusedId` could leave a stale or null value if a previous
|
|
17199
|
+
// RAF render (from arrow-key scroll) hadn't yet completed, causing branch 3
|
|
17200
|
+
// (first item) to fire in renderVirtualItems() instead of branch 2.
|
|
17201
|
+
// For mouse clicks (isKeyboardNav=false), clear virtualFocusedId so that
|
|
17202
|
+
// renderVirtualItems() Branch 2 does NOT apply the FOCUS/FOCUSED classes —
|
|
17203
|
+
// mouse-based expand/collapse should never add the e-focused class.
|
|
17204
|
+
if (isKeyboardNav) {
|
|
17205
|
+
this.virtualFocusedId = id;
|
|
17206
|
+
}
|
|
17207
|
+
else {
|
|
17208
|
+
this.virtualFocusedId = null;
|
|
17209
|
+
}
|
|
17210
|
+
this.virtualFlatNodes = this.flattenVisibleNodes();
|
|
17211
|
+
this.rebuildVirtualNodeMap();
|
|
17212
|
+
// ── Snapshot scrollTop before computing the window ────────────────────────
|
|
17213
|
+
// Read scrollTop once here and pass it into getVirtualWindow so that any
|
|
17214
|
+
// browser scroll-anchoring adjustment that happens when the padding values
|
|
17215
|
+
// change cannot affect which window we render.
|
|
17216
|
+
var scrollTopSnapshot = this.element.scrollTop;
|
|
17217
|
+
var win = this.getVirtualWindowAt(scrollTopSnapshot);
|
|
17218
|
+
this.virtualStartIndex = win.startIndex;
|
|
17219
|
+
this.virtualEndIndex = win.endIndex;
|
|
17220
|
+
// ── Block ALL scroll-triggered re-renders during this expand ─────────────
|
|
17221
|
+
// renderVirtualItems() calls li.focus() in branch 2 (keyboard focus restore).
|
|
17222
|
+
// The post-render focus() call below can also trigger browser scroll. Both
|
|
17223
|
+
// can fire the 'scroll' event and cause onVirtualScroll() to queue a RAF.
|
|
17224
|
+
// We set the skip flag ONCE here; it is consumed by the first scroll event.
|
|
17225
|
+
// To cover the second potential scroll (from the focus() call below) we use
|
|
17226
|
+
// preventScroll:true on that call so it never moves the container at all.
|
|
17227
|
+
this.virtualSkipNextScrollRender = true;
|
|
17228
|
+
this.renderVirtualItems();
|
|
17229
|
+
// renderVirtualItems() replaces all <li> elements so the old icon element that
|
|
17230
|
+
// had the PROCESS class is gone. Remove PROCESS from the newly rendered icon
|
|
17231
|
+
// so the node can be collapsed/expanded again without being blocked.
|
|
17232
|
+
var newLi = this.getElement(id);
|
|
17233
|
+
if (newLi) {
|
|
17234
|
+
var icon = select('.' + ICON, newLi);
|
|
17235
|
+
if (icon) {
|
|
17236
|
+
removeClass([icon], PROCESS);
|
|
17237
|
+
}
|
|
17238
|
+
// ── Use preventScroll:true ────────────────────────────────────────────
|
|
17239
|
+
// Without preventScroll the browser scrolls the container to bring this
|
|
17240
|
+
// node into view, which fires a second 'scroll' event. The first scroll
|
|
17241
|
+
// was already consumed by virtualSkipNextScrollRender (set above), so the
|
|
17242
|
+
// second scroll would queue a new RAF that re-renders from the
|
|
17243
|
+
// focus-adjusted scrollTop — moving the parent node to the wrong position.
|
|
17244
|
+
newLi.focus({ preventScroll: true });
|
|
17245
|
+
}
|
|
17246
|
+
if (this.isLoaded) {
|
|
17247
|
+
var currLi = this.getElement(id);
|
|
17248
|
+
if (currLi) {
|
|
17249
|
+
var expandArgs = this.getExpandEvent(currLi, null);
|
|
17250
|
+
expandArgs.isInteracted = this.isInteracted;
|
|
17251
|
+
this.trigger('nodeExpanded', expandArgs);
|
|
17252
|
+
}
|
|
17253
|
+
}
|
|
17254
|
+
};
|
|
17255
|
+
TreeView.prototype.handleVirtualCollapse = function (id, isKeyboardNav) {
|
|
17256
|
+
// ── Cancel any pending scroll RAF ─────────────────────────────────────────
|
|
17257
|
+
// Mirrors handleVirtualExpand: a queued RAF from a previous scroll event
|
|
17258
|
+
// must not override the collapse render with a stale window.
|
|
17259
|
+
if (this.virtualScrollRAF !== null) {
|
|
17260
|
+
cancelAnimationFrame(this.virtualScrollRAF);
|
|
17261
|
+
this.virtualScrollRAF = null;
|
|
17262
|
+
}
|
|
17263
|
+
var idx = this.expandedNodes.indexOf(id);
|
|
17264
|
+
if (idx !== -1) {
|
|
17265
|
+
this.expandedNodes.splice(idx, 1);
|
|
17266
|
+
}
|
|
17267
|
+
// Also update virtualExpandedNodesSet to keep it in sync
|
|
17268
|
+
if (this.virtualExpandedNodesSet) {
|
|
17269
|
+
this.virtualExpandedNodesSet.delete(id);
|
|
17270
|
+
}
|
|
17271
|
+
if (this.rootData) {
|
|
17272
|
+
var acutalRootData = this.rootData.find(function (item) { return item.id === parseInt(id, 10); });
|
|
17273
|
+
acutalRootData.isExpanded = false;
|
|
17274
|
+
}
|
|
17275
|
+
// ── Fix: Pin focused ID to the collapsing node for keyboard navigation ──
|
|
17276
|
+
// Same reasoning as handleVirtualExpand: when keyboard-triggered, `id` is
|
|
17277
|
+
// definitively the focused node. Set unconditionally to avoid the stale/null
|
|
17278
|
+
// state that could cause the RAF re-render to fall through to branch 3.
|
|
17279
|
+
// For mouse clicks (isKeyboardNav=false), clear virtualFocusedId so that
|
|
17280
|
+
// renderVirtualItems() Branch 2 does NOT apply the FOCUS/FOCUSED classes —
|
|
17281
|
+
// mouse-based expand/collapse should never add the e-focused class.
|
|
17282
|
+
if (isKeyboardNav) {
|
|
17283
|
+
this.virtualFocusedId = id;
|
|
17284
|
+
}
|
|
17285
|
+
else {
|
|
17286
|
+
this.virtualFocusedId = null;
|
|
17287
|
+
}
|
|
17288
|
+
this.virtualFlatNodes = this.flattenVisibleNodes();
|
|
17289
|
+
this.rebuildVirtualNodeMap();
|
|
17290
|
+
// ── Snapshot scrollTop before computing the window ────────────────────────
|
|
17291
|
+
// Same rationale as handleVirtualExpand: capture scrollTop before any focus()
|
|
17292
|
+
// call or padding change can cause the browser to auto-scroll.
|
|
17293
|
+
var scrollTopSnapshot = this.element.scrollTop;
|
|
17294
|
+
var win = this.getVirtualWindowAt(scrollTopSnapshot);
|
|
17295
|
+
this.virtualStartIndex = win.startIndex;
|
|
17296
|
+
this.virtualEndIndex = win.endIndex;
|
|
17297
|
+
// ── Block ALL scroll-triggered re-renders during this collapse ────────────
|
|
17298
|
+
// Same as handleVirtualExpand: use preventScroll:true on the focus() call
|
|
17299
|
+
// below so the second potential scroll event is never fired.
|
|
17300
|
+
this.virtualSkipNextScrollRender = true;
|
|
17301
|
+
this.renderVirtualItems();
|
|
17302
|
+
// renderVirtualItems() replaces all <li> elements so the old icon element that
|
|
17303
|
+
// had the PROCESS class is gone. Remove PROCESS from the newly rendered icon
|
|
17304
|
+
// so the node can be expanded/collapsed again without being blocked.
|
|
17305
|
+
var newLi = this.getElement(id);
|
|
17306
|
+
if (newLi) {
|
|
17307
|
+
var icon = select('.' + ICON, newLi);
|
|
17308
|
+
if (icon) {
|
|
17309
|
+
removeClass([icon], PROCESS);
|
|
17310
|
+
}
|
|
17311
|
+
// ── Use preventScroll:true to avoid consuming virtualSkipNextScrollRender ─
|
|
17312
|
+
newLi.focus({ preventScroll: true });
|
|
17313
|
+
}
|
|
17314
|
+
if (this.isLoaded) {
|
|
17315
|
+
var currLi = this.getElement(id);
|
|
17316
|
+
if (currLi) {
|
|
17317
|
+
var colArgs = this.getExpandEvent(currLi, null);
|
|
17318
|
+
colArgs.isInteracted = this.isInteracted;
|
|
17319
|
+
this.trigger('nodeCollapsed', colArgs);
|
|
17320
|
+
}
|
|
17321
|
+
}
|
|
17322
|
+
};
|
|
17323
|
+
/**
|
|
17324
|
+
* Updates the selected state of a node in `virtualFlatNodes` and re-renders the window.
|
|
17325
|
+
*
|
|
17326
|
+
* @param {string} id - The `data-uid` of the target node.
|
|
17327
|
+
* @param {boolean} isSelected - Whether the node is now selected.
|
|
17328
|
+
* @returns {void}
|
|
17329
|
+
* @private
|
|
17330
|
+
*/
|
|
17331
|
+
TreeView.prototype.updateVirtualNodeSelection = function (id, isSelected) {
|
|
17332
|
+
var idx = this.virtualNodeMap.get(id);
|
|
17333
|
+
if (!isNullOrUndefined(idx)) {
|
|
17334
|
+
this.virtualFlatNodes[parseInt(idx.toString(), 10)].isSelected = isSelected;
|
|
17335
|
+
this.renderVirtualItems();
|
|
17336
|
+
}
|
|
17337
|
+
};
|
|
17338
|
+
/**
|
|
17339
|
+
* Updates the checkbox state of a node in `virtualFlatNodes` and re-renders the window.
|
|
17340
|
+
*
|
|
17341
|
+
* @param {string} id - The `data-uid` of the target node.
|
|
17342
|
+
* @param {'check' | 'uncheck' | 'indeterminate'} state - The new check state.
|
|
17343
|
+
* @returns {void}
|
|
17344
|
+
* @private
|
|
17345
|
+
*/
|
|
17346
|
+
TreeView.prototype.updateVirtualNodeCheckState = function (id, state) {
|
|
17347
|
+
var idx = this.virtualNodeMap.get(id);
|
|
17348
|
+
if (!isNullOrUndefined(idx)) {
|
|
17349
|
+
this.virtualFlatNodes[parseInt(idx.toString(), 10)].isChecked =
|
|
17350
|
+
state === 'check' ? true : state === 'indeterminate' ? 'indeterminate' : false;
|
|
17351
|
+
// Keep the persistent indeterminate set in sync so flattenVisibleNodes()
|
|
17352
|
+
// correctly restores state after any full list rebuild (e.g. collapse).
|
|
17353
|
+
if (state === 'indeterminate') {
|
|
17354
|
+
this.virtualIndeterminateNodesSet.add(id);
|
|
17355
|
+
}
|
|
17356
|
+
else {
|
|
17357
|
+
this.virtualIndeterminateNodesSet.delete(id);
|
|
17358
|
+
}
|
|
17359
|
+
this.renderVirtualItems();
|
|
17360
|
+
}
|
|
17361
|
+
};
|
|
17362
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
17363
|
+
// END VIRTUALIZATION
|
|
17364
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
15983
17365
|
/**
|
|
15984
17366
|
* Called internally if any of the property value changed.
|
|
15985
17367
|
*
|
|
@@ -16117,6 +17499,33 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
16117
17499
|
this.listBaseOption.itemNavigable = newProp.fullRowNavigable;
|
|
16118
17500
|
this.reRenderNodes();
|
|
16119
17501
|
break;
|
|
17502
|
+
case 'enableVirtualization':
|
|
17503
|
+
if (this.enableVirtualization) {
|
|
17504
|
+
if (!isNullOrUndefined(this.height)) {
|
|
17505
|
+
this.initVirtualization();
|
|
17506
|
+
}
|
|
17507
|
+
}
|
|
17508
|
+
else {
|
|
17509
|
+
// Tear down virtualization and do a full re-render
|
|
17510
|
+
this.unwireVirtualScrollEvents();
|
|
17511
|
+
this.destroyVirtualMask();
|
|
17512
|
+
removeClass([this.element], VIRTUALIZATION);
|
|
17513
|
+
this.element.style.height = '';
|
|
17514
|
+
this.element.style.overflowY = '';
|
|
17515
|
+
this.reRenderNodes();
|
|
17516
|
+
}
|
|
17517
|
+
break;
|
|
17518
|
+
case 'height':
|
|
17519
|
+
if (this.enableVirtualization) {
|
|
17520
|
+
// Re-initialise so the new height takes effect
|
|
17521
|
+
this.unwireVirtualScrollEvents();
|
|
17522
|
+
this.initVirtualization();
|
|
17523
|
+
}
|
|
17524
|
+
else {
|
|
17525
|
+
var px = this.parseHeightToPixels();
|
|
17526
|
+
this.element.style.height = px > 0 ? px + 'px' : '';
|
|
17527
|
+
}
|
|
17528
|
+
break;
|
|
16120
17529
|
}
|
|
16121
17530
|
}
|
|
16122
17531
|
};
|
|
@@ -16126,6 +17535,13 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
16126
17535
|
* @returns {void}
|
|
16127
17536
|
*/
|
|
16128
17537
|
TreeView.prototype.destroy = function () {
|
|
17538
|
+
// Tear down virtualization before standard cleanup
|
|
17539
|
+
if (this.enableVirtualization) {
|
|
17540
|
+
this.unwireVirtualScrollEvents();
|
|
17541
|
+
this.destroyVirtualMask();
|
|
17542
|
+
this.virtualFlatNodes = [];
|
|
17543
|
+
this.virtualNodeMap.clear();
|
|
17544
|
+
}
|
|
16129
17545
|
this.clearTemplate();
|
|
16130
17546
|
this.element.removeAttribute('aria-activedescendant');
|
|
16131
17547
|
this.unWireEvents();
|
|
@@ -16210,9 +17626,25 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
16210
17626
|
if (isNullOrUndefined(fNode)) {
|
|
16211
17627
|
this.setNodeFocusable();
|
|
16212
17628
|
}
|
|
16213
|
-
|
|
16214
|
-
|
|
16215
|
-
|
|
17629
|
+
// In virtual mode (with a fixed height), rebuild the flat node list and re-render
|
|
17630
|
+
// the window so the newly added nodes appear in the correct hierarchical position.
|
|
17631
|
+
// When height is not provided, the tree uses normal rendering and the DOM is
|
|
17632
|
+
// already updated by addGivenNodes() above.
|
|
17633
|
+
if (this.enableVirtualization && !isNullOrUndefined(this.height)) {
|
|
17634
|
+
this.setRootData();
|
|
17635
|
+
this.rebuildVirtualCheckCache();
|
|
17636
|
+
this.virtualFlatNodes = this.flattenVisibleNodes();
|
|
17637
|
+
this.rebuildVirtualNodeMap();
|
|
17638
|
+
var win = this.getVirtualWindow();
|
|
17639
|
+
this.virtualStartIndex = win.startIndex;
|
|
17640
|
+
this.virtualEndIndex = win.endIndex;
|
|
17641
|
+
this.renderVirtualItems();
|
|
17642
|
+
}
|
|
17643
|
+
else {
|
|
17644
|
+
this.updateCheckedStateFromDS();
|
|
17645
|
+
if (this.showCheckBox && dropLi && this.autoCheck) {
|
|
17646
|
+
this.ensureParentCheckState(dropLi);
|
|
17647
|
+
}
|
|
16216
17648
|
}
|
|
16217
17649
|
if ((this.fields.dataSource instanceof DataManager === false)) {
|
|
16218
17650
|
this.preventExpand = false;
|
|
@@ -16257,6 +17689,25 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
16257
17689
|
* @returns {void}
|
|
16258
17690
|
*/
|
|
16259
17691
|
TreeView.prototype.collapseAll = function (nodes, level, excludeHiddenNodes) {
|
|
17692
|
+
var _this = this;
|
|
17693
|
+
if (this.enableVirtualization && !isNullOrUndefined(this.height)) {
|
|
17694
|
+
this.virtualExpandedNodesSet.clear();
|
|
17695
|
+
this.setProperties({ expandedNodes: [] }, true);
|
|
17696
|
+
var setAllCollapsed_1 = function (nodes) {
|
|
17697
|
+
if (!nodes) {
|
|
17698
|
+
return;
|
|
17699
|
+
}
|
|
17700
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
17701
|
+
var node = nodes[parseInt(i.toString(), 10)];
|
|
17702
|
+
node['isExpanded'] = false;
|
|
17703
|
+
var children = getValue(_this.fields.child.toString(), node);
|
|
17704
|
+
if (children && Array.isArray(children)) {
|
|
17705
|
+
setAllCollapsed_1(children);
|
|
17706
|
+
}
|
|
17707
|
+
}
|
|
17708
|
+
};
|
|
17709
|
+
setAllCollapsed_1(this.treeData);
|
|
17710
|
+
}
|
|
16260
17711
|
if (!isNullOrUndefined(nodes)) {
|
|
16261
17712
|
this.doGivenAction(nodes, COLLAPSIBLE, false);
|
|
16262
17713
|
}
|
|
@@ -16334,6 +17785,33 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
16334
17785
|
*/
|
|
16335
17786
|
TreeView.prototype.expandAll = function (nodes, level, excludeHiddenNodes, preventAnimation) {
|
|
16336
17787
|
this.isAnimate = !preventAnimation;
|
|
17788
|
+
if (this.enableVirtualization && !isNullOrUndefined(this.height)) {
|
|
17789
|
+
var allParentIds_1 = [];
|
|
17790
|
+
var idFieldName_1 = this.fields.id;
|
|
17791
|
+
var childFieldName = this.fields.child.toString();
|
|
17792
|
+
var isDataTypeFlat = this.dataType === 1;
|
|
17793
|
+
var processAllParents = function (nodeList) {
|
|
17794
|
+
if (!nodeList) {
|
|
17795
|
+
return;
|
|
17796
|
+
}
|
|
17797
|
+
for (var i = 0; i < nodeList.length; i++) {
|
|
17798
|
+
var node = nodeList[parseInt(i.toString(), 10)];
|
|
17799
|
+
var nodeId = getValue(idFieldName_1, node);
|
|
17800
|
+
if (node.hasChild) {
|
|
17801
|
+
allParentIds_1.push(nodeId);
|
|
17802
|
+
node.isExpanded = true;
|
|
17803
|
+
}
|
|
17804
|
+
}
|
|
17805
|
+
};
|
|
17806
|
+
processAllParents(this.treeData);
|
|
17807
|
+
for (var i = 0; i < allParentIds_1.length; i++) {
|
|
17808
|
+
var id = allParentIds_1[parseInt(i.toString(), 10)];
|
|
17809
|
+
if (!this.virtualExpandedNodesSet.has(id)) {
|
|
17810
|
+
this.virtualExpandedNodesSet.add(id);
|
|
17811
|
+
}
|
|
17812
|
+
}
|
|
17813
|
+
this.setProperties({ expandedNodes: allParentIds_1 }, true);
|
|
17814
|
+
}
|
|
16337
17815
|
if (!isNullOrUndefined(nodes)) {
|
|
16338
17816
|
this.doGivenAction(nodes, EXPANDABLE, true);
|
|
16339
17817
|
}
|
|
@@ -16636,6 +18114,12 @@ var TreeView = /** @__PURE__ @class */ (function (_super) {
|
|
|
16636
18114
|
__decorate$8([
|
|
16637
18115
|
Property(false)
|
|
16638
18116
|
], TreeView.prototype, "allowTextWrap", void 0);
|
|
18117
|
+
__decorate$8([
|
|
18118
|
+
Property(false)
|
|
18119
|
+
], TreeView.prototype, "enableVirtualization", void 0);
|
|
18120
|
+
__decorate$8([
|
|
18121
|
+
Property()
|
|
18122
|
+
], TreeView.prototype, "height", void 0);
|
|
16639
18123
|
__decorate$8([
|
|
16640
18124
|
Complex({}, NodeAnimationSettings)
|
|
16641
18125
|
], TreeView.prototype, "animation", void 0);
|