primeng
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primeng) [ • 108 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/cdk/scrolling'), require('@angular/common'), require('primeng/api'), require('primeng/utils'), require('primeng/dom'), require('primeng/ripple')) :
typeof define === 'function' && define.amd ? define('primeng/tree', ['exports', '@angular/core', '@angular/cdk/scrolling', '@angular/common', 'primeng/api', 'primeng/utils', 'primeng/dom', 'primeng/ripple'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.primeng = global.primeng || {}, global.primeng.tree = {}), global.ng.core, global.ng.cdk.scrolling, global.ng.common, global.primeng.api, global.primeng.utils, global.primeng.dom, global.primeng.ripple));
}(this, (function (exports, core, scrolling, common, api, utils, dom, ripple) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/** @deprecated */
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
function __spreadArray(to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
}
function __classPrivateFieldSet(receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
}
var UITreeNode = /** @class */ (function () {
function UITreeNode(tree) {
this.tree = tree;
}
UITreeNode.prototype.ngOnInit = function () {
this.node.parent = this.parentNode;
if (this.parentNode) {
this.tree.syncNodeOption(this.node, this.tree.value, 'parent', this.tree.getNodeWithKey(this.parentNode.key, this.tree.value));
}
};
UITreeNode.prototype.getIcon = function () {
var icon;
if (this.node.icon)
icon = this.node.icon;
else
icon = this.node.expanded && this.node.children && this.node.children.length ? this.node.expandedIcon : this.node.collapsedIcon;
return UITreeNode.ICON_CLASS + ' ' + icon;
};
UITreeNode.prototype.isLeaf = function () {
return this.tree.isNodeLeaf(this.node);
};
UITreeNode.prototype.toggle = function (event) {
if (this.node.expanded)
this.collapse(event);
else
this.expand(event);
};
UITreeNode.prototype.expand = function (event) {
this.node.expanded = true;
if (this.tree.virtualScroll) {
this.tree.updateSerializedValue();
}
this.tree.onNodeExpand.emit({ originalEvent: event, node: this.node });
};
UITreeNode.prototype.collapse = function (event) {
this.node.expanded = false;
if (this.tree.virtualScroll) {
this.tree.updateSerializedValue();
}
this.tree.onNodeCollapse.emit({ originalEvent: event, node: this.node });
};
UITreeNode.prototype.onNodeClick = function (event) {
this.tree.onNodeClick(event, this.node);
};
UITreeNode.prototype.onNodeKeydown = function (event) {
if (event.which === 13) {
this.tree.onNodeClick(event, this.node);
}
};
UITreeNode.prototype.onNodeTouchEnd = function () {
this.tree.onNodeTouchEnd();
};
UITreeNode.prototype.onNodeRightClick = function (event) {
this.tree.onNodeRightClick(event, this.node);
};
UITreeNode.prototype.isSelected = function () {
return this.tree.isSelected(this.node);
};
UITreeNode.prototype.onDropPoint = function (event, position) {
var _this = this;
event.preventDefault();
var dragNode = this.tree.dragNode;
var dragNodeIndex = this.tree.dragNodeIndex;
var dragNodeScope = this.tree.dragNodeScope;
var isValidDropPointIndex = this.tree.dragNodeTree === this.tree ? (position === 1 || dragNodeIndex !== this.index - 1) : true;
if (this.tree.allowDrop(dragNode, this.node, dragNodeScope) && isValidDropPointIndex) {
var dropParams_1 = Object.assign({}, this.createDropPointEventMetadata(position));
if (this.tree.validateDrop) {
this.tree.onNodeDrop.emit({
originalEvent: event,
dragNode: dragNode,
dropNode: this.node,
dropIndex: this.index,
accept: function () {
_this.processPointDrop(dropParams_1);
}
});
}
else {
this.processPointDrop(dropParams_1);
this.tree.onNodeDrop.emit({
originalEvent: event,
dragNode: dragNode,
dropNode: this.node,
dropIndex: this.index
});
}
}
this.draghoverPrev = false;
this.draghoverNext = false;
};
UITreeNode.prototype.processPointDrop = function (event) {
var newNodeList = event.dropNode.parent ? event.dropNode.parent.children : this.tree.value;
event.dragNodeSubNodes.splice(event.dragNodeIndex, 1);
var dropIndex = this.index;
if (event.position < 0) {
dropIndex = (event.dragNodeSubNodes === newNodeList) ? ((event.dragNodeIndex > event.index) ? event.index : event.index - 1) : event.index;
newNodeList.splice(dropIndex, 0, event.dragNode);
}
else {
dropIndex = newNodeList.length;
newNodeList.push(event.dragNode);
}
this.tree.dragDropService.stopDrag({
node: event.dragNode,
subNodes: event.dropNode.parent ? event.dropNode.parent.children : this.tree.value,
index: event.dragNodeIndex
});
};
UITreeNode.prototype.createDropPointEventMetadata = function (position) {
return {
dragNode: this.tree.dragNode,
dragNodeIndex: this.tree.dragNodeIndex,
dragNodeSubNodes: this.tree.dragNodeSubNodes,
dropNode: this.node,
index: this.index,
position: position
};
};
UITreeNode.prototype.onDropPointDragOver = function (event) {
event.dataTransfer.dropEffect = 'move';
event.preventDefault();
};
UITreeNode.prototype.onDropPointDragEnter = function (event, position) {
if (this.tree.allowDrop(this.tree.dragNode, this.node, this.tree.dragNodeScope)) {
if (position < 0)
this.draghoverPrev = true;
else
this.draghoverNext = true;
}
};
UITreeNode.prototype.onDropPointDragLeave = function (event) {
this.draghoverPrev = false;
this.draghoverNext = false;
};
UITreeNode.prototype.onDragStart = function (event) {
if (this.tree.draggableNodes && this.node.draggable !== false) {
event.dataTransfer.setData("text", "data");
this.tree.dragDropService.startDrag({
tree: this,
node: this.node,
subNodes: this.node.parent ? this.node.parent.children : this.tree.value,
index: this.index,
scope: this.tree.draggableScope
});
}
else {
event.preventDefault();
}
};
UITreeNode.prototype.onDragStop = function (event) {
this.tree.dragDropService.stopDrag({
node: this.node,
subNodes: this.node.parent ? this.node.parent.children : this.tree.value,
index: this.index
});
};
UITreeNode.prototype.onDropNodeDragOver = function (event) {
event.dataTransfer.dropEffect = 'move';
if (this.tree.droppableNodes) {
event.preventDefault();
event.stopPropagation();
}
};
UITreeNode.prototype.onDropNode = function (event) {
var _this = this;
if (this.tree.droppableNodes && this.node.droppable !== false) {
var dragNode = this.tree.dragNode;
if (this.tree.allowDrop(dragNode, this.node, this.tree.dragNodeScope)) {
var dropParams_2 = Object.assign({}, this.createDropNodeEventMetadata());
if (this.tree.validateDrop) {
this.tree.onNodeDrop.emit({
originalEvent: event,
dragNode: dragNode,
dropNode: this.node,
index: this.index,
accept: function () {
_this.processNodeDrop(dropParams_2);
}
});
}
else {
this.processNodeDrop(dropParams_2);
this.tree.onNodeDrop.emit({
originalEvent: event,
dragNode: dragNode,
dropNode: this.node,
index: this.index
});
}
}
}
event.preventDefault();
event.stopPropagation();
this.draghoverNode = false;
};
UITreeNode.prototype.createDropNodeEventMetadata = function () {
return {
dragNode: this.tree.dragNode,
dragNodeIndex: this.tree.dragNodeIndex,
dragNodeSubNodes: this.tree.dragNodeSubNodes,
dropNode: this.node
};
};
UITreeNode.prototype.processNodeDrop = function (event) {
var dragNodeIndex = event.dragNodeIndex;
event.dragNodeSubNodes.splice(dragNodeIndex, 1);
if (event.dropNode.children)
event.dropNode.children.push(event.dragNode);
else
event.dropNode.children = [event.dragNode];
this.tree.dragDropService.stopDrag({
node: event.dragNode,
subNodes: event.dropNode.parent ? event.dropNode.parent.children : this.tree.value,
index: dragNodeIndex
});
};
UITreeNode.prototype.onDropNodeDragEnter = function (event) {
if (this.tree.droppableNodes && this.node.droppable !== false && this.tree.allowDrop(this.tree.dragNode, this.node, this.tree.dragNodeScope)) {
this.draghoverNode = true;
}
};
UITreeNode.prototype.onDropNodeDragLeave = function (event) {
if (this.tree.droppableNodes) {
var rect = event.currentTarget.getBoundingClientRect();
if (event.x > rect.left + rect.width || event.x < rect.left || event.y >= Math.floor(rect.top + rect.height) || event.y < rect.top) {
this.draghoverNode = false;
}
}
};
UITreeNode.prototype.onKeyDown = function (event) {
var nodeElement = event.target.parentElement.parentElement;
if (nodeElement.nodeName !== 'P-TREENODE' || (this.tree.contextMenu && this.tree.contextMenu.containerViewChild.nativeElement.style.display === 'block')) {
return;
}
switch (event.which) {
//down arrow
case 40:
var listElement = (this.tree.droppableNodes) ? nodeElement.children[1].children[1] : nodeElement.children[0].children[1];
if (listElement && listElement.children.length > 0) {
this.focusNode(listElement.children[0]);
}
else {
var nextNodeElement = nodeElement.nextElementSibling;
if (nextNodeElement) {
this.focusNode(nextNodeElement);
}
else {
var nextSiblingAncestor = this.findNextSiblingOfAncestor(nodeElement);
if (nextSiblingAncestor) {
this.focusNode(nextSiblingAncestor);
}
}
}
event.preventDefault();
break;
//up arrow
case 38:
if (nodeElement.previousElementSibling) {
this.focusNode(this.findLastVisibleDescendant(nodeElement.previousElementSibling));
}
else {
var parentNodeElement = this.getParentNodeElement(nodeElement);
if (parentNodeElement) {
this.focusNode(parentNodeElement);
}
}
event.preventDefault();
break;
//right arrow
case 39:
if (!this.node.expanded && !this.tree.isNodeLeaf(this.node)) {
this.expand(event);
}
event.preventDefault();
break;
//left arrow
case 37:
if (this.node.expanded) {
this.collapse(event);
}
else {
var parentNodeElement = this.getParentNodeElement(nodeElement);
if (parentNodeElement) {
this.focusNode(parentNodeElement);
}
}
event.preventDefault();
break;
//enter
case 13:
this.tree.onNodeClick(event, this.node);
event.preventDefault();
break;
default:
//no op
break;
}
};
UITreeNode.prototype.findNextSiblingOfAncestor = function (nodeElement) {
var parentNodeElement = this.getParentNodeElement(nodeElement);
if (parentNodeElement) {
if (parentNodeElement.nextElementSibling)
return parentNodeElement.nextElementSibling;
else
return this.findNextSiblingOfAncestor(parentNodeElement);
}
else {
return null;
}
};
UITreeNode.prototype.findLastVisibleDescendant = function (nodeElement) {
var listElement = Array.from(nodeElement.children).find(function (el) { return dom.DomHandler.hasClass(el, 'p-treenode'); });
var childrenListElement = listElement.children[1];
if (childrenListElement && childrenListElement.children.length > 0) {
var lastChildElement = childrenListElement.children[childrenListElement.children.length - 1];
return this.findLastVisibleDescendant(lastChildElement);
}
else {
return nodeElement;
}
};
UITreeNode.prototype.getParentNodeElement = function (nodeElement) {
var parentNodeElement = nodeElement.parentElement.parentElement.parentElement;
return parentNodeElement.tagName === 'P-TREENODE' ? parentNodeElement : null;
};
UITreeNode.prototype.focusNode = function (element) {
if (this.tree.droppableNodes)
element.children[1].children[0].focus();
else
element.children[0].children[0].focus();
};
return UITreeNode;
}());
UITreeNode.ICON_CLASS = 'p-treenode-icon ';
UITreeNode.decorators = [
{ type: core.Component, args: [{
selector: 'p-treeNode',
template: "\n <ng-template [ngIf]=\"node\">\n <li *ngIf=\"tree.droppableNodes\" class=\"p-treenode-droppoint\" [ngClass]=\"{'p-treenode-droppoint-active':draghoverPrev}\"\n (drop)=\"onDropPoint($event,-1)\" (dragover)=\"onDropPointDragOver($event)\" (dragenter)=\"onDropPointDragEnter($event,-1)\" (dragleave)=\"onDropPointDragLeave($event)\"></li>\n <li *ngIf=\"!tree.horizontal\" [ngClass]=\"['p-treenode',node.styleClass||'', isLeaf() ? 'p-treenode-leaf': '']\">\n <div class=\"p-treenode-content\" [style.paddingLeft]=\"(level * indentation) + 'rem'\" (click)=\"onNodeClick($event)\" (contextmenu)=\"onNodeRightClick($event)\" (touchend)=\"onNodeTouchEnd()\"\n (drop)=\"onDropNode($event)\" (dragover)=\"onDropNodeDragOver($event)\" (dragenter)=\"onDropNodeDragEnter($event)\" (dragleave)=\"onDropNodeDragLeave($event)\"\n [draggable]=\"tree.draggableNodes\" (dragstart)=\"onDragStart($event)\" (dragend)=\"onDragStop($event)\" [attr.tabindex]=\"0\"\n [ngClass]=\"{'p-treenode-selectable':tree.selectionMode && node.selectable !== false,'p-treenode-dragover':draghoverNode, 'p-highlight':isSelected()}\" role=\"treeitem\"\n (keydown)=\"onKeyDown($event)\" [attr.aria-posinset]=\"this.index + 1\" [attr.aria-expanded]=\"this.node.expanded\" [attr.aria-selected]=\"isSelected()\" [attr.aria-label]=\"node.label\">\n <button type=\"button\" class=\"p-tree-toggler p-link\" (click)=\"toggle($event)\" pRipple tabindex=\"-1\">\n <span class=\"p-tree-toggler-icon pi pi-fw\" [ngClass]=\"{'pi-chevron-right':!node.expanded,'pi-chevron-down':node.expanded}\"></span>\n </button>\n <div class=\"p-checkbox p-component\" [ngClass]=\"{'p-checkbox-disabled': node.selectable === false}\" *ngIf=\"tree.selectionMode == 'checkbox'\" [attr.aria-checked]=\"isSelected()\">\n <div class=\"p-checkbox-box\" [ngClass]=\"{'p-highlight': isSelected(), 'p-indeterminate': node.partialSelected}\">\n <span class=\"p-checkbox-icon pi\" [ngClass]=\"{'pi-check':isSelected(),'pi-minus':node.partialSelected}\"></span>\n </div>\n </div>\n <span [class]=\"getIcon()\" *ngIf=\"node.icon||node.expandedIcon||node.collapsedIcon\"></span>\n <span class=\"p-treenode-label\">\n <span *ngIf=\"!tree.getTemplateForNode(node)\">{{node.label}}</span>\n <span *ngIf=\"tree.getTemplateForNode(node)\">\n <ng-container *ngTemplateOutlet=\"tree.getTemplateForNode(node); context: {$implicit: node}\"></ng-container>\n </span>\n </span>\n </div>\n <ul class=\"p-treenode-children\" style=\"display: none;\" *ngIf=\"!tree.virtualScroll && node.children && node.expanded\" [style.display]=\"node.expanded ? 'block' : 'none'\" role=\"group\">\n <p-treeNode *ngFor=\"let childNode of node.children;let firstChild=first;let lastChild=last; let index=index; trackBy: tree.trackBy\" [node]=\"childNode\" [parentNode]=\"node\"\n [firstChild]=\"firstChild\" [lastChild]=\"lastChild\" [index]=\"index\" [style.height.px]=\"tree.virtualNodeHeight\" [level]=\"level + 1\"></p-treeNode>\n </ul>\n </li>\n <li *ngIf=\"tree.droppableNodes&&lastChild\" class=\"p-treenode-droppoint\" [ngClass]=\"{'p-treenode-droppoint-active':draghoverNext}\"\n (drop)=\"onDropPoint($event,1)\" (dragover)=\"onDropPointDragOver($event)\" (dragenter)=\"onDropPointDragEnter($event,1)\" (dragleave)=\"onDropPointDragLeave($event)\"></li>\n <table *ngIf=\"tree.horizontal\" [class]=\"node.styleClass\">\n <tbody>\n <tr>\n <td class=\"p-treenode-connector\" *ngIf=\"!root\">\n <table class=\"p-treenode-connector-table\">\n <tbody>\n <tr>\n <td [ngClass]=\"{'p-treenode-connector-line':!firstChild}\"></td>\n </tr>\n <tr>\n <td [ngClass]=\"{'p-treenode-connector-line':!lastChild}\"></td>\n </tr>\n </tbody>\n </table>\n </td>\n <td class=\"p-treenode\" [ngClass]=\"{'p-treenode-collapsed':!node.expanded}\">\n <div class=\"p-treenode-content\" tabindex=\"0\" [ngClass]=\"{'p-treenode-selectable':tree.selectionMode,'p-highlight':isSelected()}\" (click)=\"onNodeClick($event)\" (contextmenu)=\"onNodeRightClick($event)\"\n (touchend)=\"onNodeTouchEnd()\" (keydown)=\"onNodeKeydown($event)\">\n <span class=\"p-tree-toggler pi pi-fw\" [ngClass]=\"{'pi-plus':!node.expanded,'pi-minus':node.expanded}\" *ngIf=\"!isLeaf()\" (click)=\"toggle($event)\"></span>\n <span [class]=\"getIcon()\" *ngIf=\"node.icon||node.expandedIcon||node.collapsedIcon\"></span>\n <span class=\"p-treenode-label\">\n <span *ngIf=\"!tree.getTemplateForNode(node)\">{{node.label}}</span>\n <span *ngIf=\"tree.getTemplateForNode(node)\">\n <ng-container *ngTemplateOutlet=\"tree.getTemplateForNode(node); context: {$implicit: node}\"></ng-container>\n </span>\n </span>\n </div>\n </td>\n <td class=\"p-treenode-children-container\" *ngIf=\"node.children && node.expanded\" [style.display]=\"node.expanded ? 'table-cell' : 'none'\">\n <div class=\"p-treenode-children\">\n <p-treeNode *ngFor=\"let childNode of node.children;let firstChild=first;let lastChild=last; trackBy: tree.trackBy\" [node]=\"childNode\"\n [firstChild]=\"firstChild\" [lastChild]=\"lastChild\"></p-treeNode>\n </div>\n </td>\n </tr>\n </tbody>\n </table>\n </ng-template>\n ",
encapsulation: core.ViewEncapsulation.None
},] }
];
UITreeNode.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return Tree; }),] }] }
]; };
UITreeNode.propDecorators = {
rowNode: [{ type: core.Input }],
node: [{ type: core.Input }],
parentNode: [{ type: core.Input }],
root: [{ type: core.Input }],
index: [{ type: core.Input }],
firstChild: [{ type: core.Input }],
lastChild: [{ type: core.Input }],
level: [{ type: core.Input }],
indentation: [{ type: core.Input }]
};
var Tree = /** @class */ (function () {
function Tree(el, dragDropService) {
this.el = el;
this.dragDropService = dragDropService;
this.selectionChange = new core.EventEmitter();
this.onNodeSelect = new core.EventEmitter();
this.onNodeUnselect = new core.EventEmitter();
this.onNodeExpand = new core.EventEmitter();
this.onNodeCollapse = new core.EventEmitter();
this.onNodeContextMenuSelect = new core.EventEmitter();
this.onNodeDrop = new core.EventEmitter();
this.layout = 'vertical';
this.metaKeySelection = true;
this.propagateSelectionUp = true;
this.propagateSelectionDown = true;
this.loadingIcon = 'pi pi-spinner';
this.emptyMessage = 'No records found';
this.filterBy = 'label';
this.filterMode = 'lenient';
this.indentation = 1.5;
this.trackBy = function (index, item) { return item; };
this.onFilter = new core.EventEmitter();
}
Tree.prototype.ngOnInit = function () {
var _this = this;
if (this.droppableNodes) {
this.dragStartSubscription = this.dragDropService.dragStart$.subscribe(function (event) {
_this.dragNodeTree = event.tree;
_this.dragNode = event.node;
_this.dragNodeSubNodes = event.subNodes;
_this.dragNodeIndex = event.index;
_this.dragNodeScope = event.scope;
});
this.dragStopSubscription = this.dragDropService.dragStop$.subscribe(function (event) {
_this.dragNodeTree = null;
_this.dragNode = null;
_this.dragNodeSubNodes = null;
_this.dragNodeIndex = null;
_this.dragNodeScope = null;
_this.dragHover = false;
});
}
};
Tree.prototype.ngOnChanges = function (simpleChange) {
if (simpleChange.value) {
this.updateSerializedValue();
}
if (simpleChange.scrollHeight && this.virtualScrollBody) {
this.virtualScrollBody.ngOnInit();
}
};
Object.defineProperty(Tree.prototype, "horizontal", {
get: function () {
return this.layout == 'horizontal';
},
enumerable: false,
configurable: true
});
Tree.prototype.ngAfterContentInit = function () {
var _this = this;
if (this.templates.length) {
this.templateMap = {};
}
this.templates.forEach(function (item) {
_this.templateMap[item.name] = item.template;
});
};
Tree.prototype.updateSerializedValue = function () {
this.serializedValue = [];
this.serializeNodes(null, this.getRootNode(), 0, true);
};
Tree.prototype.serializeNodes = function (parent, nodes, level, visible) {
var e_1, _a;
if (nodes && nodes.length) {
try {
for (var nodes_1 = __values(nodes), nodes_1_1 = nodes_1.next(); !nodes_1_1.done; nodes_1_1 = nodes_1.next()) {
var node = nodes_1_1.value;
node.parent = parent;
var rowNode = {
node: node,
parent: parent,
level: level,
visible: visible && (parent ? parent.expanded : true)
};
this.serializedValue.push(rowNode);
if (rowNode.visible && node.expanded) {
this.serializeNodes(node, node.children, level + 1, rowNode.visible);
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (nodes_1_1 && !nodes_1_1.done && (_a = nodes_1.return)) _a.call(nodes_1);
}
finally { if (e_1) throw e_1.error; }
}
}
};
Tree.prototype.onNodeClick = function (event, node) {
var eventTarget = event.target;
if (dom.DomHandler.hasClass(eventTarget, 'p-tree-toggler') || dom.DomHandler.hasClass(eventTarget, 'p-tree-toggler-icon')) {
return;
}
else if (this.selectionMode) {
if (node.selectable === false) {
return;
}
if (this.hasFilteredNodes()) {
node = this.getNodeWithKey(node.key, this.value);
if (!node) {
return;
}
}
var index_1 = this.findIndexInSelection(node);
var selected = (index_1 >= 0);
if (this.isCheckboxSelectionMode()) {
if (selected) {
if (this.propagateSelectionDown)
this.propagateDown(node, false);
else
this.selection = this.selection.filter(function (val, i) { return i != index_1; });
if (this.propagateSelectionUp && node.parent) {
this.propagateUp(node.parent, false);
}
this.selectionChange.emit(this.selection);
this.onNodeUnselect.emit({ originalEvent: event, node: node });
}
else {
if (this.propagateSelectionDown)
this.propagateDown(node, true);
else
this.selection = __spread(this.selection || [], [node]);
if (this.propagateSelectionUp && node.parent) {
this.propagateUp(node.parent, true);
}
this.selectionChange.emit(this.selection);
this.onNodeSelect.emit({ originalEvent: event, node: node });
}
}
else {
var metaSelection = this.nodeTouched ? false : this.metaKeySelection;
if (metaSelection) {
var metaKey = (event.metaKey || event.ctrlKey);
if (selected && metaKey) {
if (this.isSingleSelectionMode()) {
this.selectionChange.emit(null);
}
else {
this.selection = this.selection.filter(function (val, i) { return i != index_1; });
this.selectionChange.emit(this.selection);
}
this.onNodeUnselect.emit({ originalEvent: event, node: node });
}
else {
if (this.isSingleSelectionMode()) {
this.selectionChange.emit(node);
}
else if (this.isMultipleSelectionMode()) {
this.selection = (!metaKey) ? [] : this.selection || [];
this.selection = __spread(this.selection, [node]);
this.selectionChange.emit(this.selection);
}
this.onNodeSelect.emit({ originalEvent: event, node: node });
}
}
else {
if (this.isSingleSelectionMode()) {
if (selected) {
this.selection = null;
this.onNodeUnselect.emit({ originalEvent: event, node: node });
}
else {
this.selection = node;
this.onNodeSelect.emit({ originalEvent: event, node: node });
}
}
else {
if (selected) {
this.selection = this.selection.filter(function (val, i) { return i != index_1; });
this.onNodeUnselect.emit({ originalEvent: event, node: node });
}
else {
this.selection = __spread(this.selection || [], [node]);
this.onNodeSelect.emit({ originalEvent: event, node: node });
}
}
this.selectionChange.emit(this.selection);
}
}
}
this.nodeTouched = false;
};
Tree.prototype.onNodeTouchEnd = function () {
this.nodeTouched = true;
};
Tree.prototype.onNodeRightClick = function (event, node) {
if (this.contextMenu) {
var eventTarget = event.target;
if (eventTarget.className && eventTarget.className.indexOf('p-tree-toggler') === 0) {
return;
}
else {
var index = this.findIndexInSelection(node);
var selected = (index >= 0);
if (!selected) {
if (this.isSingleSelectionMode())
this.selectionChange.emit(node);
else
this.selectionChange.emit([node]);
}
this.contextMenu.show(event);
this.onNodeContextMenuSelect.emit({ originalEvent: event, node: node });
}
}
};
Tree.prototype.findIndexInSelection = function (node) {
var index = -1;
if (this.selectionMode && this.selection) {
if (this.isSingleSelectionMode()) {
var areNodesEqual = (this.selection.key && this.selection.key === node.key) || this.selection == node;
index = areNodesEqual ? 0 : -1;
}
else {
for (var i = 0; i < this.selection.length; i++) {
var selectedNode = this.selection[i];
var areNodesEqual = (selectedNode.key && selectedNode.key === node.key) || selectedNode == node;
if (areNodesEqual) {
index = i;
break;
}
}
}
}
return index;
};
Tree.prototype.syncNodeOption = function (node, parentNodes, option, value) {
// to synchronize the node option between the filtered nodes and the original nodes(this.value)
var _node = this.hasFilteredNodes() ? this.getNodeWithKey(node.key, parentNodes) : null;
if (_node) {
_node[option] = value || node[option];
}
};
Tree.prototype.hasFilteredNodes = function () {
return this.filter && this.filteredNodes && this.filteredNodes.length;
};
Tree.prototype.getNodeWithKey = function (key, nodes) {
var e_2, _a;
try {
for (var nodes_2 = __values(nodes), nodes_2_1 = nodes_2.next(); !nodes_2_1.done; nodes_2_1 = nodes_2.next()) {
var node = nodes_2_1.value;
if (node.key === key) {
return node;
}
if (node.children) {
var matchedNode = this.getNodeWithKey(key, node.children);
if (matchedNode) {
return matchedNode;
}
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (nodes_2_1 && !nodes_2_1.done && (_a = nodes_2.return)) _a.call(nodes_2);
}
finally { if (e_2) throw e_2.error; }
}
};
Tree.prototype.propagateUp = function (node, select) {
var e_3, _a;
if (node.children && node.children.length) {
var selectedCount = 0;
var childPartialSelected = false;
try {
for (var _b = __values(node.children), _c = _b.next(); !_c.done; _c = _b.next()) {
var child = _c.value;
if (this.isSelected(child)) {