UNPKG

@circlon/angular-tree-component

Version:
1,056 lines (1,047 loc) 137 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('mobx')) : typeof define === 'function' && define.amd ? define('@circlon/angular-tree-component', ['exports', '@angular/core', '@angular/common', 'mobx'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.circlon = global.circlon || {}, global.circlon['angular-tree-component'] = {}), global.ng.core, global.ng.common, global.mobx)); }(this, (function (exports, i0, common, mobx) { 'use strict'; var TreeMobxAutorunDirective = /** @class */ (function () { function TreeMobxAutorunDirective(templateRef, viewContainer) { this.templateRef = templateRef; this.viewContainer = viewContainer; this.templateBindings = {}; } TreeMobxAutorunDirective.prototype.ngOnInit = function () { this.view = this.viewContainer.createEmbeddedView(this.templateRef); if (this.dispose) { this.dispose(); } if (this.shouldDetach()) { this.view.detach(); } this.autoDetect(this.view); }; TreeMobxAutorunDirective.prototype.shouldDetach = function () { return this.treeMobxAutorun && this.treeMobxAutorun.detach; }; TreeMobxAutorunDirective.prototype.autoDetect = function (view) { this.dispose = mobx.autorun(function () { return view.detectChanges(); }); }; TreeMobxAutorunDirective.prototype.ngOnDestroy = function () { if (this.dispose) { this.dispose(); } }; return TreeMobxAutorunDirective; }()); TreeMobxAutorunDirective.decorators = [ { type: i0.Directive, args: [{ selector: '[treeMobxAutorun]' },] } ]; /** @nocollapse */ TreeMobxAutorunDirective.ctorParameters = function () { return [ { type: i0.TemplateRef }, { type: i0.ViewContainerRef } ]; }; TreeMobxAutorunDirective.propDecorators = { treeMobxAutorun: [{ type: i0.Input }] }; var KEYS = { LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40, ENTER: 13, SPACE: 32, CONTEXT_MENU: 32 }; var _36; var ɵ0 = function (tree, node, $event) { return node && node.toggleActivated(); }, ɵ1 = function (tree, node, $event) { return node && node.toggleActivated(true); }, ɵ2 = function (tree, node, $event) { return node && node.toggleSelected(); }, ɵ3 = function (tree, node, $event) { return node.setIsActive(true); }, ɵ4 = function (tree, node, $event) { return node.setIsActive(false); }, ɵ5 = function (tree, node, $event) { return node.setIsSelected(true); }, ɵ6 = function (tree, node, $event) { return node.setIsSelected(false); }, ɵ7 = function (tree, node, $event) { return node.focus(); }, ɵ8 = function (tree, node, $event) { return node.hasChildren && node.toggleExpanded(); }, ɵ9 = function (tree, node, $event) { return node.expand(); }, ɵ10 = function (tree, node, $event) { return node.collapse(); }, ɵ11 = function (tree, node, $event) { return tree.focusDrillDown(); }, ɵ12 = function (tree, node, $event) { return tree.focusDrillUp(); }, ɵ13 = function (tree, node, $event) { return tree.focusNextNode(); }, ɵ14 = function (tree, node, $event) { return tree.focusPreviousNode(); }, ɵ15 = function (tree, node, $event, _36) { var from = _36.from, to = _36.to; // default action assumes from = node, to = {parent, index} if ($event.ctrlKey) { tree.copyNode(from, to); } else { tree.moveNode(from, to); } }; var TREE_ACTIONS = { TOGGLE_ACTIVE: ɵ0, TOGGLE_ACTIVE_MULTI: ɵ1, TOGGLE_SELECTED: ɵ2, ACTIVATE: ɵ3, DEACTIVATE: ɵ4, SELECT: ɵ5, DESELECT: ɵ6, FOCUS: ɵ7, TOGGLE_EXPANDED: ɵ8, EXPAND: ɵ9, COLLAPSE: ɵ10, DRILL_DOWN: ɵ11, DRILL_UP: ɵ12, NEXT_NODE: ɵ13, PREVIOUS_NODE: ɵ14, MOVE_NODE: ɵ15 }; var defaultActionMapping = { mouse: { click: TREE_ACTIONS.TOGGLE_ACTIVE, dblClick: null, contextMenu: null, expanderClick: TREE_ACTIONS.TOGGLE_EXPANDED, checkboxClick: TREE_ACTIONS.TOGGLE_SELECTED, drop: TREE_ACTIONS.MOVE_NODE }, keys: (_36 = {}, _36[KEYS.RIGHT] = TREE_ACTIONS.DRILL_DOWN, _36[KEYS.LEFT] = TREE_ACTIONS.DRILL_UP, _36[KEYS.DOWN] = TREE_ACTIONS.NEXT_NODE, _36[KEYS.UP] = TREE_ACTIONS.PREVIOUS_NODE, _36[KEYS.SPACE] = TREE_ACTIONS.TOGGLE_ACTIVE, _36[KEYS.ENTER] = TREE_ACTIONS.TOGGLE_ACTIVE, _36) }; var TreeOptions = /** @class */ (function () { function TreeOptions(options) { var _36; if (options === void 0) { options = {}; } var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35; this.options = options; this.actionMapping = { mouse: { click: (_d = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.actionMapping) === null || _b === void 0 ? void 0 : _b.mouse) === null || _c === void 0 ? void 0 : _c.click) !== null && _d !== void 0 ? _d : defaultActionMapping.mouse.click, dblClick: (_h = (_g = (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.actionMapping) === null || _f === void 0 ? void 0 : _f.mouse) === null || _g === void 0 ? void 0 : _g.dblClick) !== null && _h !== void 0 ? _h : defaultActionMapping.mouse.dblClick, contextMenu: (_m = (_l = (_k = (_j = this.options) === null || _j === void 0 ? void 0 : _j.actionMapping) === null || _k === void 0 ? void 0 : _k.mouse) === null || _l === void 0 ? void 0 : _l.contextMenu) !== null && _m !== void 0 ? _m : defaultActionMapping.mouse.contextMenu, expanderClick: (_r = (_q = (_p = (_o = this.options) === null || _o === void 0 ? void 0 : _o.actionMapping) === null || _p === void 0 ? void 0 : _p.mouse) === null || _q === void 0 ? void 0 : _q.expanderClick) !== null && _r !== void 0 ? _r : defaultActionMapping.mouse.expanderClick, checkboxClick: (_v = (_u = (_t = (_s = this.options) === null || _s === void 0 ? void 0 : _s.actionMapping) === null || _t === void 0 ? void 0 : _t.mouse) === null || _u === void 0 ? void 0 : _u.checkboxClick) !== null && _v !== void 0 ? _v : defaultActionMapping.mouse.checkboxClick, drop: (_z = (_y = (_x = (_w = this.options) === null || _w === void 0 ? void 0 : _w.actionMapping) === null || _x === void 0 ? void 0 : _x.mouse) === null || _y === void 0 ? void 0 : _y.drop) !== null && _z !== void 0 ? _z : defaultActionMapping.mouse.drop, dragStart: (_3 = (_2 = (_1 = (_0 = this.options) === null || _0 === void 0 ? void 0 : _0.actionMapping) === null || _1 === void 0 ? void 0 : _1.mouse) === null || _2 === void 0 ? void 0 : _2.dragStart) !== null && _3 !== void 0 ? _3 : undefined, drag: (_7 = (_6 = (_5 = (_4 = this.options) === null || _4 === void 0 ? void 0 : _4.actionMapping) === null || _5 === void 0 ? void 0 : _5.mouse) === null || _6 === void 0 ? void 0 : _6.drag) !== null && _7 !== void 0 ? _7 : undefined, dragEnd: (_11 = (_10 = (_9 = (_8 = this.options) === null || _8 === void 0 ? void 0 : _8.actionMapping) === null || _9 === void 0 ? void 0 : _9.mouse) === null || _10 === void 0 ? void 0 : _10.dragEnd) !== null && _11 !== void 0 ? _11 : undefined, dragOver: (_15 = (_14 = (_13 = (_12 = this.options) === null || _12 === void 0 ? void 0 : _12.actionMapping) === null || _13 === void 0 ? void 0 : _13.mouse) === null || _14 === void 0 ? void 0 : _14.dragOver) !== null && _15 !== void 0 ? _15 : undefined, dragLeave: (_19 = (_18 = (_17 = (_16 = this.options) === null || _16 === void 0 ? void 0 : _16.actionMapping) === null || _17 === void 0 ? void 0 : _17.mouse) === null || _18 === void 0 ? void 0 : _18.dragLeave) !== null && _19 !== void 0 ? _19 : undefined, dragEnter: (_23 = (_22 = (_21 = (_20 = this.options) === null || _20 === void 0 ? void 0 : _20.actionMapping) === null || _21 === void 0 ? void 0 : _21.mouse) === null || _22 === void 0 ? void 0 : _22.dragEnter) !== null && _23 !== void 0 ? _23 : undefined, mouseOver: (_27 = (_26 = (_25 = (_24 = this.options) === null || _24 === void 0 ? void 0 : _24.actionMapping) === null || _25 === void 0 ? void 0 : _25.mouse) === null || _26 === void 0 ? void 0 : _26.mouseOver) !== null && _27 !== void 0 ? _27 : undefined, mouseOut: (_31 = (_30 = (_29 = (_28 = this.options) === null || _28 === void 0 ? void 0 : _28.actionMapping) === null || _29 === void 0 ? void 0 : _29.mouse) === null || _30 === void 0 ? void 0 : _30.mouseOut) !== null && _31 !== void 0 ? _31 : undefined, }, keys: (_36 = {}, _36[KEYS.RIGHT] = TREE_ACTIONS.DRILL_DOWN, _36[KEYS.LEFT] = TREE_ACTIONS.DRILL_UP, _36[KEYS.DOWN] = TREE_ACTIONS.NEXT_NODE, _36[KEYS.UP] = TREE_ACTIONS.PREVIOUS_NODE, _36[KEYS.SPACE] = TREE_ACTIONS.TOGGLE_ACTIVE, _36[KEYS.ENTER] = TREE_ACTIONS.TOGGLE_ACTIVE, _36) }; if ((_33 = (_32 = this.options) === null || _32 === void 0 ? void 0 : _32.actionMapping) === null || _33 === void 0 ? void 0 : _33.keys) { this.actionMapping.keys = Object.assign(Object.assign({}, this.actionMapping.keys), this.options.actionMapping.keys); } if (options.rtl) { this.actionMapping.keys[KEYS.RIGHT] = ((_34 = options.actionMapping) === null || _34 === void 0 ? void 0 : _34.keys[KEYS.RIGHT]) || TREE_ACTIONS.DRILL_UP; this.actionMapping.keys[KEYS.LEFT] = ((_35 = options.actionMapping) === null || _35 === void 0 ? void 0 : _35.keys[KEYS.LEFT]) || TREE_ACTIONS.DRILL_DOWN; } } Object.defineProperty(TreeOptions.prototype, "hasChildrenField", { get: function () { return this.options.hasChildrenField || 'hasChildren'; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "childrenField", { get: function () { return this.options.childrenField || 'children'; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "displayField", { get: function () { return this.options.displayField || 'name'; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "idField", { get: function () { return this.options.idField || 'id'; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "isExpandedField", { get: function () { return this.options.isExpandedField || 'isExpanded'; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "getChildren", { get: function () { return this.options.getChildren; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "levelPadding", { get: function () { return this.options.levelPadding || 0; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "useVirtualScroll", { get: function () { return this.options.useVirtualScroll; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "animateExpand", { get: function () { return this.options.animateExpand; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "animateSpeed", { get: function () { return this.options.animateSpeed || 1; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "animateAcceleration", { get: function () { return this.options.animateAcceleration || 1.2; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "scrollOnActivate", { get: function () { return this.options.scrollOnActivate === undefined ? true : this.options.scrollOnActivate; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "rtl", { get: function () { return !!this.options.rtl; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "rootId", { get: function () { return this.options.rootId; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "useCheckbox", { get: function () { return this.options.useCheckbox; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "useTriState", { get: function () { return this.options.useTriState === undefined ? true : this.options.useTriState; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "scrollContainer", { get: function () { return this.options.scrollContainer; }, enumerable: false, configurable: true }); Object.defineProperty(TreeOptions.prototype, "allowDragoverStyling", { get: function () { return this.options.allowDragoverStyling === undefined ? true : this.options.allowDragoverStyling; }, enumerable: false, configurable: true }); TreeOptions.prototype.getNodeClone = function (node) { if (this.options.getNodeClone) { return this.options.getNodeClone(node); } // remove id from clone // keeping ie11 compatibility var nodeClone = Object.assign({}, node.data); if (nodeClone.id) { delete nodeClone.id; } return nodeClone; }; TreeOptions.prototype.allowDrop = function (element, to, $event) { if (this.options.allowDrop instanceof Function) { return this.options.allowDrop(element, to, $event); } else { return this.options.allowDrop === undefined ? true : this.options.allowDrop; } }; TreeOptions.prototype.allowDrag = function (node) { if (this.options.allowDrag instanceof Function) { return this.options.allowDrag(node); } else { return this.options.allowDrag; } }; TreeOptions.prototype.nodeClass = function (node) { return this.options.nodeClass ? this.options.nodeClass(node) : ''; }; TreeOptions.prototype.nodeHeight = function (node) { if (node.data.virtual) { return 0; } var nodeHeight = this.options.nodeHeight || 22; if (typeof nodeHeight === 'function') { nodeHeight = nodeHeight(node); } // account for drop slots: return nodeHeight + (node.index === 0 ? 2 : 1) * this.dropSlotHeight; }; Object.defineProperty(TreeOptions.prototype, "dropSlotHeight", { get: function () { return typeof this.options.dropSlotHeight === 'number' ? this.options.dropSlotHeight : 2; }, enumerable: false, configurable: true }); return TreeOptions; }()); /*! ***************************************************************************** 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 (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) { 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, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, 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; } 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; } ; 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 (Object.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 TREE_EVENTS = { toggleExpanded: 'toggleExpanded', activate: 'activate', deactivate: 'deactivate', nodeActivate: 'nodeActivate', nodeDeactivate: 'nodeDeactivate', select: 'select', deselect: 'deselect', focus: 'focus', blur: 'blur', initialized: 'initialized', updateData: 'updateData', moveNode: 'moveNode', copyNode: 'copyNode', event: 'event', loadNodeChildren: 'loadNodeChildren', changeFilter: 'changeFilter', stateChange: 'stateChange' }; var __decorate$1 = (this && this.__decorate) || function (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; }; var __metadata$1 = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var TreeNode = /** @class */ (function () { function TreeNode(data, parent, treeModel, index) { var _this = this; this.data = data; this.parent = parent; this.treeModel = treeModel; this.position = 0; this.allowDrop = function (element, $event) { return _this.options.allowDrop(element, { parent: _this, index: 0 }, $event); }; this.allowDragoverStyling = function () { return _this.options.allowDragoverStyling; }; if (this.id === undefined || this.id === null) { this.id = uuid(); } // Make sure there's a unique id without overriding existing ids to work with immutable data structures this.index = index; if (this.getField('children')) { this._initChildren(); } this.autoLoadChildren(); } Object.defineProperty(TreeNode.prototype, "isHidden", { get: function () { return this.treeModel.isHidden(this); }, enumerable: false, configurable: true }); ; Object.defineProperty(TreeNode.prototype, "isExpanded", { get: function () { return this.treeModel.isExpanded(this); }, enumerable: false, configurable: true }); ; Object.defineProperty(TreeNode.prototype, "isActive", { get: function () { return this.treeModel.isActive(this); }, enumerable: false, configurable: true }); ; Object.defineProperty(TreeNode.prototype, "isFocused", { get: function () { return this.treeModel.isNodeFocused(this); }, enumerable: false, configurable: true }); ; Object.defineProperty(TreeNode.prototype, "isSelected", { get: function () { if (this.isSelectable()) { return this.treeModel.isSelected(this); } else { return this.children.some(function (node) { return node.isSelected; }); } }, enumerable: false, configurable: true }); ; Object.defineProperty(TreeNode.prototype, "isAllSelected", { get: function () { if (this.isSelectable()) { return this.treeModel.isSelected(this); } else { return this.children.every(function (node) { return node.isAllSelected; }); } }, enumerable: false, configurable: true }); ; Object.defineProperty(TreeNode.prototype, "isPartiallySelected", { get: function () { return this.isSelected && !this.isAllSelected; }, enumerable: false, configurable: true }); Object.defineProperty(TreeNode.prototype, "level", { get: function () { return this.parent ? this.parent.level + 1 : 0; }, enumerable: false, configurable: true }); Object.defineProperty(TreeNode.prototype, "path", { get: function () { return this.parent ? __spread(this.parent.path, [this.id]) : []; }, enumerable: false, configurable: true }); Object.defineProperty(TreeNode.prototype, "elementRef", { get: function () { throw "Element Ref is no longer supported since introducing virtual scroll\n\n You may use a template to obtain a reference to the element"; }, enumerable: false, configurable: true }); Object.defineProperty(TreeNode.prototype, "originalNode", { get: function () { return this._originalNode; }, enumerable: false, configurable: true }); ; Object.defineProperty(TreeNode.prototype, "hasChildren", { // helper get functions: get: function () { return !!(this.getField('hasChildren') || (this.children && this.children.length > 0)); }, enumerable: false, configurable: true }); Object.defineProperty(TreeNode.prototype, "isCollapsed", { get: function () { return !this.isExpanded; }, enumerable: false, configurable: true }); Object.defineProperty(TreeNode.prototype, "isLeaf", { get: function () { return !this.hasChildren; }, enumerable: false, configurable: true }); Object.defineProperty(TreeNode.prototype, "isRoot", { get: function () { return this.parent.data.virtual; }, enumerable: false, configurable: true }); Object.defineProperty(TreeNode.prototype, "realParent", { get: function () { return this.isRoot ? null : this.parent; }, enumerable: false, configurable: true }); Object.defineProperty(TreeNode.prototype, "options", { // proxy functions: get: function () { return this.treeModel.options; }, enumerable: false, configurable: true }); TreeNode.prototype.fireEvent = function (event) { this.treeModel.fireEvent(event); }; Object.defineProperty(TreeNode.prototype, "displayField", { // field accessors: get: function () { return this.getField('display'); }, enumerable: false, configurable: true }); Object.defineProperty(TreeNode.prototype, "id", { get: function () { return this.getField('id'); }, set: function (value) { this.setField('id', value); }, enumerable: false, configurable: true }); TreeNode.prototype.getField = function (key) { return this.data[this.options[key + "Field"]]; }; TreeNode.prototype.setField = function (key, value) { this.data[this.options[key + "Field"]] = value; }; // traversing: TreeNode.prototype._findAdjacentSibling = function (steps, skipHidden) { if (skipHidden === void 0) { skipHidden = false; } var siblings = this._getParentsChildren(skipHidden); var index = siblings.indexOf(this); return siblings.length > index + steps ? siblings[index + steps] : null; }; TreeNode.prototype.findNextSibling = function (skipHidden) { if (skipHidden === void 0) { skipHidden = false; } return this._findAdjacentSibling(+1, skipHidden); }; TreeNode.prototype.findPreviousSibling = function (skipHidden) { if (skipHidden === void 0) { skipHidden = false; } return this._findAdjacentSibling(-1, skipHidden); }; TreeNode.prototype.getVisibleChildren = function () { return this.visibleChildren; }; Object.defineProperty(TreeNode.prototype, "visibleChildren", { get: function () { return (this.children || []).filter(function (node) { return !node.isHidden; }); }, enumerable: false, configurable: true }); TreeNode.prototype.getFirstChild = function (skipHidden) { if (skipHidden === void 0) { skipHidden = false; } var children = skipHidden ? this.visibleChildren : this.children; return children != null && children.length ? children[0] : null; }; TreeNode.prototype.getLastChild = function (skipHidden) { if (skipHidden === void 0) { skipHidden = false; } var children = skipHidden ? this.visibleChildren : this.children; return children != null && children.length ? children[children.length - 1] : null; }; TreeNode.prototype.findNextNode = function (goInside, skipHidden) { if (goInside === void 0) { goInside = true; } if (skipHidden === void 0) { skipHidden = false; } return goInside && this.isExpanded && this.getFirstChild(skipHidden) || this.findNextSibling(skipHidden) || this.parent && this.parent.findNextNode(false, skipHidden); }; TreeNode.prototype.findPreviousNode = function (skipHidden) { if (skipHidden === void 0) { skipHidden = false; } var previousSibling = this.findPreviousSibling(skipHidden); if (!previousSibling) { return this.realParent; } return previousSibling._getLastOpenDescendant(skipHidden); }; TreeNode.prototype._getLastOpenDescendant = function (skipHidden) { if (skipHidden === void 0) { skipHidden = false; } var lastChild = this.getLastChild(skipHidden); return (this.isCollapsed || !lastChild) ? this : lastChild._getLastOpenDescendant(skipHidden); }; TreeNode.prototype._getParentsChildren = function (skipHidden) { if (skipHidden === void 0) { skipHidden = false; } var children = this.parent && (skipHidden ? this.parent.getVisibleChildren() : this.parent.children); return children || []; }; TreeNode.prototype.getIndexInParent = function (skipHidden) { if (skipHidden === void 0) { skipHidden = false; } return this._getParentsChildren(skipHidden).indexOf(this); }; TreeNode.prototype.isDescendantOf = function (node) { if (this === node) return true; else return this.parent && this.parent.isDescendantOf(node); }; TreeNode.prototype.getNodePadding = function () { return this.options.levelPadding * (this.level - 1) + 'px'; }; TreeNode.prototype.getClass = function () { return [this.options.nodeClass(this), "tree-node-level-" + this.level].join(' '); }; TreeNode.prototype.onDrop = function ($event) { this.mouseAction('drop', $event.event, { from: $event.element, to: { parent: this, index: 0, dropOnNode: true } }); }; TreeNode.prototype.allowDrag = function () { return this.options.allowDrag(this); }; // helper methods: TreeNode.prototype.loadNodeChildren = function () { var _this = this; if (!this.options.getChildren) { return Promise.resolve(); // Not getChildren method - for using redux } return Promise.resolve(this.options.getChildren(this)) .then(function (children) { if (children) { _this.setField('children', children); _this._initChildren(); if (_this.options.useTriState && _this.treeModel.isSelected(_this)) { _this.setIsSelected(true); } _this.children.forEach(function (child) { if (child.getField('isExpanded') && child.hasChildren) { child.expand(); } }); } }).then(function () { _this.fireEvent({ eventName: TREE_EVENTS.loadNodeChildren, node: _this }); }); }; TreeNode.prototype.expand = function () { if (!this.isExpanded) { this.toggleExpanded(); } return this; }; TreeNode.prototype.collapse = function () { if (this.isExpanded) { this.toggleExpanded(); } return this; }; TreeNode.prototype.doForAll = function (fn) { var _this = this; Promise.resolve(fn(this)).then(function () { if (_this.children) { _this.children.forEach(function (child) { return child.doForAll(fn); }); } }); }; TreeNode.prototype.expandAll = function () { this.doForAll(function (node) { return node.expand(); }); }; TreeNode.prototype.collapseAll = function () { this.doForAll(function (node) { return node.collapse(); }); }; TreeNode.prototype.ensureVisible = function () { if (this.realParent) { this.realParent.expand(); this.realParent.ensureVisible(); } return this; }; TreeNode.prototype.toggleExpanded = function () { this.setIsExpanded(!this.isExpanded); return this; }; TreeNode.prototype.setIsExpanded = function (value) { if (this.hasChildren) { this.treeModel.setExpandedNode(this, value); } return this; }; ; TreeNode.prototype.autoLoadChildren = function () { var _this = this; this.handler = mobx.reaction(function () { return _this.isExpanded; }, function (isExpanded) { if (!_this.children && _this.hasChildren && isExpanded) { _this.loadNodeChildren(); } }, { fireImmediately: true }); }; TreeNode.prototype.dispose = function () { if (this.children) { this.children.forEach(function (child) { return child.dispose(); }); } if (this.handler) { this.handler(); } this.parent = null; this.children = null; }; TreeNode.prototype.setIsActive = function (value, multi) { if (multi === void 0) { multi = false; } this.treeModel.setActiveNode(this, value, multi); if (value) { this.focus(this.options.scrollOnActivate); } return this; }; TreeNode.prototype.isSelectable = function () { return this.isLeaf || !this.children || !this.options.useTriState; }; TreeNode.prototype.setIsSelected = function (value) { if (this.isSelectable()) { this.treeModel.setSelectedNode(this, value); } else { this.visibleChildren.forEach(function (child) { return child.setIsSelected(value); }); } return this; }; TreeNode.prototype.toggleSelected = function () { this.setIsSelected(!this.isSelected); return this; }; TreeNode.prototype.toggleActivated = function (multi) { if (multi === void 0) { multi = false; } this.setIsActive(!this.isActive, multi); return this; }; TreeNode.prototype.setActiveAndVisible = function (multi) { if (multi === void 0) { multi = false; } this.setIsActive(true, multi) .ensureVisible(); setTimeout(this.scrollIntoView.bind(this)); return this; }; TreeNode.prototype.scrollIntoView = function (force) { if (force === void 0) { force = false; } this.treeModel.virtualScroll.scrollIntoView(this, force); }; TreeNode.prototype.focus = function (scroll) { if (scroll === void 0) { scroll = true; } var previousNode = this.treeModel.getFocusedNode(); this.treeModel.setFocusedNode(this); if (scroll) { this.scrollIntoView(); } if (previousNode) { this.fireEvent({ eventName: TREE_EVENTS.blur, node: previousNode }); } this.fireEvent({ eventName: TREE_EVENTS.focus, node: this }); return this; }; TreeNode.prototype.blur = function () { var previousNode = this.treeModel.getFocusedNode(); this.treeModel.setFocusedNode(null); if (previousNode) { this.fireEvent({ eventName: TREE_EVENTS.blur, node: this }); } return this; }; TreeNode.prototype.setIsHidden = function (value) { this.treeModel.setIsHidden(this, value); }; TreeNode.prototype.hide = function () { this.setIsHidden(true); }; TreeNode.prototype.show = function () { this.setIsHidden(false); }; TreeNode.prototype.mouseAction = function (actionName, $event, data) { if (data === void 0) { data = null; } this.treeModel.setFocus(true); var actionMapping = this.options.actionMapping.mouse; var mouseAction = actionMapping[actionName]; if (mouseAction) { mouseAction(this.treeModel, this, $event, data); } }; TreeNode.prototype.getSelfHeight = function () { return this.options.nodeHeight(this); }; TreeNode.prototype._initChildren = function () { var _this = this; this.children = this.getField('children') .map(function (c, index) { return new TreeNode(c, _this, _this.treeModel, index); }); }; return TreeNode; }()); __decorate$1([ mobx.computed,