"use strict"; var __extends = (this && this.__extends) || (function () { var 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 function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /*! * devextreme-angular * Version: 19.1.16 * Build date: Tue Oct 18 2022 * * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file in the root of the project for details. * * https://github.com/DevExpress/devextreme-angular */ Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var template_1 = require("./template"); var utils_1 = require("./utils"); var render = require("devextreme/core/renderer"); var events = require("devextreme/events"); var VISIBILITY_CHANGE_SELECTOR = 'dx-visibility-change-handler'; var BaseNestedOption = (function () { function BaseNestedOption() { this._initialOptions = {}; this._collectionContainerImpl = new CollectionNestedOptionContainerImpl(this._setOption.bind(this), this._filterItems.bind(this)); } BaseNestedOption.prototype._optionChangedHandler = function (e) { var fullOptionPath = this._fullOptionPath(); if (e.fullName.indexOf(fullOptionPath) === 0) { var optionName = e.fullName.slice(fullOptionPath.length); var emitter = this[optionName + 'Change']; if (emitter) { emitter.next(e.value); } } }; BaseNestedOption.prototype._createEventEmitters = function (events) { var _this = this; events.forEach(function (event) { _this[event.emit] = new core_1.EventEmitter(); }); }; BaseNestedOption.prototype._getOption = function (name) { if (this.isLinked) { return this.instance.option(this._fullOptionPath() + name); } else { return this._initialOptions[name]; } }; BaseNestedOption.prototype._setOption = function (name, value) { if (this.isLinked) { this.instance.option(this._fullOptionPath() + name, value); } else { this._initialOptions[name] = value; } }; BaseNestedOption.prototype.setHost = function (host, optionPath) { this._host = host; this._hostOptionPath = optionPath; this.optionChangedHandlers.subscribe(this._optionChangedHandler.bind(this)); }; BaseNestedOption.prototype.setChildren = function (propertyName, items) { return this._collectionContainerImpl.setChildren(propertyName, items); }; BaseNestedOption.prototype._filterItems = function (items) { var _this = this; return items.filter(function (item) { return item !== _this; }); }; Object.defineProperty(BaseNestedOption.prototype, "instance", { get: function () { return this._host && this._host.instance; }, enumerable: true, configurable: true }); Object.defineProperty(BaseNestedOption.prototype, "isLinked", { get: function () { return !!this.instance && this._host.isLinked; }, enumerable: true, configurable: true }); Object.defineProperty(BaseNestedOption.prototype, "optionChangedHandlers", { get: function () { return this._host && this._host.optionChangedHandlers; }, enumerable: true, configurable: true }); return BaseNestedOption; }()); exports.BaseNestedOption = BaseNestedOption; var CollectionNestedOptionContainerImpl = (function () { function CollectionNestedOptionContainerImpl(_setOption, _filterItems) { this._setOption = _setOption; this._filterItems = _filterItems; this._activatedQueries = {}; } CollectionNestedOptionContainerImpl.prototype.setChildren = function (propertyName, items) { if (this._filterItems) { items = this._filterItems(items); } if (items.length) { this._activatedQueries[propertyName] = true; } if (this._activatedQueries[propertyName]) { var widgetItems = items.map(function (item, index) { item._index = index; return item._value; }); this._setOption(propertyName, widgetItems); } }; return CollectionNestedOptionContainerImpl; }()); exports.CollectionNestedOptionContainerImpl = CollectionNestedOptionContainerImpl; var NestedOption = (function (_super) { __extends(NestedOption, _super); function NestedOption() { return _super !== null && _super.apply(this, arguments) || this; } NestedOption.prototype.setHost = function (host, optionPath) { _super.prototype.setHost.call(this, host, optionPath); this._host[this._optionPath] = this._initialOptions; }; NestedOption.prototype._fullOptionPath = function () { return this._hostOptionPath() + this._optionPath + '.'; }; return NestedOption; }(BaseNestedOption)); exports.NestedOption = NestedOption; var CollectionNestedOption = (function (_super) { __extends(CollectionNestedOption, _super); function CollectionNestedOption() { return _super !== null && _super.apply(this, arguments) || this; } CollectionNestedOption.prototype._fullOptionPath = function () { return this._hostOptionPath() + this._optionPath + '[' + this._index + ']' + '.'; }; Object.defineProperty(CollectionNestedOption.prototype, "_value", { get: function () { return this._initialOptions; }, enumerable: true, configurable: true }); Object.defineProperty(CollectionNestedOption.prototype, "isLinked", { get: function () { return this._index !== undefined && !!this.instance && this._host.isLinked; }, enumerable: true, configurable: true }); return CollectionNestedOption; }(BaseNestedOption)); exports.CollectionNestedOption = CollectionNestedOption; var triggerShownEvent = function (element) { var changeHandlers = []; if (!render(element).hasClass(VISIBILITY_CHANGE_SELECTOR)) { changeHandlers.push(element); } changeHandlers.push.apply(changeHandlers, element.querySelectorAll('.' + VISIBILITY_CHANGE_SELECTOR)); for (var i = 0; i < changeHandlers.length; i++) { events.triggerHandler(changeHandlers[i], 'dxshown'); } }; var ɵ0 = triggerShownEvent; exports.ɵ0 = ɵ0; function extractTemplate(option, element, renderer, document) { if (!option.template === undefined || !element.nativeElement.hasChildNodes()) { return; } var childNodes = [].slice.call(element.nativeElement.childNodes); var userContent = childNodes.filter(function (n) { if (n.tagName) { var tagNamePrefix = n.tagName.toLowerCase().substr(0, 3); return !(tagNamePrefix === 'dxi' || tagNamePrefix === 'dxo'); } else { return n.nodeName !== '#comment' && n.textContent.replace(/\s/g, '').length; } }); if (!userContent.length) { return; } option.template = { render: function (renderData) { var result = element.nativeElement; renderer.addClass(result, template_1.DX_TEMPLATE_WRAPPER_CLASS); if (renderData.container) { var container = utils_1.getElement(renderData.container); var resultInContainer = container.contains(element.nativeElement); renderer.appendChild(container, element.nativeElement); if (!resultInContainer) { var resultInBody = document.body.contains(container); if (resultInBody) { triggerShownEvent(result); } } } return result; } }; } exports.extractTemplate = extractTemplate; var NestedOptionHost = (function () { function NestedOptionHost() { } NestedOptionHost.prototype.getHost = function () { return this._host; }; NestedOptionHost.prototype.setHost = function (host, optionPath) { this._host = host; this._optionPath = optionPath || (function () { return ''; }); }; NestedOptionHost.prototype.setNestedOption = function (nestedOption) { nestedOption.setHost(this._host, this._optionPath); }; return NestedOptionHost; }()); exports.NestedOptionHost = NestedOptionHost; //# sourceMappingURL=nested-option.js.map