UNPKG

@duoduo-oba/ng-devui

Version:

DevUI components based on Angular

1,353 lines (1,325 loc) 113 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('@angular/forms'), require('ng-devui/checkbox'), require('ng-devui/loading'), require('lodash-es'), require('ng-devui/utils'), require('ng-devui/i18n'), require('ng-devui/popover')) : typeof define === 'function' && define.amd ? define('ng-devui/tree', ['exports', '@angular/common', '@angular/core', '@angular/forms', 'ng-devui/checkbox', 'ng-devui/loading', 'lodash-es', 'ng-devui/utils', 'ng-devui/i18n', 'ng-devui/popover'], factory) : (global = global || self, factory((global['ng-devui'] = global['ng-devui'] || {}, global['ng-devui'].tree = {}), global.ng.common, global.ng.core, global.ng.forms, global['ng-devui'].checkbox, global['ng-devui'].loading, global.lodashEs, global['ng-devui'].utils, global['ng-devui'].i18n, global['ng-devui'].popover)); }(this, (function (exports, common, core, forms, checkbox, loading, lodashEs, utils, i18n, popover) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { 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) { 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) : new P(function (resolve) { resolve(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 }; } } function __exportStar(m, exports) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } function __values(o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; } 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; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } 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 __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; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result.default = mod; return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } /** * @fileoverview added by tsickle * Generated from: tree-factory.class.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function ITreeNodeData() { } if (false) { /** @type {?|undefined} */ ITreeNodeData.prototype.id; /** @type {?|undefined} */ ITreeNodeData.prototype.parentId; /** @type {?|undefined} */ ITreeNodeData.prototype.title; /** @type {?|undefined} */ ITreeNodeData.prototype.isOpen; /** @type {?|undefined} */ ITreeNodeData.prototype.data; /** @type {?|undefined} */ ITreeNodeData.prototype.isParent; /** @type {?|undefined} */ ITreeNodeData.prototype.loading; /** @type {?|undefined} */ ITreeNodeData.prototype.isMatch; /** @type {?|undefined} */ ITreeNodeData.prototype.isHide; /** @type {?|undefined} */ ITreeNodeData.prototype.isActive; /** @type {?|undefined} */ ITreeNodeData.prototype.isChecked; /** @type {?|undefined} */ ITreeNodeData.prototype.disabled; /** @type {?|undefined} */ ITreeNodeData.prototype.children; /* Skipping unhandled member: [prop: string]: any;*/ } /** * @record */ function ITreeMap() { } /** * @record */ function ITreeItem() { } if (false) { /** @type {?} */ ITreeItem.prototype.title; /** @type {?|undefined} */ ITreeItem.prototype.open; /** @type {?|undefined} */ ITreeItem.prototype.loading; /** @type {?|undefined} */ ITreeItem.prototype.isMatch; /** @type {?|undefined} */ ITreeItem.prototype.items; /** @type {?|undefined} */ ITreeItem.prototype.isParent; /** @type {?|undefined} */ ITreeItem.prototype.data; /** @type {?|undefined} */ ITreeItem.prototype.id; /** @type {?|undefined} */ ITreeItem.prototype.isHide; /** @type {?|undefined} */ ITreeItem.prototype.isActive; /** @type {?|undefined} */ ITreeItem.prototype.isChecked; /** @type {?|undefined} */ ITreeItem.prototype.halfChecked; /** @type {?|undefined} */ ITreeItem.prototype.disabled; /** @type {?|undefined} */ ITreeItem.prototype.disableAdd; /** @type {?|undefined} */ ITreeItem.prototype.disableEdit; /** @type {?|undefined} */ ITreeItem.prototype.disableDelete; /* Skipping unhandled member: [prop: string]: any;*/ } /** * @record */ function ITreeInput() { } if (false) { /** @type {?} */ ITreeInput.prototype.treeItems; /** @type {?|undefined} */ ITreeInput.prototype.parentId; /** @type {?|undefined} */ ITreeInput.prototype.treeNodeChildrenKey; /** @type {?|undefined} */ ITreeInput.prototype.treeNodeIdKey; /** @type {?|undefined} */ ITreeInput.prototype.checkboxDisabledKey; /** @type {?|undefined} */ ITreeInput.prototype.treeNodeTitleKey; } var TreeNode = /** @class */ (function () { function TreeNode(id, parentId, data) { this.id = id; this.parentId = parentId; this.data = data; } return TreeNode; }()); if (false) { /** @type {?} */ TreeNode.prototype.id; /** @type {?} */ TreeNode.prototype.parentId; /** @type {?} */ TreeNode.prototype.data; } var TreeFactory = /** @class */ (function () { function TreeFactory() { var _this = this; this._checked = new Set(); this._treeRoot = []; this.mapTreeItems = (/** * @template THIS * @this {THIS} * @param {?} __0 * @return {THIS} */ function (_a) { var treeItems = _a.treeItems, parentId = _a.parentId, _b = _a.treeNodeChildrenKey, treeNodeChildrenKey = _b === void 0 ? 'items' : _b, _c = _a.treeNodeIdKey, treeNodeIdKey = _c === void 0 ? 'id' : _c, _d = _a.checkboxDisabledKey, checkboxDisabledKey = _d === void 0 ? 'disabled' : _d, _e = _a.treeNodeTitleKey, treeNodeTitleKey = _e === void 0 ? 'title' : _e; lodashEs.forEach(treeItems, (/** * @param {?} item * @return {?} */ function (item) { /** @type {?} */ var node = _this.addNode({ id: item[treeNodeIdKey], parentId: parentId, title: item[treeNodeTitleKey], isOpen: !!item.open, data: item.data || {}, originItem: item, isParent: !!item.isParent || !!(item[treeNodeChildrenKey] && item[treeNodeChildrenKey].length > 0), loading: !!item.loading, isMatch: !!item.isMatch, isHide: !!item.isHide, isChecked: !!item.isChecked, halfChecked: !!item.halfChecked, isActive: !!item.isActive, disabled: !!item[checkboxDisabledKey], disableAdd: !!item.disableAdd, disableEdit: !!item.disableEdit, disableDelete: !!item.disableDelete, children: [] }); if (!!item.isChecked) { _this._checked.add(node); } _this.mapTreeItems({ treeItems: item[treeNodeChildrenKey] || [], parentId: node.id, treeNodeChildrenKey: treeNodeChildrenKey, treeNodeIdKey: treeNodeIdKey, checkboxDisabledKey: checkboxDisabledKey, treeNodeTitleKey: treeNodeTitleKey }); })); return _this; }); this.idx = 0; this.nodes = {}; } /** * @return {?} */ TreeFactory.create = /** * @return {?} */ function () { return new TreeFactory(); }; // tree model with items // tree model with items /** * @param {?} __0 * @return {?} */ TreeFactory.fromTree = // tree model with items /** * @param {?} __0 * @return {?} */ function (_a) { var treeItems = _a.treeItems, _b = _a.treeNodeChildrenKey, treeNodeChildrenKey = _b === void 0 ? 'items' : _b, _c = _a.treeNodeIdKey, treeNodeIdKey = _c === void 0 ? 'id' : _c, _d = _a.checkboxDisabledKey, checkboxDisabledKey = _d === void 0 ? 'disabled' : _d, _e = _a.treeNodeTitleKey, treeNodeTitleKey = _e === void 0 ? 'title' : _e; /** @type {?} */ var treeFactory = TreeFactory.create(); treeFactory.mapTreeItems({ treeItems: treeItems, parentId: undefined, treeNodeChildrenKey: treeNodeChildrenKey, treeNodeIdKey: treeNodeIdKey, checkboxDisabledKey: checkboxDisabledKey, treeNodeTitleKey: treeNodeTitleKey }); return treeFactory; }; /** * @param {?} __0 * @return {?} */ TreeFactory.prototype.addNode = /** * @param {?} __0 * @return {?} */ function (_a) { var _b; var id = _a.id, parentId = _a.parentId, data = __rest(_a, ["id", "parentId"]); if (lodashEs.isUndefined(id)) { this.idx++; id = this.idx; } /** @type {?} */ var treeNode = new TreeNode(id, parentId, data); if (this.nodes.hasOwnProperty(treeNode.id)) { throw new Error("Duplicated id: " + treeNode.id + " detected, please specify unique ids in the tree."); } this.nodes = __assign({}, this.nodes, (_b = {}, _b[treeNode.id] = treeNode, _b)); this.addChildNode(this.nodes[parentId], treeNode); return treeNode; }; /** * @param {?} id * @return {?} */ TreeFactory.prototype.editNodeTitle = /** * @param {?} id * @return {?} */ function (id) { this.nodes[id].data.editable = true; }; /** * @template THIS * @this {THIS} * @param {?} id * @return {THIS} */ TreeFactory.prototype.deleteNodeById = /** * @template THIS * @this {THIS} * @param {?} id * @return {THIS} */ function (id) { var _this = this; /** @type {?} */ var node = (/** @type {?} */ (this)).nodes[id]; /** @type {?} */ var parentNode = (/** @type {?} */ (this)).nodes[node.parentId]; (/** @type {?} */ (this)).removeChildNode(parentNode, node); /** @type {?} */ var deleteItems = (/** * @param {?} nodeId * @return {?} */ function (nodeId) { /** @type {?} */ var children = (/** @type {?} */ (_this)).getChildrenById(nodeId); (/** @type {?} */ (_this)).nodes = lodashEs.omitBy((/** @type {?} */ (_this)).nodes, (/** * @param {?} _node * @return {?} */ function (_node) { return _node.id === id; })); lodashEs.forEach(children, (/** * @param {?} child * @return {?} */ function (child) { deleteItems(child.id); })); }); deleteItems(id); if (parentNode && (!parentNode.data.children || !parentNode.data.children.length)) { parentNode.data.isParent = false; } return (/** @type {?} */ (this)); }; /** * @template THIS * @this {THIS} * @param {?} id * @return {THIS} */ TreeFactory.prototype.toggleNodeById = /** * @template THIS * @this {THIS} * @param {?} id * @return {THIS} */ function (id) { (/** @type {?} */ (this)).nodes[id].data.isOpen = !(/** @type {?} */ (this)).nodes[id].data.isOpen; return (/** @type {?} */ (this)); }; /** * @template THIS * @this {THIS} * @param {?} id * @return {THIS} */ TreeFactory.prototype.openNodesById = /** * @template THIS * @this {THIS} * @param {?} id * @return {THIS} */ function (id) { (/** @type {?} */ (this)).nodes[id].data.isOpen = true; if ((/** @type {?} */ (this)).nodes[id].parentId !== undefined) { (/** @type {?} */ (this)).openNodesById((/** @type {?} */ (this)).nodes[id].parentId); } return (/** @type {?} */ (this)); }; /** * @template THIS * @this {THIS} * @param {?} id * @param {?=} closeChildren * @return {THIS} */ TreeFactory.prototype.closeNodesById = /** * @template THIS * @this {THIS} * @param {?} id * @param {?=} closeChildren * @return {THIS} */ function (id, closeChildren) { var _this = this; if (closeChildren === void 0) { closeChildren = false; } (/** @type {?} */ (this)).nodes[id].data.isOpen = false; if (closeChildren) { if ((/** @type {?} */ (this)).nodes[id] && (/** @type {?} */ (this)).nodes[id].data.children) { (/** @type {?} */ (this)).nodes[id].data.children.forEach((/** * @param {?} node * @return {?} */ function (node) { (/** @type {?} */ (_this)).closeNodesById(node.id); })); } } return (/** @type {?} */ (this)); }; /** * @template THIS * @this {THIS} * @param {?} id * @return {THIS} */ TreeFactory.prototype.disabledNodesById = /** * @template THIS * @this {THIS} * @param {?} id * @return {THIS} */ function (id) { var _this = this; (/** @type {?} */ (this)).nodes[id].data.disabled = true; /** @type {?} */ var parentId = (/** @type {?} */ (this)).nodes[id].parentId; (/** @type {?} */ (this))._disabledParentNodes(parentId); /** @type {?} */ var disabledNodes = (/** * @param {?} nodeId * @return {?} */ function (nodeId) { /** @type {?} */ var children = (/** @type {?} */ (_this)).getChildrenById(nodeId); if (children.length > 0) { children.forEach((/** * @param {?} child * @return {?} */ function (child) { (/** @type {?} */ (_this)).nodes[child.id].data.disabled = true; disabledNodes(child.id); })); } }); disabledNodes(id); return (/** @type {?} */ (this)); }; /** * @private * @param {?} parentId * @return {?} */ TreeFactory.prototype._disabledParentNodes = /** * @private * @param {?} parentId * @return {?} */ function (parentId) { /** @type {?} */ var children = this.getChildrenById(parentId); if (children.length < 1) { return; } /** @type {?} */ var result = lodashEs.reduce(children, (/** * @param {?} status * @param {?} child * @return {?} */ function (status, child) { return status && child.data.disabled; }), true); if (this.nodes[parentId]) { this.nodes[parentId].data.disabled = result; } }; /** * @param {?} id * @param {?} checked * @return {?} */ TreeFactory.prototype.checkNodesById = /** * @param {?} id * @param {?} checked * @return {?} */ function (id, checked) { this.nodes[id].data.halfChecked = false; this.nodes[id].data.isChecked = checked; this.checkParentNodes(this.nodes[id]); this.checkChildNodes(this.nodes[id], checked); this.maintainCheckedNodeList(this.nodes[id], checked); return this.getCheckedNodes(); }; /** * @private * @param {?} node * @return {?} */ TreeFactory.prototype.checkParentNodes = /** * @private * @param {?} node * @return {?} */ function (node) { var parentId = node.parentId; /** @type {?} */ var parentNode = this.nodes[parentId]; if (parentNode) { /** @type {?} */ var childrenNode = this.getChildrenById(parentId); if (childrenNode.every((/** * @param {?} childNode * @return {?} */ function (childNode) { return childNode.data.isChecked && !childNode.data.halfChecked; }))) { parentNode.data.isChecked = true; parentNode.data.halfChecked = false; } else if (childrenNode.some((/** * @param {?} childNode * @return {?} */ function (childNode) { return childNode.data.halfChecked || childNode.data.isChecked; }))) { parentNode.data.isChecked = true; parentNode.data.halfChecked = true; } else { parentNode.data.isChecked = false; parentNode.data.halfChecked = false; } this.maintainCheckedNodeList(parentNode, parentNode.data.isChecked); this.checkParentNodes(parentNode); } }; /** * @private * @param {?} node * @param {?} checked * @return {?} */ TreeFactory.prototype.checkChildNodes = /** * @private * @param {?} node * @param {?} checked * @return {?} */ function (node, checked) { var _this = this; var id = node.id; /** @type {?} */ var childrenNode = this.getChildrenById(id); if (childrenNode.length > 0) { childrenNode.forEach((/** * @param {?} childNode * @return {?} */ function (childNode) { var childId = childNode.id; var nodeData = _this.nodes[childId].data; if (!nodeData.disabled) { nodeData.isChecked = checked; nodeData.halfChecked = false; _this.maintainCheckedNodeList(childNode, checked); } _this.checkChildNodes(childNode, checked); })); /** @type {?} */ var childrenFullCheckedCount = childrenNode.filter((/** * @param {?} __0 * @return {?} */ function (_a) { var nodeData = _a.data; return nodeData.isChecked; })).length; /** @type {?} */ var childrenCheckedCount = childrenNode .filter((/** * @param {?} __0 * @return {?} */ function (_a) { var nodeData = _a.data; return nodeData.isChecked || nodeData.halfChecked; })).length; node.data.halfChecked = childrenCheckedCount > 0 && childrenNode.length > childrenFullCheckedCount; } }; /** * @return {?} */ TreeFactory.prototype.getCheckedNodes = /** * @return {?} */ function () { return Array.from(this._checked); }; /** * @return {?} */ TreeFactory.prototype.getDisabledNodes = /** * @return {?} */ function () { /** @type {?} */ var results = lodashEs.pickBy(this.nodes, (/** * @param {?} node * @return {?} */ function (node) { return node.data.disabled === true; })); return lodashEs.values(results); }; /** * @param {?} id * @return {?} */ TreeFactory.prototype.activeNodeById = /** * @param {?} id * @return {?} */ function (id) { this.deactivateAllNodes(); this.nodes[id].data.isActive = !this.nodes[id].data.isActive; }; /** * @param {?} id * @return {?} */ TreeFactory.prototype.getChildrenById = /** * @param {?} id * @return {?} */ function (id) { if (this.nodes[id]) { return this.nodes[id].data.children || []; } else if (id === undefined) { return this._treeRoot; } return []; }; /* * @deprecated * */ /* * @deprecated * */ /** * @private * @return {?} */ TreeFactory.prototype.toTree = /* * @deprecated * */ /** * @private * @return {?} */ function () { var _this = this; /** @type {?} */ var patchChildren = (/** * @param {?} nodes * @return {?} */ function (nodes) { return lodashEs.map(nodes, (/** * @param {?} node * @return {?} */ function (node) { return __assign({}, node, { children: patchChildren(_this.getChildrenById(node.id)) }); })); }); return patchChildren(this.getChildrenById(undefined)); }; /** * @param {?} id * @return {?} */ TreeFactory.prototype.startLoading = /** * @param {?} id * @return {?} */ function (id) { this.nodes[id].data.loading = true; }; /** * @param {?} id * @return {?} */ TreeFactory.prototype.endLoading = /** * @param {?} id * @return {?} */ function (id) { this.nodes[id].data.loading = false; }; /* * @deprecated */ /* * @deprecated */ /** * @private * @param {?} inputValue * @param {?=} hideUnmatched * @return {?} */ TreeFactory.prototype.isMatchNode = /* * @deprecated */ /** * @private * @param {?} inputValue * @param {?=} hideUnmatched * @return {?} */ function (inputValue, hideUnmatched) { /** @type {?} */ var target = lodashEs.trim(inputValue); this.resetSearchResults(); this.dfs(target.toLowerCase(), this._treeRoot, hideUnmatched); }; /** * @param {?} id * @return {?} */ TreeFactory.prototype.getNodeById = /** * @param {?} id * @return {?} */ function (id) { return this.nodes[id].data; }; /** * @template THIS * @this {THIS} * @param {?} id * @param {?} hide * @return {THIS} */ TreeFactory.prototype.hideNodeById = /** * @template THIS * @this {THIS} * @param {?} id * @param {?} hide * @return {THIS} */ function (id, hide) { (/** @type {?} */ (this)).nodes[id].data.isHide = hide; return (/** @type {?} */ (this)); }; /** * @private * @param {?} node * @param {?} checked * @return {?} */ TreeFactory.prototype.maintainCheckedNodeList = /** * @private * @param {?} node * @param {?} checked * @return {?} */ function (node, checked) { if (checked && !node.data.halfChecked) { this._checked.add(node); } else { this._checked.delete(node); } }; /** * @private * @param {?} target * @param {?} tree * @param {?=} hideUnmatched * @return {?} */ TreeFactory.prototype.dfs = /** * @private * @param {?} target * @param {?} tree * @param {?=} hideUnmatched * @return {?} */ function (target, tree, hideUnmatched) { var _this = this; if (!tree) { return false; } if (!target) { return false; } if (Array.isArray(tree)) { return tree.map((/** * @param {?} treeNode * @return {?} */ function (treeNode) { return _this.dfs(target, treeNode, hideUnmatched); })); } else { /** @type {?} */ var treeNode = tree; /** @type {?} */ var treeChildren = this.getChildrenById(treeNode.id); /** @type {?} */ var selfMatched = treeNode.data.title.toLowerCase().includes(target); if (selfMatched) { treeNode.data.isMatch = true; } // Test if children matches target recursively, do not hide children if parent is matched. /** @type {?} */ var childrenMatched = this.dfs(target, treeChildren, hideUnmatched && !selfMatched).some((/** * @param {?} _ * @return {?} */ function (_) { return !!_; })); if (selfMatched || childrenMatched) { if (treeChildren.length > 0) { this.openNodesById(treeNode.id); } return true; } else { treeNode.data.isHide = hideUnmatched; return false; } } }; /** * @param {?} parentNode * @param {?} childNode * @return {?} */ TreeFactory.prototype.addChildNode = /** * @param {?} parentNode * @param {?} childNode * @return {?} */ function (parentNode, childNode) { if (parentNode) { Array.isArray(parentNode.data.children) ? parentNode.data.children.push(childNode) : parentNode.data.children = [childNode]; } else { this._treeRoot.push(childNode); } }; /** * @private * @param {?} parentNode * @param {?} childNode * @return {?} */ TreeFactory.prototype.removeChildNode = /** * @private * @param {?} parentNode * @param {?} childNode * @return {?} */ function (parentNode, childNode) { if (parentNode) { parentNode.data.children = parentNode.data.children.filter((/** * @param {?} node * @return {?} */ function (node) { return node.id !== childNode.id; })); } else { this._treeRoot = this._treeRoot.filter((/** * @param {?} node * @return {?} */ function (node) { return node.id !== childNode.id; })); } }; /** * @private * @return {?} */ TreeFactory.prototype.resetSearchResults = /** * @private * @return {?} */ function () { var _this = this; Object.keys(this.nodes).forEach((/** * @param {?} key * @return {?} */ function (key) { /** @type {?} */ var treeNode = _this.nodes[key]; treeNode.data.isMatch = false; treeNode.data.isHide = false; })); }; /** * @param {?} target * @param {?=} hideUnmatched * @return {?} */ TreeFactory.prototype.searchTree = /** * @param {?} target * @param {?=} hideUnmatched * @return {?} */ function (target, hideUnmatched) { if (hideUnmatched === void 0) { hideUnmatched = false; } target = lodashEs.trim(target); this.resetSearchResults(); return this.dfs(target.toLowerCase(), this._treeRoot, hideUnmatched); }; Object.defineProperty(TreeFactory.prototype, "treeRoot", { get: /** * @return {?} */ function () { return this._treeRoot; }, enumerable: true, configurable: true }); /** * @return {?} */ TreeFactory.prototype.deactivateAllNodes = /** * @return {?} */ function () { var e_1, _a; try { for (var _b = __values(Object.keys(this.nodes)), _c = _b.next(); !_c.done; _c = _b.next()) { var id = _c.value; this.nodes[id].data.isActive = false; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } }; return TreeFactory; }()); if (false) { /** @type {?} */ TreeFactory.prototype.nodes; /** * @type {?} * @private */ TreeFactory.prototype.idx; /** * @type {?} * @private */ TreeFactory.prototype._checked; /** * @type {?} * @private */ TreeFactory.prototype._treeRoot; /** @type {?} */ TreeFactory.prototype.mapTreeItems; } /** * @fileoverview added by tsickle * Generated from: tree-mask.service.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var TreeMaskService = /** @class */ (function () { function TreeMaskService() { } /** * @return {?} */ TreeMaskService.creatMaskElement = /** * @return {?} */ function () { /** @type {?} */ var maskElement = document.createElement('span'); /** @type {?} */ var style = { display: 'none', position: 'absolute', top: '0', right: '0', 'z-index': '-1' // 设置z-index防止挡住tree }; maskElement.classList.add('devui-tree-mask'); utils.TreeUtils.addElStyles(maskElement, style); return maskElement; }; /** * @param {?} hostElement * @param {?} maskElement * @param {?} treeWidth * @return {?} */ TreeMaskService.addMask = /** * @param {?} hostElement * @param {?} maskElement * @param {?} treeWidth * @return {?} */ function (hostElement, maskElement, treeWidth) { event.stopPropagation(); if (treeWidth) { /** @type {?} */ var nodeHeight = hostElement.clientHeight; maskElement.style.width = treeWidth + 'px'; maskElement.style.height = nodeHeight + 'px'; maskElement.style.display = 'block'; hostElement.appendChild(maskElement); } }; /** * @param {?} hostElement * @param {?} maskElement * @return {?} */ TreeMaskService.removeMask = /** * @param {?} hostElement * @param {?} maskElement * @return {?} */ function (hostElement, maskElement) { maskElement.style.display = 'none'; hostElement.removeChild(maskElement); }; /** * @param {?} treeNode * @param {?=} index * @return {?} */ TreeMaskService.calcWidth = /** * @param {?} treeNode * @param {?=} index * @return {?} */ function (treeNode, index) { /** @type {?} */ var treeWidth; // 若传入的有width说明是nativeElement则直接设置宽度,若有Length说明是queryList则找子元素宽度 if (treeNode.clientWidth) { treeWidth = treeNode.clientWidth; } else if (treeNode.length) { /** @type {?} */ var nodeList = treeNode['_results']; if (index >= 0) { // 若index小于0则必定不合法,NaN和undefined都不大于0 treeWidth = nodeList[index].nativeElement.clientWidth; } else { // index不合法的和没传的都找子element里最大的 treeWidth = Math.max.apply(Math, __spread(nodeList.map((/** * @param {?} node * @return {?} */ function (node) { return node.nativeElement.clientWidth; })))); } } return treeWidth; }; return TreeMaskService; }()); /** * @fileoverview added by tsickle * Generated from: tree.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var TreeComponent = /** @class */ (function () { function TreeComponent(i18n) { var _this = this; this.i18n = i18n; this.treeNodeTitleKey = 'title'; this.checkboxDisabledKey = 'disabled'; this.nodeSelected = new core.EventEmitter(); this.nodeDblClicked = new core.EventEmitter(); this.nodeToggled = new core.EventEmitter(); this.i18nCommonText = this.i18n.getI18nText().common; this.i18nSubscription = this.i18n.langChange().subscribe((/** * @param {?} data * @return {?} */ function (data) { _this.i18nCommonText = data.common; })); } /** * @return {?} */ TreeComponent.prototype.ngOnInit = /** * @return {?} */ function () { this.treeFactory = TreeFactory.fromTree({ treeItems: this.tree, treeNodeChildrenKey: this.treeNodeChildrenKey, treeNodeIdKey: this.treeNodeIdKey, treeNodeTitleKey: this.treeNodeTitleKey, checkboxDisabledKey: this.checkboxDisabledKey }); }; /** * @param {?} changes * @return {?} */ TreeComponent.prototype.ngOnChanges = /** * @param {?} changes * @return {?} */ function (changes) { if (changes && changes.tree) { this.treeFactory = TreeFactory.fromTree({ treeItems: this.tree, treeNodeChildrenKey: this.treeNodeChildrenKey, treeNodeIdKey: this.treeNodeIdKey, treeNodeTitleKey: this.treeNodeTitleKey, checkboxDisabledKey: this.checkboxDisabledKey }); } }; /** * @return {?} */ TreeComponent.prototype.ngAfterViewInit = /** * @return {?} */ function () { this.elementAsMask = TreeMaskService.creatMaskElement(); }; /** * @param {?} e * @return {?} */ TreeComponent.prototype.addBackGround = /** * @param {?} e * @return {?} */ function (e) { e.stopPropagation(); TreeMaskService.addMask(e.target, this.elementAsMask, TreeMaskService.calcWidth(this.treeNodeContent, 0)); }; /** * @param {?} e * @return {?} */ TreeComponent.prototype.removeBackGround = /** * @param {?} e * @return {?} */ function (e) { e.stopPropagation(); TreeMaskService.removeMask(e.target, this.elementAsMask); }; /** * @param {?} event * @param {?} treeNode * @return {?} */ TreeComponent.prototype.selectNode = /** * @param {?} event * @param {?} treeNode * @return {?} */ function (event, treeNode) { this.nodeSelected.emit(treeNode); this.treeFactory.activeNodeById(treeNode.id); }; /** * @param {?} event * @param {?} treeNode * @return {?} */ TreeComponent.prototype.toggleNode = /** * @param {?} event * @param {?} treeNode * @return {?} */ function (event, treeNode) { this.treeFactory.toggleNodeById(treeNode.id); this.nodeToggled.emit(treeNode); }; /** * @param {?} treeItems * @param {?} parentId * @return {?} */ TreeComponent.prototype.appendTreeItems = /** * @param {?} treeItems * @param {?} parentId * @return {?} */ function (treeItems, parentId) { if (!this.treeFactory.nodes[parentId]) {