component.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 common_1 = require("@angular/common");
  27. var platform_browser_1 = require("@angular/platform-browser");
  28. var events_strategy_1 = require("./events-strategy");
  29. var domAdapter = require("devextreme/core/dom_adapter");
  30. var events = require("devextreme/events");
  31. var nested_option_1 = require("./nested-option");
  32. exports.IS_PLATFORM_SERVER = platform_browser_1.makeStateKey('DX_isPlatformServer');
  33. var DxComponent = (function () {
  34. function DxComponent(element, ngZone, templateHost, watcherHelper, transferState, platformId) {
  35. this.element = element;
  36. this.watcherHelper = watcherHelper;
  37. this.transferState = transferState;
  38. this.platformId = platformId;
  39. this._initialOptions = {};
  40. this._optionsToUpdate = {};
  41. this.optionChangedHandlers = new core_1.EventEmitter();
  42. this.isLinked = true;
  43. this.changedOptions = {};
  44. this.widgetUpdateLocked = false;
  45. this.templates = [];
  46. templateHost.setHost(this);
  47. this._collectionContainerImpl = new nested_option_1.CollectionNestedOptionContainerImpl(this._setOption.bind(this));
  48. this.eventHelper = new events_strategy_1.EmitterHelper(ngZone, this);
  49. }
  50. DxComponent.prototype._initTemplates = function () {
  51. if (this.templates.length) {
  52. var initialTemplates_1 = {};
  53. this.templates.forEach(function (template) {
  54. initialTemplates_1[template.name] = template;
  55. });
  56. this.instance.option('integrationOptions.templates', initialTemplates_1);
  57. }
  58. };
  59. DxComponent.prototype._initEvents = function () {
  60. var _this = this;
  61. this.instance.on('optionChanged', function (e) {
  62. _this.changedOptions[e.name] = e.value;
  63. var value = e.name === e.fullName ? e.value : e.component.option(e.name);
  64. _this.eventHelper.fireNgEvent(e.name + 'Change', [value]);
  65. _this.optionChangedHandlers.emit(e);
  66. });
  67. };
  68. DxComponent.prototype._initOptions = function () {
  69. this._initialOptions.integrationOptions.watchMethod = this.watcherHelper.getWatchMethod();
  70. };
  71. DxComponent.prototype._initPlatform = function () {
  72. if (this.transferState.hasKey(exports.IS_PLATFORM_SERVER)) {
  73. this._initialOptions.integrationOptions.renderedOnServer = this.transferState.get(exports.IS_PLATFORM_SERVER, null);
  74. }
  75. else if (common_1.isPlatformServer(this.platformId)) {
  76. this.transferState.set(exports.IS_PLATFORM_SERVER, true);
  77. }
  78. };
  79. DxComponent.prototype._createEventEmitters = function (events) {
  80. var _this = this;
  81. this.eventHelper.createEmitters(events);
  82. this._initialOptions.eventsStrategy = function (instance) {
  83. var strategy = new events_strategy_1.NgEventsStrategy(instance);
  84. events.filter(function (event) { return event.subscribe; }).forEach(function (event) {
  85. strategy.addEmitter(event.subscribe, _this[event.emit]);
  86. });
  87. return strategy;
  88. };
  89. this._initialOptions.nestedComponentOptions = function (component) {
  90. return {
  91. eventsStrategy: function (instance) { return new events_strategy_1.NgEventsStrategy(instance); },
  92. nestedComponentOptions: component.option('nestedComponentOptions')
  93. };
  94. };
  95. };
  96. DxComponent.prototype._shouldOptionChange = function (name, value) {
  97. if (this.changedOptions.hasOwnProperty(name)) {
  98. var prevValue = this.changedOptions[name];
  99. delete this.changedOptions[name];
  100. return value !== prevValue;
  101. }
  102. return true;
  103. };
  104. DxComponent.prototype.clearChangedOptions = function () {
  105. this.changedOptions = {};
  106. };
  107. DxComponent.prototype._getOption = function (name) {
  108. return this.instance ?
  109. this.instance.option(name) :
  110. this._initialOptions[name];
  111. };
  112. DxComponent.prototype.lockWidgetUpdate = function () {
  113. if (!this.widgetUpdateLocked && this.instance) {
  114. this.instance.beginUpdate();
  115. this.widgetUpdateLocked = true;
  116. }
  117. };
  118. DxComponent.prototype.unlockWidgetUpdate = function () {
  119. if (this.widgetUpdateLocked) {
  120. this.widgetUpdateLocked = false;
  121. this.instance.endUpdate();
  122. }
  123. };
  124. DxComponent.prototype._setOption = function (name, value) {
  125. this.lockWidgetUpdate();
  126. if (!this._shouldOptionChange(name, value)) {
  127. return;
  128. }
  129. if (this.instance) {
  130. this.instance.option(name, value);
  131. }
  132. else {
  133. this._initialOptions[name] = value;
  134. }
  135. };
  136. DxComponent.prototype._createWidget = function (element) {
  137. this._initialOptions.integrationOptions = {};
  138. this._initPlatform();
  139. this._initOptions();
  140. this._initialOptions.onInitializing = function () {
  141. this.beginUpdate();
  142. };
  143. this.instance = this._createInstance(element, this._initialOptions);
  144. this._initEvents();
  145. this._initialOptions = {};
  146. };
  147. DxComponent.prototype._destroyWidget = function () {
  148. if (this.instance) {
  149. var element = this.instance.element();
  150. events.triggerHandler(element, 'dxremove', { _angularIntegration: true });
  151. this.instance.dispose();
  152. domAdapter.removeElement(element);
  153. }
  154. };
  155. DxComponent.prototype.ngOnChanges = function (changes) {
  156. for (var key in changes) {
  157. var change = changes[key];
  158. if (change.currentValue !== this[key]) {
  159. this._optionsToUpdate[key] = changes[key].currentValue;
  160. }
  161. }
  162. };
  163. DxComponent.prototype.ngOnInit = function () {
  164. this._createWidget(this.element.nativeElement);
  165. };
  166. DxComponent.prototype.ngDoCheck = function () {
  167. this.applyOptions();
  168. };
  169. DxComponent.prototype.ngAfterContentChecked = function () {
  170. this.applyOptions();
  171. this.unlockWidgetUpdate();
  172. };
  173. DxComponent.prototype.ngAfterViewInit = function () {
  174. this._initTemplates();
  175. this.instance.endUpdate();
  176. };
  177. DxComponent.prototype.applyOptions = function () {
  178. if (Object.keys(this._optionsToUpdate).length) {
  179. if (this.instance) {
  180. this.instance.option(this._optionsToUpdate);
  181. }
  182. this._optionsToUpdate = {};
  183. }
  184. };
  185. DxComponent.prototype.setTemplate = function (template) {
  186. this.templates.push(template);
  187. };
  188. DxComponent.prototype.setChildren = function (propertyName, items) {
  189. return this._collectionContainerImpl.setChildren(propertyName, items);
  190. };
  191. /** @nocollapse */
  192. DxComponent.ctorParameters = function () { return [
  193. { type: core_1.ElementRef, },
  194. { type: core_1.NgZone, },
  195. { type: template_host_1.DxTemplateHost, },
  196. { type: watcher_helper_1.WatcherHelper, },
  197. { type: platform_browser_1.TransferState, },
  198. { type: undefined, decorators: [{ type: core_1.Inject, args: [core_1.PLATFORM_ID,] },] },
  199. ]; };
  200. return DxComponent;
  201. }());
  202. exports.DxComponent = DxComponent;
  203. var DxComponentExtension = (function (_super) {
  204. __extends(DxComponentExtension, _super);
  205. function DxComponentExtension() {
  206. return _super !== null && _super.apply(this, arguments) || this;
  207. }
  208. DxComponentExtension.prototype.createInstance = function (element) {
  209. this._createWidget(element);
  210. };
  211. DxComponentExtension.prototype.ngOnInit = function () {
  212. };
  213. DxComponentExtension.prototype.ngAfterViewInit = function () {
  214. this._createWidget(this.element.nativeElement);
  215. this.instance.endUpdate();
  216. };
  217. return DxComponentExtension;
  218. }(DxComponent));
  219. exports.DxComponentExtension = DxComponentExtension;
  220. //# sourceMappingURL=component.js.map