devextreme-vue
Version:
DevExtreme Vue UI and Visualization Components
103 lines (101 loc) • 4.07 kB
JavaScript
/*!
* devextreme-vue
* Version: 19.2.6
* Build date: Thu Jan 30 2020
*
* Copyright (c) 2012 - 2020 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-vue
*/
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(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);
};
Object.defineProperty(exports, "__esModule", { value: true });
var config_1 = require("./config");
var templates_discovering_1 = require("./templates-discovering");
var events = require("devextreme/events");
var constants_1 = require("./constants");
var helpers_1 = require("./helpers");
var TemplatesManager = /** @class */ (function () {
function TemplatesManager(component) {
this._slots = {};
this._templates = {};
this._isDirty = false;
this._component = component;
this.discover();
}
TemplatesManager.prototype.discover = function () {
var slots = templates_discovering_1.discover(this._component);
this._slots = __assign(__assign({}, this._slots), slots);
if (!helpers_1.allKeysAreEqual(this._templates, slots)) {
this._prepareTemplates();
}
};
Object.defineProperty(TemplatesManager.prototype, "templates", {
get: function () {
return this._templates;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TemplatesManager.prototype, "isDirty", {
get: function () {
return this._isDirty;
},
enumerable: true,
configurable: true
});
TemplatesManager.prototype.resetDirtyFlag = function () {
this._isDirty = false;
};
TemplatesManager.prototype._prepareTemplates = function () {
this._templates = {};
for (var _i = 0, _a = Object.keys(this._slots); _i < _a.length; _i++) {
var name_1 = _a[_i];
this._templates[name_1] = this.createDxTemplate(name_1);
}
this._isDirty = true;
};
TemplatesManager.prototype.createDxTemplate = function (name) {
var _this = this;
return {
render: function (data) {
var scopeData = config_1.getOption("useLegacyTemplateEngine")
? data.model
: { data: data.model, index: data.index };
var container = data.container.get ? data.container.get(0) : data.container;
var placeholder = document.createElement("div");
container.appendChild(placeholder);
var mountedTemplate = templates_discovering_1.mountTemplate(function () { return _this._slots[name]; }, _this._component, scopeData, name, placeholder);
var element = mountedTemplate.$el;
if (element.classList) {
element.classList.add(constants_1.DX_TEMPLATE_WRAPPER_CLASS);
}
if (element.nodeType === Node.TEXT_NODE) {
var removalListener = document.createElement(container.nodeName === "TABLE" ? "tbody" : "span");
removalListener.style.display = "none";
container.appendChild(removalListener);
events.one(removalListener, constants_1.DX_REMOVE_EVENT, mountedTemplate.$destroy.bind(mountedTemplate));
}
else {
events.one(element, constants_1.DX_REMOVE_EVENT, mountedTemplate.$destroy.bind(mountedTemplate));
}
return element;
}
};
};
return TemplatesManager;
}());
exports.TemplatesManager = TemplatesManager;