UNPKG

ngx-tree-select

Version:

Angular component for select with tree items.

1,355 lines (1,317 loc) 106 kB
/** * NgxTreeSelect Copyright 2019 * Licensed under MIT */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("@angular/core"), require("@angular/forms"), require("@angular/common")); else if(typeof define === 'function' && define.amd) define(["@angular/core", "@angular/forms", "@angular/common"], factory); else if(typeof exports === 'object') exports["ngxTreeSelect"] = factory(require("@angular/core"), require("@angular/forms"), require("@angular/common")); else root["ngxTreeSelect"] = factory(root["@angular/core"], root["@angular/forms"], root["@angular/common"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_0__, __WEBPACK_EXTERNAL_MODULE_8__, __WEBPACK_EXTERNAL_MODULE_14__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = "/"; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 17); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_0__; /***/ }), /* 1 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ExpandMode; }); var ExpandMode = /** @class */ (function () { function ExpandMode() { } ExpandMode.None = 'None'; ExpandMode.Selection = 'Selection'; ExpandMode.All = 'All'; return ExpandMode; }()); function ExpandMode_tsickle_Closure_declarations() { /** @type {?} */ ExpandMode.None; /** @type {?} */ ExpandMode.Selection; /** @type {?} */ ExpandMode.All; } //# sourceMappingURL=expand-mode.js.map /***/ }), /* 2 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return TreeSelectDefaultOptions; }); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__angular_core__ = __webpack_require__(0); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__angular_core___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__angular_core__); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__expand_mode__ = __webpack_require__(1); var TreeSelectDefaultOptions = /** @class */ (function () { function TreeSelectDefaultOptions() { this.expandMode = __WEBPACK_IMPORTED_MODULE_1__expand_mode__["a" /* ExpandMode */].None; } TreeSelectDefaultOptions.decorators = [ { type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Injectable"] }, ]; /** * @nocollapse */ TreeSelectDefaultOptions.ctorParameters = function () { return []; }; return TreeSelectDefaultOptions; }()); function TreeSelectDefaultOptions_tsickle_Closure_declarations() { /** @type {?} */ TreeSelectDefaultOptions.decorators; /** * @nocollapse * @type {?} */ TreeSelectDefaultOptions.ctorParameters; /** @type {?} */ TreeSelectDefaultOptions.prototype.allowFilter; /** @type {?} */ TreeSelectDefaultOptions.prototype.filterPlaceholder; /** @type {?} */ TreeSelectDefaultOptions.prototype.maxVisibleItemCount; /** @type {?} */ TreeSelectDefaultOptions.prototype.allowParentSelection; /** @type {?} */ TreeSelectDefaultOptions.prototype.idField; /** @type {?} */ TreeSelectDefaultOptions.prototype.textField; /** @type {?} */ TreeSelectDefaultOptions.prototype.childrenField; /** @type {?} */ TreeSelectDefaultOptions.prototype.filterCaseSensitive; /** @type {?} */ TreeSelectDefaultOptions.prototype.expandMode; } //# sourceMappingURL=tree-select-default-options.js.map /***/ }), /* 3 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return TreeSelectComponent; }); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__angular_core__ = __webpack_require__(0); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__angular_core___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__angular_core__); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__angular_forms__ = __webpack_require__(8); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__angular_forms___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__angular_forms__); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__services_select_service__ = __webpack_require__(4); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__models_tree_select_default_options__ = __webpack_require__(2); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__models_expand_mode__ = __webpack_require__(1); // tslint:disable-next-line:no-empty var /** @type {?} */ noop = function () { }; var /** @type {?} */ CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR = { provide: __WEBPACK_IMPORTED_MODULE_1__angular_forms__["NG_VALUE_ACCESSOR"], // tslint:disable-next-line:no-forward-ref useExisting: Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["forwardRef"])(function () { return TreeSelectComponent; }), multi: true }; var TreeSelectComponent = /** @class */ (function () { /** * @param {?} svc * @param {?} defaultOpts */ function TreeSelectComponent(svc, defaultOpts) { var _this = this; this.svc = svc; this.defaultOpts = defaultOpts; this.onTouchedCallback = noop; this.showMoreLink = false; this.moreLoaded = false; this.disabled = false; this.placeholder = ''; this.filterPlaceholder = 'Type here for filtering items...'; this.allowFilter = true; this._isOpen = false; this.onChangeCallback = noop; this.haveFocus = false; this.inputFocus = false; this.clickedOutside = this.clickedOutside.bind(this); this.svc.modelChanged$.subscribe(function (result) { _this.onChangeCallback(result); }); this.maxVisibleItemCount = (defaultOpts.maxVisibleItemCount || 0); this.allowParentSelection = ((defaultOpts.allowParentSelection === undefined || defaultOpts.allowParentSelection === null) ? true : defaultOpts.allowParentSelection); this.allowFilter = ((defaultOpts.allowFilter === undefined || defaultOpts.allowFilter === null) ? true : defaultOpts.allowFilter); this.filterCaseSensitive = ((defaultOpts.filterCaseSensitive === undefined || defaultOpts.filterCaseSensitive === null) ? false : defaultOpts.filterCaseSensitive); this.filterPlaceholder = (defaultOpts.filterPlaceholder || 'Type here for filtering items...'); this.idField = (defaultOpts.idField || 'id'); this.textField = (defaultOpts.textField || 'id'); this.childrenField = (defaultOpts.childrenField || ''); this.expandMode = (defaultOpts.expandMode || __WEBPACK_IMPORTED_MODULE_4__models_expand_mode__["a" /* ExpandMode */].None); } Object.defineProperty(TreeSelectComponent.prototype, "items", { /** * @param {?} value * @return {?} */ set: function (value) { this.svc.setItems(value); }, enumerable: true, configurable: true }); Object.defineProperty(TreeSelectComponent.prototype, "idField", { /** * @param {?} value * @return {?} */ set: function (value) { this.svc.setConfiguration(function (opt) { return opt.idProperty = value; }, true); }, enumerable: true, configurable: true }); Object.defineProperty(TreeSelectComponent.prototype, "textField", { /** * @param {?} value * @return {?} */ set: function (value) { this.svc.setConfiguration(function (opt) { return opt.textProperty = value; }, true); }, enumerable: true, configurable: true }); Object.defineProperty(TreeSelectComponent.prototype, "allowParentSelection", { /** * @return {?} */ get: function () { return this.svc.Configuration.allowParentSelection; }, /** * @param {?} value * @return {?} */ set: function (value) { this.svc.setConfiguration(function (opt) { return opt.allowParentSelection = value; }, true); }, enumerable: true, configurable: true }); Object.defineProperty(TreeSelectComponent.prototype, "restructureWhenChildSameName", { /** * @return {?} */ get: function () { return this.svc.Configuration.restructureWhenChildSameName; }, /** * @param {?} value * @return {?} */ set: function (value) { this.svc.setConfiguration(function (opt) { return opt.restructureWhenChildSameName = value; }, true); }, enumerable: true, configurable: true }); Object.defineProperty(TreeSelectComponent.prototype, "childrenField", { /** * @param {?} value * @return {?} */ set: function (value) { this.svc.setConfiguration(function (opt) { return opt.childProperty = value; }, true); }, enumerable: true, configurable: true }); Object.defineProperty(TreeSelectComponent.prototype, "multiple", { /** * @return {?} */ get: function () { return this.svc.Configuration.allowMultiple; }, /** * @param {?} value * @return {?} */ set: function (value) { this.svc.setConfiguration(function (opt) { return opt.allowMultiple = value; }, true); }, enumerable: true, configurable: true }); Object.defineProperty(TreeSelectComponent.prototype, "filterCaseSensitive", { /** * @return {?} */ get: function () { return this.svc.Configuration.filterCaseSensitive; }, /** * @param {?} value * @return {?} */ set: function (value) { this.svc.setConfiguration(function (opt) { return opt.filterCaseSensitive = value; }, true); }, enumerable: true, configurable: true }); Object.defineProperty(TreeSelectComponent.prototype, "expandMode", { /** * @return {?} */ get: function () { return this.svc.Configuration.expandMode; }, /** * @param {?} value * @return {?} */ set: function (value) { this.svc.setConfiguration(function (opt) { return opt.expandMode = value; }, true); this.svc.setExpand(); }, enumerable: true, configurable: true }); Object.defineProperty(TreeSelectComponent.prototype, "maxVisibleItemCount", { /** * @return {?} */ get: function () { return this.svc.Configuration.maxVisibleItemCount; }, /** * @param {?} value * @return {?} */ set: function (value) { this.svc.setConfiguration(function (opt) { return opt.maxVisibleItemCount = value; }, true); }, enumerable: true, configurable: true }); Object.defineProperty(TreeSelectComponent.prototype, "internalItems", { /** * @return {?} */ get: function () { return this.svc.getInternalItems() || []; }, enumerable: true, configurable: true }); Object.defineProperty(TreeSelectComponent.prototype, "selection", { /** * @return {?} */ get: function () { this.showMoreLink = (this.maxVisibleItemCount > 0 && ((this.svc.getInternalSelection().length - this.maxVisibleItemCount) > 0)); return this.svc.getInternalSelection(); }, enumerable: true, configurable: true }); Object.defineProperty(TreeSelectComponent.prototype, "filter", { /** * @return {?} */ get: function () { return this.svc.Configuration.filter; }, /** * @param {?} value * @return {?} */ set: function (value) { this.svc.setConfiguration(function (opt) { return opt.filter = value; }, false); for (var _i = 0, _a = this.internalItems; _i < _a.length; _i++) { var item = _a[_i]; this.ProcessMatchFilterTreeItem(item, this.svc.Configuration.filter); } this.svc.setExpand(); }, enumerable: true, configurable: true }); /** * @param {?} $event * @return {?} */ TreeSelectComponent.prototype.keyUp = function ($event) { }; /** * @param {?} $event * @return {?} */ TreeSelectComponent.prototype.toggle = function ($event) { $event.preventDefault(); this.haveFocus = true; this.svc.toggleOpen(); }; /** * @param {?} $event * @param {?} item * @return {?} */ TreeSelectComponent.prototype.removeItem = function ($event, item) { $event.stopPropagation(); this.svc.toggleItemSelection(item); }; Object.defineProperty(TreeSelectComponent.prototype, "isOpen", { /** * @return {?} */ get: function () { return this.svc.Configuration.isOpen; }, enumerable: true, configurable: true }); /** * @return {?} */ TreeSelectComponent.prototype.clickedOutside = function () { if (!this.inputFocus) { if (!this.haveFocus && this.isOpen || this.haveFocus && !this.isOpen) { this.onTouched(); } this.haveFocus = false; } }; /** * @return {?} */ TreeSelectComponent.prototype.onTouched = function () { this.svc.close(); this.onTouchedCallback(); }; /** * @return {?} */ TreeSelectComponent.prototype.setInputFocus = function () { this.inputFocus = true; }; /** * @return {?} */ TreeSelectComponent.prototype.setInputFocusOut = function () { this.inputFocus = false; }; /** * Write a new value to the element. * * \@memberof TreeSelectComponent * @param {?} value * @return {?} */ TreeSelectComponent.prototype.writeValue = function (value) { this.svc.setSelection(value); }; /** * Set the function to be called when the control receives a change event. * * \@memberof TreeSelectComponent * @param {?} fn * @return {?} */ TreeSelectComponent.prototype.registerOnChange = function (fn) { this.onChangeCallback = fn; }; /** * Set the function to be called when the control receives a touch event. * * \@memberof TreeSelectComponent * @param {?} fn * @return {?} */ TreeSelectComponent.prototype.registerOnTouched = function (fn) { this.onTouchedCallback = fn; }; /** * This function is called when the control status changes to or from "DISABLED". * Depending on the value, it will enable or disable the appropriate DOM element. * * \@memberof TreeSelectComponent * @param {?} isDisabled * @return {?} */ TreeSelectComponent.prototype.setDisabledState = function (isDisabled) { this.disabled = isDisabled; }; /** * This finction is called when user click on show more link. * * \@memberof TreeSelectComponent * @param {?} $event * @return {?} */ TreeSelectComponent.prototype.loadMore = function ($event) { $event.stopPropagation(); this.moreLoaded = !this.moreLoaded; }; /** * @param {?} tree * @param {?} filter * @return {?} */ TreeSelectComponent.prototype.ProcessMatchFilterTreeItem = function (tree, filter) { var /** @type {?} */ result = false; if (tree && tree.children && tree.children.length > 0) { for (var _i = 0, _a = tree.children; _i < _a.length; _i++) { var child = _a[_i]; result = this.ProcessMatchFilterTreeItem(child, filter) || result; } } tree.matchFilter = this.filterCaseSensitive ? (tree.id.indexOf(filter) > -1 || tree.text.indexOf(filter) > -1 || result) : (tree.id.toLowerCase().indexOf(filter.toLowerCase()) > -1 || tree.text.toLowerCase().indexOf(filter.toLowerCase()) > -1 || result); return tree.matchFilter; }; TreeSelectComponent.decorators = [ { type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Component"], args: [{ selector: 'tree-select', templateUrl: './tree-select.component.html', providers: [CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR, __WEBPACK_IMPORTED_MODULE_2__services_select_service__["a" /* SelectService */]], styleUrls: ['./tree-select.component.scss'] },] }, ]; /** * @nocollapse */ TreeSelectComponent.ctorParameters = function () { return [ { type: __WEBPACK_IMPORTED_MODULE_2__services_select_service__["a" /* SelectService */], }, { type: __WEBPACK_IMPORTED_MODULE_3__models_tree_select_default_options__["a" /* TreeSelectDefaultOptions */], }, ]; }; TreeSelectComponent.propDecorators = { 'disabled': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], 'placeholder': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], 'filterPlaceholder': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], 'allowFilter': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], 'items': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], 'idField': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], 'textField': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], 'allowParentSelection': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], 'restructureWhenChildSameName': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], 'childrenField': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], 'multiple': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], 'filterCaseSensitive': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], 'expandMode': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], 'maxVisibleItemCount': [{ type: __WEBPACK_IMPORTED_MODULE_0__angular_core__["Input"] },], }; return TreeSelectComponent; }()); function TreeSelectComponent_tsickle_Closure_declarations() { /** @type {?} */ TreeSelectComponent.decorators; /** * @nocollapse * @type {?} */ TreeSelectComponent.ctorParameters; /** @type {?} */ TreeSelectComponent.propDecorators; /** @type {?} */ TreeSelectComponent.prototype.onTouchedCallback; /** @type {?} */ TreeSelectComponent.prototype.showMoreLink; /** @type {?} */ TreeSelectComponent.prototype.moreLoaded; /** @type {?} */ TreeSelectComponent.prototype.disabled; /** @type {?} */ TreeSelectComponent.prototype.placeholder; /** @type {?} */ TreeSelectComponent.prototype.filterPlaceholder; /** @type {?} */ TreeSelectComponent.prototype.allowFilter; /** @type {?} */ TreeSelectComponent.prototype._isOpen; /** @type {?} */ TreeSelectComponent.prototype.onChangeCallback; /** @type {?} */ TreeSelectComponent.prototype.haveFocus; /** @type {?} */ TreeSelectComponent.prototype.inputFocus; /** @type {?} */ TreeSelectComponent.prototype.svc; /** @type {?} */ TreeSelectComponent.prototype.defaultOpts; } //# sourceMappingURL=tree-select.component.js.map /***/ }), /* 4 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SelectService; }); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_rxjs_Subject__ = __webpack_require__(19); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_rxjs_Subject___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_rxjs_Subject__); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__models_selectable_item__ = __webpack_require__(32); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__models_select_option__ = __webpack_require__(33); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__angular_core__ = __webpack_require__(0); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__angular_core___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3__angular_core__); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__models_expand_mode__ = __webpack_require__(1); var SelectService = /** @class */ (function () { function SelectService() { this.modelChanged$ = new __WEBPACK_IMPORTED_MODULE_0_rxjs_Subject__["Subject"](); this._options = new __WEBPACK_IMPORTED_MODULE_2__models_select_option__["a" /* SelectOption */](); } /** * @return {?} */ SelectService.prototype.close = function () { if (this.Configuration.isOpen) { this.setConfiguration(function (opt) { return opt.isOpen = false; }, false); } }; /** * @return {?} */ SelectService.prototype.open = function () { if (!this.Configuration.isOpen) { this.setConfiguration(function (opt) { return opt.isOpen = true; }, false); } }; /** * @return {?} */ SelectService.prototype.toggleOpen = function () { this.setConfiguration(function (opt) { return opt.isOpen = !opt.isOpen; }, false); }; /** * @param {?} value * @return {?} */ SelectService.prototype.setItems = function (value) { this.setConfiguration(function (opt) { return opt.items = value; }, true); this.setExpand(); }; /** * @return {?} */ SelectService.prototype.getInternalItems = function () { return this._items; }; /** * @param {?} values * @return {?} */ SelectService.prototype.setSelection = function (values) { this.setConfiguration(function (opt) { return opt.model = values; }, true); this.setExpand(); }; /** * @param {?} items * @param {?} destination * @return {?} */ SelectService.prototype.setSelectedItemOrChild = function (items, destination) { for (var _i = 0, items_1 = items; _i < items_1.length; _i++) { var itm = items_1[_i]; if (itm.hasChild) { if (itm.id === destination) { itm.selected = true; } this.setSelectedItemOrChild(itm.children, destination); } else if (itm.id === destination) { itm.selected = true; } } }; /** * @return {?} */ SelectService.prototype.getSelection = function () { if (this.Configuration.allowMultiple) { return this.getInternalSelection().map(function (v) { return v.data; }); } else { var /** @type {?} */ result = this.getInternalSelection(); if (result && result.length > 0) { return result[0].data; } } return null; }; /** * @return {?} */ SelectService.prototype.getInternalSelection = function () { var /** @type {?} */ selectedItems = this.getSelectedItems(this._items); if (selectedItems && selectedItems.length > 0) { var /** @type {?} */ i = 0; var /** @type {?} */ max = this._options.maxVisibleItemCount ? this._options.maxVisibleItemCount : 0; for (var _i = 0, selectedItems_1 = selectedItems; _i < selectedItems_1.length; _i++) { var item = selectedItems_1[_i]; item.isVisible = // Max not reached or not max value (i < max || max === 0) && // all my children are unselected (!item.hasChild || item.children.every(function (child) { return child.selected === false; })); if (item.isVisible && max > 0) { i++; } } } return selectedItems; }; /** * @param {?} item * @return {?} */ SelectService.prototype.toggleItemSelection = function (item) { var _this = this; if (!this.Configuration.allowMultiple) { this.setAllUnselected(this._items); } item.selected = !item.selected; this.setConfiguration(function (opt) { return opt.model = _this.getSelection(); }, false); if (this.Configuration.closeOnSelection) { this.setConfiguration(function (opt) { return opt.isOpen = false; }, false); } }; /** * @param {?} items * @return {?} */ SelectService.prototype.setAllUnselected = function (items) { for (var _i = 0, items_2 = items; _i < items_2.length; _i++) { var itm = items_2[_i]; if (itm.hasChild) { itm.selected = false; this.setAllUnselected(itm.children); } else { itm.selected = false; } } }; /** * @param {?} delegate * @param {?} processItems * @return {?} */ SelectService.prototype.setConfiguration = function (delegate, processItems) { var /** @type {?} */ modelBck = this._options.model; delegate(this._options); if (this._options.isValid()) { this.reconfigure(processItems); } // if model changed, raise event if (!processItems && ((modelBck && this._options.model !== modelBck) || (!modelBck && this._options.model))) { this.modelChanged$.next(this._options.model); } }; Object.defineProperty(SelectService.prototype, "Configuration", { /** * @return {?} */ get: function () { return this._options; }, enumerable: true, configurable: true }); /** * @return {?} */ SelectService.prototype.setExpand = function () { this.setExpandForList(this._items); }; /** * @param {?} items * @return {?} */ SelectService.prototype.setExpandForList = function (items) { if (!items) { return; } for (var _i = 0, items_3 = items; _i < items_3.length; _i++) { var item = items_3[_i]; this.setExpandForList(item.children); item.isOpen = (this._options.filterExpandMode === __WEBPACK_IMPORTED_MODULE_4__models_expand_mode__["a" /* ExpandMode */].All); if (this._options.filterExpandMode === __WEBPACK_IMPORTED_MODULE_4__models_expand_mode__["a" /* ExpandMode */].Selection) { if (item.children) { item.isOpen = item.children.some(function (itm) { return itm.isOpen || itm.selected; }); } } } }; /** * @param {?} sources * @return {?} */ SelectService.prototype.toSelectableItems = function (sources) { var _this = this; if (sources && Array.isArray(sources)) { var /** @type {?} */ i_1 = 1; return sources.map(function (srcItem) { var /** @type {?} */ item; if (srcItem[_this._options.idProperty] && srcItem[_this._options.idProperty] !== '' && srcItem[_this._options.textProperty]) { item = new __WEBPACK_IMPORTED_MODULE_1__models_selectable_item__["a" /* SelectableItem */]((srcItem[_this._options.idProperty] || '').toString(), /** @type {?} */ (srcItem[_this._options.textProperty]), srcItem, _this); } else { item = new __WEBPACK_IMPORTED_MODULE_1__models_selectable_item__["a" /* SelectableItem */](i_1.toString(), /** @type {?} */ (srcItem), srcItem, _this); i_1++; } if (_this._options.isHierarchy()) { item.children = _this.toSelectableItems(srcItem[_this._options.childProperty]); } return item; }); } return []; }; /** * @param {?} array * @return {?} */ SelectService.prototype.getSelectedItems = function (array) { if (this.Configuration.isValid()) { var /** @type {?} */ res = []; for (var _i = 0, array_1 = array; _i < array_1.length; _i++) { var v = array_1[_i]; if (v.hasChild && v.selected === true) { if (v.children.every(function (child) { return child.selected === false; })) { res = res.concat([v]); } else { res = res.concat(this.getSelectedItems(v.children)); } } else if (v.hasChild) { res = res.concat(this.getSelectedItems(v.children)); } else if (v.selected === true) { res = res.concat([v]); } } return res; } else { return []; } }; /** * @param {?} processItems * @return {?} */ SelectService.prototype.reconfigure = function (processItems) { var _this = this; if (this.Configuration.isValid()) { this.checkConfig(); if (processItems) { this._items = this.toSelectableItems(this.Configuration.items); } var /** @type {?} */ model = this.getModel(); var /** @type {?} */ select_1 = []; model.forEach(function (v) { select_1 = select_1.concat(_this.getItemForModel(v, _this._items)); }); select_1.forEach(function (v) { return v._selected = true; }); } }; /** * @return {?} */ SelectService.prototype.checkConfig = function () { if (this.Configuration.allowMultiple && this.Configuration.closeOnSelection) { this.Configuration.closeOnSelection = false; } else if (!this.Configuration.allowMultiple && !this.Configuration.closeOnSelection) { this.Configuration.closeOnSelection = true; } }; /** * @return {?} */ SelectService.prototype.getModel = function () { if (!this.Configuration.model) { return []; } else if (!Array.isArray(this.Configuration.model)) { return [this.Configuration.model]; } else { return this.Configuration.model; } }; /** * @param {?} value * @param {?} array * @return {?} */ SelectService.prototype.getItemForModel = function (value, array) { var /** @type {?} */ result = []; for (var _i = 0, array_2 = array; _i < array_2.length; _i++) { var v = array_2[_i]; if (value) { if (typeof value !== 'object') { if (v.data === value) { result.push(v); } } else { if (value[this.Configuration.idProperty]) { if (v.id === (value[this.Configuration.idProperty] || '').toString()) { result.push(v); } } if (this.Configuration.isHierarchy() && v.children && v.children.length > 0) { result = result.concat(this.getItemForModel(value, v.children)); } } } } return result; }; SelectService.decorators = [ { type: __WEBPACK_IMPORTED_MODULE_3__angular_core__["Injectable"] }, ]; /** * @nocollapse */ SelectService.ctorParameters = function () { return []; }; return SelectService; }()); function SelectService_tsickle_Closure_declarations() { /** @type {?} */ SelectService.decorators; /** * @nocollapse * @type {?} */ SelectService.ctorParameters; /** @type {?} */ SelectService.prototype.modelChanged$; /** @type {?} */ SelectService.prototype._items; /** @type {?} */ SelectService.prototype._options; } //# sourceMappingURL=select.service.js.map /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* WEBPACK VAR INJECTION */(function(global) { // CommonJS / Node have global context exposed as "global" variable. // We don't want to include the whole node.d.ts this this compilation unit so we'll just fake // the global "global" var for now. var __window = typeof window !== 'undefined' && window; var __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope && self; var __global = typeof global !== 'undefined' && global; var _root = __window || __global || __self; exports.root = _root; // Workaround Closure Compiler restriction: The body of a goog.module cannot use throw. // This is needed when used with angular/tsickle which inserts a goog.module statement. // Wrap in IIFE (function () { if (!_root) { throw new Error('RxJS could not find any global context (window, self, global)'); } })(); //# sourceMappingURL=root.js.map /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(21))) /***/ }), /* 6 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var isArray_1 = __webpack_require__(23); var isObject_1 = __webpack_require__(24); var isFunction_1 = __webpack_require__(10); var tryCatch_1 = __webpack_require__(25); var errorObject_1 = __webpack_require__(11); var UnsubscriptionError_1 = __webpack_require__(26); /** * Represents a disposable resource, such as the execution of an Observable. A * Subscription has one important method, `unsubscribe`, that takes no argument * and just disposes the resource held by the subscription. * * Additionally, subscriptions may be grouped together through the `add()` * method, which will attach a child Subscription to the current Subscription. * When a Subscription is unsubscribed, all its children (and its grandchildren) * will be unsubscribed as well. * * @class Subscription */ var Subscription = (function () { /** * @param {function(): void} [unsubscribe] A function describing how to * perform the disposal of resources when the `unsubscribe` method is called. */ function Subscription(unsubscribe) { /** * A flag to indicate whether this Subscription has already been unsubscribed. * @type {boolean} */ this.closed = false; this._parent = null; this._parents = null; this._subscriptions = null; if (unsubscribe) { this._unsubscribe = unsubscribe; } } /** * Disposes the resources held by the subscription. May, for instance, cancel * an ongoing Observable execution or cancel any other type of work that * started when the Subscription was created. * @return {void} */ Subscription.prototype.unsubscribe = function () { var hasErrors = false; var errors; if (this.closed) { return; } var _a = this, _parent = _a._parent, _parents = _a._parents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions; this.closed = true; this._parent = null; this._parents = null; // null out _subscriptions first so any child subscriptions that attempt // to remove themselves from this subscription will noop this._subscriptions = null; var index = -1; var len = _parents ? _parents.length : 0; // if this._parent is null, then so is this._parents, and we // don't have to remove ourselves from any parent subscriptions. while (_parent) { _parent.remove(this); // if this._parents is null or index >= len, // then _parent is set to null, and the loop exits _parent = ++index < len && _parents[index] || null; } if (isFunction_1.isFunction(_unsubscribe)) { var trial = tryCatch_1.tryCatch(_unsubscribe).call(this); if (trial === errorObject_1.errorObject) { hasErrors = true; errors = errors || (errorObject_1.errorObject.e instanceof UnsubscriptionError_1.UnsubscriptionError ? flattenUnsubscriptionErrors(errorObject_1.errorObject.e.errors) : [errorObject_1.errorObject.e]); } } if (isArray_1.isArray(_subscriptions)) { index = -1; len = _subscriptions.length; while (++index < len) { var sub = _subscriptions[index]; if (isObject_1.isObject(sub)) { var trial = tryCatch_1.tryCatch(sub.unsubscribe).call(sub); if (trial === errorObject_1.errorObject) { hasErrors = true; errors = errors || []; var err = errorObject_1.errorObject.e; if (err instanceof UnsubscriptionError_1.UnsubscriptionError) { errors = errors.concat(flattenUnsubscriptionErrors(err.errors)); } else { errors.push(err); } } } } } if (hasErrors) { throw new UnsubscriptionError_1.UnsubscriptionError(errors); } }; /** * Adds a tear down to be called during the unsubscribe() of this * Subscription. * * If the tear down being added is a subscription that is already * unsubscribed, is the same reference `add` is being called on, or is * `Subscription.EMPTY`, it will not be added. * * If this subscription is already in an `closed` state, the passed * tear down logic will be executed immediately. * * @param {TeardownLogic} teardown The additional logic to execute on * teardown. * @return {Subscription} Returns the Subscription used or created to be * added to the inner subscriptions list. This Subscription can be used with * `remove()` to remove the passed teardown logic from the inner subscriptions * list. */ Subscription.prototype.add = function (teardown) { if (!teardown || (teardown === Subscription.EMPTY)) { return Subscription.EMPTY; } if (teardown === this) { return this; } var subscription = teardown; switch (typeof teardown) { case 'function': subscription = new Subscription(teardown); case 'object': if (subscription.closed || typeof subscription.unsubscribe !== 'function') { return subscription; } else if (this.closed) { subscription.unsubscribe(); return subscription; } else if (typeof subscription._addParent !== 'function' /* quack quack */) { var tmp = subscription; subscription = new Subscription(); subscription._subscriptions = [tmp]; } break; default: throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.'); } var subscriptions = this._subscriptions || (this._subscriptions = []); subscriptions.push(subscription); subscription._addParent(this); return subscription; }; /** * Removes a Subscription from the internal list of subscriptions that will * unsubscribe during the unsubscribe process of this Subscription. * @param {Subscription} subscription The subscription to remove. * @return {void} */ Subscription.prototype.remove = function (subscription) { var subscriptions = this._subscriptions; if (subscriptions) { var subscriptionIndex = subscriptions.indexOf(subscription); if (subscriptionIndex !== -1) { subscriptions.splice(subscriptionIndex, 1); } } }; Subscription.prototype._addParent = function (parent) { var _a = this, _parent = _a._parent, _parents = _a._parents; if (!_parent || _parent === parent) { // If we don't have a parent, or the new parent is the same as the // current parent, then set this._parent to the new parent. this._parent = parent; } else if (!_parents) { // If there's already one parent, but not multiple, allocate an Array to // store the rest of the parent Subscriptions. this._parents = [parent]; } else if (_parents.indexOf(parent) === -1) { // Only add the new parent to the _parents list if it's not already there. _parents.push(parent); } }; Subscription.EMPTY = (function (empty) { empty.closed = true; return empty; }(new Subscription())); return Subscription; }()); exports.Subscription = Subscription; function flattenUnsubscriptionErrors(errors) { return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError_1.UnsubscriptionError) ? err.errors : err); }, []); } //# sourceMappingURL=Subscription.js.map /***/ }), /* 7 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var root_1 = __webpack_require__(5); var Symbol = root_1.root.Symbol; exports.rxSubscriber = (typeof Symbol === 'function' && typeof Symbol.for === 'function') ? Symbol.for('rxSubscriber') : '@@rxSubscriber'; /** * @deprecated use rxSubscriber instead */ exports.$$rxSubscriber = exports.rxSubscriber; //# sourceMappingURL=rxSubscriber.js.map /***/ }), /* 8 */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_8__; /***/ }), /* 9 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var isFunction_1 = __webpack_require__(10); var Subscription_1 = __webpack_require__(6); var Observer_1 = __webpack_require__(12); var rxSubscriber_1 = __webpack_require__(7); /** * Implements the {@link Observer} interface and extends the * {@link Subscription} class. While the {@link Observer} is the public API for * consuming the values of an {@link Observable}, all Observers get converted to * a Subscriber, in order to provide Subscription-like capabilities such as * `unsubscribe`. Subscriber is a common type in RxJS, and crucial for * implementing operators, but it is rarely used as a public API. * * @class Subscriber<T> */ var Subscriber = (function (_super) { __extends(Subscriber, _super); /** * @param {Observer|function(value: T): void} [destinationOrNext] A partially * defined Observer or a `next` callback function. * @param {function(e: ?any): void} [error] The `error` callback of an * Observer. * @param {function(): void} [complete] The `complete` callback of an * Observer. */ function Subscriber(destinationOrNext, error, complete) { _super.call(this); this.syncErrorValue = null; this.syncErrorThrown = false; this.syncErrorThrowable = false; this.isStopped = false; switch (arguments.length) { case 0: this.destination = Observer_1.empty; break; case 1: if (!destinationOrNext) { this.destination = Observer_1.empty; break; } if (typeof destinationOrNext === 'object') { if (destinationOrNext instanceof Subscriber) { this.destination = destinationOrNext; this.destination.add(this); } else { this.syncErrorThrowable = true; this.destination = new SafeSubscriber(this, destinationOrNext); } break; } default: this.syncErrorThrowable = true; this.destination = new SafeSubscriber(this, destinationOrNext, error, complete); break; } } Subscriber.prototype[rxSubscriber_1.rxSubscriber] = function () { return this; }; /** * A static factory for a Subscriber, given a (potentially partial) definition * of an Observer. * @param {function(x: ?T): void} [next] The `next` callback of an Observer. * @param {function(e: ?any): void} [error] The `error` callback of an * Observer. * @param {function(): void} [complete] The `complete` callback of an * Observer. * @return {Subscriber<T>} A Subscriber wrapping the (partially defined) * Observer represented by the given arguments. */ Subscriber.create = function (next, error, complete) { var subscriber = new Subscriber(next, error, complete); subscriber.syncErrorThrowable = false; return subscriber; }; /** * The {@link Observer} callback to receive notifications of type `next` from * the Observable, with a value. The Observable may call this method 0 or more * times. * @param {T} [value] The `next` value. * @return {void} */ Subscriber.prototype.next = function (value) { if (!this.isStopped) { this._next(value); } }; /** * The {@link Observer} callback to receive notifications of type `error` from * the Observable, with an attached {@link Error}. Notifies the Observer that * the Observable has experienced an error condition. * @param {any} [err] The `error` exception. * @return {void} */ Subscriber.prototype.error = function (err) { if (!this.isStopped) { this.isStopped = true; this._error(err); } }; /** * The {@link Observer} callback to rec