nested-option.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return function (d, b) {
  7. extendStatics(d, b);
  8. function __() { this.constructor = d; }
  9. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10. };
  11. })();
  12. /*!
  13. * devextreme-angular
  14. * Version: 19.1.16
  15. * Build date: Tue Oct 18 2022
  16. *
  17. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  18. *
  19. * This software may be modified and distributed under the terms
  20. * of the MIT license. See the LICENSE file in the root of the project for details.
  21. *
  22. * https://github.com/DevExpress/devextreme-angular
  23. */
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var core_1 = require("@angular/core");
  26. var template_1 = require("./template");
  27. var utils_1 = require("./utils");
  28. var render = require("devextreme/core/renderer");
  29. var events = require("devextreme/events");
  30. var VISIBILITY_CHANGE_SELECTOR = 'dx-visibility-change-handler';
  31. var BaseNestedOption = (function () {
  32. function BaseNestedOption() {
  33. this._initialOptions = {};
  34. this._collectionContainerImpl = new CollectionNestedOptionContainerImpl(this._setOption.bind(this), this._filterItems.bind(this));
  35. }
  36. BaseNestedOption.prototype._optionChangedHandler = function (e) {
  37. var fullOptionPath = this._fullOptionPath();
  38. if (e.fullName.indexOf(fullOptionPath) === 0) {
  39. var optionName = e.fullName.slice(fullOptionPath.length);
  40. var emitter = this[optionName + 'Change'];
  41. if (emitter) {
  42. emitter.next(e.value);
  43. }
  44. }
  45. };
  46. BaseNestedOption.prototype._createEventEmitters = function (events) {
  47. var _this = this;
  48. events.forEach(function (event) {
  49. _this[event.emit] = new core_1.EventEmitter();
  50. });
  51. };
  52. BaseNestedOption.prototype._getOption = function (name) {
  53. if (this.isLinked) {
  54. return this.instance.option(this._fullOptionPath() + name);
  55. }
  56. else {
  57. return this._initialOptions[name];
  58. }
  59. };
  60. BaseNestedOption.prototype._setOption = function (name, value) {
  61. if (this.isLinked) {
  62. this.instance.option(this._fullOptionPath() + name, value);
  63. }
  64. else {
  65. this._initialOptions[name] = value;
  66. }
  67. };
  68. BaseNestedOption.prototype.setHost = function (host, optionPath) {
  69. this._host = host;
  70. this._hostOptionPath = optionPath;
  71. this.optionChangedHandlers.subscribe(this._optionChangedHandler.bind(this));
  72. };
  73. BaseNestedOption.prototype.setChildren = function (propertyName, items) {
  74. return this._collectionContainerImpl.setChildren(propertyName, items);
  75. };
  76. BaseNestedOption.prototype._filterItems = function (items) {
  77. var _this = this;
  78. return items.filter(function (item) { return item !== _this; });
  79. };
  80. Object.defineProperty(BaseNestedOption.prototype, "instance", {
  81. get: function () {
  82. return this._host && this._host.instance;
  83. },
  84. enumerable: true,
  85. configurable: true
  86. });
  87. Object.defineProperty(BaseNestedOption.prototype, "isLinked", {
  88. get: function () {
  89. return !!this.instance && this._host.isLinked;
  90. },
  91. enumerable: true,
  92. configurable: true
  93. });
  94. Object.defineProperty(BaseNestedOption.prototype, "optionChangedHandlers", {
  95. get: function () {
  96. return this._host && this._host.optionChangedHandlers;
  97. },
  98. enumerable: true,
  99. configurable: true
  100. });
  101. return BaseNestedOption;
  102. }());
  103. exports.BaseNestedOption = BaseNestedOption;
  104. var CollectionNestedOptionContainerImpl = (function () {
  105. function CollectionNestedOptionContainerImpl(_setOption, _filterItems) {
  106. this._setOption = _setOption;
  107. this._filterItems = _filterItems;
  108. this._activatedQueries = {};
  109. }
  110. CollectionNestedOptionContainerImpl.prototype.setChildren = function (propertyName, items) {
  111. if (this._filterItems) {
  112. items = this._filterItems(items);
  113. }
  114. if (items.length) {
  115. this._activatedQueries[propertyName] = true;
  116. }
  117. if (this._activatedQueries[propertyName]) {
  118. var widgetItems = items.map(function (item, index) {
  119. item._index = index;
  120. return item._value;
  121. });
  122. this._setOption(propertyName, widgetItems);
  123. }
  124. };
  125. return CollectionNestedOptionContainerImpl;
  126. }());
  127. exports.CollectionNestedOptionContainerImpl = CollectionNestedOptionContainerImpl;
  128. var NestedOption = (function (_super) {
  129. __extends(NestedOption, _super);
  130. function NestedOption() {
  131. return _super !== null && _super.apply(this, arguments) || this;
  132. }
  133. NestedOption.prototype.setHost = function (host, optionPath) {
  134. _super.prototype.setHost.call(this, host, optionPath);
  135. this._host[this._optionPath] = this._initialOptions;
  136. };
  137. NestedOption.prototype._fullOptionPath = function () {
  138. return this._hostOptionPath() + this._optionPath + '.';
  139. };
  140. return NestedOption;
  141. }(BaseNestedOption));
  142. exports.NestedOption = NestedOption;
  143. var CollectionNestedOption = (function (_super) {
  144. __extends(CollectionNestedOption, _super);
  145. function CollectionNestedOption() {
  146. return _super !== null && _super.apply(this, arguments) || this;
  147. }
  148. CollectionNestedOption.prototype._fullOptionPath = function () {
  149. return this._hostOptionPath() + this._optionPath + '[' + this._index + ']' + '.';
  150. };
  151. Object.defineProperty(CollectionNestedOption.prototype, "_value", {
  152. get: function () {
  153. return this._initialOptions;
  154. },
  155. enumerable: true,
  156. configurable: true
  157. });
  158. Object.defineProperty(CollectionNestedOption.prototype, "isLinked", {
  159. get: function () {
  160. return this._index !== undefined && !!this.instance && this._host.isLinked;
  161. },
  162. enumerable: true,
  163. configurable: true
  164. });
  165. return CollectionNestedOption;
  166. }(BaseNestedOption));
  167. exports.CollectionNestedOption = CollectionNestedOption;
  168. var triggerShownEvent = function (element) {
  169. var changeHandlers = [];
  170. if (!render(element).hasClass(VISIBILITY_CHANGE_SELECTOR)) {
  171. changeHandlers.push(element);
  172. }
  173. changeHandlers.push.apply(changeHandlers, element.querySelectorAll('.' + VISIBILITY_CHANGE_SELECTOR));
  174. for (var i = 0; i < changeHandlers.length; i++) {
  175. events.triggerHandler(changeHandlers[i], 'dxshown');
  176. }
  177. };
  178. var ɵ0 = triggerShownEvent;
  179. exports.ɵ0 = ɵ0;
  180. function extractTemplate(option, element, renderer, document) {
  181. if (!option.template === undefined || !element.nativeElement.hasChildNodes()) {
  182. return;
  183. }
  184. var childNodes = [].slice.call(element.nativeElement.childNodes);
  185. var userContent = childNodes.filter(function (n) {
  186. if (n.tagName) {
  187. var tagNamePrefix = n.tagName.toLowerCase().substr(0, 3);
  188. return !(tagNamePrefix === 'dxi' || tagNamePrefix === 'dxo');
  189. }
  190. else {
  191. return n.nodeName !== '#comment' && n.textContent.replace(/\s/g, '').length;
  192. }
  193. });
  194. if (!userContent.length) {
  195. return;
  196. }
  197. option.template = {
  198. render: function (renderData) {
  199. var result = element.nativeElement;
  200. renderer.addClass(result, template_1.DX_TEMPLATE_WRAPPER_CLASS);
  201. if (renderData.container) {
  202. var container = utils_1.getElement(renderData.container);
  203. var resultInContainer = container.contains(element.nativeElement);
  204. renderer.appendChild(container, element.nativeElement);
  205. if (!resultInContainer) {
  206. var resultInBody = document.body.contains(container);
  207. if (resultInBody) {
  208. triggerShownEvent(result);
  209. }
  210. }
  211. }
  212. return result;
  213. }
  214. };
  215. }
  216. exports.extractTemplate = extractTemplate;
  217. var NestedOptionHost = (function () {
  218. function NestedOptionHost() {
  219. }
  220. NestedOptionHost.prototype.getHost = function () {
  221. return this._host;
  222. };
  223. NestedOptionHost.prototype.setHost = function (host, optionPath) {
  224. this._host = host;
  225. this._optionPath = optionPath || (function () { return ''; });
  226. };
  227. NestedOptionHost.prototype.setNestedOption = function (nestedOption) {
  228. nestedOption.setHost(this._host, this._optionPath);
  229. };
  230. return NestedOptionHost;
  231. }());
  232. exports.NestedOptionHost = NestedOptionHost;
  233. //# sourceMappingURL=nested-option.js.map